1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "sal/config.h"
40 static ::rtl::OString
lcl_NormalizeFilename(const ::rtl::OString
& rFilename
)
42 return rFilename
.copy(
44 rFilename
.lastIndexOf( "\\" ),
45 rFilename
.lastIndexOf( "/" ))+1);
53 sal_Bool
PFormEntrys::GetTransex3Text( rtl::OString
&rReturn
,
54 sal_uInt16 nTyp
, const rtl::OString
&nLangIndex
, sal_Bool bDel
)
56 sal_Bool rc
= GetText( rReturn
, nTyp
, nLangIndex
, bDel
);
57 for( sal_Int32 idx
= 0; idx
< rReturn
.getLength(); idx
++ )
59 if( rReturn
[idx
] == '\"' && ( idx
>= 1 ) && rReturn
[idx
-1] == '\\' )
61 rReturn
= rReturn
.replaceAt( idx
-1, 1, rtl::OString() );
66 /*****************************************************************************/
67 sal_Bool
PFormEntrys::GetText( rtl::OString
&rReturn
,
68 sal_uInt16 nTyp
, const rtl::OString
&nLangIndex
, sal_Bool bDel
)
71 sal_Bool bReturn
=sal_True
;
73 case STRING_TYP_TEXT
:
74 rReturn
= sText
[ nLangIndex
];
76 sText
[ nLangIndex
] = "";
77 bReturn
= bTextFirst
[ nLangIndex
];
78 bTextFirst
[ nLangIndex
] = sal_False
;
80 case STRING_TYP_HELPTEXT
:
83 case STRING_TYP_QUICKHELPTEXT
:
84 rReturn
= sQuickHelpText
[ nLangIndex
];
86 sQuickHelpText
[ nLangIndex
] = "";
87 bReturn
= bQuickHelpTextFirst
[ nLangIndex
];
88 bQuickHelpTextFirst
[ nLangIndex
] = sal_False
;
90 case STRING_TYP_TITLE
:
91 rReturn
= sTitle
[ nLangIndex
];
93 sTitle
[ nLangIndex
] = "";
94 bReturn
= bTitleFirst
[ nLangIndex
];
95 bTitleFirst
[ nLangIndex
] = sal_False
;
106 MergeData::~MergeData()
110 PFormEntrys
* MergeData::GetPFormEntries()
112 if( aMap
.find( rtl::OString(RTL_CONSTASCII_STRINGPARAM("HACK")) ) != aMap
.end() )
113 return aMap
[rtl::OString(RTL_CONSTASCII_STRINGPARAM("HACK"))];
117 void MergeData::Insert(PFormEntrys
* pfEntrys
)
119 aMap
.insert( PFormEntrysHashMap::value_type( rtl::OString(RTL_CONSTASCII_STRINGPARAM("HACK")) , pfEntrys
) );
122 PFormEntrys
* MergeData::GetPFObject( const rtl::OString
& rPFO
)
124 if( aMap
.find( rtl::OString(RTL_CONSTASCII_STRINGPARAM("HACK")) ) != aMap
.end() )
129 sal_Bool
MergeData::operator==( ResData
*pData
)
131 return pData
->sId
== sLID
&& pData
->sGId
== sGID
132 && pData
->sResTyp
.equalsIgnoreAsciiCase(sTyp
);
136 // class MergeDataFile
139 #define FFORMAT_UNKNOWN 0x0000
140 #define FFORMAT_NEW 0x0001
141 #define FFORMAT_OLD 0x0002
144 MergeDataFile::MergeDataFile(
145 const rtl::OString
&rFileName
,
146 const rtl::OString
&rFile
,
149 : bErrorLog( bErrLog
)
151 std::ifstream
aInputStream(rFileName
.getStr());
152 const ::rtl::OString
sHACK(RTL_CONSTASCII_STRINGPARAM("HACK"));
153 const ::rtl::OString
sFileNormalized(lcl_NormalizeFilename(rFile
));
154 const bool isFileEmpty
= !sFileNormalized
.isEmpty();
156 if (!aInputStream
.is_open())
158 printf("Warning : Can't open %s\n", rFileName
.getStr());
162 while (!aInputStream
.eof())
165 std::getline(aInputStream
, buf
);
166 rtl::OString
sLine(buf
.data(), buf
.length());
168 // Skip all wrong filenames
169 const ::rtl::OString filename
= lcl_NormalizeFilename(sLine
.getToken(1, '\t', n
)); // token 1
170 if(isFileEmpty
|| sFileNormalized
.equals("") || (!isFileEmpty
&& filename
.equals(sFileNormalized
)) )
172 const rtl::OString sTYP
= sLine
.getToken( 1, '\t', n
); // token 3
173 const rtl::OString sGID
= sLine
.getToken( 0, '\t', n
); // token 4
174 const rtl::OString sLID
= sLine
.getToken( 0, '\t', n
); // token 5
175 rtl::OString sPFO
= sLine
.getToken( 1, '\t', n
); // token 7
177 rtl::OString nLANG
= sLine
.getToken( 1, '\t', n
); // token 9
178 nLANG
= nLANG
.trim();
179 const rtl::OString sTEXT
= sLine
.getToken( 0, '\t', n
); // token 10
180 const rtl::OString sQHTEXT
= sLine
.getToken( 1, '\t', n
); // token 12
181 const rtl::OString sTITLE
= sLine
.getToken( 0, '\t', n
); // token 13
182 const rtl::OString
sSDF(buf
.data(),buf
.length());
184 if (!nLANG
.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("en-US")))
186 aLanguageSet
.insert(nLANG
);
187 InsertEntry( sTYP
, sGID
, sLID
, sPFO
, nLANG
, sTEXT
, sQHTEXT
, sTITLE
, filename
, bCaseSensitive
, sSDF
, ++nLine
);
191 aInputStream
.close();
194 MergeDataFile::~MergeDataFile()
196 for (MergeDataHashMap::iterator aI
= aMap
.begin(), aEnd
= aMap
.end(); aI
!= aEnd
; ++aI
)
200 std::vector
<rtl::OString
> MergeDataFile::GetLanguages()
202 return std::vector
<rtl::OString
>(aLanguageSet
.begin(),aLanguageSet
.end());
205 MergeData
*MergeDataFile::GetMergeData( ResData
*pResData
, bool bCaseSensitive
)
207 rtl::OString sOldG
= pResData
->sGId
;
208 rtl::OString sOldL
= pResData
->sId
;
209 rtl::OString sGID
= pResData
->sGId
;
212 sGID
= pResData
->sId
;
214 sLID
= pResData
->sId
;
215 pResData
->sGId
= sGID
;
216 pResData
->sId
= sLID
;
218 rtl::OString sKey
= CreateKey( pResData
->sResTyp
, pResData
->sGId
, pResData
->sId
, pResData
->sFilename
, bCaseSensitive
);
220 if(aMap
.find( sKey
) != aMap
.end())
222 pResData
->sGId
= sOldG
;
223 pResData
->sId
= sOldL
;
226 pResData
->sGId
= sOldG
;
227 pResData
->sId
= sOldL
;
232 PFormEntrys
*MergeDataFile::GetPFormEntrys( ResData
*pResData
)
234 // search for requested PFormEntrys
235 MergeData
*pData
= GetMergeData( pResData
);
237 return pData
->GetPFormEntries();
241 PFormEntrys
*MergeDataFile::GetPFormEntrysCaseSensitive( ResData
*pResData
)
243 // search for requested PFormEntrys
244 MergeData
*pData
= GetMergeData( pResData
, true );
246 return pData
->GetPFormEntries();
250 void MergeDataFile::InsertEntry(
251 const rtl::OString
&rTYP
, const rtl::OString
&rGID
,
252 const rtl::OString
&rLID
, const rtl::OString
&rPFO
,
253 const rtl::OString
&nLANG
, const rtl::OString
&rTEXT
,
254 const rtl::OString
&rQHTEXT
, const rtl::OString
&rTITLE
,
255 const rtl::OString
&rInFilename
, bool bCaseSensitive
,
256 const rtl::OString
&rSDFLine
, const std::size_t nLine
261 // search for MergeData
262 rtl::OString sKey
= CreateKey(rTYP
, rGID
, rLID
, rInFilename
, bCaseSensitive
);
263 MergeDataHashMap::const_iterator mit
;
264 mit
= aMap
.find( sKey
);
265 if( mit
!= aMap
.end() )
271 pData
= new MergeData( rTYP
, rGID
, rLID
, rInFilename
);
272 aMap
.insert( MergeDataHashMap::value_type( sKey
, pData
) );
275 PFormEntrys
*pFEntrys
= 0;
277 // search for PFormEntrys
278 pFEntrys
= pData
->GetPFObject( rPFO
);
281 // create new PFormEntrys, cause no one exists with current properties
282 pFEntrys
= new PFormEntrys( rPFO
);
283 pData
->Insert( pFEntrys
);
286 // finaly insert the cur string
287 pFEntrys
->InsertEntry( nLANG
, rTEXT
, rQHTEXT
, rTITLE
, rSDFLine
, nLine
);
290 rtl::OString
MergeDataFile::CreateKey(const rtl::OString
& rTYP
, const rtl::OString
& rGID
,
291 const rtl::OString
& rLID
, const rtl::OString
& rFilename
, bool bCaseSensitive
)
293 static const ::rtl::OString
sStroke('-');
294 ::rtl::OString
sKey( rTYP
);
300 sKey
+= lcl_NormalizeFilename(rFilename
);
301 OSL_TRACE("created key: %s", sKey
.getStr());
303 return sKey
; // officecfg case sensitive identifier
304 return sKey
.toAsciiUpperCase();
307 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */