2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2000-09-18 16:07:07 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 08:39:31 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 08:39:31 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 08:39:31 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 08:39:31 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 08:39:31 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-10 08:39:31 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
2006-09-17 07:17:03 +00:00
|
|
|
|
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
2010-01-25 17:20:55 +01:00
|
|
|
#include "precompiled_l10ntools.hxx"
|
2000-09-18 16:07:07 +00:00
|
|
|
#include "export.hxx"
|
2001-05-30 11:10:22 +00:00
|
|
|
#include "utf8conv.hxx"
|
2001-06-07 12:33:31 +00:00
|
|
|
#include <tools/datetime.hxx>
|
2004-06-25 11:41:02 +00:00
|
|
|
#include <tools/isofallback.hxx>
|
|
|
|
#include <stdio.h>
|
2006-03-29 12:26:35 +00:00
|
|
|
#include <osl/time.h>
|
|
|
|
#include <osl/process.h>
|
2004-06-25 11:41:02 +00:00
|
|
|
#include <rtl/ustring.hxx>
|
2010-10-18 12:28:33 +02:00
|
|
|
#include <sal/macros.h>
|
2004-11-02 15:04:16 +00:00
|
|
|
#include <iostream>
|
2006-03-29 12:26:35 +00:00
|
|
|
#include <iomanip>
|
2005-01-13 18:16:55 +00:00
|
|
|
#include <tools/urlobj.hxx>
|
2006-03-29 12:26:35 +00:00
|
|
|
#include <time.h>
|
2009-11-18 17:50:36 +01:00
|
|
|
#include <stdlib.h>
|
2004-11-02 15:04:16 +00:00
|
|
|
|
|
|
|
using namespace std;
|
2000-09-18 16:07:07 +00:00
|
|
|
//
|
|
|
|
// class ResData();
|
|
|
|
//
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
ResData::~ResData()
|
|
|
|
/*****************************************************************************/
|
|
|
|
{
|
|
|
|
if ( pStringList ) {
|
|
|
|
// delete existing res. of type StringList
|
|
|
|
for ( ULONG i = 0; i < pStringList->Count(); i++ ) {
|
2004-06-25 11:41:02 +00:00
|
|
|
ExportListEntry* test = pStringList->GetObject( i );
|
|
|
|
if( test != NULL ) delete test;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
delete pStringList;
|
|
|
|
}
|
|
|
|
if ( pFilterList ) {
|
|
|
|
// delete existing res. of type FilterList
|
|
|
|
for ( ULONG i = 0; i < pFilterList->Count(); i++ ) {
|
2004-06-25 11:41:02 +00:00
|
|
|
ExportListEntry* test = pFilterList->GetObject( i );
|
|
|
|
delete test;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
delete pFilterList;
|
|
|
|
}
|
|
|
|
if ( pItemList ) {
|
|
|
|
// delete existing res. of type ItemList
|
|
|
|
for ( ULONG i = 0; i < pItemList->Count(); i++ ) {
|
2004-06-25 11:41:02 +00:00
|
|
|
ExportListEntry* test = pItemList->GetObject( i );
|
|
|
|
delete test;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
delete pItemList;
|
|
|
|
}
|
|
|
|
if ( pUIEntries ) {
|
|
|
|
// delete existing res. of type UIEntries
|
|
|
|
for ( ULONG i = 0; i < pUIEntries->Count(); i++ ) {
|
2004-06-25 11:41:02 +00:00
|
|
|
ExportListEntry* test = pUIEntries->GetObject( i );
|
|
|
|
delete test;
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
delete pUIEntries;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// class Export
|
|
|
|
//
|
|
|
|
|
2001-05-23 07:05:40 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
ByteString Export::sLanguages;
|
2004-08-30 16:30:29 +00:00
|
|
|
ByteString Export::sForcedLanguages;
|
2009-11-18 17:50:36 +01:00
|
|
|
//ByteString Export::sIsoCode99;
|
2001-05-23 07:05:40 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
2004-11-18 07:16:51 +00:00
|
|
|
void Export::DumpExportList( ByteString& sListName , ExportList& aList ){
|
|
|
|
printf( "%s\n", sListName.GetBuffer() );
|
|
|
|
ByteString l("");
|
|
|
|
ExportListEntry* aEntry;
|
2006-06-19 16:21:42 +00:00
|
|
|
for( unsigned int x = 0; x < aList.Count() ; x++ ){
|
2004-11-18 07:16:51 +00:00
|
|
|
aEntry = (ExportListEntry*) aList.GetObject( x );
|
|
|
|
Export::DumpMap( l , *aEntry );
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
ByteString Export::DumpMap( ByteString& sMapName , ByteStringHashMap& aMap ){
|
|
|
|
ByteStringHashMap::const_iterator idbg;
|
|
|
|
ByteString sReturn;
|
|
|
|
|
|
|
|
if( sMapName.Len() )
|
|
|
|
printf("MapName %s\n", sMapName.GetBuffer());
|
|
|
|
if( aMap.size() < 1 ) return ByteString();
|
|
|
|
for( idbg = aMap.begin() ; idbg != aMap.end(); ++idbg ){
|
|
|
|
ByteString a( idbg->first );
|
|
|
|
ByteString b( idbg->second );
|
|
|
|
printf("[%s]= %s",a.GetBuffer(),b.GetBuffer());
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
return sReturn;
|
|
|
|
}
|
2000-11-22 11:57:00 +00:00
|
|
|
/*****************************************************************************/
|
2004-06-25 11:41:02 +00:00
|
|
|
void Export::SetLanguages( std::vector<ByteString> val ){
|
|
|
|
/*****************************************************************************/
|
|
|
|
aLanguages = val;
|
|
|
|
isInitialized = true;
|
|
|
|
}
|
|
|
|
/*****************************************************************************/
|
|
|
|
std::vector<ByteString> Export::GetLanguages(){
|
|
|
|
/*****************************************************************************/
|
|
|
|
return aLanguages;
|
|
|
|
}
|
2004-08-30 16:30:29 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
std::vector<ByteString> Export::GetForcedLanguages(){
|
|
|
|
/*****************************************************************************/
|
|
|
|
return aForcedLanguages;
|
|
|
|
}
|
|
|
|
std::vector<ByteString> Export::aLanguages = std::vector<ByteString>();
|
|
|
|
std::vector<ByteString> Export::aForcedLanguages = std::vector<ByteString>();
|
2000-11-22 11:57:00 +00:00
|
|
|
|
|
|
|
|
2006-12-12 14:52:30 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
void Export::QuotHTMLXRM( ByteString &rString )
|
|
|
|
/*****************************************************************************/
|
|
|
|
{
|
|
|
|
ByteString sReturn;
|
|
|
|
//BOOL bBreak = FALSE;
|
|
|
|
for ( USHORT i = 0; i < rString.Len(); i++ ) {
|
|
|
|
ByteString sTemp = rString.Copy( i );
|
|
|
|
if ( sTemp.Search( "<Arg n=" ) == 0 ) {
|
|
|
|
while ( i < rString.Len() && rString.GetChar( i ) != '>' ) {
|
|
|
|
sReturn += rString.GetChar( i );
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if ( rString.GetChar( i ) == '>' ) {
|
|
|
|
sReturn += ">";
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( i < rString.Len()) {
|
|
|
|
switch ( rString.GetChar( i )) {
|
|
|
|
case '<':
|
|
|
|
if( i+2 < rString.Len() &&
|
2009-03-14 17:15:26 +00:00
|
|
|
(rString.GetChar( i+1 ) == 'b' || rString.GetChar( i+1 ) == 'B') &&
|
|
|
|
rString.GetChar( i+2 ) == '>' )
|
2006-12-12 14:52:30 +00:00
|
|
|
{
|
|
|
|
sReturn +="<b>";
|
|
|
|
i += 2;
|
|
|
|
}
|
|
|
|
else if( i+3 < rString.Len() &&
|
|
|
|
rString.GetChar( i+1 ) == '/' &&
|
2009-03-14 17:15:26 +00:00
|
|
|
(rString.GetChar( i+2 ) == 'b' || rString.GetChar( i+2 ) == 'B') &&
|
2006-12-12 14:52:30 +00:00
|
|
|
rString.GetChar( i+3 ) == '>' )
|
|
|
|
{
|
|
|
|
sReturn +="</b>";
|
|
|
|
i += 3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
sReturn += "<";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '>':
|
|
|
|
sReturn += ">";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '\"':
|
|
|
|
sReturn += """;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '\'':
|
|
|
|
sReturn += "'";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '&':
|
|
|
|
if ((( i + 4 ) < rString.Len()) &&
|
|
|
|
( rString.Copy( i, 5 ) == "&" ))
|
|
|
|
sReturn += rString.GetChar( i );
|
|
|
|
else
|
|
|
|
sReturn += "&";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
sReturn += rString.GetChar( i );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rString = sReturn;
|
|
|
|
}
|
2000-11-22 11:57:00 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
void Export::QuotHTML( ByteString &rString )
|
|
|
|
/*****************************************************************************/
|
|
|
|
{
|
|
|
|
ByteString sReturn;
|
2001-10-15 13:46:07 +00:00
|
|
|
for ( USHORT i = 0; i < rString.Len(); i++ ) {
|
2000-12-08 11:49:25 +00:00
|
|
|
ByteString sTemp = rString.Copy( i );
|
|
|
|
if ( sTemp.Search( "<Arg n=" ) == 0 ) {
|
2000-12-18 10:49:11 +00:00
|
|
|
while ( i < rString.Len() && rString.GetChar( i ) != '>' ) {
|
2000-12-08 11:49:25 +00:00
|
|
|
sReturn += rString.GetChar( i );
|
|
|
|
i++;
|
|
|
|
}
|
2000-12-18 10:49:11 +00:00
|
|
|
if ( rString.GetChar( i ) == '>' ) {
|
|
|
|
sReturn += ">";
|
|
|
|
i++;
|
|
|
|
}
|
2000-12-08 11:49:25 +00:00
|
|
|
}
|
|
|
|
if ( i < rString.Len()) {
|
|
|
|
switch ( rString.GetChar( i )) {
|
|
|
|
case '<':
|
|
|
|
sReturn += "<";
|
|
|
|
break;
|
2000-11-22 11:57:00 +00:00
|
|
|
|
2000-12-08 11:49:25 +00:00
|
|
|
case '>':
|
|
|
|
sReturn += ">";
|
|
|
|
break;
|
2000-11-22 11:57:00 +00:00
|
|
|
|
2000-12-08 11:49:25 +00:00
|
|
|
case '\"':
|
|
|
|
sReturn += """;
|
|
|
|
break;
|
2000-11-22 11:57:00 +00:00
|
|
|
|
2000-12-08 11:49:25 +00:00
|
|
|
case '\'':
|
|
|
|
sReturn += "'";
|
|
|
|
break;
|
2000-11-22 11:57:00 +00:00
|
|
|
|
2000-12-08 11:49:25 +00:00
|
|
|
case '&':
|
|
|
|
if ((( i + 4 ) < rString.Len()) &&
|
|
|
|
( rString.Copy( i, 5 ) == "&" ))
|
|
|
|
sReturn += rString.GetChar( i );
|
|
|
|
else
|
|
|
|
sReturn += "&";
|
|
|
|
break;
|
2000-11-22 11:57:00 +00:00
|
|
|
|
2000-12-08 11:49:25 +00:00
|
|
|
default:
|
|
|
|
sReturn += rString.GetChar( i );
|
|
|
|
break;
|
|
|
|
}
|
2000-11-22 11:57:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
rString = sReturn;
|
|
|
|
}
|
|
|
|
|
2004-11-02 15:04:16 +00:00
|
|
|
void Export::RemoveUTF8ByteOrderMarker( ByteString &rString ){
|
|
|
|
if( hasUTF8ByteOrderMarker( rString ) )
|
|
|
|
rString.Erase( 0 , 3 );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Export::hasUTF8ByteOrderMarker( const ByteString &rString ){
|
|
|
|
// Byte order marker signature
|
2006-06-19 16:21:42 +00:00
|
|
|
|
|
|
|
const unsigned char c1 = 0xEF;
|
|
|
|
const unsigned char c2 = 0xBB;
|
|
|
|
const unsigned char c3 = 0xBF;
|
|
|
|
|
|
|
|
const char bom[ 3 ] = { c1 , c2 , c3 };
|
2004-11-02 15:04:16 +00:00
|
|
|
|
|
|
|
return rString.Len() >= 3 &&
|
|
|
|
rString.GetChar( 0 ) == bom[ 0 ] &&
|
|
|
|
rString.GetChar( 1 ) == bom[ 1 ] &&
|
|
|
|
rString.GetChar( 2 ) == bom[ 2 ] ;
|
|
|
|
}
|
|
|
|
bool Export::fileHasUTF8ByteOrderMarker( const ByteString &rString ){
|
|
|
|
SvFileStream aFileIn( String( rString , RTL_TEXTENCODING_ASCII_US ) , STREAM_READ );
|
|
|
|
ByteString sLine;
|
|
|
|
if( !aFileIn.IsEof() ) {
|
|
|
|
aFileIn.ReadLine( sLine );
|
|
|
|
if( aFileIn.IsOpen() ) aFileIn.Close();
|
|
|
|
return hasUTF8ByteOrderMarker( sLine );
|
|
|
|
}
|
|
|
|
if( aFileIn.IsOpen() ) aFileIn.Close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
void Export::RemoveUTF8ByteOrderMarkerFromFile( const ByteString &rFilename ){
|
|
|
|
SvFileStream aFileIn( String( rFilename , RTL_TEXTENCODING_ASCII_US ) , STREAM_READ );
|
|
|
|
ByteString sLine;
|
|
|
|
if( !aFileIn.IsEof() ) {
|
|
|
|
aFileIn.ReadLine( sLine );
|
|
|
|
// Test header
|
|
|
|
if( hasUTF8ByteOrderMarker( sLine ) ){
|
|
|
|
//cout << "UTF8 Header found!\n";
|
|
|
|
DirEntry aTempFile = Export::GetTempFile();
|
|
|
|
ByteString sTempFile = ByteString( aTempFile.GetFull() , RTL_TEXTENCODING_ASCII_US );
|
|
|
|
SvFileStream aNewFile( String( sTempFile , RTL_TEXTENCODING_ASCII_US ) , STREAM_WRITE );
|
|
|
|
// Remove header
|
|
|
|
RemoveUTF8ByteOrderMarker( sLine );
|
|
|
|
//cout << "Copy stripped stuff to " << sTempFile.GetBuffer() << endl;
|
|
|
|
aNewFile.WriteLine( sLine );
|
|
|
|
// Copy the rest
|
|
|
|
while( !aFileIn.IsEof() ){
|
|
|
|
aFileIn.ReadLine( sLine );
|
|
|
|
aNewFile.WriteLine( sLine );
|
|
|
|
}
|
|
|
|
if( aFileIn.IsOpen() ) aFileIn.Close();
|
|
|
|
if( aNewFile.IsOpen() ) aNewFile.Close();
|
|
|
|
DirEntry aEntry( rFilename.GetBuffer() );
|
|
|
|
//cout << "Removing file " << rFilename.GetBuffer() << "\n";
|
|
|
|
aEntry.Kill();
|
|
|
|
//cout << "Renaming file " << sTempFile.GetBuffer() << " to " << rFilename.GetBuffer() << "\n";
|
|
|
|
DirEntry( sTempFile ).MoveTo( DirEntry( rFilename.GetBuffer() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( aFileIn.IsOpen() ) aFileIn.Close();
|
|
|
|
}
|
2005-06-06 15:24:48 +00:00
|
|
|
|
|
|
|
// Merge it into source code!
|
2007-04-19 14:18:36 +00:00
|
|
|
//bool Export::isMergingGermanAllowed( const ByteString& rPrj ){
|
|
|
|
// (void) rPrj;
|
|
|
|
// return true;
|
|
|
|
/* static ByteStringBoolHashMap aHash;
|
2005-09-23 13:29:55 +00:00
|
|
|
|
|
|
|
if( aHash.find( rPrj ) != aHash.end() ){
|
|
|
|
return aHash[ rPrj ];
|
|
|
|
}
|
|
|
|
|
2006-08-14 16:09:50 +00:00
|
|
|
ByteString sFile = Export::GetEnv( "SRC_ROOT" ) ;
|
2005-06-06 15:24:48 +00:00
|
|
|
sFile.Append("/");
|
|
|
|
sFile.Append( rPrj );
|
|
|
|
sFile.Append("/prj/l10n");
|
2007-09-20 14:02:34 +00:00
|
|
|
#if defined(WNT) || defined(OS2)
|
2005-06-06 15:24:48 +00:00
|
|
|
sFile.SearchAndReplaceAll('/','\\');
|
|
|
|
#endif
|
|
|
|
DirEntry aFlagfile( sFile );
|
2005-09-23 13:29:55 +00:00
|
|
|
|
|
|
|
aHash[ rPrj ] = !aFlagfile.Exists();
|
2007-04-19 14:18:36 +00:00
|
|
|
return aHash[ rPrj ];*/
|
|
|
|
//}
|
2008-02-05 11:55:28 +00:00
|
|
|
bool Export::CopyFile( const ByteString& source , const ByteString& dest )
|
|
|
|
{
|
|
|
|
// cout << "CopyFile( " << source.GetBuffer() << " , " << dest.GetBuffer() << " )\n";
|
|
|
|
const int BUFFERSIZE = 8192;
|
|
|
|
char buf[ BUFFERSIZE ];
|
|
|
|
|
2010-01-12 13:06:48 +00:00
|
|
|
FILE* IN_FILE = fopen( source.GetBuffer() , "r" );
|
2008-02-05 11:55:28 +00:00
|
|
|
if( IN_FILE == NULL )
|
|
|
|
{
|
|
|
|
cerr << "Export::CopyFile WARNING: Could not open " << source.GetBuffer() << "\n";
|
|
|
|
return false;
|
|
|
|
}
|
2010-01-12 13:06:48 +00:00
|
|
|
|
|
|
|
FILE* OUT_FILE = fopen( dest.GetBuffer() , "w" );
|
2008-02-05 11:55:28 +00:00
|
|
|
if( OUT_FILE == NULL )
|
|
|
|
{
|
|
|
|
cerr << "Export::CopyFile WARNING: Could not open/create " << dest.GetBuffer() << " for writing\n";
|
2010-01-12 13:06:48 +00:00
|
|
|
fclose( IN_FILE );
|
2008-02-05 11:55:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
while( fgets( buf , BUFFERSIZE , IN_FILE ) != NULL )
|
|
|
|
{
|
|
|
|
if( fputs( buf , OUT_FILE ) == EOF )
|
|
|
|
{
|
|
|
|
cerr << "Export::CopyFile WARNING: Write problems " << source.GetBuffer() << "\n";
|
|
|
|
fclose( IN_FILE );
|
|
|
|
fclose( OUT_FILE );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( ferror( IN_FILE ) )
|
|
|
|
{
|
|
|
|
cerr << "Export::CopyFile WARNING: Read problems " << dest.GetBuffer() << "\n";
|
|
|
|
fclose( IN_FILE );
|
|
|
|
fclose( OUT_FILE );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
fclose ( IN_FILE );
|
|
|
|
fclose ( OUT_FILE );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2000-11-22 11:57:00 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
void Export::UnquotHTML( ByteString &rString )
|
|
|
|
/*****************************************************************************/
|
|
|
|
{
|
|
|
|
ByteString sReturn;
|
|
|
|
while ( rString.Len()) {
|
|
|
|
if ( rString.Copy( 0, 5 ) == "&" ) {
|
|
|
|
sReturn += "&";
|
|
|
|
rString.Erase( 0, 5 );
|
|
|
|
}
|
|
|
|
else if ( rString.Copy( 0, 4 ) == "<" ) {
|
|
|
|
sReturn += "<";
|
|
|
|
rString.Erase( 0, 4 );
|
|
|
|
}
|
|
|
|
else if ( rString.Copy( 0, 4 ) == ">" ) {
|
|
|
|
sReturn += ">";
|
|
|
|
rString.Erase( 0, 4 );
|
|
|
|
}
|
|
|
|
else if ( rString.Copy( 0, 6 ) == """ ) {
|
|
|
|
sReturn += "\"";
|
|
|
|
rString.Erase( 0, 6 );
|
|
|
|
}
|
|
|
|
else if ( rString.Copy( 0, 6 ) == "'" ) {
|
|
|
|
sReturn += "\'";
|
|
|
|
rString.Erase( 0, 6 );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sReturn += rString.GetChar( 0 );
|
|
|
|
rString.Erase( 0, 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rString = sReturn;
|
|
|
|
}
|
2007-04-19 14:18:36 +00:00
|
|
|
bool Export::isSourceLanguage( const ByteString &sLanguage )
|
|
|
|
{
|
|
|
|
return !isAllowed( sLanguage );
|
|
|
|
}
|
2006-06-19 16:21:42 +00:00
|
|
|
bool Export::isAllowed( const ByteString &sLanguage ){
|
2007-04-19 14:18:36 +00:00
|
|
|
return ! ( sLanguage.EqualsIgnoreCaseAscii("en-US") );
|
2005-09-23 13:29:55 +00:00
|
|
|
}
|
2000-11-22 11:57:00 +00:00
|
|
|
/*****************************************************************************/
|
2004-06-25 11:41:02 +00:00
|
|
|
bool Export::LanguageAllowed( const ByteString &nLanguage )
|
2000-11-22 11:57:00 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
{
|
2004-06-25 11:41:02 +00:00
|
|
|
return std::find( aLanguages.begin() , aLanguages.end() , nLanguage ) != aLanguages.end();
|
|
|
|
}
|
2001-05-23 07:05:40 +00:00
|
|
|
|
2004-06-25 11:41:02 +00:00
|
|
|
bool Export::isInitialized = false;
|
2001-05-23 07:05:40 +00:00
|
|
|
|
2004-06-25 11:41:02 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
void Export::InitLanguages( bool bMergeMode ){
|
|
|
|
/*****************************************************************************/
|
2004-11-02 15:04:16 +00:00
|
|
|
if( !isInitialized ){
|
|
|
|
ByteString sTmp;
|
|
|
|
ByteStringBoolHashMap aEnvLangs;
|
|
|
|
for ( USHORT x = 0; x < sLanguages.GetTokenCount( ',' ); x++ ){
|
|
|
|
sTmp = sLanguages.GetToken( x, ',' ).GetToken( 0, '=' );
|
|
|
|
sTmp.EraseLeadingAndTrailingChars();
|
2005-09-23 13:29:55 +00:00
|
|
|
if( bMergeMode && !isAllowed( sTmp ) ){}
|
2004-11-02 15:04:16 +00:00
|
|
|
else if( !( (sTmp.GetChar(0)=='x' || sTmp.GetChar(0)=='X') && sTmp.GetChar(1)=='-' ) ){
|
|
|
|
aLanguages.push_back( sTmp );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
InitForcedLanguages( bMergeMode );
|
|
|
|
isInitialized = true;
|
2004-06-25 11:41:02 +00:00
|
|
|
}
|
2001-05-23 07:05:40 +00:00
|
|
|
}
|
2004-08-30 16:30:29 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
void Export::InitForcedLanguages( bool bMergeMode ){
|
|
|
|
/*****************************************************************************/
|
|
|
|
ByteString sTmp;
|
|
|
|
ByteStringBoolHashMap aEnvLangs;
|
|
|
|
for ( USHORT x = 0; x < sForcedLanguages.GetTokenCount( ',' ); x++ ){
|
|
|
|
sTmp = sForcedLanguages.GetToken( x, ',' ).GetToken( 0, '=' );
|
|
|
|
sTmp.EraseLeadingAndTrailingChars();
|
2005-09-23 13:29:55 +00:00
|
|
|
if( bMergeMode && isAllowed( sTmp ) ){}
|
2004-08-30 16:30:29 +00:00
|
|
|
else if( !( (sTmp.GetChar(0)=='x' || sTmp.GetChar(0)=='X') && sTmp.GetChar(1)=='-' ) )
|
|
|
|
aForcedLanguages.push_back( sTmp );
|
|
|
|
}
|
|
|
|
}
|
2004-06-25 11:41:02 +00:00
|
|
|
|
2001-05-28 07:25:29 +00:00
|
|
|
/*****************************************************************************/
|
2004-06-25 11:41:02 +00:00
|
|
|
ByteString Export::GetFallbackLanguage( const ByteString nLanguage )
|
2001-05-28 07:25:29 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
{
|
2004-06-25 11:41:02 +00:00
|
|
|
ByteString sFallback=nLanguage;
|
|
|
|
GetIsoFallback( sFallback );
|
|
|
|
return sFallback;
|
2001-05-28 07:25:29 +00:00
|
|
|
}
|
|
|
|
|
2008-02-12 12:10:06 +00:00
|
|
|
void Export::replaceEncoding( ByteString& rString )
|
|
|
|
{
|
|
|
|
// ™ -> \u2122
|
|
|
|
|
2008-02-13 14:09:24 +00:00
|
|
|
for( xub_StrLen idx = 0; idx <= rString.Len()-8 ; idx++ )
|
2008-02-12 12:10:06 +00:00
|
|
|
{
|
|
|
|
if( rString.GetChar( idx ) == '&' &&
|
|
|
|
rString.GetChar( idx+1 ) == '#' &&
|
|
|
|
rString.GetChar( idx+2 ) == 'x' &&
|
|
|
|
rString.GetChar( idx+7 ) == ';' )
|
|
|
|
{
|
|
|
|
ByteString sTmp = rString.Copy( 0 , idx );
|
|
|
|
sTmp.Append( "\\u" );
|
|
|
|
sTmp.Append( rString.GetChar( idx+3 ) );
|
|
|
|
sTmp.Append( rString.GetChar( idx+4 ) );
|
|
|
|
sTmp.Append( rString.GetChar( idx+5 ) );
|
|
|
|
sTmp.Append( rString.GetChar( idx+6 ) );
|
|
|
|
sTmp.Append( rString.Copy( idx+8 , rString.Len() ) );
|
|
|
|
rString = sTmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-28 07:25:29 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
void Export::FillInFallbacks( ResData *pResData )
|
|
|
|
/*****************************************************************************/
|
|
|
|
{
|
2004-06-25 11:41:02 +00:00
|
|
|
ByteString sCur;
|
2006-06-19 16:21:42 +00:00
|
|
|
for( unsigned int n = 0; n < aLanguages.size(); n++ ){
|
2004-06-25 11:41:02 +00:00
|
|
|
sCur = aLanguages[ n ];
|
2005-09-23 13:29:55 +00:00
|
|
|
if( isAllowed( sCur ) ){
|
2004-06-25 11:41:02 +00:00
|
|
|
ByteString nFallbackIndex = GetFallbackLanguage( sCur );
|
|
|
|
if( nFallbackIndex.Len() ){
|
|
|
|
if ( !pResData->sText[ sCur ].Len())
|
|
|
|
pResData->sText[ sCur ] =
|
|
|
|
pResData->sText[ nFallbackIndex ];
|
|
|
|
|
|
|
|
if ( !pResData->sHelpText[ sCur ].Len())
|
|
|
|
pResData->sHelpText[ sCur ] =
|
|
|
|
pResData->sHelpText[ nFallbackIndex ];
|
|
|
|
|
|
|
|
if ( !pResData->sQuickHelpText[ sCur ].Len())
|
|
|
|
pResData->sQuickHelpText[ sCur ] =
|
|
|
|
pResData->sQuickHelpText[ nFallbackIndex ];
|
|
|
|
|
|
|
|
if ( !pResData->sTitle[ sCur ].Len())
|
|
|
|
pResData->sTitle[ sCur ] =
|
|
|
|
pResData->sTitle[ nFallbackIndex ];
|
2001-05-28 07:25:29 +00:00
|
|
|
|
|
|
|
if ( pResData->pStringList )
|
|
|
|
FillInListFallbacks(
|
2004-06-25 11:41:02 +00:00
|
|
|
pResData->pStringList, sCur, nFallbackIndex );
|
|
|
|
|
2004-11-18 07:16:51 +00:00
|
|
|
if ( pResData->pPairedList )
|
|
|
|
FillInListFallbacks(
|
|
|
|
pResData->pPairedList, sCur, nFallbackIndex );
|
|
|
|
|
2001-05-28 07:25:29 +00:00
|
|
|
if ( pResData->pFilterList )
|
|
|
|
FillInListFallbacks(
|
2004-06-25 11:41:02 +00:00
|
|
|
pResData->pFilterList, sCur, nFallbackIndex );
|
|
|
|
|
2001-05-28 07:25:29 +00:00
|
|
|
if ( pResData->pItemList )
|
|
|
|
FillInListFallbacks(
|
2004-06-25 11:41:02 +00:00
|
|
|
pResData->pItemList, sCur, nFallbackIndex );
|
|
|
|
|
2001-05-28 07:25:29 +00:00
|
|
|
if ( pResData->pUIEntries )
|
|
|
|
FillInListFallbacks(
|
2004-06-25 11:41:02 +00:00
|
|
|
pResData->pUIEntries, sCur, nFallbackIndex );
|
2001-05-28 07:25:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
void Export::FillInListFallbacks(
|
2004-06-25 11:41:02 +00:00
|
|
|
ExportList *pList, const ByteString &nSource, const ByteString &nFallback )
|
2001-05-28 07:25:29 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
{
|
2001-05-30 11:10:22 +00:00
|
|
|
|
2001-05-28 07:25:29 +00:00
|
|
|
for ( ULONG i = 0; i < pList->Count(); i++ ) {
|
|
|
|
ExportListEntry *pEntry = pList->GetObject( i );
|
2004-11-18 07:16:51 +00:00
|
|
|
if ( !( *pEntry )[ nSource ].Len()){
|
2004-06-25 11:41:02 +00:00
|
|
|
( *pEntry )[ nSource ] = ( *pEntry )[ nFallback ];
|
2004-11-18 07:16:51 +00:00
|
|
|
ByteString x = ( *pEntry )[ nSource ];
|
|
|
|
ByteString y = ( *pEntry )[ nFallback ];
|
|
|
|
}
|
2001-05-28 07:25:29 +00:00
|
|
|
}
|
|
|
|
}
|
2001-06-07 12:33:31 +00:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
ByteString Export::GetTimeStamp()
|
|
|
|
/*****************************************************************************/
|
|
|
|
{
|
|
|
|
// return "xx.xx.xx";
|
2004-06-25 11:41:02 +00:00
|
|
|
char buf[20];
|
|
|
|
Time aTime;
|
2001-06-07 12:33:31 +00:00
|
|
|
|
2006-06-19 16:21:42 +00:00
|
|
|
snprintf(buf, sizeof(buf), "%8d %02d:%02d:%02d", int(Date().GetDate()),
|
|
|
|
int(aTime.GetHour()), int(aTime.GetMin()), int(aTime.GetSec()));
|
2004-06-25 11:41:02 +00:00
|
|
|
return ByteString(buf);
|
2001-06-07 12:33:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
BOOL Export::ConvertLineEnds(
|
|
|
|
ByteString sSource, ByteString sDestination )
|
|
|
|
/*****************************************************************************/
|
|
|
|
{
|
|
|
|
String sSourceFile( sSource, RTL_TEXTENCODING_ASCII_US );
|
|
|
|
String sDestinationFile( sDestination, RTL_TEXTENCODING_ASCII_US );
|
|
|
|
|
|
|
|
SvFileStream aSource( sSourceFile, STREAM_READ );
|
|
|
|
if ( !aSource.IsOpen())
|
|
|
|
return FALSE;
|
|
|
|
SvFileStream aDestination( sDestinationFile, STREAM_STD_WRITE | STREAM_TRUNC );
|
|
|
|
if ( !aDestination.IsOpen()) {
|
|
|
|
aSource.Close();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ByteString sLine;
|
|
|
|
|
|
|
|
while ( !aSource.IsEof()) {
|
|
|
|
aSource.ReadLine( sLine );
|
2002-01-14 13:11:04 +00:00
|
|
|
if ( !aSource.IsEof()) {
|
|
|
|
sLine.EraseAllChars( '\r' );
|
|
|
|
aDestination.WriteLine( sLine );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
aDestination.WriteByteString( sLine );
|
2001-06-07 12:33:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
aSource.Close();
|
|
|
|
aDestination.Close();
|
2001-10-15 13:41:01 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2001-06-07 12:33:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
ByteString Export::GetNativeFile( ByteString sSource )
|
|
|
|
/*****************************************************************************/
|
|
|
|
{
|
|
|
|
DirEntry aTemp( GetTempFile());
|
|
|
|
ByteString sReturn( aTemp.GetFull(), RTL_TEXTENCODING_ASCII_US );
|
|
|
|
|
2001-06-11 12:49:22 +00:00
|
|
|
for ( USHORT i = 0; i < 10; i++ )
|
|
|
|
if ( ConvertLineEnds( sSource, sReturn ))
|
|
|
|
return sReturn;
|
2001-06-07 12:33:31 +00:00
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2006-08-14 16:09:50 +00:00
|
|
|
const char* Export::GetEnv( const char *pVar )
|
|
|
|
{
|
|
|
|
char *pRet = getenv( pVar );
|
|
|
|
if ( !pRet )
|
|
|
|
pRet = 0;
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-29 12:26:35 +00:00
|
|
|
int Export::getCurrentDirectory( rtl::OUString& base_fqurl_out, rtl::OUString& base_out )
|
|
|
|
{
|
|
|
|
DirEntry aDir(".");
|
|
|
|
aDir.ToAbs();
|
|
|
|
base_out = rtl::OUString( aDir.GetFull() );
|
|
|
|
return osl::File::getFileURLFromSystemPath( base_out , base_fqurl_out );
|
|
|
|
}
|
|
|
|
|
2009-11-18 17:50:36 +01:00
|
|
|
void Export::getCurrentDir( string& dir )
|
|
|
|
{
|
|
|
|
char buffer[64000];
|
|
|
|
if( getcwd( buffer , sizeof( buffer ) ) == 0 ){
|
|
|
|
cerr << "Error: getcwd failed!\n";
|
|
|
|
exit( -1 );
|
|
|
|
}
|
|
|
|
dir = string( buffer );
|
|
|
|
}
|
|
|
|
|
2006-03-29 12:26:35 +00:00
|
|
|
|
|
|
|
// Stolen from sal/osl/unx/tempfile.c
|
|
|
|
|
|
|
|
#define RAND_NAME_LENGTH 6
|
|
|
|
|
|
|
|
void Export::getRandomName( const ByteString& sPrefix , ByteString& sRandStr , const ByteString& sPostfix )
|
|
|
|
{
|
|
|
|
static const char LETTERS[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
|
2010-10-18 12:28:33 +02:00
|
|
|
static const int COUNT_OF_LETTERS = SAL_N_ELEMENTS(LETTERS) - 1;
|
2006-03-29 12:26:35 +00:00
|
|
|
sRandStr.Append( sPrefix );
|
|
|
|
|
|
|
|
static sal_uInt64 value;
|
|
|
|
char buffer[RAND_NAME_LENGTH];
|
|
|
|
|
|
|
|
TimeValue tv;
|
|
|
|
sal_uInt64 v;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
osl_getSystemTime( &tv );
|
2010-12-30 20:51:41 +00:00
|
|
|
oslProcessInfo proInfo;
|
|
|
|
proInfo.Size = sizeof(oslProcessInfo);
|
2006-03-29 12:26:35 +00:00
|
|
|
osl_getProcessInfo( 0 , osl_Process_IDENTIFIER , &proInfo );
|
|
|
|
|
|
|
|
value += ((sal_uInt64) ( tv.Nanosec / 1000 ) << 16) ^ ( tv.Nanosec / 1000 ) ^ proInfo.Ident;
|
|
|
|
|
|
|
|
v = value;
|
|
|
|
|
|
|
|
for (i = 0; i < RAND_NAME_LENGTH; i++)
|
|
|
|
{
|
|
|
|
buffer[i] = LETTERS[v % COUNT_OF_LETTERS];
|
|
|
|
v /= COUNT_OF_LETTERS;
|
|
|
|
}
|
|
|
|
|
|
|
|
sRandStr.Append( buffer , RAND_NAME_LENGTH );
|
|
|
|
sRandStr.Append( sPostfix );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Export::getRandomName( ByteString& sRandStr )
|
|
|
|
{
|
|
|
|
const ByteString sEmpty;
|
|
|
|
getRandomName( sEmpty , sRandStr , sEmpty );
|
|
|
|
}
|
|
|
|
|
2001-06-07 12:33:31 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
DirEntry Export::GetTempFile()
|
|
|
|
/*****************************************************************************/
|
|
|
|
{
|
2004-06-25 11:41:02 +00:00
|
|
|
rtl::OUString* sTempFilename = new rtl::OUString();
|
2005-01-13 18:16:55 +00:00
|
|
|
|
|
|
|
// Create a temp file
|
2004-06-25 11:41:02 +00:00
|
|
|
int nRC = osl::FileBase::createTempFile( 0 , 0 , sTempFilename );
|
|
|
|
if( nRC ) printf(" osl::FileBase::createTempFile RC = %d",nRC);
|
2005-01-13 18:16:55 +00:00
|
|
|
|
|
|
|
String strTmp( *sTempFilename );
|
|
|
|
|
|
|
|
INetURLObject::DecodeMechanism eMechanism = INetURLObject::DECODE_TO_IURI;
|
|
|
|
String sDecodedStr = INetURLObject::decode( strTmp , '%' , eMechanism );
|
|
|
|
ByteString sTmp( sDecodedStr , RTL_TEXTENCODING_UTF8 );
|
|
|
|
|
2007-09-20 14:02:34 +00:00
|
|
|
#if defined(WNT) || defined(OS2)
|
2004-06-25 11:41:02 +00:00
|
|
|
sTmp.SearchAndReplace("file:///","");
|
|
|
|
sTmp.SearchAndReplaceAll('/','\\');
|
|
|
|
#else
|
2005-01-13 18:16:55 +00:00
|
|
|
// Set file permission to 644
|
|
|
|
const sal_uInt64 nPerm = osl_File_Attribute_OwnRead | osl_File_Attribute_OwnWrite |
|
|
|
|
osl_File_Attribute_GrpRead | osl_File_Attribute_OthRead ;
|
|
|
|
|
|
|
|
nRC = osl::File::setAttributes( *sTempFilename , nPerm );
|
|
|
|
if( nRC ) printf(" osl::File::setAttributes RC = %d",nRC);
|
|
|
|
|
2004-06-25 11:41:02 +00:00
|
|
|
sTmp.SearchAndReplace("file://","");
|
|
|
|
#endif
|
|
|
|
DirEntry aDirEntry( sTmp );
|
|
|
|
delete sTempFilename;
|
|
|
|
return aDirEntry;
|
2001-06-07 12:33:31 +00:00
|
|
|
}
|
2010-10-14 08:27:31 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|