1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_l10ntools.hxx" 26 #include <tools/fsys.hxx> 27 #include <osl/file.hxx> 28 // local includes 29 #include <stdio.h> 30 #include <stdlib.h> 31 #include "helpmerge.hxx" 32 #include "utf8conv.hxx" 33 #include <algorithm> 34 #include <sys/types.h> 35 #include <sys/stat.h> 36 #include <iostream> 37 #include <fstream> 38 #include <vector> 39 #include "rtl/strbuf.hxx" 40 #ifdef WNT 41 #include <direct.h> 42 //#include <WinBase.h> 43 #include "tools/prewin.h" 44 #include <windows.h> 45 #include "tools/postwin.h" 46 #endif 47 48 /*****************************************************************************/ 49 void HelpParser::FillInFallbacks( LangHashMap& rElem_out, ByteString sLangIdx_in ){ 50 /*****************************************************************************/ 51 static const ByteString ENGLISH_LANGUAGECODE( "en-US" ); 52 static const ByteString GERMAN_LANGUAGECODE ( "de" ); 53 ByteString sCur; 54 XMLElement* pTmp = NULL; 55 XMLElement* pTmp2 = NULL; 56 57 sCur = sLangIdx_in; 58 ByteString sFallback( sCur ); 59 GetIsoFallback( sFallback ); 60 if( (rElem_out.find( sFallback ) != rElem_out.end()) && rElem_out[ sFallback ] != NULL ){ 61 pTmp2 = rElem_out[ sFallback ]; 62 pTmp = new XMLElement( *pTmp2 ) ; // Copy 63 pTmp->SetPos( pTmp2->GetPos()+1 ); 64 pTmp->ChangeLanguageTag( String( sLangIdx_in , RTL_TEXTENCODING_ASCII_US) ); 65 rElem_out[ sLangIdx_in ] = pTmp; 66 pTmp2 = NULL; 67 } 68 else if( (rElem_out.find( ENGLISH_LANGUAGECODE ) != rElem_out.end()) && rElem_out[ ENGLISH_LANGUAGECODE ] != NULL ){// No English 69 pTmp2 = rElem_out[ ENGLISH_LANGUAGECODE ]; 70 pTmp = new XMLElement( *pTmp2 ) ; // Copy 71 pTmp->SetPos( pTmp2->GetPos()+1 ); 72 pTmp->ChangeLanguageTag( String( sLangIdx_in , RTL_TEXTENCODING_ASCII_US) ); 73 rElem_out[ sCur ] = pTmp; 74 pTmp2 = NULL; 75 } 76 else if( (rElem_out.find( GERMAN_LANGUAGECODE ) != rElem_out.end() ) && rElem_out[ GERMAN_LANGUAGECODE ] != NULL ){// No English 77 pTmp2 = rElem_out[ GERMAN_LANGUAGECODE ]; 78 pTmp = new XMLElement( *pTmp2 ); // Copy 79 pTmp->SetPos( pTmp2->GetPos()+1 ); 80 pTmp->ChangeLanguageTag( String( sLangIdx_in , RTL_TEXTENCODING_ASCII_US ) ); 81 rElem_out[ sCur ] = pTmp; 82 pTmp2 = NULL; 83 }else{ 84 fprintf(stdout,"ERROR: No Fallback found for language %s:\n",sCur.GetBuffer()); 85 rElem_out[ sCur ]=new XMLElement(); // Use dummy element 86 } 87 } 88 89 /*****************************************************************************/ 90 void HelpParser::Dump(XMLHashMap* rElem_in) { 91 /*****************************************************************************/ 92 for(XMLHashMap::iterator pos = rElem_in->begin();pos != rElem_in->end(); ++pos){ 93 Dump(pos->second,pos->first); 94 } 95 } 96 /*****************************************************************************/ 97 void HelpParser::Dump(LangHashMap* rElem_in,const ByteString sKey_in) { 98 /*****************************************************************************/ 99 ByteString x; 100 OString y; 101 fprintf(stdout,"+------------%s-----------+\n",sKey_in.GetBuffer() ); 102 for(LangHashMap::iterator posn=rElem_in->begin();posn!=rElem_in->end();++posn){ 103 x=posn->first; 104 y=posn->second->ToOString(); 105 fprintf(stdout,"key=%s value=%s\n",x.GetBuffer(),y.getStr()); 106 } 107 fprintf(stdout,"+--------------------------+\n"); 108 } 109 110 HelpParser::HelpParser( const ByteString &rHelpFile, bool rUTF8 , bool rHasInputList ) 111 : sHelpFile( rHelpFile ), 112 bUTF8 ( rUTF8 ), 113 bHasInputList( rHasInputList ) 114 {}; 115 116 /*****************************************************************************/ 117 bool HelpParser::CreateSDF( 118 /*****************************************************************************/ 119 const ByteString &rSDFFile_in, const ByteString &rPrj_in,const ByteString &rRoot_in, 120 const ByteString &sHelpFile, XMLFile *pXmlFile, const ByteString &rGsi1){ 121 // GSI File constants 122 static const String GSI_SEQUENCE1( String::CreateFromAscii("\t0\t") ); 123 static const String GSI_SEQUENCE2( String::CreateFromAscii("\t\t\t0\t") ); 124 static const String GSI_TAB ( String::CreateFromAscii("\t") ); 125 static const String GSI_SEQUENCE4( String::CreateFromAscii("\t\t\t\t") ); 126 static const String ret ( String::CreateFromAscii("\n") ); 127 static const String ret_char ( String::CreateFromAscii("") ); 128 static const String tab ( String::CreateFromAscii("\t") ); 129 static const String tab_char ( String::CreateFromAscii("") ); 130 131 SimpleXMLParser aParser; 132 String sUsedTempFile; 133 String sXmlFile; 134 135 if( Export::fileHasUTF8ByteOrderMarker( sHelpFile ) ){ 136 DirEntry aTempFile = Export::GetTempFile(); 137 DirEntry aSourceFile( String( sHelpFile , RTL_TEXTENCODING_ASCII_US ) ); 138 aSourceFile.CopyTo( aTempFile , FSYS_ACTION_COPYFILE ); 139 String sTempFile = aTempFile.GetFull(); 140 Export::RemoveUTF8ByteOrderMarkerFromFile( ByteString( sTempFile , RTL_TEXTENCODING_ASCII_US ) ); 141 sUsedTempFile = sTempFile; 142 sXmlFile = sTempFile; 143 }else{ 144 sUsedTempFile = String::CreateFromAscii(""); 145 sXmlFile = String( sHelpFile , RTL_TEXTENCODING_ASCII_US ); 146 } 147 148 // ByteString fullFilePath; 149 //DirEntry aFile( sXmlFile ); 150 //makeAbsolutePath( sHelpFile , rRoot_in); 151 ByteString fullFilePath = rPrj_in; 152 fullFilePath.Append( "\\" ); 153 fullFilePath.Append( makeAbsolutePath( sHelpFile , rRoot_in ) ); 154 fullFilePath.SearchAndReplaceAll( "\\", "/" ); 155 156 String strFullPath( fullFilePath.GetBuffer() , RTL_TEXTENCODING_ASCII_US ); 157 158 //printf( "%s\n", fullFilePath.GetBuffer() ); 159 std::auto_ptr <XMLFile> file ( aParser.Execute( strFullPath , sXmlFile, pXmlFile ) ); 160 161 if(file.get() == NULL){ 162 printf("%s\n",ByteString(aParser.GetError().sMessage,RTL_TEXTENCODING_ASCII_US).GetBuffer()); 163 exit(-1); 164 //return false; 165 } 166 file->Extract(); 167 if( !file->CheckExportStatus() ){ 168 return true; 169 } 170 SvFileStream aSDFStream( String( rSDFFile_in, RTL_TEXTENCODING_ASCII_US ), 171 STREAM_STD_WRITE | STREAM_TRUNC ); 172 173 if ( !aSDFStream.IsOpen()) { 174 fprintf(stdout,"Can't open file %s\n",rSDFFile_in.GetBuffer()); 175 return false; 176 } 177 178 ByteString sActFileName = makeAbsolutePath( sHelpFile , rRoot_in ); 179 180 XMLHashMap* aXMLStrHM = file->GetStrings(); 181 LangHashMap* pElem; 182 XMLElement* pXMLElement = NULL; 183 184 //Dump(aXMLStrHM); 185 186 ByteString sTimeStamp( Export::GetTimeStamp() ); 187 OUString sOUTimeStamp( sTimeStamp.GetBuffer() , sTimeStamp.Len() , RTL_TEXTENCODING_ASCII_US ); 188 189 OUStringBuffer sBuffer; 190 const OUString sOUPrj( rPrj_in.GetBuffer() , rPrj_in.Len() , RTL_TEXTENCODING_ASCII_US ); 191 const OUString sOUActFileName(sActFileName.GetBuffer() , sActFileName.Len() , RTL_TEXTENCODING_ASCII_US ); 192 const OUString sOUGsi1( rGsi1.GetBuffer() , rGsi1.Len() , RTL_TEXTENCODING_ASCII_US ); 193 194 Export::InitLanguages( false ); 195 std::vector<ByteString> aLanguages = Export::GetLanguages(); 196 197 std::vector<ByteString> order = file->getOrder(); 198 std::vector<ByteString>::iterator pos; 199 XMLHashMap::iterator posm; 200 201 for( pos = order.begin(); pos != order.end() ; ++pos ) 202 { 203 posm = aXMLStrHM->find( *pos ); 204 pElem = posm->second; 205 ByteString sCur; 206 207 for( unsigned int n = 0; n < aLanguages.size(); n++ ) 208 { 209 sCur = aLanguages[ n ]; 210 if(pElem->find( sCur )==pElem->end()) 211 { 212 FillInFallbacks( *pElem , sCur ); 213 } 214 pXMLElement = (*pElem)[ sCur ]; 215 216 if( pXMLElement != NULL ) 217 { 218 OUString data = pXMLElement->ToOUString(); 219 String sTmp = String(data.getStr()); 220 sTmp.SearchAndReplaceAll(ret,ret_char); // Remove \n 221 sTmp.SearchAndReplaceAll(tab,tab_char); // Remove \t 222 223 data = OUString( sTmp ); 224 sBuffer.append( sOUPrj ); 225 sBuffer.append( GSI_TAB ); //"\t"; 226 if ( rRoot_in.Len()) 227 sBuffer.append( sOUActFileName ); 228 sBuffer.append( GSI_SEQUENCE1 ); //"\t0\t"; 229 sBuffer.append( sOUGsi1 ); //"help"; 230 sBuffer.append( GSI_TAB ); //"\t"; 231 ByteString sID = posm->first; // ID 232 sBuffer.append( OUString( sID.GetBuffer() , sID.Len() , RTL_TEXTENCODING_UTF8 ) ); 233 sBuffer.append( GSI_TAB ); //"\t"; 234 ByteString sOldRef = pXMLElement->GetOldref(); // oldref 235 sBuffer.append( OUString(sOldRef.GetBuffer() , sOldRef.Len() , RTL_TEXTENCODING_UTF8 ) ); 236 sBuffer.append( GSI_SEQUENCE2 ); //"\t\t\t0\t"; 237 sBuffer.append( OUString( sCur.GetBuffer() , sCur.Len() , RTL_TEXTENCODING_UTF8 ) ); 238 sBuffer.append( GSI_TAB ); //"\t"; 239 sBuffer.append( data ); 240 sBuffer.append( GSI_SEQUENCE4 ); //"\t\t\t\t"; 241 sBuffer.append( sOUTimeStamp ); 242 ByteString sOut( sBuffer.makeStringAndClear().getStr() , RTL_TEXTENCODING_UTF8 ); 243 //if( !sCur.EqualsIgnoreCaseAscii("de") ||( sCur.EqualsIgnoreCaseAscii("de") && !Export::isMergingGermanAllowed( rPrj_in ) ) ) 244 //{ 245 if( data.getLength() > 0 ) aSDFStream.WriteLine( sOut ); 246 //} 247 pXMLElement=NULL; 248 }else fprintf(stdout,"\nDBG: NullPointer in HelpParser::CreateSDF , Language %s\n",sCur.GetBuffer() ); 249 } 250 251 } 252 //Dump(aXMLStrHM); 253 aSDFStream.Close(); 254 255 if( !sUsedTempFile.EqualsIgnoreCaseAscii( "" ) ){ 256 DirEntry aTempFile( sUsedTempFile ); 257 aTempFile.Kill(); 258 } 259 return sal_True; 260 } 261 262 ByteString HelpParser::makeAbsolutePath( const ByteString& sHelpFile , const ByteString& rRoot_in ) 263 { 264 DirEntry aEntry( String( sHelpFile, RTL_TEXTENCODING_ASCII_US )); 265 aEntry.ToAbs(); 266 String sFullEntry = aEntry.GetFull(); 267 aEntry += DirEntry( String( "..", RTL_TEXTENCODING_ASCII_US )); 268 aEntry += DirEntry( rRoot_in ); 269 ByteString sPrjEntry( aEntry.GetFull(), gsl_getSystemTextEncoding()); 270 ByteString sActFileName( 271 sFullEntry.Copy( sPrjEntry.Len() + 1 ), gsl_getSystemTextEncoding()); 272 273 sActFileName.SearchAndReplaceAll( "/", "\\" ); 274 return sActFileName; 275 } 276 bool HelpParser::Merge( const ByteString &rSDFFile, const ByteString &rDestinationFile , 277 ByteString& sLanguage , MergeDataFile& aMergeDataFile ) 278 { 279 280 (void) rSDFFile; 281 bool hasNoError = true; 282 283 SimpleXMLParser aParser; 284 285 String sUsedTempFile; 286 String sXmlFile; 287 288 if( Export::fileHasUTF8ByteOrderMarker( sHelpFile ) ){ 289 DirEntry aTempFile = Export::GetTempFile(); 290 DirEntry aSourceFile( String( sHelpFile , RTL_TEXTENCODING_ASCII_US ) ); 291 aSourceFile.CopyTo( aTempFile , FSYS_ACTION_COPYFILE ); 292 String sTempFile = aTempFile.GetFull(); 293 Export::RemoveUTF8ByteOrderMarkerFromFile( ByteString( sTempFile , RTL_TEXTENCODING_ASCII_US ) ); 294 sUsedTempFile = sTempFile; 295 sXmlFile = sTempFile; 296 }else{ 297 sUsedTempFile = String::CreateFromAscii(""); 298 sXmlFile = String( sHelpFile , RTL_TEXTENCODING_ASCII_US ); 299 } 300 301 OUString sOUHelpFile( sXmlFile ); 302 String fullFilePath; 303 DirEntry aFile( sXmlFile ); 304 305 XMLFile* xmlfile = ( aParser.Execute( aFile.GetFull() , sOUHelpFile, new XMLFile( '0' ) ) ); 306 printf("Dest file %s\n",rDestinationFile.GetBuffer()); 307 hasNoError = MergeSingleFile( xmlfile , aMergeDataFile , sLanguage , rDestinationFile ); 308 delete xmlfile; 309 if( !sUsedTempFile.EqualsIgnoreCaseAscii( "" ) ){ 310 DirEntry aTempFile( sUsedTempFile ); 311 aTempFile.Kill(); 312 } 313 return hasNoError; 314 } 315 316 bool ByteStringEqual( const ByteString& rKey1, const ByteString& rKey2 ) { 317 return rKey1.CompareTo( rKey2 )==COMPARE_EQUAL; 318 }; 319 bool ByteStringLess( const ByteString& rKey1, const ByteString& rKey2 ) { 320 return rKey1.CompareTo( rKey2 )==COMPARE_LESS; 321 } 322 323 void HelpParser::parse_languages( std::vector<ByteString>& aLanguages , MergeDataFile& aMergeDataFile ){ 324 std::vector<ByteString> aTmp; 325 326 const ByteString DE ("de"); 327 const ByteString ENUS ("en-US"); 328 static const ByteString ALL( "ALL" ); 329 330 Export::InitLanguages( false ); 331 332 if( Export::sLanguages.EqualsIgnoreCaseAscii( ALL ) ) 333 { 334 aLanguages = aMergeDataFile.GetLanguages(); 335 aLanguages.push_back( DE ); 336 aLanguages.push_back( ENUS ); 337 338 if( !Export::sForcedLanguages.Equals("") ) 339 { 340 std::vector<ByteString> aFL = Export::GetForcedLanguages(); 341 std::copy( aFL.begin() , 342 aFL.end() , 343 back_inserter( aLanguages ) 344 ); 345 std::sort( aLanguages.begin() , aLanguages.end() , ByteStringLess ); 346 std::vector<ByteString>::iterator unique_iter = std::unique( aLanguages.begin() , aLanguages.end() , ByteStringEqual ); 347 std::copy( aLanguages.begin() , unique_iter , back_inserter( aTmp ) ); 348 aLanguages = aTmp; 349 } 350 } 351 else{ 352 aLanguages = Export::GetLanguages(); 353 } 354 355 } 356 357 bool HelpParser::Merge( 358 const ByteString &rSDFFile, const ByteString &rPathX , const ByteString &rPathY , bool bISO , 359 const std::vector<ByteString>& aLanguages , MergeDataFile& aMergeDataFile , bool bCreateDir ) 360 { 361 362 363 (void) rSDFFile ; 364 bool hasNoError = true; 365 SimpleXMLParser aParser; 366 String sUsedTempFile; 367 String sXmlFile; 368 369 if( Export::fileHasUTF8ByteOrderMarker( sHelpFile ) ) 370 { 371 DirEntry aTempFile = Export::GetTempFile(); 372 DirEntry aSourceFile( String( sHelpFile , RTL_TEXTENCODING_ASCII_US ) ); 373 aSourceFile.CopyTo( aTempFile , FSYS_ACTION_COPYFILE ); 374 String sTempFile = aTempFile.GetFull(); 375 Export::RemoveUTF8ByteOrderMarkerFromFile( ByteString( sTempFile , RTL_TEXTENCODING_ASCII_US ) ); 376 sUsedTempFile = sTempFile; 377 sXmlFile = sTempFile; 378 } 379 else 380 { 381 sUsedTempFile = String::CreateFromAscii(""); 382 sXmlFile = String( sHelpFile , RTL_TEXTENCODING_ASCII_US ); 383 } 384 385 386 OUString sOUHelpFile( sXmlFile ); 387 String fullFilePath; 388 DirEntry aFile( sXmlFile ); 389 390 XMLFile* xmlfile = ( aParser.Execute( aFile.GetFull() , sOUHelpFile, new XMLFile( '0' ) ) ); 391 xmlfile->Extract(); 392 393 if( xmlfile == NULL) 394 { 395 printf("%s\n",ByteString(aParser.GetError().sMessage,RTL_TEXTENCODING_UTF8).GetBuffer()); 396 exit(-1); 397 //return false; 398 } 399 400 401 ByteString sCur; 402 for( unsigned int n = 0; n < aLanguages.size(); n++ ){ 403 sCur = aLanguages[ n ]; 404 405 ByteString sFilepath; 406 if( bISO ) sFilepath = GetOutpath( rPathX , sCur , rPathY ); 407 else sFilepath = rPathX; 408 if( bCreateDir ) MakeDir( sFilepath ); 409 410 XMLFile* file = new XMLFile( *xmlfile ); 411 sFilepath.Append( sHelpFile ); 412 hasNoError = MergeSingleFile( file , aMergeDataFile , sCur , sFilepath ); 413 delete file; 414 415 if( !hasNoError ) return false; // Stop on error 416 } 417 418 if( !sUsedTempFile.EqualsIgnoreCaseAscii( "" ) ) 419 { 420 DirEntry aTempFile( sUsedTempFile ); 421 aTempFile.Kill(); 422 } 423 delete xmlfile; 424 return hasNoError; 425 } 426 427 bool HelpParser::MergeSingleFile( XMLFile* file , MergeDataFile& aMergeDataFile , const ByteString& sLanguage , 428 ByteString sPath ) 429 { 430 file->Extract(); 431 432 XMLHashMap* aXMLStrHM = file->GetStrings(); 433 LangHashMap* aLangHM; 434 static ResData pResData( "","",""); 435 pResData.sResTyp = "help"; 436 437 ByteString sTmp = Export::sLanguages; 438 439 sTmp.EraseLeadingAndTrailingChars(); 440 441 for(XMLHashMap::iterator pos=aXMLStrHM->begin();pos!=aXMLStrHM->end();++pos) // Merge every l10n related string 442 { 443 444 aLangHM = pos->second; 445 //printf("*********************DUMPING HASHMAP***************************************"); 446 //Dump( aXMLStrHM ); 447 //printf("DBG: sHelpFile = %s\n",sHelpFile.GetBuffer() ); 448 449 pResData.sGId = pos->first; 450 pResData.sFilename = sHelpFile; 451 452 ProcessHelp( aLangHM , sLanguage, &pResData , aMergeDataFile ); 453 } 454 455 456 // Init temp and target file 457 ByteString sTempFile; 458 ByteString sTargetFile( sPath ); 459 ByteString sTempFileCopy; 460 461 static const ByteString INPATH = Export::GetEnv( "INPATH" ); 462 Export::getRandomName( sPath , sTempFile , INPATH ); 463 Export::getRandomName( sPath , sTempFileCopy , INPATH ); 464 // Write in the temp file 465 bool hasNoError = file->Write ( sTempFile ); 466 if( !hasNoError ) 467 { 468 cerr << "ERROR: file->Write failed\n"; 469 return false; 470 } 471 472 DirEntry aTmp( sTempFile ); 473 DirEntry aTmp2( sTempFileCopy ); 474 DirEntry aTar( sTargetFile ); 475 476 if( !Export::CopyFile( sTempFile , sTempFileCopy ) ) 477 { 478 #if defined(UNX) || defined(OS2) 479 sleep( 3 ); 480 #else 481 Sleep( 3 ); 482 #endif 483 if( !Export::CopyFile( sTempFile , sTempFileCopy ) ) 484 { 485 cerr << "ERROR: Can not copy file from " << sTempFile.GetBuffer() << " to " << sTempFileCopy.GetBuffer() << "\n"; 486 return false; 487 } 488 } 489 //remove( sTargetFile.GetBuffer() ); 490 491 FileStat aFSTest( aTar ); 492 if( aFSTest.GetSize() < 1 ) 493 { 494 remove( sTargetFile.GetBuffer() ); 495 } 496 int rc; 497 #if defined(UNX) || defined(OS2) 498 rc = rename( sTempFile.GetBuffer() , sTargetFile.GetBuffer() ); 499 #else 500 rc = MoveFileEx( sTempFile.GetBuffer() , sTargetFile.GetBuffer(), MOVEFILE_REPLACE_EXISTING ); 501 #endif 502 FileStat aFS( aTar ); 503 504 //cout << "mv " << sTempFile.GetBuffer() << " " << sTargetFile.GetBuffer() << "\n"; 505 //cout << "rc -> " << rc << " filesize -> " << aFS.GetSize() << "\n"; 506 // Windows rename returns -1 if the file already exits 507 //#ifdef UNX 508 if( rc < 0 || aFS.GetSize() < 1 ) 509 //#else 510 // if( aFS.GetSize() < 1 ) 511 //#endif 512 { 513 #if defined(UNX) || defined(OS2) 514 sleep( 3 ); 515 #else 516 Sleep( 3 ); 517 #endif 518 aFSTest.Update( aTar ); 519 if( aFSTest.GetSize() < 1 ) 520 { 521 remove( sTargetFile.GetBuffer() ); 522 } 523 #if defined(UNX) || defined(OS2) 524 rc = rename( sTempFileCopy.GetBuffer() , sTargetFile.GetBuffer() ); 525 #else 526 rc = MoveFileEx( sTempFileCopy.GetBuffer() , sTargetFile.GetBuffer() , MOVEFILE_REPLACE_EXISTING ); 527 #endif 528 aFS.Update( aTar ); 529 530 //cout << "mv2 " << sTempFileCopy.GetBuffer() << " " << sTargetFile.GetBuffer() << "\n"; 531 //cout << "rc -> " << rc << " filesize -> " << aFS.GetSize() << "\n"; 532 533 // Windows rename returns -1 if the file already exits 534 //#ifdef WNT 535 // if( aFS.GetSize() < 1 ) 536 //#else 537 if( rc < 0 || aFS.GetSize() < 1 ) 538 //#endif 539 { 540 cerr << "ERROR: helpex Can't rename file " << sTempFileCopy.GetBuffer() << " to " << sTargetFile.GetBuffer() << " rename rc=" << rc << " filesize=" << aFS.GetSize() << "\n"; 541 aTmp.Kill(); 542 aTmp2.Kill(); 543 if( aFS.GetSize() < 1 ) 544 aTar.Kill(); 545 return false; 546 } 547 } 548 aTmp.Kill(); 549 aTmp2.Kill(); 550 551 return true; 552 } 553 554 ByteString HelpParser::GetOutpath( const ByteString& rPathX , const ByteString& sCur , const ByteString& rPathY ){ 555 ByteString testpath = rPathX; 556 static const ByteString sDelimiter( DirEntry::GetAccessDelimiter(), RTL_TEXTENCODING_ASCII_US ); 557 testpath.EraseTrailingChars( '/' ); 558 testpath.EraseTrailingChars( '\\' ); 559 testpath += sDelimiter; 560 testpath += sCur; 561 testpath += sDelimiter; 562 ByteString sRelativePath( rPathY ); 563 sRelativePath.EraseLeadingChars( '/' ); 564 sRelativePath.EraseLeadingChars( '\\' ); 565 testpath += sRelativePath; 566 testpath += sDelimiter; 567 return testpath; 568 } 569 void HelpParser::MakeDir( const ByteString& sPath ){ 570 ByteString sTPath( sPath ); 571 ByteString sDelimiter( DirEntry::GetAccessDelimiter(), RTL_TEXTENCODING_ASCII_US ); 572 sTPath.SearchAndReplaceAll( sDelimiter , '/' ); 573 sal_uInt16 cnt = sTPath.GetTokenCount( '/' ); 574 ByteString sCreateDir; 575 for( sal_uInt16 i = 0 ; i < cnt ; i++ ) 576 { 577 sCreateDir += sTPath.GetToken( i , '/' ); 578 sCreateDir += sDelimiter; 579 #ifdef WNT 580 _mkdir( sCreateDir.GetBuffer() ); 581 #else 582 mkdir( sCreateDir.GetBuffer() , S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH ); 583 #endif 584 } 585 } 586 587 588 /* ProcessHelp Methode: search for en-US entry and replace it with the current language*/ 589 void HelpParser::ProcessHelp( LangHashMap* aLangHM , const ByteString& sCur , ResData *pResData , MergeDataFile& aMergeDataFile ){ 590 591 XMLElement* pXMLElement = NULL; 592 PFormEntrys *pEntrys = NULL; 593 XMLData *data = NULL; 594 XMLParentNode *parent = NULL; 595 596 String sNewdata; 597 ByteString sLId; 598 ByteString sGId; 599 600 pEntrys = NULL; 601 602 #ifdef MERGE_SOURCE_LANGUAGES 603 if( true ){ // Merge en-US! 604 #else 605 if( !sCur.EqualsIgnoreCaseAscii("en-US") ){ 606 #endif 607 pXMLElement = (*aLangHM)[ "en-US" ]; 608 if( pXMLElement == NULL ) 609 { 610 printf("Error: Can't find en-US entry\n"); 611 } 612 if( pXMLElement != NULL ) 613 { 614 parent = pXMLElement->GetParent(); 615 sLId = pXMLElement->GetOldref(); 616 pResData->sId = sLId; 617 618 pEntrys = aMergeDataFile.GetPFormEntrys( pResData ); 619 if( pEntrys != NULL) 620 { 621 ByteString sNewText; 622 pEntrys->GetText( sNewText, STRING_TYP_TEXT, sCur , true ); 623 sNewdata = String( sNewText , RTL_TEXTENCODING_UTF8 ); 624 if ( sNewdata.Len()) 625 { 626 if( pXMLElement != NULL ) 627 { 628 data = new XMLData( sNewdata , NULL , true ); // Add new one 629 pXMLElement->RemoveAndDeleteAllChilds(); 630 pXMLElement->AddChild( data ); 631 aLangHM->erase( sCur ); 632 } 633 } 634 }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());} 635 pXMLElement->ChangeLanguageTag( String( sCur , RTL_TEXTENCODING_ASCII_US) ); 636 } 637 638 } 639 } 640 /* Process() Method merges */ 641 void HelpParser::Process( LangHashMap* aLangHM , const ByteString& sCur , ResData *pResData , MergeDataFile& aMergeDataFile ){ 642 643 XMLElement* pXMLElement = NULL; 644 PFormEntrys *pEntrys = NULL; 645 XMLData *data = NULL; 646 XMLParentNode *parent = NULL; 647 XMLDefault *xmldefault = NULL; 648 649 short curLang = 0; 650 String sNewdata; 651 bool isFallback = false; 652 ByteString sLId; 653 ByteString sGId; 654 655 pEntrys = NULL; 656 657 #ifdef MERGE_SOURCE_LANGUAGES 658 if( true ){ // Merge en-US! 659 #else 660 if( !sCur.EqualsIgnoreCaseAscii("en-US") ){ 661 #endif 662 pXMLElement = (*aLangHM)[ sCur ]; 663 if( pXMLElement == NULL ) 664 { 665 FillInFallbacks( *aLangHM , sCur ); 666 pXMLElement = ( *aLangHM )[ sCur ]; 667 isFallback = true; 668 } 669 if( pXMLElement != NULL ) 670 { 671 parent = pXMLElement->GetParent(); 672 sLId = pXMLElement->GetOldref(); 673 pResData->sId = sLId; 674 675 pEntrys = aMergeDataFile.GetPFormEntrys( pResData ); 676 if( pEntrys != NULL) 677 { 678 ByteString sNewText; 679 pEntrys->GetText( sNewText, STRING_TYP_TEXT, sCur , true ); 680 sNewdata = String( sNewText , RTL_TEXTENCODING_UTF8 ); 681 if ( sNewdata.Len()) 682 { 683 printf("Entries found\n"); 684 if( pXMLElement != NULL ) 685 { 686 data = new XMLData( sNewdata , NULL , true ); // Add new one 687 if( pXMLElement->ToOUString().compareTo( OUString(data->GetData()) ) != 0 ) 688 { 689 pXMLElement->RemoveAndDeleteAllChilds(); 690 pXMLElement->AddChild( data ); 691 } 692 if( isFallback ) 693 { 694 xmldefault = new XMLDefault( String::CreateFromAscii("\n") , NULL ); 695 int pos = parent->GetPosition( pXMLElement->GetId() ); 696 if( pos != -1 ){ 697 parent->AddChild(xmldefault , pos+1 ); 698 parent->AddChild(pXMLElement , pos+2 ); 699 } 700 else fprintf(stdout,"ERROR: Can't find reference Element of id %s language %d\n",pXMLElement->GetId().GetBuffer(),curLang); 701 } 702 703 aLangHM->erase( sCur ); 704 } 705 } 706 delete pResData; 707 }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());} 708 } 709 710 } 711 } 712 713