1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: helpmerge.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_transex3.hxx"
33 #include <tools/fsys.hxx>
34 #include <osl/file.hxx>
38 #include "helpmerge.hxx"
39 #include "utf8conv.hxx"
41 #include <sys/types.h>
46 #include "rtl/strbuf.hxx"
49 //#include <WinBase.h>
50 #include "tools/prewin.h"
52 #include "tools/postwin.h"
55 /*****************************************************************************/
56 void HelpParser::FillInFallbacks( LangHashMap
& rElem_out
, ByteString sLangIdx_in
){
57 /*****************************************************************************/
58 static const ByteString
ENGLISH_LANGUAGECODE( "en-US" );
59 static const ByteString
GERMAN_LANGUAGECODE ( "de" );
61 XMLElement
* pTmp
= NULL
;
62 XMLElement
* pTmp2
= NULL
;
65 ByteString
sFallback( sCur
);
66 GetIsoFallback( sFallback
);
67 if( (rElem_out
.find( sFallback
) != rElem_out
.end()) && rElem_out
[ sFallback
] != NULL
){
68 pTmp2
= rElem_out
[ sFallback
];
69 pTmp
= new XMLElement( *pTmp2
) ; // Copy
70 pTmp
->SetPos( pTmp2
->GetPos()+1 );
71 pTmp
->ChangeLanguageTag( String( sLangIdx_in
, RTL_TEXTENCODING_ASCII_US
) );
72 rElem_out
[ sLangIdx_in
] = pTmp
;
75 else if( (rElem_out
.find( ENGLISH_LANGUAGECODE
) != rElem_out
.end()) && rElem_out
[ ENGLISH_LANGUAGECODE
] != NULL
){// No English
76 pTmp2
= rElem_out
[ ENGLISH_LANGUAGECODE
];
77 pTmp
= new XMLElement( *pTmp2
) ; // Copy
78 pTmp
->SetPos( pTmp2
->GetPos()+1 );
79 pTmp
->ChangeLanguageTag( String( sLangIdx_in
, RTL_TEXTENCODING_ASCII_US
) );
80 rElem_out
[ sCur
] = pTmp
;
83 else if( (rElem_out
.find( GERMAN_LANGUAGECODE
) != rElem_out
.end() ) && rElem_out
[ GERMAN_LANGUAGECODE
] != NULL
){// No English
84 pTmp2
= rElem_out
[ GERMAN_LANGUAGECODE
];
85 pTmp
= new XMLElement( *pTmp2
); // Copy
86 pTmp
->SetPos( pTmp2
->GetPos()+1 );
87 pTmp
->ChangeLanguageTag( String( sLangIdx_in
, RTL_TEXTENCODING_ASCII_US
) );
88 rElem_out
[ sCur
] = pTmp
;
91 fprintf(stdout
,"ERROR: No Fallback found for language %s:\n",sCur
.GetBuffer());
92 rElem_out
[ sCur
]=new XMLElement(); // Use dummy element
96 /*****************************************************************************/
97 void HelpParser::Dump(XMLHashMap
* rElem_in
) {
98 /*****************************************************************************/
99 for(XMLHashMap::iterator pos
= rElem_in
->begin();pos
!= rElem_in
->end(); ++pos
){
100 Dump(pos
->second
,pos
->first
);
103 /*****************************************************************************/
104 void HelpParser::Dump(LangHashMap
* rElem_in
,const ByteString sKey_in
) {
105 /*****************************************************************************/
108 fprintf(stdout
,"+------------%s-----------+\n",sKey_in
.GetBuffer() );
109 for(LangHashMap::iterator posn
=rElem_in
->begin();posn
!=rElem_in
->end();++posn
){
111 y
=posn
->second
->ToOString();
112 fprintf(stdout
,"key=%s value=%s\n",x
.GetBuffer(),y
.getStr());
114 fprintf(stdout
,"+--------------------------+\n");
117 HelpParser::HelpParser( const ByteString
&rHelpFile
, bool rUTF8
, bool rHasInputList
)
118 : sHelpFile( rHelpFile
),
120 bHasInputList( rHasInputList
)
123 /*****************************************************************************/
124 bool HelpParser::CreateSDF(
125 /*****************************************************************************/
126 const ByteString
&rSDFFile_in
, const ByteString
&rPrj_in
,const ByteString
&rRoot_in
,
127 const ByteString
&sHelpFile
, XMLFile
*pXmlFile
, const ByteString
&rGsi1
){
128 // GSI File constants
129 static const String
GSI_SEQUENCE1( String::CreateFromAscii("\t0\t") );
130 static const String
GSI_SEQUENCE2( String::CreateFromAscii("\t\t\t0\t") );
131 static const String
GSI_TAB ( String::CreateFromAscii("\t") );
132 static const String
GSI_SEQUENCE4( String::CreateFromAscii("\t\t\t\t") );
133 static const String
ret ( String::CreateFromAscii("\n") );
134 static const String
ret_char ( String::CreateFromAscii("") );
135 static const String
tab ( String::CreateFromAscii("\t") );
136 static const String
tab_char ( String::CreateFromAscii("") );
138 SimpleXMLParser aParser
;
139 String sUsedTempFile
;
142 if( Export::fileHasUTF8ByteOrderMarker( sHelpFile
) ){
143 DirEntry aTempFile
= Export::GetTempFile();
144 DirEntry
aSourceFile( String( sHelpFile
, RTL_TEXTENCODING_ASCII_US
) );
145 aSourceFile
.CopyTo( aTempFile
, FSYS_ACTION_COPYFILE
);
146 String sTempFile
= aTempFile
.GetFull();
147 Export::RemoveUTF8ByteOrderMarkerFromFile( ByteString( sTempFile
, RTL_TEXTENCODING_ASCII_US
) );
148 sUsedTempFile
= sTempFile
;
149 sXmlFile
= sTempFile
;
151 sUsedTempFile
= String::CreateFromAscii("");
152 sXmlFile
= String( sHelpFile
, RTL_TEXTENCODING_ASCII_US
);
155 // ByteString fullFilePath;
156 //DirEntry aFile( sXmlFile );
157 //makeAbsolutePath( sHelpFile , rRoot_in);
158 ByteString fullFilePath
= rPrj_in
;
159 fullFilePath
.Append( "\\" );
160 fullFilePath
.Append( makeAbsolutePath( sHelpFile
, rRoot_in
) );
161 fullFilePath
.SearchAndReplaceAll( "\\", "/" );
163 String
strFullPath( fullFilePath
.GetBuffer() , RTL_TEXTENCODING_ASCII_US
);
165 //printf( "%s\n", fullFilePath.GetBuffer() );
166 std::auto_ptr
<XMLFile
> file ( aParser
.Execute( strFullPath
, sXmlFile
, pXmlFile
) );
168 if(file
.get() == NULL
){
169 printf("%s\n",ByteString(aParser
.GetError().sMessage
,RTL_TEXTENCODING_ASCII_US
).GetBuffer());
174 if( !file
->CheckExportStatus() ){
177 SvFileStream
aSDFStream( String( rSDFFile_in
, RTL_TEXTENCODING_ASCII_US
),
178 STREAM_STD_WRITE
| STREAM_TRUNC
);
180 if ( !aSDFStream
.IsOpen()) {
181 fprintf(stdout
,"Can't open file %s\n",rSDFFile_in
.GetBuffer());
185 ByteString sActFileName
= makeAbsolutePath( sHelpFile
, rRoot_in
);
187 /* DirEntry aEntry( String( sHelpFile, RTL_TEXTENCODING_ASCII_US ));
189 String sFullEntry = aEntry.GetFull();
190 aEntry += DirEntry( String( "..", RTL_TEXTENCODING_ASCII_US ));
191 aEntry += DirEntry( rRoot_in );
192 ByteString sPrjEntry( aEntry.GetFull(), gsl_getSystemTextEncoding());
193 ByteString sActFileName(
194 sFullEntry.Copy( sPrjEntry.Len() + 1 ), gsl_getSystemTextEncoding());
196 sActFileName.SearchAndReplaceAll( "/", "\\" );
198 XMLHashMap
* aXMLStrHM
= file
->GetStrings();
200 XMLElement
* pXMLElement
= NULL
;
204 ByteString
sTimeStamp( Export::GetTimeStamp() );
205 OUString
sOUTimeStamp( sTimeStamp
.GetBuffer() , sTimeStamp
.Len() , RTL_TEXTENCODING_ASCII_US
);
207 OUStringBuffer sBuffer
;
208 const OUString
sOUPrj( rPrj_in
.GetBuffer() , rPrj_in
.Len() , RTL_TEXTENCODING_ASCII_US
);
209 const OUString
sOUActFileName(sActFileName
.GetBuffer() , sActFileName
.Len() , RTL_TEXTENCODING_ASCII_US
);
210 const OUString
sOUGsi1( rGsi1
.GetBuffer() , rGsi1
.Len() , RTL_TEXTENCODING_ASCII_US
);
212 Export::InitLanguages( false );
213 std::vector
<ByteString
> aLanguages
= Export::GetLanguages();
215 std::vector
<ByteString
> order
= file
->getOrder();
216 std::vector
<ByteString
>::iterator pos
;
217 XMLHashMap::iterator posm
;
219 for( pos
= order
.begin(); pos
!= order
.end() ; ++pos
)
221 posm
= aXMLStrHM
->find( *pos
);
222 pElem
= posm
->second
;
225 for( unsigned int n
= 0; n
< aLanguages
.size(); n
++ )
227 sCur
= aLanguages
[ n
];
228 if(pElem
->find( sCur
)==pElem
->end())
230 FillInFallbacks( *pElem
, sCur
);
232 pXMLElement
= (*pElem
)[ sCur
];
234 if( pXMLElement
!= NULL
)
236 OUString data
= pXMLElement
->ToOUString();
237 String sTmp
= String(data
.getStr());
238 sTmp
.SearchAndReplaceAll(ret
,ret_char
); // Remove \n
239 sTmp
.SearchAndReplaceAll(tab
,tab_char
); // Remove \t
241 data
= OUString( sTmp
);
242 sBuffer
.append( sOUPrj
);
243 sBuffer
.append( GSI_TAB
); //"\t";
245 sBuffer
.append( sOUActFileName
);
246 sBuffer
.append( GSI_SEQUENCE1
); //"\t0\t";
247 sBuffer
.append( sOUGsi1
); //"help";
248 sBuffer
.append( GSI_TAB
); //"\t";
249 ByteString sID
= posm
->first
; // ID
250 sBuffer
.append( OUString( sID
.GetBuffer() , sID
.Len() , RTL_TEXTENCODING_UTF8
) );
251 sBuffer
.append( GSI_TAB
); //"\t";
252 ByteString sOldRef
= pXMLElement
->GetOldref(); // oldref
253 sBuffer
.append( OUString(sOldRef
.GetBuffer() , sOldRef
.Len() , RTL_TEXTENCODING_UTF8
) );
254 sBuffer
.append( GSI_SEQUENCE2
); //"\t\t\t0\t";
255 sBuffer
.append( OUString( sCur
.GetBuffer() , sCur
.Len() , RTL_TEXTENCODING_UTF8
) );
256 sBuffer
.append( GSI_TAB
); //"\t";
257 sBuffer
.append( data
);
258 sBuffer
.append( GSI_SEQUENCE4
); //"\t\t\t\t";
259 sBuffer
.append( sOUTimeStamp
);
260 ByteString
sOut( sBuffer
.makeStringAndClear().getStr() , RTL_TEXTENCODING_UTF8
);
261 //if( !sCur.EqualsIgnoreCaseAscii("de") ||( sCur.EqualsIgnoreCaseAscii("de") && !Export::isMergingGermanAllowed( rPrj_in ) ) )
263 if( data
.getLength() > 0 ) aSDFStream
.WriteLine( sOut
);
266 }else fprintf(stdout
,"\nDBG: NullPointer in HelpParser::CreateSDF , Language %s\n",sCur
.GetBuffer() );
273 if( !sUsedTempFile
.EqualsIgnoreCaseAscii( "" ) ){
274 DirEntry
aTempFile( sUsedTempFile
);
280 ByteString
HelpParser::makeAbsolutePath( const ByteString
& sHelpFile
, const ByteString
& rRoot_in
)
282 DirEntry
aEntry( String( sHelpFile
, RTL_TEXTENCODING_ASCII_US
));
284 String sFullEntry
= aEntry
.GetFull();
285 aEntry
+= DirEntry( String( "..", RTL_TEXTENCODING_ASCII_US
));
286 aEntry
+= DirEntry( rRoot_in
);
287 ByteString
sPrjEntry( aEntry
.GetFull(), gsl_getSystemTextEncoding());
288 ByteString
sActFileName(
289 sFullEntry
.Copy( sPrjEntry
.Len() + 1 ), gsl_getSystemTextEncoding());
291 sActFileName
.SearchAndReplaceAll( "/", "\\" );
294 bool HelpParser::Merge( const ByteString
&rSDFFile
, const ByteString
&rDestinationFile
,
295 ByteString
& sLanguage
, MergeDataFile
& aMergeDataFile
)
299 bool hasNoError
= true;
301 SimpleXMLParser aParser
;
303 String sUsedTempFile
;
306 if( Export::fileHasUTF8ByteOrderMarker( sHelpFile
) ){
307 DirEntry aTempFile
= Export::GetTempFile();
308 DirEntry
aSourceFile( String( sHelpFile
, RTL_TEXTENCODING_ASCII_US
) );
309 aSourceFile
.CopyTo( aTempFile
, FSYS_ACTION_COPYFILE
);
310 String sTempFile
= aTempFile
.GetFull();
311 Export::RemoveUTF8ByteOrderMarkerFromFile( ByteString( sTempFile
, RTL_TEXTENCODING_ASCII_US
) );
312 sUsedTempFile
= sTempFile
;
313 sXmlFile
= sTempFile
;
315 sUsedTempFile
= String::CreateFromAscii("");
316 sXmlFile
= String( sHelpFile
, RTL_TEXTENCODING_ASCII_US
);
319 OUString
sOUHelpFile( sXmlFile
);
321 DirEntry
aFile( sXmlFile
);
323 XMLFile
* xmlfile
= ( aParser
.Execute( aFile
.GetFull() , sOUHelpFile
, new XMLFile( '0' ) ) );
324 printf("Dest file %s\n",rDestinationFile
.GetBuffer());
325 hasNoError
= MergeSingleFile( xmlfile
, aMergeDataFile
, sLanguage
, rDestinationFile
);
327 if( !sUsedTempFile
.EqualsIgnoreCaseAscii( "" ) ){
328 DirEntry
aTempFile( sUsedTempFile
);
334 bool ByteStringEqual( const ByteString
& rKey1
, const ByteString
& rKey2
) {
335 return rKey1
.CompareTo( rKey2
)==COMPARE_EQUAL
;
337 bool ByteStringLess( const ByteString
& rKey1
, const ByteString
& rKey2
) {
338 return rKey1
.CompareTo( rKey2
)==COMPARE_LESS
;
341 void HelpParser::parse_languages( std::vector
<ByteString
>& aLanguages
, MergeDataFile
& aMergeDataFile
){
342 std::vector
<ByteString
> aTmp
;
344 const ByteString
DE ("de");
345 const ByteString
ENUS ("en-US");
346 static const ByteString
ALL( "ALL" );
348 Export::InitLanguages( false );
350 if( Export::sLanguages
.EqualsIgnoreCaseAscii( ALL
) )
352 aLanguages
= aMergeDataFile
.GetLanguages();
353 aLanguages
.push_back( DE
);
354 aLanguages
.push_back( ENUS
);
356 if( !Export::sForcedLanguages
.Equals("") )
358 std::vector
<ByteString
> aFL
= Export::GetForcedLanguages();
359 std::copy( aFL
.begin() ,
361 back_inserter( aLanguages
)
363 std::sort( aLanguages
.begin() , aLanguages
.end() , ByteStringLess
);
364 std::vector
<ByteString
>::iterator unique_iter
= std::unique( aLanguages
.begin() , aLanguages
.end() , ByteStringEqual
);
365 std::copy( aLanguages
.begin() , unique_iter
, back_inserter( aTmp
) );
370 aLanguages
= Export::GetLanguages();
375 bool HelpParser::Merge(
376 const ByteString
&rSDFFile
, const ByteString
&rPathX
, const ByteString
&rPathY
, bool bISO
,
377 const std::vector
<ByteString
>& aLanguages
, MergeDataFile
& aMergeDataFile
, bool bCreateDir
)
382 bool hasNoError
= true;
383 SimpleXMLParser aParser
;
384 String sUsedTempFile
;
387 if( Export::fileHasUTF8ByteOrderMarker( sHelpFile
) )
389 DirEntry aTempFile
= Export::GetTempFile();
390 DirEntry
aSourceFile( String( sHelpFile
, RTL_TEXTENCODING_ASCII_US
) );
391 aSourceFile
.CopyTo( aTempFile
, FSYS_ACTION_COPYFILE
);
392 String sTempFile
= aTempFile
.GetFull();
393 Export::RemoveUTF8ByteOrderMarkerFromFile( ByteString( sTempFile
, RTL_TEXTENCODING_ASCII_US
) );
394 sUsedTempFile
= sTempFile
;
395 sXmlFile
= sTempFile
;
399 sUsedTempFile
= String::CreateFromAscii("");
400 sXmlFile
= String( sHelpFile
, RTL_TEXTENCODING_ASCII_US
);
404 OUString
sOUHelpFile( sXmlFile
);
406 DirEntry
aFile( sXmlFile
);
408 XMLFile
* xmlfile
= ( aParser
.Execute( aFile
.GetFull() , sOUHelpFile
, new XMLFile( '0' ) ) );
413 printf("%s\n",ByteString(aParser
.GetError().sMessage
,RTL_TEXTENCODING_UTF8
).GetBuffer());
420 for( unsigned int n
= 0; n
< aLanguages
.size(); n
++ ){
421 sCur
= aLanguages
[ n
];
423 ByteString sFilepath
;
424 if( bISO
) sFilepath
= GetOutpath( rPathX
, sCur
, rPathY
);
425 else sFilepath
= rPathX
;
426 if( bCreateDir
) MakeDir( sFilepath
);
428 XMLFile
* file
= new XMLFile( *xmlfile
);
429 sFilepath
.Append( sHelpFile
);
430 hasNoError
= MergeSingleFile( file
, aMergeDataFile
, sCur
, sFilepath
);
433 if( !hasNoError
) return false; // Stop on error
436 if( !sUsedTempFile
.EqualsIgnoreCaseAscii( "" ) )
438 DirEntry
aTempFile( sUsedTempFile
);
445 bool HelpParser::MergeSingleFile( XMLFile
* file
, MergeDataFile
& aMergeDataFile
, const ByteString
& sLanguage
,
450 XMLHashMap
* aXMLStrHM
= file
->GetStrings();
451 LangHashMap
* aLangHM
;
452 static ResData
pResData( "","","");
453 pResData
.sResTyp
= "help";
455 ByteString sTmp
= Export::sLanguages
;
457 sTmp
.EraseLeadingAndTrailingChars();
459 for(XMLHashMap::iterator pos
=aXMLStrHM
->begin();pos
!=aXMLStrHM
->end();++pos
) // Merge every l10n related string
462 aLangHM
= pos
->second
;
463 //printf("*********************DUMPING HASHMAP***************************************");
465 //printf("DBG: sHelpFile = %s\n",sHelpFile.GetBuffer() );
467 pResData
.sGId
= pos
->first
;
468 pResData
.sFilename
= sHelpFile
;
470 ProcessHelp( aLangHM
, sLanguage
, &pResData
, aMergeDataFile
);
474 // Init temp and target file
475 ByteString sTempFile
;
476 ByteString
sTargetFile( sPath
);
477 ByteString sTempFileCopy
;
479 static const ByteString INPATH
= Export::GetEnv( "INPATH" );
480 Export::getRandomName( sPath
, sTempFile
, INPATH
);
481 Export::getRandomName( sPath
, sTempFileCopy
, INPATH
);
482 // Write in the temp file
483 bool hasNoError
= file
->Write ( sTempFile
);
486 cerr
<< "ERROR: file->Write failed\n";
490 DirEntry
aTmp( sTempFile
);
491 DirEntry
aTmp2( sTempFileCopy
);
492 DirEntry
aTar( sTargetFile
);
494 if( !Export::CopyFile( sTempFile
, sTempFileCopy
) )
496 #if defined(UNX) || defined(OS2)
501 if( !Export::CopyFile( sTempFile
, sTempFileCopy
) )
503 cerr
<< "ERROR: Can not copy file from " << sTempFile
.GetBuffer() << " to " << sTempFileCopy
.GetBuffer() << "\n";
507 //remove( sTargetFile.GetBuffer() );
509 FileStat
aFSTest( aTar
);
510 if( aFSTest
.GetSize() < 1 )
512 remove( sTargetFile
.GetBuffer() );
515 #if defined(UNX) || defined(OS2)
516 rc
= rename( sTempFile
.GetBuffer() , sTargetFile
.GetBuffer() );
518 rc
= MoveFileEx( sTempFile
.GetBuffer() , sTargetFile
.GetBuffer(), MOVEFILE_REPLACE_EXISTING
);
520 FileStat
aFS( aTar
);
522 //cout << "mv " << sTempFile.GetBuffer() << " " << sTargetFile.GetBuffer() << "\n";
523 //cout << "rc -> " << rc << " filesize -> " << aFS.GetSize() << "\n";
524 // Windows rename returns -1 if the file already exits
526 if( rc
< 0 || aFS
.GetSize() < 1 )
528 // if( aFS.GetSize() < 1 )
531 #if defined(UNX) || defined(OS2)
536 aFSTest
.Update( aTar
);
537 if( aFSTest
.GetSize() < 1 )
539 remove( sTargetFile
.GetBuffer() );
541 #if defined(UNX) || defined(OS2)
542 rc
= rename( sTempFileCopy
.GetBuffer() , sTargetFile
.GetBuffer() );
544 rc
= MoveFileEx( sTempFileCopy
.GetBuffer() , sTargetFile
.GetBuffer() , MOVEFILE_REPLACE_EXISTING
);
548 //cout << "mv2 " << sTempFileCopy.GetBuffer() << " " << sTargetFile.GetBuffer() << "\n";
549 //cout << "rc -> " << rc << " filesize -> " << aFS.GetSize() << "\n";
551 // Windows rename returns -1 if the file already exits
553 // if( aFS.GetSize() < 1 )
555 if( rc
< 0 || aFS
.GetSize() < 1 )
558 cerr
<< "ERROR: helpex Can't rename file " << sTempFileCopy
.GetBuffer() << " to " << sTargetFile
.GetBuffer() << " rename rc=" << rc
<< " filesize=" << aFS
.GetSize() << "\n";
561 if( aFS
.GetSize() < 1 )
572 ByteString
HelpParser::GetOutpath( const ByteString
& rPathX
, const ByteString
& sCur
, const ByteString
& rPathY
){
573 ByteString testpath
= rPathX
;
574 static const ByteString
sDelimiter( DirEntry::GetAccessDelimiter(), RTL_TEXTENCODING_ASCII_US
);
575 testpath
.EraseTrailingChars( '/' );
576 testpath
.EraseTrailingChars( '\\' );
577 testpath
+= sDelimiter
;
579 testpath
+= sDelimiter
;
580 ByteString
sRelativePath( rPathY
);
581 sRelativePath
.EraseLeadingChars( '/' );
582 sRelativePath
.EraseLeadingChars( '\\' );
583 testpath
+= sRelativePath
;
584 testpath
+= sDelimiter
;
587 void HelpParser::MakeDir( const ByteString
& sPath
){
588 ByteString
sTPath( sPath
);
589 ByteString
sDelimiter( DirEntry::GetAccessDelimiter(), RTL_TEXTENCODING_ASCII_US
);
590 sTPath
.SearchAndReplaceAll( sDelimiter
, '/' );
591 USHORT cnt
= sTPath
.GetTokenCount( '/' );
592 ByteString sCreateDir
;
593 for( USHORT i
= 0 ; i
< cnt
; i
++ )
595 sCreateDir
+= sTPath
.GetToken( i
, '/' );
596 sCreateDir
+= sDelimiter
;
598 _mkdir( sCreateDir
.GetBuffer() );
600 mkdir( sCreateDir
.GetBuffer() , S_IRWXU
| S_IRWXG
| S_IROTH
| S_IXOTH
);
606 /* ProcessHelp Methode: search for en-US entry and replace it with the current language*/
607 void HelpParser::ProcessHelp( LangHashMap
* aLangHM
, const ByteString
& sCur
, ResData
*pResData
, MergeDataFile
& aMergeDataFile
){
609 XMLElement
* pXMLElement
= NULL
;
610 PFormEntrys
*pEntrys
= NULL
;
611 XMLData
*data
= NULL
;
612 XMLParentNode
*parent
= NULL
;
620 #ifdef MERGE_SOURCE_LANGUAGES
621 if( true ){ // Merge en-US!
623 if( !sCur
.EqualsIgnoreCaseAscii("en-US") ){
625 pXMLElement
= (*aLangHM
)[ "en-US" ];
626 if( pXMLElement
== NULL
)
628 printf("Error: Can't find en-US entry\n");
630 if( pXMLElement
!= NULL
)
632 parent
= pXMLElement
->GetParent();
633 sLId
= pXMLElement
->GetOldref();
634 pResData
->sId
= sLId
;
636 pEntrys
= aMergeDataFile
.GetPFormEntrys( pResData
);
640 pEntrys
->GetText( sNewText
, STRING_TYP_TEXT
, sCur
, true );
641 sNewdata
= String( sNewText
, RTL_TEXTENCODING_UTF8
);
644 if( pXMLElement
!= NULL
)
646 data
= new XMLData( sNewdata
, NULL
, true ); // Add new one
647 pXMLElement
->RemoveAndDeleteAllChilds();
648 pXMLElement
->AddChild( data
);
649 aLangHM
->erase( sCur
);
652 }else if( pResData
== NULL
){fprintf(stdout
,"Can't find GID=%s LID=%s TYP=%s\n",pResData
->sGId
.GetBuffer(),pResData
->sId
.GetBuffer(),pResData
->sResTyp
.GetBuffer());}
653 pXMLElement
->ChangeLanguageTag( String( sCur
, RTL_TEXTENCODING_ASCII_US
) );
658 /* Process() Method merges */
659 void HelpParser::Process( LangHashMap
* aLangHM
, const ByteString
& sCur
, ResData
*pResData
, MergeDataFile
& aMergeDataFile
){
661 XMLElement
* pXMLElement
= NULL
;
662 PFormEntrys
*pEntrys
= NULL
;
663 XMLData
*data
= NULL
;
664 XMLParentNode
*parent
= NULL
;
665 XMLDefault
*xmldefault
= NULL
;
669 bool isFallback
= false;
675 #ifdef MERGE_SOURCE_LANGUAGES
676 if( true ){ // Merge en-US!
678 if( !sCur
.EqualsIgnoreCaseAscii("en-US") ){
680 pXMLElement
= (*aLangHM
)[ sCur
];
681 if( pXMLElement
== NULL
)
683 FillInFallbacks( *aLangHM
, sCur
);
684 pXMLElement
= ( *aLangHM
)[ sCur
];
687 if( pXMLElement
!= NULL
)
689 parent
= pXMLElement
->GetParent();
690 sLId
= pXMLElement
->GetOldref();
691 pResData
->sId
= sLId
;
693 pEntrys
= aMergeDataFile
.GetPFormEntrys( pResData
);
697 pEntrys
->GetText( sNewText
, STRING_TYP_TEXT
, sCur
, true );
698 sNewdata
= String( sNewText
, RTL_TEXTENCODING_UTF8
);
701 printf("Entries found\n");
702 if( pXMLElement
!= NULL
)
704 data
= new XMLData( sNewdata
, NULL
, true ); // Add new one
705 if( pXMLElement
->ToOUString().compareTo( OUString(data
->GetData()) ) != 0 )
707 pXMLElement
->RemoveAndDeleteAllChilds();
708 pXMLElement
->AddChild( data
);
712 xmldefault
= new XMLDefault( String::CreateFromAscii("\n") , NULL
);
713 int pos
= parent
->GetPosition( pXMLElement
->GetId() );
715 parent
->AddChild(xmldefault
, pos
+1 );
716 parent
->AddChild(pXMLElement
, pos
+2 );
718 else fprintf(stdout
,"ERROR: Can't find reference Element of id %s language %d\n",pXMLElement
->GetId().GetBuffer(),curLang
);
721 aLangHM
->erase( sCur
);
725 }else if( pResData
== NULL
){fprintf(stdout
,"Can't find GID=%s LID=%s TYP=%s\n",pResData
->sGId
.GetBuffer(),pResData
->sId
.GetBuffer(),pResData
->sResTyp
.GetBuffer());}