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