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