xref: /aoo41x/main/oox/source/dump/dumperbase.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include "oox/dump/dumperbase.hxx"
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include <algorithm>
31*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/io/XTextOutputStream.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
35*cdf0e10cSrcweir #include <comphelper/docpasswordhelper.hxx>
36*cdf0e10cSrcweir #include <osl/file.hxx>
37*cdf0e10cSrcweir #include <rtl/math.hxx>
38*cdf0e10cSrcweir #include <rtl/tencinfo.h>
39*cdf0e10cSrcweir #include "oox/core/filterbase.hxx"
40*cdf0e10cSrcweir #include "oox/helper/binaryoutputstream.hxx"
41*cdf0e10cSrcweir #include "oox/helper/textinputstream.hxx"
42*cdf0e10cSrcweir #include "oox/xls/biffhelper.hxx"
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #if OOX_INCLUDE_DUMPER
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir namespace oox {
47*cdf0e10cSrcweir namespace dump {
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir // ============================================================================
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
52*cdf0e10cSrcweir using namespace ::com::sun::star::io;
53*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
54*cdf0e10cSrcweir using namespace ::com::sun::star::ucb;
55*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
56*cdf0e10cSrcweir using namespace ::com::sun::star::util;
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir using ::comphelper::MediaDescriptor;
59*cdf0e10cSrcweir using ::oox::core::FilterBase;
60*cdf0e10cSrcweir using ::rtl::OString;
61*cdf0e10cSrcweir using ::rtl::OStringBuffer;
62*cdf0e10cSrcweir using ::rtl::OStringToOUString;
63*cdf0e10cSrcweir using ::rtl::OUString;
64*cdf0e10cSrcweir using ::rtl::OUStringBuffer;
65*cdf0e10cSrcweir using ::rtl::OUStringToOString;
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir // ============================================================================
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir namespace {
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir const sal_Unicode OOX_DUMP_BOM          = 0xFEFF;
72*cdf0e10cSrcweir const sal_Int32 OOX_DUMP_MAXSTRLEN      = 80;
73*cdf0e10cSrcweir const sal_Int32 OOX_DUMP_INDENT         = 2;
74*cdf0e10cSrcweir const sal_Unicode OOX_DUMP_BINDOT       = '.';
75*cdf0e10cSrcweir const sal_Unicode OOX_DUMP_CFG_LISTSEP  = ',';
76*cdf0e10cSrcweir const sal_Unicode OOX_DUMP_CFG_QUOTE    = '\'';
77*cdf0e10cSrcweir const sal_Unicode OOX_DUMP_LF           = '\n';
78*cdf0e10cSrcweir const sal_Unicode OOX_DUMP_ITEMSEP      = '=';
79*cdf0e10cSrcweir const sal_Int32 OOX_DUMP_BYTESPERLINE   = 16;
80*cdf0e10cSrcweir const sal_Int64 OOX_DUMP_MAXARRAY       = 16;
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir } // namespace
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir // ============================================================================
85*cdf0e10cSrcweir // ============================================================================
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir // file names -----------------------------------------------------------------
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir OUString InputOutputHelper::convertFileNameToUrl( const OUString& rFileName )
90*cdf0e10cSrcweir {
91*cdf0e10cSrcweir     OUString aFileUrl;
92*cdf0e10cSrcweir     if( ::osl::FileBase::getFileURLFromSystemPath( rFileName, aFileUrl ) == ::osl::FileBase::E_None )
93*cdf0e10cSrcweir         return aFileUrl;
94*cdf0e10cSrcweir     return OUString();
95*cdf0e10cSrcweir }
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir sal_Int32 InputOutputHelper::getFileNamePos( const OUString& rFileUrl )
98*cdf0e10cSrcweir {
99*cdf0e10cSrcweir     sal_Int32 nSepPos = rFileUrl.lastIndexOf( '/' );
100*cdf0e10cSrcweir     return (nSepPos < 0) ? 0 : (nSepPos + 1);
101*cdf0e10cSrcweir }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir OUString InputOutputHelper::getFileNameExtension( const OUString& rFileUrl )
104*cdf0e10cSrcweir {
105*cdf0e10cSrcweir     sal_Int32 nNamePos = getFileNamePos( rFileUrl );
106*cdf0e10cSrcweir     sal_Int32 nExtPos = rFileUrl.lastIndexOf( '.' );
107*cdf0e10cSrcweir     if( nExtPos >= nNamePos )
108*cdf0e10cSrcweir         return rFileUrl.copy( nExtPos + 1 );
109*cdf0e10cSrcweir     return OUString();
110*cdf0e10cSrcweir }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir // input streams --------------------------------------------------------------
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir Reference< XInputStream > InputOutputHelper::openInputStream(
115*cdf0e10cSrcweir         const Reference< XComponentContext >& rxContext, const OUString& rFileName )
116*cdf0e10cSrcweir {
117*cdf0e10cSrcweir     Reference< XInputStream > xInStrm;
118*cdf0e10cSrcweir     if( rxContext.is() ) try
119*cdf0e10cSrcweir     {
120*cdf0e10cSrcweir         Reference< XMultiServiceFactory > xFactory( rxContext->getServiceManager(), UNO_QUERY_THROW );
121*cdf0e10cSrcweir         Reference< XSimpleFileAccess > xFileAccess( xFactory->createInstance( CREATE_OUSTRING( "com.sun.star.ucb.SimpleFileAccess" ) ), UNO_QUERY_THROW );
122*cdf0e10cSrcweir         xInStrm = xFileAccess->openFileRead( rFileName );
123*cdf0e10cSrcweir     }
124*cdf0e10cSrcweir     catch( Exception& )
125*cdf0e10cSrcweir     {
126*cdf0e10cSrcweir     }
127*cdf0e10cSrcweir     return xInStrm;
128*cdf0e10cSrcweir }
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir // output streams -------------------------------------------------------------
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir Reference< XOutputStream > InputOutputHelper::openOutputStream(
133*cdf0e10cSrcweir         const Reference< XComponentContext >& rxContext, const OUString& rFileName )
134*cdf0e10cSrcweir {
135*cdf0e10cSrcweir     Reference< XOutputStream > xOutStrm;
136*cdf0e10cSrcweir     if( rxContext.is() ) try
137*cdf0e10cSrcweir     {
138*cdf0e10cSrcweir         Reference< XMultiServiceFactory > xFactory( rxContext->getServiceManager(), UNO_QUERY_THROW );
139*cdf0e10cSrcweir         Reference< XSimpleFileAccess > xFileAccess( xFactory->createInstance( CREATE_OUSTRING( "com.sun.star.ucb.SimpleFileAccess" ) ), UNO_QUERY_THROW );
140*cdf0e10cSrcweir         xOutStrm = xFileAccess->openFileWrite( rFileName );
141*cdf0e10cSrcweir     }
142*cdf0e10cSrcweir     catch( Exception& )
143*cdf0e10cSrcweir     {
144*cdf0e10cSrcweir     }
145*cdf0e10cSrcweir     return xOutStrm;
146*cdf0e10cSrcweir }
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir Reference< XTextOutputStream > InputOutputHelper::openTextOutputStream(
149*cdf0e10cSrcweir         const Reference< XComponentContext >& rxContext, const Reference< XOutputStream >& rxOutStrm, rtl_TextEncoding eTextEnc )
150*cdf0e10cSrcweir {
151*cdf0e10cSrcweir     Reference< XTextOutputStream > xTextOutStrm;
152*cdf0e10cSrcweir     const char* pcCharset = rtl_getMimeCharsetFromTextEncoding( eTextEnc );
153*cdf0e10cSrcweir     if( rxContext.is() && rxOutStrm.is() && pcCharset ) try
154*cdf0e10cSrcweir     {
155*cdf0e10cSrcweir         Reference< XMultiServiceFactory > xFactory( rxContext->getServiceManager(), UNO_QUERY_THROW );
156*cdf0e10cSrcweir         Reference< XActiveDataSource > xDataSource( xFactory->createInstance( CREATE_OUSTRING( "com.sun.star.io.TextOutputStream" ) ), UNO_QUERY_THROW );
157*cdf0e10cSrcweir         xDataSource->setOutputStream( rxOutStrm );
158*cdf0e10cSrcweir         xTextOutStrm.set( xDataSource, UNO_QUERY_THROW );
159*cdf0e10cSrcweir         xTextOutStrm->setEncoding( OUString::createFromAscii( pcCharset ) );
160*cdf0e10cSrcweir     }
161*cdf0e10cSrcweir     catch( Exception& )
162*cdf0e10cSrcweir     {
163*cdf0e10cSrcweir     }
164*cdf0e10cSrcweir     return xTextOutStrm;
165*cdf0e10cSrcweir }
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir Reference< XTextOutputStream > InputOutputHelper::openTextOutputStream(
168*cdf0e10cSrcweir         const Reference< XComponentContext >& rxContext, const OUString& rFileName, rtl_TextEncoding eTextEnc )
169*cdf0e10cSrcweir {
170*cdf0e10cSrcweir     return openTextOutputStream( rxContext, openOutputStream( rxContext, rFileName ), eTextEnc );
171*cdf0e10cSrcweir }
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir // ============================================================================
174*cdf0e10cSrcweir // ============================================================================
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir ItemFormat::ItemFormat() :
177*cdf0e10cSrcweir     meDataType( DATATYPE_VOID ),
178*cdf0e10cSrcweir     meFmtType( FORMATTYPE_NONE )
179*cdf0e10cSrcweir {
180*cdf0e10cSrcweir }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir void ItemFormat::set( DataType eDataType, FormatType eFmtType, const OUString& rItemName )
183*cdf0e10cSrcweir {
184*cdf0e10cSrcweir     meDataType = eDataType;
185*cdf0e10cSrcweir     meFmtType = eFmtType;
186*cdf0e10cSrcweir     maItemName = rItemName;
187*cdf0e10cSrcweir     maListName = OUString();
188*cdf0e10cSrcweir }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir void ItemFormat::set( DataType eDataType, FormatType eFmtType, const OUString& rItemName, const OUString& rListName )
191*cdf0e10cSrcweir {
192*cdf0e10cSrcweir     set( eDataType, eFmtType, rItemName );
193*cdf0e10cSrcweir     maListName = rListName;
194*cdf0e10cSrcweir }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir OUStringVector::const_iterator ItemFormat::parse( const OUStringVector& rFormatVec )
197*cdf0e10cSrcweir {
198*cdf0e10cSrcweir     set( DATATYPE_VOID, FORMATTYPE_NONE, OUString() );
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir     OUStringVector::const_iterator aIt = rFormatVec.begin(), aEnd = rFormatVec.end();
201*cdf0e10cSrcweir     OUString aDataType, aFmtType;
202*cdf0e10cSrcweir     if( aIt != aEnd ) aDataType = *aIt++;
203*cdf0e10cSrcweir     if( aIt != aEnd ) aFmtType = *aIt++;
204*cdf0e10cSrcweir     if( aIt != aEnd ) maItemName = *aIt++;
205*cdf0e10cSrcweir     if( aIt != aEnd ) maListName = *aIt++;
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir     meDataType = StringHelper::convertToDataType( aDataType );
208*cdf0e10cSrcweir     meFmtType = StringHelper::convertToFormatType( aFmtType );
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir     if( meFmtType == FORMATTYPE_NONE )
211*cdf0e10cSrcweir     {
212*cdf0e10cSrcweir         if( aFmtType.equalsAscii( "unused" ) )
213*cdf0e10cSrcweir             set( meDataType, FORMATTYPE_HEX, CREATE_OUSTRING( OOX_DUMP_UNUSED ) );
214*cdf0e10cSrcweir         else if( aFmtType.equalsAscii( "unknown" ) )
215*cdf0e10cSrcweir             set( meDataType, FORMATTYPE_HEX, CREATE_OUSTRING( OOX_DUMP_UNKNOWN ) );
216*cdf0e10cSrcweir     }
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir     return aIt;
219*cdf0e10cSrcweir }
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir OUStringVector ItemFormat::parse( const OUString& rFormatStr )
222*cdf0e10cSrcweir {
223*cdf0e10cSrcweir     OUStringVector aFormatVec;
224*cdf0e10cSrcweir     StringHelper::convertStringToStringList( aFormatVec, rFormatStr, false );
225*cdf0e10cSrcweir     OUStringVector::const_iterator aIt = parse( aFormatVec );
226*cdf0e10cSrcweir     return OUStringVector( aIt, const_cast< const OUStringVector& >( aFormatVec ).end() );
227*cdf0e10cSrcweir }
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir // ============================================================================
230*cdf0e10cSrcweir // ============================================================================
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir // append string to string ----------------------------------------------------
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir void StringHelper::appendChar( OUStringBuffer& rStr, sal_Unicode cChar, sal_Int32 nCount )
235*cdf0e10cSrcweir {
236*cdf0e10cSrcweir     for( sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex )
237*cdf0e10cSrcweir         rStr.append( cChar );
238*cdf0e10cSrcweir }
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir void StringHelper::appendString( OUStringBuffer& rStr, const OUString& rData, sal_Int32 nWidth, sal_Unicode cFill )
241*cdf0e10cSrcweir {
242*cdf0e10cSrcweir     appendChar( rStr, cFill, nWidth - rData.getLength() );
243*cdf0e10cSrcweir     rStr.append( rData );
244*cdf0e10cSrcweir }
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir // append decimal -------------------------------------------------------------
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir void StringHelper::appendDec( OUStringBuffer& rStr, sal_uInt8 nData, sal_Int32 nWidth, sal_Unicode cFill )
249*cdf0e10cSrcweir {
250*cdf0e10cSrcweir     appendString( rStr, OUString::valueOf( static_cast< sal_Int32 >( nData ) ), nWidth, cFill );
251*cdf0e10cSrcweir }
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir void StringHelper::appendDec( OUStringBuffer& rStr, sal_Int8 nData, sal_Int32 nWidth, sal_Unicode cFill )
254*cdf0e10cSrcweir {
255*cdf0e10cSrcweir     appendString( rStr, OUString::valueOf( static_cast< sal_Int32 >( nData ) ), nWidth, cFill );
256*cdf0e10cSrcweir }
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir void StringHelper::appendDec( OUStringBuffer& rStr, sal_uInt16 nData, sal_Int32 nWidth, sal_Unicode cFill )
259*cdf0e10cSrcweir {
260*cdf0e10cSrcweir     appendString( rStr, OUString::valueOf( static_cast< sal_Int32 >( nData ) ), nWidth, cFill );
261*cdf0e10cSrcweir }
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir void StringHelper::appendDec( OUStringBuffer& rStr, sal_Int16 nData, sal_Int32 nWidth, sal_Unicode cFill )
264*cdf0e10cSrcweir {
265*cdf0e10cSrcweir     appendString( rStr, OUString::valueOf( static_cast< sal_Int32 >( nData ) ), nWidth, cFill );
266*cdf0e10cSrcweir }
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir void StringHelper::appendDec( OUStringBuffer& rStr, sal_uInt32 nData, sal_Int32 nWidth, sal_Unicode cFill )
269*cdf0e10cSrcweir {
270*cdf0e10cSrcweir     appendString( rStr, OUString::valueOf( static_cast< sal_Int64 >( nData ) ), nWidth, cFill );
271*cdf0e10cSrcweir }
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir void StringHelper::appendDec( OUStringBuffer& rStr, sal_Int32 nData, sal_Int32 nWidth, sal_Unicode cFill )
274*cdf0e10cSrcweir {
275*cdf0e10cSrcweir     appendString( rStr, OUString::valueOf( nData ), nWidth, cFill );
276*cdf0e10cSrcweir }
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir void StringHelper::appendDec( OUStringBuffer& rStr, sal_uInt64 nData, sal_Int32 nWidth, sal_Unicode cFill )
279*cdf0e10cSrcweir {
280*cdf0e10cSrcweir     /*  Values greater than biggest signed 64bit integer will change to
281*cdf0e10cSrcweir         negative when converting to sal_Int64. Therefore, the trailing digit
282*cdf0e10cSrcweir         will be written separately. */
283*cdf0e10cSrcweir     OUStringBuffer aBuffer;
284*cdf0e10cSrcweir     if( nData > 9 )
285*cdf0e10cSrcweir         aBuffer.append( OUString::valueOf( static_cast< sal_Int64 >( nData / 10 ) ) );
286*cdf0e10cSrcweir     aBuffer.append( static_cast< sal_Unicode >( '0' + (nData % 10) ) );
287*cdf0e10cSrcweir     appendString( rStr, aBuffer.makeStringAndClear(), nWidth, cFill );
288*cdf0e10cSrcweir }
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir void StringHelper::appendDec( OUStringBuffer& rStr, sal_Int64 nData, sal_Int32 nWidth, sal_Unicode cFill )
291*cdf0e10cSrcweir {
292*cdf0e10cSrcweir     appendString( rStr, OUString::valueOf( nData ), nWidth, cFill );
293*cdf0e10cSrcweir }
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir void StringHelper::appendDec( OUStringBuffer& rStr, double fData, sal_Int32 nWidth, sal_Unicode cFill )
296*cdf0e10cSrcweir {
297*cdf0e10cSrcweir     appendString( rStr, ::rtl::math::doubleToUString( fData, rtl_math_StringFormat_G, 15, '.', true ), nWidth, cFill );
298*cdf0e10cSrcweir }
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir // append hexadecimal ---------------------------------------------------------
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir void StringHelper::appendHex( OUStringBuffer& rStr, sal_uInt8 nData, bool bPrefix )
303*cdf0e10cSrcweir {
304*cdf0e10cSrcweir     static const sal_Unicode spcHexDigits[] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' };
305*cdf0e10cSrcweir     if( bPrefix )
306*cdf0e10cSrcweir         rStr.appendAscii( "0x" );
307*cdf0e10cSrcweir     rStr.append( spcHexDigits[ (nData >> 4) & 0x0F ] ).append( spcHexDigits[ nData & 0x0F ] );
308*cdf0e10cSrcweir }
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir void StringHelper::appendHex( OUStringBuffer& rStr, sal_Int8 nData, bool bPrefix )
311*cdf0e10cSrcweir {
312*cdf0e10cSrcweir     appendHex( rStr, static_cast< sal_uInt8 >( nData ), bPrefix );
313*cdf0e10cSrcweir }
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir void StringHelper::appendHex( OUStringBuffer& rStr, sal_uInt16 nData, bool bPrefix )
316*cdf0e10cSrcweir {
317*cdf0e10cSrcweir     appendHex( rStr, static_cast< sal_uInt8 >( nData >> 8 ), bPrefix );
318*cdf0e10cSrcweir     appendHex( rStr, static_cast< sal_uInt8 >( nData ), false );
319*cdf0e10cSrcweir }
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir void StringHelper::appendHex( OUStringBuffer& rStr, sal_Int16 nData, bool bPrefix )
322*cdf0e10cSrcweir {
323*cdf0e10cSrcweir     appendHex( rStr, static_cast< sal_uInt16 >( nData ), bPrefix );
324*cdf0e10cSrcweir }
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir void StringHelper::appendHex( OUStringBuffer& rStr, sal_uInt32 nData, bool bPrefix )
327*cdf0e10cSrcweir {
328*cdf0e10cSrcweir     appendHex( rStr, static_cast< sal_uInt16 >( nData >> 16 ), bPrefix );
329*cdf0e10cSrcweir     appendHex( rStr, static_cast< sal_uInt16 >( nData ), false );
330*cdf0e10cSrcweir }
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir void StringHelper::appendHex( OUStringBuffer& rStr, sal_Int32 nData, bool bPrefix )
333*cdf0e10cSrcweir {
334*cdf0e10cSrcweir     appendHex( rStr, static_cast< sal_uInt32 >( nData ), bPrefix );
335*cdf0e10cSrcweir }
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir void StringHelper::appendHex( OUStringBuffer& rStr, sal_uInt64 nData, bool bPrefix )
338*cdf0e10cSrcweir {
339*cdf0e10cSrcweir     appendHex( rStr, static_cast< sal_uInt32 >( nData >> 32 ), bPrefix );
340*cdf0e10cSrcweir     appendHex( rStr, static_cast< sal_uInt32 >( nData ), false );
341*cdf0e10cSrcweir }
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir void StringHelper::appendHex( OUStringBuffer& rStr, sal_Int64 nData, bool bPrefix )
344*cdf0e10cSrcweir {
345*cdf0e10cSrcweir     appendHex( rStr, static_cast< sal_uInt64 >( nData ), bPrefix );
346*cdf0e10cSrcweir }
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir void StringHelper::appendHex( OUStringBuffer& rStr, double fData, bool bPrefix )
349*cdf0e10cSrcweir {
350*cdf0e10cSrcweir     appendHex( rStr, *reinterpret_cast< const sal_uInt64* >( &fData ), bPrefix );
351*cdf0e10cSrcweir }
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir // append shortened hexadecimal -----------------------------------------------
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir void StringHelper::appendShortHex( OUStringBuffer& rStr, sal_uInt8 nData, bool bPrefix )
356*cdf0e10cSrcweir {
357*cdf0e10cSrcweir     appendHex( rStr, nData, bPrefix );
358*cdf0e10cSrcweir }
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir void StringHelper::appendShortHex( OUStringBuffer& rStr, sal_Int8 nData, bool bPrefix )
361*cdf0e10cSrcweir {
362*cdf0e10cSrcweir     appendHex( rStr, nData, bPrefix );
363*cdf0e10cSrcweir }
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir void StringHelper::appendShortHex( OUStringBuffer& rStr, sal_uInt16 nData, bool bPrefix )
366*cdf0e10cSrcweir {
367*cdf0e10cSrcweir     if( nData > SAL_MAX_UINT8 )
368*cdf0e10cSrcweir         appendHex( rStr, nData, bPrefix );
369*cdf0e10cSrcweir     else
370*cdf0e10cSrcweir         appendHex( rStr, static_cast< sal_uInt8 >( nData ), bPrefix );
371*cdf0e10cSrcweir }
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir void StringHelper::appendShortHex( OUStringBuffer& rStr, sal_Int16 nData, bool bPrefix )
374*cdf0e10cSrcweir {
375*cdf0e10cSrcweir     appendShortHex( rStr, static_cast< sal_uInt16 >( nData ), bPrefix );
376*cdf0e10cSrcweir }
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir void StringHelper::appendShortHex( OUStringBuffer& rStr, sal_uInt32 nData, bool bPrefix )
379*cdf0e10cSrcweir {
380*cdf0e10cSrcweir     if( nData > SAL_MAX_UINT16 )
381*cdf0e10cSrcweir         appendHex( rStr, nData, bPrefix );
382*cdf0e10cSrcweir     else
383*cdf0e10cSrcweir         appendShortHex( rStr, static_cast< sal_uInt16 >( nData ), bPrefix );
384*cdf0e10cSrcweir }
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir void StringHelper::appendShortHex( OUStringBuffer& rStr, sal_Int32 nData, bool bPrefix )
387*cdf0e10cSrcweir {
388*cdf0e10cSrcweir     appendShortHex( rStr, static_cast< sal_uInt32 >( nData ), bPrefix );
389*cdf0e10cSrcweir }
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir void StringHelper::appendShortHex( OUStringBuffer& rStr, sal_uInt64 nData, bool bPrefix )
392*cdf0e10cSrcweir {
393*cdf0e10cSrcweir     if( nData > SAL_MAX_UINT32 )
394*cdf0e10cSrcweir         appendHex( rStr, nData, bPrefix );
395*cdf0e10cSrcweir     else
396*cdf0e10cSrcweir         appendShortHex( rStr, static_cast< sal_uInt32 >( nData ), bPrefix );
397*cdf0e10cSrcweir }
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir void StringHelper::appendShortHex( OUStringBuffer& rStr, sal_Int64 nData, bool bPrefix )
400*cdf0e10cSrcweir {
401*cdf0e10cSrcweir     appendShortHex( rStr, static_cast< sal_uInt64 >( nData ), bPrefix );
402*cdf0e10cSrcweir }
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir void StringHelper::appendShortHex( OUStringBuffer& rStr, double fData, bool bPrefix )
405*cdf0e10cSrcweir {
406*cdf0e10cSrcweir     appendHex( rStr, fData, bPrefix );
407*cdf0e10cSrcweir }
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir // append binary --------------------------------------------------------------
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir void StringHelper::appendBin( OUStringBuffer& rStr, sal_uInt8 nData, bool bDots )
412*cdf0e10cSrcweir {
413*cdf0e10cSrcweir     for( sal_uInt8 nMask = 0x80; nMask != 0; (nMask >>= 1) &= 0x7F )
414*cdf0e10cSrcweir     {
415*cdf0e10cSrcweir         rStr.append( static_cast< sal_Unicode >( (nData & nMask) ? '1' : '0' ) );
416*cdf0e10cSrcweir         if( bDots && (nMask == 0x10) )
417*cdf0e10cSrcweir             rStr.append( OOX_DUMP_BINDOT );
418*cdf0e10cSrcweir     }
419*cdf0e10cSrcweir }
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir void StringHelper::appendBin( OUStringBuffer& rStr, sal_Int8 nData, bool bDots )
422*cdf0e10cSrcweir {
423*cdf0e10cSrcweir     appendBin( rStr, static_cast< sal_uInt8 >( nData ), bDots );
424*cdf0e10cSrcweir }
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir void StringHelper::appendBin( OUStringBuffer& rStr, sal_uInt16 nData, bool bDots )
427*cdf0e10cSrcweir {
428*cdf0e10cSrcweir     appendBin( rStr, static_cast< sal_uInt8 >( nData >> 8 ), bDots );
429*cdf0e10cSrcweir     if( bDots )
430*cdf0e10cSrcweir         rStr.append( OOX_DUMP_BINDOT );
431*cdf0e10cSrcweir     appendBin( rStr, static_cast< sal_uInt8 >( nData ), bDots );
432*cdf0e10cSrcweir }
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir void StringHelper::appendBin( OUStringBuffer& rStr, sal_Int16 nData, bool bDots )
435*cdf0e10cSrcweir {
436*cdf0e10cSrcweir     appendBin( rStr, static_cast< sal_uInt16 >( nData ), bDots );
437*cdf0e10cSrcweir }
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir void StringHelper::appendBin( OUStringBuffer& rStr, sal_uInt32 nData, bool bDots )
440*cdf0e10cSrcweir {
441*cdf0e10cSrcweir     appendBin( rStr, static_cast< sal_uInt16 >( nData >> 16 ), bDots );
442*cdf0e10cSrcweir     if( bDots )
443*cdf0e10cSrcweir         rStr.append( OOX_DUMP_BINDOT );
444*cdf0e10cSrcweir     appendBin( rStr, static_cast< sal_uInt16 >( nData ), bDots );
445*cdf0e10cSrcweir }
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir void StringHelper::appendBin( OUStringBuffer& rStr, sal_Int32 nData, bool bDots )
448*cdf0e10cSrcweir {
449*cdf0e10cSrcweir     appendBin( rStr, static_cast< sal_uInt32 >( nData ), bDots );
450*cdf0e10cSrcweir }
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir void StringHelper::appendBin( OUStringBuffer& rStr, sal_uInt64 nData, bool bDots )
453*cdf0e10cSrcweir {
454*cdf0e10cSrcweir     appendBin( rStr, static_cast< sal_uInt32 >( nData >> 32 ), bDots );
455*cdf0e10cSrcweir     if( bDots )
456*cdf0e10cSrcweir         rStr.append( OOX_DUMP_BINDOT );
457*cdf0e10cSrcweir     appendBin( rStr, static_cast< sal_uInt32 >( nData ), bDots );
458*cdf0e10cSrcweir }
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir void StringHelper::appendBin( OUStringBuffer& rStr, sal_Int64 nData, bool bDots )
461*cdf0e10cSrcweir {
462*cdf0e10cSrcweir     appendBin( rStr, static_cast< sal_uInt64 >( nData ), bDots );
463*cdf0e10cSrcweir }
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir void StringHelper::appendBin( OUStringBuffer& rStr, double fData, bool bDots )
466*cdf0e10cSrcweir {
467*cdf0e10cSrcweir     appendBin( rStr, *reinterpret_cast< const sal_uInt64* >( &fData ), bDots );
468*cdf0e10cSrcweir }
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir // append formatted value -----------------------------------------------------
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir void StringHelper::appendBool( OUStringBuffer& rStr, bool bData )
473*cdf0e10cSrcweir {
474*cdf0e10cSrcweir     rStr.appendAscii( bData ? "true" : "false" );
475*cdf0e10cSrcweir }
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir // append columns, rows, addresses --------------------------------------------
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir void StringHelper::appendAddrCol( OUStringBuffer& rStr, sal_Int32 nCol, bool bRel )
480*cdf0e10cSrcweir {
481*cdf0e10cSrcweir     if( !bRel ) rStr.append( OOX_DUMP_ADDRABS );
482*cdf0e10cSrcweir     sal_Int32 nPos = rStr.getLength();
483*cdf0e10cSrcweir     for( sal_Int32 nTemp = nCol; nTemp >= 0; (nTemp /= 26) -= 1 )
484*cdf0e10cSrcweir         rStr.insert( nPos, static_cast< sal_Unicode >( 'A' + (nTemp % 26) ) );
485*cdf0e10cSrcweir }
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir void StringHelper::appendAddrRow( OUStringBuffer& rStr, sal_Int32 nRow, bool bRel )
488*cdf0e10cSrcweir {
489*cdf0e10cSrcweir     if( !bRel ) rStr.append( OOX_DUMP_ADDRABS );
490*cdf0e10cSrcweir     appendDec( rStr, nRow + 1 );
491*cdf0e10cSrcweir }
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir void StringHelper::appendAddrName( OUStringBuffer& rStr, sal_Unicode cPrefix, sal_Int32 nColRow, bool bRel )
494*cdf0e10cSrcweir {
495*cdf0e10cSrcweir     rStr.append( cPrefix );
496*cdf0e10cSrcweir     if( bRel && (nColRow != 0) )
497*cdf0e10cSrcweir     {
498*cdf0e10cSrcweir         rStr.append( OOX_DUMP_R1C1OPEN );
499*cdf0e10cSrcweir         appendDec( rStr, nColRow );
500*cdf0e10cSrcweir         rStr.append( OOX_DUMP_R1C1CLOSE );
501*cdf0e10cSrcweir     }
502*cdf0e10cSrcweir     else if( !bRel )
503*cdf0e10cSrcweir         appendDec( rStr, nColRow + 1 );
504*cdf0e10cSrcweir }
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir void StringHelper::appendAddress( OUStringBuffer& rStr, const Address& rPos )
507*cdf0e10cSrcweir {
508*cdf0e10cSrcweir     appendAddrCol( rStr, rPos.mnCol, true );
509*cdf0e10cSrcweir     appendAddrRow( rStr, rPos.mnRow, true );
510*cdf0e10cSrcweir }
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir void StringHelper::appendRange( OUStringBuffer& rStr, const Range& rRange )
513*cdf0e10cSrcweir {
514*cdf0e10cSrcweir     appendAddress( rStr, rRange.maFirst );
515*cdf0e10cSrcweir     rStr.append( OOX_DUMP_RANGESEP );
516*cdf0e10cSrcweir     appendAddress( rStr, rRange.maLast );
517*cdf0e10cSrcweir }
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir void StringHelper::appendRangeList( OUStringBuffer& rStr, const RangeList& rRanges )
520*cdf0e10cSrcweir {
521*cdf0e10cSrcweir     OUStringBuffer aData;
522*cdf0e10cSrcweir     for( RangeList::const_iterator aIt = rRanges.begin(), aEnd = rRanges.end(); aIt != aEnd; ++aIt )
523*cdf0e10cSrcweir     {
524*cdf0e10cSrcweir         OUStringBuffer aRange;
525*cdf0e10cSrcweir         appendRange( aRange, *aIt );
526*cdf0e10cSrcweir         appendToken( aData, aRange.makeStringAndClear(), OOX_DUMP_LISTSEP );
527*cdf0e10cSrcweir     }
528*cdf0e10cSrcweir     rStr.append( aData.makeStringAndClear() );
529*cdf0e10cSrcweir }
530*cdf0e10cSrcweir 
531*cdf0e10cSrcweir void StringHelper::appendAddress( OUStringBuffer& rStr, const TokenAddress& rPos, bool bR1C1 )
532*cdf0e10cSrcweir {
533*cdf0e10cSrcweir     if( bR1C1 && (rPos.mbRelCol || rPos.mbRelRow) )
534*cdf0e10cSrcweir     {
535*cdf0e10cSrcweir         appendAddrName( rStr, OOX_DUMP_R1C1ROW, rPos.mnRow, rPos.mbRelRow );
536*cdf0e10cSrcweir         appendAddrName( rStr, OOX_DUMP_R1C1COL, rPos.mnCol, rPos.mbRelCol );
537*cdf0e10cSrcweir     }
538*cdf0e10cSrcweir     else
539*cdf0e10cSrcweir     {
540*cdf0e10cSrcweir         appendAddrCol( rStr, rPos.mnCol, rPos.mbRelCol );
541*cdf0e10cSrcweir         appendAddrRow( rStr, rPos.mnRow, rPos.mbRelRow );
542*cdf0e10cSrcweir     }
543*cdf0e10cSrcweir }
544*cdf0e10cSrcweir 
545*cdf0e10cSrcweir void StringHelper::appendRange( OUStringBuffer& rStr, const TokenRange& rRange, bool bR1C1 )
546*cdf0e10cSrcweir {
547*cdf0e10cSrcweir     appendAddress( rStr, rRange.maFirst, bR1C1 );
548*cdf0e10cSrcweir     rStr.append( OOX_DUMP_RANGESEP );
549*cdf0e10cSrcweir     appendAddress( rStr, rRange.maLast, bR1C1 );
550*cdf0e10cSrcweir }
551*cdf0e10cSrcweir 
552*cdf0e10cSrcweir // encoded text output --------------------------------------------------------
553*cdf0e10cSrcweir 
554*cdf0e10cSrcweir void StringHelper::appendCChar( OUStringBuffer& rStr, sal_Unicode cChar, bool bPrefix )
555*cdf0e10cSrcweir {
556*cdf0e10cSrcweir     if( cChar > 0x00FF )
557*cdf0e10cSrcweir     {
558*cdf0e10cSrcweir         if( bPrefix )
559*cdf0e10cSrcweir             rStr.appendAscii( "\\u" );
560*cdf0e10cSrcweir         appendHex( rStr, static_cast< sal_uInt16 >( cChar ), false );
561*cdf0e10cSrcweir     }
562*cdf0e10cSrcweir     else
563*cdf0e10cSrcweir     {
564*cdf0e10cSrcweir         if( bPrefix )
565*cdf0e10cSrcweir             rStr.appendAscii( "\\x" );
566*cdf0e10cSrcweir         appendHex( rStr, static_cast< sal_uInt8 >( cChar ), false );
567*cdf0e10cSrcweir     }
568*cdf0e10cSrcweir }
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir void StringHelper::appendEncChar( OUStringBuffer& rStr, sal_Unicode cChar, sal_Int32 nCount, bool bPrefix )
571*cdf0e10cSrcweir {
572*cdf0e10cSrcweir     if( cChar < 0x0020 )
573*cdf0e10cSrcweir     {
574*cdf0e10cSrcweir         // C-style hex code
575*cdf0e10cSrcweir         OUStringBuffer aCode;
576*cdf0e10cSrcweir         appendCChar( aCode, cChar, bPrefix );
577*cdf0e10cSrcweir         for( sal_Int32 nIdx = 0; nIdx < nCount; ++nIdx )
578*cdf0e10cSrcweir             rStr.append( aCode );
579*cdf0e10cSrcweir     }
580*cdf0e10cSrcweir     else
581*cdf0e10cSrcweir     {
582*cdf0e10cSrcweir         appendChar( rStr, cChar, nCount );
583*cdf0e10cSrcweir     }
584*cdf0e10cSrcweir }
585*cdf0e10cSrcweir 
586*cdf0e10cSrcweir void StringHelper::appendEncString( OUStringBuffer& rStr, const OUString& rData, bool bPrefix )
587*cdf0e10cSrcweir {
588*cdf0e10cSrcweir     sal_Int32 nBeg = 0;
589*cdf0e10cSrcweir     sal_Int32 nIdx = 0;
590*cdf0e10cSrcweir     sal_Int32 nEnd = rData.getLength();
591*cdf0e10cSrcweir     while( nIdx < nEnd )
592*cdf0e10cSrcweir     {
593*cdf0e10cSrcweir         // find next character that needs encoding
594*cdf0e10cSrcweir         while( (nIdx < nEnd) && (rData[ nIdx ] >= 0x20) ) ++nIdx;
595*cdf0e10cSrcweir         // append portion
596*cdf0e10cSrcweir         if( nBeg < nIdx )
597*cdf0e10cSrcweir         {
598*cdf0e10cSrcweir             if( (nBeg == 0) && (nIdx == nEnd) )
599*cdf0e10cSrcweir                 rStr.append( rData );
600*cdf0e10cSrcweir             else
601*cdf0e10cSrcweir                 rStr.append( rData.copy( nBeg, nIdx - nBeg ) );
602*cdf0e10cSrcweir         }
603*cdf0e10cSrcweir         // append characters to be encoded
604*cdf0e10cSrcweir         while( (nIdx < nEnd) && (rData[ nIdx ] < 0x20) )
605*cdf0e10cSrcweir         {
606*cdf0e10cSrcweir             appendCChar( rStr, rData[ nIdx ], bPrefix );
607*cdf0e10cSrcweir             ++nIdx;
608*cdf0e10cSrcweir         }
609*cdf0e10cSrcweir         // adjust limits
610*cdf0e10cSrcweir         nBeg = nIdx;
611*cdf0e10cSrcweir     }
612*cdf0e10cSrcweir }
613*cdf0e10cSrcweir 
614*cdf0e10cSrcweir // token list -----------------------------------------------------------------
615*cdf0e10cSrcweir 
616*cdf0e10cSrcweir void StringHelper::appendToken( OUStringBuffer& rStr, const OUString& rToken, sal_Unicode cSep )
617*cdf0e10cSrcweir {
618*cdf0e10cSrcweir     if( (rStr.getLength() > 0) && (rToken.getLength() > 0) )
619*cdf0e10cSrcweir         rStr.append( cSep );
620*cdf0e10cSrcweir     rStr.append( rToken );
621*cdf0e10cSrcweir }
622*cdf0e10cSrcweir 
623*cdf0e10cSrcweir void StringHelper::appendToken( OUStringBuffer& rStr, sal_Int64 nToken, sal_Unicode cSep )
624*cdf0e10cSrcweir {
625*cdf0e10cSrcweir     OUStringBuffer aToken;
626*cdf0e10cSrcweir     appendDec( aToken, nToken );
627*cdf0e10cSrcweir     appendToken( rStr, aToken.makeStringAndClear(), cSep );
628*cdf0e10cSrcweir }
629*cdf0e10cSrcweir 
630*cdf0e10cSrcweir void StringHelper::prependToken( OUStringBuffer& rStr, const OUString& rToken, sal_Unicode cSep )
631*cdf0e10cSrcweir {
632*cdf0e10cSrcweir     if( (rStr.getLength() > 0) && (rToken.getLength() > 0) )
633*cdf0e10cSrcweir         rStr.insert( 0, cSep );
634*cdf0e10cSrcweir     rStr.insert( 0, rToken );
635*cdf0e10cSrcweir }
636*cdf0e10cSrcweir 
637*cdf0e10cSrcweir void StringHelper::prependToken( OUStringBuffer& rStr, sal_Int64 nToken, sal_Unicode cSep )
638*cdf0e10cSrcweir {
639*cdf0e10cSrcweir     OUStringBuffer aToken;
640*cdf0e10cSrcweir     appendDec( aToken, nToken );
641*cdf0e10cSrcweir     prependToken( rStr, aToken.makeStringAndClear(), cSep );
642*cdf0e10cSrcweir }
643*cdf0e10cSrcweir 
644*cdf0e10cSrcweir void StringHelper::appendIndex( OUStringBuffer& rStr, const OUString& rIdx )
645*cdf0e10cSrcweir {
646*cdf0e10cSrcweir     rStr.append( sal_Unicode( '[' ) ).append( rIdx ).append( sal_Unicode( ']' ) );
647*cdf0e10cSrcweir }
648*cdf0e10cSrcweir 
649*cdf0e10cSrcweir void StringHelper::appendIndex( OUStringBuffer& rStr, sal_Int64 nIdx )
650*cdf0e10cSrcweir {
651*cdf0e10cSrcweir     OUStringBuffer aToken;
652*cdf0e10cSrcweir     appendDec( aToken, nIdx );
653*cdf0e10cSrcweir     appendIndex( rStr, aToken.makeStringAndClear() );
654*cdf0e10cSrcweir }
655*cdf0e10cSrcweir 
656*cdf0e10cSrcweir void StringHelper::appendIndexedText( OUStringBuffer& rStr, const OUString& rData, const OUString& rIdx )
657*cdf0e10cSrcweir {
658*cdf0e10cSrcweir     rStr.append( rData );
659*cdf0e10cSrcweir     appendIndex( rStr, rIdx );
660*cdf0e10cSrcweir }
661*cdf0e10cSrcweir 
662*cdf0e10cSrcweir void StringHelper::appendIndexedText( OUStringBuffer& rStr, const OUString& rData, sal_Int64 nIdx )
663*cdf0e10cSrcweir {
664*cdf0e10cSrcweir     rStr.append( rData );
665*cdf0e10cSrcweir     appendIndex( rStr, nIdx );
666*cdf0e10cSrcweir }
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir OUString StringHelper::getToken( const OUString& rData, sal_Int32& rnPos, sal_Unicode cSep )
669*cdf0e10cSrcweir {
670*cdf0e10cSrcweir     return trimSpaces( rData.getToken( 0, cSep, rnPos ) );
671*cdf0e10cSrcweir }
672*cdf0e10cSrcweir 
673*cdf0e10cSrcweir void StringHelper::enclose( OUStringBuffer& rStr, sal_Unicode cOpen, sal_Unicode cClose )
674*cdf0e10cSrcweir {
675*cdf0e10cSrcweir     rStr.insert( 0, cOpen ).append( cClose ? cClose : cOpen );
676*cdf0e10cSrcweir }
677*cdf0e10cSrcweir 
678*cdf0e10cSrcweir // string conversion ----------------------------------------------------------
679*cdf0e10cSrcweir 
680*cdf0e10cSrcweir namespace {
681*cdf0e10cSrcweir 
682*cdf0e10cSrcweir sal_Int32 lclIndexOf( const OUString& rStr, sal_Unicode cChar, sal_Int32 nStartPos )
683*cdf0e10cSrcweir {
684*cdf0e10cSrcweir     sal_Int32 nIndex = rStr.indexOf( cChar, nStartPos );
685*cdf0e10cSrcweir     return (nIndex < 0) ? rStr.getLength() : nIndex;
686*cdf0e10cSrcweir }
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir OUString lclTrimQuotedStringList( const OUString& rStr )
689*cdf0e10cSrcweir {
690*cdf0e10cSrcweir     OUStringBuffer aBuffer;
691*cdf0e10cSrcweir     sal_Int32 nPos = 0;
692*cdf0e10cSrcweir     sal_Int32 nLen = rStr.getLength();
693*cdf0e10cSrcweir     while( nPos < nLen )
694*cdf0e10cSrcweir     {
695*cdf0e10cSrcweir         if( rStr[ nPos ] == OOX_DUMP_CFG_QUOTE )
696*cdf0e10cSrcweir         {
697*cdf0e10cSrcweir             // quoted string, skip leading quote character
698*cdf0e10cSrcweir             ++nPos;
699*cdf0e10cSrcweir             // process quoted text and ambedded literal quote characters
700*cdf0e10cSrcweir             OUStringBuffer aToken;
701*cdf0e10cSrcweir             do
702*cdf0e10cSrcweir             {
703*cdf0e10cSrcweir                 // seek to next quote character and add text portion to token buffer
704*cdf0e10cSrcweir                 sal_Int32 nEnd = lclIndexOf( rStr, OOX_DUMP_CFG_QUOTE, nPos );
705*cdf0e10cSrcweir                 aToken.append( rStr.copy( nPos, nEnd - nPos ) );
706*cdf0e10cSrcweir                 // process literal quotes
707*cdf0e10cSrcweir                 while( (nEnd + 1 < nLen) && (rStr[ nEnd ] == OOX_DUMP_CFG_QUOTE) && (rStr[ nEnd + 1 ] == OOX_DUMP_CFG_QUOTE) )
708*cdf0e10cSrcweir                 {
709*cdf0e10cSrcweir                     aToken.append( OOX_DUMP_CFG_QUOTE );
710*cdf0e10cSrcweir                     nEnd += 2;
711*cdf0e10cSrcweir                 }
712*cdf0e10cSrcweir                 // nEnd is start of possible next text portion
713*cdf0e10cSrcweir                 nPos = nEnd;
714*cdf0e10cSrcweir             }
715*cdf0e10cSrcweir             while( (nPos < nLen) && (rStr[ nPos ] != OOX_DUMP_CFG_QUOTE) );
716*cdf0e10cSrcweir             // add token, seek to list separator, ignore text following closing quote
717*cdf0e10cSrcweir             aBuffer.append( aToken.makeStringAndClear() );
718*cdf0e10cSrcweir             nPos = lclIndexOf( rStr, OOX_DUMP_CFG_LISTSEP, nPos );
719*cdf0e10cSrcweir             if( nPos < nLen )
720*cdf0e10cSrcweir                 aBuffer.append( OOX_DUMP_LF );
721*cdf0e10cSrcweir             // set current position behind list separator
722*cdf0e10cSrcweir             ++nPos;
723*cdf0e10cSrcweir         }
724*cdf0e10cSrcweir         else
725*cdf0e10cSrcweir         {
726*cdf0e10cSrcweir             // find list separator, add token text to buffer
727*cdf0e10cSrcweir             sal_Int32 nEnd = lclIndexOf( rStr, OOX_DUMP_CFG_LISTSEP, nPos );
728*cdf0e10cSrcweir             aBuffer.append( rStr.copy( nPos, nEnd - nPos ) );
729*cdf0e10cSrcweir             if( nEnd < nLen )
730*cdf0e10cSrcweir                 aBuffer.append( OOX_DUMP_LF );
731*cdf0e10cSrcweir             // set current position behind list separator
732*cdf0e10cSrcweir             nPos = nEnd + 1;
733*cdf0e10cSrcweir         }
734*cdf0e10cSrcweir     }
735*cdf0e10cSrcweir 
736*cdf0e10cSrcweir     return aBuffer.makeStringAndClear();
737*cdf0e10cSrcweir }
738*cdf0e10cSrcweir 
739*cdf0e10cSrcweir } // namespace
740*cdf0e10cSrcweir 
741*cdf0e10cSrcweir OUString StringHelper::trimSpaces( const OUString& rStr )
742*cdf0e10cSrcweir {
743*cdf0e10cSrcweir     sal_Int32 nBeg = 0;
744*cdf0e10cSrcweir     while( (nBeg < rStr.getLength()) && ((rStr[ nBeg ] == ' ') || (rStr[ nBeg ] == '\t')) )
745*cdf0e10cSrcweir         ++nBeg;
746*cdf0e10cSrcweir     sal_Int32 nEnd = rStr.getLength();
747*cdf0e10cSrcweir     while( (nEnd > nBeg) && ((rStr[ nEnd - 1 ] == ' ') || (rStr[ nEnd - 1 ] == '\t')) )
748*cdf0e10cSrcweir         --nEnd;
749*cdf0e10cSrcweir     return rStr.copy( nBeg, nEnd - nBeg );
750*cdf0e10cSrcweir }
751*cdf0e10cSrcweir 
752*cdf0e10cSrcweir OUString StringHelper::trimTrailingNul( const OUString& rStr )
753*cdf0e10cSrcweir {
754*cdf0e10cSrcweir     sal_Int32 nLastPos = rStr.getLength() - 1;
755*cdf0e10cSrcweir     if( (nLastPos >= 0) && (rStr[ nLastPos ] == 0) )
756*cdf0e10cSrcweir         return rStr.copy( 0, nLastPos );
757*cdf0e10cSrcweir     return rStr;
758*cdf0e10cSrcweir }
759*cdf0e10cSrcweir 
760*cdf0e10cSrcweir OString StringHelper::convertToUtf8( const OUString& rStr )
761*cdf0e10cSrcweir {
762*cdf0e10cSrcweir     return OUStringToOString( rStr, RTL_TEXTENCODING_UTF8 );
763*cdf0e10cSrcweir }
764*cdf0e10cSrcweir 
765*cdf0e10cSrcweir DataType StringHelper::convertToDataType( const OUString& rStr )
766*cdf0e10cSrcweir {
767*cdf0e10cSrcweir     DataType eType = DATATYPE_VOID;
768*cdf0e10cSrcweir     if( rStr.equalsAscii( "int8" ) )
769*cdf0e10cSrcweir         eType = DATATYPE_INT8;
770*cdf0e10cSrcweir     else if( rStr.equalsAscii( "uint8" ) )
771*cdf0e10cSrcweir         eType = DATATYPE_UINT8;
772*cdf0e10cSrcweir     else if( rStr.equalsAscii( "int16" ) )
773*cdf0e10cSrcweir         eType = DATATYPE_INT16;
774*cdf0e10cSrcweir     else if( rStr.equalsAscii( "uint16" ) )
775*cdf0e10cSrcweir         eType = DATATYPE_UINT16;
776*cdf0e10cSrcweir     else if( rStr.equalsAscii( "int32" ) )
777*cdf0e10cSrcweir         eType = DATATYPE_INT32;
778*cdf0e10cSrcweir     else if( rStr.equalsAscii( "uint32" ) )
779*cdf0e10cSrcweir         eType = DATATYPE_UINT32;
780*cdf0e10cSrcweir     else if( rStr.equalsAscii( "int64" ) )
781*cdf0e10cSrcweir         eType = DATATYPE_INT64;
782*cdf0e10cSrcweir     else if( rStr.equalsAscii( "uint64" ) )
783*cdf0e10cSrcweir         eType = DATATYPE_UINT64;
784*cdf0e10cSrcweir     else if( rStr.equalsAscii( "float" ) )
785*cdf0e10cSrcweir         eType = DATATYPE_FLOAT;
786*cdf0e10cSrcweir     else if( rStr.equalsAscii( "double" ) )
787*cdf0e10cSrcweir         eType = DATATYPE_DOUBLE;
788*cdf0e10cSrcweir     return eType;
789*cdf0e10cSrcweir }
790*cdf0e10cSrcweir 
791*cdf0e10cSrcweir FormatType StringHelper::convertToFormatType( const OUString& rStr )
792*cdf0e10cSrcweir {
793*cdf0e10cSrcweir     FormatType eType = FORMATTYPE_NONE;
794*cdf0e10cSrcweir     if( rStr.equalsAscii( "dec" ) )
795*cdf0e10cSrcweir         eType = FORMATTYPE_DEC;
796*cdf0e10cSrcweir     else if( rStr.equalsAscii( "hex" ) )
797*cdf0e10cSrcweir         eType = FORMATTYPE_HEX;
798*cdf0e10cSrcweir     else if( rStr.equalsAscii( "shorthex" ) )
799*cdf0e10cSrcweir         eType = FORMATTYPE_SHORTHEX;
800*cdf0e10cSrcweir     else if( rStr.equalsAscii( "bin" ) )
801*cdf0e10cSrcweir         eType = FORMATTYPE_BIN;
802*cdf0e10cSrcweir     else if( rStr.equalsAscii( "fix" ) )
803*cdf0e10cSrcweir         eType = FORMATTYPE_FIX;
804*cdf0e10cSrcweir     else if( rStr.equalsAscii( "bool" ) )
805*cdf0e10cSrcweir         eType = FORMATTYPE_BOOL;
806*cdf0e10cSrcweir     return eType;
807*cdf0e10cSrcweir }
808*cdf0e10cSrcweir 
809*cdf0e10cSrcweir bool StringHelper::convertFromDec( sal_Int64& ornData, const OUString& rData )
810*cdf0e10cSrcweir {
811*cdf0e10cSrcweir     sal_Int32 nPos = 0;
812*cdf0e10cSrcweir     sal_Int32 nLen = rData.getLength();
813*cdf0e10cSrcweir     bool bNeg = false;
814*cdf0e10cSrcweir     if( (nLen > 0) && (rData[ 0 ] == '-') )
815*cdf0e10cSrcweir     {
816*cdf0e10cSrcweir         bNeg = true;
817*cdf0e10cSrcweir         ++nPos;
818*cdf0e10cSrcweir     }
819*cdf0e10cSrcweir     ornData = 0;
820*cdf0e10cSrcweir     for( ; nPos < nLen; ++nPos )
821*cdf0e10cSrcweir     {
822*cdf0e10cSrcweir         sal_Unicode cChar = rData[ nPos ];
823*cdf0e10cSrcweir         if( (cChar < '0') || (cChar > '9') )
824*cdf0e10cSrcweir             return false;
825*cdf0e10cSrcweir         (ornData *= 10) += (cChar - '0');
826*cdf0e10cSrcweir     }
827*cdf0e10cSrcweir     if( bNeg )
828*cdf0e10cSrcweir         ornData *= -1;
829*cdf0e10cSrcweir     return true;
830*cdf0e10cSrcweir }
831*cdf0e10cSrcweir 
832*cdf0e10cSrcweir bool StringHelper::convertFromHex( sal_Int64& ornData, const OUString& rData )
833*cdf0e10cSrcweir {
834*cdf0e10cSrcweir     ornData = 0;
835*cdf0e10cSrcweir     for( sal_Int32 nPos = 0, nLen = rData.getLength(); nPos < nLen; ++nPos )
836*cdf0e10cSrcweir     {
837*cdf0e10cSrcweir         sal_Unicode cChar = rData[ nPos ];
838*cdf0e10cSrcweir         if( ('0' <= cChar) && (cChar <= '9') )
839*cdf0e10cSrcweir             cChar -= '0';
840*cdf0e10cSrcweir         else if( ('A' <= cChar) && (cChar <= 'F') )
841*cdf0e10cSrcweir             cChar -= ('A' - 10);
842*cdf0e10cSrcweir         else if( ('a' <= cChar) && (cChar <= 'f') )
843*cdf0e10cSrcweir             cChar -= ('a' - 10);
844*cdf0e10cSrcweir         else
845*cdf0e10cSrcweir             return false;
846*cdf0e10cSrcweir         (ornData <<= 4) += cChar;
847*cdf0e10cSrcweir     }
848*cdf0e10cSrcweir     return true;
849*cdf0e10cSrcweir }
850*cdf0e10cSrcweir 
851*cdf0e10cSrcweir bool StringHelper::convertStringToInt( sal_Int64& ornData, const OUString& rData )
852*cdf0e10cSrcweir {
853*cdf0e10cSrcweir     if( (rData.getLength() > 2) && (rData[ 0 ] == '0') && ((rData[ 1 ] == 'X') || (rData[ 1 ] == 'x')) )
854*cdf0e10cSrcweir         return convertFromHex( ornData, rData.copy( 2 ) );
855*cdf0e10cSrcweir     return convertFromDec( ornData, rData );
856*cdf0e10cSrcweir }
857*cdf0e10cSrcweir 
858*cdf0e10cSrcweir bool StringHelper::convertStringToDouble( double& orfData, const OUString& rData )
859*cdf0e10cSrcweir {
860*cdf0e10cSrcweir     rtl_math_ConversionStatus eStatus = rtl_math_ConversionStatus_Ok;
861*cdf0e10cSrcweir     sal_Int32 nSize = 0;
862*cdf0e10cSrcweir     orfData = rtl::math::stringToDouble( rData, '.', '\0', &eStatus, &nSize );
863*cdf0e10cSrcweir     return (eStatus == rtl_math_ConversionStatus_Ok) && (nSize == rData.getLength());
864*cdf0e10cSrcweir }
865*cdf0e10cSrcweir 
866*cdf0e10cSrcweir bool StringHelper::convertStringToBool( const OUString& rData )
867*cdf0e10cSrcweir {
868*cdf0e10cSrcweir     if( rData.equalsAscii( "true" ) )
869*cdf0e10cSrcweir         return true;
870*cdf0e10cSrcweir     if( rData.equalsAscii( "false" ) )
871*cdf0e10cSrcweir         return false;
872*cdf0e10cSrcweir     sal_Int64 nData;
873*cdf0e10cSrcweir     return convertStringToInt( nData, rData ) && (nData != 0);
874*cdf0e10cSrcweir }
875*cdf0e10cSrcweir 
876*cdf0e10cSrcweir OUStringPair StringHelper::convertStringToPair( const OUString& rString, sal_Unicode cSep )
877*cdf0e10cSrcweir {
878*cdf0e10cSrcweir     OUStringPair aPair;
879*cdf0e10cSrcweir     if( rString.getLength() > 0 )
880*cdf0e10cSrcweir     {
881*cdf0e10cSrcweir         sal_Int32 nEqPos = rString.indexOf( cSep );
882*cdf0e10cSrcweir         if( nEqPos < 0 )
883*cdf0e10cSrcweir         {
884*cdf0e10cSrcweir             aPair.first = rString;
885*cdf0e10cSrcweir         }
886*cdf0e10cSrcweir         else
887*cdf0e10cSrcweir         {
888*cdf0e10cSrcweir             aPair.first = StringHelper::trimSpaces( rString.copy( 0, nEqPos ) );
889*cdf0e10cSrcweir             aPair.second = StringHelper::trimSpaces( rString.copy( nEqPos + 1 ) );
890*cdf0e10cSrcweir         }
891*cdf0e10cSrcweir     }
892*cdf0e10cSrcweir     return aPair;
893*cdf0e10cSrcweir }
894*cdf0e10cSrcweir 
895*cdf0e10cSrcweir void StringHelper::convertStringToStringList( OUStringVector& orVec, const OUString& rData, bool bIgnoreEmpty )
896*cdf0e10cSrcweir {
897*cdf0e10cSrcweir     orVec.clear();
898*cdf0e10cSrcweir     OUString aUnquotedData = lclTrimQuotedStringList( rData );
899*cdf0e10cSrcweir     sal_Int32 nPos = 0;
900*cdf0e10cSrcweir     sal_Int32 nLen = aUnquotedData.getLength();
901*cdf0e10cSrcweir     while( (0 <= nPos) && (nPos < nLen) )
902*cdf0e10cSrcweir     {
903*cdf0e10cSrcweir         OUString aToken = getToken( aUnquotedData, nPos, OOX_DUMP_LF );
904*cdf0e10cSrcweir         if( !bIgnoreEmpty || (aToken.getLength() > 0) )
905*cdf0e10cSrcweir             orVec.push_back( aToken );
906*cdf0e10cSrcweir     }
907*cdf0e10cSrcweir }
908*cdf0e10cSrcweir 
909*cdf0e10cSrcweir void StringHelper::convertStringToIntList( Int64Vector& orVec, const OUString& rData, bool bIgnoreEmpty )
910*cdf0e10cSrcweir {
911*cdf0e10cSrcweir     orVec.clear();
912*cdf0e10cSrcweir     OUString aUnquotedData = lclTrimQuotedStringList( rData );
913*cdf0e10cSrcweir     sal_Int32 nPos = 0;
914*cdf0e10cSrcweir     sal_Int32 nLen = aUnquotedData.getLength();
915*cdf0e10cSrcweir     sal_Int64 nData;
916*cdf0e10cSrcweir     while( (0 <= nPos) && (nPos < nLen) )
917*cdf0e10cSrcweir     {
918*cdf0e10cSrcweir         bool bOk = convertStringToInt( nData, getToken( aUnquotedData, nPos, OOX_DUMP_LF ) );
919*cdf0e10cSrcweir         if( !bIgnoreEmpty || bOk )
920*cdf0e10cSrcweir             orVec.push_back( bOk ? nData : 0 );
921*cdf0e10cSrcweir     }
922*cdf0e10cSrcweir }
923*cdf0e10cSrcweir 
924*cdf0e10cSrcweir // ============================================================================
925*cdf0e10cSrcweir // ============================================================================
926*cdf0e10cSrcweir 
927*cdf0e10cSrcweir FormulaStack::FormulaStack() :
928*cdf0e10cSrcweir     mbError( false )
929*cdf0e10cSrcweir {
930*cdf0e10cSrcweir }
931*cdf0e10cSrcweir 
932*cdf0e10cSrcweir void FormulaStack::pushOperand( const String& rOp, const OUString& rTokClass )
933*cdf0e10cSrcweir {
934*cdf0e10cSrcweir     maFmlaStack.push( rOp );
935*cdf0e10cSrcweir     maClassStack.push( rTokClass );
936*cdf0e10cSrcweir }
937*cdf0e10cSrcweir 
938*cdf0e10cSrcweir void FormulaStack::pushOperand( const String& rOp )
939*cdf0e10cSrcweir {
940*cdf0e10cSrcweir     pushOperand( rOp, OUString( OOX_DUMP_BASECLASS ) );
941*cdf0e10cSrcweir }
942*cdf0e10cSrcweir 
943*cdf0e10cSrcweir void FormulaStack::pushUnaryOp( const String& rLOp, const String& rROp )
944*cdf0e10cSrcweir {
945*cdf0e10cSrcweir     pushUnaryOp( maFmlaStack, rLOp, rROp );
946*cdf0e10cSrcweir     pushUnaryOp( maClassStack, rLOp, rROp );
947*cdf0e10cSrcweir }
948*cdf0e10cSrcweir 
949*cdf0e10cSrcweir void FormulaStack::pushBinaryOp( const String& rOp )
950*cdf0e10cSrcweir {
951*cdf0e10cSrcweir     pushBinaryOp( maFmlaStack, rOp );
952*cdf0e10cSrcweir     pushBinaryOp( maClassStack, rOp );
953*cdf0e10cSrcweir }
954*cdf0e10cSrcweir 
955*cdf0e10cSrcweir void FormulaStack::pushFuncOp( const String& rFunc, const OUString& rTokClass, sal_uInt8 nParamCount )
956*cdf0e10cSrcweir {
957*cdf0e10cSrcweir     pushFuncOp( maFmlaStack, rFunc, nParamCount );
958*cdf0e10cSrcweir     pushFuncOp( maClassStack, rTokClass, nParamCount );
959*cdf0e10cSrcweir }
960*cdf0e10cSrcweir 
961*cdf0e10cSrcweir void FormulaStack::replaceOnTop( const OUString& rOld, const OUString& rNew )
962*cdf0e10cSrcweir {
963*cdf0e10cSrcweir     if( !maFmlaStack.empty() )
964*cdf0e10cSrcweir     {
965*cdf0e10cSrcweir         sal_Int32 nPos = maFmlaStack.top().indexOf( rOld );
966*cdf0e10cSrcweir         if( nPos >= 0 )
967*cdf0e10cSrcweir             maFmlaStack.top() = maFmlaStack.top().copy( 0, nPos ) + rNew + maFmlaStack.top().copy( nPos + rOld.getLength() );
968*cdf0e10cSrcweir     }
969*cdf0e10cSrcweir }
970*cdf0e10cSrcweir 
971*cdf0e10cSrcweir const OUString& FormulaStack::getString( const StringStack& rStack ) const
972*cdf0e10cSrcweir {
973*cdf0e10cSrcweir     static const OUString saStackError = OOX_DUMP_ERRSTRING( "stack" );
974*cdf0e10cSrcweir     return (mbError || rStack.empty()) ? saStackError : rStack.top();
975*cdf0e10cSrcweir }
976*cdf0e10cSrcweir 
977*cdf0e10cSrcweir void FormulaStack::pushUnaryOp( StringStack& rStack, const OUString& rLOp, const OUString& rROp )
978*cdf0e10cSrcweir {
979*cdf0e10cSrcweir     if( check( !rStack.empty() ) )
980*cdf0e10cSrcweir         rStack.top() = rLOp + rStack.top() + rROp;
981*cdf0e10cSrcweir }
982*cdf0e10cSrcweir 
983*cdf0e10cSrcweir void FormulaStack::pushBinaryOp( StringStack& rStack, const OUString& rOp )
984*cdf0e10cSrcweir {
985*cdf0e10cSrcweir     OUString aSecond;
986*cdf0e10cSrcweir     if( check( !rStack.empty() ) )
987*cdf0e10cSrcweir     {
988*cdf0e10cSrcweir         aSecond = rStack.top();
989*cdf0e10cSrcweir         rStack.pop();
990*cdf0e10cSrcweir     }
991*cdf0e10cSrcweir     if( check( !rStack.empty() ) )
992*cdf0e10cSrcweir         rStack.top() = rStack.top() + rOp + aSecond;
993*cdf0e10cSrcweir }
994*cdf0e10cSrcweir 
995*cdf0e10cSrcweir void FormulaStack::pushFuncOp( StringStack& rStack, const OUString& rOp, sal_uInt8 nParamCount )
996*cdf0e10cSrcweir {
997*cdf0e10cSrcweir     OUStringBuffer aFunc;
998*cdf0e10cSrcweir     for( sal_uInt8 nParam = 0; (nParam < nParamCount) && check( !rStack.empty() ); ++nParam )
999*cdf0e10cSrcweir     {
1000*cdf0e10cSrcweir         StringHelper::prependToken( aFunc, rStack.top(), OOX_DUMP_FUNCSEP );
1001*cdf0e10cSrcweir         rStack.pop();
1002*cdf0e10cSrcweir     }
1003*cdf0e10cSrcweir     StringHelper::enclose( aFunc, '(', ')' );
1004*cdf0e10cSrcweir     aFunc.insert( 0, rOp );
1005*cdf0e10cSrcweir     rStack.push( aFunc.makeStringAndClear() );
1006*cdf0e10cSrcweir }
1007*cdf0e10cSrcweir 
1008*cdf0e10cSrcweir // ============================================================================
1009*cdf0e10cSrcweir // ============================================================================
1010*cdf0e10cSrcweir 
1011*cdf0e10cSrcweir Base::~Base()
1012*cdf0e10cSrcweir {
1013*cdf0e10cSrcweir }
1014*cdf0e10cSrcweir 
1015*cdf0e10cSrcweir // ============================================================================
1016*cdf0e10cSrcweir // ============================================================================
1017*cdf0e10cSrcweir 
1018*cdf0e10cSrcweir ConfigItemBase::~ConfigItemBase()
1019*cdf0e10cSrcweir {
1020*cdf0e10cSrcweir }
1021*cdf0e10cSrcweir 
1022*cdf0e10cSrcweir void ConfigItemBase::readConfigBlock( TextInputStream& rStrm )
1023*cdf0e10cSrcweir {
1024*cdf0e10cSrcweir     readConfigBlockContents( rStrm );
1025*cdf0e10cSrcweir }
1026*cdf0e10cSrcweir 
1027*cdf0e10cSrcweir void ConfigItemBase::implProcessConfigItemStr(
1028*cdf0e10cSrcweir         TextInputStream& /*rStrm*/, const OUString& /*rKey*/, const OUString& /*rData*/ )
1029*cdf0e10cSrcweir {
1030*cdf0e10cSrcweir }
1031*cdf0e10cSrcweir 
1032*cdf0e10cSrcweir void ConfigItemBase::implProcessConfigItemInt(
1033*cdf0e10cSrcweir         TextInputStream& /*rStrm*/, sal_Int64 /*nKey*/, const OUString& /*rData*/ )
1034*cdf0e10cSrcweir {
1035*cdf0e10cSrcweir }
1036*cdf0e10cSrcweir 
1037*cdf0e10cSrcweir void ConfigItemBase::readConfigBlockContents( TextInputStream& rStrm )
1038*cdf0e10cSrcweir {
1039*cdf0e10cSrcweir     bool bLoop = true;
1040*cdf0e10cSrcweir     while( bLoop && !rStrm.isEof() )
1041*cdf0e10cSrcweir     {
1042*cdf0e10cSrcweir         OUString aKey, aData;
1043*cdf0e10cSrcweir         switch( readConfigLine( rStrm, aKey, aData ) )
1044*cdf0e10cSrcweir         {
1045*cdf0e10cSrcweir             case LINETYPE_DATA:
1046*cdf0e10cSrcweir                 processConfigItem( rStrm, aKey, aData );
1047*cdf0e10cSrcweir             break;
1048*cdf0e10cSrcweir             case LINETYPE_END:
1049*cdf0e10cSrcweir                 bLoop = false;
1050*cdf0e10cSrcweir             break;
1051*cdf0e10cSrcweir         }
1052*cdf0e10cSrcweir     }
1053*cdf0e10cSrcweir }
1054*cdf0e10cSrcweir 
1055*cdf0e10cSrcweir ConfigItemBase::LineType ConfigItemBase::readConfigLine(
1056*cdf0e10cSrcweir         TextInputStream& rStrm, OUString& orKey, OUString& orData ) const
1057*cdf0e10cSrcweir {
1058*cdf0e10cSrcweir     OUString aLine;
1059*cdf0e10cSrcweir     while( !rStrm.isEof() && (aLine.getLength() == 0) )
1060*cdf0e10cSrcweir     {
1061*cdf0e10cSrcweir         aLine = rStrm.readLine();
1062*cdf0e10cSrcweir         if( (aLine.getLength() > 0) && (aLine[ 0 ] == OOX_DUMP_BOM) )
1063*cdf0e10cSrcweir             aLine = aLine.copy( 1 );
1064*cdf0e10cSrcweir         aLine = StringHelper::trimSpaces( aLine );
1065*cdf0e10cSrcweir         if( aLine.getLength() > 0 )
1066*cdf0e10cSrcweir         {
1067*cdf0e10cSrcweir             // ignore comments (starting with hash or semicolon)
1068*cdf0e10cSrcweir             sal_Unicode cChar = aLine[ 0 ];
1069*cdf0e10cSrcweir             if( (cChar == '#') || (cChar == ';') )
1070*cdf0e10cSrcweir                 aLine = OUString();
1071*cdf0e10cSrcweir         }
1072*cdf0e10cSrcweir     }
1073*cdf0e10cSrcweir 
1074*cdf0e10cSrcweir     OUStringPair aPair = StringHelper::convertStringToPair( aLine );
1075*cdf0e10cSrcweir     orKey = aPair.first;
1076*cdf0e10cSrcweir     orData = aPair.second;
1077*cdf0e10cSrcweir     return ((orKey.getLength() > 0) && ((orData.getLength() > 0) || !orKey.equalsAscii( "end" ))) ?
1078*cdf0e10cSrcweir         LINETYPE_DATA : LINETYPE_END;
1079*cdf0e10cSrcweir }
1080*cdf0e10cSrcweir 
1081*cdf0e10cSrcweir ConfigItemBase::LineType ConfigItemBase::readConfigLine( TextInputStream& rStrm ) const
1082*cdf0e10cSrcweir {
1083*cdf0e10cSrcweir     OUString aKey, aData;
1084*cdf0e10cSrcweir     return readConfigLine( rStrm, aKey, aData );
1085*cdf0e10cSrcweir }
1086*cdf0e10cSrcweir 
1087*cdf0e10cSrcweir void ConfigItemBase::processConfigItem(
1088*cdf0e10cSrcweir         TextInputStream& rStrm, const OUString& rKey, const OUString& rData )
1089*cdf0e10cSrcweir {
1090*cdf0e10cSrcweir     sal_Int64 nKey;
1091*cdf0e10cSrcweir     if( StringHelper::convertStringToInt( nKey, rKey ) )
1092*cdf0e10cSrcweir         implProcessConfigItemInt( rStrm, nKey, rData );
1093*cdf0e10cSrcweir     else
1094*cdf0e10cSrcweir         implProcessConfigItemStr( rStrm, rKey, rData );
1095*cdf0e10cSrcweir }
1096*cdf0e10cSrcweir 
1097*cdf0e10cSrcweir // ============================================================================
1098*cdf0e10cSrcweir 
1099*cdf0e10cSrcweir NameListBase::~NameListBase()
1100*cdf0e10cSrcweir {
1101*cdf0e10cSrcweir }
1102*cdf0e10cSrcweir 
1103*cdf0e10cSrcweir void NameListBase::setName( sal_Int64 nKey, const String& rName )
1104*cdf0e10cSrcweir {
1105*cdf0e10cSrcweir     implSetName( nKey, rName );
1106*cdf0e10cSrcweir }
1107*cdf0e10cSrcweir 
1108*cdf0e10cSrcweir void NameListBase::includeList( const NameListRef& rxList )
1109*cdf0e10cSrcweir {
1110*cdf0e10cSrcweir     if( rxList.get() )
1111*cdf0e10cSrcweir     {
1112*cdf0e10cSrcweir         for( const_iterator aIt = rxList->begin(), aEnd = rxList->end(); aIt != aEnd; ++aIt )
1113*cdf0e10cSrcweir             maMap[ aIt->first ] = aIt->second;
1114*cdf0e10cSrcweir         implIncludeList( *rxList );
1115*cdf0e10cSrcweir     }
1116*cdf0e10cSrcweir }
1117*cdf0e10cSrcweir 
1118*cdf0e10cSrcweir bool NameListBase::implIsValid() const
1119*cdf0e10cSrcweir {
1120*cdf0e10cSrcweir     return true;
1121*cdf0e10cSrcweir }
1122*cdf0e10cSrcweir 
1123*cdf0e10cSrcweir void NameListBase::implProcessConfigItemStr(
1124*cdf0e10cSrcweir         TextInputStream& rStrm, const OUString& rKey, const OUString& rData )
1125*cdf0e10cSrcweir {
1126*cdf0e10cSrcweir     if( rKey.equalsAscii( "include" ) )
1127*cdf0e10cSrcweir         include( rData );
1128*cdf0e10cSrcweir     else if( rKey.equalsAscii( "exclude" ) )
1129*cdf0e10cSrcweir         exclude( rData );
1130*cdf0e10cSrcweir     else
1131*cdf0e10cSrcweir         ConfigItemBase::implProcessConfigItemStr( rStrm, rKey, rData );
1132*cdf0e10cSrcweir }
1133*cdf0e10cSrcweir 
1134*cdf0e10cSrcweir void NameListBase::implProcessConfigItemInt(
1135*cdf0e10cSrcweir         TextInputStream& /*rStrm*/, sal_Int64 nKey, const OUString& rData )
1136*cdf0e10cSrcweir {
1137*cdf0e10cSrcweir     implSetName( nKey, rData );
1138*cdf0e10cSrcweir }
1139*cdf0e10cSrcweir 
1140*cdf0e10cSrcweir void NameListBase::insertRawName( sal_Int64 nKey, const OUString& rName )
1141*cdf0e10cSrcweir {
1142*cdf0e10cSrcweir     maMap[ nKey ] = rName;
1143*cdf0e10cSrcweir }
1144*cdf0e10cSrcweir 
1145*cdf0e10cSrcweir const OUString* NameListBase::findRawName( sal_Int64 nKey ) const
1146*cdf0e10cSrcweir {
1147*cdf0e10cSrcweir     const_iterator aIt = maMap.find( nKey );
1148*cdf0e10cSrcweir     return (aIt == end()) ? 0 : &aIt->second;
1149*cdf0e10cSrcweir }
1150*cdf0e10cSrcweir 
1151*cdf0e10cSrcweir void NameListBase::include( const OUString& rListKeys )
1152*cdf0e10cSrcweir {
1153*cdf0e10cSrcweir     OUStringVector aVec;
1154*cdf0e10cSrcweir     StringHelper::convertStringToStringList( aVec, rListKeys, true );
1155*cdf0e10cSrcweir     for( OUStringVector::const_iterator aIt = aVec.begin(), aEnd = aVec.end(); aIt != aEnd; ++aIt )
1156*cdf0e10cSrcweir         includeList( mrCfgData.getNameList( *aIt ) );
1157*cdf0e10cSrcweir }
1158*cdf0e10cSrcweir 
1159*cdf0e10cSrcweir void NameListBase::exclude( const OUString& rKeys )
1160*cdf0e10cSrcweir {
1161*cdf0e10cSrcweir     Int64Vector aVec;
1162*cdf0e10cSrcweir     StringHelper::convertStringToIntList( aVec, rKeys, true );
1163*cdf0e10cSrcweir     for( Int64Vector::const_iterator aIt = aVec.begin(), aEnd = aVec.end(); aIt != aEnd; ++aIt )
1164*cdf0e10cSrcweir         maMap.erase( *aIt );
1165*cdf0e10cSrcweir }
1166*cdf0e10cSrcweir 
1167*cdf0e10cSrcweir // ============================================================================
1168*cdf0e10cSrcweir 
1169*cdf0e10cSrcweir void ItemFormatMap::insertFormats( const NameListRef& rxNameList )
1170*cdf0e10cSrcweir {
1171*cdf0e10cSrcweir     if( Base::isValid( rxNameList ) )
1172*cdf0e10cSrcweir         for( NameListBase::const_iterator aIt = rxNameList->begin(), aEnd = rxNameList->end(); aIt != aEnd; ++aIt )
1173*cdf0e10cSrcweir             (*this)[ aIt->first ].parse( aIt->second );
1174*cdf0e10cSrcweir }
1175*cdf0e10cSrcweir 
1176*cdf0e10cSrcweir // ============================================================================
1177*cdf0e10cSrcweir 
1178*cdf0e10cSrcweir ConstList::ConstList( const SharedConfigData& rCfgData ) :
1179*cdf0e10cSrcweir     NameListBase( rCfgData ),
1180*cdf0e10cSrcweir     maDefName( OOX_DUMP_ERR_NONAME ),
1181*cdf0e10cSrcweir     mbQuoteNames( false )
1182*cdf0e10cSrcweir {
1183*cdf0e10cSrcweir }
1184*cdf0e10cSrcweir 
1185*cdf0e10cSrcweir void ConstList::implProcessConfigItemStr(
1186*cdf0e10cSrcweir         TextInputStream& rStrm, const OUString& rKey, const OUString& rData )
1187*cdf0e10cSrcweir {
1188*cdf0e10cSrcweir     if( rKey.equalsAscii( "default" ) )
1189*cdf0e10cSrcweir         setDefaultName( rData );
1190*cdf0e10cSrcweir     else if( rKey.equalsAscii( "quote-names" ) )
1191*cdf0e10cSrcweir         setQuoteNames( StringHelper::convertStringToBool( rData ) );
1192*cdf0e10cSrcweir     else
1193*cdf0e10cSrcweir         NameListBase::implProcessConfigItemStr( rStrm, rKey, rData );
1194*cdf0e10cSrcweir }
1195*cdf0e10cSrcweir 
1196*cdf0e10cSrcweir void ConstList::implSetName( sal_Int64 nKey, const OUString& rName )
1197*cdf0e10cSrcweir {
1198*cdf0e10cSrcweir     insertRawName( nKey, rName );
1199*cdf0e10cSrcweir }
1200*cdf0e10cSrcweir 
1201*cdf0e10cSrcweir OUString ConstList::implGetName( const Config& /*rCfg*/, sal_Int64 nKey ) const
1202*cdf0e10cSrcweir {
1203*cdf0e10cSrcweir     const OUString* pName = findRawName( nKey );
1204*cdf0e10cSrcweir     OUString aName = pName ? *pName : maDefName;
1205*cdf0e10cSrcweir     if( mbQuoteNames )
1206*cdf0e10cSrcweir     {
1207*cdf0e10cSrcweir         OUStringBuffer aBuffer( aName );
1208*cdf0e10cSrcweir         StringHelper::enclose( aBuffer, OOX_DUMP_STRQUOTE );
1209*cdf0e10cSrcweir         aName = aBuffer.makeStringAndClear();
1210*cdf0e10cSrcweir     }
1211*cdf0e10cSrcweir     return aName;
1212*cdf0e10cSrcweir }
1213*cdf0e10cSrcweir 
1214*cdf0e10cSrcweir OUString ConstList::implGetNameDbl( const Config& /*rCfg*/, double /*fValue*/ ) const
1215*cdf0e10cSrcweir {
1216*cdf0e10cSrcweir     return OUString();
1217*cdf0e10cSrcweir }
1218*cdf0e10cSrcweir 
1219*cdf0e10cSrcweir void ConstList::implIncludeList( const NameListBase& rList )
1220*cdf0e10cSrcweir {
1221*cdf0e10cSrcweir     if( const ConstList* pConstList = dynamic_cast< const ConstList* >( &rList ) )
1222*cdf0e10cSrcweir     {
1223*cdf0e10cSrcweir         maDefName = pConstList->maDefName;
1224*cdf0e10cSrcweir         mbQuoteNames = pConstList->mbQuoteNames;
1225*cdf0e10cSrcweir     }
1226*cdf0e10cSrcweir }
1227*cdf0e10cSrcweir 
1228*cdf0e10cSrcweir // ============================================================================
1229*cdf0e10cSrcweir 
1230*cdf0e10cSrcweir MultiList::MultiList( const SharedConfigData& rCfgData ) :
1231*cdf0e10cSrcweir     ConstList( rCfgData ),
1232*cdf0e10cSrcweir     mbIgnoreEmpty( true )
1233*cdf0e10cSrcweir {
1234*cdf0e10cSrcweir }
1235*cdf0e10cSrcweir 
1236*cdf0e10cSrcweir void MultiList::setNamesFromVec( sal_Int64 nStartKey, const OUStringVector& rNames )
1237*cdf0e10cSrcweir {
1238*cdf0e10cSrcweir     sal_Int64 nKey = nStartKey;
1239*cdf0e10cSrcweir     for( OUStringVector::const_iterator aIt = rNames.begin(), aEnd = rNames.end(); aIt != aEnd; ++aIt, ++nKey )
1240*cdf0e10cSrcweir         if( !mbIgnoreEmpty || (aIt->getLength() > 0) )
1241*cdf0e10cSrcweir             insertRawName( nKey, *aIt );
1242*cdf0e10cSrcweir }
1243*cdf0e10cSrcweir 
1244*cdf0e10cSrcweir void MultiList::implProcessConfigItemStr(
1245*cdf0e10cSrcweir         TextInputStream& rStrm, const OUString& rKey, const OUString& rData )
1246*cdf0e10cSrcweir {
1247*cdf0e10cSrcweir     if( rKey.equalsAscii( "ignore-empty" ) )
1248*cdf0e10cSrcweir         mbIgnoreEmpty = StringHelper::convertStringToBool( rData );
1249*cdf0e10cSrcweir     else
1250*cdf0e10cSrcweir         ConstList::implProcessConfigItemStr( rStrm, rKey, rData );
1251*cdf0e10cSrcweir }
1252*cdf0e10cSrcweir 
1253*cdf0e10cSrcweir void MultiList::implSetName( sal_Int64 nKey, const OUString& rName )
1254*cdf0e10cSrcweir {
1255*cdf0e10cSrcweir     OUStringVector aNames;
1256*cdf0e10cSrcweir     StringHelper::convertStringToStringList( aNames, rName, false );
1257*cdf0e10cSrcweir     setNamesFromVec( nKey, aNames );
1258*cdf0e10cSrcweir }
1259*cdf0e10cSrcweir 
1260*cdf0e10cSrcweir // ============================================================================
1261*cdf0e10cSrcweir 
1262*cdf0e10cSrcweir FlagsList::FlagsList( const SharedConfigData& rCfgData ) :
1263*cdf0e10cSrcweir     NameListBase( rCfgData ),
1264*cdf0e10cSrcweir     mnIgnore( 0 )
1265*cdf0e10cSrcweir {
1266*cdf0e10cSrcweir }
1267*cdf0e10cSrcweir 
1268*cdf0e10cSrcweir void FlagsList::implProcessConfigItemStr(
1269*cdf0e10cSrcweir         TextInputStream& rStrm, const OUString& rKey, const OUString& rData )
1270*cdf0e10cSrcweir {
1271*cdf0e10cSrcweir     if( rKey.equalsAscii( "ignore" ) )
1272*cdf0e10cSrcweir     {
1273*cdf0e10cSrcweir         sal_Int64 nIgnore;
1274*cdf0e10cSrcweir         if( StringHelper::convertStringToInt( nIgnore, rData ) )
1275*cdf0e10cSrcweir             setIgnoreFlags( nIgnore );
1276*cdf0e10cSrcweir     }
1277*cdf0e10cSrcweir     else
1278*cdf0e10cSrcweir     {
1279*cdf0e10cSrcweir         NameListBase::implProcessConfigItemStr( rStrm, rKey, rData );
1280*cdf0e10cSrcweir     }
1281*cdf0e10cSrcweir }
1282*cdf0e10cSrcweir 
1283*cdf0e10cSrcweir void FlagsList::implSetName( sal_Int64 nKey, const OUString& rName )
1284*cdf0e10cSrcweir {
1285*cdf0e10cSrcweir     if( (nKey != 0) && ((nKey & (nKey - 1)) == 0) )  // only a single bit set?
1286*cdf0e10cSrcweir         insertRawName( nKey, rName );
1287*cdf0e10cSrcweir }
1288*cdf0e10cSrcweir 
1289*cdf0e10cSrcweir OUString FlagsList::implGetName( const Config& /*rCfg*/, sal_Int64 nKey ) const
1290*cdf0e10cSrcweir {
1291*cdf0e10cSrcweir     sal_Int64 nFound = mnIgnore;
1292*cdf0e10cSrcweir     OUStringBuffer aName;
1293*cdf0e10cSrcweir     // add known flags
1294*cdf0e10cSrcweir     for( const_iterator aIt = begin(), aEnd = end(); aIt != aEnd; ++aIt )
1295*cdf0e10cSrcweir     {
1296*cdf0e10cSrcweir         sal_Int64 nMask = aIt->first;
1297*cdf0e10cSrcweir         setFlag( nFound, nMask );
1298*cdf0e10cSrcweir         if( !getFlag( mnIgnore, nMask ) )
1299*cdf0e10cSrcweir         {
1300*cdf0e10cSrcweir             const OUString& rFlagName = aIt->second;
1301*cdf0e10cSrcweir             bool bOnOff = (rFlagName.getLength() > 0) && (rFlagName[ 0 ] == ':');
1302*cdf0e10cSrcweir             bool bFlag = getFlag( nKey, nMask );
1303*cdf0e10cSrcweir             if( bOnOff )
1304*cdf0e10cSrcweir             {
1305*cdf0e10cSrcweir                 StringHelper::appendToken( aName, rFlagName.copy( 1 ) );
1306*cdf0e10cSrcweir                 aName.appendAscii( bFlag ? ":on" : ":off" );
1307*cdf0e10cSrcweir             }
1308*cdf0e10cSrcweir             else
1309*cdf0e10cSrcweir             {
1310*cdf0e10cSrcweir                 bool bNegated = (rFlagName.getLength() > 0) && (rFlagName[ 0 ] == '!');
1311*cdf0e10cSrcweir                 sal_Int32 nBothSep = bNegated ? rFlagName.indexOf( '!', 1 ) : -1;
1312*cdf0e10cSrcweir                 if( bFlag )
1313*cdf0e10cSrcweir                 {
1314*cdf0e10cSrcweir                     if( !bNegated )
1315*cdf0e10cSrcweir                         StringHelper::appendToken( aName, rFlagName );
1316*cdf0e10cSrcweir                     else if( nBothSep > 0 )
1317*cdf0e10cSrcweir                         StringHelper::appendToken( aName, rFlagName.copy( nBothSep + 1 ) );
1318*cdf0e10cSrcweir                 }
1319*cdf0e10cSrcweir                 else if( bNegated )
1320*cdf0e10cSrcweir                 {
1321*cdf0e10cSrcweir                     if( nBothSep > 0 )
1322*cdf0e10cSrcweir                         StringHelper::appendToken( aName, rFlagName.copy( 1, nBothSep - 1 ) );
1323*cdf0e10cSrcweir                     else
1324*cdf0e10cSrcweir                         StringHelper::appendToken( aName, rFlagName.copy( 1 ) );
1325*cdf0e10cSrcweir                 }
1326*cdf0e10cSrcweir             }
1327*cdf0e10cSrcweir         }
1328*cdf0e10cSrcweir     }
1329*cdf0e10cSrcweir     // add unknown flags
1330*cdf0e10cSrcweir     setFlag( nKey, nFound, false );
1331*cdf0e10cSrcweir     if( nKey != 0 )
1332*cdf0e10cSrcweir     {
1333*cdf0e10cSrcweir         OUStringBuffer aUnknown( CREATE_OUSTRING( OOX_DUMP_UNKNOWN ) );
1334*cdf0e10cSrcweir         aUnknown.append( OOX_DUMP_ITEMSEP );
1335*cdf0e10cSrcweir         StringHelper::appendShortHex( aUnknown, nKey, true );
1336*cdf0e10cSrcweir         StringHelper::enclose( aUnknown, '(', ')' );
1337*cdf0e10cSrcweir         StringHelper::appendToken( aName, aUnknown.makeStringAndClear() );
1338*cdf0e10cSrcweir     }
1339*cdf0e10cSrcweir     return aName.makeStringAndClear();
1340*cdf0e10cSrcweir }
1341*cdf0e10cSrcweir 
1342*cdf0e10cSrcweir OUString FlagsList::implGetNameDbl( const Config& /*rCfg*/, double /*fValue*/ ) const
1343*cdf0e10cSrcweir {
1344*cdf0e10cSrcweir     return OUString();
1345*cdf0e10cSrcweir }
1346*cdf0e10cSrcweir 
1347*cdf0e10cSrcweir void FlagsList::implIncludeList( const NameListBase& rList )
1348*cdf0e10cSrcweir {
1349*cdf0e10cSrcweir     if( const FlagsList* pFlagsList = dynamic_cast< const FlagsList* >( &rList ) )
1350*cdf0e10cSrcweir         mnIgnore = pFlagsList->mnIgnore;
1351*cdf0e10cSrcweir }
1352*cdf0e10cSrcweir 
1353*cdf0e10cSrcweir // ============================================================================
1354*cdf0e10cSrcweir 
1355*cdf0e10cSrcweir bool CombiList::ExtItemFormatKey::operator<( const ExtItemFormatKey& rRight ) const
1356*cdf0e10cSrcweir {
1357*cdf0e10cSrcweir     return (mnKey < rRight.mnKey) || ((mnKey == rRight.mnKey) && (maFilter < rRight.maFilter));
1358*cdf0e10cSrcweir }
1359*cdf0e10cSrcweir 
1360*cdf0e10cSrcweir CombiList::CombiList( const SharedConfigData& rCfgData ) :
1361*cdf0e10cSrcweir     FlagsList( rCfgData )
1362*cdf0e10cSrcweir {
1363*cdf0e10cSrcweir }
1364*cdf0e10cSrcweir 
1365*cdf0e10cSrcweir void CombiList::implSetName( sal_Int64 nKey, const OUString& rName )
1366*cdf0e10cSrcweir {
1367*cdf0e10cSrcweir     if( (nKey & (nKey - 1)) != 0 )  // more than a single bit set?
1368*cdf0e10cSrcweir     {
1369*cdf0e10cSrcweir         typedef ::std::set< ExtItemFormatKey > ExtItemFormatKeySet;
1370*cdf0e10cSrcweir         ::std::set< ExtItemFormatKey > aItemKeys;
1371*cdf0e10cSrcweir         ExtItemFormat aItemFmt;
1372*cdf0e10cSrcweir         OUStringVector aRemain = aItemFmt.parse( rName );
1373*cdf0e10cSrcweir         for( OUStringVector::iterator aIt = aRemain.begin(), aEnd = aRemain.end(); aIt != aEnd; ++aIt )
1374*cdf0e10cSrcweir         {
1375*cdf0e10cSrcweir             OUStringPair aPair = StringHelper::convertStringToPair( *aIt );
1376*cdf0e10cSrcweir             if( aPair.first.equalsAscii( "noshift" ) )
1377*cdf0e10cSrcweir             {
1378*cdf0e10cSrcweir                 aItemFmt.mbShiftValue = StringHelper::convertStringToBool( aPair.second );
1379*cdf0e10cSrcweir             }
1380*cdf0e10cSrcweir             else if( aPair.first.equalsAscii( "filter" ) )
1381*cdf0e10cSrcweir             {
1382*cdf0e10cSrcweir                 OUStringPair aFilter = StringHelper::convertStringToPair( aPair.second, '~' );
1383*cdf0e10cSrcweir                 ExtItemFormatKey aKey( nKey );
1384*cdf0e10cSrcweir                 if( (aFilter.first.getLength() > 0) && StringHelper::convertStringToInt( aKey.maFilter.first, aFilter.first ) &&
1385*cdf0e10cSrcweir                     (aFilter.second.getLength() > 0) && StringHelper::convertStringToInt( aKey.maFilter.second, aFilter.second ) )
1386*cdf0e10cSrcweir                 {
1387*cdf0e10cSrcweir                     if( aKey.maFilter.first == 0 )
1388*cdf0e10cSrcweir                         aKey.maFilter.second = 0;
1389*cdf0e10cSrcweir                     aItemKeys.insert( aKey );
1390*cdf0e10cSrcweir                 }
1391*cdf0e10cSrcweir             }
1392*cdf0e10cSrcweir         }
1393*cdf0e10cSrcweir         if( aItemKeys.empty() )
1394*cdf0e10cSrcweir             aItemKeys.insert( ExtItemFormatKey( nKey ) );
1395*cdf0e10cSrcweir         for( ExtItemFormatKeySet::iterator aIt = aItemKeys.begin(), aEnd = aItemKeys.end(); aIt != aEnd; ++aIt )
1396*cdf0e10cSrcweir             maFmtMap[ *aIt ] = aItemFmt;
1397*cdf0e10cSrcweir     }
1398*cdf0e10cSrcweir     else
1399*cdf0e10cSrcweir     {
1400*cdf0e10cSrcweir         FlagsList::implSetName( nKey, rName );
1401*cdf0e10cSrcweir     }
1402*cdf0e10cSrcweir }
1403*cdf0e10cSrcweir 
1404*cdf0e10cSrcweir OUString CombiList::implGetName( const Config& rCfg, sal_Int64 nKey ) const
1405*cdf0e10cSrcweir {
1406*cdf0e10cSrcweir     sal_Int64 nFound = 0;
1407*cdf0e10cSrcweir     OUStringBuffer aName;
1408*cdf0e10cSrcweir     // add known flag fields
1409*cdf0e10cSrcweir     for( ExtItemFormatMap::const_iterator aIt = maFmtMap.begin(), aEnd = maFmtMap.end(); aIt != aEnd; ++aIt )
1410*cdf0e10cSrcweir     {
1411*cdf0e10cSrcweir         const ExtItemFormatKey& rMapKey = aIt->first;
1412*cdf0e10cSrcweir         sal_Int64 nMask = rMapKey.mnKey;
1413*cdf0e10cSrcweir         if( (nMask != 0) && ((nKey & rMapKey.maFilter.first) == rMapKey.maFilter.second) )
1414*cdf0e10cSrcweir         {
1415*cdf0e10cSrcweir             const ExtItemFormat& rItemFmt = aIt->second;
1416*cdf0e10cSrcweir 
1417*cdf0e10cSrcweir             sal_uInt64 nUFlags = static_cast< sal_uInt64 >( nKey );
1418*cdf0e10cSrcweir             sal_uInt64 nUMask = static_cast< sal_uInt64 >( nMask );
1419*cdf0e10cSrcweir             if( rItemFmt.mbShiftValue )
1420*cdf0e10cSrcweir                 while( (nUMask & 1) == 0 ) { nUFlags >>= 1; nUMask >>= 1; }
1421*cdf0e10cSrcweir 
1422*cdf0e10cSrcweir             sal_uInt64 nUValue = nUFlags & nUMask;
1423*cdf0e10cSrcweir             sal_Int64 nSValue = static_cast< sal_Int64 >( nUValue );
1424*cdf0e10cSrcweir             if( getFlag< sal_uInt64 >( nUValue, (nUMask + 1) >> 1 ) )
1425*cdf0e10cSrcweir                 setFlag( nSValue, static_cast< sal_Int64 >( ~nUMask ) );
1426*cdf0e10cSrcweir 
1427*cdf0e10cSrcweir             OUStringBuffer aItem( rItemFmt.maItemName );
1428*cdf0e10cSrcweir             OUStringBuffer aValue;
1429*cdf0e10cSrcweir             switch( rItemFmt.meDataType )
1430*cdf0e10cSrcweir             {
1431*cdf0e10cSrcweir                 case DATATYPE_INT8:     StringHelper::appendValue( aValue, static_cast< sal_Int8 >( nSValue ), rItemFmt.meFmtType );    break;
1432*cdf0e10cSrcweir                 case DATATYPE_UINT8:    StringHelper::appendValue( aValue, static_cast< sal_uInt8 >( nUValue ), rItemFmt.meFmtType );   break;
1433*cdf0e10cSrcweir                 case DATATYPE_INT16:    StringHelper::appendValue( aValue, static_cast< sal_Int16 >( nSValue ), rItemFmt.meFmtType );   break;
1434*cdf0e10cSrcweir                 case DATATYPE_UINT16:   StringHelper::appendValue( aValue, static_cast< sal_uInt16 >( nUValue ), rItemFmt.meFmtType );  break;
1435*cdf0e10cSrcweir                 case DATATYPE_INT32:    StringHelper::appendValue( aValue, static_cast< sal_Int32 >( nSValue ), rItemFmt.meFmtType );   break;
1436*cdf0e10cSrcweir                 case DATATYPE_UINT32:   StringHelper::appendValue( aValue, static_cast< sal_uInt32 >( nUValue ), rItemFmt.meFmtType );  break;
1437*cdf0e10cSrcweir                 case DATATYPE_INT64:    StringHelper::appendValue( aValue, nSValue, rItemFmt.meFmtType );                               break;
1438*cdf0e10cSrcweir                 case DATATYPE_UINT64:   StringHelper::appendValue( aValue, nUValue, rItemFmt.meFmtType );                               break;
1439*cdf0e10cSrcweir                 case DATATYPE_FLOAT:    StringHelper::appendValue( aValue, static_cast< float >( nSValue ), rItemFmt.meFmtType );       break;
1440*cdf0e10cSrcweir                 case DATATYPE_DOUBLE:   StringHelper::appendValue( aValue, static_cast< double >( nSValue ), rItemFmt.meFmtType );      break;
1441*cdf0e10cSrcweir                 default:;
1442*cdf0e10cSrcweir             }
1443*cdf0e10cSrcweir             StringHelper::appendToken( aItem, aValue.makeStringAndClear(), OOX_DUMP_ITEMSEP );
1444*cdf0e10cSrcweir             if( rItemFmt.maListName.getLength() > 0 )
1445*cdf0e10cSrcweir             {
1446*cdf0e10cSrcweir                 OUString aValueName = rCfg.getName( rItemFmt.maListName, static_cast< sal_Int64 >( nUValue ) );
1447*cdf0e10cSrcweir                 StringHelper::appendToken( aItem, aValueName, OOX_DUMP_ITEMSEP );
1448*cdf0e10cSrcweir             }
1449*cdf0e10cSrcweir             StringHelper::enclose( aItem, '(', ')' );
1450*cdf0e10cSrcweir             StringHelper::appendToken( aName, aItem.makeStringAndClear() );
1451*cdf0e10cSrcweir             setFlag( nFound, nMask );
1452*cdf0e10cSrcweir         }
1453*cdf0e10cSrcweir     }
1454*cdf0e10cSrcweir     setFlag( nKey, nFound, false );
1455*cdf0e10cSrcweir     StringHelper::appendToken( aName, FlagsList::implGetName( rCfg, nKey ) );
1456*cdf0e10cSrcweir     return aName.makeStringAndClear();
1457*cdf0e10cSrcweir }
1458*cdf0e10cSrcweir 
1459*cdf0e10cSrcweir void CombiList::implIncludeList( const NameListBase& rList )
1460*cdf0e10cSrcweir {
1461*cdf0e10cSrcweir     if( const CombiList* pCombiList = dynamic_cast< const CombiList* >( &rList ) )
1462*cdf0e10cSrcweir         maFmtMap = pCombiList->maFmtMap;
1463*cdf0e10cSrcweir     FlagsList::implIncludeList( rList );
1464*cdf0e10cSrcweir }
1465*cdf0e10cSrcweir 
1466*cdf0e10cSrcweir // ============================================================================
1467*cdf0e10cSrcweir 
1468*cdf0e10cSrcweir UnitConverter::UnitConverter( const SharedConfigData& rCfgData ) :
1469*cdf0e10cSrcweir     NameListBase( rCfgData ),
1470*cdf0e10cSrcweir     mfFactor( 1.0 )
1471*cdf0e10cSrcweir {
1472*cdf0e10cSrcweir }
1473*cdf0e10cSrcweir 
1474*cdf0e10cSrcweir void UnitConverter::implSetName( sal_Int64 /*nKey*/, const OUString& /*rName*/ )
1475*cdf0e10cSrcweir {
1476*cdf0e10cSrcweir     // nothing to do
1477*cdf0e10cSrcweir }
1478*cdf0e10cSrcweir 
1479*cdf0e10cSrcweir OUString UnitConverter::implGetName( const Config& rCfg, sal_Int64 nKey ) const
1480*cdf0e10cSrcweir {
1481*cdf0e10cSrcweir     return implGetNameDbl( rCfg, static_cast< double >( nKey ) );
1482*cdf0e10cSrcweir }
1483*cdf0e10cSrcweir 
1484*cdf0e10cSrcweir OUString UnitConverter::implGetNameDbl( const Config& /*rCfg*/, double fValue ) const
1485*cdf0e10cSrcweir {
1486*cdf0e10cSrcweir     OUStringBuffer aValue;
1487*cdf0e10cSrcweir     StringHelper::appendDec( aValue, mfFactor * fValue );
1488*cdf0e10cSrcweir     aValue.append( maUnitName );
1489*cdf0e10cSrcweir     return aValue.makeStringAndClear();
1490*cdf0e10cSrcweir }
1491*cdf0e10cSrcweir 
1492*cdf0e10cSrcweir void UnitConverter::implIncludeList( const NameListBase& /*rList*/ )
1493*cdf0e10cSrcweir {
1494*cdf0e10cSrcweir }
1495*cdf0e10cSrcweir 
1496*cdf0e10cSrcweir // ============================================================================
1497*cdf0e10cSrcweir 
1498*cdf0e10cSrcweir NameListRef NameListWrapper::getNameList( const Config& rCfg ) const
1499*cdf0e10cSrcweir {
1500*cdf0e10cSrcweir     return mxList.get() ? mxList : (mxList = rCfg.getNameList( maName ));
1501*cdf0e10cSrcweir }
1502*cdf0e10cSrcweir 
1503*cdf0e10cSrcweir // ============================================================================
1504*cdf0e10cSrcweir // ============================================================================
1505*cdf0e10cSrcweir 
1506*cdf0e10cSrcweir SharedConfigData::SharedConfigData( const OUString& rFileName,
1507*cdf0e10cSrcweir         const Reference< XComponentContext >& rxContext, const StorageRef& rxRootStrg,
1508*cdf0e10cSrcweir         const OUString& rSysFileName, MediaDescriptor& rMediaDesc ) :
1509*cdf0e10cSrcweir     mxContext( rxContext ),
1510*cdf0e10cSrcweir     mxRootStrg( rxRootStrg ),
1511*cdf0e10cSrcweir     maSysFileName( rSysFileName ),
1512*cdf0e10cSrcweir     mrMediaDesc( rMediaDesc ),
1513*cdf0e10cSrcweir     mbLoaded( false ),
1514*cdf0e10cSrcweir     mbPwCancelled( false )
1515*cdf0e10cSrcweir {
1516*cdf0e10cSrcweir     OUString aFileUrl = InputOutputHelper::convertFileNameToUrl( rFileName );
1517*cdf0e10cSrcweir     if( aFileUrl.getLength() > 0 )
1518*cdf0e10cSrcweir     {
1519*cdf0e10cSrcweir         sal_Int32 nNamePos = InputOutputHelper::getFileNamePos( aFileUrl );
1520*cdf0e10cSrcweir         maConfigPath = aFileUrl.copy( 0, nNamePos );
1521*cdf0e10cSrcweir         mbLoaded = readConfigFile( aFileUrl );
1522*cdf0e10cSrcweir     }
1523*cdf0e10cSrcweir }
1524*cdf0e10cSrcweir 
1525*cdf0e10cSrcweir SharedConfigData::~SharedConfigData()
1526*cdf0e10cSrcweir {
1527*cdf0e10cSrcweir }
1528*cdf0e10cSrcweir 
1529*cdf0e10cSrcweir void SharedConfigData::setOption( const OUString& rKey, const OUString& rData )
1530*cdf0e10cSrcweir {
1531*cdf0e10cSrcweir     maConfigData[ rKey ] = rData;
1532*cdf0e10cSrcweir }
1533*cdf0e10cSrcweir 
1534*cdf0e10cSrcweir const OUString* SharedConfigData::getOption( const OUString& rKey ) const
1535*cdf0e10cSrcweir {
1536*cdf0e10cSrcweir     ConfigDataMap::const_iterator aIt = maConfigData.find( rKey );
1537*cdf0e10cSrcweir     return (aIt == maConfigData.end()) ? 0 : &aIt->second;
1538*cdf0e10cSrcweir }
1539*cdf0e10cSrcweir 
1540*cdf0e10cSrcweir void SharedConfigData::setNameList( const OUString& rListName, const NameListRef& rxList )
1541*cdf0e10cSrcweir {
1542*cdf0e10cSrcweir     if( rListName.getLength() > 0 )
1543*cdf0e10cSrcweir         maNameLists[ rListName ] = rxList;
1544*cdf0e10cSrcweir }
1545*cdf0e10cSrcweir 
1546*cdf0e10cSrcweir void SharedConfigData::eraseNameList( const OUString& rListName )
1547*cdf0e10cSrcweir {
1548*cdf0e10cSrcweir     maNameLists.erase( rListName );
1549*cdf0e10cSrcweir }
1550*cdf0e10cSrcweir 
1551*cdf0e10cSrcweir NameListRef SharedConfigData::getNameList( const OUString& rListName ) const
1552*cdf0e10cSrcweir {
1553*cdf0e10cSrcweir     NameListRef xList;
1554*cdf0e10cSrcweir     NameListMap::const_iterator aIt = maNameLists.find( rListName );
1555*cdf0e10cSrcweir     if( aIt != maNameLists.end() )
1556*cdf0e10cSrcweir         xList = aIt->second;
1557*cdf0e10cSrcweir     return xList;
1558*cdf0e10cSrcweir }
1559*cdf0e10cSrcweir 
1560*cdf0e10cSrcweir Sequence< NamedValue > SharedConfigData::requestEncryptionData( ::comphelper::IDocPasswordVerifier& rVerifier )
1561*cdf0e10cSrcweir {
1562*cdf0e10cSrcweir     Sequence< NamedValue > aEncryptionData;
1563*cdf0e10cSrcweir     if( !mbPwCancelled )
1564*cdf0e10cSrcweir     {
1565*cdf0e10cSrcweir         ::std::vector< OUString > aDefaultPasswords;
1566*cdf0e10cSrcweir         aDefaultPasswords.push_back( CREATE_OUSTRING( "VelvetSweatshop" ) );
1567*cdf0e10cSrcweir         aEncryptionData = ::comphelper::DocPasswordHelper::requestAndVerifyDocPassword(
1568*cdf0e10cSrcweir             rVerifier, mrMediaDesc, ::comphelper::DocPasswordRequestType_MS, &aDefaultPasswords );
1569*cdf0e10cSrcweir         mbPwCancelled = !aEncryptionData.hasElements();
1570*cdf0e10cSrcweir     }
1571*cdf0e10cSrcweir     return aEncryptionData;
1572*cdf0e10cSrcweir }
1573*cdf0e10cSrcweir 
1574*cdf0e10cSrcweir bool SharedConfigData::implIsValid() const
1575*cdf0e10cSrcweir {
1576*cdf0e10cSrcweir     return mbLoaded && mxContext.is() && mxRootStrg.get() && (maSysFileName.getLength() > 0);
1577*cdf0e10cSrcweir }
1578*cdf0e10cSrcweir 
1579*cdf0e10cSrcweir void SharedConfigData::implProcessConfigItemStr(
1580*cdf0e10cSrcweir         TextInputStream& rStrm, const OUString& rKey, const OUString& rData )
1581*cdf0e10cSrcweir {
1582*cdf0e10cSrcweir     if( rKey.equalsAscii( "include-config-file" ) )
1583*cdf0e10cSrcweir         readConfigFile( maConfigPath + rData );
1584*cdf0e10cSrcweir     else if( rKey.equalsAscii( "constlist" ) )
1585*cdf0e10cSrcweir         readNameList< ConstList >( rStrm, rData );
1586*cdf0e10cSrcweir     else if( rKey.equalsAscii( "multilist" ) )
1587*cdf0e10cSrcweir         readNameList< MultiList >( rStrm, rData );
1588*cdf0e10cSrcweir     else if( rKey.equalsAscii( "flagslist" ) )
1589*cdf0e10cSrcweir         readNameList< FlagsList >( rStrm, rData );
1590*cdf0e10cSrcweir     else if( rKey.equalsAscii( "combilist" ) )
1591*cdf0e10cSrcweir         readNameList< CombiList >( rStrm, rData );
1592*cdf0e10cSrcweir     else if( rKey.equalsAscii( "shortlist" ) )
1593*cdf0e10cSrcweir         createShortList( rData );
1594*cdf0e10cSrcweir     else if( rKey.equalsAscii( "unitconverter" ) )
1595*cdf0e10cSrcweir         createUnitConverter( rData );
1596*cdf0e10cSrcweir     else
1597*cdf0e10cSrcweir         setOption( rKey, rData );
1598*cdf0e10cSrcweir }
1599*cdf0e10cSrcweir 
1600*cdf0e10cSrcweir bool SharedConfigData::readConfigFile( const OUString& rFileUrl )
1601*cdf0e10cSrcweir {
1602*cdf0e10cSrcweir     bool bLoaded = maConfigFiles.count( rFileUrl ) > 0;
1603*cdf0e10cSrcweir     if( !bLoaded )
1604*cdf0e10cSrcweir     {
1605*cdf0e10cSrcweir         Reference< XInputStream > xInStrm = InputOutputHelper::openInputStream( mxContext, rFileUrl );
1606*cdf0e10cSrcweir         TextInputStream aTxtStrm( mxContext, xInStrm, RTL_TEXTENCODING_UTF8 );
1607*cdf0e10cSrcweir         if( !aTxtStrm.isEof() )
1608*cdf0e10cSrcweir         {
1609*cdf0e10cSrcweir             maConfigFiles.insert( rFileUrl );
1610*cdf0e10cSrcweir             readConfigBlockContents( aTxtStrm );
1611*cdf0e10cSrcweir             bLoaded = true;
1612*cdf0e10cSrcweir         }
1613*cdf0e10cSrcweir     }
1614*cdf0e10cSrcweir     return bLoaded;
1615*cdf0e10cSrcweir }
1616*cdf0e10cSrcweir 
1617*cdf0e10cSrcweir void SharedConfigData::createShortList( const OUString& rData )
1618*cdf0e10cSrcweir {
1619*cdf0e10cSrcweir     OUStringVector aDataVec;
1620*cdf0e10cSrcweir     StringHelper::convertStringToStringList( aDataVec, rData, false );
1621*cdf0e10cSrcweir     if( aDataVec.size() >= 3 )
1622*cdf0e10cSrcweir     {
1623*cdf0e10cSrcweir         sal_Int64 nStartKey;
1624*cdf0e10cSrcweir         if( StringHelper::convertStringToInt( nStartKey, aDataVec[ 1 ] ) )
1625*cdf0e10cSrcweir         {
1626*cdf0e10cSrcweir             ::boost::shared_ptr< MultiList > xList = createNameList< MultiList >( aDataVec[ 0 ] );
1627*cdf0e10cSrcweir             if( xList.get() )
1628*cdf0e10cSrcweir             {
1629*cdf0e10cSrcweir                 aDataVec.erase( aDataVec.begin(), aDataVec.begin() + 2 );
1630*cdf0e10cSrcweir                 xList->setNamesFromVec( nStartKey, aDataVec );
1631*cdf0e10cSrcweir             }
1632*cdf0e10cSrcweir         }
1633*cdf0e10cSrcweir     }
1634*cdf0e10cSrcweir }
1635*cdf0e10cSrcweir 
1636*cdf0e10cSrcweir void SharedConfigData::createUnitConverter( const OUString& rData )
1637*cdf0e10cSrcweir {
1638*cdf0e10cSrcweir     OUStringVector aDataVec;
1639*cdf0e10cSrcweir     StringHelper::convertStringToStringList( aDataVec, rData, false );
1640*cdf0e10cSrcweir     if( aDataVec.size() >= 2 )
1641*cdf0e10cSrcweir     {
1642*cdf0e10cSrcweir         OUString aFactor = aDataVec[ 1 ];
1643*cdf0e10cSrcweir         bool bRecip = (aFactor.getLength() > 0) && (aFactor[ 0 ] == '/');
1644*cdf0e10cSrcweir         if( bRecip )
1645*cdf0e10cSrcweir             aFactor = aFactor.copy( 1 );
1646*cdf0e10cSrcweir         double fFactor;
1647*cdf0e10cSrcweir         if( StringHelper::convertStringToDouble( fFactor, aFactor ) && (fFactor != 0.0) )
1648*cdf0e10cSrcweir         {
1649*cdf0e10cSrcweir             ::boost::shared_ptr< UnitConverter > xList = createNameList< UnitConverter >( aDataVec[ 0 ] );
1650*cdf0e10cSrcweir             if( xList.get() )
1651*cdf0e10cSrcweir             {
1652*cdf0e10cSrcweir                 xList->setFactor( bRecip ? (1.0 / fFactor) : fFactor );
1653*cdf0e10cSrcweir                 if( aDataVec.size() >= 3 )
1654*cdf0e10cSrcweir                     xList->setUnitName( aDataVec[ 2 ] );
1655*cdf0e10cSrcweir             }
1656*cdf0e10cSrcweir         }
1657*cdf0e10cSrcweir     }
1658*cdf0e10cSrcweir }
1659*cdf0e10cSrcweir 
1660*cdf0e10cSrcweir // ============================================================================
1661*cdf0e10cSrcweir 
1662*cdf0e10cSrcweir Config::Config( const Config& rParent ) :
1663*cdf0e10cSrcweir     Base()  // c'tor needs to be called explicitly to avoid compiler warning
1664*cdf0e10cSrcweir {
1665*cdf0e10cSrcweir     construct( rParent );
1666*cdf0e10cSrcweir }
1667*cdf0e10cSrcweir 
1668*cdf0e10cSrcweir Config::Config( const sal_Char* pcEnvVar, const FilterBase& rFilter )
1669*cdf0e10cSrcweir {
1670*cdf0e10cSrcweir     construct( pcEnvVar, rFilter );
1671*cdf0e10cSrcweir }
1672*cdf0e10cSrcweir 
1673*cdf0e10cSrcweir Config::Config( const sal_Char* pcEnvVar, const Reference< XComponentContext >& rxContext, const StorageRef& rxRootStrg, const OUString& rSysFileName, MediaDescriptor& rMediaDesc )
1674*cdf0e10cSrcweir {
1675*cdf0e10cSrcweir     construct( pcEnvVar, rxContext, rxRootStrg, rSysFileName, rMediaDesc );
1676*cdf0e10cSrcweir }
1677*cdf0e10cSrcweir 
1678*cdf0e10cSrcweir Config::~Config()
1679*cdf0e10cSrcweir {
1680*cdf0e10cSrcweir }
1681*cdf0e10cSrcweir 
1682*cdf0e10cSrcweir void Config::construct( const Config& rParent )
1683*cdf0e10cSrcweir {
1684*cdf0e10cSrcweir     *this = rParent;
1685*cdf0e10cSrcweir }
1686*cdf0e10cSrcweir 
1687*cdf0e10cSrcweir void Config::construct( const sal_Char* pcEnvVar, const FilterBase& rFilter )
1688*cdf0e10cSrcweir {
1689*cdf0e10cSrcweir     if( rFilter.getFileUrl().getLength() > 0 )
1690*cdf0e10cSrcweir         construct( pcEnvVar, rFilter.getComponentContext(), rFilter.getStorage(), rFilter.getFileUrl(), rFilter.getMediaDescriptor() );
1691*cdf0e10cSrcweir }
1692*cdf0e10cSrcweir 
1693*cdf0e10cSrcweir void Config::construct( const sal_Char* pcEnvVar, const Reference< XComponentContext >& rxContext, const StorageRef& rxRootStrg, const OUString& rSysFileName, MediaDescriptor& rMediaDesc )
1694*cdf0e10cSrcweir {
1695*cdf0e10cSrcweir     if( pcEnvVar && rxRootStrg.get() && (rSysFileName.getLength() > 0) )
1696*cdf0e10cSrcweir         if( const sal_Char* pcFileName = ::getenv( pcEnvVar ) )
1697*cdf0e10cSrcweir             mxCfgData.reset( new SharedConfigData( OUString::createFromAscii( pcFileName ), rxContext, rxRootStrg, rSysFileName, rMediaDesc ) );
1698*cdf0e10cSrcweir }
1699*cdf0e10cSrcweir 
1700*cdf0e10cSrcweir void Config::setStringOption( const String& rKey, const String& rData )
1701*cdf0e10cSrcweir {
1702*cdf0e10cSrcweir     mxCfgData->setOption( rKey, rData );
1703*cdf0e10cSrcweir }
1704*cdf0e10cSrcweir 
1705*cdf0e10cSrcweir const OUString& Config::getStringOption( const String& rKey, const OUString& rDefault ) const
1706*cdf0e10cSrcweir {
1707*cdf0e10cSrcweir     const OUString* pData = implGetOption( rKey );
1708*cdf0e10cSrcweir     return pData ? *pData : rDefault;
1709*cdf0e10cSrcweir }
1710*cdf0e10cSrcweir 
1711*cdf0e10cSrcweir bool Config::getBoolOption( const String& rKey, bool bDefault ) const
1712*cdf0e10cSrcweir {
1713*cdf0e10cSrcweir     const OUString* pData = implGetOption( rKey );
1714*cdf0e10cSrcweir     return pData ? StringHelper::convertStringToBool( *pData ) : bDefault;
1715*cdf0e10cSrcweir }
1716*cdf0e10cSrcweir 
1717*cdf0e10cSrcweir bool Config::isDumperEnabled() const
1718*cdf0e10cSrcweir {
1719*cdf0e10cSrcweir     return getBoolOption( "enable-dumper", false );
1720*cdf0e10cSrcweir }
1721*cdf0e10cSrcweir 
1722*cdf0e10cSrcweir bool Config::isImportEnabled() const
1723*cdf0e10cSrcweir {
1724*cdf0e10cSrcweir     return getBoolOption( "enable-import", true );
1725*cdf0e10cSrcweir }
1726*cdf0e10cSrcweir 
1727*cdf0e10cSrcweir void Config::setNameList( const String& rListName, const NameListRef& rxList )
1728*cdf0e10cSrcweir {
1729*cdf0e10cSrcweir     mxCfgData->setNameList( rListName, rxList );
1730*cdf0e10cSrcweir }
1731*cdf0e10cSrcweir 
1732*cdf0e10cSrcweir void Config::eraseNameList( const String& rListName )
1733*cdf0e10cSrcweir {
1734*cdf0e10cSrcweir     mxCfgData->eraseNameList( rListName );
1735*cdf0e10cSrcweir }
1736*cdf0e10cSrcweir 
1737*cdf0e10cSrcweir NameListRef Config::getNameList( const String& rListName ) const
1738*cdf0e10cSrcweir {
1739*cdf0e10cSrcweir     return implGetNameList( rListName );
1740*cdf0e10cSrcweir }
1741*cdf0e10cSrcweir 
1742*cdf0e10cSrcweir Sequence< NamedValue > Config::requestEncryptionData( ::comphelper::IDocPasswordVerifier& rVerifier )
1743*cdf0e10cSrcweir {
1744*cdf0e10cSrcweir     return mxCfgData->requestEncryptionData( rVerifier );
1745*cdf0e10cSrcweir }
1746*cdf0e10cSrcweir 
1747*cdf0e10cSrcweir bool Config::isPasswordCancelled() const
1748*cdf0e10cSrcweir {
1749*cdf0e10cSrcweir     return mxCfgData->isPasswordCancelled();
1750*cdf0e10cSrcweir }
1751*cdf0e10cSrcweir 
1752*cdf0e10cSrcweir bool Config::implIsValid() const
1753*cdf0e10cSrcweir {
1754*cdf0e10cSrcweir     return isValid( mxCfgData );
1755*cdf0e10cSrcweir }
1756*cdf0e10cSrcweir 
1757*cdf0e10cSrcweir const OUString* Config::implGetOption( const OUString& rKey ) const
1758*cdf0e10cSrcweir {
1759*cdf0e10cSrcweir     return mxCfgData->getOption( rKey );
1760*cdf0e10cSrcweir }
1761*cdf0e10cSrcweir 
1762*cdf0e10cSrcweir NameListRef Config::implGetNameList( const OUString& rListName ) const
1763*cdf0e10cSrcweir {
1764*cdf0e10cSrcweir     return mxCfgData->getNameList( rListName );
1765*cdf0e10cSrcweir }
1766*cdf0e10cSrcweir 
1767*cdf0e10cSrcweir // ============================================================================
1768*cdf0e10cSrcweir // ============================================================================
1769*cdf0e10cSrcweir 
1770*cdf0e10cSrcweir Output::Output( const Reference< XComponentContext >& rxContext, const OUString& rFileName ) :
1771*cdf0e10cSrcweir     mxStrm( InputOutputHelper::openTextOutputStream( rxContext, rFileName, RTL_TEXTENCODING_UTF8 ) ),
1772*cdf0e10cSrcweir     mnCol( 0 ),
1773*cdf0e10cSrcweir     mnItemLevel( 0 ),
1774*cdf0e10cSrcweir     mnMultiLevel( 0 ),
1775*cdf0e10cSrcweir     mnItemIdx( 0 ),
1776*cdf0e10cSrcweir     mnLastItem( 0 )
1777*cdf0e10cSrcweir {
1778*cdf0e10cSrcweir     if( mxStrm.is() )
1779*cdf0e10cSrcweir         mxStrm->writeString( OUString( OOX_DUMP_BOM ) );
1780*cdf0e10cSrcweir }
1781*cdf0e10cSrcweir 
1782*cdf0e10cSrcweir // ----------------------------------------------------------------------------
1783*cdf0e10cSrcweir 
1784*cdf0e10cSrcweir void Output::newLine()
1785*cdf0e10cSrcweir {
1786*cdf0e10cSrcweir     if( maLine.getLength() > 0 )
1787*cdf0e10cSrcweir     {
1788*cdf0e10cSrcweir         mxStrm->writeString( maIndent );
1789*cdf0e10cSrcweir         maLine.append( sal_Unicode( '\n' ) );
1790*cdf0e10cSrcweir         mxStrm->writeString( maLine.makeStringAndClear() );
1791*cdf0e10cSrcweir         mnCol = 0;
1792*cdf0e10cSrcweir         mnLastItem = 0;
1793*cdf0e10cSrcweir     }
1794*cdf0e10cSrcweir }
1795*cdf0e10cSrcweir 
1796*cdf0e10cSrcweir void Output::emptyLine( size_t nCount )
1797*cdf0e10cSrcweir {
1798*cdf0e10cSrcweir     for( size_t nIdx = 0; nIdx < nCount; ++nIdx )
1799*cdf0e10cSrcweir         mxStrm->writeString( OUString( sal_Unicode( '\n' ) ) );
1800*cdf0e10cSrcweir }
1801*cdf0e10cSrcweir 
1802*cdf0e10cSrcweir void Output::incIndent()
1803*cdf0e10cSrcweir {
1804*cdf0e10cSrcweir     OUStringBuffer aBuffer( maIndent );
1805*cdf0e10cSrcweir     StringHelper::appendChar( aBuffer, ' ', OOX_DUMP_INDENT );
1806*cdf0e10cSrcweir     maIndent = aBuffer.makeStringAndClear();
1807*cdf0e10cSrcweir }
1808*cdf0e10cSrcweir 
1809*cdf0e10cSrcweir void Output::decIndent()
1810*cdf0e10cSrcweir {
1811*cdf0e10cSrcweir     if( maIndent.getLength() >= OOX_DUMP_INDENT )
1812*cdf0e10cSrcweir         maIndent = maIndent.copy( OOX_DUMP_INDENT );
1813*cdf0e10cSrcweir }
1814*cdf0e10cSrcweir 
1815*cdf0e10cSrcweir void Output::resetIndent()
1816*cdf0e10cSrcweir {
1817*cdf0e10cSrcweir     maIndent = OUString();
1818*cdf0e10cSrcweir }
1819*cdf0e10cSrcweir 
1820*cdf0e10cSrcweir void Output::startTable( sal_Int32 nW1 )
1821*cdf0e10cSrcweir {
1822*cdf0e10cSrcweir     startTable( 1, &nW1 );
1823*cdf0e10cSrcweir }
1824*cdf0e10cSrcweir 
1825*cdf0e10cSrcweir void Output::startTable( sal_Int32 nW1, sal_Int32 nW2 )
1826*cdf0e10cSrcweir {
1827*cdf0e10cSrcweir     sal_Int32 pnColWidths[ 2 ];
1828*cdf0e10cSrcweir     pnColWidths[ 0 ] = nW1;
1829*cdf0e10cSrcweir     pnColWidths[ 1 ] = nW2;
1830*cdf0e10cSrcweir     startTable( 2, pnColWidths );
1831*cdf0e10cSrcweir }
1832*cdf0e10cSrcweir 
1833*cdf0e10cSrcweir void Output::startTable( sal_Int32 nW1, sal_Int32 nW2, sal_Int32 nW3 )
1834*cdf0e10cSrcweir {
1835*cdf0e10cSrcweir     sal_Int32 pnColWidths[ 3 ];
1836*cdf0e10cSrcweir     pnColWidths[ 0 ] = nW1;
1837*cdf0e10cSrcweir     pnColWidths[ 1 ] = nW2;
1838*cdf0e10cSrcweir     pnColWidths[ 2 ] = nW3;
1839*cdf0e10cSrcweir     startTable( 3, pnColWidths );
1840*cdf0e10cSrcweir }
1841*cdf0e10cSrcweir 
1842*cdf0e10cSrcweir void Output::startTable( sal_Int32 nW1, sal_Int32 nW2, sal_Int32 nW3, sal_Int32 nW4 )
1843*cdf0e10cSrcweir {
1844*cdf0e10cSrcweir     sal_Int32 pnColWidths[ 4 ];
1845*cdf0e10cSrcweir     pnColWidths[ 0 ] = nW1;
1846*cdf0e10cSrcweir     pnColWidths[ 1 ] = nW2;
1847*cdf0e10cSrcweir     pnColWidths[ 2 ] = nW3;
1848*cdf0e10cSrcweir     pnColWidths[ 3 ] = nW4;
1849*cdf0e10cSrcweir     startTable( 4, pnColWidths );
1850*cdf0e10cSrcweir }
1851*cdf0e10cSrcweir 
1852*cdf0e10cSrcweir void Output::startTable( size_t nColCount, const sal_Int32* pnColWidths )
1853*cdf0e10cSrcweir {
1854*cdf0e10cSrcweir     maColPos.clear();
1855*cdf0e10cSrcweir     maColPos.push_back( 0 );
1856*cdf0e10cSrcweir     sal_Int32 nColPos = 0;
1857*cdf0e10cSrcweir     for( size_t nCol = 0; nCol < nColCount; ++nCol )
1858*cdf0e10cSrcweir     {
1859*cdf0e10cSrcweir         nColPos = nColPos + pnColWidths[ nCol ];
1860*cdf0e10cSrcweir         maColPos.push_back( nColPos );
1861*cdf0e10cSrcweir     }
1862*cdf0e10cSrcweir }
1863*cdf0e10cSrcweir 
1864*cdf0e10cSrcweir void Output::tab()
1865*cdf0e10cSrcweir {
1866*cdf0e10cSrcweir     tab( mnCol + 1 );
1867*cdf0e10cSrcweir }
1868*cdf0e10cSrcweir 
1869*cdf0e10cSrcweir void Output::tab( size_t nCol )
1870*cdf0e10cSrcweir {
1871*cdf0e10cSrcweir     mnCol = nCol;
1872*cdf0e10cSrcweir     if( mnCol < maColPos.size() )
1873*cdf0e10cSrcweir     {
1874*cdf0e10cSrcweir         sal_Int32 nColPos = maColPos[ mnCol ];
1875*cdf0e10cSrcweir         if( maLine.getLength() >= nColPos )
1876*cdf0e10cSrcweir             maLine.setLength( ::std::max< sal_Int32 >( nColPos - 1, 0 ) );
1877*cdf0e10cSrcweir         StringHelper::appendChar( maLine, ' ', nColPos - maLine.getLength() );
1878*cdf0e10cSrcweir     }
1879*cdf0e10cSrcweir     else
1880*cdf0e10cSrcweir     {
1881*cdf0e10cSrcweir         StringHelper::appendChar( maLine, ' ', 2 );
1882*cdf0e10cSrcweir     }
1883*cdf0e10cSrcweir }
1884*cdf0e10cSrcweir 
1885*cdf0e10cSrcweir void Output::endTable()
1886*cdf0e10cSrcweir {
1887*cdf0e10cSrcweir     maColPos.clear();
1888*cdf0e10cSrcweir }
1889*cdf0e10cSrcweir 
1890*cdf0e10cSrcweir void Output::resetItemIndex( sal_Int64 nIdx )
1891*cdf0e10cSrcweir {
1892*cdf0e10cSrcweir     mnItemIdx = nIdx;
1893*cdf0e10cSrcweir }
1894*cdf0e10cSrcweir 
1895*cdf0e10cSrcweir void Output::startItem( const String& rItemName )
1896*cdf0e10cSrcweir {
1897*cdf0e10cSrcweir     if( mnItemLevel == 0 )
1898*cdf0e10cSrcweir     {
1899*cdf0e10cSrcweir         if( (mnMultiLevel > 0) && (maLine.getLength() > 0) )
1900*cdf0e10cSrcweir             tab();
1901*cdf0e10cSrcweir         if( rItemName.has() )
1902*cdf0e10cSrcweir         {
1903*cdf0e10cSrcweir             writeItemName( rItemName );
1904*cdf0e10cSrcweir             writeChar( OOX_DUMP_ITEMSEP );
1905*cdf0e10cSrcweir         }
1906*cdf0e10cSrcweir     }
1907*cdf0e10cSrcweir     ++mnItemLevel;
1908*cdf0e10cSrcweir     mnLastItem = maLine.getLength();
1909*cdf0e10cSrcweir }
1910*cdf0e10cSrcweir 
1911*cdf0e10cSrcweir void Output::contItem()
1912*cdf0e10cSrcweir {
1913*cdf0e10cSrcweir     if( mnItemLevel > 0 )
1914*cdf0e10cSrcweir     {
1915*cdf0e10cSrcweir         if( (maLine.getLength() == 0) || (maLine[ maLine.getLength() - 1 ] != OOX_DUMP_ITEMSEP) )
1916*cdf0e10cSrcweir             writeChar( OOX_DUMP_ITEMSEP );
1917*cdf0e10cSrcweir         mnLastItem = maLine.getLength();
1918*cdf0e10cSrcweir     }
1919*cdf0e10cSrcweir }
1920*cdf0e10cSrcweir 
1921*cdf0e10cSrcweir void Output::endItem()
1922*cdf0e10cSrcweir {
1923*cdf0e10cSrcweir     if( mnItemLevel > 0 )
1924*cdf0e10cSrcweir     {
1925*cdf0e10cSrcweir         maLastItem = OUString( maLine.getStr() + mnLastItem );
1926*cdf0e10cSrcweir         if( (maLastItem.getLength() == 0) && (mnLastItem > 0) && (maLine[ mnLastItem - 1 ] == OOX_DUMP_ITEMSEP) )
1927*cdf0e10cSrcweir             maLine.setLength( mnLastItem - 1 );
1928*cdf0e10cSrcweir         --mnItemLevel;
1929*cdf0e10cSrcweir     }
1930*cdf0e10cSrcweir     if( mnItemLevel == 0 )
1931*cdf0e10cSrcweir     {
1932*cdf0e10cSrcweir         if( mnMultiLevel == 0 )
1933*cdf0e10cSrcweir             newLine();
1934*cdf0e10cSrcweir     }
1935*cdf0e10cSrcweir     else
1936*cdf0e10cSrcweir         contItem();
1937*cdf0e10cSrcweir }
1938*cdf0e10cSrcweir 
1939*cdf0e10cSrcweir void Output::startMultiItems()
1940*cdf0e10cSrcweir {
1941*cdf0e10cSrcweir     ++mnMultiLevel;
1942*cdf0e10cSrcweir }
1943*cdf0e10cSrcweir 
1944*cdf0e10cSrcweir void Output::endMultiItems()
1945*cdf0e10cSrcweir {
1946*cdf0e10cSrcweir     if( mnMultiLevel > 0 )
1947*cdf0e10cSrcweir         --mnMultiLevel;
1948*cdf0e10cSrcweir     if( mnMultiLevel == 0 )
1949*cdf0e10cSrcweir         newLine();
1950*cdf0e10cSrcweir }
1951*cdf0e10cSrcweir 
1952*cdf0e10cSrcweir // ----------------------------------------------------------------------------
1953*cdf0e10cSrcweir 
1954*cdf0e10cSrcweir void Output::writeChar( sal_Unicode cChar, sal_Int32 nCount )
1955*cdf0e10cSrcweir {
1956*cdf0e10cSrcweir     StringHelper::appendEncChar( maLine, cChar, nCount );
1957*cdf0e10cSrcweir }
1958*cdf0e10cSrcweir 
1959*cdf0e10cSrcweir void Output::writeAscii( const sal_Char* pcStr )
1960*cdf0e10cSrcweir {
1961*cdf0e10cSrcweir     if( pcStr )
1962*cdf0e10cSrcweir         maLine.appendAscii( pcStr );
1963*cdf0e10cSrcweir }
1964*cdf0e10cSrcweir 
1965*cdf0e10cSrcweir void Output::writeString( const OUString& rStr )
1966*cdf0e10cSrcweir {
1967*cdf0e10cSrcweir     StringHelper::appendEncString( maLine, rStr );
1968*cdf0e10cSrcweir }
1969*cdf0e10cSrcweir 
1970*cdf0e10cSrcweir void Output::writeArray( const sal_uInt8* pnData, sal_Size nSize, sal_Unicode cSep )
1971*cdf0e10cSrcweir {
1972*cdf0e10cSrcweir     const sal_uInt8* pnEnd = pnData ? (pnData + nSize) : 0;
1973*cdf0e10cSrcweir     for( const sal_uInt8* pnByte = pnData; pnByte < pnEnd; ++pnByte )
1974*cdf0e10cSrcweir     {
1975*cdf0e10cSrcweir         if( pnByte > pnData )
1976*cdf0e10cSrcweir             writeChar( cSep );
1977*cdf0e10cSrcweir         writeHex( *pnByte, false );
1978*cdf0e10cSrcweir     }
1979*cdf0e10cSrcweir }
1980*cdf0e10cSrcweir 
1981*cdf0e10cSrcweir void Output::writeBool( bool bData )
1982*cdf0e10cSrcweir {
1983*cdf0e10cSrcweir     StringHelper::appendBool( maLine, bData );
1984*cdf0e10cSrcweir }
1985*cdf0e10cSrcweir 
1986*cdf0e10cSrcweir void Output::writeColorABGR( sal_Int32 nColor )
1987*cdf0e10cSrcweir {
1988*cdf0e10cSrcweir     writeChar( 'a' );
1989*cdf0e10cSrcweir     writeDec( static_cast< sal_uInt8 >( nColor >> 24 ) );
1990*cdf0e10cSrcweir     writeAscii( ",r" );
1991*cdf0e10cSrcweir     writeDec( static_cast< sal_uInt8 >( nColor ) );
1992*cdf0e10cSrcweir     writeAscii( ",g" );
1993*cdf0e10cSrcweir     writeDec( static_cast< sal_uInt8 >( nColor >> 8 ) );
1994*cdf0e10cSrcweir     writeAscii( ",b" );
1995*cdf0e10cSrcweir     writeDec( static_cast< sal_uInt8 >( nColor >> 16 ) );
1996*cdf0e10cSrcweir }
1997*cdf0e10cSrcweir 
1998*cdf0e10cSrcweir void Output::writeDateTime( const DateTime& rDateTime )
1999*cdf0e10cSrcweir {
2000*cdf0e10cSrcweir     writeDec( rDateTime.Year, 4, '0' );
2001*cdf0e10cSrcweir     writeChar( '-' );
2002*cdf0e10cSrcweir     writeDec( rDateTime.Month, 2, '0' );
2003*cdf0e10cSrcweir     writeChar( '-' );
2004*cdf0e10cSrcweir     writeDec( rDateTime.Day, 2, '0' );
2005*cdf0e10cSrcweir     writeChar( 'T' );
2006*cdf0e10cSrcweir     writeDec( rDateTime.Hours, 2, '0' );
2007*cdf0e10cSrcweir     writeChar( ':' );
2008*cdf0e10cSrcweir     writeDec( rDateTime.Minutes, 2, '0' );
2009*cdf0e10cSrcweir     writeChar( ':' );
2010*cdf0e10cSrcweir     writeDec( rDateTime.Seconds, 2, '0' );
2011*cdf0e10cSrcweir }
2012*cdf0e10cSrcweir 
2013*cdf0e10cSrcweir void Output::writeColIndex( sal_Int32 nCol )
2014*cdf0e10cSrcweir {
2015*cdf0e10cSrcweir     StringHelper::appendAddrCol( maLine, nCol, true );
2016*cdf0e10cSrcweir }
2017*cdf0e10cSrcweir 
2018*cdf0e10cSrcweir void Output::writeRowIndex( sal_Int32 nRow )
2019*cdf0e10cSrcweir {
2020*cdf0e10cSrcweir     StringHelper::appendAddrRow( maLine, nRow, true );
2021*cdf0e10cSrcweir }
2022*cdf0e10cSrcweir 
2023*cdf0e10cSrcweir void Output::writeColRowRange( sal_Int32 nColRow1, sal_Int32 nColRow2 )
2024*cdf0e10cSrcweir {
2025*cdf0e10cSrcweir     writeDec( nColRow1 );
2026*cdf0e10cSrcweir     writeChar( OOX_DUMP_RANGESEP );
2027*cdf0e10cSrcweir     writeDec( nColRow2 );
2028*cdf0e10cSrcweir }
2029*cdf0e10cSrcweir 
2030*cdf0e10cSrcweir void Output::writeColRange( sal_Int32 nCol1, sal_Int32 nCol2 )
2031*cdf0e10cSrcweir {
2032*cdf0e10cSrcweir     writeColIndex( nCol1 );
2033*cdf0e10cSrcweir     writeChar( OOX_DUMP_RANGESEP );
2034*cdf0e10cSrcweir     writeColIndex( nCol2 );
2035*cdf0e10cSrcweir }
2036*cdf0e10cSrcweir 
2037*cdf0e10cSrcweir void Output::writeRowRange( sal_Int32 nRow1, sal_Int32 nRow2 )
2038*cdf0e10cSrcweir {
2039*cdf0e10cSrcweir     writeRowIndex( nRow1 );
2040*cdf0e10cSrcweir     writeChar( OOX_DUMP_RANGESEP );
2041*cdf0e10cSrcweir     writeRowIndex( nRow2 );
2042*cdf0e10cSrcweir }
2043*cdf0e10cSrcweir 
2044*cdf0e10cSrcweir void Output::writeAddress( const Address& rPos )
2045*cdf0e10cSrcweir {
2046*cdf0e10cSrcweir     StringHelper::appendAddress( maLine, rPos );
2047*cdf0e10cSrcweir }
2048*cdf0e10cSrcweir 
2049*cdf0e10cSrcweir void Output::writeRange( const Range& rRange )
2050*cdf0e10cSrcweir {
2051*cdf0e10cSrcweir     StringHelper::appendRange( maLine, rRange );
2052*cdf0e10cSrcweir }
2053*cdf0e10cSrcweir 
2054*cdf0e10cSrcweir void Output::writeRangeList( const RangeList& rRanges )
2055*cdf0e10cSrcweir {
2056*cdf0e10cSrcweir     StringHelper::appendRangeList( maLine, rRanges );
2057*cdf0e10cSrcweir }
2058*cdf0e10cSrcweir 
2059*cdf0e10cSrcweir // ----------------------------------------------------------------------------
2060*cdf0e10cSrcweir 
2061*cdf0e10cSrcweir bool Output::implIsValid() const
2062*cdf0e10cSrcweir {
2063*cdf0e10cSrcweir     return mxStrm.is();
2064*cdf0e10cSrcweir }
2065*cdf0e10cSrcweir 
2066*cdf0e10cSrcweir void Output::writeItemName( const String& rItemName )
2067*cdf0e10cSrcweir {
2068*cdf0e10cSrcweir     if( rItemName.has() && (rItemName[ 0 ] == '#') )
2069*cdf0e10cSrcweir     {
2070*cdf0e10cSrcweir         writeString( rItemName.copy( 1 ) );
2071*cdf0e10cSrcweir         StringHelper::appendIndex( maLine, mnItemIdx++ );
2072*cdf0e10cSrcweir     }
2073*cdf0e10cSrcweir     else
2074*cdf0e10cSrcweir         writeString( rItemName );
2075*cdf0e10cSrcweir }
2076*cdf0e10cSrcweir 
2077*cdf0e10cSrcweir // ============================================================================
2078*cdf0e10cSrcweir 
2079*cdf0e10cSrcweir StorageIterator::StorageIterator( const StorageRef& rxStrg ) :
2080*cdf0e10cSrcweir     mxStrg( rxStrg )
2081*cdf0e10cSrcweir {
2082*cdf0e10cSrcweir     if( mxStrg.get() )
2083*cdf0e10cSrcweir         mxStrg->getElementNames( maNames );
2084*cdf0e10cSrcweir     maIt = maNames.begin();
2085*cdf0e10cSrcweir }
2086*cdf0e10cSrcweir 
2087*cdf0e10cSrcweir StorageIterator::~StorageIterator()
2088*cdf0e10cSrcweir {
2089*cdf0e10cSrcweir }
2090*cdf0e10cSrcweir 
2091*cdf0e10cSrcweir size_t StorageIterator::getElementCount() const
2092*cdf0e10cSrcweir {
2093*cdf0e10cSrcweir     return maNames.size();
2094*cdf0e10cSrcweir }
2095*cdf0e10cSrcweir 
2096*cdf0e10cSrcweir StorageIterator& StorageIterator::operator++()
2097*cdf0e10cSrcweir {
2098*cdf0e10cSrcweir     if( maIt != maNames.end() )
2099*cdf0e10cSrcweir         ++maIt;
2100*cdf0e10cSrcweir     return *this;
2101*cdf0e10cSrcweir }
2102*cdf0e10cSrcweir 
2103*cdf0e10cSrcweir OUString StorageIterator::getName() const
2104*cdf0e10cSrcweir {
2105*cdf0e10cSrcweir     OUString aName;
2106*cdf0e10cSrcweir     if( maIt != maNames.end() )
2107*cdf0e10cSrcweir         aName = *maIt;
2108*cdf0e10cSrcweir     return aName;
2109*cdf0e10cSrcweir }
2110*cdf0e10cSrcweir 
2111*cdf0e10cSrcweir bool StorageIterator::isStream() const
2112*cdf0e10cSrcweir {
2113*cdf0e10cSrcweir     return isValid() && mxStrg->openInputStream( *maIt ).is();
2114*cdf0e10cSrcweir }
2115*cdf0e10cSrcweir 
2116*cdf0e10cSrcweir bool StorageIterator::isStorage() const
2117*cdf0e10cSrcweir {
2118*cdf0e10cSrcweir     if( !isValid() )
2119*cdf0e10cSrcweir         return false;
2120*cdf0e10cSrcweir     StorageRef xStrg = mxStrg->openSubStorage( *maIt, false );
2121*cdf0e10cSrcweir     return xStrg.get() && xStrg->isStorage();
2122*cdf0e10cSrcweir }
2123*cdf0e10cSrcweir 
2124*cdf0e10cSrcweir bool StorageIterator::implIsValid() const
2125*cdf0e10cSrcweir {
2126*cdf0e10cSrcweir     return mxStrg.get() && mxStrg->isStorage() && (maIt != maNames.end());
2127*cdf0e10cSrcweir }
2128*cdf0e10cSrcweir 
2129*cdf0e10cSrcweir // ============================================================================
2130*cdf0e10cSrcweir // ============================================================================
2131*cdf0e10cSrcweir 
2132*cdf0e10cSrcweir ObjectBase::~ObjectBase()
2133*cdf0e10cSrcweir {
2134*cdf0e10cSrcweir }
2135*cdf0e10cSrcweir 
2136*cdf0e10cSrcweir void ObjectBase::construct( const ConfigRef& rxConfig )
2137*cdf0e10cSrcweir {
2138*cdf0e10cSrcweir     mxConfig = rxConfig;
2139*cdf0e10cSrcweir }
2140*cdf0e10cSrcweir 
2141*cdf0e10cSrcweir void ObjectBase::construct( const ObjectBase& rParent )
2142*cdf0e10cSrcweir {
2143*cdf0e10cSrcweir     *this = rParent;
2144*cdf0e10cSrcweir }
2145*cdf0e10cSrcweir 
2146*cdf0e10cSrcweir void ObjectBase::dump()
2147*cdf0e10cSrcweir {
2148*cdf0e10cSrcweir     if( isValid() )
2149*cdf0e10cSrcweir         implDump();
2150*cdf0e10cSrcweir }
2151*cdf0e10cSrcweir 
2152*cdf0e10cSrcweir bool ObjectBase::implIsValid() const
2153*cdf0e10cSrcweir {
2154*cdf0e10cSrcweir     return isValid( mxConfig );
2155*cdf0e10cSrcweir }
2156*cdf0e10cSrcweir 
2157*cdf0e10cSrcweir void ObjectBase::implDump()
2158*cdf0e10cSrcweir {
2159*cdf0e10cSrcweir }
2160*cdf0e10cSrcweir 
2161*cdf0e10cSrcweir void ObjectBase::reconstructConfig( const ConfigRef& rxConfig )
2162*cdf0e10cSrcweir {
2163*cdf0e10cSrcweir     if( isValid( rxConfig ) )
2164*cdf0e10cSrcweir         mxConfig = rxConfig;
2165*cdf0e10cSrcweir }
2166*cdf0e10cSrcweir 
2167*cdf0e10cSrcweir // ============================================================================
2168*cdf0e10cSrcweir // ============================================================================
2169*cdf0e10cSrcweir 
2170*cdf0e10cSrcweir void StorageObjectBase::construct( const ObjectBase& rParent, const StorageRef& rxStrg, const OUString& rSysPath )
2171*cdf0e10cSrcweir {
2172*cdf0e10cSrcweir     ObjectBase::construct( rParent );
2173*cdf0e10cSrcweir     mxStrg = rxStrg;
2174*cdf0e10cSrcweir     maSysPath = rSysPath;
2175*cdf0e10cSrcweir }
2176*cdf0e10cSrcweir 
2177*cdf0e10cSrcweir void StorageObjectBase::construct( const ObjectBase& rParent )
2178*cdf0e10cSrcweir {
2179*cdf0e10cSrcweir     ObjectBase::construct( rParent );
2180*cdf0e10cSrcweir     if( ObjectBase::implIsValid() )
2181*cdf0e10cSrcweir     {
2182*cdf0e10cSrcweir         mxStrg = cfg().getRootStorage();
2183*cdf0e10cSrcweir         maSysPath = cfg().getSysFileName();
2184*cdf0e10cSrcweir     }
2185*cdf0e10cSrcweir }
2186*cdf0e10cSrcweir 
2187*cdf0e10cSrcweir bool StorageObjectBase::implIsValid() const
2188*cdf0e10cSrcweir {
2189*cdf0e10cSrcweir     return mxStrg.get() && (maSysPath.getLength() > 0) && ObjectBase::implIsValid();
2190*cdf0e10cSrcweir }
2191*cdf0e10cSrcweir 
2192*cdf0e10cSrcweir void StorageObjectBase::implDump()
2193*cdf0e10cSrcweir {
2194*cdf0e10cSrcweir     bool bIsStrg = mxStrg->isStorage();
2195*cdf0e10cSrcweir     bool bIsRoot = mxStrg->isRootStorage();
2196*cdf0e10cSrcweir     Reference< XInputStream > xBaseStrm;
2197*cdf0e10cSrcweir     if( !bIsStrg )
2198*cdf0e10cSrcweir         xBaseStrm = mxStrg->openInputStream( OUString() );
2199*cdf0e10cSrcweir 
2200*cdf0e10cSrcweir     OUString aSysOutPath = maSysPath;
2201*cdf0e10cSrcweir     if( bIsRoot ) try
2202*cdf0e10cSrcweir     {
2203*cdf0e10cSrcweir         aSysOutPath += OOX_DUMP_DUMPEXT;
2204*cdf0e10cSrcweir         Reference< XMultiServiceFactory > xFactory( getContext()->getServiceManager(), UNO_QUERY_THROW );
2205*cdf0e10cSrcweir         Reference< XSimpleFileAccess > xFileAccess( xFactory->createInstance( CREATE_OUSTRING( "com.sun.star.ucb.SimpleFileAccess" ) ), UNO_QUERY_THROW );
2206*cdf0e10cSrcweir         xFileAccess->kill( aSysOutPath );
2207*cdf0e10cSrcweir     }
2208*cdf0e10cSrcweir     catch( Exception& )
2209*cdf0e10cSrcweir     {
2210*cdf0e10cSrcweir     }
2211*cdf0e10cSrcweir 
2212*cdf0e10cSrcweir     if( bIsStrg )
2213*cdf0e10cSrcweir     {
2214*cdf0e10cSrcweir         extractStorage( mxStrg, OUString(), aSysOutPath );
2215*cdf0e10cSrcweir     }
2216*cdf0e10cSrcweir     else if( xBaseStrm.is() )
2217*cdf0e10cSrcweir     {
2218*cdf0e10cSrcweir         BinaryInputStreamRef xInStrm( new BinaryXInputStream( xBaseStrm, false ) );
2219*cdf0e10cSrcweir         xInStrm->seekToStart();
2220*cdf0e10cSrcweir         implDumpBaseStream( xInStrm, aSysOutPath );
2221*cdf0e10cSrcweir     }
2222*cdf0e10cSrcweir }
2223*cdf0e10cSrcweir 
2224*cdf0e10cSrcweir void StorageObjectBase::implDumpStream( const Reference< XInputStream >&, const OUString&, const OUString&, const OUString& )
2225*cdf0e10cSrcweir {
2226*cdf0e10cSrcweir }
2227*cdf0e10cSrcweir 
2228*cdf0e10cSrcweir void StorageObjectBase::implDumpStorage( const StorageRef& rxStrg, const OUString& rStrgPath, const OUString& rSysPath )
2229*cdf0e10cSrcweir {
2230*cdf0e10cSrcweir     extractStorage( rxStrg, rStrgPath, rSysPath );
2231*cdf0e10cSrcweir }
2232*cdf0e10cSrcweir 
2233*cdf0e10cSrcweir void StorageObjectBase::implDumpBaseStream( const BinaryInputStreamRef&, const OUString& )
2234*cdf0e10cSrcweir {
2235*cdf0e10cSrcweir }
2236*cdf0e10cSrcweir 
2237*cdf0e10cSrcweir void StorageObjectBase::addPreferredStream( const String& rStrmName )
2238*cdf0e10cSrcweir {
2239*cdf0e10cSrcweir     if( rStrmName.has() )
2240*cdf0e10cSrcweir         maPreferred.push_back( PreferredItem( rStrmName, false ) );
2241*cdf0e10cSrcweir }
2242*cdf0e10cSrcweir 
2243*cdf0e10cSrcweir void StorageObjectBase::addPreferredStorage( const String& rStrgPath )
2244*cdf0e10cSrcweir {
2245*cdf0e10cSrcweir     if( rStrgPath.has() )
2246*cdf0e10cSrcweir         maPreferred.push_back( PreferredItem( rStrgPath, true ) );
2247*cdf0e10cSrcweir }
2248*cdf0e10cSrcweir 
2249*cdf0e10cSrcweir OUString StorageObjectBase::getSysFileName( const OUString& rStrmName, const OUString& rSysOutPath )
2250*cdf0e10cSrcweir {
2251*cdf0e10cSrcweir     // encode all characters < 0x20
2252*cdf0e10cSrcweir     OUStringBuffer aBuffer;
2253*cdf0e10cSrcweir     StringHelper::appendEncString( aBuffer, rStrmName, false );
2254*cdf0e10cSrcweir 
2255*cdf0e10cSrcweir     // replace all characters reserved in file system
2256*cdf0e10cSrcweir     OUString aFileName = aBuffer.makeStringAndClear();
2257*cdf0e10cSrcweir     static const sal_Unicode spcReserved[] = { '/', '\\', ':', '*', '?', '<', '>', '|' };
2258*cdf0e10cSrcweir     for( const sal_Unicode* pcChar = spcReserved; pcChar < STATIC_ARRAY_END( spcReserved ); ++pcChar )
2259*cdf0e10cSrcweir         aFileName = aFileName.replace( *pcChar, '_' );
2260*cdf0e10cSrcweir 
2261*cdf0e10cSrcweir     // build full path
2262*cdf0e10cSrcweir     return rSysOutPath + OUString( sal_Unicode( '/' ) ) + aFileName;
2263*cdf0e10cSrcweir }
2264*cdf0e10cSrcweir 
2265*cdf0e10cSrcweir void StorageObjectBase::extractStream( StorageBase& rStrg, const OUString& rStrgPath, const OUString& rStrmName, const OUString& rSysFileName )
2266*cdf0e10cSrcweir {
2267*cdf0e10cSrcweir     BinaryXInputStream aInStrm( rStrg.openInputStream( rStrmName ), true );
2268*cdf0e10cSrcweir     if( !aInStrm.isEof() )
2269*cdf0e10cSrcweir     {
2270*cdf0e10cSrcweir         BinaryXOutputStream aOutStrm( InputOutputHelper::openOutputStream( getContext(), rSysFileName ), true );
2271*cdf0e10cSrcweir         if( !aOutStrm.isEof() )
2272*cdf0e10cSrcweir             aInStrm.copyToStream( aOutStrm );
2273*cdf0e10cSrcweir     }
2274*cdf0e10cSrcweir     Reference< XInputStream > xDumpStrm = InputOutputHelper::openInputStream( getContext(), rSysFileName );
2275*cdf0e10cSrcweir     if( xDumpStrm.is() )
2276*cdf0e10cSrcweir         implDumpStream( xDumpStrm, rStrgPath, rStrmName, rSysFileName );
2277*cdf0e10cSrcweir }
2278*cdf0e10cSrcweir 
2279*cdf0e10cSrcweir void StorageObjectBase::extractStorage( const StorageRef& rxStrg, const OUString& rStrgPath, const OUString& rSysPath )
2280*cdf0e10cSrcweir {
2281*cdf0e10cSrcweir     // create directory in file system
2282*cdf0e10cSrcweir     ::osl::FileBase::RC eRes = ::osl::Directory::create( rSysPath );
2283*cdf0e10cSrcweir     if( (eRes != ::osl::FileBase::E_None) && (eRes != ::osl::FileBase::E_EXIST) )
2284*cdf0e10cSrcweir         return;
2285*cdf0e10cSrcweir 
2286*cdf0e10cSrcweir     // process preferred storages and streams in root storage first
2287*cdf0e10cSrcweir     if( rStrgPath.getLength() == 0 )
2288*cdf0e10cSrcweir         for( PreferredItemVector::iterator aIt = maPreferred.begin(), aEnd = maPreferred.end(); aIt != aEnd; ++aIt )
2289*cdf0e10cSrcweir             extractItem( rxStrg, rStrgPath, aIt->maName, rSysPath, aIt->mbStorage, !aIt->mbStorage );
2290*cdf0e10cSrcweir 
2291*cdf0e10cSrcweir     // process children of the storage
2292*cdf0e10cSrcweir     for( StorageIterator aIt( rxStrg ); aIt.isValid(); ++aIt )
2293*cdf0e10cSrcweir     {
2294*cdf0e10cSrcweir         // skip processed preferred items
2295*cdf0e10cSrcweir         OUString aItemName = aIt.getName();
2296*cdf0e10cSrcweir         bool bFound = false;
2297*cdf0e10cSrcweir         if( rStrgPath.getLength() == 0 )
2298*cdf0e10cSrcweir             for( PreferredItemVector::iterator aIIt = maPreferred.begin(), aIEnd = maPreferred.end(); !bFound && (aIIt != aIEnd); ++aIIt )
2299*cdf0e10cSrcweir                 bFound = aIIt->maName == aItemName;
2300*cdf0e10cSrcweir         if( !bFound )
2301*cdf0e10cSrcweir             extractItem( rxStrg, rStrgPath, aItemName, rSysPath, aIt.isStorage(), aIt.isStream() );
2302*cdf0e10cSrcweir     }
2303*cdf0e10cSrcweir }
2304*cdf0e10cSrcweir 
2305*cdf0e10cSrcweir void StorageObjectBase::extractItem( const StorageRef& rxStrg, const OUString& rStrgPath, const OUString& rItemName, const OUString& rSysPath, bool bIsStrg, bool bIsStrm )
2306*cdf0e10cSrcweir {
2307*cdf0e10cSrcweir     OUString aSysFileName = getSysFileName( rItemName, rSysPath );
2308*cdf0e10cSrcweir     if( bIsStrg )
2309*cdf0e10cSrcweir     {
2310*cdf0e10cSrcweir         OUStringBuffer aStrgPath( rStrgPath );
2311*cdf0e10cSrcweir         StringHelper::appendToken( aStrgPath, rItemName, '/' );
2312*cdf0e10cSrcweir         implDumpStorage( rxStrg->openSubStorage( rItemName, false ), aStrgPath.makeStringAndClear(), aSysFileName );
2313*cdf0e10cSrcweir     }
2314*cdf0e10cSrcweir     else if( bIsStrm )
2315*cdf0e10cSrcweir     {
2316*cdf0e10cSrcweir         extractStream( *rxStrg, rStrgPath, rItemName, aSysFileName );
2317*cdf0e10cSrcweir     }
2318*cdf0e10cSrcweir }
2319*cdf0e10cSrcweir 
2320*cdf0e10cSrcweir // ============================================================================
2321*cdf0e10cSrcweir // ============================================================================
2322*cdf0e10cSrcweir 
2323*cdf0e10cSrcweir OutputObjectBase::~OutputObjectBase()
2324*cdf0e10cSrcweir {
2325*cdf0e10cSrcweir }
2326*cdf0e10cSrcweir 
2327*cdf0e10cSrcweir void OutputObjectBase::construct( const ObjectBase& rParent, const OUString& rSysFileName )
2328*cdf0e10cSrcweir {
2329*cdf0e10cSrcweir     ObjectBase::construct( rParent );
2330*cdf0e10cSrcweir     if( ObjectBase::implIsValid() )
2331*cdf0e10cSrcweir     {
2332*cdf0e10cSrcweir         maSysFileName = rSysFileName;
2333*cdf0e10cSrcweir         mxOut.reset( new Output( getContext(), rSysFileName + OOX_DUMP_DUMPEXT ) );
2334*cdf0e10cSrcweir     }
2335*cdf0e10cSrcweir }
2336*cdf0e10cSrcweir 
2337*cdf0e10cSrcweir void OutputObjectBase::construct( const OutputObjectBase& rParent )
2338*cdf0e10cSrcweir {
2339*cdf0e10cSrcweir     *this = rParent;
2340*cdf0e10cSrcweir }
2341*cdf0e10cSrcweir 
2342*cdf0e10cSrcweir bool OutputObjectBase::implIsValid() const
2343*cdf0e10cSrcweir {
2344*cdf0e10cSrcweir     return isValid( mxOut ) && ObjectBase::implIsValid();
2345*cdf0e10cSrcweir }
2346*cdf0e10cSrcweir 
2347*cdf0e10cSrcweir void OutputObjectBase::writeEmptyItem( const String& rName )
2348*cdf0e10cSrcweir {
2349*cdf0e10cSrcweir     ItemGuard aItem( mxOut, rName );
2350*cdf0e10cSrcweir }
2351*cdf0e10cSrcweir 
2352*cdf0e10cSrcweir void OutputObjectBase::writeInfoItem( const String& rName, const String& rData )
2353*cdf0e10cSrcweir {
2354*cdf0e10cSrcweir     ItemGuard aItem( mxOut, rName );
2355*cdf0e10cSrcweir     mxOut->writeString( rData );
2356*cdf0e10cSrcweir }
2357*cdf0e10cSrcweir 
2358*cdf0e10cSrcweir void OutputObjectBase::writeCharItem( const String& rName, sal_Unicode cData )
2359*cdf0e10cSrcweir {
2360*cdf0e10cSrcweir     ItemGuard aItem( mxOut, rName );
2361*cdf0e10cSrcweir     mxOut->writeChar( OOX_DUMP_STRQUOTE );
2362*cdf0e10cSrcweir     mxOut->writeChar( cData );
2363*cdf0e10cSrcweir     mxOut->writeChar( OOX_DUMP_STRQUOTE );
2364*cdf0e10cSrcweir }
2365*cdf0e10cSrcweir 
2366*cdf0e10cSrcweir void OutputObjectBase::writeStringItem( const String& rName, const OUString& rData )
2367*cdf0e10cSrcweir {
2368*cdf0e10cSrcweir     ItemGuard aItem( mxOut, rName );
2369*cdf0e10cSrcweir     mxOut->writeAscii( "(len=" );
2370*cdf0e10cSrcweir     mxOut->writeDec( rData.getLength() );
2371*cdf0e10cSrcweir     mxOut->writeAscii( ")," );
2372*cdf0e10cSrcweir     OUStringBuffer aValue( rData.copy( 0, ::std::min( rData.getLength(), OOX_DUMP_MAXSTRLEN ) ) );
2373*cdf0e10cSrcweir     StringHelper::enclose( aValue, OOX_DUMP_STRQUOTE );
2374*cdf0e10cSrcweir     mxOut->writeString( aValue.makeStringAndClear() );
2375*cdf0e10cSrcweir     if( rData.getLength() > OOX_DUMP_MAXSTRLEN )
2376*cdf0e10cSrcweir         mxOut->writeAscii( ",cut" );
2377*cdf0e10cSrcweir }
2378*cdf0e10cSrcweir 
2379*cdf0e10cSrcweir void OutputObjectBase::writeArrayItem( const String& rName, const sal_uInt8* pnData, sal_Size nSize, sal_Unicode cSep )
2380*cdf0e10cSrcweir {
2381*cdf0e10cSrcweir     ItemGuard aItem( mxOut, rName );
2382*cdf0e10cSrcweir     mxOut->writeArray( pnData, nSize, cSep );
2383*cdf0e10cSrcweir }
2384*cdf0e10cSrcweir 
2385*cdf0e10cSrcweir void OutputObjectBase::writeBoolItem( const String& rName, bool bData )
2386*cdf0e10cSrcweir {
2387*cdf0e10cSrcweir     ItemGuard aItem( mxOut, rName );
2388*cdf0e10cSrcweir     mxOut->writeBool( bData );
2389*cdf0e10cSrcweir }
2390*cdf0e10cSrcweir 
2391*cdf0e10cSrcweir double OutputObjectBase::writeRkItem( const String& rName, sal_Int32 nRk )
2392*cdf0e10cSrcweir {
2393*cdf0e10cSrcweir     MultiItemsGuard aMultiGuard( mxOut );
2394*cdf0e10cSrcweir     writeHexItem( rName, static_cast< sal_uInt32 >( nRk ), "RK-FLAGS" );
2395*cdf0e10cSrcweir     double fValue = ::oox::xls::BiffHelper::calcDoubleFromRk( nRk );
2396*cdf0e10cSrcweir     writeDecItem( "decoded", fValue );
2397*cdf0e10cSrcweir     return fValue;
2398*cdf0e10cSrcweir }
2399*cdf0e10cSrcweir 
2400*cdf0e10cSrcweir void OutputObjectBase::writeColorABGRItem( const String& rName, sal_Int32 nColor )
2401*cdf0e10cSrcweir {
2402*cdf0e10cSrcweir     ItemGuard aItem( mxOut, rName );
2403*cdf0e10cSrcweir     writeHexItem( rName, nColor );
2404*cdf0e10cSrcweir     mxOut->writeColorABGR( nColor );
2405*cdf0e10cSrcweir }
2406*cdf0e10cSrcweir 
2407*cdf0e10cSrcweir void OutputObjectBase::writeDateTimeItem( const String& rName, const DateTime& rDateTime )
2408*cdf0e10cSrcweir {
2409*cdf0e10cSrcweir     ItemGuard aItem( mxOut, rName );
2410*cdf0e10cSrcweir     mxOut->writeDateTime( rDateTime );
2411*cdf0e10cSrcweir }
2412*cdf0e10cSrcweir 
2413*cdf0e10cSrcweir void OutputObjectBase::writeGuidItem( const String& rName, const OUString& rGuid )
2414*cdf0e10cSrcweir {
2415*cdf0e10cSrcweir     ItemGuard aItem( mxOut, rName );
2416*cdf0e10cSrcweir     mxOut->writeString( rGuid );
2417*cdf0e10cSrcweir     aItem.cont();
2418*cdf0e10cSrcweir     mxOut->writeString( cfg().getStringOption( rGuid, OUString() ) );
2419*cdf0e10cSrcweir }
2420*cdf0e10cSrcweir 
2421*cdf0e10cSrcweir void OutputObjectBase::writeColIndexItem( const String& rName, sal_Int32 nCol )
2422*cdf0e10cSrcweir {
2423*cdf0e10cSrcweir     ItemGuard aItem( mxOut, rName );
2424*cdf0e10cSrcweir     mxOut->writeDec( nCol );
2425*cdf0e10cSrcweir     aItem.cont();
2426*cdf0e10cSrcweir     mxOut->writeColIndex( nCol );
2427*cdf0e10cSrcweir }
2428*cdf0e10cSrcweir 
2429*cdf0e10cSrcweir void OutputObjectBase::writeRowIndexItem( const String& rName, sal_Int32 nRow )
2430*cdf0e10cSrcweir {
2431*cdf0e10cSrcweir     ItemGuard aItem( mxOut, rName );
2432*cdf0e10cSrcweir     mxOut->writeDec( nRow );
2433*cdf0e10cSrcweir     aItem.cont();
2434*cdf0e10cSrcweir     mxOut->writeRowIndex( nRow );
2435*cdf0e10cSrcweir }
2436*cdf0e10cSrcweir 
2437*cdf0e10cSrcweir void OutputObjectBase::writeColRangeItem( const String& rName, sal_Int32 nCol1, sal_Int32 nCol2 )
2438*cdf0e10cSrcweir {
2439*cdf0e10cSrcweir     ItemGuard aItem( mxOut, rName );
2440*cdf0e10cSrcweir     mxOut->writeColRowRange( nCol1, nCol2 );
2441*cdf0e10cSrcweir     aItem.cont();
2442*cdf0e10cSrcweir     mxOut->writeColRange( nCol1, nCol2 );
2443*cdf0e10cSrcweir }
2444*cdf0e10cSrcweir 
2445*cdf0e10cSrcweir void OutputObjectBase::writeRowRangeItem( const String& rName, sal_Int32 nRow1, sal_Int32 nRow2 )
2446*cdf0e10cSrcweir {
2447*cdf0e10cSrcweir     ItemGuard aItem( mxOut, rName );
2448*cdf0e10cSrcweir     mxOut->writeColRowRange( nRow1, nRow2 );
2449*cdf0e10cSrcweir     aItem.cont();
2450*cdf0e10cSrcweir     mxOut->writeRowRange( nRow1, nRow2 );
2451*cdf0e10cSrcweir }
2452*cdf0e10cSrcweir 
2453*cdf0e10cSrcweir void OutputObjectBase::writeAddressItem( const String& rName, const Address& rPos )
2454*cdf0e10cSrcweir {
2455*cdf0e10cSrcweir     ItemGuard aItem( mxOut, rName );
2456*cdf0e10cSrcweir     StringHelper::appendAddress( mxOut->getLine(), rPos );
2457*cdf0e10cSrcweir }
2458*cdf0e10cSrcweir 
2459*cdf0e10cSrcweir void OutputObjectBase::writeRangeItem( const String& rName, const Range& rRange )
2460*cdf0e10cSrcweir {
2461*cdf0e10cSrcweir     ItemGuard aItem( mxOut, rName );
2462*cdf0e10cSrcweir     StringHelper::appendRange( mxOut->getLine(), rRange );
2463*cdf0e10cSrcweir }
2464*cdf0e10cSrcweir 
2465*cdf0e10cSrcweir void OutputObjectBase::writeRangeListItem( const String& rName, const RangeList& rRanges )
2466*cdf0e10cSrcweir {
2467*cdf0e10cSrcweir     MultiItemsGuard aMultiGuard( mxOut );
2468*cdf0e10cSrcweir     writeEmptyItem( rName );
2469*cdf0e10cSrcweir     writeDecItem( "count", static_cast< sal_uInt16 >( rRanges.size() ) );
2470*cdf0e10cSrcweir     ItemGuard aItem( mxOut, "ranges" );
2471*cdf0e10cSrcweir     StringHelper::appendRangeList( mxOut->getLine(), rRanges );
2472*cdf0e10cSrcweir }
2473*cdf0e10cSrcweir 
2474*cdf0e10cSrcweir void OutputObjectBase::writeTokenAddressItem( const String& rName, const TokenAddress& rPos, bool bNameMode )
2475*cdf0e10cSrcweir {
2476*cdf0e10cSrcweir     ItemGuard aItem( mxOut, rName );
2477*cdf0e10cSrcweir     StringHelper::appendAddress( mxOut->getLine(), rPos, bNameMode );
2478*cdf0e10cSrcweir }
2479*cdf0e10cSrcweir 
2480*cdf0e10cSrcweir void OutputObjectBase::writeTokenAddress3dItem( const String& rName, const OUString& rRef, const TokenAddress& rPos, bool bNameMode )
2481*cdf0e10cSrcweir {
2482*cdf0e10cSrcweir     ItemGuard aItem( mxOut, rName );
2483*cdf0e10cSrcweir     mxOut->writeString( rRef );
2484*cdf0e10cSrcweir     StringHelper::appendAddress( mxOut->getLine(), rPos, bNameMode );
2485*cdf0e10cSrcweir }
2486*cdf0e10cSrcweir 
2487*cdf0e10cSrcweir void OutputObjectBase::writeTokenRangeItem( const String& rName, const TokenRange& rRange, bool bNameMode )
2488*cdf0e10cSrcweir {
2489*cdf0e10cSrcweir     ItemGuard aItem( mxOut, rName );
2490*cdf0e10cSrcweir     StringHelper::appendRange( mxOut->getLine(), rRange, bNameMode );
2491*cdf0e10cSrcweir }
2492*cdf0e10cSrcweir 
2493*cdf0e10cSrcweir void OutputObjectBase::writeTokenRange3dItem( const String& rName, const OUString& rRef, const TokenRange& rRange, bool bNameMode )
2494*cdf0e10cSrcweir {
2495*cdf0e10cSrcweir     ItemGuard aItem( mxOut, rName );
2496*cdf0e10cSrcweir     mxOut->writeString( rRef );
2497*cdf0e10cSrcweir     StringHelper::appendRange( mxOut->getLine(), rRange, bNameMode );
2498*cdf0e10cSrcweir }
2499*cdf0e10cSrcweir 
2500*cdf0e10cSrcweir // ============================================================================
2501*cdf0e10cSrcweir // ============================================================================
2502*cdf0e10cSrcweir 
2503*cdf0e10cSrcweir InputObjectBase::~InputObjectBase()
2504*cdf0e10cSrcweir {
2505*cdf0e10cSrcweir }
2506*cdf0e10cSrcweir 
2507*cdf0e10cSrcweir void InputObjectBase::construct( const ObjectBase& rParent, const BinaryInputStreamRef& rxStrm, const OUString& rSysFileName )
2508*cdf0e10cSrcweir {
2509*cdf0e10cSrcweir     OutputObjectBase::construct( rParent, rSysFileName );
2510*cdf0e10cSrcweir     mxStrm = rxStrm;
2511*cdf0e10cSrcweir }
2512*cdf0e10cSrcweir 
2513*cdf0e10cSrcweir void InputObjectBase::construct( const OutputObjectBase& rParent, const BinaryInputStreamRef& rxStrm )
2514*cdf0e10cSrcweir {
2515*cdf0e10cSrcweir     OutputObjectBase::construct( rParent );
2516*cdf0e10cSrcweir     mxStrm = rxStrm;
2517*cdf0e10cSrcweir }
2518*cdf0e10cSrcweir 
2519*cdf0e10cSrcweir void InputObjectBase::construct( const InputObjectBase& rParent )
2520*cdf0e10cSrcweir {
2521*cdf0e10cSrcweir     *this = rParent;
2522*cdf0e10cSrcweir }
2523*cdf0e10cSrcweir 
2524*cdf0e10cSrcweir bool InputObjectBase::implIsValid() const
2525*cdf0e10cSrcweir {
2526*cdf0e10cSrcweir     return mxStrm.get() && OutputObjectBase::implIsValid();
2527*cdf0e10cSrcweir }
2528*cdf0e10cSrcweir 
2529*cdf0e10cSrcweir void InputObjectBase::skipBlock( sal_Int64 nBytes, bool bShowSize )
2530*cdf0e10cSrcweir {
2531*cdf0e10cSrcweir     sal_Int64 nEndPos = ::std::min< sal_Int64 >( mxStrm->tell() + nBytes, mxStrm->size() );
2532*cdf0e10cSrcweir     if( mxStrm->tell() < nEndPos )
2533*cdf0e10cSrcweir     {
2534*cdf0e10cSrcweir         if( bShowSize )
2535*cdf0e10cSrcweir             writeDecItem( "skipped-data-size", static_cast< sal_uInt64 >( nEndPos - mxStrm->tell() ) );
2536*cdf0e10cSrcweir         mxStrm->seek( nEndPos );
2537*cdf0e10cSrcweir     }
2538*cdf0e10cSrcweir }
2539*cdf0e10cSrcweir 
2540*cdf0e10cSrcweir void InputObjectBase::dumpRawBinary( sal_Int64 nBytes, bool bShowOffset, bool bStream )
2541*cdf0e10cSrcweir {
2542*cdf0e10cSrcweir     TableGuard aTabGuard( mxOut,
2543*cdf0e10cSrcweir         bShowOffset ? 12 : 0,
2544*cdf0e10cSrcweir         3 * OOX_DUMP_BYTESPERLINE / 2 + 1,
2545*cdf0e10cSrcweir         3 * OOX_DUMP_BYTESPERLINE / 2 + 1,
2546*cdf0e10cSrcweir         OOX_DUMP_BYTESPERLINE / 2 + 1 );
2547*cdf0e10cSrcweir 
2548*cdf0e10cSrcweir     sal_Int64 nMaxShowSize = cfg().getIntOption< sal_Int64 >(
2549*cdf0e10cSrcweir         bStream ? "max-binary-stream-size" : "max-binary-data-size", SAL_MAX_INT64 );
2550*cdf0e10cSrcweir 
2551*cdf0e10cSrcweir     bool bSeekable = mxStrm->size() >= 0;
2552*cdf0e10cSrcweir     sal_Int64 nEndPos = bSeekable ? ::std::min< sal_Int64 >( mxStrm->tell() + nBytes, mxStrm->size() ) : 0;
2553*cdf0e10cSrcweir     sal_Int64 nDumpEnd = bSeekable ? ::std::min< sal_Int64 >( mxStrm->tell() + nMaxShowSize, nEndPos ) : nMaxShowSize;
2554*cdf0e10cSrcweir     sal_Int64 nPos = bSeekable ? mxStrm->tell() : 0;
2555*cdf0e10cSrcweir     bool bLoop = true;
2556*cdf0e10cSrcweir 
2557*cdf0e10cSrcweir     while( bLoop && (nPos < nDumpEnd) )
2558*cdf0e10cSrcweir     {
2559*cdf0e10cSrcweir         mxOut->writeHex( static_cast< sal_uInt32 >( nPos ) );
2560*cdf0e10cSrcweir         mxOut->tab();
2561*cdf0e10cSrcweir 
2562*cdf0e10cSrcweir         sal_uInt8 pnLineData[ OOX_DUMP_BYTESPERLINE ];
2563*cdf0e10cSrcweir         sal_Int32 nLineSize = bSeekable ? ::std::min( static_cast< sal_Int32 >( nDumpEnd - mxStrm->tell() ), OOX_DUMP_BYTESPERLINE ) : OOX_DUMP_BYTESPERLINE;
2564*cdf0e10cSrcweir         sal_Int32 nReadSize = mxStrm->readMemory( pnLineData, nLineSize );
2565*cdf0e10cSrcweir         bLoop = nReadSize == nLineSize;
2566*cdf0e10cSrcweir         nPos += nReadSize;
2567*cdf0e10cSrcweir 
2568*cdf0e10cSrcweir         if( nReadSize > 0 )
2569*cdf0e10cSrcweir         {
2570*cdf0e10cSrcweir             const sal_uInt8* pnByte = 0;
2571*cdf0e10cSrcweir             const sal_uInt8* pnEnd = 0;
2572*cdf0e10cSrcweir             for( pnByte = pnLineData, pnEnd = pnLineData + nReadSize; pnByte != pnEnd; ++pnByte )
2573*cdf0e10cSrcweir             {
2574*cdf0e10cSrcweir                 if( (pnByte - pnLineData) == (OOX_DUMP_BYTESPERLINE / 2) ) mxOut->tab();
2575*cdf0e10cSrcweir                 mxOut->writeHex( *pnByte, false );
2576*cdf0e10cSrcweir                 mxOut->writeChar( ' ' );
2577*cdf0e10cSrcweir             }
2578*cdf0e10cSrcweir 
2579*cdf0e10cSrcweir             aTabGuard.tab( 3 );
2580*cdf0e10cSrcweir             for( pnByte = pnLineData, pnEnd = pnLineData + nReadSize; pnByte != pnEnd; ++pnByte )
2581*cdf0e10cSrcweir             {
2582*cdf0e10cSrcweir                 if( (pnByte - pnLineData) == (OOX_DUMP_BYTESPERLINE / 2) ) mxOut->tab();
2583*cdf0e10cSrcweir                 mxOut->writeChar( static_cast< sal_Unicode >( (*pnByte < 0x20) ? '.' : *pnByte ) );
2584*cdf0e10cSrcweir             }
2585*cdf0e10cSrcweir             mxOut->newLine();
2586*cdf0e10cSrcweir         }
2587*cdf0e10cSrcweir     }
2588*cdf0e10cSrcweir 
2589*cdf0e10cSrcweir     // skip undumped data
2590*cdf0e10cSrcweir     if( bSeekable )
2591*cdf0e10cSrcweir         skipBlock( nEndPos - mxStrm->tell() );
2592*cdf0e10cSrcweir }
2593*cdf0e10cSrcweir 
2594*cdf0e10cSrcweir void InputObjectBase::dumpBinary( const String& rName, sal_Int64 nBytes, bool bShowOffset )
2595*cdf0e10cSrcweir {
2596*cdf0e10cSrcweir     {
2597*cdf0e10cSrcweir         MultiItemsGuard aMultiGuard( mxOut );
2598*cdf0e10cSrcweir         writeEmptyItem( rName );
2599*cdf0e10cSrcweir         writeDecItem( "size", nBytes );
2600*cdf0e10cSrcweir     }
2601*cdf0e10cSrcweir     IndentGuard aIndGuard( mxOut );
2602*cdf0e10cSrcweir     dumpRawBinary( nBytes, bShowOffset );
2603*cdf0e10cSrcweir }
2604*cdf0e10cSrcweir 
2605*cdf0e10cSrcweir void InputObjectBase::dumpRemaining( sal_Int64 nBytes )
2606*cdf0e10cSrcweir {
2607*cdf0e10cSrcweir     if( nBytes > 0 )
2608*cdf0e10cSrcweir     {
2609*cdf0e10cSrcweir         if( cfg().getBoolOption( "show-trailing-unknown", true ) )
2610*cdf0e10cSrcweir             dumpBinary( "remaining-data", nBytes, false );
2611*cdf0e10cSrcweir         else
2612*cdf0e10cSrcweir             skipBlock( nBytes );
2613*cdf0e10cSrcweir     }
2614*cdf0e10cSrcweir }
2615*cdf0e10cSrcweir 
2616*cdf0e10cSrcweir void InputObjectBase::dumpRemainingTo( sal_Int64 nPos )
2617*cdf0e10cSrcweir {
2618*cdf0e10cSrcweir     if( mxStrm->isEof() || (mxStrm->tell() > nPos) )
2619*cdf0e10cSrcweir         writeInfoItem( "stream-state", OOX_DUMP_ERR_STREAM );
2620*cdf0e10cSrcweir     else
2621*cdf0e10cSrcweir         dumpRemaining( nPos - mxStrm->tell() );
2622*cdf0e10cSrcweir     mxStrm->seek( nPos );
2623*cdf0e10cSrcweir }
2624*cdf0e10cSrcweir 
2625*cdf0e10cSrcweir void InputObjectBase::dumpRemainingStream()
2626*cdf0e10cSrcweir {
2627*cdf0e10cSrcweir     dumpRemainingTo( mxStrm->size() );
2628*cdf0e10cSrcweir }
2629*cdf0e10cSrcweir 
2630*cdf0e10cSrcweir void InputObjectBase::dumpArray( const String& rName, sal_Int32 nBytes, sal_Unicode cSep )
2631*cdf0e10cSrcweir {
2632*cdf0e10cSrcweir     sal_Int32 nDumpSize = getLimitedValue< sal_Int32, sal_Int64 >( mxStrm->size() - mxStrm->tell(), 0, nBytes );
2633*cdf0e10cSrcweir     if( nDumpSize > OOX_DUMP_MAXARRAY )
2634*cdf0e10cSrcweir     {
2635*cdf0e10cSrcweir         dumpBinary( rName, nBytes, false );
2636*cdf0e10cSrcweir     }
2637*cdf0e10cSrcweir     else if( nDumpSize > 1 )
2638*cdf0e10cSrcweir     {
2639*cdf0e10cSrcweir         sal_uInt8 pnData[ OOX_DUMP_MAXARRAY ];
2640*cdf0e10cSrcweir         mxStrm->readMemory( pnData, nDumpSize );
2641*cdf0e10cSrcweir         writeArrayItem( rName, pnData, nDumpSize, cSep );
2642*cdf0e10cSrcweir     }
2643*cdf0e10cSrcweir     else if( nDumpSize == 1 )
2644*cdf0e10cSrcweir         dumpHex< sal_uInt8 >( rName );
2645*cdf0e10cSrcweir }
2646*cdf0e10cSrcweir 
2647*cdf0e10cSrcweir sal_Unicode InputObjectBase::dumpChar( const String& rName, rtl_TextEncoding eTextEnc )
2648*cdf0e10cSrcweir {
2649*cdf0e10cSrcweir     sal_uInt8 nChar;
2650*cdf0e10cSrcweir     *mxStrm >> nChar;
2651*cdf0e10cSrcweir     OUString aChar = OStringToOUString( OString( static_cast< sal_Char >( nChar ) ), eTextEnc );
2652*cdf0e10cSrcweir     sal_Unicode cChar = (aChar.getLength() > 0) ? aChar[ 0 ] : 0;
2653*cdf0e10cSrcweir     writeCharItem( rName( "char" ), cChar );
2654*cdf0e10cSrcweir     return cChar;
2655*cdf0e10cSrcweir }
2656*cdf0e10cSrcweir 
2657*cdf0e10cSrcweir sal_Unicode InputObjectBase::dumpUnicode( const String& rName )
2658*cdf0e10cSrcweir {
2659*cdf0e10cSrcweir     sal_uInt16 nChar;
2660*cdf0e10cSrcweir     *mxStrm >> nChar;
2661*cdf0e10cSrcweir     sal_Unicode cChar = static_cast< sal_Unicode >( nChar );
2662*cdf0e10cSrcweir     writeCharItem( rName( "char" ), cChar );
2663*cdf0e10cSrcweir     return cChar;
2664*cdf0e10cSrcweir }
2665*cdf0e10cSrcweir 
2666*cdf0e10cSrcweir OUString InputObjectBase::dumpCharArray( const String& rName, sal_Int32 nLen, rtl_TextEncoding eTextEnc, bool bHideTrailingNul )
2667*cdf0e10cSrcweir {
2668*cdf0e10cSrcweir     sal_Int32 nDumpSize = getLimitedValue< sal_Int32, sal_Int64 >( mxStrm->size() - mxStrm->tell(), 0, nLen );
2669*cdf0e10cSrcweir     OUString aString;
2670*cdf0e10cSrcweir     if( nDumpSize > 0 )
2671*cdf0e10cSrcweir     {
2672*cdf0e10cSrcweir         ::std::vector< sal_Char > aBuffer( static_cast< sal_Size >( nLen ) + 1 );
2673*cdf0e10cSrcweir         sal_Int32 nCharsRead = mxStrm->readMemory( &aBuffer.front(), nLen );
2674*cdf0e10cSrcweir         aBuffer[ nCharsRead ] = 0;
2675*cdf0e10cSrcweir         aString = OStringToOUString( OString( &aBuffer.front() ), eTextEnc );
2676*cdf0e10cSrcweir     }
2677*cdf0e10cSrcweir     if( bHideTrailingNul )
2678*cdf0e10cSrcweir         aString = StringHelper::trimTrailingNul( aString );
2679*cdf0e10cSrcweir     writeStringItem( rName( "text" ), aString );
2680*cdf0e10cSrcweir     return aString;
2681*cdf0e10cSrcweir }
2682*cdf0e10cSrcweir 
2683*cdf0e10cSrcweir OUString InputObjectBase::dumpUnicodeArray( const String& rName, sal_Int32 nLen, bool bHideTrailingNul )
2684*cdf0e10cSrcweir {
2685*cdf0e10cSrcweir     OUStringBuffer aBuffer;
2686*cdf0e10cSrcweir     for( sal_Int32 nIndex = 0; !mxStrm->isEof() && (nIndex < nLen); ++nIndex )
2687*cdf0e10cSrcweir         aBuffer.append( static_cast< sal_Unicode >( mxStrm->readuInt16() ) );
2688*cdf0e10cSrcweir     OUString aString = aBuffer.makeStringAndClear();
2689*cdf0e10cSrcweir     if( bHideTrailingNul )
2690*cdf0e10cSrcweir         aString = StringHelper::trimTrailingNul( aString );
2691*cdf0e10cSrcweir     writeStringItem( rName( "text" ), aString );
2692*cdf0e10cSrcweir     return aString;
2693*cdf0e10cSrcweir }
2694*cdf0e10cSrcweir 
2695*cdf0e10cSrcweir OUString InputObjectBase::dumpNullCharArray( const String& rName, rtl_TextEncoding eTextEnc )
2696*cdf0e10cSrcweir {
2697*cdf0e10cSrcweir     OStringBuffer aBuffer;
2698*cdf0e10cSrcweir     sal_uInt8 nChar;
2699*cdf0e10cSrcweir     for( *mxStrm >> nChar; !mxStrm->isEof() && (nChar > 0); *mxStrm >> nChar )
2700*cdf0e10cSrcweir         aBuffer.append( static_cast< sal_Char >( nChar ) );
2701*cdf0e10cSrcweir     OUString aString = OStringToOUString( aBuffer.makeStringAndClear(), eTextEnc );
2702*cdf0e10cSrcweir     writeStringItem( rName( "text" ), aString );
2703*cdf0e10cSrcweir     return aString;
2704*cdf0e10cSrcweir }
2705*cdf0e10cSrcweir 
2706*cdf0e10cSrcweir OUString InputObjectBase::dumpNullUnicodeArray( const String& rName )
2707*cdf0e10cSrcweir {
2708*cdf0e10cSrcweir     OUStringBuffer aBuffer;
2709*cdf0e10cSrcweir     sal_uInt16 nChar;
2710*cdf0e10cSrcweir     for( *mxStrm >> nChar; !mxStrm->isEof() && (nChar > 0); *mxStrm >> nChar )
2711*cdf0e10cSrcweir         aBuffer.append( static_cast< sal_Unicode >( nChar ) );
2712*cdf0e10cSrcweir     OUString aString = aBuffer.makeStringAndClear();
2713*cdf0e10cSrcweir     writeStringItem( rName( "text" ), aString );
2714*cdf0e10cSrcweir     return aString;
2715*cdf0e10cSrcweir }
2716*cdf0e10cSrcweir 
2717*cdf0e10cSrcweir double InputObjectBase::dumpRk( const String& rName )
2718*cdf0e10cSrcweir {
2719*cdf0e10cSrcweir     sal_Int32 nRk;
2720*cdf0e10cSrcweir     *mxStrm >> nRk;
2721*cdf0e10cSrcweir     return writeRkItem( rName( "rk-value" ), nRk );
2722*cdf0e10cSrcweir }
2723*cdf0e10cSrcweir 
2724*cdf0e10cSrcweir sal_Int32 InputObjectBase::dumpColorABGR( const String& rName )
2725*cdf0e10cSrcweir {
2726*cdf0e10cSrcweir     sal_Int32 nColor;
2727*cdf0e10cSrcweir     *mxStrm >> nColor;
2728*cdf0e10cSrcweir     writeColorABGRItem( rName( "color" ), nColor );
2729*cdf0e10cSrcweir     return nColor;
2730*cdf0e10cSrcweir }
2731*cdf0e10cSrcweir 
2732*cdf0e10cSrcweir DateTime InputObjectBase::dumpFileTime( const String& rName )
2733*cdf0e10cSrcweir {
2734*cdf0e10cSrcweir     DateTime aDateTime;
2735*cdf0e10cSrcweir 
2736*cdf0e10cSrcweir     ItemGuard aItem( mxOut, rName( "file-time" ) );
2737*cdf0e10cSrcweir     sal_Int64 nFileTime = dumpDec< sal_Int64 >( EMPTY_STRING );
2738*cdf0e10cSrcweir     // file time is in 10^-7 seconds (100 nanoseconds), convert to 1/100 seconds
2739*cdf0e10cSrcweir     nFileTime /= 100000;
2740*cdf0e10cSrcweir     // entire days
2741*cdf0e10cSrcweir     sal_Int64 nDays = nFileTime / sal_Int64( 360000 * 24 );
2742*cdf0e10cSrcweir     // number of entire years
2743*cdf0e10cSrcweir     sal_Int64 nYears = (nDays - (nDays / (4 * 365)) + (nDays / (100 * 365)) - (nDays / (400 * 365))) / 365;
2744*cdf0e10cSrcweir     // remaining days in the year
2745*cdf0e10cSrcweir     sal_Int64 nDaysInYear = nDays - (nYears * 365 + nYears / 4 - nYears / 100 + nYears / 400);
2746*cdf0e10cSrcweir     // the year (file dates start from 1601-01-01)
2747*cdf0e10cSrcweir     aDateTime.Year = static_cast< sal_uInt16 >( 1601 + nYears );
2748*cdf0e10cSrcweir     // leap year?
2749*cdf0e10cSrcweir     bool bLeap = ((aDateTime.Year % 4 == 0) && (aDateTime.Year % 100 != 0)) || (aDateTime.Year % 400 == 0);
2750*cdf0e10cSrcweir     // static arrays with number of days in month
2751*cdf0e10cSrcweir     static const sal_Int64 spnDaysInMonth[]  = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
2752*cdf0e10cSrcweir     static const sal_Int64 spnDaysInMonthL[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
2753*cdf0e10cSrcweir     const sal_Int64* pnDaysInMonth = bLeap ? spnDaysInMonthL : spnDaysInMonth;
2754*cdf0e10cSrcweir     // the month
2755*cdf0e10cSrcweir     aDateTime.Month = 1;
2756*cdf0e10cSrcweir     while( nDaysInYear >= *pnDaysInMonth )
2757*cdf0e10cSrcweir     {
2758*cdf0e10cSrcweir         nDaysInYear -= *pnDaysInMonth++;
2759*cdf0e10cSrcweir         ++aDateTime.Month;
2760*cdf0e10cSrcweir     }
2761*cdf0e10cSrcweir     // the day
2762*cdf0e10cSrcweir     aDateTime.Day = static_cast< sal_uInt16 >( nDaysInYear + 1 );
2763*cdf0e10cSrcweir     // number of 1/100 seconds in the day
2764*cdf0e10cSrcweir     sal_Int64 nTimeInDay = nFileTime % sal_Int64( 360000 * 24 );
2765*cdf0e10cSrcweir     // 1/100 seconds
2766*cdf0e10cSrcweir     aDateTime.HundredthSeconds = static_cast< sal_uInt16 >( nTimeInDay % 100 );
2767*cdf0e10cSrcweir     nTimeInDay /= 100;
2768*cdf0e10cSrcweir     // seconds
2769*cdf0e10cSrcweir     aDateTime.Seconds = static_cast< sal_uInt16 >( nTimeInDay % 60 );
2770*cdf0e10cSrcweir     nTimeInDay /= 60;
2771*cdf0e10cSrcweir     // minutes
2772*cdf0e10cSrcweir     aDateTime.Minutes = static_cast< sal_uInt16 >( nTimeInDay % 60 );
2773*cdf0e10cSrcweir     nTimeInDay /= 60;
2774*cdf0e10cSrcweir     // hours
2775*cdf0e10cSrcweir     aDateTime.Hours = static_cast< sal_uInt16 >( nTimeInDay );
2776*cdf0e10cSrcweir 
2777*cdf0e10cSrcweir     writeDateTimeItem( EMPTY_STRING, aDateTime );
2778*cdf0e10cSrcweir     return aDateTime;
2779*cdf0e10cSrcweir }
2780*cdf0e10cSrcweir 
2781*cdf0e10cSrcweir OUString InputObjectBase::dumpGuid( const String& rName )
2782*cdf0e10cSrcweir {
2783*cdf0e10cSrcweir     OUStringBuffer aBuffer;
2784*cdf0e10cSrcweir     sal_uInt32 nData32;
2785*cdf0e10cSrcweir     sal_uInt16 nData16;
2786*cdf0e10cSrcweir     sal_uInt8 nData8;
2787*cdf0e10cSrcweir 
2788*cdf0e10cSrcweir     *mxStrm >> nData32;
2789*cdf0e10cSrcweir     StringHelper::appendHex( aBuffer, nData32, false );
2790*cdf0e10cSrcweir     aBuffer.append( sal_Unicode( '-' ) );
2791*cdf0e10cSrcweir     *mxStrm >> nData16;
2792*cdf0e10cSrcweir     StringHelper::appendHex( aBuffer, nData16, false );
2793*cdf0e10cSrcweir     aBuffer.append( sal_Unicode( '-' ) );
2794*cdf0e10cSrcweir     *mxStrm >> nData16;
2795*cdf0e10cSrcweir     StringHelper::appendHex( aBuffer, nData16, false );
2796*cdf0e10cSrcweir     aBuffer.append( sal_Unicode( '-' ) );
2797*cdf0e10cSrcweir     *mxStrm >> nData8;
2798*cdf0e10cSrcweir     StringHelper::appendHex( aBuffer, nData8, false );
2799*cdf0e10cSrcweir     *mxStrm >> nData8;
2800*cdf0e10cSrcweir     StringHelper::appendHex( aBuffer, nData8, false );
2801*cdf0e10cSrcweir     aBuffer.append( sal_Unicode( '-' ) );
2802*cdf0e10cSrcweir     for( int nIndex = 0; nIndex < 6; ++nIndex )
2803*cdf0e10cSrcweir     {
2804*cdf0e10cSrcweir         *mxStrm >> nData8;
2805*cdf0e10cSrcweir         StringHelper::appendHex( aBuffer, nData8, false );
2806*cdf0e10cSrcweir     }
2807*cdf0e10cSrcweir     StringHelper::enclose( aBuffer, '{', '}' );
2808*cdf0e10cSrcweir     OUString aGuid = aBuffer.makeStringAndClear();
2809*cdf0e10cSrcweir     writeGuidItem( rName( "guid" ), aGuid );
2810*cdf0e10cSrcweir     return aGuid;
2811*cdf0e10cSrcweir }
2812*cdf0e10cSrcweir 
2813*cdf0e10cSrcweir void InputObjectBase::dumpItem( const ItemFormat& rItemFmt )
2814*cdf0e10cSrcweir {
2815*cdf0e10cSrcweir     switch( rItemFmt.meDataType )
2816*cdf0e10cSrcweir     {
2817*cdf0e10cSrcweir         case DATATYPE_VOID:                                         break;
2818*cdf0e10cSrcweir         case DATATYPE_INT8:    dumpValue< sal_Int8 >( rItemFmt );   break;
2819*cdf0e10cSrcweir         case DATATYPE_UINT8:   dumpValue< sal_uInt8 >( rItemFmt );  break;
2820*cdf0e10cSrcweir         case DATATYPE_INT16:   dumpValue< sal_Int16 >( rItemFmt );  break;
2821*cdf0e10cSrcweir         case DATATYPE_UINT16:  dumpValue< sal_uInt16 >( rItemFmt ); break;
2822*cdf0e10cSrcweir         case DATATYPE_INT32:   dumpValue< sal_Int32 >( rItemFmt );  break;
2823*cdf0e10cSrcweir         case DATATYPE_UINT32:  dumpValue< sal_uInt32 >( rItemFmt ); break;
2824*cdf0e10cSrcweir         case DATATYPE_INT64:   dumpValue< sal_Int64 >( rItemFmt );  break;
2825*cdf0e10cSrcweir         case DATATYPE_UINT64:  dumpValue< sal_uInt64 >( rItemFmt ); break;
2826*cdf0e10cSrcweir         case DATATYPE_FLOAT:   dumpValue< float >( rItemFmt );      break;
2827*cdf0e10cSrcweir         case DATATYPE_DOUBLE:  dumpValue< double >( rItemFmt );     break;
2828*cdf0e10cSrcweir         default:;
2829*cdf0e10cSrcweir     }
2830*cdf0e10cSrcweir }
2831*cdf0e10cSrcweir 
2832*cdf0e10cSrcweir // ============================================================================
2833*cdf0e10cSrcweir // ============================================================================
2834*cdf0e10cSrcweir 
2835*cdf0e10cSrcweir BinaryStreamObject::BinaryStreamObject( const ObjectBase& rParent, const BinaryInputStreamRef& rxStrm, const OUString& rSysFileName )
2836*cdf0e10cSrcweir {
2837*cdf0e10cSrcweir     InputObjectBase::construct( rParent, rxStrm, rSysFileName );
2838*cdf0e10cSrcweir }
2839*cdf0e10cSrcweir 
2840*cdf0e10cSrcweir BinaryStreamObject::BinaryStreamObject( const OutputObjectBase& rParent, const BinaryInputStreamRef& rxStrm )
2841*cdf0e10cSrcweir {
2842*cdf0e10cSrcweir     InputObjectBase::construct( rParent, rxStrm );
2843*cdf0e10cSrcweir }
2844*cdf0e10cSrcweir 
2845*cdf0e10cSrcweir void BinaryStreamObject::dumpBinaryStream( bool bShowOffset )
2846*cdf0e10cSrcweir {
2847*cdf0e10cSrcweir     mxStrm->seekToStart();
2848*cdf0e10cSrcweir     dumpRawBinary( mxStrm->size(), bShowOffset, true );
2849*cdf0e10cSrcweir     mxOut->emptyLine();
2850*cdf0e10cSrcweir }
2851*cdf0e10cSrcweir 
2852*cdf0e10cSrcweir void BinaryStreamObject::implDump()
2853*cdf0e10cSrcweir {
2854*cdf0e10cSrcweir     dumpBinaryStream();
2855*cdf0e10cSrcweir }
2856*cdf0e10cSrcweir 
2857*cdf0e10cSrcweir // ============================================================================
2858*cdf0e10cSrcweir // ============================================================================
2859*cdf0e10cSrcweir 
2860*cdf0e10cSrcweir void TextStreamObjectBase::construct( const ObjectBase& rParent,
2861*cdf0e10cSrcweir         const BinaryInputStreamRef& rxStrm, rtl_TextEncoding eTextEnc, const OUString& rSysFileName )
2862*cdf0e10cSrcweir {
2863*cdf0e10cSrcweir     InputObjectBase::construct( rParent, rxStrm, rSysFileName );
2864*cdf0e10cSrcweir     constructTextStrmObj( eTextEnc );
2865*cdf0e10cSrcweir }
2866*cdf0e10cSrcweir 
2867*cdf0e10cSrcweir void TextStreamObjectBase::construct( const OutputObjectBase& rParent,
2868*cdf0e10cSrcweir         const BinaryInputStreamRef& rxStrm, rtl_TextEncoding eTextEnc )
2869*cdf0e10cSrcweir {
2870*cdf0e10cSrcweir     InputObjectBase::construct( rParent, rxStrm );
2871*cdf0e10cSrcweir     constructTextStrmObj( eTextEnc );
2872*cdf0e10cSrcweir }
2873*cdf0e10cSrcweir 
2874*cdf0e10cSrcweir void TextStreamObjectBase::construct( const InputObjectBase& rParent, rtl_TextEncoding eTextEnc )
2875*cdf0e10cSrcweir {
2876*cdf0e10cSrcweir     InputObjectBase::construct( rParent );
2877*cdf0e10cSrcweir     constructTextStrmObj( eTextEnc );
2878*cdf0e10cSrcweir }
2879*cdf0e10cSrcweir 
2880*cdf0e10cSrcweir bool TextStreamObjectBase::implIsValid() const
2881*cdf0e10cSrcweir {
2882*cdf0e10cSrcweir     return InputObjectBase::implIsValid() && mxTextStrm.get();
2883*cdf0e10cSrcweir }
2884*cdf0e10cSrcweir 
2885*cdf0e10cSrcweir void TextStreamObjectBase::implDump()
2886*cdf0e10cSrcweir {
2887*cdf0e10cSrcweir     implDumpText( *mxTextStrm );
2888*cdf0e10cSrcweir }
2889*cdf0e10cSrcweir 
2890*cdf0e10cSrcweir void TextStreamObjectBase::constructTextStrmObj( rtl_TextEncoding eTextEnc )
2891*cdf0e10cSrcweir {
2892*cdf0e10cSrcweir     if( mxStrm.get() )
2893*cdf0e10cSrcweir         mxTextStrm.reset( new TextInputStream( getContext(), *mxStrm, eTextEnc ) );
2894*cdf0e10cSrcweir }
2895*cdf0e10cSrcweir 
2896*cdf0e10cSrcweir // ============================================================================
2897*cdf0e10cSrcweir 
2898*cdf0e10cSrcweir TextLineStreamObject::TextLineStreamObject( const ObjectBase& rParent,
2899*cdf0e10cSrcweir         const BinaryInputStreamRef& rxStrm, rtl_TextEncoding eTextEnc, const OUString& rSysFileName )
2900*cdf0e10cSrcweir {
2901*cdf0e10cSrcweir     TextStreamObjectBase::construct( rParent, rxStrm, eTextEnc, rSysFileName );
2902*cdf0e10cSrcweir }
2903*cdf0e10cSrcweir 
2904*cdf0e10cSrcweir TextLineStreamObject::TextLineStreamObject( const OutputObjectBase& rParent,
2905*cdf0e10cSrcweir         const BinaryInputStreamRef& rxStrm, rtl_TextEncoding eTextEnc )
2906*cdf0e10cSrcweir {
2907*cdf0e10cSrcweir     TextStreamObjectBase::construct( rParent, rxStrm, eTextEnc );
2908*cdf0e10cSrcweir }
2909*cdf0e10cSrcweir 
2910*cdf0e10cSrcweir void TextLineStreamObject::implDumpText( TextInputStream& rTextStrm )
2911*cdf0e10cSrcweir {
2912*cdf0e10cSrcweir     sal_uInt32 nLine = 0;
2913*cdf0e10cSrcweir     while( !rTextStrm.isEof() )
2914*cdf0e10cSrcweir     {
2915*cdf0e10cSrcweir         OUString aLine = rTextStrm.readLine();
2916*cdf0e10cSrcweir         if( !rTextStrm.isEof() || (aLine.getLength() > 0) )
2917*cdf0e10cSrcweir             implDumpLine( aLine, ++nLine );
2918*cdf0e10cSrcweir     }
2919*cdf0e10cSrcweir }
2920*cdf0e10cSrcweir 
2921*cdf0e10cSrcweir void TextLineStreamObject::implDumpLine( const OUString& rLine, sal_uInt32 nLine )
2922*cdf0e10cSrcweir {
2923*cdf0e10cSrcweir     TableGuard aTabGuard( mxOut, 8 );
2924*cdf0e10cSrcweir     mxOut->writeDec( nLine, 6 );
2925*cdf0e10cSrcweir     mxOut->tab();
2926*cdf0e10cSrcweir     mxOut->writeString( rLine );
2927*cdf0e10cSrcweir     mxOut->newLine();
2928*cdf0e10cSrcweir }
2929*cdf0e10cSrcweir 
2930*cdf0e10cSrcweir // ============================================================================
2931*cdf0e10cSrcweir 
2932*cdf0e10cSrcweir XmlStreamObject::XmlStreamObject( const ObjectBase& rParent,
2933*cdf0e10cSrcweir         const BinaryInputStreamRef& rxStrm, const OUString& rSysFileName )
2934*cdf0e10cSrcweir {
2935*cdf0e10cSrcweir     TextStreamObjectBase::construct( rParent, rxStrm, RTL_TEXTENCODING_UTF8, rSysFileName );
2936*cdf0e10cSrcweir }
2937*cdf0e10cSrcweir 
2938*cdf0e10cSrcweir XmlStreamObject::XmlStreamObject( const OutputObjectBase& rParent, const BinaryInputStreamRef& rxStrm )
2939*cdf0e10cSrcweir {
2940*cdf0e10cSrcweir     TextStreamObjectBase::construct( rParent, rxStrm, RTL_TEXTENCODING_UTF8 );
2941*cdf0e10cSrcweir }
2942*cdf0e10cSrcweir 
2943*cdf0e10cSrcweir void XmlStreamObject::implDumpText( TextInputStream& rTextStrm )
2944*cdf0e10cSrcweir {
2945*cdf0e10cSrcweir     /*  Buffers a start element and the following element text. Needed to dump
2946*cdf0e10cSrcweir         matching start/end elements and the element text on the same line. */
2947*cdf0e10cSrcweir     OUStringBuffer aOldStartElem;
2948*cdf0e10cSrcweir     // special handling for VML
2949*cdf0e10cSrcweir     bool bIsVml = InputOutputHelper::getFileNameExtension( maSysFileName ).equalsIgnoreAsciiCaseAscii( "vml" );
2950*cdf0e10cSrcweir 
2951*cdf0e10cSrcweir     while( !rTextStrm.isEof() )
2952*cdf0e10cSrcweir     {
2953*cdf0e10cSrcweir         // get the next element and the following element text from text stream
2954*cdf0e10cSrcweir         OUString aElem = rTextStrm.readToChar( '>', true ).trim();
2955*cdf0e10cSrcweir         OUString aText = rTextStrm.readToChar( '<', false );
2956*cdf0e10cSrcweir 
2957*cdf0e10cSrcweir         // remove multiple whitespace from element
2958*cdf0e10cSrcweir         sal_Int32 nPos = 0;
2959*cdf0e10cSrcweir         while( nPos < aElem.getLength() )
2960*cdf0e10cSrcweir         {
2961*cdf0e10cSrcweir             while( (nPos < aElem.getLength()) && (aElem[ nPos ] >= 32) ) ++nPos;
2962*cdf0e10cSrcweir             if( nPos < aElem.getLength() )
2963*cdf0e10cSrcweir                 aElem = OUStringBuffer( aElem.copy( 0, nPos ) ).append( sal_Unicode( ' ' ) ).append( aElem.copy( nPos ).trim() ).makeStringAndClear();
2964*cdf0e10cSrcweir             ++nPos;
2965*cdf0e10cSrcweir         }
2966*cdf0e10cSrcweir 
2967*cdf0e10cSrcweir         sal_Int32 nElemLen = aElem.getLength();
2968*cdf0e10cSrcweir         if( (nElemLen >= 2) && (aElem[ 0 ] == '<') && (aElem[ nElemLen - 1 ] == '>') )
2969*cdf0e10cSrcweir         {
2970*cdf0e10cSrcweir             // determine type of the element
2971*cdf0e10cSrcweir             bool bSimpleElem = (aElem[ 1 ] == '!') || (aElem[ 1 ] == '?') || (aElem[ nElemLen - 2 ] == '/') ||
2972*cdf0e10cSrcweir                 (bIsVml && (nElemLen == 4) && (aElem[ 1 ] == 'b') && (aElem[ 2 ] == 'r'));
2973*cdf0e10cSrcweir             bool bStartElem = !bSimpleElem && (aElem[ 1 ] != '/');
2974*cdf0e10cSrcweir             bool bEndElem = !bSimpleElem && !bStartElem;
2975*cdf0e10cSrcweir 
2976*cdf0e10cSrcweir             /*  Start element or simple element: flush old start element and
2977*cdf0e10cSrcweir                 its text from previous iteration, and start a new indentation
2978*cdf0e10cSrcweir                 level for the new element. Trim whitespace and line breaks from
2979*cdf0e10cSrcweir                 the text of the old start element. */
2980*cdf0e10cSrcweir             if( (bSimpleElem || bStartElem) && (aOldStartElem.getLength() > 0) )
2981*cdf0e10cSrcweir             {
2982*cdf0e10cSrcweir                 mxOut->writeString( aOldStartElem.makeStringAndClear().trim() );
2983*cdf0e10cSrcweir                 mxOut->newLine();
2984*cdf0e10cSrcweir                 mxOut->incIndent();
2985*cdf0e10cSrcweir             }
2986*cdf0e10cSrcweir 
2987*cdf0e10cSrcweir             /*  Start element: remember it and its text, to be able to print the
2988*cdf0e10cSrcweir                 matching end element on the same line in the next iteration. */
2989*cdf0e10cSrcweir             if( bStartElem )
2990*cdf0e10cSrcweir             {
2991*cdf0e10cSrcweir                 aOldStartElem.append( aElem ).append( aText );
2992*cdf0e10cSrcweir             }
2993*cdf0e10cSrcweir             else
2994*cdf0e10cSrcweir             {
2995*cdf0e10cSrcweir                 /*  End element: if a start element has been remembered in the
2996*cdf0e10cSrcweir                     previous iteration, write it out here untrimmed, to show
2997*cdf0e10cSrcweir                     all whitespace in the element text, and without trailing
2998*cdf0e10cSrcweir                     line break. Code below will add the end element right after
2999*cdf0e10cSrcweir                     it. Otherwise, return to previous indentation level. */
3000*cdf0e10cSrcweir                 if( bEndElem )
3001*cdf0e10cSrcweir                 {
3002*cdf0e10cSrcweir                     if( aOldStartElem.getLength() == 0 )
3003*cdf0e10cSrcweir                         mxOut->decIndent();
3004*cdf0e10cSrcweir                     else
3005*cdf0e10cSrcweir                         mxOut->writeString( aOldStartElem.makeStringAndClear() );
3006*cdf0e10cSrcweir                 }
3007*cdf0e10cSrcweir 
3008*cdf0e10cSrcweir                 /*  Write the element. Write following element text in a new
3009*cdf0e10cSrcweir                     line, but only, if it does not contain of white space
3010*cdf0e10cSrcweir                     entirely. */
3011*cdf0e10cSrcweir                 mxOut->writeString( aElem );
3012*cdf0e10cSrcweir                 mxOut->newLine();
3013*cdf0e10cSrcweir                 if( aText.trim().getLength() > 0 )
3014*cdf0e10cSrcweir                 {
3015*cdf0e10cSrcweir                     mxOut->writeString( aText );
3016*cdf0e10cSrcweir                     mxOut->newLine();
3017*cdf0e10cSrcweir                 }
3018*cdf0e10cSrcweir             }
3019*cdf0e10cSrcweir         }
3020*cdf0e10cSrcweir     }
3021*cdf0e10cSrcweir }
3022*cdf0e10cSrcweir 
3023*cdf0e10cSrcweir // ============================================================================
3024*cdf0e10cSrcweir // ============================================================================
3025*cdf0e10cSrcweir 
3026*cdf0e10cSrcweir void RecordObjectBase::construct( const ObjectBase& rParent,
3027*cdf0e10cSrcweir         const BinaryInputStreamRef& rxBaseStrm, const OUString& rSysFileName,
3028*cdf0e10cSrcweir         const BinaryInputStreamRef& rxRecStrm, const String& rRecNames, const String& rSimpleRecs )
3029*cdf0e10cSrcweir {
3030*cdf0e10cSrcweir     InputObjectBase::construct( rParent, rxRecStrm, rSysFileName );
3031*cdf0e10cSrcweir     constructRecObjBase( rxBaseStrm, rRecNames, rSimpleRecs );
3032*cdf0e10cSrcweir }
3033*cdf0e10cSrcweir 
3034*cdf0e10cSrcweir void RecordObjectBase::construct( const OutputObjectBase& rParent, const BinaryInputStreamRef& rxBaseStrm,
3035*cdf0e10cSrcweir         const BinaryInputStreamRef& rxRecStrm, const String& rRecNames, const String& rSimpleRecs )
3036*cdf0e10cSrcweir {
3037*cdf0e10cSrcweir     InputObjectBase::construct( rParent, rxRecStrm );
3038*cdf0e10cSrcweir     constructRecObjBase( rxBaseStrm, rRecNames, rSimpleRecs );
3039*cdf0e10cSrcweir }
3040*cdf0e10cSrcweir 
3041*cdf0e10cSrcweir bool RecordObjectBase::implIsValid() const
3042*cdf0e10cSrcweir {
3043*cdf0e10cSrcweir     return mxBaseStrm.get() && InputObjectBase::implIsValid();
3044*cdf0e10cSrcweir }
3045*cdf0e10cSrcweir 
3046*cdf0e10cSrcweir void RecordObjectBase::implDump()
3047*cdf0e10cSrcweir {
3048*cdf0e10cSrcweir     NameListRef xRecNames = getRecNames();
3049*cdf0e10cSrcweir     ItemFormatMap aSimpleRecs( maSimpleRecs.getNameList( cfg() ) );
3050*cdf0e10cSrcweir 
3051*cdf0e10cSrcweir     while( implStartRecord( *mxBaseStrm, mnRecPos, mnRecId, mnRecSize ) )
3052*cdf0e10cSrcweir     {
3053*cdf0e10cSrcweir         // record header
3054*cdf0e10cSrcweir         mxOut->emptyLine();
3055*cdf0e10cSrcweir         writeHeader();
3056*cdf0e10cSrcweir         implWriteExtHeader();
3057*cdf0e10cSrcweir         IndentGuard aIndGuard( mxOut );
3058*cdf0e10cSrcweir         sal_Int64 nRecPos = mxStrm->tell();
3059*cdf0e10cSrcweir 
3060*cdf0e10cSrcweir         // record body
3061*cdf0e10cSrcweir         if( !mbBinaryOnly && cfg().hasName( xRecNames, mnRecId ) )
3062*cdf0e10cSrcweir         {
3063*cdf0e10cSrcweir             ItemFormatMap::const_iterator aIt = aSimpleRecs.find( mnRecId );
3064*cdf0e10cSrcweir             if( aIt != aSimpleRecs.end() )
3065*cdf0e10cSrcweir                 dumpItem( aIt->second );
3066*cdf0e10cSrcweir             else
3067*cdf0e10cSrcweir                 implDumpRecordBody();
3068*cdf0e10cSrcweir         }
3069*cdf0e10cSrcweir 
3070*cdf0e10cSrcweir         // remaining undumped data
3071*cdf0e10cSrcweir         if( !mxStrm->isEof() && (mxStrm->tell() == nRecPos) )
3072*cdf0e10cSrcweir             dumpRawBinary( mnRecSize, false );
3073*cdf0e10cSrcweir         else
3074*cdf0e10cSrcweir             dumpRemainingTo( nRecPos + mnRecSize );
3075*cdf0e10cSrcweir     }
3076*cdf0e10cSrcweir }
3077*cdf0e10cSrcweir 
3078*cdf0e10cSrcweir void RecordObjectBase::implWriteExtHeader()
3079*cdf0e10cSrcweir {
3080*cdf0e10cSrcweir }
3081*cdf0e10cSrcweir 
3082*cdf0e10cSrcweir void RecordObjectBase::implDumpRecordBody()
3083*cdf0e10cSrcweir {
3084*cdf0e10cSrcweir }
3085*cdf0e10cSrcweir 
3086*cdf0e10cSrcweir void RecordObjectBase::constructRecObjBase( const BinaryInputStreamRef& rxBaseStrm, const String& rRecNames, const String& rSimpleRecs )
3087*cdf0e10cSrcweir {
3088*cdf0e10cSrcweir     mxBaseStrm = rxBaseStrm;
3089*cdf0e10cSrcweir     maRecNames = rRecNames;
3090*cdf0e10cSrcweir     maSimpleRecs = rSimpleRecs;
3091*cdf0e10cSrcweir     mnRecPos = mnRecId = mnRecSize = 0;
3092*cdf0e10cSrcweir     mbBinaryOnly = false;
3093*cdf0e10cSrcweir     if( InputObjectBase::implIsValid() )
3094*cdf0e10cSrcweir         mbShowRecPos = cfg().getBoolOption( "show-record-position", true );
3095*cdf0e10cSrcweir }
3096*cdf0e10cSrcweir 
3097*cdf0e10cSrcweir void RecordObjectBase::writeHeader()
3098*cdf0e10cSrcweir {
3099*cdf0e10cSrcweir     MultiItemsGuard aMultiGuard( mxOut );
3100*cdf0e10cSrcweir     writeEmptyItem( "REC" );
3101*cdf0e10cSrcweir     if( mbShowRecPos && mxBaseStrm->isSeekable() )
3102*cdf0e10cSrcweir         writeShortHexItem( "pos", mnRecPos, "CONV-DEC" );
3103*cdf0e10cSrcweir     writeShortHexItem( "size", mnRecSize, "CONV-DEC" );
3104*cdf0e10cSrcweir     ItemGuard aItem( mxOut, "id" );
3105*cdf0e10cSrcweir     mxOut->writeShortHex( mnRecId );
3106*cdf0e10cSrcweir     addNameToItem( mnRecId, "CONV-DEC" );
3107*cdf0e10cSrcweir     addNameToItem( mnRecId, maRecNames );
3108*cdf0e10cSrcweir }
3109*cdf0e10cSrcweir 
3110*cdf0e10cSrcweir // ============================================================================
3111*cdf0e10cSrcweir 
3112*cdf0e10cSrcweir void SequenceRecordObjectBase::construct( const ObjectBase& rParent,
3113*cdf0e10cSrcweir         const BinaryInputStreamRef& rxBaseStrm, const ::rtl::OUString& rSysFileName,
3114*cdf0e10cSrcweir         const String& rRecNames, const String& rSimpleRecs )
3115*cdf0e10cSrcweir {
3116*cdf0e10cSrcweir     BinaryInputStreamRef xRecStrm( new SequenceInputStream( *mxRecData ) );
3117*cdf0e10cSrcweir     RecordObjectBase::construct( rParent, rxBaseStrm, rSysFileName, xRecStrm, rRecNames, rSimpleRecs );
3118*cdf0e10cSrcweir }
3119*cdf0e10cSrcweir 
3120*cdf0e10cSrcweir void SequenceRecordObjectBase::construct( const OutputObjectBase& rParent,
3121*cdf0e10cSrcweir         const BinaryInputStreamRef& rxBaseStrm, const String& rRecNames, const String& rSimpleRecs )
3122*cdf0e10cSrcweir {
3123*cdf0e10cSrcweir     BinaryInputStreamRef xRecStrm( new SequenceInputStream( *mxRecData ) );
3124*cdf0e10cSrcweir     RecordObjectBase::construct( rParent, rxBaseStrm, xRecStrm, rRecNames, rSimpleRecs );
3125*cdf0e10cSrcweir }
3126*cdf0e10cSrcweir 
3127*cdf0e10cSrcweir bool SequenceRecordObjectBase::implStartRecord( BinaryInputStream& rBaseStrm, sal_Int64& ornRecPos, sal_Int64& ornRecId, sal_Int64& ornRecSize )
3128*cdf0e10cSrcweir {
3129*cdf0e10cSrcweir     bool bValid = true;
3130*cdf0e10cSrcweir     if( rBaseStrm.isSeekable() )
3131*cdf0e10cSrcweir     {
3132*cdf0e10cSrcweir         ornRecPos = rBaseStrm.tell();
3133*cdf0e10cSrcweir         // do not try to overread seekable streams, may cause assertions
3134*cdf0e10cSrcweir         bValid = ornRecPos < rBaseStrm.size();
3135*cdf0e10cSrcweir     }
3136*cdf0e10cSrcweir 
3137*cdf0e10cSrcweir     // read the record header
3138*cdf0e10cSrcweir     if( bValid )
3139*cdf0e10cSrcweir         bValid = implReadRecordHeader( rBaseStrm, ornRecId, ornRecSize ) && !rBaseStrm.isEof() && (0 <= ornRecSize) && (ornRecSize <= 0x00100000);
3140*cdf0e10cSrcweir 
3141*cdf0e10cSrcweir     // read record contents into data sequence
3142*cdf0e10cSrcweir     if( bValid )
3143*cdf0e10cSrcweir     {
3144*cdf0e10cSrcweir         sal_Int32 nRecSize = static_cast< sal_Int32 >( ornRecSize );
3145*cdf0e10cSrcweir         mxRecData->realloc( nRecSize );
3146*cdf0e10cSrcweir         bValid = (nRecSize == 0) || (rBaseStrm.readData( *mxRecData, nRecSize ) == nRecSize);
3147*cdf0e10cSrcweir         mxStrm->seekToStart();
3148*cdf0e10cSrcweir     }
3149*cdf0e10cSrcweir     return bValid;
3150*cdf0e10cSrcweir }
3151*cdf0e10cSrcweir 
3152*cdf0e10cSrcweir // ============================================================================
3153*cdf0e10cSrcweir // ============================================================================
3154*cdf0e10cSrcweir 
3155*cdf0e10cSrcweir DumperBase::~DumperBase()
3156*cdf0e10cSrcweir {
3157*cdf0e10cSrcweir }
3158*cdf0e10cSrcweir 
3159*cdf0e10cSrcweir bool DumperBase::isImportEnabled() const
3160*cdf0e10cSrcweir {
3161*cdf0e10cSrcweir     return !isValid() || cfg().isImportEnabled();
3162*cdf0e10cSrcweir }
3163*cdf0e10cSrcweir 
3164*cdf0e10cSrcweir bool DumperBase::isImportCancelled() const
3165*cdf0e10cSrcweir {
3166*cdf0e10cSrcweir     return isValid() && cfg().isPasswordCancelled();
3167*cdf0e10cSrcweir }
3168*cdf0e10cSrcweir 
3169*cdf0e10cSrcweir void DumperBase::construct( const ConfigRef& rxConfig )
3170*cdf0e10cSrcweir {
3171*cdf0e10cSrcweir     if( isValid( rxConfig ) && rxConfig->isDumperEnabled() )
3172*cdf0e10cSrcweir         ObjectBase::construct( rxConfig );
3173*cdf0e10cSrcweir }
3174*cdf0e10cSrcweir 
3175*cdf0e10cSrcweir // ============================================================================
3176*cdf0e10cSrcweir // ============================================================================
3177*cdf0e10cSrcweir 
3178*cdf0e10cSrcweir } // namespace dump
3179*cdf0e10cSrcweir } // namespace oox
3180*cdf0e10cSrcweir 
3181*cdf0e10cSrcweir #endif
3182