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 "export.hxx" 27cdf0e10cSrcweir #include "utf8conv.hxx" 28cdf0e10cSrcweir #include <tools/datetime.hxx> 29cdf0e10cSrcweir #include <tools/isofallback.hxx> 30cdf0e10cSrcweir #include <stdio.h> 31cdf0e10cSrcweir #include <osl/time.h> 32cdf0e10cSrcweir #include <osl/process.h> 33cdf0e10cSrcweir #include <rtl/ustring.hxx> 34cdf0e10cSrcweir #include <iostream> 35cdf0e10cSrcweir #include <iomanip> 36cdf0e10cSrcweir #include <tools/urlobj.hxx> 37cdf0e10cSrcweir #include <time.h> 38cdf0e10cSrcweir #include <stdlib.h> 39cdf0e10cSrcweir 40cdf0e10cSrcweir using namespace std; 41cdf0e10cSrcweir // 42cdf0e10cSrcweir // class ResData(); 43cdf0e10cSrcweir // 44cdf0e10cSrcweir 45cdf0e10cSrcweir /*****************************************************************************/ 46cdf0e10cSrcweir ResData::~ResData() 47cdf0e10cSrcweir /*****************************************************************************/ 48cdf0e10cSrcweir { 49cdf0e10cSrcweir if ( pStringList ) { 50cdf0e10cSrcweir // delete existing res. of type StringList 51cdf0e10cSrcweir for ( sal_uLong i = 0; i < pStringList->Count(); i++ ) { 52cdf0e10cSrcweir ExportListEntry* test = pStringList->GetObject( i ); 53cdf0e10cSrcweir if( test != NULL ) delete test; 54cdf0e10cSrcweir } 55cdf0e10cSrcweir delete pStringList; 56cdf0e10cSrcweir } 57cdf0e10cSrcweir if ( pFilterList ) { 58cdf0e10cSrcweir // delete existing res. of type FilterList 59cdf0e10cSrcweir for ( sal_uLong i = 0; i < pFilterList->Count(); i++ ) { 60cdf0e10cSrcweir ExportListEntry* test = pFilterList->GetObject( i ); 61cdf0e10cSrcweir delete test; 62cdf0e10cSrcweir } 63cdf0e10cSrcweir delete pFilterList; 64cdf0e10cSrcweir } 65cdf0e10cSrcweir if ( pItemList ) { 66cdf0e10cSrcweir // delete existing res. of type ItemList 67cdf0e10cSrcweir for ( sal_uLong i = 0; i < pItemList->Count(); i++ ) { 68cdf0e10cSrcweir ExportListEntry* test = pItemList->GetObject( i ); 69cdf0e10cSrcweir delete test; 70cdf0e10cSrcweir } 71cdf0e10cSrcweir delete pItemList; 72cdf0e10cSrcweir } 73cdf0e10cSrcweir if ( pUIEntries ) { 74cdf0e10cSrcweir // delete existing res. of type UIEntries 75cdf0e10cSrcweir for ( sal_uLong i = 0; i < pUIEntries->Count(); i++ ) { 76cdf0e10cSrcweir ExportListEntry* test = pUIEntries->GetObject( i ); 77cdf0e10cSrcweir delete test; 78cdf0e10cSrcweir } 79cdf0e10cSrcweir delete pUIEntries; 80cdf0e10cSrcweir } 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir // 84cdf0e10cSrcweir // class Export 85cdf0e10cSrcweir // 86cdf0e10cSrcweir 87cdf0e10cSrcweir /*****************************************************************************/ 88cdf0e10cSrcweir ByteString Export::sLanguages; 89cdf0e10cSrcweir ByteString Export::sForcedLanguages; 90cdf0e10cSrcweir //ByteString Export::sIsoCode99; 91cdf0e10cSrcweir /*****************************************************************************/ 92cdf0e10cSrcweir 93cdf0e10cSrcweir void Export::DumpExportList( ByteString& sListName , ExportList& aList ){ 94cdf0e10cSrcweir printf( "%s\n", sListName.GetBuffer() ); 95cdf0e10cSrcweir ByteString l(""); 96cdf0e10cSrcweir ExportListEntry* aEntry; 97cdf0e10cSrcweir for( unsigned int x = 0; x < aList.Count() ; x++ ){ 98cdf0e10cSrcweir aEntry = (ExportListEntry*) aList.GetObject( x ); 99cdf0e10cSrcweir Export::DumpMap( l , *aEntry ); 100cdf0e10cSrcweir } 101cdf0e10cSrcweir printf("\n"); 102cdf0e10cSrcweir } 103cdf0e10cSrcweir ByteString Export::DumpMap( ByteString& sMapName , ByteStringHashMap& aMap ){ 104cdf0e10cSrcweir ByteStringHashMap::const_iterator idbg; 105cdf0e10cSrcweir ByteString sReturn; 106cdf0e10cSrcweir 107cdf0e10cSrcweir if( sMapName.Len() ) 108cdf0e10cSrcweir printf("MapName %s\n", sMapName.GetBuffer()); 109cdf0e10cSrcweir if( aMap.size() < 1 ) return ByteString(); 110cdf0e10cSrcweir for( idbg = aMap.begin() ; idbg != aMap.end(); ++idbg ){ 111cdf0e10cSrcweir ByteString a( idbg->first ); 112cdf0e10cSrcweir ByteString b( idbg->second ); 113cdf0e10cSrcweir printf("[%s]= %s",a.GetBuffer(),b.GetBuffer()); 114cdf0e10cSrcweir printf("\n"); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir printf("\n"); 117cdf0e10cSrcweir return sReturn; 118cdf0e10cSrcweir } 119cdf0e10cSrcweir /*****************************************************************************/ 120cdf0e10cSrcweir void Export::SetLanguages( std::vector<ByteString> val ){ 121cdf0e10cSrcweir /*****************************************************************************/ 122cdf0e10cSrcweir aLanguages = val; 123cdf0e10cSrcweir isInitialized = true; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir /*****************************************************************************/ 126cdf0e10cSrcweir std::vector<ByteString> Export::GetLanguages(){ 127cdf0e10cSrcweir /*****************************************************************************/ 128cdf0e10cSrcweir return aLanguages; 129cdf0e10cSrcweir } 130cdf0e10cSrcweir /*****************************************************************************/ 131cdf0e10cSrcweir std::vector<ByteString> Export::GetForcedLanguages(){ 132cdf0e10cSrcweir /*****************************************************************************/ 133cdf0e10cSrcweir return aForcedLanguages; 134cdf0e10cSrcweir } 135cdf0e10cSrcweir std::vector<ByteString> Export::aLanguages = std::vector<ByteString>(); 136cdf0e10cSrcweir std::vector<ByteString> Export::aForcedLanguages = std::vector<ByteString>(); 137cdf0e10cSrcweir 138cdf0e10cSrcweir 139cdf0e10cSrcweir /*****************************************************************************/ 140cdf0e10cSrcweir void Export::QuotHTMLXRM( ByteString &rString ) 141cdf0e10cSrcweir /*****************************************************************************/ 142cdf0e10cSrcweir { 143cdf0e10cSrcweir ByteString sReturn; 144cdf0e10cSrcweir //sal_Bool bBreak = sal_False; 145cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < rString.Len(); i++ ) { 146cdf0e10cSrcweir ByteString sTemp = rString.Copy( i ); 147cdf0e10cSrcweir if ( sTemp.Search( "<Arg n=" ) == 0 ) { 148cdf0e10cSrcweir while ( i < rString.Len() && rString.GetChar( i ) != '>' ) { 149cdf0e10cSrcweir sReturn += rString.GetChar( i ); 150cdf0e10cSrcweir i++; 151cdf0e10cSrcweir } 152cdf0e10cSrcweir if ( rString.GetChar( i ) == '>' ) { 153cdf0e10cSrcweir sReturn += ">"; 154cdf0e10cSrcweir i++; 155cdf0e10cSrcweir } 156cdf0e10cSrcweir } 157cdf0e10cSrcweir 158cdf0e10cSrcweir if ( i < rString.Len()) { 159cdf0e10cSrcweir switch ( rString.GetChar( i )) { 160cdf0e10cSrcweir case '<': 161cdf0e10cSrcweir if( i+2 < rString.Len() && 162cdf0e10cSrcweir (rString.GetChar( i+1 ) == 'b' || rString.GetChar( i+1 ) == 'B') && 163cdf0e10cSrcweir rString.GetChar( i+2 ) == '>' ) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir sReturn +="<b>"; 166cdf0e10cSrcweir i += 2; 167cdf0e10cSrcweir } 168cdf0e10cSrcweir else if( i+3 < rString.Len() && 169cdf0e10cSrcweir rString.GetChar( i+1 ) == '/' && 170cdf0e10cSrcweir (rString.GetChar( i+2 ) == 'b' || rString.GetChar( i+2 ) == 'B') && 171cdf0e10cSrcweir rString.GetChar( i+3 ) == '>' ) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir sReturn +="</b>"; 174cdf0e10cSrcweir i += 3; 175cdf0e10cSrcweir } 176cdf0e10cSrcweir else 177cdf0e10cSrcweir sReturn += "<"; 178cdf0e10cSrcweir break; 179cdf0e10cSrcweir 180cdf0e10cSrcweir case '>': 181cdf0e10cSrcweir sReturn += ">"; 182cdf0e10cSrcweir break; 183cdf0e10cSrcweir 184cdf0e10cSrcweir case '\"': 185cdf0e10cSrcweir sReturn += """; 186cdf0e10cSrcweir break; 187cdf0e10cSrcweir 188cdf0e10cSrcweir case '\'': 189cdf0e10cSrcweir sReturn += "'"; 190cdf0e10cSrcweir break; 191cdf0e10cSrcweir 192cdf0e10cSrcweir case '&': 193cdf0e10cSrcweir if ((( i + 4 ) < rString.Len()) && 194cdf0e10cSrcweir ( rString.Copy( i, 5 ) == "&" )) 195cdf0e10cSrcweir sReturn += rString.GetChar( i ); 196cdf0e10cSrcweir else 197cdf0e10cSrcweir sReturn += "&"; 198cdf0e10cSrcweir break; 199cdf0e10cSrcweir 200cdf0e10cSrcweir default: 201cdf0e10cSrcweir sReturn += rString.GetChar( i ); 202cdf0e10cSrcweir break; 203cdf0e10cSrcweir } 204cdf0e10cSrcweir } 205cdf0e10cSrcweir } 206cdf0e10cSrcweir rString = sReturn; 207cdf0e10cSrcweir } 208cdf0e10cSrcweir /*****************************************************************************/ 209cdf0e10cSrcweir void Export::QuotHTML( ByteString &rString ) 210cdf0e10cSrcweir /*****************************************************************************/ 211cdf0e10cSrcweir { 212cdf0e10cSrcweir ByteString sReturn; 213cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < rString.Len(); i++ ) { 214cdf0e10cSrcweir ByteString sTemp = rString.Copy( i ); 215cdf0e10cSrcweir if ( sTemp.Search( "<Arg n=" ) == 0 ) { 216cdf0e10cSrcweir while ( i < rString.Len() && rString.GetChar( i ) != '>' ) { 217cdf0e10cSrcweir sReturn += rString.GetChar( i ); 218cdf0e10cSrcweir i++; 219cdf0e10cSrcweir } 220cdf0e10cSrcweir if ( rString.GetChar( i ) == '>' ) { 221cdf0e10cSrcweir sReturn += ">"; 222cdf0e10cSrcweir i++; 223cdf0e10cSrcweir } 224cdf0e10cSrcweir } 225cdf0e10cSrcweir if ( i < rString.Len()) { 226cdf0e10cSrcweir switch ( rString.GetChar( i )) { 227cdf0e10cSrcweir case '<': 228cdf0e10cSrcweir sReturn += "<"; 229cdf0e10cSrcweir break; 230cdf0e10cSrcweir 231cdf0e10cSrcweir case '>': 232cdf0e10cSrcweir sReturn += ">"; 233cdf0e10cSrcweir break; 234cdf0e10cSrcweir 235cdf0e10cSrcweir case '\"': 236cdf0e10cSrcweir sReturn += """; 237cdf0e10cSrcweir break; 238cdf0e10cSrcweir 239cdf0e10cSrcweir case '\'': 240cdf0e10cSrcweir sReturn += "'"; 241cdf0e10cSrcweir break; 242cdf0e10cSrcweir 243cdf0e10cSrcweir case '&': 244cdf0e10cSrcweir if ((( i + 4 ) < rString.Len()) && 245cdf0e10cSrcweir ( rString.Copy( i, 5 ) == "&" )) 246cdf0e10cSrcweir sReturn += rString.GetChar( i ); 247cdf0e10cSrcweir else 248cdf0e10cSrcweir sReturn += "&"; 249cdf0e10cSrcweir break; 250cdf0e10cSrcweir 251cdf0e10cSrcweir default: 252cdf0e10cSrcweir sReturn += rString.GetChar( i ); 253cdf0e10cSrcweir break; 254cdf0e10cSrcweir } 255cdf0e10cSrcweir } 256cdf0e10cSrcweir } 257cdf0e10cSrcweir rString = sReturn; 258cdf0e10cSrcweir } 259cdf0e10cSrcweir 260cdf0e10cSrcweir void Export::RemoveUTF8ByteOrderMarker( ByteString &rString ){ 261cdf0e10cSrcweir if( hasUTF8ByteOrderMarker( rString ) ) 262cdf0e10cSrcweir rString.Erase( 0 , 3 ); 263cdf0e10cSrcweir } 264cdf0e10cSrcweir 265cdf0e10cSrcweir bool Export::hasUTF8ByteOrderMarker( const ByteString &rString ){ 266cdf0e10cSrcweir // Byte order marker signature 267cdf0e10cSrcweir 268cdf0e10cSrcweir const unsigned char c1 = 0xEF; 269cdf0e10cSrcweir const unsigned char c2 = 0xBB; 270cdf0e10cSrcweir const unsigned char c3 = 0xBF; 271cdf0e10cSrcweir 272cdf0e10cSrcweir const char bom[ 3 ] = { c1 , c2 , c3 }; 273cdf0e10cSrcweir 274cdf0e10cSrcweir return rString.Len() >= 3 && 275cdf0e10cSrcweir rString.GetChar( 0 ) == bom[ 0 ] && 276cdf0e10cSrcweir rString.GetChar( 1 ) == bom[ 1 ] && 277cdf0e10cSrcweir rString.GetChar( 2 ) == bom[ 2 ] ; 278cdf0e10cSrcweir } 279cdf0e10cSrcweir bool Export::fileHasUTF8ByteOrderMarker( const ByteString &rString ){ 280cdf0e10cSrcweir SvFileStream aFileIn( String( rString , RTL_TEXTENCODING_ASCII_US ) , STREAM_READ ); 281cdf0e10cSrcweir ByteString sLine; 282cdf0e10cSrcweir if( !aFileIn.IsEof() ) { 283cdf0e10cSrcweir aFileIn.ReadLine( sLine ); 284cdf0e10cSrcweir if( aFileIn.IsOpen() ) aFileIn.Close(); 285cdf0e10cSrcweir return hasUTF8ByteOrderMarker( sLine ); 286cdf0e10cSrcweir } 287cdf0e10cSrcweir if( aFileIn.IsOpen() ) aFileIn.Close(); 288cdf0e10cSrcweir return false; 289cdf0e10cSrcweir } 290cdf0e10cSrcweir void Export::RemoveUTF8ByteOrderMarkerFromFile( const ByteString &rFilename ){ 291cdf0e10cSrcweir SvFileStream aFileIn( String( rFilename , RTL_TEXTENCODING_ASCII_US ) , STREAM_READ ); 292cdf0e10cSrcweir ByteString sLine; 293cdf0e10cSrcweir if( !aFileIn.IsEof() ) { 294cdf0e10cSrcweir aFileIn.ReadLine( sLine ); 295cdf0e10cSrcweir // Test header 296cdf0e10cSrcweir if( hasUTF8ByteOrderMarker( sLine ) ){ 297cdf0e10cSrcweir //cout << "UTF8 Header found!\n"; 298cdf0e10cSrcweir DirEntry aTempFile = Export::GetTempFile(); 299cdf0e10cSrcweir ByteString sTempFile = ByteString( aTempFile.GetFull() , RTL_TEXTENCODING_ASCII_US ); 300cdf0e10cSrcweir SvFileStream aNewFile( String( sTempFile , RTL_TEXTENCODING_ASCII_US ) , STREAM_WRITE ); 301cdf0e10cSrcweir // Remove header 302cdf0e10cSrcweir RemoveUTF8ByteOrderMarker( sLine ); 303cdf0e10cSrcweir //cout << "Copy stripped stuff to " << sTempFile.GetBuffer() << endl; 304cdf0e10cSrcweir aNewFile.WriteLine( sLine ); 305cdf0e10cSrcweir // Copy the rest 306cdf0e10cSrcweir while( !aFileIn.IsEof() ){ 307cdf0e10cSrcweir aFileIn.ReadLine( sLine ); 308cdf0e10cSrcweir aNewFile.WriteLine( sLine ); 309cdf0e10cSrcweir } 310cdf0e10cSrcweir if( aFileIn.IsOpen() ) aFileIn.Close(); 311cdf0e10cSrcweir if( aNewFile.IsOpen() ) aNewFile.Close(); 312cdf0e10cSrcweir DirEntry aEntry( rFilename.GetBuffer() ); 313cdf0e10cSrcweir //cout << "Removing file " << rFilename.GetBuffer() << "\n"; 314cdf0e10cSrcweir aEntry.Kill(); 315cdf0e10cSrcweir //cout << "Renaming file " << sTempFile.GetBuffer() << " to " << rFilename.GetBuffer() << "\n"; 316cdf0e10cSrcweir DirEntry( sTempFile ).MoveTo( DirEntry( rFilename.GetBuffer() ) ); 317cdf0e10cSrcweir } 318cdf0e10cSrcweir } 319cdf0e10cSrcweir if( aFileIn.IsOpen() ) aFileIn.Close(); 320cdf0e10cSrcweir } 321cdf0e10cSrcweir 322cdf0e10cSrcweir // Merge it into source code! 323cdf0e10cSrcweir //bool Export::isMergingGermanAllowed( const ByteString& rPrj ){ 324cdf0e10cSrcweir // (void) rPrj; 325cdf0e10cSrcweir // return true; 326cdf0e10cSrcweir /* static ByteStringBoolHashMap aHash; 327cdf0e10cSrcweir 328cdf0e10cSrcweir if( aHash.find( rPrj ) != aHash.end() ){ 329cdf0e10cSrcweir return aHash[ rPrj ]; 330cdf0e10cSrcweir } 331cdf0e10cSrcweir 332cdf0e10cSrcweir ByteString sFile = Export::GetEnv( "SRC_ROOT" ) ; 333cdf0e10cSrcweir sFile.Append("/"); 334cdf0e10cSrcweir sFile.Append( rPrj ); 335cdf0e10cSrcweir sFile.Append("/prj/l10n"); 336cdf0e10cSrcweir #if defined(WNT) || defined(OS2) 337cdf0e10cSrcweir sFile.SearchAndReplaceAll('/','\\'); 338cdf0e10cSrcweir #endif 339cdf0e10cSrcweir DirEntry aFlagfile( sFile ); 340cdf0e10cSrcweir 341cdf0e10cSrcweir aHash[ rPrj ] = !aFlagfile.Exists(); 342cdf0e10cSrcweir return aHash[ rPrj ];*/ 343cdf0e10cSrcweir //} 344cdf0e10cSrcweir bool Export::CopyFile( const ByteString& source , const ByteString& dest ) 345cdf0e10cSrcweir { 346cdf0e10cSrcweir // cout << "CopyFile( " << source.GetBuffer() << " , " << dest.GetBuffer() << " )\n"; 347cdf0e10cSrcweir const int BUFFERSIZE = 8192; 348cdf0e10cSrcweir char buf[ BUFFERSIZE ]; 349cdf0e10cSrcweir 350cdf0e10cSrcweir FILE* IN_FILE = fopen( source.GetBuffer() , "r" ); 351cdf0e10cSrcweir if( IN_FILE == NULL ) 352cdf0e10cSrcweir { 353cdf0e10cSrcweir cerr << "Export::CopyFile WARNING: Could not open " << source.GetBuffer() << "\n"; 354cdf0e10cSrcweir return false; 355cdf0e10cSrcweir } 356cdf0e10cSrcweir 357cdf0e10cSrcweir FILE* OUT_FILE = fopen( dest.GetBuffer() , "w" ); 358cdf0e10cSrcweir if( OUT_FILE == NULL ) 359cdf0e10cSrcweir { 360cdf0e10cSrcweir cerr << "Export::CopyFile WARNING: Could not open/create " << dest.GetBuffer() << " for writing\n"; 361cdf0e10cSrcweir fclose( IN_FILE ); 362cdf0e10cSrcweir return false; 363cdf0e10cSrcweir } 364cdf0e10cSrcweir 365cdf0e10cSrcweir while( fgets( buf , BUFFERSIZE , IN_FILE ) != NULL ) 366cdf0e10cSrcweir { 367cdf0e10cSrcweir if( fputs( buf , OUT_FILE ) == EOF ) 368cdf0e10cSrcweir { 369cdf0e10cSrcweir cerr << "Export::CopyFile WARNING: Write problems " << source.GetBuffer() << "\n"; 370cdf0e10cSrcweir fclose( IN_FILE ); 371cdf0e10cSrcweir fclose( OUT_FILE ); 372cdf0e10cSrcweir return false; 373cdf0e10cSrcweir } 374cdf0e10cSrcweir } 375cdf0e10cSrcweir if( ferror( IN_FILE ) ) 376cdf0e10cSrcweir { 377cdf0e10cSrcweir cerr << "Export::CopyFile WARNING: Read problems " << dest.GetBuffer() << "\n"; 378cdf0e10cSrcweir fclose( IN_FILE ); 379cdf0e10cSrcweir fclose( OUT_FILE ); 380cdf0e10cSrcweir return false; 381cdf0e10cSrcweir } 382cdf0e10cSrcweir fclose ( IN_FILE ); 383cdf0e10cSrcweir fclose ( OUT_FILE ); 384cdf0e10cSrcweir 385cdf0e10cSrcweir return true; 386cdf0e10cSrcweir } 387cdf0e10cSrcweir 388cdf0e10cSrcweir /*****************************************************************************/ 389cdf0e10cSrcweir void Export::UnquotHTML( ByteString &rString ) 390cdf0e10cSrcweir /*****************************************************************************/ 391cdf0e10cSrcweir { 392cdf0e10cSrcweir ByteString sReturn; 393cdf0e10cSrcweir while ( rString.Len()) { 394cdf0e10cSrcweir if ( rString.Copy( 0, 5 ) == "&" ) { 395cdf0e10cSrcweir sReturn += "&"; 396cdf0e10cSrcweir rString.Erase( 0, 5 ); 397cdf0e10cSrcweir } 398cdf0e10cSrcweir else if ( rString.Copy( 0, 4 ) == "<" ) { 399cdf0e10cSrcweir sReturn += "<"; 400cdf0e10cSrcweir rString.Erase( 0, 4 ); 401cdf0e10cSrcweir } 402cdf0e10cSrcweir else if ( rString.Copy( 0, 4 ) == ">" ) { 403cdf0e10cSrcweir sReturn += ">"; 404cdf0e10cSrcweir rString.Erase( 0, 4 ); 405cdf0e10cSrcweir } 406cdf0e10cSrcweir else if ( rString.Copy( 0, 6 ) == """ ) { 407cdf0e10cSrcweir sReturn += "\""; 408cdf0e10cSrcweir rString.Erase( 0, 6 ); 409cdf0e10cSrcweir } 410cdf0e10cSrcweir else if ( rString.Copy( 0, 6 ) == "'" ) { 411cdf0e10cSrcweir sReturn += "\'"; 412cdf0e10cSrcweir rString.Erase( 0, 6 ); 413cdf0e10cSrcweir } 414cdf0e10cSrcweir else { 415cdf0e10cSrcweir sReturn += rString.GetChar( 0 ); 416cdf0e10cSrcweir rString.Erase( 0, 1 ); 417cdf0e10cSrcweir } 418cdf0e10cSrcweir } 419cdf0e10cSrcweir rString = sReturn; 420cdf0e10cSrcweir } 421cdf0e10cSrcweir bool Export::isSourceLanguage( const ByteString &sLanguage ) 422cdf0e10cSrcweir { 423cdf0e10cSrcweir return !isAllowed( sLanguage ); 424cdf0e10cSrcweir } 425cdf0e10cSrcweir bool Export::isAllowed( const ByteString &sLanguage ){ 426cdf0e10cSrcweir return ! ( sLanguage.EqualsIgnoreCaseAscii("en-US") ); 427cdf0e10cSrcweir } 428cdf0e10cSrcweir /*****************************************************************************/ 429cdf0e10cSrcweir bool Export::LanguageAllowed( const ByteString &nLanguage ) 430cdf0e10cSrcweir /*****************************************************************************/ 431cdf0e10cSrcweir { 432cdf0e10cSrcweir return std::find( aLanguages.begin() , aLanguages.end() , nLanguage ) != aLanguages.end(); 433cdf0e10cSrcweir } 434cdf0e10cSrcweir 435cdf0e10cSrcweir bool Export::isInitialized = false; 436cdf0e10cSrcweir 437cdf0e10cSrcweir /*****************************************************************************/ 438cdf0e10cSrcweir void Export::InitLanguages( bool bMergeMode ){ 439cdf0e10cSrcweir /*****************************************************************************/ 440cdf0e10cSrcweir if( !isInitialized ){ 441cdf0e10cSrcweir ByteString sTmp; 442cdf0e10cSrcweir ByteStringBoolHashMap aEnvLangs; 443cdf0e10cSrcweir for ( sal_uInt16 x = 0; x < sLanguages.GetTokenCount( ',' ); x++ ){ 444cdf0e10cSrcweir sTmp = sLanguages.GetToken( x, ',' ).GetToken( 0, '=' ); 445cdf0e10cSrcweir sTmp.EraseLeadingAndTrailingChars(); 446cdf0e10cSrcweir if( bMergeMode && !isAllowed( sTmp ) ){} 447cdf0e10cSrcweir else if( !( (sTmp.GetChar(0)=='x' || sTmp.GetChar(0)=='X') && sTmp.GetChar(1)=='-' ) ){ 448cdf0e10cSrcweir aLanguages.push_back( sTmp ); 449cdf0e10cSrcweir } 450cdf0e10cSrcweir } 451cdf0e10cSrcweir InitForcedLanguages( bMergeMode ); 452cdf0e10cSrcweir isInitialized = true; 453cdf0e10cSrcweir } 454cdf0e10cSrcweir } 455cdf0e10cSrcweir /*****************************************************************************/ 456cdf0e10cSrcweir void Export::InitForcedLanguages( bool bMergeMode ){ 457cdf0e10cSrcweir /*****************************************************************************/ 458cdf0e10cSrcweir ByteString sTmp; 459cdf0e10cSrcweir ByteStringBoolHashMap aEnvLangs; 460cdf0e10cSrcweir for ( sal_uInt16 x = 0; x < sForcedLanguages.GetTokenCount( ',' ); x++ ){ 461cdf0e10cSrcweir sTmp = sForcedLanguages.GetToken( x, ',' ).GetToken( 0, '=' ); 462cdf0e10cSrcweir sTmp.EraseLeadingAndTrailingChars(); 463cdf0e10cSrcweir if( bMergeMode && isAllowed( sTmp ) ){} 464cdf0e10cSrcweir else if( !( (sTmp.GetChar(0)=='x' || sTmp.GetChar(0)=='X') && sTmp.GetChar(1)=='-' ) ) 465cdf0e10cSrcweir aForcedLanguages.push_back( sTmp ); 466cdf0e10cSrcweir } 467cdf0e10cSrcweir } 468cdf0e10cSrcweir 469cdf0e10cSrcweir /*****************************************************************************/ 470cdf0e10cSrcweir ByteString Export::GetFallbackLanguage( const ByteString nLanguage ) 471cdf0e10cSrcweir /*****************************************************************************/ 472cdf0e10cSrcweir { 473cdf0e10cSrcweir ByteString sFallback=nLanguage; 474cdf0e10cSrcweir GetIsoFallback( sFallback ); 475cdf0e10cSrcweir return sFallback; 476cdf0e10cSrcweir } 477cdf0e10cSrcweir 478cdf0e10cSrcweir void Export::replaceEncoding( ByteString& rString ) 479cdf0e10cSrcweir { 480cdf0e10cSrcweir // ™ -> \u2122 481cdf0e10cSrcweir 482cdf0e10cSrcweir for( xub_StrLen idx = 0; idx <= rString.Len()-8 ; idx++ ) 483cdf0e10cSrcweir { 484cdf0e10cSrcweir if( rString.GetChar( idx ) == '&' && 485cdf0e10cSrcweir rString.GetChar( idx+1 ) == '#' && 486cdf0e10cSrcweir rString.GetChar( idx+2 ) == 'x' && 487cdf0e10cSrcweir rString.GetChar( idx+7 ) == ';' ) 488cdf0e10cSrcweir { 489cdf0e10cSrcweir ByteString sTmp = rString.Copy( 0 , idx ); 490cdf0e10cSrcweir sTmp.Append( "\\u" ); 491cdf0e10cSrcweir sTmp.Append( rString.GetChar( idx+3 ) ); 492cdf0e10cSrcweir sTmp.Append( rString.GetChar( idx+4 ) ); 493cdf0e10cSrcweir sTmp.Append( rString.GetChar( idx+5 ) ); 494cdf0e10cSrcweir sTmp.Append( rString.GetChar( idx+6 ) ); 495cdf0e10cSrcweir sTmp.Append( rString.Copy( idx+8 , rString.Len() ) ); 496cdf0e10cSrcweir rString = sTmp; 497cdf0e10cSrcweir } 498cdf0e10cSrcweir } 499cdf0e10cSrcweir } 500cdf0e10cSrcweir 501cdf0e10cSrcweir /*****************************************************************************/ 502cdf0e10cSrcweir void Export::FillInFallbacks( ResData *pResData ) 503cdf0e10cSrcweir /*****************************************************************************/ 504cdf0e10cSrcweir { 505cdf0e10cSrcweir ByteString sCur; 506cdf0e10cSrcweir for( unsigned int n = 0; n < aLanguages.size(); n++ ){ 507cdf0e10cSrcweir sCur = aLanguages[ n ]; 508cdf0e10cSrcweir if( isAllowed( sCur ) ){ 509cdf0e10cSrcweir ByteString nFallbackIndex = GetFallbackLanguage( sCur ); 510cdf0e10cSrcweir if( nFallbackIndex.Len() ){ 511cdf0e10cSrcweir if ( !pResData->sText[ sCur ].Len()) 512cdf0e10cSrcweir pResData->sText[ sCur ] = 513cdf0e10cSrcweir pResData->sText[ nFallbackIndex ]; 514cdf0e10cSrcweir 515cdf0e10cSrcweir if ( !pResData->sHelpText[ sCur ].Len()) 516cdf0e10cSrcweir pResData->sHelpText[ sCur ] = 517cdf0e10cSrcweir pResData->sHelpText[ nFallbackIndex ]; 518cdf0e10cSrcweir 519cdf0e10cSrcweir if ( !pResData->sQuickHelpText[ sCur ].Len()) 520cdf0e10cSrcweir pResData->sQuickHelpText[ sCur ] = 521cdf0e10cSrcweir pResData->sQuickHelpText[ nFallbackIndex ]; 522cdf0e10cSrcweir 523cdf0e10cSrcweir if ( !pResData->sTitle[ sCur ].Len()) 524cdf0e10cSrcweir pResData->sTitle[ sCur ] = 525cdf0e10cSrcweir pResData->sTitle[ nFallbackIndex ]; 526cdf0e10cSrcweir 527cdf0e10cSrcweir if ( pResData->pStringList ) 528cdf0e10cSrcweir FillInListFallbacks( 529cdf0e10cSrcweir pResData->pStringList, sCur, nFallbackIndex ); 530cdf0e10cSrcweir 531cdf0e10cSrcweir if ( pResData->pPairedList ) 532cdf0e10cSrcweir FillInListFallbacks( 533cdf0e10cSrcweir pResData->pPairedList, sCur, nFallbackIndex ); 534cdf0e10cSrcweir 535cdf0e10cSrcweir if ( pResData->pFilterList ) 536cdf0e10cSrcweir FillInListFallbacks( 537cdf0e10cSrcweir pResData->pFilterList, sCur, nFallbackIndex ); 538cdf0e10cSrcweir 539cdf0e10cSrcweir if ( pResData->pItemList ) 540cdf0e10cSrcweir FillInListFallbacks( 541cdf0e10cSrcweir pResData->pItemList, sCur, nFallbackIndex ); 542cdf0e10cSrcweir 543cdf0e10cSrcweir if ( pResData->pUIEntries ) 544cdf0e10cSrcweir FillInListFallbacks( 545cdf0e10cSrcweir pResData->pUIEntries, sCur, nFallbackIndex ); 546cdf0e10cSrcweir } 547cdf0e10cSrcweir } 548cdf0e10cSrcweir } 549cdf0e10cSrcweir } 550cdf0e10cSrcweir 551cdf0e10cSrcweir /*****************************************************************************/ 552cdf0e10cSrcweir void Export::FillInListFallbacks( 553cdf0e10cSrcweir ExportList *pList, const ByteString &nSource, const ByteString &nFallback ) 554cdf0e10cSrcweir /*****************************************************************************/ 555cdf0e10cSrcweir { 556cdf0e10cSrcweir 557cdf0e10cSrcweir for ( sal_uLong i = 0; i < pList->Count(); i++ ) { 558cdf0e10cSrcweir ExportListEntry *pEntry = pList->GetObject( i ); 559cdf0e10cSrcweir if ( !( *pEntry )[ nSource ].Len()){ 560cdf0e10cSrcweir ( *pEntry )[ nSource ] = ( *pEntry )[ nFallback ]; 561cdf0e10cSrcweir ByteString x = ( *pEntry )[ nSource ]; 562cdf0e10cSrcweir ByteString y = ( *pEntry )[ nFallback ]; 563cdf0e10cSrcweir } 564cdf0e10cSrcweir } 565cdf0e10cSrcweir } 566cdf0e10cSrcweir 567cdf0e10cSrcweir /*****************************************************************************/ 568cdf0e10cSrcweir ByteString Export::GetTimeStamp() 569cdf0e10cSrcweir /*****************************************************************************/ 570cdf0e10cSrcweir { 571cdf0e10cSrcweir // return "xx.xx.xx"; 572cdf0e10cSrcweir char buf[20]; 573cdf0e10cSrcweir Time aTime; 574cdf0e10cSrcweir 575cdf0e10cSrcweir snprintf(buf, sizeof(buf), "%8d %02d:%02d:%02d", int(Date().GetDate()), 576cdf0e10cSrcweir int(aTime.GetHour()), int(aTime.GetMin()), int(aTime.GetSec())); 577cdf0e10cSrcweir return ByteString(buf); 578cdf0e10cSrcweir } 579cdf0e10cSrcweir 580cdf0e10cSrcweir /*****************************************************************************/ 581cdf0e10cSrcweir sal_Bool Export::ConvertLineEnds( 582cdf0e10cSrcweir ByteString sSource, ByteString sDestination ) 583cdf0e10cSrcweir /*****************************************************************************/ 584cdf0e10cSrcweir { 585cdf0e10cSrcweir String sSourceFile( sSource, RTL_TEXTENCODING_ASCII_US ); 586cdf0e10cSrcweir String sDestinationFile( sDestination, RTL_TEXTENCODING_ASCII_US ); 587cdf0e10cSrcweir 588cdf0e10cSrcweir SvFileStream aSource( sSourceFile, STREAM_READ ); 589cdf0e10cSrcweir if ( !aSource.IsOpen()) 590cdf0e10cSrcweir return sal_False; 591cdf0e10cSrcweir SvFileStream aDestination( sDestinationFile, STREAM_STD_WRITE | STREAM_TRUNC ); 592cdf0e10cSrcweir if ( !aDestination.IsOpen()) { 593cdf0e10cSrcweir aSource.Close(); 594cdf0e10cSrcweir return sal_False; 595cdf0e10cSrcweir } 596cdf0e10cSrcweir 597cdf0e10cSrcweir ByteString sLine; 598cdf0e10cSrcweir 599cdf0e10cSrcweir while ( !aSource.IsEof()) { 600cdf0e10cSrcweir aSource.ReadLine( sLine ); 601cdf0e10cSrcweir if ( !aSource.IsEof()) { 602cdf0e10cSrcweir sLine.EraseAllChars( '\r' ); 603cdf0e10cSrcweir aDestination.WriteLine( sLine ); 604cdf0e10cSrcweir } 605cdf0e10cSrcweir else 606cdf0e10cSrcweir aDestination.WriteByteString( sLine ); 607cdf0e10cSrcweir } 608cdf0e10cSrcweir 609cdf0e10cSrcweir aSource.Close(); 610cdf0e10cSrcweir aDestination.Close(); 611cdf0e10cSrcweir 612cdf0e10cSrcweir return sal_True; 613cdf0e10cSrcweir } 614cdf0e10cSrcweir 615cdf0e10cSrcweir /*****************************************************************************/ 616cdf0e10cSrcweir ByteString Export::GetNativeFile( ByteString sSource ) 617cdf0e10cSrcweir /*****************************************************************************/ 618cdf0e10cSrcweir { 619cdf0e10cSrcweir DirEntry aTemp( GetTempFile()); 620cdf0e10cSrcweir ByteString sReturn( aTemp.GetFull(), RTL_TEXTENCODING_ASCII_US ); 621cdf0e10cSrcweir 622cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < 10; i++ ) 623cdf0e10cSrcweir if ( ConvertLineEnds( sSource, sReturn )) 624cdf0e10cSrcweir return sReturn; 625cdf0e10cSrcweir 626cdf0e10cSrcweir return ""; 627cdf0e10cSrcweir } 628cdf0e10cSrcweir 629cdf0e10cSrcweir const char* Export::GetEnv( const char *pVar ) 630cdf0e10cSrcweir { 631cdf0e10cSrcweir char *pRet = getenv( pVar ); 632cdf0e10cSrcweir if ( !pRet ) 633cdf0e10cSrcweir pRet = 0; 634cdf0e10cSrcweir return pRet; 635cdf0e10cSrcweir } 636cdf0e10cSrcweir 637cdf0e10cSrcweir 638cdf0e10cSrcweir int Export::getCurrentDirectory( rtl::OUString& base_fqurl_out, rtl::OUString& base_out ) 639cdf0e10cSrcweir { 640cdf0e10cSrcweir DirEntry aDir("."); 641cdf0e10cSrcweir aDir.ToAbs(); 642cdf0e10cSrcweir base_out = rtl::OUString( aDir.GetFull() ); 643cdf0e10cSrcweir return osl::File::getFileURLFromSystemPath( base_out , base_fqurl_out ); 644cdf0e10cSrcweir } 645cdf0e10cSrcweir 646cdf0e10cSrcweir void Export::getCurrentDir( string& dir ) 647cdf0e10cSrcweir { 648cdf0e10cSrcweir char buffer[64000]; 649cdf0e10cSrcweir if( getcwd( buffer , sizeof( buffer ) ) == 0 ){ 650cdf0e10cSrcweir cerr << "Error: getcwd failed!\n"; 651cdf0e10cSrcweir exit( -1 ); 652cdf0e10cSrcweir } 653cdf0e10cSrcweir dir = string( buffer ); 654cdf0e10cSrcweir } 655cdf0e10cSrcweir 656cdf0e10cSrcweir 657cdf0e10cSrcweir // Stolen from sal/osl/unx/tempfile.c 658cdf0e10cSrcweir 659cdf0e10cSrcweir #define RAND_NAME_LENGTH 6 660cdf0e10cSrcweir 661cdf0e10cSrcweir void Export::getRandomName( const ByteString& sPrefix , ByteString& sRandStr , const ByteString& sPostfix ) 662cdf0e10cSrcweir { 663cdf0e10cSrcweir static const char LETTERS[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; 664cdf0e10cSrcweir static const int COUNT_OF_LETTERS = sizeof(LETTERS)/sizeof(LETTERS[0]) - 1; 665cdf0e10cSrcweir sRandStr.Append( sPrefix ); 666cdf0e10cSrcweir 667cdf0e10cSrcweir static sal_uInt64 value; 668cdf0e10cSrcweir char buffer[RAND_NAME_LENGTH]; 669cdf0e10cSrcweir 670cdf0e10cSrcweir TimeValue tv; 671cdf0e10cSrcweir sal_uInt64 v; 672cdf0e10cSrcweir int i; 673cdf0e10cSrcweir 674cdf0e10cSrcweir osl_getSystemTime( &tv ); 675cdf0e10cSrcweir oslProcessInfo proInfo; 676cdf0e10cSrcweir osl_getProcessInfo( 0 , osl_Process_IDENTIFIER , &proInfo ); 677cdf0e10cSrcweir 678cdf0e10cSrcweir value += ((sal_uInt64) ( tv.Nanosec / 1000 ) << 16) ^ ( tv.Nanosec / 1000 ) ^ proInfo.Ident; 679cdf0e10cSrcweir 680cdf0e10cSrcweir v = value; 681cdf0e10cSrcweir 682cdf0e10cSrcweir for (i = 0; i < RAND_NAME_LENGTH; i++) 683cdf0e10cSrcweir { 684cdf0e10cSrcweir buffer[i] = LETTERS[v % COUNT_OF_LETTERS]; 685cdf0e10cSrcweir v /= COUNT_OF_LETTERS; 686cdf0e10cSrcweir } 687cdf0e10cSrcweir 688cdf0e10cSrcweir sRandStr.Append( buffer , RAND_NAME_LENGTH ); 689cdf0e10cSrcweir sRandStr.Append( sPostfix ); 690cdf0e10cSrcweir } 691cdf0e10cSrcweir 692cdf0e10cSrcweir void Export::getRandomName( ByteString& sRandStr ) 693cdf0e10cSrcweir { 694cdf0e10cSrcweir const ByteString sEmpty; 695cdf0e10cSrcweir getRandomName( sEmpty , sRandStr , sEmpty ); 696cdf0e10cSrcweir } 697cdf0e10cSrcweir 698cdf0e10cSrcweir /*****************************************************************************/ 699cdf0e10cSrcweir DirEntry Export::GetTempFile() 700cdf0e10cSrcweir /*****************************************************************************/ 701cdf0e10cSrcweir { 702cdf0e10cSrcweir rtl::OUString* sTempFilename = new rtl::OUString(); 703cdf0e10cSrcweir 704cdf0e10cSrcweir // Create a temp file 705cdf0e10cSrcweir int nRC = osl::FileBase::createTempFile( 0 , 0 , sTempFilename ); 706cdf0e10cSrcweir if( nRC ) printf(" osl::FileBase::createTempFile RC = %d",nRC); 707cdf0e10cSrcweir 708cdf0e10cSrcweir String strTmp( *sTempFilename ); 709cdf0e10cSrcweir 710cdf0e10cSrcweir INetURLObject::DecodeMechanism eMechanism = INetURLObject::DECODE_TO_IURI; 711cdf0e10cSrcweir String sDecodedStr = INetURLObject::decode( strTmp , '%' , eMechanism ); 712cdf0e10cSrcweir ByteString sTmp( sDecodedStr , RTL_TEXTENCODING_UTF8 ); 713cdf0e10cSrcweir 714cdf0e10cSrcweir #if defined(WNT) || defined(OS2) 715cdf0e10cSrcweir sTmp.SearchAndReplace("file:///",""); 716cdf0e10cSrcweir sTmp.SearchAndReplaceAll('/','\\'); 717cdf0e10cSrcweir #else 718cdf0e10cSrcweir // Set file permission to 644 719cdf0e10cSrcweir const sal_uInt64 nPerm = osl_File_Attribute_OwnRead | osl_File_Attribute_OwnWrite | 720cdf0e10cSrcweir osl_File_Attribute_GrpRead | osl_File_Attribute_OthRead ; 721cdf0e10cSrcweir 722cdf0e10cSrcweir nRC = osl::File::setAttributes( *sTempFilename , nPerm ); 723cdf0e10cSrcweir if( nRC ) printf(" osl::File::setAttributes RC = %d",nRC); 724cdf0e10cSrcweir 725cdf0e10cSrcweir sTmp.SearchAndReplace("file://",""); 726cdf0e10cSrcweir #endif 727cdf0e10cSrcweir DirEntry aDirEntry( sTmp ); 728cdf0e10cSrcweir delete sTempFilename; 729cdf0e10cSrcweir return aDirEntry; 730cdf0e10cSrcweir } 731