13cd96b95SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
33cd96b95SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
43cd96b95SAndrew Rist * or more contributor license agreements. See the NOTICE file
53cd96b95SAndrew Rist * distributed with this work for additional information
63cd96b95SAndrew Rist * regarding copyright ownership. The ASF licenses this file
73cd96b95SAndrew Rist * to you under the Apache License, Version 2.0 (the
83cd96b95SAndrew Rist * "License"); you may not use this file except in compliance
93cd96b95SAndrew Rist * with the License. You may obtain a copy of the License at
103cd96b95SAndrew Rist *
113cd96b95SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
123cd96b95SAndrew Rist *
133cd96b95SAndrew Rist * Unless required by applicable law or agreed to in writing,
143cd96b95SAndrew Rist * software distributed under the License is distributed on an
153cd96b95SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
163cd96b95SAndrew Rist * KIND, either express or implied. See the License for the
173cd96b95SAndrew Rist * specific language governing permissions and limitations
183cd96b95SAndrew Rist * under the License.
193cd96b95SAndrew Rist *
203cd96b95SAndrew Rist *************************************************************/
213cd96b95SAndrew Rist
223cd96b95SAndrew 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 /*****************************************************************************/
FillInFallbacks(LangHashMap & rElem_out,ByteString sLangIdx_in)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 /*****************************************************************************/
Dump(XMLHashMap * rElem_in)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 /*****************************************************************************/
Dump(LangHashMap * rElem_in,const ByteString sKey_in)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
HelpParser(const ByteString & rHelpFile,bool rUTF8,bool rHasInputList)110cdf0e10cSrcweir HelpParser::HelpParser( const ByteString &rHelpFile, bool rUTF8 , bool rHasInputList )
111cdf0e10cSrcweir : sHelpFile( rHelpFile ),
112cdf0e10cSrcweir bUTF8 ( rUTF8 ),
113cdf0e10cSrcweir bHasInputList( rHasInputList )
114cdf0e10cSrcweir {};
115cdf0e10cSrcweir
116cdf0e10cSrcweir /*****************************************************************************/
CreateSDF(const ByteString & rSDFFile_in,const ByteString & rPrj_in,const ByteString & rRoot_in,const ByteString & sHelpFile,XMLFile * pXmlFile,const ByteString & rGsi1)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
makeAbsolutePath(const ByteString & sHelpFile,const ByteString & rRoot_in)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 }
Merge(const ByteString & rSDFFile,const ByteString & rDestinationFile,ByteString & sLanguage,MergeDataFile & aMergeDataFile)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' ) ) );
306*ebd57642SArrigo Marchiori if (xmlfile == NULL) {
307*ebd57642SArrigo Marchiori printf("%s\n",ByteString(aParser.GetError().sMessage,
308*ebd57642SArrigo Marchiori RTL_TEXTENCODING_ASCII_US).GetBuffer());
309*ebd57642SArrigo Marchiori exit(-1);
310*ebd57642SArrigo Marchiori }
311cdf0e10cSrcweir printf("Dest file %s\n",rDestinationFile.GetBuffer());
312cdf0e10cSrcweir hasNoError = MergeSingleFile( xmlfile , aMergeDataFile , sLanguage , rDestinationFile );
313cdf0e10cSrcweir delete xmlfile;
314cdf0e10cSrcweir if( !sUsedTempFile.EqualsIgnoreCaseAscii( "" ) ){
315cdf0e10cSrcweir DirEntry aTempFile( sUsedTempFile );
316cdf0e10cSrcweir aTempFile.Kill();
317cdf0e10cSrcweir }
318cdf0e10cSrcweir return hasNoError;
319cdf0e10cSrcweir }
320cdf0e10cSrcweir
ByteStringEqual(const ByteString & rKey1,const ByteString & rKey2)321cdf0e10cSrcweir bool ByteStringEqual( const ByteString& rKey1, const ByteString& rKey2 ) {
322cdf0e10cSrcweir return rKey1.CompareTo( rKey2 )==COMPARE_EQUAL;
323cdf0e10cSrcweir };
ByteStringLess(const ByteString & rKey1,const ByteString & rKey2)324cdf0e10cSrcweir bool ByteStringLess( const ByteString& rKey1, const ByteString& rKey2 ) {
325cdf0e10cSrcweir return rKey1.CompareTo( rKey2 )==COMPARE_LESS;
326cdf0e10cSrcweir }
327cdf0e10cSrcweir
parse_languages(std::vector<ByteString> & aLanguages,MergeDataFile & aMergeDataFile)328cdf0e10cSrcweir void HelpParser::parse_languages( std::vector<ByteString>& aLanguages , MergeDataFile& aMergeDataFile ){
329cdf0e10cSrcweir std::vector<ByteString> aTmp;
330cdf0e10cSrcweir
331cdf0e10cSrcweir const ByteString DE ("de");
332cdf0e10cSrcweir const ByteString ENUS ("en-US");
333cdf0e10cSrcweir static const ByteString ALL( "ALL" );
334cdf0e10cSrcweir
335cdf0e10cSrcweir Export::InitLanguages( false );
336cdf0e10cSrcweir
337cdf0e10cSrcweir if( Export::sLanguages.EqualsIgnoreCaseAscii( ALL ) )
338cdf0e10cSrcweir {
339cdf0e10cSrcweir aLanguages = aMergeDataFile.GetLanguages();
340cdf0e10cSrcweir aLanguages.push_back( DE );
341cdf0e10cSrcweir aLanguages.push_back( ENUS );
342cdf0e10cSrcweir
343cdf0e10cSrcweir if( !Export::sForcedLanguages.Equals("") )
344cdf0e10cSrcweir {
345cdf0e10cSrcweir std::vector<ByteString> aFL = Export::GetForcedLanguages();
346cdf0e10cSrcweir std::copy( aFL.begin() ,
347cdf0e10cSrcweir aFL.end() ,
348cdf0e10cSrcweir back_inserter( aLanguages )
349cdf0e10cSrcweir );
350cdf0e10cSrcweir std::sort( aLanguages.begin() , aLanguages.end() , ByteStringLess );
351cdf0e10cSrcweir std::vector<ByteString>::iterator unique_iter = std::unique( aLanguages.begin() , aLanguages.end() , ByteStringEqual );
352cdf0e10cSrcweir std::copy( aLanguages.begin() , unique_iter , back_inserter( aTmp ) );
353cdf0e10cSrcweir aLanguages = aTmp;
354cdf0e10cSrcweir }
355cdf0e10cSrcweir }
356cdf0e10cSrcweir else{
357cdf0e10cSrcweir aLanguages = Export::GetLanguages();
358cdf0e10cSrcweir }
359cdf0e10cSrcweir
360cdf0e10cSrcweir }
361cdf0e10cSrcweir
Merge(const ByteString & rSDFFile,const ByteString & rPathX,const ByteString & rPathY,bool bISO,const std::vector<ByteString> & aLanguages,MergeDataFile & aMergeDataFile,bool bCreateDir)362cdf0e10cSrcweir bool HelpParser::Merge(
363cdf0e10cSrcweir const ByteString &rSDFFile, const ByteString &rPathX , const ByteString &rPathY , bool bISO ,
364cdf0e10cSrcweir const std::vector<ByteString>& aLanguages , MergeDataFile& aMergeDataFile , bool bCreateDir )
365cdf0e10cSrcweir {
366cdf0e10cSrcweir
367cdf0e10cSrcweir
368cdf0e10cSrcweir (void) rSDFFile ;
369cdf0e10cSrcweir bool hasNoError = true;
370cdf0e10cSrcweir SimpleXMLParser aParser;
371cdf0e10cSrcweir String sUsedTempFile;
372cdf0e10cSrcweir String sXmlFile;
373cdf0e10cSrcweir
374cdf0e10cSrcweir if( Export::fileHasUTF8ByteOrderMarker( sHelpFile ) )
375cdf0e10cSrcweir {
376cdf0e10cSrcweir DirEntry aTempFile = Export::GetTempFile();
377cdf0e10cSrcweir DirEntry aSourceFile( String( sHelpFile , RTL_TEXTENCODING_ASCII_US ) );
378cdf0e10cSrcweir aSourceFile.CopyTo( aTempFile , FSYS_ACTION_COPYFILE );
379cdf0e10cSrcweir String sTempFile = aTempFile.GetFull();
380cdf0e10cSrcweir Export::RemoveUTF8ByteOrderMarkerFromFile( ByteString( sTempFile , RTL_TEXTENCODING_ASCII_US ) );
381cdf0e10cSrcweir sUsedTempFile = sTempFile;
382cdf0e10cSrcweir sXmlFile = sTempFile;
383cdf0e10cSrcweir }
384cdf0e10cSrcweir else
385cdf0e10cSrcweir {
386cdf0e10cSrcweir sUsedTempFile = String::CreateFromAscii("");
387cdf0e10cSrcweir sXmlFile = String( sHelpFile , RTL_TEXTENCODING_ASCII_US );
388cdf0e10cSrcweir }
389cdf0e10cSrcweir
390cdf0e10cSrcweir
391cdf0e10cSrcweir OUString sOUHelpFile( sXmlFile );
392cdf0e10cSrcweir String fullFilePath;
393cdf0e10cSrcweir DirEntry aFile( sXmlFile );
394cdf0e10cSrcweir
395cdf0e10cSrcweir XMLFile* xmlfile = ( aParser.Execute( aFile.GetFull() , sOUHelpFile, new XMLFile( '0' ) ) );
396cdf0e10cSrcweir
397cdf0e10cSrcweir if( xmlfile == NULL)
398cdf0e10cSrcweir {
399cdf0e10cSrcweir printf("%s\n",ByteString(aParser.GetError().sMessage,RTL_TEXTENCODING_UTF8).GetBuffer());
400cdf0e10cSrcweir exit(-1);
401cdf0e10cSrcweir //return false;
402cdf0e10cSrcweir }
403*ebd57642SArrigo Marchiori xmlfile->Extract();
404cdf0e10cSrcweir
405cdf0e10cSrcweir
406cdf0e10cSrcweir ByteString sCur;
407cdf0e10cSrcweir for( unsigned int n = 0; n < aLanguages.size(); n++ ){
408cdf0e10cSrcweir sCur = aLanguages[ n ];
409cdf0e10cSrcweir
410cdf0e10cSrcweir ByteString sFilepath;
411cdf0e10cSrcweir if( bISO ) sFilepath = GetOutpath( rPathX , sCur , rPathY );
412cdf0e10cSrcweir else sFilepath = rPathX;
413cdf0e10cSrcweir if( bCreateDir ) MakeDir( sFilepath );
414cdf0e10cSrcweir
415cdf0e10cSrcweir XMLFile* file = new XMLFile( *xmlfile );
416cdf0e10cSrcweir sFilepath.Append( sHelpFile );
417cdf0e10cSrcweir hasNoError = MergeSingleFile( file , aMergeDataFile , sCur , sFilepath );
418cdf0e10cSrcweir delete file;
419cdf0e10cSrcweir
420cdf0e10cSrcweir if( !hasNoError ) return false; // Stop on error
421cdf0e10cSrcweir }
422cdf0e10cSrcweir
423cdf0e10cSrcweir if( !sUsedTempFile.EqualsIgnoreCaseAscii( "" ) )
424cdf0e10cSrcweir {
425cdf0e10cSrcweir DirEntry aTempFile( sUsedTempFile );
426cdf0e10cSrcweir aTempFile.Kill();
427cdf0e10cSrcweir }
428cdf0e10cSrcweir delete xmlfile;
429cdf0e10cSrcweir return hasNoError;
430cdf0e10cSrcweir }
431cdf0e10cSrcweir
MergeSingleFile(XMLFile * file,MergeDataFile & aMergeDataFile,const ByteString & sLanguage,ByteString sPath)432cdf0e10cSrcweir bool HelpParser::MergeSingleFile( XMLFile* file , MergeDataFile& aMergeDataFile , const ByteString& sLanguage ,
433cdf0e10cSrcweir ByteString sPath )
434cdf0e10cSrcweir {
435cdf0e10cSrcweir file->Extract();
436cdf0e10cSrcweir
437cdf0e10cSrcweir XMLHashMap* aXMLStrHM = file->GetStrings();
438cdf0e10cSrcweir LangHashMap* aLangHM;
439cdf0e10cSrcweir static ResData pResData( "","","");
440cdf0e10cSrcweir pResData.sResTyp = "help";
441cdf0e10cSrcweir
442cdf0e10cSrcweir ByteString sTmp = Export::sLanguages;
443cdf0e10cSrcweir
444cdf0e10cSrcweir sTmp.EraseLeadingAndTrailingChars();
445cdf0e10cSrcweir
446cdf0e10cSrcweir for(XMLHashMap::iterator pos=aXMLStrHM->begin();pos!=aXMLStrHM->end();++pos) // Merge every l10n related string
447cdf0e10cSrcweir {
448cdf0e10cSrcweir
449cdf0e10cSrcweir aLangHM = pos->second;
450cdf0e10cSrcweir //printf("*********************DUMPING HASHMAP***************************************");
451cdf0e10cSrcweir //Dump( aXMLStrHM );
452cdf0e10cSrcweir //printf("DBG: sHelpFile = %s\n",sHelpFile.GetBuffer() );
453cdf0e10cSrcweir
454cdf0e10cSrcweir pResData.sGId = pos->first;
455cdf0e10cSrcweir pResData.sFilename = sHelpFile;
456cdf0e10cSrcweir
457cdf0e10cSrcweir ProcessHelp( aLangHM , sLanguage, &pResData , aMergeDataFile );
458cdf0e10cSrcweir }
459cdf0e10cSrcweir
460cdf0e10cSrcweir
461cdf0e10cSrcweir // Init temp and target file
462cdf0e10cSrcweir ByteString sTempFile;
463cdf0e10cSrcweir ByteString sTargetFile( sPath );
464cdf0e10cSrcweir ByteString sTempFileCopy;
465cdf0e10cSrcweir
466cdf0e10cSrcweir static const ByteString INPATH = Export::GetEnv( "INPATH" );
467cdf0e10cSrcweir Export::getRandomName( sPath , sTempFile , INPATH );
468cdf0e10cSrcweir Export::getRandomName( sPath , sTempFileCopy , INPATH );
469cdf0e10cSrcweir // Write in the temp file
470cdf0e10cSrcweir bool hasNoError = file->Write ( sTempFile );
471cdf0e10cSrcweir if( !hasNoError )
472cdf0e10cSrcweir {
473cdf0e10cSrcweir cerr << "ERROR: file->Write failed\n";
474cdf0e10cSrcweir return false;
475cdf0e10cSrcweir }
476cdf0e10cSrcweir
477cdf0e10cSrcweir DirEntry aTmp( sTempFile );
478cdf0e10cSrcweir DirEntry aTmp2( sTempFileCopy );
479cdf0e10cSrcweir DirEntry aTar( sTargetFile );
480cdf0e10cSrcweir
481cdf0e10cSrcweir if( !Export::CopyFile( sTempFile , sTempFileCopy ) )
482cdf0e10cSrcweir {
483cdf0e10cSrcweir #if defined(UNX) || defined(OS2)
484cdf0e10cSrcweir sleep( 3 );
485cdf0e10cSrcweir #else
486cdf0e10cSrcweir Sleep( 3 );
487cdf0e10cSrcweir #endif
488cdf0e10cSrcweir if( !Export::CopyFile( sTempFile , sTempFileCopy ) )
489cdf0e10cSrcweir {
490cdf0e10cSrcweir cerr << "ERROR: Can not copy file from " << sTempFile.GetBuffer() << " to " << sTempFileCopy.GetBuffer() << "\n";
491cdf0e10cSrcweir return false;
492cdf0e10cSrcweir }
493cdf0e10cSrcweir }
494cdf0e10cSrcweir //remove( sTargetFile.GetBuffer() );
495cdf0e10cSrcweir
496cdf0e10cSrcweir FileStat aFSTest( aTar );
497cdf0e10cSrcweir if( aFSTest.GetSize() < 1 )
498cdf0e10cSrcweir {
499cdf0e10cSrcweir remove( sTargetFile.GetBuffer() );
500cdf0e10cSrcweir }
501cdf0e10cSrcweir int rc;
502cdf0e10cSrcweir #if defined(UNX) || defined(OS2)
503cdf0e10cSrcweir rc = rename( sTempFile.GetBuffer() , sTargetFile.GetBuffer() );
504cdf0e10cSrcweir #else
505cdf0e10cSrcweir rc = MoveFileEx( sTempFile.GetBuffer() , sTargetFile.GetBuffer(), MOVEFILE_REPLACE_EXISTING );
506cdf0e10cSrcweir #endif
507cdf0e10cSrcweir FileStat aFS( aTar );
508cdf0e10cSrcweir
509cdf0e10cSrcweir //cout << "mv " << sTempFile.GetBuffer() << " " << sTargetFile.GetBuffer() << "\n";
510cdf0e10cSrcweir //cout << "rc -> " << rc << " filesize -> " << aFS.GetSize() << "\n";
511cdf0e10cSrcweir // Windows rename returns -1 if the file already exits
512cdf0e10cSrcweir //#ifdef UNX
513cdf0e10cSrcweir if( rc < 0 || aFS.GetSize() < 1 )
514cdf0e10cSrcweir //#else
515cdf0e10cSrcweir // if( aFS.GetSize() < 1 )
516cdf0e10cSrcweir //#endif
517cdf0e10cSrcweir {
518cdf0e10cSrcweir #if defined(UNX) || defined(OS2)
519cdf0e10cSrcweir sleep( 3 );
520cdf0e10cSrcweir #else
521cdf0e10cSrcweir Sleep( 3 );
522cdf0e10cSrcweir #endif
523cdf0e10cSrcweir aFSTest.Update( aTar );
524cdf0e10cSrcweir if( aFSTest.GetSize() < 1 )
525cdf0e10cSrcweir {
526cdf0e10cSrcweir remove( sTargetFile.GetBuffer() );
527cdf0e10cSrcweir }
528cdf0e10cSrcweir #if defined(UNX) || defined(OS2)
529cdf0e10cSrcweir rc = rename( sTempFileCopy.GetBuffer() , sTargetFile.GetBuffer() );
530cdf0e10cSrcweir #else
531cdf0e10cSrcweir rc = MoveFileEx( sTempFileCopy.GetBuffer() , sTargetFile.GetBuffer() , MOVEFILE_REPLACE_EXISTING );
532cdf0e10cSrcweir #endif
533cdf0e10cSrcweir aFS.Update( aTar );
534cdf0e10cSrcweir
535cdf0e10cSrcweir //cout << "mv2 " << sTempFileCopy.GetBuffer() << " " << sTargetFile.GetBuffer() << "\n";
536cdf0e10cSrcweir //cout << "rc -> " << rc << " filesize -> " << aFS.GetSize() << "\n";
537cdf0e10cSrcweir
538cdf0e10cSrcweir // Windows rename returns -1 if the file already exits
539cdf0e10cSrcweir //#ifdef WNT
540cdf0e10cSrcweir // if( aFS.GetSize() < 1 )
541cdf0e10cSrcweir //#else
542cdf0e10cSrcweir if( rc < 0 || aFS.GetSize() < 1 )
543cdf0e10cSrcweir //#endif
544cdf0e10cSrcweir {
545cdf0e10cSrcweir cerr << "ERROR: helpex Can't rename file " << sTempFileCopy.GetBuffer() << " to " << sTargetFile.GetBuffer() << " rename rc=" << rc << " filesize=" << aFS.GetSize() << "\n";
546cdf0e10cSrcweir aTmp.Kill();
547cdf0e10cSrcweir aTmp2.Kill();
548cdf0e10cSrcweir if( aFS.GetSize() < 1 )
549cdf0e10cSrcweir aTar.Kill();
550cdf0e10cSrcweir return false;
551cdf0e10cSrcweir }
552cdf0e10cSrcweir }
553cdf0e10cSrcweir aTmp.Kill();
554cdf0e10cSrcweir aTmp2.Kill();
555cdf0e10cSrcweir
556cdf0e10cSrcweir return true;
557cdf0e10cSrcweir }
558cdf0e10cSrcweir
GetOutpath(const ByteString & rPathX,const ByteString & sCur,const ByteString & rPathY)559cdf0e10cSrcweir ByteString HelpParser::GetOutpath( const ByteString& rPathX , const ByteString& sCur , const ByteString& rPathY ){
560cdf0e10cSrcweir ByteString testpath = rPathX;
561cdf0e10cSrcweir static const ByteString sDelimiter( DirEntry::GetAccessDelimiter(), RTL_TEXTENCODING_ASCII_US );
562cdf0e10cSrcweir testpath.EraseTrailingChars( '/' );
563cdf0e10cSrcweir testpath.EraseTrailingChars( '\\' );
564cdf0e10cSrcweir testpath += sDelimiter;
565cdf0e10cSrcweir testpath += sCur;
566cdf0e10cSrcweir testpath += sDelimiter;
567cdf0e10cSrcweir ByteString sRelativePath( rPathY );
568cdf0e10cSrcweir sRelativePath.EraseLeadingChars( '/' );
569cdf0e10cSrcweir sRelativePath.EraseLeadingChars( '\\' );
570cdf0e10cSrcweir testpath += sRelativePath;
571cdf0e10cSrcweir testpath += sDelimiter;
572cdf0e10cSrcweir return testpath;
573cdf0e10cSrcweir }
MakeDir(const ByteString & sPath)574cdf0e10cSrcweir void HelpParser::MakeDir( const ByteString& sPath ){
575cdf0e10cSrcweir ByteString sTPath( sPath );
576cdf0e10cSrcweir ByteString sDelimiter( DirEntry::GetAccessDelimiter(), RTL_TEXTENCODING_ASCII_US );
577cdf0e10cSrcweir sTPath.SearchAndReplaceAll( sDelimiter , '/' );
578cdf0e10cSrcweir sal_uInt16 cnt = sTPath.GetTokenCount( '/' );
579cdf0e10cSrcweir ByteString sCreateDir;
580cdf0e10cSrcweir for( sal_uInt16 i = 0 ; i < cnt ; i++ )
581cdf0e10cSrcweir {
582cdf0e10cSrcweir sCreateDir += sTPath.GetToken( i , '/' );
583cdf0e10cSrcweir sCreateDir += sDelimiter;
584cdf0e10cSrcweir #ifdef WNT
585cdf0e10cSrcweir _mkdir( sCreateDir.GetBuffer() );
586cdf0e10cSrcweir #else
587cdf0e10cSrcweir mkdir( sCreateDir.GetBuffer() , S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH );
588cdf0e10cSrcweir #endif
589cdf0e10cSrcweir }
590cdf0e10cSrcweir }
591cdf0e10cSrcweir
592cdf0e10cSrcweir
593cdf0e10cSrcweir /* ProcessHelp Methode: search for en-US entry and replace it with the current language*/
ProcessHelp(LangHashMap * aLangHM,const ByteString & sCur,ResData * pResData,MergeDataFile & aMergeDataFile)594cdf0e10cSrcweir void HelpParser::ProcessHelp( LangHashMap* aLangHM , const ByteString& sCur , ResData *pResData , MergeDataFile& aMergeDataFile ){
595cdf0e10cSrcweir
596cdf0e10cSrcweir XMLElement* pXMLElement = NULL;
597cdf0e10cSrcweir PFormEntrys *pEntrys = NULL;
598cdf0e10cSrcweir XMLData *data = NULL;
599cdf0e10cSrcweir XMLParentNode *parent = NULL;
600cdf0e10cSrcweir
601cdf0e10cSrcweir String sNewdata;
602cdf0e10cSrcweir ByteString sLId;
603cdf0e10cSrcweir ByteString sGId;
604cdf0e10cSrcweir
605cdf0e10cSrcweir pEntrys = NULL;
606cdf0e10cSrcweir
607cdf0e10cSrcweir #ifdef MERGE_SOURCE_LANGUAGES
608cdf0e10cSrcweir if( true ){ // Merge en-US!
609cdf0e10cSrcweir #else
610cdf0e10cSrcweir if( !sCur.EqualsIgnoreCaseAscii("en-US") ){
611cdf0e10cSrcweir #endif
612cdf0e10cSrcweir pXMLElement = (*aLangHM)[ "en-US" ];
613cdf0e10cSrcweir if( pXMLElement == NULL )
614cdf0e10cSrcweir {
615cdf0e10cSrcweir printf("Error: Can't find en-US entry\n");
616cdf0e10cSrcweir }
617cdf0e10cSrcweir if( pXMLElement != NULL )
618cdf0e10cSrcweir {
619cdf0e10cSrcweir parent = pXMLElement->GetParent();
620cdf0e10cSrcweir sLId = pXMLElement->GetOldref();
621cdf0e10cSrcweir pResData->sId = sLId;
622cdf0e10cSrcweir
623cdf0e10cSrcweir pEntrys = aMergeDataFile.GetPFormEntrys( pResData );
624cdf0e10cSrcweir if( pEntrys != NULL)
625cdf0e10cSrcweir {
626cdf0e10cSrcweir ByteString sNewText;
627cdf0e10cSrcweir pEntrys->GetText( sNewText, STRING_TYP_TEXT, sCur , true );
628cdf0e10cSrcweir sNewdata = String( sNewText , RTL_TEXTENCODING_UTF8 );
629cdf0e10cSrcweir if ( sNewdata.Len())
630cdf0e10cSrcweir {
631cdf0e10cSrcweir if( pXMLElement != NULL )
632cdf0e10cSrcweir {
633cdf0e10cSrcweir data = new XMLData( sNewdata , NULL , true ); // Add new one
634cdf0e10cSrcweir pXMLElement->RemoveAndDeleteAllChilds();
635cdf0e10cSrcweir pXMLElement->AddChild( data );
636cdf0e10cSrcweir aLangHM->erase( sCur );
637cdf0e10cSrcweir }
638cdf0e10cSrcweir }
639cdf0e10cSrcweir }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());}
640cdf0e10cSrcweir pXMLElement->ChangeLanguageTag( String( sCur , RTL_TEXTENCODING_ASCII_US) );
641cdf0e10cSrcweir }
642cdf0e10cSrcweir
643cdf0e10cSrcweir }
644cdf0e10cSrcweir }
645cdf0e10cSrcweir /* Process() Method merges */
646cdf0e10cSrcweir void HelpParser::Process( LangHashMap* aLangHM , const ByteString& sCur , ResData *pResData , MergeDataFile& aMergeDataFile ){
647cdf0e10cSrcweir
648cdf0e10cSrcweir XMLElement* pXMLElement = NULL;
649cdf0e10cSrcweir PFormEntrys *pEntrys = NULL;
650cdf0e10cSrcweir XMLData *data = NULL;
651cdf0e10cSrcweir XMLParentNode *parent = NULL;
652cdf0e10cSrcweir XMLDefault *xmldefault = NULL;
653cdf0e10cSrcweir
654cdf0e10cSrcweir short curLang = 0;
655cdf0e10cSrcweir String sNewdata;
656cdf0e10cSrcweir bool isFallback = false;
657cdf0e10cSrcweir ByteString sLId;
658cdf0e10cSrcweir ByteString sGId;
659cdf0e10cSrcweir
660cdf0e10cSrcweir pEntrys = NULL;
661cdf0e10cSrcweir
662cdf0e10cSrcweir #ifdef MERGE_SOURCE_LANGUAGES
663cdf0e10cSrcweir if( true ){ // Merge en-US!
664cdf0e10cSrcweir #else
665cdf0e10cSrcweir if( !sCur.EqualsIgnoreCaseAscii("en-US") ){
666cdf0e10cSrcweir #endif
667cdf0e10cSrcweir pXMLElement = (*aLangHM)[ sCur ];
668cdf0e10cSrcweir if( pXMLElement == NULL )
669cdf0e10cSrcweir {
670cdf0e10cSrcweir FillInFallbacks( *aLangHM , sCur );
671cdf0e10cSrcweir pXMLElement = ( *aLangHM )[ sCur ];
672cdf0e10cSrcweir isFallback = true;
673cdf0e10cSrcweir }
674cdf0e10cSrcweir if( pXMLElement != NULL )
675cdf0e10cSrcweir {
676cdf0e10cSrcweir parent = pXMLElement->GetParent();
677cdf0e10cSrcweir sLId = pXMLElement->GetOldref();
678cdf0e10cSrcweir pResData->sId = sLId;
679cdf0e10cSrcweir
680cdf0e10cSrcweir pEntrys = aMergeDataFile.GetPFormEntrys( pResData );
681cdf0e10cSrcweir if( pEntrys != NULL)
682cdf0e10cSrcweir {
683cdf0e10cSrcweir ByteString sNewText;
684cdf0e10cSrcweir pEntrys->GetText( sNewText, STRING_TYP_TEXT, sCur , true );
685cdf0e10cSrcweir sNewdata = String( sNewText , RTL_TEXTENCODING_UTF8 );
686cdf0e10cSrcweir if ( sNewdata.Len())
687cdf0e10cSrcweir {
688cdf0e10cSrcweir printf("Entries found\n");
689cdf0e10cSrcweir if( pXMLElement != NULL )
690cdf0e10cSrcweir {
691cdf0e10cSrcweir data = new XMLData( sNewdata , NULL , true ); // Add new one
692cdf0e10cSrcweir if( pXMLElement->ToOUString().compareTo( OUString(data->GetData()) ) != 0 )
693cdf0e10cSrcweir {
694cdf0e10cSrcweir pXMLElement->RemoveAndDeleteAllChilds();
695cdf0e10cSrcweir pXMLElement->AddChild( data );
696cdf0e10cSrcweir }
697cdf0e10cSrcweir if( isFallback )
698cdf0e10cSrcweir {
699cdf0e10cSrcweir xmldefault = new XMLDefault( String::CreateFromAscii("\n") , NULL );
700cdf0e10cSrcweir int pos = parent->GetPosition( pXMLElement->GetId() );
701cdf0e10cSrcweir if( pos != -1 ){
702cdf0e10cSrcweir parent->AddChild(xmldefault , pos+1 );
703cdf0e10cSrcweir parent->AddChild(pXMLElement , pos+2 );
704cdf0e10cSrcweir }
705cdf0e10cSrcweir else fprintf(stdout,"ERROR: Can't find reference Element of id %s language %d\n",pXMLElement->GetId().GetBuffer(),curLang);
706cdf0e10cSrcweir }
707cdf0e10cSrcweir
708cdf0e10cSrcweir aLangHM->erase( sCur );
709cdf0e10cSrcweir }
710cdf0e10cSrcweir }
711cdf0e10cSrcweir delete pResData;
712cdf0e10cSrcweir }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());}
713cdf0e10cSrcweir }
714cdf0e10cSrcweir
715cdf0e10cSrcweir }
716cdf0e10cSrcweir }
717cdf0e10cSrcweir
718