xref: /AOO41X/main/l10ntools/source/export2.cxx (revision 8809db7a87f97847b57a57f4cd2b0104b2b83182)
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 += "&lt;";
178                 break;
179 
180                 case '>':
181                     sReturn += "&gt;";
182                 break;
183 
184                 case '\"':
185                     sReturn += "&quot;";
186                 break;
187 
188                 case '\'':
189                     sReturn += "&apos;";
190                 break;
191 
192                 case '&':
193                     if ((( i + 4 ) < rString.Len()) &&
194                         ( rString.Copy( i, 5 ) == "&amp;" ))
195                             sReturn += rString.GetChar( i );
196                     else
197                         sReturn += "&amp;";
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 += "&lt;";
229                 break;
230 
231                 case '>':
232                     sReturn += "&gt;";
233                 break;
234 
235                 case '\"':
236                     sReturn += "&quot;";
237                 break;
238 
239                 case '\'':
240                     sReturn += "&apos;";
241                 break;
242 
243                 case '&':
244                     if ((( i + 4 ) < rString.Len()) &&
245                         ( rString.Copy( i, 5 ) == "&amp;" ))
246                             sReturn += rString.GetChar( i );
247                     else
248                         sReturn += "&amp;";
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     // Byte order marker signature
267 
268     const unsigned char c1 =  0xEF;
269     const unsigned char c2 =  0xBB;
270     const unsigned char c3 =  0xBF;
271 
272     const char bom[ 3 ] = { c1 , c2 , c3 };
273 
274     return      rString.Len() >= 3 &&
275                 rString.GetChar( 0 ) == bom[ 0 ] &&
276                 rString.GetChar( 1 ) == bom[ 1 ] &&
277                 rString.GetChar( 2 ) == bom[ 2 ] ;
278 }
279 bool Export::fileHasUTF8ByteOrderMarker( const ByteString &rString ){
280     SvFileStream aFileIn( String( rString , RTL_TEXTENCODING_ASCII_US ) , STREAM_READ );
281     ByteString sLine;
282     if( !aFileIn.IsEof() ) {
283         aFileIn.ReadLine( sLine );
284         if( aFileIn.IsOpen() ) aFileIn.Close();
285         return hasUTF8ByteOrderMarker( sLine );
286     }
287     if( aFileIn.IsOpen() ) aFileIn.Close();
288     return false;
289 }
290 void Export::RemoveUTF8ByteOrderMarkerFromFile( const ByteString &rFilename ){
291     SvFileStream aFileIn( String( rFilename , RTL_TEXTENCODING_ASCII_US ) , STREAM_READ );
292     ByteString sLine;
293     if( !aFileIn.IsEof() ) {
294         aFileIn.ReadLine( sLine );
295         // Test header
296         if( hasUTF8ByteOrderMarker( sLine ) ){
297             //cout << "UTF8 Header found!\n";
298             DirEntry aTempFile = Export::GetTempFile();
299             ByteString sTempFile = ByteString( aTempFile.GetFull() , RTL_TEXTENCODING_ASCII_US );
300             SvFileStream aNewFile( String( sTempFile , RTL_TEXTENCODING_ASCII_US ) , STREAM_WRITE );
301             // Remove header
302             RemoveUTF8ByteOrderMarker( sLine );
303             //cout << "Copy stripped stuff to " << sTempFile.GetBuffer() << endl;
304             aNewFile.WriteLine( sLine );
305             // Copy the rest
306             while( !aFileIn.IsEof() ){
307                 aFileIn.ReadLine( sLine );
308                 aNewFile.WriteLine( sLine );
309             }
310             if( aFileIn.IsOpen() ) aFileIn.Close();
311             if( aNewFile.IsOpen() ) aNewFile.Close();
312             DirEntry aEntry( rFilename.GetBuffer() );
313             //cout << "Removing file " << rFilename.GetBuffer() << "\n";
314             aEntry.Kill();
315             //cout << "Renaming file " << sTempFile.GetBuffer() << " to " << rFilename.GetBuffer() << "\n";
316             DirEntry( sTempFile ).MoveTo( DirEntry( rFilename.GetBuffer() ) );
317         }
318     }
319     if( aFileIn.IsOpen() ) aFileIn.Close();
320 }
321 
322 // Merge it into source code!
323 //bool Export::isMergingGermanAllowed( const ByteString& rPrj ){
324 //    (void) rPrj;
325 //  return true;
326 /*  static ByteStringBoolHashMap aHash;
327 
328     if( aHash.find( rPrj ) != aHash.end() ){
329         return aHash[ rPrj ];
330     }
331 
332     ByteString sFile = Export::GetEnv( "SRC_ROOT" ) ;
333     sFile.Append("/");
334     sFile.Append( rPrj );
335     sFile.Append("/prj/l10n");
336 #if defined(WNT) || defined(OS2)
337     sFile.SearchAndReplaceAll('/','\\');
338 #endif
339     DirEntry aFlagfile( sFile );
340 
341     aHash[ rPrj ] = !aFlagfile.Exists();
342     return aHash[ rPrj ];*/
343 //}
344 bool Export::CopyFile( const ByteString& source , const ByteString& dest )
345 {
346 //    cout << "CopyFile( " << source.GetBuffer() << " , " << dest.GetBuffer() << " )\n";
347     const int BUFFERSIZE    = 8192;
348     char buf[ BUFFERSIZE ];
349 
350     FILE* IN_FILE = fopen( source.GetBuffer() , "r" );
351     if( IN_FILE == NULL )
352     {
353         cerr << "Export::CopyFile WARNING: Could not open " << source.GetBuffer() << "\n";
354         return false;
355     }
356 
357     FILE* OUT_FILE = fopen( dest.GetBuffer() , "w" );
358     if( OUT_FILE == NULL )
359     {
360         cerr << "Export::CopyFile WARNING: Could not open/create " << dest.GetBuffer() << " for writing\n";
361         fclose( IN_FILE );
362         return false;
363     }
364 
365     while( fgets( buf , BUFFERSIZE , IN_FILE ) != NULL )
366     {
367         if( fputs( buf , OUT_FILE ) == EOF )
368         {
369             cerr << "Export::CopyFile WARNING: Write problems " << source.GetBuffer() << "\n";
370             fclose( IN_FILE );
371             fclose( OUT_FILE );
372             return false;
373         }
374     }
375     if( ferror( IN_FILE ) )
376     {
377         cerr << "Export::CopyFile WARNING: Read problems " << dest.GetBuffer() << "\n";
378         fclose( IN_FILE );
379         fclose( OUT_FILE );
380         return false;
381     }
382     fclose ( IN_FILE );
383     fclose ( OUT_FILE );
384 
385     return true;
386 }
387 
388 /*****************************************************************************/
389 void Export::UnquotHTML( ByteString &rString )
390 /*****************************************************************************/
391 {
392     ByteString sReturn;
393     while ( rString.Len()) {
394         if ( rString.Copy( 0, 5 ) == "&amp;" ) {
395             sReturn += "&";
396             rString.Erase( 0, 5 );
397         }
398         else if ( rString.Copy( 0, 4 ) == "&lt;" ) {
399             sReturn += "<";
400             rString.Erase( 0, 4 );
401         }
402         else if ( rString.Copy( 0, 4 ) == "&gt;" ) {
403             sReturn += ">";
404             rString.Erase( 0, 4 );
405         }
406         else if ( rString.Copy( 0, 6 ) == "&quot;" ) {
407             sReturn += "\"";
408             rString.Erase( 0, 6 );
409         }
410         else if ( rString.Copy( 0, 6 ) == "&apos;" ) {
411             sReturn += "\'";
412             rString.Erase( 0, 6 );
413         }
414         else {
415             sReturn += rString.GetChar( 0 );
416             rString.Erase( 0, 1 );
417         }
418     }
419     rString = sReturn;
420 }
421 bool Export::isSourceLanguage( const ByteString &sLanguage )
422 {
423     return !isAllowed( sLanguage );
424 }
425 bool Export::isAllowed( const ByteString &sLanguage ){
426     return ! ( sLanguage.EqualsIgnoreCaseAscii("en-US") );
427 }
428 /*****************************************************************************/
429 bool Export::LanguageAllowed( const ByteString &nLanguage )
430 /*****************************************************************************/
431 {
432     return std::find( aLanguages.begin() , aLanguages.end() , nLanguage ) != aLanguages.end();
433 }
434 
435 bool Export::isInitialized = false;
436 
437 /*****************************************************************************/
438 void Export::InitLanguages( bool bMergeMode ){
439 /*****************************************************************************/
440     if( !isInitialized ){
441         ByteString sTmp;
442         ByteStringBoolHashMap aEnvLangs;
443         for ( sal_uInt16 x = 0; x < sLanguages.GetTokenCount( ',' ); x++ ){
444             sTmp = sLanguages.GetToken( x, ',' ).GetToken( 0, '=' );
445             sTmp.EraseLeadingAndTrailingChars();
446             if( bMergeMode && !isAllowed( sTmp ) ){}
447             else if( !( (sTmp.GetChar(0)=='x' || sTmp.GetChar(0)=='X') && sTmp.GetChar(1)=='-' ) ){
448                 aLanguages.push_back( sTmp );
449             }
450         }
451         InitForcedLanguages( bMergeMode );
452         isInitialized = true;
453     }
454 }
455 /*****************************************************************************/
456 void Export::InitForcedLanguages( bool bMergeMode ){
457 /*****************************************************************************/
458     ByteString sTmp;
459     ByteStringBoolHashMap aEnvLangs;
460     for ( sal_uInt16 x = 0; x < sForcedLanguages.GetTokenCount( ',' ); x++ ){
461         sTmp = sForcedLanguages.GetToken( x, ',' ).GetToken( 0, '=' );
462         sTmp.EraseLeadingAndTrailingChars();
463         if( bMergeMode && isAllowed( sTmp ) ){}
464         else if( !( (sTmp.GetChar(0)=='x' || sTmp.GetChar(0)=='X') && sTmp.GetChar(1)=='-' ) )
465             aForcedLanguages.push_back( sTmp );
466     }
467 }
468 
469 /*****************************************************************************/
470 ByteString Export::GetFallbackLanguage( const ByteString nLanguage )
471 /*****************************************************************************/
472 {
473     ByteString sFallback=nLanguage;
474     GetIsoFallback( sFallback );
475     return sFallback;
476 }
477 
478 void Export::replaceEncoding( ByteString& rString )
479 {
480 // &#x2122; -> \u2122
481 
482     for( xub_StrLen idx = 0; idx <= rString.Len()-8 ; idx++ )
483     {
484         if( rString.GetChar( idx )   == '&' &&
485             rString.GetChar( idx+1 ) == '#' &&
486             rString.GetChar( idx+2 ) == 'x' &&
487             rString.GetChar( idx+7 ) == ';' )
488         {
489             ByteString sTmp = rString.Copy( 0 , idx );
490             sTmp.Append( "\\u" );
491             sTmp.Append( rString.GetChar( idx+3 ) );
492             sTmp.Append( rString.GetChar( idx+4 ) );
493             sTmp.Append( rString.GetChar( idx+5 ) );
494             sTmp.Append( rString.GetChar( idx+6 ) );
495             sTmp.Append( rString.Copy( idx+8 , rString.Len() ) );
496             rString = sTmp;
497          }
498     }
499 }
500 
501 /*****************************************************************************/
502 void Export::FillInFallbacks( ResData *pResData )
503 /*****************************************************************************/
504 {
505     ByteString sCur;
506     for( unsigned int n = 0; n < aLanguages.size(); n++ ){
507         sCur = aLanguages[ n ];
508         if( isAllowed( sCur )  ){
509             ByteString nFallbackIndex = GetFallbackLanguage( sCur );
510             if( nFallbackIndex.Len() ){
511                 if ( !pResData->sText[ sCur ].Len())
512                     pResData->sText[ sCur ] =
513                         pResData->sText[ nFallbackIndex ];
514 
515                 if ( !pResData->sHelpText[ sCur ].Len())
516                     pResData->sHelpText[ sCur ] =
517                         pResData->sHelpText[ nFallbackIndex ];
518 
519                 if ( !pResData->sQuickHelpText[ sCur ].Len())
520                     pResData->sQuickHelpText[ sCur ] =
521                         pResData->sQuickHelpText[ nFallbackIndex ];
522 
523                 if ( !pResData->sTitle[ sCur ].Len())
524                     pResData->sTitle[ sCur ] =
525                         pResData->sTitle[ nFallbackIndex ];
526 
527                 if ( pResData->pStringList )
528                     FillInListFallbacks(
529                         pResData->pStringList, sCur, nFallbackIndex );
530 
531                 if ( pResData->pPairedList )
532                     FillInListFallbacks(
533                         pResData->pPairedList, sCur, nFallbackIndex );
534 
535                 if ( pResData->pFilterList )
536                     FillInListFallbacks(
537                         pResData->pFilterList, sCur, nFallbackIndex );
538 
539                 if ( pResData->pItemList )
540                     FillInListFallbacks(
541                         pResData->pItemList, sCur, nFallbackIndex );
542 
543                 if ( pResData->pUIEntries )
544                     FillInListFallbacks(
545                         pResData->pUIEntries, sCur, nFallbackIndex );
546             }
547         }
548     }
549 }
550 
551 /*****************************************************************************/
552 void Export::FillInListFallbacks(
553     ExportList *pList, const ByteString &nSource, const ByteString &nFallback )
554 /*****************************************************************************/
555 {
556 
557     for ( sal_uLong i = 0; i < pList->Count(); i++ ) {
558         ExportListEntry *pEntry = pList->GetObject( i );
559         if ( !( *pEntry )[ nSource ].Len()){
560             ( *pEntry )[ nSource ] = ( *pEntry )[ nFallback ];
561             ByteString x = ( *pEntry )[ nSource ];
562             ByteString y = ( *pEntry )[ nFallback ];
563         }
564     }
565 }
566 
567 /*****************************************************************************/
568 ByteString Export::GetTimeStamp()
569 /*****************************************************************************/
570 {
571 //  return "xx.xx.xx";
572     char buf[20];
573     Time aTime;
574 
575     snprintf(buf, sizeof(buf), "%8d %02d:%02d:%02d", int(Date().GetDate()),
576         int(aTime.GetHour()), int(aTime.GetMin()), int(aTime.GetSec()));
577     return ByteString(buf);
578 }
579 
580 /*****************************************************************************/
581 sal_Bool Export::ConvertLineEnds(
582     ByteString sSource, ByteString sDestination )
583 /*****************************************************************************/
584 {
585     String sSourceFile( sSource, RTL_TEXTENCODING_ASCII_US );
586     String sDestinationFile( sDestination, RTL_TEXTENCODING_ASCII_US );
587 
588     SvFileStream aSource( sSourceFile, STREAM_READ );
589     if ( !aSource.IsOpen())
590         return sal_False;
591     SvFileStream aDestination( sDestinationFile, STREAM_STD_WRITE | STREAM_TRUNC );
592     if ( !aDestination.IsOpen()) {
593         aSource.Close();
594         return sal_False;
595     }
596 
597     ByteString sLine;
598 
599     while ( !aSource.IsEof()) {
600         aSource.ReadLine( sLine );
601         if ( !aSource.IsEof()) {
602             sLine.EraseAllChars( '\r' );
603             aDestination.WriteLine( sLine );
604         }
605         else
606             aDestination.WriteByteString( sLine );
607     }
608 
609     aSource.Close();
610     aDestination.Close();
611 
612     return sal_True;
613 }
614 
615 /*****************************************************************************/
616 ByteString Export::GetNativeFile( ByteString sSource )
617 /*****************************************************************************/
618 {
619     DirEntry aTemp( GetTempFile());
620     ByteString sReturn( aTemp.GetFull(), RTL_TEXTENCODING_ASCII_US );
621 
622     for ( sal_uInt16 i = 0; i < 10; i++ )
623         if ( ConvertLineEnds( sSource, sReturn ))
624             return sReturn;
625 
626     return "";
627 }
628 
629 const char* Export::GetEnv( const char *pVar )
630 {
631         char *pRet = getenv( pVar );
632         if ( !pRet )
633             pRet = 0;
634         return pRet;
635 }
636 
637 
638 int Export::getCurrentDirectory( rtl::OUString& base_fqurl_out, rtl::OUString& base_out )
639 {
640     DirEntry aDir(".");
641     aDir.ToAbs();
642     base_out = rtl::OUString( aDir.GetFull() );
643     return osl::File::getFileURLFromSystemPath( base_out , base_fqurl_out );
644 }
645 
646 void Export::getCurrentDir( string& dir )
647 {
648     char buffer[64000];
649     if( getcwd( buffer , sizeof( buffer ) ) == 0 ){
650         cerr << "Error: getcwd failed!\n";
651         exit( -1 );
652     }
653     dir = string( buffer );
654 }
655 
656 
657 // Stolen from sal/osl/unx/tempfile.c
658 
659 #define RAND_NAME_LENGTH 6
660 
661 void Export::getRandomName( const ByteString& sPrefix , ByteString& sRandStr , const ByteString& sPostfix )
662 {
663     static const char LETTERS[]        = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
664     static const int  COUNT_OF_LETTERS = sizeof(LETTERS)/sizeof(LETTERS[0]) - 1;
665     sRandStr.Append( sPrefix );
666 
667     static sal_uInt64 value;
668     char     buffer[RAND_NAME_LENGTH];
669 
670     TimeValue           tv;
671     sal_uInt64          v;
672     int                 i;
673 
674     osl_getSystemTime( &tv );
675     oslProcessInfo  proInfo;
676     osl_getProcessInfo( 0 , osl_Process_IDENTIFIER , &proInfo );
677 
678     value += ((sal_uInt64) ( tv.Nanosec / 1000 ) << 16) ^ ( tv.Nanosec / 1000 ) ^ proInfo.Ident;
679 
680     v = value;
681 
682     for (i = 0; i < RAND_NAME_LENGTH; i++)
683     {
684         buffer[i] = LETTERS[v % COUNT_OF_LETTERS];
685         v        /= COUNT_OF_LETTERS;
686     }
687 
688     sRandStr.Append( buffer , RAND_NAME_LENGTH );
689     sRandStr.Append( sPostfix );
690 }
691 
692 void Export::getRandomName( ByteString& sRandStr )
693 {
694     const ByteString sEmpty;
695     getRandomName( sEmpty , sRandStr , sEmpty );
696 }
697 
698 /*****************************************************************************/
699 DirEntry Export::GetTempFile()
700 /*****************************************************************************/
701 {
702     rtl::OUString* sTempFilename = new rtl::OUString();
703 
704     // Create a temp file
705     int nRC = osl::FileBase::createTempFile( 0 , 0 , sTempFilename );
706     if( nRC ) printf(" osl::FileBase::createTempFile RC = %d",nRC);
707 
708     String strTmp( *sTempFilename  );
709 
710     INetURLObject::DecodeMechanism eMechanism = INetURLObject::DECODE_TO_IURI;
711     String sDecodedStr = INetURLObject::decode( strTmp , '%' , eMechanism );
712     ByteString sTmp( sDecodedStr , RTL_TEXTENCODING_UTF8 );
713 
714 #if defined(WNT) || defined(OS2)
715     sTmp.SearchAndReplace("file:///","");
716     sTmp.SearchAndReplaceAll('/','\\');
717 #else
718     // Set file permission to 644
719     const sal_uInt64 nPerm = osl_File_Attribute_OwnRead | osl_File_Attribute_OwnWrite |
720                              osl_File_Attribute_GrpRead | osl_File_Attribute_OthRead ;
721 
722     nRC = osl::File::setAttributes( *sTempFilename , nPerm );
723     if( nRC ) printf(" osl::File::setAttributes RC = %d",nRC);
724 
725     sTmp.SearchAndReplace("file://","");
726 #endif
727     DirEntry aDirEntry( sTmp );
728     delete sTempFilename;
729     return aDirEntry;
730 }
731