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