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