bump product version to 4.1.6.2
[LibreOffice.git] / include / oox / dump / dumperbase.hxx
blob043bb73ecfa844255a0e2aff5b765618ae1c56e1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef OOX_DUMP_DUMPERBASE_HXX
21 #define OOX_DUMP_DUMPERBASE_HXX
23 #include <math.h>
24 #include <vector>
25 #include <stack>
26 #include <set>
27 #include <map>
28 #include <boost/shared_ptr.hpp>
29 #include <rtl/strbuf.hxx>
30 #include <rtl/ustrbuf.hxx>
31 #include <com/sun/star/uno/Reference.hxx>
32 #include <com/sun/star/util/DateTime.hpp>
33 #include "oox/helper/binaryinputstream.hxx"
34 #include "oox/helper/helper.hxx"
35 #include "oox/helper/storagebase.hxx"
37 #define OOX_INCLUDE_DUMPER (OSL_DEBUG_LEVEL > 0)
39 #if OOX_INCLUDE_DUMPER
41 namespace com { namespace sun { namespace star {
42 namespace io { class XInputStream; }
43 namespace io { class XOutputStream; }
44 namespace io { class XTextOutputStream2; }
45 namespace uno { class XComponentContext; }
46 } } }
48 namespace comphelper {
49 class IDocPasswordVerifier;
52 namespace oox {
53 class BinaryOutputStream;
54 class TextInputStream;
57 namespace oox { namespace core {
58 class FilterBase;
59 } }
61 namespace oox {
62 namespace dump {
64 // ============================================================================
66 #define OOX_DUMP_UNUSED "unused"
67 #define OOX_DUMP_UNKNOWN "?unknown"
69 #define OOX_DUMP_ERRASCII( ascii ) "?err:" ascii
71 #define OOX_DUMP_ERR_NOMAP "no-map"
72 #define OOX_DUMP_ERR_NONAME "no-name"
73 #define OOX_DUMP_ERR_STREAM "stream-error"
75 #define OOX_DUMP_DUMPEXT ".dump"
77 const sal_Unicode OOX_DUMP_STRQUOTE = '\'';
78 const sal_Unicode OOX_DUMP_FMLASTRQUOTE = '"';
79 const sal_Unicode OOX_DUMP_ADDRABS = '$';
80 const sal_Unicode OOX_DUMP_R1C1ROW = 'R';
81 const sal_Unicode OOX_DUMP_R1C1COL = 'C';
82 const sal_Unicode OOX_DUMP_R1C1OPEN = '[';
83 const sal_Unicode OOX_DUMP_R1C1CLOSE = ']';
84 const sal_Unicode OOX_DUMP_RANGESEP = ':';
85 const sal_Unicode OOX_DUMP_BASECLASS = 'B';
86 const sal_Unicode OOX_DUMP_FUNCSEP = ',';
87 const sal_Unicode OOX_DUMP_LISTSEP = ',';
88 const sal_Unicode OOX_DUMP_TABSEP = '!';
89 const sal_Unicode OOX_DUMP_ARRAYSEP = ';';
90 const sal_Unicode OOX_DUMP_EMPTYVALUE = '~';
91 const sal_Unicode OOX_DUMP_CMDPROMPT = '?';
92 const sal_Unicode OOX_DUMP_PLACEHOLDER = '\x01';
94 typedef ::std::pair< OUString, OUString > OUStringPair;
95 typedef ::std::pair< sal_Int64, sal_Int64 > Int64Pair;
97 typedef ::std::vector< OUString > OUStringVector;
98 typedef ::std::vector< sal_Int64 > Int64Vector;
100 // ============================================================================
101 // ============================================================================
103 /** Static helper functions for system file and stream access. */
104 class InputOutputHelper
106 public:
107 // file names -------------------------------------------------------------
109 static OUString convertFileNameToUrl( const OUString& rFileName );
110 static sal_Int32 getFileNamePos( const OUString& rFileUrl );
111 static OUString getFileNameExtension( const OUString& rFileUrl );
113 // input streams ----------------------------------------------------------
115 static ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
116 openInputStream(
117 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
118 const OUString& rFileName );
120 // output streams ---------------------------------------------------------
122 static ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >
123 openOutputStream(
124 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
125 const OUString& rFileName );
127 static ::com::sun::star::uno::Reference< ::com::sun::star::io::XTextOutputStream2 >
128 openTextOutputStream(
129 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
130 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& rxOutStrm,
131 rtl_TextEncoding eTextEnc );
133 static ::com::sun::star::uno::Reference< ::com::sun::star::io::XTextOutputStream2 >
134 openTextOutputStream(
135 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
136 const OUString& rFileName,
137 rtl_TextEncoding eTextEnc );
140 // ============================================================================
142 class BinaryInputStreamRef : public ::oox::BinaryInputStreamRef
144 public:
145 inline BinaryInputStreamRef() {}
147 inline /*implicit*/ BinaryInputStreamRef( BinaryInputStream* pInStrm ) :
148 ::oox::BinaryInputStreamRef( pInStrm ) {}
150 inline /*implicit*/ BinaryInputStreamRef( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxInStrm ) :
151 ::oox::BinaryInputStreamRef( new BinaryXInputStream( rxInStrm, true ) ) {}
153 template< typename StreamType >
154 inline /*implicit*/ BinaryInputStreamRef( const ::boost::shared_ptr< StreamType >& rxInStrm ) :
155 ::oox::BinaryInputStreamRef( rxInStrm ) {}
158 // ============================================================================
159 // ============================================================================
161 /** Specifiers for atomic data types. */
162 enum DataType
164 DATATYPE_VOID, ///< No data type.
165 DATATYPE_INT8, ///< Signed 8-bit integer.
166 DATATYPE_UINT8, ///< Unsigned 8-bit integer.
167 DATATYPE_INT16, ///< Signed 16-bit integer.
168 DATATYPE_UINT16, ///< Unsigned 16-bit integer.
169 DATATYPE_INT32, ///< Signed 32-bit integer.
170 DATATYPE_UINT32, ///< Unsigned 32-bit integer.
171 DATATYPE_INT64, ///< Signed 64-bit integer.
172 DATATYPE_UINT64, ///< Unsigned 64-bit integer.
173 DATATYPE_FLOAT, ///< Floating-point, single precision.
174 DATATYPE_DOUBLE ///< Floating-point, double precision.
177 // ----------------------------------------------------------------------------
179 /** Specifiers for the output format of values. */
180 enum FormatType
182 FORMATTYPE_NONE, ///< No numeric format (e.g. show name only).
183 FORMATTYPE_DEC, ///< Decimal.
184 FORMATTYPE_HEX, ///< Hexadecimal.
185 FORMATTYPE_SHORTHEX, ///< Hexadecimal, as short as possible (no leading zeros).
186 FORMATTYPE_BIN, ///< Binary.
187 FORMATTYPE_FIX, ///< Fixed-point.
188 FORMATTYPE_BOOL ///< Boolean ('true' or 'false').
191 // ----------------------------------------------------------------------------
193 /** Describes the output format of a data item.
195 Data items are written in the following format:
197 <NAME>=<VALUE>=<NAME-FROM-LIST>
199 NAME is the name of the data item. The name is contained in the member
200 maItemName. If the name is empty, only the value is written (without a
201 leading equality sign).
203 VALUE is the numeric value of the data item. Its format is dependent on the
204 output format given in the member meFmtType. If the format type is
205 FORMATTYPE_NONE, no value is written.
207 NAME-FROM-LIST is a symbolic name for the current value of the data item.
208 Various types of name lists produce different names for values, which can
209 be used for enumerations or names for single bits in bitfields (see class
210 NameListBase and derived classes). The name of the list is given in the
211 member maListName. If it is empty, no name is written for the value.
213 struct ItemFormat
215 DataType meDataType; ///< Data type of the item.
216 FormatType meFmtType; ///< Output format for the value.
217 OUString maItemName; ///< Name of the item.
218 OUString maListName; ///< Name of a name list to be used for this item.
220 explicit ItemFormat();
222 void set( DataType eDataType, FormatType eFmtType, const OUString& rItemName );
224 /** Initializes the struct from a vector of strings containing the item format.
226 The vector must contain at least 2 strings. The struct is filled from
227 the strings in the vector in the following order:
228 1) Data type (one of: [u]int8, [u]int16, [u]int32, [u]int64, float, double).
229 2) Format type (one of: dec, hex, shorthex, bin, fix, bool, unused, unknown).
230 3) Item name (optional).
231 4) Name list name (optional).
233 @return Iterator pointing to the first unhandled string.
235 OUStringVector::const_iterator parse( const OUStringVector& rFormatVec );
237 /** Initializes the struct from a string containing the item format.
239 The string must have the following format:
240 DATATYPE,FORMATTYPE[,ITEMNAME[,LISTNAME]]
242 DATATYPE is the data type of the item (see above for possible values).
243 FORMATTYPE is the format type of the item (see above for possible values).
244 ITEMNAME is the name of the item (optional).
245 LISTNAME is the name of a name list (optional).
247 @return List containing remaining unhandled format strings.
249 OUStringVector parse( const OUString& rFormatStr );
252 // ============================================================================
253 // ============================================================================
255 struct Address
257 sal_Int32 mnCol;
258 sal_Int32 mnRow;
259 inline explicit Address() : mnCol( 0 ), mnRow( 0 ) {}
260 inline explicit Address( sal_Int32 nCol, sal_Int32 nRow ) : mnCol( nCol ), mnRow( nRow ) {}
263 // ----------------------------------------------------------------------------
265 struct Range
267 Address maFirst;
268 Address maLast;
269 inline explicit Range() {}
272 // ----------------------------------------------------------------------------
274 typedef ::std::vector< Range > RangeList;
276 // ============================================================================
278 struct TokenAddress : public Address
280 bool mbRelCol;
281 bool mbRelRow;
282 inline explicit TokenAddress() : mbRelCol( false ), mbRelRow( false ) {}
285 // ----------------------------------------------------------------------------
287 struct TokenRange
289 TokenAddress maFirst;
290 TokenAddress maLast;
291 inline explicit TokenRange() {}
294 // ============================================================================
295 // ============================================================================
297 /** Static helper functions for formatted output to strings. */
298 class StringHelper
300 public:
301 // append string to string ------------------------------------------------
303 static void appendChar( OUStringBuffer& rStr, sal_Unicode cChar, sal_Int32 nCount = 1 );
304 static void appendString( OUStringBuffer& rStr, const OUString& rData, sal_Int32 nWidth = 0, sal_Unicode cFill = ' ' );
306 // append decimal ---------------------------------------------------------
308 static void appendDec( OUStringBuffer& rStr, sal_uInt8 nData, sal_Int32 nWidth = 0, sal_Unicode cFill = ' ' );
309 static void appendDec( OUStringBuffer& rStr, sal_Int8 nData, sal_Int32 nWidth = 0, sal_Unicode cFill = ' ' );
310 static void appendDec( OUStringBuffer& rStr, sal_uInt16 nData, sal_Int32 nWidth = 0, sal_Unicode cFill = ' ' );
311 static void appendDec( OUStringBuffer& rStr, sal_Int16 nData, sal_Int32 nWidth = 0, sal_Unicode cFill = ' ' );
312 static void appendDec( OUStringBuffer& rStr, sal_uInt32 nData, sal_Int32 nWidth = 0, sal_Unicode cFill = ' ' );
313 static void appendDec( OUStringBuffer& rStr, sal_Int32 nData, sal_Int32 nWidth = 0, sal_Unicode cFill = ' ' );
314 static void appendDec( OUStringBuffer& rStr, sal_uInt64 nData, sal_Int32 nWidth = 0, sal_Unicode cFill = ' ' );
315 static void appendDec( OUStringBuffer& rStr, sal_Int64 nData, sal_Int32 nWidth = 0, sal_Unicode cFill = ' ' );
316 static void appendDec( OUStringBuffer& rStr, double fData, sal_Int32 nWidth = 0, sal_Unicode cFill = ' ' );
318 // append hexadecimal -----------------------------------------------------
320 static void appendHex( OUStringBuffer& rStr, sal_uInt8 nData, bool bPrefix = true );
321 static void appendHex( OUStringBuffer& rStr, sal_Int8 nData, bool bPrefix = true );
322 static void appendHex( OUStringBuffer& rStr, sal_uInt16 nData, bool bPrefix = true );
323 static void appendHex( OUStringBuffer& rStr, sal_Int16 nData, bool bPrefix = true );
324 static void appendHex( OUStringBuffer& rStr, sal_uInt32 nData, bool bPrefix = true );
325 static void appendHex( OUStringBuffer& rStr, sal_Int32 nData, bool bPrefix = true );
326 static void appendHex( OUStringBuffer& rStr, sal_uInt64 nData, bool bPrefix = true );
327 static void appendHex( OUStringBuffer& rStr, sal_Int64 nData, bool bPrefix = true );
328 static void appendHex( OUStringBuffer& rStr, double fData, bool bPrefix = true );
330 // append shortened hexadecimal -------------------------------------------
332 static void appendShortHex( OUStringBuffer& rStr, sal_uInt8 nData, bool bPrefix = true );
333 static void appendShortHex( OUStringBuffer& rStr, sal_Int8 nData, bool bPrefix = true );
334 static void appendShortHex( OUStringBuffer& rStr, sal_uInt16 nData, bool bPrefix = true );
335 static void appendShortHex( OUStringBuffer& rStr, sal_Int16 nData, bool bPrefix = true );
336 static void appendShortHex( OUStringBuffer& rStr, sal_uInt32 nData, bool bPrefix = true );
337 static void appendShortHex( OUStringBuffer& rStr, sal_Int32 nData, bool bPrefix = true );
338 static void appendShortHex( OUStringBuffer& rStr, sal_uInt64 nData, bool bPrefix = true );
339 static void appendShortHex( OUStringBuffer& rStr, sal_Int64 nData, bool bPrefix = true );
340 static void appendShortHex( OUStringBuffer& rStr, double fData, bool bPrefix = true );
342 // append binary ----------------------------------------------------------
344 static void appendBin( OUStringBuffer& rStr, sal_uInt8 nData, bool bDots = true );
345 static void appendBin( OUStringBuffer& rStr, sal_Int8 nData, bool bDots = true );
346 static void appendBin( OUStringBuffer& rStr, sal_uInt16 nData, bool bDots = true );
347 static void appendBin( OUStringBuffer& rStr, sal_Int16 nData, bool bDots = true );
348 static void appendBin( OUStringBuffer& rStr, sal_uInt32 nData, bool bDots = true );
349 static void appendBin( OUStringBuffer& rStr, sal_Int32 nData, bool bDots = true );
350 static void appendBin( OUStringBuffer& rStr, sal_uInt64 nData, bool bDots = true );
351 static void appendBin( OUStringBuffer& rStr, sal_Int64 nData, bool bDots = true );
352 static void appendBin( OUStringBuffer& rStr, double fData, bool bDots = true );
354 // append fixed-point decimal ---------------------------------------------
356 template< typename Type >
357 static void appendFix( OUStringBuffer& rStr, Type nData, sal_Int32 nWidth = 0 );
359 // append formatted value -------------------------------------------------
361 static void appendBool( OUStringBuffer& rStr, bool bData );
362 template< typename Type >
363 static void appendValue( OUStringBuffer& rStr, Type nData, FormatType eFmtType );
365 // encoded text output ----------------------------------------------------
367 static void appendCChar( OUStringBuffer& rStr, sal_Unicode cChar, bool bPrefix = true );
368 static void appendEncChar( OUStringBuffer& rStr, sal_Unicode cChar, sal_Int32 nCount = 1, bool bPrefix = true );
369 static void appendEncString( OUStringBuffer& rStr, const OUString& rData, bool bPrefix = true );
371 // token list -------------------------------------------------------------
373 static void appendToken( OUStringBuffer& rStr, const OUString& rToken, sal_Unicode cSep = OOX_DUMP_LISTSEP );
375 static void appendIndex( OUStringBuffer& rStr, const OUString& rIdx );
376 static void appendIndex( OUStringBuffer& rStr, sal_Int64 nIdx );
378 static OUString getToken( const OUString& rData, sal_Int32& rnPos, sal_Unicode cSep = OOX_DUMP_LISTSEP );
380 /** Encloses the passed string with the passed characters. Uses cOpen, if cClose is NUL. */
381 static void enclose( OUStringBuffer& rStr, sal_Unicode cOpen, sal_Unicode cClose = '\0' );
383 // string conversion ------------------------------------------------------
385 static OUString trimSpaces( const OUString& rStr );
386 static OUString trimTrailingNul( const OUString& rStr );
388 static OString convertToUtf8( const OUString& rStr );
389 static DataType convertToDataType( const OUString& rStr );
390 static FormatType convertToFormatType( const OUString& rStr );
392 static bool convertFromDec( sal_Int64& ornData, const OUString& rData );
393 static bool convertFromHex( sal_Int64& ornData, const OUString& rData );
395 static bool convertStringToInt( sal_Int64& ornData, const OUString& rData );
396 static bool convertStringToDouble( double& orfData, const OUString& rData );
397 static bool convertStringToBool( const OUString& rData );
399 static OUStringPair convertStringToPair( const OUString& rString, sal_Unicode cSep = '=' );
401 // string to list conversion ----------------------------------------------
403 static void convertStringToStringList( OUStringVector& orVec, const OUString& rData, bool bIgnoreEmpty );
404 static void convertStringToIntList( Int64Vector& orVec, const OUString& rData, bool bIgnoreEmpty );
407 // ----------------------------------------------------------------------------
409 template< typename Type >
410 void StringHelper::appendFix( OUStringBuffer& rStr, Type nData, sal_Int32 nWidth )
412 appendDec( rStr, static_cast< double >( nData ) / pow( 2.0, 4.0 * sizeof( Type ) ), nWidth );
415 template< typename Type >
416 void StringHelper::appendValue( OUStringBuffer& rStr, Type nData, FormatType eFmtType )
418 switch( eFmtType )
420 case FORMATTYPE_DEC: appendDec( rStr, nData ); break;
421 case FORMATTYPE_HEX: appendHex( rStr, nData ); break;
422 case FORMATTYPE_SHORTHEX: appendShortHex( rStr, nData ); break;
423 case FORMATTYPE_BIN: appendBin( rStr, nData ); break;
424 case FORMATTYPE_FIX: appendFix( rStr, nData ); break;
425 case FORMATTYPE_BOOL: appendBool( rStr, nData ); break;
426 default:;
430 // ============================================================================
432 class String : public OUString
434 public:
435 inline String() {}
436 inline /*implicit*/ String( const OUString& rStr ) : OUString( rStr ) {}
437 inline /*implicit*/ String( const sal_Char* pcStr ) : OUString( OUString::createFromAscii( pcStr ? pcStr : "" ) ) {}
438 inline /*implicit*/ String( sal_Unicode cChar ) : OUString( cChar ) {}
440 inline bool has() const { return getLength() > 0; }
441 inline OUString operator()( const sal_Char* pcDefault ) const { if( has() ) return *this; return String( pcDefault ); }
444 static const String EMPTY_STRING;
446 // ============================================================================
447 // ============================================================================
449 class Base;
450 typedef ::boost::shared_ptr< Base > BaseRef;
452 /** Base class for all dumper classes.
454 Derived classes implement the virtual function implIsValid(). It should
455 check all members the other functions rely on. If the function
456 implIsValid() returns true, all references and pointers can be used without
457 further checking.
459 Overview of all classes in this header file based on this Base class:
461 Base
463 +----> NameListBase
465 | +----> ConstList ------> MultiList
467 | +----> FlagsList ------> CombiList
469 | +----> UnitConverter
471 +----> SharedConfigData
473 +----> Config
475 +----> Output
477 +----> StorageIterator
479 +----> ObjectBase
481 +----> StorageObjectBase
483 +----> OutputObjectBase
485 | +----> InputObjectBase
487 | +----> BinaryStreamObject
489 | +----> TextStreamObjectBase
490 | | |
491 | | +----> TextStreamObject
492 | | |
493 | | +----> XmlStreamObject
495 | +----> RecordObjectBase
497 | +----> SequenceRecordObjectBase
499 +----> DumperBase
501 class Base
503 public:
504 virtual ~Base();
506 inline bool isValid() const { return implIsValid(); }
507 inline static bool isValid( const BaseRef& rxBase ) { return rxBase.get() && rxBase->isValid(); }
509 protected:
510 inline explicit Base() {}
512 virtual bool implIsValid() const = 0;
515 // ============================================================================
516 // ============================================================================
518 class ConfigItemBase
520 public:
521 virtual ~ConfigItemBase();
522 void readConfigBlock( TextInputStream& rStrm );
524 protected:
525 inline explicit ConfigItemBase() {}
527 virtual void implProcessConfigItemStr(
528 TextInputStream& rStrm,
529 const OUString& rKey,
530 const OUString& rData );
532 virtual void implProcessConfigItemInt(
533 TextInputStream& rStrm,
534 sal_Int64 nKey,
535 const OUString& rData );
537 void readConfigBlockContents(
538 TextInputStream& rStrm );
540 private:
541 enum LineType { LINETYPE_DATA, LINETYPE_END };
543 LineType readConfigLine(
544 TextInputStream& rStrm,
545 OUString& orKey,
546 OUString& orData ) const;
548 void processConfigItem(
549 TextInputStream& rStrm,
550 const OUString& rKey,
551 const OUString& rData );
554 // ============================================================================
556 class SharedConfigData;
557 class Config;
559 class NameListBase;
560 typedef ::boost::shared_ptr< NameListBase > NameListRef;
562 /** Base class of all classes providing names for specific values (name lists).
564 The idea is to provide a unique interfase for all different methods to
565 write specific names for any values. This can be enumerations (dedicated
566 names for a subset of values), or names for bits in bit fields. Classes
567 derived from this base class implement the specific behaviour for the
568 desired purpose.
570 class NameListBase : public Base, public ConfigItemBase
572 public:
573 typedef ::std::map< sal_Int64, OUString > OUStringMap;
574 typedef OUStringMap::const_iterator const_iterator;
576 public:
577 virtual ~NameListBase();
579 /** Sets a name for the specified key. */
580 void setName( sal_Int64 nKey, const String& rName );
582 /** Include all names of the passed list. */
583 void includeList( const NameListRef& rxList );
585 /** Returns true, if the map contains an entry for the passed key. */
586 template< typename Type >
587 inline bool hasName( Type nKey ) const
588 { return maMap.count( static_cast< sal_Int64 >( nKey ) ) != 0; }
590 /** Returns the name for the passed key. */
591 template< typename Type >
592 inline OUString getName( const Config& rCfg, Type nKey ) const
593 { return implGetName( rCfg, static_cast< sal_Int64 >( nKey ) ); }
595 /** Returns a display name for the passed double value. */
596 inline OUString getName( const Config& rCfg, double fValue ) const
597 { return implGetNameDbl( rCfg, fValue ); }
599 /** Returns a map iterator pointing to the first contained name. */
600 inline const_iterator begin() const { return maMap.begin(); }
601 /** Returns a map iterator pointing one past the last contained name. */
602 inline const_iterator end() const { return maMap.end(); }
604 protected:
605 inline explicit NameListBase( const SharedConfigData& rCfgData ) : mrCfgData( rCfgData ) {}
607 virtual bool implIsValid() const;
609 virtual void implProcessConfigItemStr(
610 TextInputStream& rStrm,
611 const OUString& rKey,
612 const OUString& rData );
614 virtual void implProcessConfigItemInt(
615 TextInputStream& rStrm,
616 sal_Int64 nKey,
617 const OUString& rData );
619 /** Derived classes set the name for the passed key. */
620 virtual void implSetName( sal_Int64 nKey, const OUString& rName ) = 0;
621 /** Derived classes generate and return the name for the passed key. */
622 virtual OUString implGetName( const Config& rCfg, sal_Int64 nKey ) const = 0;
623 /** Derived classes generate and return the name for the passed double value. */
624 virtual OUString implGetNameDbl( const Config& rCfg, double fValue ) const = 0;
625 /** Derived classes insert all names and other settings from the passed list. */
626 virtual void implIncludeList( const NameListBase& rList ) = 0;
628 /** Inserts the passed name into the internal map. */
629 void insertRawName( sal_Int64 nKey, const OUString& rName );
630 /** Returns the name for the passed key, or 0, if nothing found. */
631 const OUString* findRawName( sal_Int64 nKey ) const;
633 private:
634 /** Includes name lists, given in a comma separated list of names of the lists. */
635 void include( const OUString& rListKeys );
636 /** Excludes names from the list, given in a comma separated list of their keys. */
637 void exclude( const OUString& rKeys );
639 private:
640 OUStringMap maMap;
641 const SharedConfigData& mrCfgData;
644 // ============================================================================
646 class ConstList : public NameListBase
648 public:
649 explicit ConstList( const SharedConfigData& rCfgData );
651 /** Sets a default name for unknown keys. */
652 inline void setDefaultName( const String& rDefName ) { maDefName = rDefName; }
653 /** Enables or disables automatic quotation of returned names. */
654 inline void setQuoteNames( bool bQuoteNames ) { mbQuoteNames = bQuoteNames; }
656 protected:
657 virtual void implProcessConfigItemStr(
658 TextInputStream& rStrm,
659 const OUString& rKey,
660 const OUString& rData );
662 /** Sets the name for the passed key. */
663 virtual void implSetName( sal_Int64 nKey, const OUString& rName );
664 /** Returns the name for the passed key, or the default name, if key is not contained. */
665 virtual OUString implGetName( const Config& rCfg, sal_Int64 nKey ) const;
666 /** Returns the name for the passed double value. */
667 virtual OUString implGetNameDbl( const Config& rCfg, double fValue ) const;
668 /** Inserts all names from the passed list. */
669 virtual void implIncludeList( const NameListBase& rList );
671 private:
672 OUString maDefName;
673 bool mbQuoteNames;
676 // ============================================================================
678 class MultiList : public ConstList
680 public:
681 explicit MultiList( const SharedConfigData& rCfgData );
683 void setNamesFromVec( sal_Int64 nStartKey, const OUStringVector& rNames );
685 protected:
686 virtual void implProcessConfigItemStr(
687 TextInputStream& rStrm,
688 const OUString& rKey,
689 const OUString& rData );
691 virtual void implSetName( sal_Int64 nKey, const OUString& rName );
693 private:
694 void insertNames( sal_Int64 nStartKey, const OUString& rData );
696 private:
697 bool mbIgnoreEmpty;
700 // ============================================================================
702 class FlagsList : public NameListBase
704 public:
705 explicit FlagsList( const SharedConfigData& rCfgData );
707 /** Returns the flags to be ignored on output. */
708 inline sal_Int64 getIgnoreFlags() const { return mnIgnore; }
709 /** Sets flags to be ignored on output. */
710 inline void setIgnoreFlags( sal_Int64 nIgnore ) { mnIgnore = nIgnore; }
712 protected:
713 virtual void implProcessConfigItemStr(
714 TextInputStream& rStrm,
715 const OUString& rKey,
716 const OUString& rData );
718 /** Sets the name for the passed key. */
719 virtual void implSetName( sal_Int64 nKey, const OUString& rName );
720 /** Returns the name for the passed key. */
721 virtual OUString implGetName( const Config& rCfg, sal_Int64 nKey ) const;
722 /** Returns the name for the passed double value. */
723 virtual OUString implGetNameDbl( const Config& rCfg, double fValue ) const;
724 /** Inserts all flags from the passed list. */
725 virtual void implIncludeList( const NameListBase& rList );
727 private:
728 sal_Int64 mnIgnore;
731 // ============================================================================
733 class CombiList : public FlagsList
735 public:
736 explicit CombiList( const SharedConfigData& rCfgData );
738 protected:
739 /** Sets the name for the passed key. */
740 virtual void implSetName( sal_Int64 nKey, const OUString& rName );
741 /** Returns the name for the passed key. */
742 virtual OUString implGetName( const Config& rCfg, sal_Int64 nKey ) const;
743 /** Inserts all flags from the passed list. */
744 virtual void implIncludeList( const NameListBase& rList );
746 private:
747 struct ExtItemFormatKey
749 sal_Int64 mnKey;
750 Int64Pair maFilter;
751 inline explicit ExtItemFormatKey( sal_Int64 nKey ) : mnKey( nKey ), maFilter( 0, 0 ) {}
752 bool operator<( const ExtItemFormatKey& rRight ) const;
755 struct ExtItemFormat : public ItemFormat
757 bool mbShiftValue;
758 inline explicit ExtItemFormat() : mbShiftValue( true ) {}
760 typedef ::std::map< ExtItemFormatKey, ExtItemFormat > ExtItemFormatMap;
761 ExtItemFormatMap maFmtMap;
764 // ============================================================================
766 class UnitConverter : public NameListBase
768 public:
769 explicit UnitConverter( const SharedConfigData& rCfgData );
771 inline void setUnitName( const String& rUnitName ) { maUnitName = rUnitName; }
772 inline void setFactor( double fFactor ) { mfFactor = fFactor; }
774 protected:
775 /** Sets the name for the passed key. */
776 virtual void implSetName( sal_Int64 nKey, const OUString& rName );
777 /** Returns the converted value with appended unit name. */
778 virtual OUString implGetName( const Config& rCfg, sal_Int64 nKey ) const;
779 /** Returns the converted value with appended unit name. */
780 virtual OUString implGetNameDbl( const Config& rCfg, double fValue ) const;
781 /** Empty implementation. */
782 virtual void implIncludeList( const NameListBase& rList );
784 private:
785 OUString maUnitName;
786 double mfFactor;
789 // ============================================================================
791 class NameListWrapper
793 public:
794 inline NameListWrapper() {}
795 inline /*implicit*/ NameListWrapper( const OUString& rListName ) : maName( rListName ) {}
796 inline /*implicit*/ NameListWrapper( const sal_Char* pcListName ) : maName( pcListName ) {}
797 inline /*implicit*/ NameListWrapper( const NameListRef& rxList ) : mxList( rxList ) {}
799 inline bool isEmpty() const { return !mxList && !maName.has(); }
800 NameListRef getNameList( const Config& rCfg ) const;
802 private:
803 String maName;
804 mutable NameListRef mxList;
807 static const NameListWrapper NO_LIST;
809 // ============================================================================
811 class ItemFormatMap : public ::std::map< sal_Int64, ItemFormat >
813 public:
814 inline explicit ItemFormatMap() {}
815 inline explicit ItemFormatMap( const NameListRef& rxNameList ) { insertFormats( rxNameList ); }
817 void insertFormats( const NameListRef& rxNameList );
820 // ============================================================================
821 // ============================================================================
823 class SharedConfigData : public Base, public ConfigItemBase
825 public:
826 explicit SharedConfigData(
827 const OUString& rFileName,
828 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
829 const StorageRef& rxRootStrg,
830 const OUString& rSysFileName );
832 virtual ~SharedConfigData();
834 inline const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& getContext() const { return mxContext; }
835 inline const StorageRef& getRootStorage() const { return mxRootStrg; }
836 inline const OUString& getSysFileName() const { return maSysFileName; }
838 void setOption( const OUString& rKey, const OUString& rData );
839 const OUString* getOption( const OUString& rKey ) const;
841 template< typename ListType >
842 ::boost::shared_ptr< ListType > createNameList( const OUString& rListName );
843 void setNameList( const OUString& rListName, const NameListRef& rxList );
844 void eraseNameList( const OUString& rListName );
845 NameListRef getNameList( const OUString& rListName ) const;
847 inline bool isPasswordCancelled() const { return mbPwCancelled; }
849 protected:
850 virtual bool implIsValid() const;
851 virtual void implProcessConfigItemStr(
852 TextInputStream& rStrm,
853 const OUString& rKey,
854 const OUString& rData );
856 private:
857 bool readConfigFile( const OUString& rFileUrl );
858 template< typename ListType >
859 void readNameList( TextInputStream& rStrm, const OUString& rListName );
860 void createShortList( const OUString& rData );
861 void createUnitConverter( const OUString& rData );
863 private:
864 typedef ::std::set< OUString > ConfigFileSet;
865 typedef ::std::map< OUString, OUString > ConfigDataMap;
866 typedef ::std::map< OUString, NameListRef > NameListMap;
868 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > mxContext;
869 StorageRef mxRootStrg;
870 OUString maSysFileName;
871 ConfigFileSet maConfigFiles;
872 ConfigDataMap maConfigData;
873 NameListMap maNameLists;
874 OUString maConfigPath;
875 bool mbLoaded;
876 bool mbPwCancelled;
879 // ----------------------------------------------------------------------------
881 template< typename ListType >
882 ::boost::shared_ptr< ListType > SharedConfigData::createNameList( const OUString& rListName )
884 ::boost::shared_ptr< ListType > xList;
885 if( !rListName.isEmpty() )
887 xList.reset( new ListType( *this ) );
888 setNameList( rListName, xList );
890 return xList;
893 template< typename ListType >
894 void SharedConfigData::readNameList( TextInputStream& rStrm, const OUString& rListName )
896 NameListRef xList = createNameList< ListType >( rListName );
897 if( xList.get() )
898 xList->readConfigBlock( rStrm );
901 // ============================================================================
903 class Config : public Base
905 public:
906 explicit Config( const Config& rParent );
907 explicit Config(
908 const sal_Char* pcEnvVar,
909 const ::oox::core::FilterBase& rFilter );
910 explicit Config(
911 const sal_Char* pcEnvVar,
912 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
913 const StorageRef& rxRootStrg,
914 const OUString& rSysFileName );
916 virtual ~Config();
918 inline const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& getContext() const { return mxCfgData->getContext(); }
919 inline const StorageRef& getRootStorage() const { return mxCfgData->getRootStorage(); }
920 inline const OUString& getSysFileName() const { return mxCfgData->getSysFileName(); }
922 const OUString& getStringOption( const String& rKey, const OUString& rDefault ) const;
923 bool getBoolOption( const String& rKey, bool bDefault ) const;
924 template< typename Type >
925 Type getIntOption( const String& rKey, Type nDefault ) const;
927 bool isDumperEnabled() const;
928 bool isImportEnabled() const;
930 template< typename ListType >
931 ::boost::shared_ptr< ListType > createNameList( const String& rListName );
932 void eraseNameList( const String& rListName );
933 NameListRef getNameList( const String& rListName ) const;
935 /** Returns the name for the passed key from the passed name list. */
936 template< typename Type >
937 OUString getName( const NameListWrapper& rListWrp, Type nKey ) const;
938 /** Returns true, if the passed name list contains an entry for the passed key. */
939 template< typename Type >
940 bool hasName( const NameListWrapper& rListWrp, Type nKey ) const;
942 bool isPasswordCancelled() const;
944 protected:
945 inline explicit Config() {}
946 void construct( const Config& rParent );
947 void construct(
948 const sal_Char* pcEnvVar,
949 const ::oox::core::FilterBase& rFilter );
950 void construct(
951 const sal_Char* pcEnvVar,
952 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
953 const StorageRef& rxRootStrg,
954 const OUString& rSysFileName );
956 virtual bool implIsValid() const;
957 virtual const OUString* implGetOption( const OUString& rKey ) const;
958 virtual NameListRef implGetNameList( const OUString& rListName ) const;
960 private:
961 typedef ::boost::shared_ptr< SharedConfigData > SharedConfigDataRef;
962 SharedConfigDataRef mxCfgData;
965 typedef ::boost::shared_ptr< Config > ConfigRef;
967 // ----------------------------------------------------------------------------
969 template< typename Type >
970 Type Config::getIntOption( const String& rKey, Type nDefault ) const
972 sal_Int64 nRawData;
973 const OUString* pData = implGetOption( rKey );
974 return (pData && StringHelper::convertStringToInt( nRawData, *pData )) ?
975 static_cast< Type >( nRawData ) : nDefault;
978 template< typename ListType >
979 ::boost::shared_ptr< ListType > Config::createNameList( const String& rListName )
981 return mxCfgData->createNameList< ListType >( rListName );
984 template< typename Type >
985 OUString Config::getName( const NameListWrapper& rListWrp, Type nKey ) const
987 NameListRef xList = rListWrp.getNameList( *this );
988 return xList.get() ? xList->getName( *this, nKey ) : OOX_DUMP_ERR_NOMAP;
991 template< typename Type >
992 bool Config::hasName( const NameListWrapper& rListWrp, Type nKey ) const
994 NameListRef xList = rListWrp.getNameList( *this );
995 return xList.get() && xList->hasName( nKey );
998 // ============================================================================
999 // ============================================================================
1001 class Output : public Base
1003 public:
1004 explicit Output(
1005 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
1006 const OUString& rFileName );
1008 // ------------------------------------------------------------------------
1010 void newLine();
1011 void emptyLine( size_t nCount = 1 );
1012 inline OUStringBuffer& getLine() { return maLine; }
1014 void incIndent();
1015 void decIndent();
1017 void startTable( sal_Int32 nW1 );
1018 void startTable( sal_Int32 nW1, sal_Int32 nW2 );
1019 void startTable( sal_Int32 nW1, sal_Int32 nW2, sal_Int32 nW3, sal_Int32 nW4 );
1020 void startTable( size_t nColCount, const sal_Int32* pnColWidths );
1021 void tab();
1022 void tab( size_t nCol );
1023 void endTable();
1025 void resetItemIndex( sal_Int64 nIdx = 0 );
1026 void startItem( const String& rItemName );
1027 void contItem();
1028 void endItem();
1029 inline const OUString& getLastItemValue() const { return maLastItem; }
1031 void startMultiItems();
1032 void endMultiItems();
1034 // ------------------------------------------------------------------------
1036 void writeChar( sal_Unicode cChar, sal_Int32 nCount = 1 );
1037 void writeAscii( const sal_Char* pcStr );
1038 void writeString( const OUString& rStr );
1039 void writeArray( const sal_uInt8* pnData, sal_Size nSize, sal_Unicode cSep = OOX_DUMP_LISTSEP );
1040 void writeBool( bool bData );
1041 void writeDateTime( const ::com::sun::star::util::DateTime& rDateTime );
1043 template< typename Type >
1044 inline void writeDec( Type nData, sal_Int32 nWidth = 0, sal_Unicode cFill = ' ' )
1045 { StringHelper::appendDec( maLine, nData, nWidth, cFill ); }
1046 template< typename Type >
1047 inline void writeHex( Type nData, bool bPrefix = true )
1048 { StringHelper::appendHex( maLine, nData, bPrefix ); }
1049 template< typename Type >
1050 inline void writeShortHex( Type nData, bool bPrefix = true )
1051 { StringHelper::appendShortHex( maLine, nData, bPrefix ); }
1052 template< typename Type >
1053 inline void writeBin( Type nData, bool bDots = true )
1054 { StringHelper::appendBin( maLine, nData, bDots ); }
1055 template< typename Type >
1056 inline void writeFix( Type nData, sal_Int32 nWidth = 0 )
1057 { StringHelper::appendFix( maLine, nData, nWidth ); }
1058 template< typename Type >
1059 inline void writeValue( Type nData, FormatType eFmtType )
1060 { StringHelper::appendValue( maLine, nData, eFmtType ); }
1061 template< typename Type >
1062 inline void writeName( const Config& rCfg, Type nData, const NameListWrapper& rListWrp )
1063 { writeString( rCfg.getName( rListWrp, nData ) ); }
1065 // ------------------------------------------------------------------------
1066 protected:
1067 virtual bool implIsValid() const;
1069 private:
1070 void writeItemName( const String& rItemName );
1072 private:
1073 typedef ::std::vector< sal_Int32 > StringLenVec;
1075 ::com::sun::star::uno::Reference< ::com::sun::star::io::XTextOutputStream2 > mxStrm;
1076 OUString maIndent;
1077 OUStringBuffer maLine;
1078 OUString maLastItem;
1079 StringLenVec maColPos;
1080 size_t mnCol;
1081 size_t mnItemLevel;
1082 size_t mnMultiLevel;
1083 sal_Int64 mnItemIdx;
1084 sal_Int32 mnLastItem;
1087 typedef ::boost::shared_ptr< Output > OutputRef;
1089 // ============================================================================
1091 class IndentGuard
1093 public:
1094 inline explicit IndentGuard( const OutputRef& rxOut ) : mrOut( *rxOut ) { mrOut.incIndent(); }
1095 inline ~IndentGuard() { mrOut.decIndent(); }
1096 private:
1097 IndentGuard( const IndentGuard& );
1098 IndentGuard& operator=( const IndentGuard& );
1099 private:
1100 Output& mrOut;
1103 // ----------------------------------------------------------------------------
1105 class TableGuard
1107 public:
1108 inline explicit TableGuard( const OutputRef& rxOut, sal_Int32 nW1 ) :
1109 mrOut( *rxOut ) { mrOut.startTable( nW1 ); }
1110 inline explicit TableGuard( const OutputRef& rxOut, sal_Int32 nW1, sal_Int32 nW2 ) :
1111 mrOut( *rxOut ) { mrOut.startTable( nW1, nW2 ); }
1112 inline explicit TableGuard( const OutputRef& rxOut, sal_Int32 nW1, sal_Int32 nW2, sal_Int32 nW3, sal_Int32 nW4 ) :
1113 mrOut( *rxOut ) { mrOut.startTable( nW1, nW2, nW3, nW4 ); }
1114 inline explicit TableGuard( const OutputRef& rxOut, size_t nColCount,
1115 const sal_Int32* pnColWidths ) :
1116 mrOut( *rxOut ) { mrOut.startTable( nColCount, pnColWidths ); }
1117 inline ~TableGuard() { mrOut.endTable(); }
1118 inline void tab() { mrOut.tab(); }
1119 inline void tab( size_t nCol ) { mrOut.tab( nCol ); }
1120 private:
1121 TableGuard( const TableGuard& );
1122 TableGuard& operator=( const TableGuard& );
1123 private:
1124 Output& mrOut;
1127 // ----------------------------------------------------------------------------
1129 class ItemGuard
1131 public:
1132 inline explicit ItemGuard( const OutputRef& rxOut, const String& rName = EMPTY_STRING ) :
1133 mrOut( *rxOut ) { mrOut.startItem( rName ); }
1134 inline ~ItemGuard() { mrOut.endItem(); }
1135 inline void cont() { mrOut.contItem(); }
1136 private:
1137 ItemGuard( const ItemGuard& );
1138 ItemGuard& operator=( const ItemGuard& );
1139 private:
1140 Output& mrOut;
1143 // ----------------------------------------------------------------------------
1145 class MultiItemsGuard
1147 public:
1148 inline explicit MultiItemsGuard( const OutputRef& rxOut ) : mrOut( *rxOut ) { mrOut.startMultiItems(); }
1149 inline ~MultiItemsGuard() { mrOut.endMultiItems(); }
1150 private:
1151 MultiItemsGuard( const MultiItemsGuard& );
1152 MultiItemsGuard& operator=( const MultiItemsGuard& );
1153 private:
1154 Output& mrOut;
1157 // ============================================================================
1159 class StorageIterator : public Base
1161 public:
1162 explicit StorageIterator( const StorageRef& rxStrg );
1163 virtual ~StorageIterator();
1165 StorageIterator& operator++();
1167 OUString getName() const;
1168 bool isStream() const;
1169 bool isStorage() const;
1171 private:
1172 virtual bool implIsValid() const;
1174 private:
1175 StorageRef mxStrg;
1176 OUStringVector maNames;
1177 OUStringVector::const_iterator maIt;
1180 // ============================================================================
1181 // ============================================================================
1183 class ObjectBase : public Base
1185 public:
1186 virtual ~ObjectBase();
1188 inline const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&
1189 getContext() const { return mxConfig->getContext(); }
1191 void dump();
1193 // ------------------------------------------------------------------------
1194 protected:
1195 inline explicit ObjectBase() {}
1197 void construct( const ConfigRef& rxConfig );
1198 void construct( const ObjectBase& rParent );
1200 virtual bool implIsValid() const;
1201 virtual void implDump();
1203 // ------------------------------------------------------------------------
1205 inline Config& cfg() const { return *mxConfig; }
1207 private:
1208 ConfigRef mxConfig;
1211 typedef ::boost::shared_ptr< ObjectBase > ObjectRef;
1213 // ============================================================================
1214 // ============================================================================
1216 class StorageObjectBase : public ObjectBase
1218 protected:
1219 inline explicit StorageObjectBase() {}
1221 protected:
1222 using ObjectBase::construct;
1223 void construct( const ObjectBase& rParent, const StorageRef& rxStrg, const OUString& rSysPath );
1224 void construct( const ObjectBase& rParent );
1226 virtual bool implIsValid() const;
1227 virtual void implDump();
1229 virtual void implDumpStream(
1230 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxStrm,
1231 const OUString& rStrgPath,
1232 const OUString& rStrmName,
1233 const OUString& rSysFileName );
1235 virtual void implDumpStorage(
1236 const StorageRef& rxStrg,
1237 const OUString& rStrgPath,
1238 const OUString& rSysPath );
1240 virtual void implDumpBaseStream(
1241 const BinaryInputStreamRef& rxStrm,
1242 const OUString& rSysFileName );
1244 void addPreferredStream( const String& rStrmName );
1245 void addPreferredStorage( const String& rStrgPath );
1247 private:
1248 OUString getSysFileName(
1249 const OUString& rStrmName,
1250 const OUString& rSysOutPath );
1252 void extractStream(
1253 StorageBase& rStrg,
1254 const OUString& rStrgPath,
1255 const OUString& rStrmName,
1256 const OUString& rSysFileName );
1257 void extractStorage(
1258 const StorageRef& rxStrg,
1259 const OUString& rStrgPath,
1260 const OUString& rSysPath );
1262 void extractItem(
1263 const StorageRef& rxStrg,
1264 const OUString& rStrgPath,
1265 const OUString& rItemName,
1266 const OUString& rSysPath,
1267 bool bIsStrg, bool bIsStrm );
1269 private:
1270 struct PreferredItem
1272 OUString maName;
1273 bool mbStorage;
1275 inline explicit PreferredItem( const OUString rName, bool bStorage ) :
1276 maName( rName ), mbStorage( bStorage ) {}
1278 typedef ::std::vector< PreferredItem > PreferredItemVector;
1280 StorageRef mxStrg;
1281 OUString maSysPath;
1282 PreferredItemVector maPreferred;
1285 typedef ::boost::shared_ptr< StorageObjectBase > StorageObjectRef;
1287 // ============================================================================
1288 // ============================================================================
1290 class OutputObjectBase : public ObjectBase
1292 public:
1293 virtual ~OutputObjectBase();
1295 // ------------------------------------------------------------------------
1296 protected:
1297 inline explicit OutputObjectBase() {}
1299 using ObjectBase::construct;
1300 void construct( const ObjectBase& rParent, const OUString& rSysFileName );
1301 void construct( const OutputObjectBase& rParent );
1303 virtual bool implIsValid() const;
1305 // ------------------------------------------------------------------------
1307 void writeEmptyItem( const String& rName );
1308 void writeInfoItem( const String& rName, const String& rData );
1309 void writeCharItem( const String& rName, sal_Unicode cData );
1310 void writeStringItem( const String& rName, const OUString& rData );
1311 void writeArrayItem( const String& rName, const sal_uInt8* pnData, sal_Size nSize, sal_Unicode cSep = OOX_DUMP_LISTSEP );
1312 void writeDateTimeItem( const String& rName, const ::com::sun::star::util::DateTime& rDateTime );
1313 void writeGuidItem( const String& rName, const OUString& rGuid );
1315 template< typename Type >
1316 void addNameToItem( Type nData, const NameListWrapper& rListWrp );
1318 template< typename Type >
1319 void writeNameItem( const String& rName, Type nData, const NameListWrapper& rListWrp );
1320 template< typename Type >
1321 void writeDecItem( const String& rName, Type nData, const NameListWrapper& rListWrp = NO_LIST );
1322 template< typename Type >
1323 void writeHexItem( const String& rName, Type nData, const NameListWrapper& rListWrp = NO_LIST );
1324 template< typename Type >
1325 void writeShortHexItem( const String& rName, Type nData, const NameListWrapper& rListWrp = NO_LIST );
1326 template< typename Type >
1327 void writeBinItem( const String& rName, Type nData, const NameListWrapper& rListWrp = NO_LIST );
1328 template< typename Type >
1329 void writeFixItem( const String& rName, Type nData, const NameListWrapper& rListWrp = NO_LIST );
1330 template< typename Type >
1331 void writeDecBoolItem( const String& rName, Type nData, const NameListWrapper& rListWrp = NO_LIST );
1332 template< typename Type >
1333 void writeValueItem( const String& rName, Type nData, FormatType eFmtType, const NameListWrapper& rListWrp = NO_LIST );
1335 template< typename Type >
1336 void writeValueItem( const ItemFormat& rItemFmt, Type nData );
1338 template< typename Type >
1339 void writeDecPairItem( const String& rName, Type nData1, Type nData2, sal_Unicode cSep = ',' );
1340 template< typename Type >
1341 void writeHexPairItem( const String& rName, Type nData1, Type nData2, sal_Unicode cSep = ',' );
1343 protected:
1344 OutputRef mxOut;
1345 OUString maSysFileName;
1348 typedef ::boost::shared_ptr< OutputObjectBase > OutputObjectRef;
1350 // ----------------------------------------------------------------------------
1352 template< typename Type >
1353 void OutputObjectBase::addNameToItem( Type nData, const NameListWrapper& rListWrp )
1355 if( !rListWrp.isEmpty() )
1357 mxOut->contItem();
1358 mxOut->writeName( cfg(), nData, rListWrp );
1362 template< typename Type >
1363 void OutputObjectBase::writeNameItem( const String& rName, Type nData, const NameListWrapper& rListWrp )
1365 ItemGuard aItem( mxOut, rName );
1366 mxOut->writeName( cfg(), nData, rListWrp );
1369 template< typename Type >
1370 void OutputObjectBase::writeDecItem( const String& rName, Type nData, const NameListWrapper& rListWrp )
1372 ItemGuard aItem( mxOut, rName );
1373 mxOut->writeDec( nData );
1374 addNameToItem( nData, rListWrp );
1377 template< typename Type >
1378 void OutputObjectBase::writeHexItem( const String& rName, Type nData, const NameListWrapper& rListWrp )
1380 ItemGuard aItem( mxOut, rName );
1381 mxOut->writeHex( nData );
1382 addNameToItem( nData, rListWrp );
1385 template< typename Type >
1386 void OutputObjectBase::writeShortHexItem( const String& rName, Type nData, const NameListWrapper& rListWrp )
1388 ItemGuard aItem( mxOut, rName );
1389 mxOut->writeShortHex( nData );
1390 addNameToItem( nData, rListWrp );
1393 template< typename Type >
1394 void OutputObjectBase::writeBinItem( const String& rName, Type nData, const NameListWrapper& rListWrp )
1396 ItemGuard aItem( mxOut, rName );
1397 mxOut->writeBin( nData );
1398 addNameToItem( nData, rListWrp );
1401 template< typename Type >
1402 void OutputObjectBase::writeFixItem( const String& rName, Type nData, const NameListWrapper& rListWrp )
1404 ItemGuard aItem( mxOut, rName );
1405 mxOut->writeFix( nData );
1406 addNameToItem( nData, rListWrp );
1409 template< typename Type >
1410 void OutputObjectBase::writeDecBoolItem( const String& rName, Type nData, const NameListWrapper& rListWrp )
1412 ItemGuard aItem( mxOut, rName );
1413 mxOut->writeDec( nData );
1414 aItem.cont();
1415 mxOut->writeBool( nData != 0 );
1416 addNameToItem( nData, rListWrp );
1419 template< typename Type >
1420 void OutputObjectBase::writeValueItem( const String& rName, Type nData, FormatType eFmtType, const NameListWrapper& rListWrp )
1422 if( eFmtType == FORMATTYPE_BOOL )
1423 writeDecBoolItem( rName, nData, rListWrp );
1424 else
1426 ItemGuard aItem( mxOut, rName );
1427 mxOut->writeValue( nData, eFmtType );
1428 addNameToItem( nData, rListWrp );
1432 template< typename Type >
1433 void OutputObjectBase::writeValueItem( const ItemFormat& rItemFmt, Type nData )
1435 OString aNameUtf8 = StringHelper::convertToUtf8( rItemFmt.maItemName );
1436 writeValueItem( aNameUtf8.getStr(), nData, rItemFmt.meFmtType, rItemFmt.maListName );
1439 template< typename Type >
1440 void OutputObjectBase::writeDecPairItem( const String& rName, Type nData1, Type nData2, sal_Unicode cSep )
1442 ItemGuard aItem( mxOut, rName );
1443 mxOut->writeDec( nData1 );
1444 mxOut->writeChar( cSep );
1445 mxOut->writeDec( nData2 );
1448 template< typename Type >
1449 void OutputObjectBase::writeHexPairItem( const String& rName, Type nData1, Type nData2, sal_Unicode cSep )
1451 ItemGuard aItem( mxOut, rName );
1452 mxOut->writeHex( nData1 );
1453 mxOut->writeChar( cSep );
1454 mxOut->writeHex( nData2 );
1457 // ============================================================================
1458 // ============================================================================
1460 class InputObjectBase : public OutputObjectBase
1462 public:
1463 virtual ~InputObjectBase();
1465 // ------------------------------------------------------------------------
1466 protected:
1467 inline explicit InputObjectBase() {}
1469 using OutputObjectBase::construct;
1470 void construct( const ObjectBase& rParent, const BinaryInputStreamRef& rxStrm, const OUString& rSysFileName );
1471 void construct( const OutputObjectBase& rParent, const BinaryInputStreamRef& rxStrm );
1472 void construct( const InputObjectBase& rParent );
1474 virtual bool implIsValid() const;
1476 // ------------------------------------------------------------------------
1478 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
1479 getXInputStream() const;
1481 // ------------------------------------------------------------------------
1483 void skipBlock( sal_Int64 nBytes, bool bShowSize = true );
1484 void dumpRawBinary( sal_Int64 nBytes, bool bShowOffset = true, bool bStream = false );
1486 void dumpBinary( const String& rName, sal_Int64 nBytes, bool bShowOffset = true );
1487 void dumpRemaining( sal_Int64 nBytes );
1488 void dumpRemainingTo( sal_Int64 nPos );
1489 void dumpRemainingStream();
1491 void dumpArray( const String& rName, sal_Int32 nBytes, sal_Unicode cSep = OOX_DUMP_LISTSEP );
1492 inline void dumpUnused( sal_Int32 nBytes ) { dumpArray( OOX_DUMP_UNUSED, nBytes ); }
1493 inline void dumpUnknown( sal_Int32 nBytes ) { dumpArray( OOX_DUMP_UNKNOWN, nBytes ); }
1495 sal_Unicode dumpUnicode( const String& rName );
1497 OUString dumpCharArray( const String& rName, sal_Int32 nLen, rtl_TextEncoding eTextEnc, bool bHideTrailingNul = false );
1498 OUString dumpUnicodeArray( const String& rName, sal_Int32 nLen, bool bHideTrailingNul = false );
1500 ::com::sun::star::util::DateTime dumpFileTime( const String& rName = EMPTY_STRING );
1501 OUString dumpGuid( const String& rName = EMPTY_STRING );
1503 void dumpItem( const ItemFormat& rItemFmt );
1505 template< typename Type >
1506 Type dumpName( const String& rName, const NameListWrapper& rListWrp );
1507 template< typename Type >
1508 Type dumpDec( const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1509 template< typename Type >
1510 Type dumpHex( const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1511 template< typename Type >
1512 Type dumpBin( const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1513 template< typename Type >
1514 Type dumpFix( const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1515 template< typename Type >
1516 Type dumpBool( const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1517 template< typename Type >
1518 Type dumpValue( const ItemFormat& rItemFmt );
1520 template< typename Type1, typename Type2 >
1521 Type1 dumpName( bool bType1, const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1522 template< typename Type1, typename Type2 >
1523 Type1 dumpDec( bool bType1, const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1524 template< typename Type1, typename Type2 >
1525 Type1 dumpHex( bool bType1, const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1526 template< typename Type1, typename Type2 >
1527 Type1 dumpBin( bool bType1, const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1528 template< typename Type1, typename Type2 >
1529 Type1 dumpFix( bool bType1, const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1530 template< typename Type1, typename Type2 >
1531 Type1 dumpBool( bool bType1, const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1532 template< typename Type1, typename Type2 >
1533 Type1 dumpValue( bool bType1, const ItemFormat& rItemFmt );
1535 template< typename Type >
1536 void dumpDecPair( const String& rName, sal_Unicode cSep = ',' );
1537 template< typename Type >
1538 void dumpHexPair( const String& rName, sal_Unicode cSep = ',' );
1540 protected:
1541 BinaryInputStreamRef mxStrm;
1544 typedef ::boost::shared_ptr< InputObjectBase > InputObjectRef;
1546 // ----------------------------------------------------------------------------
1548 template< typename Type >
1549 Type InputObjectBase::dumpName( const String& rName, const NameListWrapper& rListWrp )
1551 Type nData;
1552 *mxStrm >> nData;
1553 writeNameItem( rName, nData, rListWrp );
1554 return nData;
1557 template< typename Type >
1558 Type InputObjectBase::dumpDec( const String& rName, const NameListWrapper& rListWrp )
1560 Type nData;
1561 *mxStrm >> nData;
1562 writeDecItem( rName, nData, rListWrp );
1563 return nData;
1566 template< typename Type >
1567 Type InputObjectBase::dumpHex( const String& rName, const NameListWrapper& rListWrp )
1569 Type nData;
1570 *mxStrm >> nData;
1571 writeHexItem( rName, nData, rListWrp );
1572 return nData;
1575 template< typename Type >
1576 Type InputObjectBase::dumpBin( const String& rName, const NameListWrapper& rListWrp )
1578 Type nData;
1579 *mxStrm >> nData;
1580 writeBinItem( rName, nData, rListWrp );
1581 return nData;
1584 template< typename Type >
1585 Type InputObjectBase::dumpFix( const String& rName, const NameListWrapper& rListWrp )
1587 Type nData;
1588 *mxStrm >> nData;
1589 writeFixItem( rName, nData, rListWrp );
1590 return nData;
1593 template< typename Type >
1594 Type InputObjectBase::dumpBool( const String& rName, const NameListWrapper& rListWrp )
1596 Type nData;
1597 *mxStrm >> nData;
1598 writeDecBoolItem( rName, nData, rListWrp );
1599 return nData;
1602 template< typename Type >
1603 Type InputObjectBase::dumpValue( const ItemFormat& rItemFmt )
1605 Type nData;
1606 *mxStrm >> nData;
1607 writeValueItem( rItemFmt, nData );
1608 return nData;
1611 template< typename Type1, typename Type2 >
1612 Type1 InputObjectBase::dumpName( bool bType1, const String& rName, const NameListWrapper& rListWrp )
1614 return bType1 ? dumpName< Type1 >( rName, rListWrp ) : static_cast< Type1 >( dumpName< Type2 >( rName, rListWrp ) );
1617 template< typename Type1, typename Type2 >
1618 Type1 InputObjectBase::dumpDec( bool bType1, const String& rName, const NameListWrapper& rListWrp )
1620 return bType1 ? dumpDec< Type1 >( rName, rListWrp ) : static_cast< Type1 >( dumpDec< Type2 >( rName, rListWrp ) );
1623 template< typename Type1, typename Type2 >
1624 Type1 InputObjectBase::dumpHex( bool bType1, const String& rName, const NameListWrapper& rListWrp )
1626 return bType1 ? dumpHex< Type1 >( rName, rListWrp ) : static_cast< Type1 >( dumpHex< Type2 >( rName, rListWrp ) );
1629 template< typename Type1, typename Type2 >
1630 Type1 InputObjectBase::dumpBin( bool bType1, const String& rName, const NameListWrapper& rListWrp )
1632 return bType1 ? dumpBin< Type1 >( rName, rListWrp ) : static_cast< Type1 >( dumpBin< Type2 >( rName, rListWrp ) );
1635 template< typename Type1, typename Type2 >
1636 Type1 InputObjectBase::dumpFix( bool bType1, const String& rName, const NameListWrapper& rListWrp )
1638 return bType1 ? dumpFix< Type1 >( rName, rListWrp ) : static_cast< Type1 >( dumpFix< Type2 >( rName, rListWrp ) );
1641 template< typename Type1, typename Type2 >
1642 Type1 InputObjectBase::dumpBool( bool bType1, const String& rName, const NameListWrapper& rListWrp )
1644 return bType1 ? dumpBool< Type1 >( rName, rListWrp ) : static_cast< Type1 >( dumpBool< Type2 >( rName, rListWrp ) );
1647 template< typename Type1, typename Type2 >
1648 Type1 InputObjectBase::dumpValue( bool bType1, const ItemFormat& rItemFmt )
1650 return bType1 ? dumpValue< Type1 >( rItemFmt ) : static_cast< Type1 >( dumpValue< Type2 >( rItemFmt ) );
1653 template< typename Type >
1654 void InputObjectBase::dumpDecPair( const String& rName, sal_Unicode cSep )
1656 Type nData1, nData2;
1657 *mxStrm >> nData1 >> nData2;
1658 writeDecPairItem( rName, nData1, nData2, cSep );
1661 template< typename Type >
1662 void InputObjectBase::dumpHexPair( const String& rName, sal_Unicode cSep )
1664 Type nData1, nData2;
1665 *mxStrm >> nData1 >> nData2;
1666 writeHexPairItem( rName, nData1, nData2, cSep );
1669 // ============================================================================
1670 // ============================================================================
1672 class BinaryStreamObject : public InputObjectBase
1674 public:
1675 explicit BinaryStreamObject(
1676 const ObjectBase& rParent,
1677 const BinaryInputStreamRef& rxStrm,
1678 const OUString& rSysFileName );
1680 protected:
1681 void dumpBinaryStream( bool bShowOffset = true );
1683 virtual void implDump();
1686 // ============================================================================
1687 // ============================================================================
1689 class TextStreamObjectBase : public InputObjectBase
1691 protected:
1692 inline TextStreamObjectBase() {}
1694 using InputObjectBase::construct;
1695 void construct(
1696 const ObjectBase& rParent,
1697 const BinaryInputStreamRef& rxStrm,
1698 rtl_TextEncoding eTextEnc,
1699 const OUString& rSysFileName );
1700 void construct(
1701 const OutputObjectBase& rParent,
1702 const BinaryInputStreamRef& rxStrm,
1703 rtl_TextEncoding eTextEnc );
1705 virtual bool implIsValid() const;
1706 virtual void implDump();
1708 virtual void implDumpText( TextInputStream& rTextStrm ) = 0;
1710 private:
1711 void constructTextStrmObj( rtl_TextEncoding eTextEnc );
1713 protected:
1714 ::boost::shared_ptr< TextInputStream > mxTextStrm;
1717 // ============================================================================
1719 class TextLineStreamObject : public TextStreamObjectBase
1721 public:
1722 explicit TextLineStreamObject(
1723 const ObjectBase& rParent,
1724 const BinaryInputStreamRef& rxStrm,
1725 rtl_TextEncoding eTextEnc,
1726 const OUString& rSysFileName );
1728 explicit TextLineStreamObject(
1729 const OutputObjectBase& rParent,
1730 const BinaryInputStreamRef& rxStrm,
1731 rtl_TextEncoding eTextEnc );
1733 protected:
1734 virtual void implDumpText( TextInputStream& rTextStrm );
1735 virtual void implDumpLine( const OUString& rLine, sal_uInt32 nLine );
1738 // ============================================================================
1740 class XmlStreamObject : public TextStreamObjectBase
1742 public:
1743 explicit XmlStreamObject(
1744 const ObjectBase& rParent,
1745 const BinaryInputStreamRef& rxStrm,
1746 const OUString& rSysFileName );
1748 protected:
1749 virtual void implDumpText( TextInputStream& rTextStrm );
1752 // ============================================================================
1753 // ============================================================================
1755 class RecordObjectBase : public InputObjectBase
1757 protected:
1758 inline explicit RecordObjectBase() {}
1760 using InputObjectBase::construct;
1761 void construct(
1762 const ObjectBase& rParent,
1763 const BinaryInputStreamRef& rxBaseStrm,
1764 const OUString& rSysFileName,
1765 const BinaryInputStreamRef& rxRecStrm,
1766 const String& rRecNames,
1767 const String& rSimpleRecs = EMPTY_STRING );
1769 inline sal_Int64 getRecPos() const { return mnRecPos; }
1770 inline sal_Int64 getRecId() const { return mnRecId; }
1771 inline sal_Int64 getRecSize() const { return mnRecSize; }
1772 inline NameListRef getRecNames() const { return maRecNames.getNameList( cfg() ); }
1774 inline void setBinaryOnlyMode( bool bBinaryOnly ) { mbBinaryOnly = bBinaryOnly; }
1775 inline bool isBinaryOnlyMode() const { return mbBinaryOnly; }
1777 virtual bool implIsValid() const;
1778 virtual void implDump();
1780 virtual bool implStartRecord( BinaryInputStream& rBaseStrm, sal_Int64& ornRecPos, sal_Int64& ornRecId, sal_Int64& ornRecSize ) = 0;
1781 virtual void implWriteExtHeader();
1782 virtual void implDumpRecordBody();
1784 private:
1785 void constructRecObjBase(
1786 const BinaryInputStreamRef& rxBaseStrm,
1787 const String& rRecNames,
1788 const String& rSimpleRecs );
1790 void writeHeader();
1792 private:
1793 BinaryInputStreamRef mxBaseStrm;
1794 NameListWrapper maRecNames;
1795 NameListWrapper maSimpleRecs;
1796 sal_Int64 mnRecPos;
1797 sal_Int64 mnRecId;
1798 sal_Int64 mnRecSize;
1799 bool mbShowRecPos;
1800 bool mbBinaryOnly;
1803 // ============================================================================
1805 class SequenceRecordObjectBase : public RecordObjectBase
1807 protected:
1808 inline explicit SequenceRecordObjectBase() : mxRecData( new StreamDataSequence ) {}
1810 inline StreamDataSequence& getRecordDataSequence() { return *mxRecData; }
1812 using RecordObjectBase::construct;
1813 void construct(
1814 const ObjectBase& rParent,
1815 const BinaryInputStreamRef& rxBaseStrm,
1816 const OUString& rSysFileName,
1817 const String& rRecNames,
1818 const String& rSimpleRecs = EMPTY_STRING );
1820 virtual bool implStartRecord( BinaryInputStream& rBaseStrm, sal_Int64& ornRecPos, sal_Int64& ornRecId, sal_Int64& ornRecSize );
1821 virtual bool implReadRecordHeader( BinaryInputStream& rBaseStrm, sal_Int64& ornRecId, sal_Int64& ornRecSize ) = 0;
1823 private:
1824 typedef ::boost::shared_ptr< StreamDataSequence > StreamDataSeqRef;
1825 StreamDataSeqRef mxRecData;
1828 // ============================================================================
1829 // ============================================================================
1831 /** Base class for a file dumper. Derived classes implement the implDump()
1832 function to add functionality.
1834 class DumperBase : public ObjectBase
1836 public:
1837 virtual ~DumperBase();
1839 bool isImportEnabled() const;
1840 bool isImportCancelled() const;
1842 protected:
1843 inline explicit DumperBase() {}
1845 using ObjectBase::construct;
1846 void construct( const ConfigRef& rxConfig );
1849 // ============================================================================
1850 // ============================================================================
1852 } // namespace dump
1853 } // namespace oox
1855 #define OOX_DUMP_FILE( DumperClassName ) \
1856 do { \
1857 DumperClassName aDumper( *this ); \
1858 aDumper.dump(); \
1859 bool bCancelled = aDumper.isImportCancelled(); \
1860 if( !aDumper.isImportEnabled() || bCancelled ) \
1861 return aDumper.isValid() && !bCancelled; \
1862 } while( false )
1864 #else // OOX_INCLUDE_DUMPER
1866 #define OOX_DUMP_FILE( DumperClassName ) (void)0
1868 #endif // OOX_INCLUDE_DUMPER
1869 #endif
1871 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */