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 "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>
39*37fbd264SHerbert Dürr #include <boost/shared_ptr.hpp>
40cdf0e10cSrcweir
41cdf0e10cSrcweir using namespace std;
42cdf0e10cSrcweir //
43cdf0e10cSrcweir // class ResData();
44cdf0e10cSrcweir //
45cdf0e10cSrcweir
46cdf0e10cSrcweir /*****************************************************************************/
~ResData()47cdf0e10cSrcweir ResData::~ResData()
48cdf0e10cSrcweir /*****************************************************************************/
49cdf0e10cSrcweir {
50cdf0e10cSrcweir if ( pStringList ) {
51cdf0e10cSrcweir // delete existing res. of type StringList
52cdf0e10cSrcweir for ( sal_uLong i = 0; i < pStringList->Count(); i++ ) {
53cdf0e10cSrcweir ExportListEntry* test = pStringList->GetObject( i );
54cdf0e10cSrcweir if( test != NULL ) delete test;
55cdf0e10cSrcweir }
56cdf0e10cSrcweir delete pStringList;
57cdf0e10cSrcweir }
58cdf0e10cSrcweir if ( pFilterList ) {
59cdf0e10cSrcweir // delete existing res. of type FilterList
60cdf0e10cSrcweir for ( sal_uLong i = 0; i < pFilterList->Count(); i++ ) {
61cdf0e10cSrcweir ExportListEntry* test = pFilterList->GetObject( i );
62cdf0e10cSrcweir delete test;
63cdf0e10cSrcweir }
64cdf0e10cSrcweir delete pFilterList;
65cdf0e10cSrcweir }
66cdf0e10cSrcweir if ( pItemList ) {
67cdf0e10cSrcweir // delete existing res. of type ItemList
68cdf0e10cSrcweir for ( sal_uLong i = 0; i < pItemList->Count(); i++ ) {
69cdf0e10cSrcweir ExportListEntry* test = pItemList->GetObject( i );
70cdf0e10cSrcweir delete test;
71cdf0e10cSrcweir }
72cdf0e10cSrcweir delete pItemList;
73cdf0e10cSrcweir }
74cdf0e10cSrcweir if ( pUIEntries ) {
75cdf0e10cSrcweir // delete existing res. of type UIEntries
76cdf0e10cSrcweir for ( sal_uLong i = 0; i < pUIEntries->Count(); i++ ) {
77cdf0e10cSrcweir ExportListEntry* test = pUIEntries->GetObject( i );
78cdf0e10cSrcweir delete test;
79cdf0e10cSrcweir }
80cdf0e10cSrcweir delete pUIEntries;
81cdf0e10cSrcweir }
82cdf0e10cSrcweir }
83cdf0e10cSrcweir
84cdf0e10cSrcweir //
85cdf0e10cSrcweir // class Export
86cdf0e10cSrcweir //
87cdf0e10cSrcweir
88cdf0e10cSrcweir /*****************************************************************************/
89cdf0e10cSrcweir ByteString Export::sLanguages;
90cdf0e10cSrcweir ByteString Export::sForcedLanguages;
91cdf0e10cSrcweir //ByteString Export::sIsoCode99;
92cdf0e10cSrcweir /*****************************************************************************/
93cdf0e10cSrcweir
DumpExportList(ByteString & sListName,ExportList & aList)94cdf0e10cSrcweir void Export::DumpExportList( ByteString& sListName , ExportList& aList ){
95cdf0e10cSrcweir printf( "%s\n", sListName.GetBuffer() );
96cdf0e10cSrcweir ByteString l("");
97cdf0e10cSrcweir ExportListEntry* aEntry;
98cdf0e10cSrcweir for( unsigned int x = 0; x < aList.Count() ; x++ ){
99cdf0e10cSrcweir aEntry = (ExportListEntry*) aList.GetObject( x );
100cdf0e10cSrcweir Export::DumpMap( l , *aEntry );
101cdf0e10cSrcweir }
102cdf0e10cSrcweir printf("\n");
103cdf0e10cSrcweir }
DumpMap(ByteString & sMapName,ByteStringHashMap & aMap)104cdf0e10cSrcweir ByteString Export::DumpMap( ByteString& sMapName , ByteStringHashMap& aMap ){
105cdf0e10cSrcweir ByteStringHashMap::const_iterator idbg;
106cdf0e10cSrcweir ByteString sReturn;
107cdf0e10cSrcweir
108cdf0e10cSrcweir if( sMapName.Len() )
109cdf0e10cSrcweir printf("MapName %s\n", sMapName.GetBuffer());
110cdf0e10cSrcweir if( aMap.size() < 1 ) return ByteString();
111cdf0e10cSrcweir for( idbg = aMap.begin() ; idbg != aMap.end(); ++idbg ){
112cdf0e10cSrcweir ByteString a( idbg->first );
113cdf0e10cSrcweir ByteString b( idbg->second );
114cdf0e10cSrcweir printf("[%s]= %s",a.GetBuffer(),b.GetBuffer());
115cdf0e10cSrcweir printf("\n");
116cdf0e10cSrcweir }
117cdf0e10cSrcweir printf("\n");
118cdf0e10cSrcweir return sReturn;
119cdf0e10cSrcweir }
120cdf0e10cSrcweir /*****************************************************************************/
SetLanguages(std::vector<ByteString> val)121cdf0e10cSrcweir void Export::SetLanguages( std::vector<ByteString> val ){
122cdf0e10cSrcweir /*****************************************************************************/
123cdf0e10cSrcweir aLanguages = val;
124cdf0e10cSrcweir isInitialized = true;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir /*****************************************************************************/
GetLanguages()127cdf0e10cSrcweir std::vector<ByteString> Export::GetLanguages(){
128cdf0e10cSrcweir /*****************************************************************************/
129cdf0e10cSrcweir return aLanguages;
130cdf0e10cSrcweir }
131cdf0e10cSrcweir /*****************************************************************************/
GetForcedLanguages()132cdf0e10cSrcweir std::vector<ByteString> Export::GetForcedLanguages(){
133cdf0e10cSrcweir /*****************************************************************************/
134cdf0e10cSrcweir return aForcedLanguages;
135cdf0e10cSrcweir }
136cdf0e10cSrcweir std::vector<ByteString> Export::aLanguages = std::vector<ByteString>();
137cdf0e10cSrcweir std::vector<ByteString> Export::aForcedLanguages = std::vector<ByteString>();
138cdf0e10cSrcweir
139cdf0e10cSrcweir
140cdf0e10cSrcweir /*****************************************************************************/
QuotHTMLXRM(ByteString & rString)141cdf0e10cSrcweir void Export::QuotHTMLXRM( ByteString &rString )
142cdf0e10cSrcweir /*****************************************************************************/
143cdf0e10cSrcweir {
144cdf0e10cSrcweir ByteString sReturn;
145cdf0e10cSrcweir //sal_Bool bBreak = sal_False;
146cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < rString.Len(); i++ ) {
147cdf0e10cSrcweir ByteString sTemp = rString.Copy( i );
148cdf0e10cSrcweir if ( sTemp.Search( "<Arg n=" ) == 0 ) {
149cdf0e10cSrcweir while ( i < rString.Len() && rString.GetChar( i ) != '>' ) {
150cdf0e10cSrcweir sReturn += rString.GetChar( i );
151cdf0e10cSrcweir i++;
152cdf0e10cSrcweir }
153cdf0e10cSrcweir if ( rString.GetChar( i ) == '>' ) {
154cdf0e10cSrcweir sReturn += ">";
155cdf0e10cSrcweir i++;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir }
158cdf0e10cSrcweir
159cdf0e10cSrcweir if ( i < rString.Len()) {
160cdf0e10cSrcweir switch ( rString.GetChar( i )) {
161cdf0e10cSrcweir case '<':
162cdf0e10cSrcweir if( i+2 < rString.Len() &&
163cdf0e10cSrcweir (rString.GetChar( i+1 ) == 'b' || rString.GetChar( i+1 ) == 'B') &&
164cdf0e10cSrcweir rString.GetChar( i+2 ) == '>' )
165cdf0e10cSrcweir {
166cdf0e10cSrcweir sReturn +="<b>";
167cdf0e10cSrcweir i += 2;
168cdf0e10cSrcweir }
169cdf0e10cSrcweir else if( i+3 < rString.Len() &&
170cdf0e10cSrcweir rString.GetChar( i+1 ) == '/' &&
171cdf0e10cSrcweir (rString.GetChar( i+2 ) == 'b' || rString.GetChar( i+2 ) == 'B') &&
172cdf0e10cSrcweir rString.GetChar( i+3 ) == '>' )
173cdf0e10cSrcweir {
174cdf0e10cSrcweir sReturn +="</b>";
175cdf0e10cSrcweir i += 3;
176cdf0e10cSrcweir }
177cdf0e10cSrcweir else
178cdf0e10cSrcweir sReturn += "<";
179cdf0e10cSrcweir break;
180cdf0e10cSrcweir
181cdf0e10cSrcweir case '>':
182cdf0e10cSrcweir sReturn += ">";
183cdf0e10cSrcweir break;
184cdf0e10cSrcweir
185cdf0e10cSrcweir case '\"':
186cdf0e10cSrcweir sReturn += """;
187cdf0e10cSrcweir break;
188cdf0e10cSrcweir
189cdf0e10cSrcweir case '\'':
190cdf0e10cSrcweir sReturn += "'";
191cdf0e10cSrcweir break;
192cdf0e10cSrcweir
193cdf0e10cSrcweir case '&':
194cdf0e10cSrcweir if ((( i + 4 ) < rString.Len()) &&
195cdf0e10cSrcweir ( rString.Copy( i, 5 ) == "&" ))
196cdf0e10cSrcweir sReturn += rString.GetChar( i );
197cdf0e10cSrcweir else
198cdf0e10cSrcweir sReturn += "&";
199cdf0e10cSrcweir break;
200cdf0e10cSrcweir
201cdf0e10cSrcweir default:
202cdf0e10cSrcweir sReturn += rString.GetChar( i );
203cdf0e10cSrcweir break;
204cdf0e10cSrcweir }
205cdf0e10cSrcweir }
206cdf0e10cSrcweir }
207cdf0e10cSrcweir rString = sReturn;
208cdf0e10cSrcweir }
209cdf0e10cSrcweir /*****************************************************************************/
QuotHTML(ByteString & rString)210cdf0e10cSrcweir void Export::QuotHTML( ByteString &rString )
211cdf0e10cSrcweir /*****************************************************************************/
212cdf0e10cSrcweir {
213cdf0e10cSrcweir ByteString sReturn;
214cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < rString.Len(); i++ ) {
215cdf0e10cSrcweir ByteString sTemp = rString.Copy( i );
216cdf0e10cSrcweir if ( sTemp.Search( "<Arg n=" ) == 0 ) {
217cdf0e10cSrcweir while ( i < rString.Len() && rString.GetChar( i ) != '>' ) {
218cdf0e10cSrcweir sReturn += rString.GetChar( i );
219cdf0e10cSrcweir i++;
220cdf0e10cSrcweir }
221cdf0e10cSrcweir if ( rString.GetChar( i ) == '>' ) {
222cdf0e10cSrcweir sReturn += ">";
223cdf0e10cSrcweir i++;
224cdf0e10cSrcweir }
225cdf0e10cSrcweir }
226cdf0e10cSrcweir if ( i < rString.Len()) {
227cdf0e10cSrcweir switch ( rString.GetChar( i )) {
228cdf0e10cSrcweir case '<':
229cdf0e10cSrcweir sReturn += "<";
230cdf0e10cSrcweir break;
231cdf0e10cSrcweir
232cdf0e10cSrcweir case '>':
233cdf0e10cSrcweir sReturn += ">";
234cdf0e10cSrcweir break;
235cdf0e10cSrcweir
236cdf0e10cSrcweir case '\"':
237cdf0e10cSrcweir sReturn += """;
238cdf0e10cSrcweir break;
239cdf0e10cSrcweir
240cdf0e10cSrcweir case '\'':
241cdf0e10cSrcweir sReturn += "'";
242cdf0e10cSrcweir break;
243cdf0e10cSrcweir
244cdf0e10cSrcweir case '&':
245cdf0e10cSrcweir if ((( i + 4 ) < rString.Len()) &&
246cdf0e10cSrcweir ( rString.Copy( i, 5 ) == "&" ))
247cdf0e10cSrcweir sReturn += rString.GetChar( i );
248cdf0e10cSrcweir else
249cdf0e10cSrcweir sReturn += "&";
250cdf0e10cSrcweir break;
251cdf0e10cSrcweir
252cdf0e10cSrcweir default:
253cdf0e10cSrcweir sReturn += rString.GetChar( i );
254cdf0e10cSrcweir break;
255cdf0e10cSrcweir }
256cdf0e10cSrcweir }
257cdf0e10cSrcweir }
258cdf0e10cSrcweir rString = sReturn;
259cdf0e10cSrcweir }
260cdf0e10cSrcweir
RemoveUTF8ByteOrderMarker(ByteString & rString)261cdf0e10cSrcweir void Export::RemoveUTF8ByteOrderMarker( ByteString &rString ){
262cdf0e10cSrcweir if( hasUTF8ByteOrderMarker( rString ) )
263cdf0e10cSrcweir rString.Erase( 0 , 3 );
264cdf0e10cSrcweir }
265cdf0e10cSrcweir
hasUTF8ByteOrderMarker(const ByteString & rString)266cdf0e10cSrcweir bool Export::hasUTF8ByteOrderMarker( const ByteString &rString ){
267ab4b560eSHerbert Dürr // UTF-8 BOM: Byte order marker signature
268ab4b560eSHerbert Dürr static const unsigned char bom[3] = { 0xEF, 0xBB, 0xBF };
269cdf0e10cSrcweir
270cdf0e10cSrcweir return rString.Len() >= 3 &&
271cdf0e10cSrcweir rString.GetChar( 0 ) == bom[ 0 ] &&
272cdf0e10cSrcweir rString.GetChar( 1 ) == bom[ 1 ] &&
273cdf0e10cSrcweir rString.GetChar( 2 ) == bom[ 2 ] ;
274cdf0e10cSrcweir }
fileHasUTF8ByteOrderMarker(const ByteString & rString)275cdf0e10cSrcweir bool Export::fileHasUTF8ByteOrderMarker( const ByteString &rString ){
276cdf0e10cSrcweir SvFileStream aFileIn( String( rString , RTL_TEXTENCODING_ASCII_US ) , STREAM_READ );
277cdf0e10cSrcweir ByteString sLine;
278cdf0e10cSrcweir if( !aFileIn.IsEof() ) {
279cdf0e10cSrcweir aFileIn.ReadLine( sLine );
280cdf0e10cSrcweir if( aFileIn.IsOpen() ) aFileIn.Close();
281cdf0e10cSrcweir return hasUTF8ByteOrderMarker( sLine );
282cdf0e10cSrcweir }
283cdf0e10cSrcweir if( aFileIn.IsOpen() ) aFileIn.Close();
284cdf0e10cSrcweir return false;
285cdf0e10cSrcweir }
RemoveUTF8ByteOrderMarkerFromFile(const ByteString & rFilename)286cdf0e10cSrcweir void Export::RemoveUTF8ByteOrderMarkerFromFile( const ByteString &rFilename ){
287cdf0e10cSrcweir SvFileStream aFileIn( String( rFilename , RTL_TEXTENCODING_ASCII_US ) , STREAM_READ );
288cdf0e10cSrcweir ByteString sLine;
289cdf0e10cSrcweir if( !aFileIn.IsEof() ) {
290cdf0e10cSrcweir aFileIn.ReadLine( sLine );
291cdf0e10cSrcweir // Test header
292cdf0e10cSrcweir if( hasUTF8ByteOrderMarker( sLine ) ){
293cdf0e10cSrcweir //cout << "UTF8 Header found!\n";
294cdf0e10cSrcweir DirEntry aTempFile = Export::GetTempFile();
295cdf0e10cSrcweir ByteString sTempFile = ByteString( aTempFile.GetFull() , RTL_TEXTENCODING_ASCII_US );
296cdf0e10cSrcweir SvFileStream aNewFile( String( sTempFile , RTL_TEXTENCODING_ASCII_US ) , STREAM_WRITE );
297cdf0e10cSrcweir // Remove header
298cdf0e10cSrcweir RemoveUTF8ByteOrderMarker( sLine );
299cdf0e10cSrcweir //cout << "Copy stripped stuff to " << sTempFile.GetBuffer() << endl;
300cdf0e10cSrcweir aNewFile.WriteLine( sLine );
301cdf0e10cSrcweir // Copy the rest
302cdf0e10cSrcweir while( !aFileIn.IsEof() ){
303cdf0e10cSrcweir aFileIn.ReadLine( sLine );
304cdf0e10cSrcweir aNewFile.WriteLine( sLine );
305cdf0e10cSrcweir }
306cdf0e10cSrcweir if( aFileIn.IsOpen() ) aFileIn.Close();
307cdf0e10cSrcweir if( aNewFile.IsOpen() ) aNewFile.Close();
308cdf0e10cSrcweir DirEntry aEntry( rFilename.GetBuffer() );
309cdf0e10cSrcweir //cout << "Removing file " << rFilename.GetBuffer() << "\n";
310cdf0e10cSrcweir aEntry.Kill();
311cdf0e10cSrcweir //cout << "Renaming file " << sTempFile.GetBuffer() << " to " << rFilename.GetBuffer() << "\n";
312cdf0e10cSrcweir DirEntry( sTempFile ).MoveTo( DirEntry( rFilename.GetBuffer() ) );
313cdf0e10cSrcweir }
314cdf0e10cSrcweir }
315cdf0e10cSrcweir if( aFileIn.IsOpen() ) aFileIn.Close();
316cdf0e10cSrcweir }
317cdf0e10cSrcweir
318cdf0e10cSrcweir // Merge it into source code!
319cdf0e10cSrcweir //bool Export::isMergingGermanAllowed( const ByteString& rPrj ){
320cdf0e10cSrcweir // (void) rPrj;
321cdf0e10cSrcweir // return true;
322cdf0e10cSrcweir /* static ByteStringBoolHashMap aHash;
323cdf0e10cSrcweir
324cdf0e10cSrcweir if( aHash.find( rPrj ) != aHash.end() ){
325cdf0e10cSrcweir return aHash[ rPrj ];
326cdf0e10cSrcweir }
327cdf0e10cSrcweir
328cdf0e10cSrcweir ByteString sFile = Export::GetEnv( "SRC_ROOT" ) ;
329cdf0e10cSrcweir sFile.Append("/");
330cdf0e10cSrcweir sFile.Append( rPrj );
331cdf0e10cSrcweir sFile.Append("/prj/l10n");
332cdf0e10cSrcweir #if defined(WNT) || defined(OS2)
333cdf0e10cSrcweir sFile.SearchAndReplaceAll('/','\\');
334cdf0e10cSrcweir #endif
335cdf0e10cSrcweir DirEntry aFlagfile( sFile );
336cdf0e10cSrcweir
337cdf0e10cSrcweir aHash[ rPrj ] = !aFlagfile.Exists();
338cdf0e10cSrcweir return aHash[ rPrj ];*/
339cdf0e10cSrcweir //}
CopyFile(const ByteString & source,const ByteString & dest)340cdf0e10cSrcweir bool Export::CopyFile( const ByteString& source , const ByteString& dest )
341cdf0e10cSrcweir {
342cdf0e10cSrcweir // cout << "CopyFile( " << source.GetBuffer() << " , " << dest.GetBuffer() << " )\n";
343cdf0e10cSrcweir FILE* IN_FILE = fopen( source.GetBuffer() , "r" );
344cdf0e10cSrcweir if( IN_FILE == NULL )
345cdf0e10cSrcweir {
346cdf0e10cSrcweir cerr << "Export::CopyFile WARNING: Could not open " << source.GetBuffer() << "\n";
347cdf0e10cSrcweir return false;
348cdf0e10cSrcweir }
349cdf0e10cSrcweir
350cdf0e10cSrcweir FILE* OUT_FILE = fopen( dest.GetBuffer() , "w" );
351cdf0e10cSrcweir if( OUT_FILE == NULL )
352cdf0e10cSrcweir {
353cdf0e10cSrcweir cerr << "Export::CopyFile WARNING: Could not open/create " << dest.GetBuffer() << " for writing\n";
354cdf0e10cSrcweir fclose( IN_FILE );
355cdf0e10cSrcweir return false;
356cdf0e10cSrcweir }
357*37fbd264SHerbert Dürr
358*37fbd264SHerbert Dürr static const int BUFFERSIZE = 0x100000;
359*37fbd264SHerbert Dürr boost::shared_ptr<char> aScopedBuffer( new char[BUFFERSIZE] );
360*37fbd264SHerbert Dürr char* buf = aScopedBuffer.get();
361*37fbd264SHerbert Dürr
362*37fbd264SHerbert Dürr bool bOk = true;
363*37fbd264SHerbert Dürr while( bOk )
364cdf0e10cSrcweir {
365*37fbd264SHerbert Dürr if( feof( IN_FILE ) )
366*37fbd264SHerbert Dürr break;
367*37fbd264SHerbert Dürr const size_t nBytesRead = fread( buf, 1, BUFFERSIZE, IN_FILE );
368*37fbd264SHerbert Dürr if( nBytesRead <= 0 )
369*37fbd264SHerbert Dürr {
370*37fbd264SHerbert Dürr if( ferror( IN_FILE ) )
371*37fbd264SHerbert Dürr {
372*37fbd264SHerbert Dürr cerr << "Export::CopyFile WARNING: Read problems " << dest.GetBuffer() << "\n";
373*37fbd264SHerbert Dürr bOk = false;
374*37fbd264SHerbert Dürr }
375*37fbd264SHerbert Dürr }
376*37fbd264SHerbert Dürr else if( fwrite( buf, 1, nBytesRead, OUT_FILE ) <= 0 )
377cdf0e10cSrcweir {
378cdf0e10cSrcweir cerr << "Export::CopyFile WARNING: Write problems " << source.GetBuffer() << "\n";
379*37fbd264SHerbert Dürr bOk = false;
380cdf0e10cSrcweir }
381cdf0e10cSrcweir }
382cdf0e10cSrcweir fclose ( IN_FILE );
383cdf0e10cSrcweir fclose ( OUT_FILE );
384cdf0e10cSrcweir
385*37fbd264SHerbert Dürr return bOk;
386cdf0e10cSrcweir }
387cdf0e10cSrcweir
388cdf0e10cSrcweir /*****************************************************************************/
UnquotHTML(ByteString & rString)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 }
isSourceLanguage(const ByteString & sLanguage)421cdf0e10cSrcweir bool Export::isSourceLanguage( const ByteString &sLanguage )
422cdf0e10cSrcweir {
423cdf0e10cSrcweir return !isAllowed( sLanguage );
424cdf0e10cSrcweir }
isAllowed(const ByteString & sLanguage)425cdf0e10cSrcweir bool Export::isAllowed( const ByteString &sLanguage ){
426cdf0e10cSrcweir return ! ( sLanguage.EqualsIgnoreCaseAscii("en-US") );
427cdf0e10cSrcweir }
428cdf0e10cSrcweir /*****************************************************************************/
LanguageAllowed(const ByteString & nLanguage)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 /*****************************************************************************/
InitLanguages(bool bMergeMode)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 /*****************************************************************************/
InitForcedLanguages(bool bMergeMode)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 /*****************************************************************************/
GetFallbackLanguage(const ByteString nLanguage)470cdf0e10cSrcweir ByteString Export::GetFallbackLanguage( const ByteString nLanguage )
471cdf0e10cSrcweir /*****************************************************************************/
472cdf0e10cSrcweir {
473cdf0e10cSrcweir ByteString sFallback=nLanguage;
474cdf0e10cSrcweir GetIsoFallback( sFallback );
475cdf0e10cSrcweir return sFallback;
476cdf0e10cSrcweir }
477cdf0e10cSrcweir
replaceEncoding(ByteString & rString)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 /*****************************************************************************/
FillInFallbacks(ResData * pResData)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 /*****************************************************************************/
FillInListFallbacks(ExportList * pList,const ByteString & nSource,const ByteString & nFallback)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 /*****************************************************************************/
GetTimeStamp()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 /*****************************************************************************/
ConvertLineEnds(ByteString sSource,ByteString sDestination)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 /*****************************************************************************/
GetNativeFile(ByteString sSource)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
GetEnv(const char * pVar)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
getCurrentDirectory(rtl::OUString & base_fqurl_out,rtl::OUString & base_out)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
getCurrentDir(string & dir)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
getRandomName(const ByteString & sPrefix,ByteString & sRandStr,const ByteString & sPostfix)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
getRandomName(ByteString & sRandStr)692cdf0e10cSrcweir void Export::getRandomName( ByteString& sRandStr )
693cdf0e10cSrcweir {
694cdf0e10cSrcweir const ByteString sEmpty;
695cdf0e10cSrcweir getRandomName( sEmpty , sRandStr , sEmpty );
696cdf0e10cSrcweir }
697cdf0e10cSrcweir
698cdf0e10cSrcweir /*****************************************************************************/
GetTempFile()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