update emoji autocorrect entries from po-files
[LibreOffice.git] / include / oox / dump / dumperbase.hxx
blobd637ddf754ffc92911797a2c1f875d67546ec782
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 INCLUDED_OOX_DUMP_DUMPERBASE_HXX
21 #define INCLUDED_OOX_DUMP_DUMPERBASE_HXX
23 #include <math.h>
24 #include <vector>
25 #include <stack>
26 #include <set>
27 #include <map>
28 #include <memory>
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 {
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;
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 );
142 class BinaryInputStreamRef : public ::oox::BinaryInputStreamRef
144 public:
145 BinaryInputStreamRef() {}
147 /*implicit*/ BinaryInputStreamRef( BinaryInputStream* pInStrm ) :
148 ::oox::BinaryInputStreamRef( pInStrm ) {}
150 /*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 /*implicit*/ BinaryInputStreamRef( const std::shared_ptr< StreamType >& rxInStrm ) :
155 ::oox::BinaryInputStreamRef( rxInStrm ) {}
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.
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').
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 );
255 struct Address
257 sal_Int32 mnCol;
258 sal_Int32 mnRow;
259 Address() : mnCol( 0 ), mnRow( 0 ) {}
260 explicit Address( sal_Int32 nCol, sal_Int32 nRow ) : mnCol( nCol ), mnRow( nRow ) {}
265 struct Range
267 Address maFirst;
268 Address maLast;
269 Range() {}
274 typedef ::std::vector< Range > RangeList;
278 struct TokenAddress : public Address
280 bool mbRelCol;
281 bool mbRelRow;
282 TokenAddress() : mbRelCol( false ), mbRelRow( false ) {}
287 struct TokenRange
289 TokenAddress maFirst;
290 TokenAddress maLast;
291 TokenRange() {}
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 );
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:;
432 class String : public OUString
434 public:
435 String() {}
436 /*implicit*/ String( const OUString& rStr ) : OUString( rStr ) {}
437 /*implicit*/ String( const sal_Char* pcStr ) : OUString( OUString::createFromAscii( pcStr ? pcStr : "" ) ) {}
438 /*implicit*/ String( sal_Unicode cChar ) : OUString( cChar ) {}
440 bool has() const { return getLength() > 0; }
441 OUString operator()( const sal_Char* pcDefault ) const { if( has() ) return *this; return String( pcDefault ); }
444 static const String EMPTY_STRING;
449 class Base;
450 typedef std::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 bool isValid() const { return implIsValid(); }
507 static bool isValid( const BaseRef& rxBase ) { return rxBase.get() && rxBase->isValid(); }
509 protected:
510 Base() {}
512 virtual bool implIsValid() const = 0;
518 class ConfigItemBase
520 public:
521 virtual ~ConfigItemBase();
522 void readConfigBlock( TextInputStream& rStrm );
524 protected:
525 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 static LineType readConfigLine(
544 TextInputStream& rStrm,
545 OUString& orKey,
546 OUString& orData );
548 void processConfigItem(
549 TextInputStream& rStrm,
550 const OUString& rKey,
551 const OUString& rData );
556 class SharedConfigData;
557 class Config;
559 class NameListBase;
560 typedef std::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 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 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 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 const_iterator begin() const { return maMap.begin(); }
601 /** Returns a map iterator pointing one past the last contained name. */
602 const_iterator end() const { return maMap.end(); }
604 protected:
605 explicit NameListBase( const SharedConfigData& rCfgData ) : mrCfgData( rCfgData ) {}
607 virtual bool implIsValid() const SAL_OVERRIDE;
609 virtual void implProcessConfigItemStr(
610 TextInputStream& rStrm,
611 const OUString& rKey,
612 const OUString& rData ) SAL_OVERRIDE;
614 virtual void implProcessConfigItemInt(
615 TextInputStream& rStrm,
616 sal_Int64 nKey,
617 const OUString& rData ) SAL_OVERRIDE;
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;
646 class ConstList : public NameListBase
648 public:
649 explicit ConstList( const SharedConfigData& rCfgData );
651 /** Sets a default name for unknown keys. */
652 void setDefaultName( const String& rDefName ) { maDefName = rDefName; }
653 /** Enables or disables automatic quotation of returned names. */
654 void setQuoteNames( bool bQuoteNames ) { mbQuoteNames = bQuoteNames; }
656 protected:
657 virtual void implProcessConfigItemStr(
658 TextInputStream& rStrm,
659 const OUString& rKey,
660 const OUString& rData ) SAL_OVERRIDE;
662 /** Sets the name for the passed key. */
663 virtual void implSetName( sal_Int64 nKey, const OUString& rName ) SAL_OVERRIDE;
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 SAL_OVERRIDE;
666 /** Returns the name for the passed double value. */
667 virtual OUString implGetNameDbl( const Config& rCfg, double fValue ) const SAL_OVERRIDE;
668 /** Inserts all names from the passed list. */
669 virtual void implIncludeList( const NameListBase& rList ) SAL_OVERRIDE;
671 private:
672 OUString maDefName;
673 bool mbQuoteNames;
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 ) SAL_OVERRIDE;
691 virtual void implSetName( sal_Int64 nKey, const OUString& rName ) SAL_OVERRIDE;
693 private:
694 void insertNames( sal_Int64 nStartKey, const OUString& rData );
696 private:
697 bool mbIgnoreEmpty;
702 class FlagsList : public NameListBase
704 public:
705 explicit FlagsList( const SharedConfigData& rCfgData );
707 /** Returns the flags to be ignored on output. */
708 sal_Int64 getIgnoreFlags() const { return mnIgnore; }
709 /** Sets flags to be ignored on output. */
710 void setIgnoreFlags( sal_Int64 nIgnore ) { mnIgnore = nIgnore; }
712 protected:
713 virtual void implProcessConfigItemStr(
714 TextInputStream& rStrm,
715 const OUString& rKey,
716 const OUString& rData ) SAL_OVERRIDE;
718 /** Sets the name for the passed key. */
719 virtual void implSetName( sal_Int64 nKey, const OUString& rName ) SAL_OVERRIDE;
720 /** Returns the name for the passed key. */
721 virtual OUString implGetName( const Config& rCfg, sal_Int64 nKey ) const SAL_OVERRIDE;
722 /** Returns the name for the passed double value. */
723 virtual OUString implGetNameDbl( const Config& rCfg, double fValue ) const SAL_OVERRIDE;
724 /** Inserts all flags from the passed list. */
725 virtual void implIncludeList( const NameListBase& rList ) SAL_OVERRIDE;
727 private:
728 sal_Int64 mnIgnore;
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 ) SAL_OVERRIDE;
741 /** Returns the name for the passed key. */
742 virtual OUString implGetName( const Config& rCfg, sal_Int64 nKey ) const SAL_OVERRIDE;
743 /** Inserts all flags from the passed list. */
744 virtual void implIncludeList( const NameListBase& rList ) SAL_OVERRIDE;
746 private:
747 struct ExtItemFormatKey
749 sal_Int64 mnKey;
750 Int64Pair maFilter;
751 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 ExtItemFormat() : mbShiftValue( true ) {}
760 typedef ::std::map< ExtItemFormatKey, ExtItemFormat > ExtItemFormatMap;
761 ExtItemFormatMap maFmtMap;
766 class UnitConverter : public NameListBase
768 public:
769 explicit UnitConverter( const SharedConfigData& rCfgData );
771 void setUnitName( const String& rUnitName ) { maUnitName = rUnitName; }
772 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 ) SAL_OVERRIDE;
777 /** Returns the converted value with appended unit name. */
778 virtual OUString implGetName( const Config& rCfg, sal_Int64 nKey ) const SAL_OVERRIDE;
779 /** Returns the converted value with appended unit name. */
780 virtual OUString implGetNameDbl( const Config& rCfg, double fValue ) const SAL_OVERRIDE;
781 /** Empty implementation. */
782 virtual void implIncludeList( const NameListBase& rList ) SAL_OVERRIDE;
784 private:
785 OUString maUnitName;
786 double mfFactor;
791 class NameListWrapper
793 public:
794 NameListWrapper() {}
795 /*implicit*/ NameListWrapper( const OUString& rListName ) : maName( rListName ) {}
796 /*implicit*/ NameListWrapper( const sal_Char* pcListName ) : maName( pcListName ) {}
797 /*implicit*/ NameListWrapper( const NameListRef& rxList ) : mxList( rxList ) {}
799 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;
811 class ItemFormatMap
813 private:
814 ::std::map< sal_Int64, ItemFormat > maMap;
816 public:
817 ItemFormatMap() : maMap() {}
818 explicit ItemFormatMap( const NameListRef& rxNameList ) { insertFormats( rxNameList ); }
820 ::std::map< sal_Int64, ItemFormat >::const_iterator end() const { return maMap.end(); }
821 ::std::map< sal_Int64, ItemFormat >::const_iterator find(sal_Int64 nId) const
823 return maMap.find(nId);
826 void insertFormats( const NameListRef& rxNameList );
832 class SharedConfigData : public Base, public ConfigItemBase
834 public:
835 explicit SharedConfigData(
836 const OUString& rFileName,
837 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
838 const StorageRef& rxRootStrg,
839 const OUString& rSysFileName );
841 virtual ~SharedConfigData();
843 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& getContext() const { return mxContext; }
844 const StorageRef& getRootStorage() const { return mxRootStrg; }
845 const OUString& getSysFileName() const { return maSysFileName; }
847 void setOption( const OUString& rKey, const OUString& rData );
848 const OUString* getOption( const OUString& rKey ) const;
850 template< typename ListType >
851 std::shared_ptr< ListType > createNameList( const OUString& rListName );
852 void setNameList( const OUString& rListName, const NameListRef& rxList );
853 void eraseNameList( const OUString& rListName );
854 NameListRef getNameList( const OUString& rListName ) const;
856 bool isPasswordCancelled() const { return mbPwCancelled; }
858 protected:
859 virtual bool implIsValid() const SAL_OVERRIDE;
860 virtual void implProcessConfigItemStr(
861 TextInputStream& rStrm,
862 const OUString& rKey,
863 const OUString& rData ) SAL_OVERRIDE;
865 private:
866 bool readConfigFile( const OUString& rFileUrl );
867 template< typename ListType >
868 void readNameList( TextInputStream& rStrm, const OUString& rListName );
869 void createShortList( const OUString& rData );
870 void createUnitConverter( const OUString& rData );
872 private:
873 typedef ::std::set< OUString > ConfigFileSet;
874 typedef ::std::map< OUString, OUString > ConfigDataMap;
875 typedef ::std::map< OUString, NameListRef > NameListMap;
877 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > mxContext;
878 StorageRef mxRootStrg;
879 OUString maSysFileName;
880 ConfigFileSet maConfigFiles;
881 ConfigDataMap maConfigData;
882 NameListMap maNameLists;
883 OUString maConfigPath;
884 bool mbLoaded;
885 bool mbPwCancelled;
890 template< typename ListType >
891 std::shared_ptr< ListType > SharedConfigData::createNameList( const OUString& rListName )
893 std::shared_ptr< ListType > xList;
894 if( !rListName.isEmpty() )
896 xList.reset( new ListType( *this ) );
897 setNameList( rListName, xList );
899 return xList;
902 template< typename ListType >
903 void SharedConfigData::readNameList( TextInputStream& rStrm, const OUString& rListName )
905 NameListRef xList = createNameList< ListType >( rListName );
906 if( xList.get() )
907 xList->readConfigBlock( rStrm );
912 class Config : public Base
914 public:
915 explicit Config( const Config& rParent );
916 explicit Config(
917 const sal_Char* pcEnvVar,
918 const ::oox::core::FilterBase& rFilter );
919 explicit Config(
920 const sal_Char* pcEnvVar,
921 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
922 const StorageRef& rxRootStrg,
923 const OUString& rSysFileName );
925 virtual ~Config();
927 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& getContext() const { return mxCfgData->getContext(); }
928 const StorageRef& getRootStorage() const { return mxCfgData->getRootStorage(); }
929 const OUString& getSysFileName() const { return mxCfgData->getSysFileName(); }
931 const OUString& getStringOption( const String& rKey, const OUString& rDefault ) const;
932 bool getBoolOption( const String& rKey, bool bDefault ) const;
933 template< typename Type >
934 Type getIntOption( const String& rKey, Type nDefault ) const;
936 bool isDumperEnabled() const;
937 bool isImportEnabled() const;
939 template< typename ListType >
940 std::shared_ptr< ListType > createNameList( const String& rListName );
941 void eraseNameList( const String& rListName );
942 NameListRef getNameList( const String& rListName ) const;
944 /** Returns the name for the passed key from the passed name list. */
945 template< typename Type >
946 OUString getName( const NameListWrapper& rListWrp, Type nKey ) const;
947 /** Returns true, if the passed name list contains an entry for the passed key. */
948 template< typename Type >
949 bool hasName( const NameListWrapper& rListWrp, Type nKey ) const;
951 bool isPasswordCancelled() const;
953 protected:
954 Config() {}
955 void construct( const Config& rParent );
956 void construct(
957 const sal_Char* pcEnvVar,
958 const ::oox::core::FilterBase& rFilter );
959 void construct(
960 const sal_Char* pcEnvVar,
961 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
962 const StorageRef& rxRootStrg,
963 const OUString& rSysFileName );
965 virtual bool implIsValid() const SAL_OVERRIDE;
966 const OUString* implGetOption( const OUString& rKey ) const;
967 NameListRef implGetNameList( const OUString& rListName ) const;
969 private:
970 typedef std::shared_ptr< SharedConfigData > SharedConfigDataRef;
971 SharedConfigDataRef mxCfgData;
974 typedef std::shared_ptr< Config > ConfigRef;
978 template< typename Type >
979 Type Config::getIntOption( const String& rKey, Type nDefault ) const
981 sal_Int64 nRawData;
982 const OUString* pData = implGetOption( rKey );
983 return (pData && StringHelper::convertStringToInt( nRawData, *pData )) ?
984 static_cast< Type >( nRawData ) : nDefault;
987 template< typename ListType >
988 std::shared_ptr< ListType > Config::createNameList( const String& rListName )
990 return mxCfgData->createNameList< ListType >( rListName );
993 template< typename Type >
994 OUString Config::getName( const NameListWrapper& rListWrp, Type nKey ) const
996 NameListRef xList = rListWrp.getNameList( *this );
997 return xList.get() ? xList->getName( *this, nKey ) : OOX_DUMP_ERR_NOMAP;
1000 template< typename Type >
1001 bool Config::hasName( const NameListWrapper& rListWrp, Type nKey ) const
1003 NameListRef xList = rListWrp.getNameList( *this );
1004 return xList.get() && xList->hasName( nKey );
1010 class Output : public Base
1012 public:
1013 explicit Output(
1014 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
1015 const OUString& rFileName );
1019 void newLine();
1020 void emptyLine( size_t nCount = 1 );
1021 OUStringBuffer& getLine() { return maLine; }
1023 void incIndent();
1024 void decIndent();
1026 void startTable( sal_Int32 nW1 );
1027 void startTable( sal_Int32 nW1, sal_Int32 nW2 );
1028 void startTable( sal_Int32 nW1, sal_Int32 nW2, sal_Int32 nW3, sal_Int32 nW4 );
1029 void startTable( size_t nColCount, const sal_Int32* pnColWidths );
1030 void tab();
1031 void tab( size_t nCol );
1032 void endTable();
1034 void resetItemIndex( sal_Int64 nIdx = 0 );
1035 void startItem( const String& rItemName );
1036 void contItem();
1037 void endItem();
1038 const OUString& getLastItemValue() const { return maLastItem; }
1040 void startMultiItems();
1041 void endMultiItems();
1045 void writeChar( sal_Unicode cChar, sal_Int32 nCount = 1 );
1046 void writeAscii( const sal_Char* pcStr );
1047 void writeString( const OUString& rStr );
1048 void writeArray( const sal_uInt8* pnData, sal_Size nSize, sal_Unicode cSep = OOX_DUMP_LISTSEP );
1049 void writeBool( bool bData );
1050 void writeDateTime( const ::com::sun::star::util::DateTime& rDateTime );
1052 template< typename Type >
1053 void writeDec( Type nData, sal_Int32 nWidth = 0, sal_Unicode cFill = ' ' )
1054 { StringHelper::appendDec( maLine, nData, nWidth, cFill ); }
1055 template< typename Type >
1056 void writeHex( Type nData, bool bPrefix = true )
1057 { StringHelper::appendHex( maLine, nData, bPrefix ); }
1058 template< typename Type >
1059 void writeShortHex( Type nData, bool bPrefix = true )
1060 { StringHelper::appendShortHex( maLine, nData, bPrefix ); }
1061 template< typename Type >
1062 void writeBin( Type nData, bool bDots = true )
1063 { StringHelper::appendBin( maLine, nData, bDots ); }
1064 template< typename Type >
1065 void writeFix( Type nData, sal_Int32 nWidth = 0 )
1066 { StringHelper::appendFix( maLine, nData, nWidth ); }
1067 template< typename Type >
1068 void writeValue( Type nData, FormatType eFmtType )
1069 { StringHelper::appendValue( maLine, nData, eFmtType ); }
1070 template< typename Type >
1071 void writeName( const Config& rCfg, Type nData, const NameListWrapper& rListWrp )
1072 { writeString( rCfg.getName( rListWrp, nData ) ); }
1075 protected:
1076 virtual bool implIsValid() const SAL_OVERRIDE;
1078 private:
1079 void writeItemName( const String& rItemName );
1081 private:
1082 typedef ::std::vector< sal_Int32 > StringLenVec;
1084 ::com::sun::star::uno::Reference< ::com::sun::star::io::XTextOutputStream2 > mxStrm;
1085 OUString maIndent;
1086 OUStringBuffer maLine;
1087 OUString maLastItem;
1088 StringLenVec maColPos;
1089 size_t mnCol;
1090 size_t mnItemLevel;
1091 size_t mnMultiLevel;
1092 sal_Int64 mnItemIdx;
1093 sal_Int32 mnLastItem;
1096 typedef std::shared_ptr< Output > OutputRef;
1100 class IndentGuard
1102 public:
1103 explicit IndentGuard( const OutputRef& rxOut ) : mrOut( *rxOut ) { mrOut.incIndent(); }
1104 ~IndentGuard() { mrOut.decIndent(); }
1105 private:
1106 IndentGuard( const IndentGuard& ) SAL_DELETED_FUNCTION;
1107 IndentGuard& operator=( const IndentGuard& ) SAL_DELETED_FUNCTION;
1108 private:
1109 Output& mrOut;
1114 class TableGuard
1116 public:
1117 explicit TableGuard( const OutputRef& rxOut, sal_Int32 nW1 ) :
1118 mrOut( *rxOut ) { mrOut.startTable( nW1 ); }
1119 explicit TableGuard( const OutputRef& rxOut, sal_Int32 nW1, sal_Int32 nW2 ) :
1120 mrOut( *rxOut ) { mrOut.startTable( nW1, nW2 ); }
1121 explicit TableGuard( const OutputRef& rxOut, sal_Int32 nW1, sal_Int32 nW2, sal_Int32 nW3, sal_Int32 nW4 ) :
1122 mrOut( *rxOut ) { mrOut.startTable( nW1, nW2, nW3, nW4 ); }
1123 explicit TableGuard( const OutputRef& rxOut, size_t nColCount,
1124 const sal_Int32* pnColWidths ) :
1125 mrOut( *rxOut ) { mrOut.startTable( nColCount, pnColWidths ); }
1126 ~TableGuard() { mrOut.endTable(); }
1127 void tab() { mrOut.tab(); }
1128 void tab( size_t nCol ) { mrOut.tab( nCol ); }
1129 private:
1130 TableGuard( const TableGuard& ) SAL_DELETED_FUNCTION;
1131 TableGuard& operator=( const TableGuard& ) SAL_DELETED_FUNCTION;
1132 private:
1133 Output& mrOut;
1138 class ItemGuard
1140 public:
1141 explicit ItemGuard( const OutputRef& rxOut, const String& rName = EMPTY_STRING ) :
1142 mrOut( *rxOut ) { mrOut.startItem( rName ); }
1143 ~ItemGuard() { mrOut.endItem(); }
1144 void cont() { mrOut.contItem(); }
1145 private:
1146 ItemGuard( const ItemGuard& ) SAL_DELETED_FUNCTION;
1147 ItemGuard& operator=( const ItemGuard& ) SAL_DELETED_FUNCTION;
1148 private:
1149 Output& mrOut;
1154 class MultiItemsGuard
1156 public:
1157 explicit MultiItemsGuard( const OutputRef& rxOut ) : mrOut( *rxOut ) { mrOut.startMultiItems(); }
1158 ~MultiItemsGuard() { mrOut.endMultiItems(); }
1159 private:
1160 MultiItemsGuard( const MultiItemsGuard& ) SAL_DELETED_FUNCTION;
1161 MultiItemsGuard& operator=( const MultiItemsGuard& ) SAL_DELETED_FUNCTION;
1162 private:
1163 Output& mrOut;
1168 class StorageIterator : public Base
1170 public:
1171 explicit StorageIterator( const StorageRef& rxStrg );
1172 virtual ~StorageIterator();
1174 StorageIterator& operator++();
1176 OUString getName() const;
1177 bool isStream() const;
1178 bool isStorage() const;
1180 private:
1181 virtual bool implIsValid() const SAL_OVERRIDE;
1183 private:
1184 StorageRef mxStrg;
1185 OUStringVector maNames;
1186 OUStringVector::const_iterator maIt;
1192 class ObjectBase : public Base
1194 public:
1195 virtual ~ObjectBase();
1197 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&
1198 getContext() const { return mxConfig->getContext(); }
1200 void dump();
1203 protected:
1204 ObjectBase() {}
1206 void construct( const ConfigRef& rxConfig );
1207 void construct( const ObjectBase& rParent );
1209 virtual bool implIsValid() const SAL_OVERRIDE;
1210 virtual void implDump();
1214 Config& cfg() const { return *mxConfig; }
1216 private:
1217 ConfigRef mxConfig;
1220 typedef std::shared_ptr< ObjectBase > ObjectRef;
1225 class StorageObjectBase : public ObjectBase
1227 protected:
1228 StorageObjectBase() {}
1230 protected:
1231 using ObjectBase::construct;
1232 void construct( const ObjectBase& rParent, const StorageRef& rxStrg, const OUString& rSysPath );
1233 void construct( const ObjectBase& rParent );
1235 virtual bool implIsValid() const SAL_OVERRIDE;
1236 virtual void implDump() SAL_OVERRIDE;
1238 virtual void implDumpStream(
1239 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxStrm,
1240 const OUString& rStrgPath,
1241 const OUString& rStrmName,
1242 const OUString& rSysFileName );
1244 virtual void implDumpStorage(
1245 const StorageRef& rxStrg,
1246 const OUString& rStrgPath,
1247 const OUString& rSysPath );
1249 virtual void implDumpBaseStream(
1250 const BinaryInputStreamRef& rxStrm,
1251 const OUString& rSysFileName );
1253 void addPreferredStream( const String& rStrmName );
1254 void addPreferredStorage( const String& rStrgPath );
1256 private:
1257 static OUString getSysFileName(
1258 const OUString& rStrmName,
1259 const OUString& rSysOutPath );
1261 void extractStream(
1262 StorageBase& rStrg,
1263 const OUString& rStrgPath,
1264 const OUString& rStrmName,
1265 const OUString& rSysFileName );
1266 void extractStorage(
1267 const StorageRef& rxStrg,
1268 const OUString& rStrgPath,
1269 const OUString& rSysPath );
1271 void extractItem(
1272 const StorageRef& rxStrg,
1273 const OUString& rStrgPath,
1274 const OUString& rItemName,
1275 const OUString& rSysPath,
1276 bool bIsStrg, bool bIsStrm );
1278 private:
1279 struct PreferredItem
1281 OUString maName;
1282 bool mbStorage;
1284 explicit PreferredItem( const OUString& rName, bool bStorage ) :
1285 maName( rName ), mbStorage( bStorage ) {}
1287 typedef ::std::vector< PreferredItem > PreferredItemVector;
1289 StorageRef mxStrg;
1290 OUString maSysPath;
1291 PreferredItemVector maPreferred;
1298 class OutputObjectBase : public ObjectBase
1300 public:
1301 virtual ~OutputObjectBase();
1304 protected:
1305 OutputObjectBase() {}
1307 using ObjectBase::construct;
1308 void construct( const ObjectBase& rParent, const OUString& rSysFileName );
1309 void construct( const OutputObjectBase& rParent );
1311 virtual bool implIsValid() const SAL_OVERRIDE;
1315 void writeEmptyItem( const String& rName );
1316 void writeInfoItem( const String& rName, const String& rData );
1317 void writeCharItem( const String& rName, sal_Unicode cData );
1318 void writeStringItem( const String& rName, const OUString& rData );
1319 void writeArrayItem( const String& rName, const sal_uInt8* pnData, sal_Size nSize, sal_Unicode cSep = OOX_DUMP_LISTSEP );
1320 void writeDateTimeItem( const String& rName, const ::com::sun::star::util::DateTime& rDateTime );
1321 void writeGuidItem( const String& rName, const OUString& rGuid );
1323 template< typename Type >
1324 void addNameToItem( Type nData, const NameListWrapper& rListWrp );
1326 template< typename Type >
1327 void writeNameItem( const String& rName, Type nData, const NameListWrapper& rListWrp );
1328 template< typename Type >
1329 void writeDecItem( const String& rName, Type nData, const NameListWrapper& rListWrp = NO_LIST );
1330 template< typename Type >
1331 void writeHexItem( const String& rName, Type nData, const NameListWrapper& rListWrp = NO_LIST );
1332 template< typename Type >
1333 void writeShortHexItem( const String& rName, Type nData, const NameListWrapper& rListWrp = NO_LIST );
1334 template< typename Type >
1335 void writeBinItem( const String& rName, Type nData, const NameListWrapper& rListWrp = NO_LIST );
1336 template< typename Type >
1337 void writeFixItem( const String& rName, Type nData, const NameListWrapper& rListWrp = NO_LIST );
1338 template< typename Type >
1339 void writeDecBoolItem( const String& rName, Type nData, const NameListWrapper& rListWrp = NO_LIST );
1340 template< typename Type >
1341 void writeValueItem( const String& rName, Type nData, FormatType eFmtType, const NameListWrapper& rListWrp = NO_LIST );
1343 template< typename Type >
1344 void writeValueItem( const ItemFormat& rItemFmt, Type nData );
1346 template< typename Type >
1347 void writeDecPairItem( const String& rName, Type nData1, Type nData2, sal_Unicode cSep = ',' );
1348 template< typename Type >
1349 void writeHexPairItem( const String& rName, Type nData1, Type nData2, sal_Unicode cSep = ',' );
1351 protected:
1352 OutputRef mxOut;
1353 OUString maSysFileName;
1359 template< typename Type >
1360 void OutputObjectBase::addNameToItem( Type nData, const NameListWrapper& rListWrp )
1362 if( !rListWrp.isEmpty() )
1364 mxOut->contItem();
1365 mxOut->writeName( cfg(), nData, rListWrp );
1369 template< typename Type >
1370 void OutputObjectBase::writeNameItem( const String& rName, Type nData, const NameListWrapper& rListWrp )
1372 ItemGuard aItem( mxOut, rName );
1373 mxOut->writeName( cfg(), nData, rListWrp );
1376 template< typename Type >
1377 void OutputObjectBase::writeDecItem( const String& rName, Type nData, const NameListWrapper& rListWrp )
1379 ItemGuard aItem( mxOut, rName );
1380 mxOut->writeDec( nData );
1381 addNameToItem( nData, rListWrp );
1384 template< typename Type >
1385 void OutputObjectBase::writeHexItem( const String& rName, Type nData, const NameListWrapper& rListWrp )
1387 ItemGuard aItem( mxOut, rName );
1388 mxOut->writeHex( nData );
1389 addNameToItem( nData, rListWrp );
1392 template< typename Type >
1393 void OutputObjectBase::writeShortHexItem( const String& rName, Type nData, const NameListWrapper& rListWrp )
1395 ItemGuard aItem( mxOut, rName );
1396 mxOut->writeShortHex( nData );
1397 addNameToItem( nData, rListWrp );
1400 template< typename Type >
1401 void OutputObjectBase::writeBinItem( const String& rName, Type nData, const NameListWrapper& rListWrp )
1403 ItemGuard aItem( mxOut, rName );
1404 mxOut->writeBin( nData );
1405 addNameToItem( nData, rListWrp );
1408 template< typename Type >
1409 void OutputObjectBase::writeFixItem( const String& rName, Type nData, const NameListWrapper& rListWrp )
1411 ItemGuard aItem( mxOut, rName );
1412 mxOut->writeFix( nData );
1413 addNameToItem( nData, rListWrp );
1416 template< typename Type >
1417 void OutputObjectBase::writeDecBoolItem( const String& rName, Type nData, const NameListWrapper& rListWrp )
1419 ItemGuard aItem( mxOut, rName );
1420 mxOut->writeDec( nData );
1421 aItem.cont();
1422 mxOut->writeBool( nData != 0 );
1423 addNameToItem( nData, rListWrp );
1426 template< typename Type >
1427 void OutputObjectBase::writeValueItem( const String& rName, Type nData, FormatType eFmtType, const NameListWrapper& rListWrp )
1429 if( eFmtType == FORMATTYPE_BOOL )
1430 writeDecBoolItem( rName, nData, rListWrp );
1431 else
1433 ItemGuard aItem( mxOut, rName );
1434 mxOut->writeValue( nData, eFmtType );
1435 addNameToItem( nData, rListWrp );
1439 template< typename Type >
1440 void OutputObjectBase::writeValueItem( const ItemFormat& rItemFmt, Type nData )
1442 OString aNameUtf8 = StringHelper::convertToUtf8( rItemFmt.maItemName );
1443 writeValueItem( aNameUtf8.getStr(), nData, rItemFmt.meFmtType, rItemFmt.maListName );
1446 template< typename Type >
1447 void OutputObjectBase::writeDecPairItem( const String& rName, Type nData1, Type nData2, sal_Unicode cSep )
1449 ItemGuard aItem( mxOut, rName );
1450 mxOut->writeDec( nData1 );
1451 mxOut->writeChar( cSep );
1452 mxOut->writeDec( nData2 );
1455 template< typename Type >
1456 void OutputObjectBase::writeHexPairItem( const String& rName, Type nData1, Type nData2, sal_Unicode cSep )
1458 ItemGuard aItem( mxOut, rName );
1459 mxOut->writeHex( nData1 );
1460 mxOut->writeChar( cSep );
1461 mxOut->writeHex( nData2 );
1467 class InputObjectBase : public OutputObjectBase
1469 public:
1470 virtual ~InputObjectBase();
1473 protected:
1474 InputObjectBase() {}
1476 using OutputObjectBase::construct;
1477 void construct( const ObjectBase& rParent, const BinaryInputStreamRef& rxStrm, const OUString& rSysFileName );
1478 void construct( const OutputObjectBase& rParent, const BinaryInputStreamRef& rxStrm );
1479 void construct( const InputObjectBase& rParent );
1481 virtual bool implIsValid() const SAL_OVERRIDE;
1485 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
1486 getXInputStream() const;
1490 void skipBlock( sal_Int64 nBytes, bool bShowSize = true );
1491 void dumpRawBinary( sal_Int64 nBytes, bool bShowOffset = true, bool bStream = false );
1493 void dumpBinary( const String& rName, sal_Int64 nBytes, bool bShowOffset = true );
1494 void dumpRemaining( sal_Int64 nBytes );
1495 void dumpRemainingTo( sal_Int64 nPos );
1496 void dumpRemainingStream();
1498 void dumpArray( const String& rName, sal_Int32 nBytes, sal_Unicode cSep = OOX_DUMP_LISTSEP );
1499 void dumpUnused( sal_Int32 nBytes ) { dumpArray( OOX_DUMP_UNUSED, nBytes ); }
1500 void dumpUnknown( sal_Int32 nBytes ) { dumpArray( OOX_DUMP_UNKNOWN, nBytes ); }
1502 sal_Unicode dumpUnicode( const String& rName );
1504 OUString dumpCharArray( const String& rName, sal_Int32 nLen, rtl_TextEncoding eTextEnc, bool bHideTrailingNul = false );
1505 OUString dumpUnicodeArray( const String& rName, sal_Int32 nLen, bool bHideTrailingNul = false );
1507 ::com::sun::star::util::DateTime dumpFileTime( const String& rName = EMPTY_STRING );
1508 OUString dumpGuid( const String& rName = EMPTY_STRING );
1510 void dumpItem( const ItemFormat& rItemFmt );
1512 template< typename Type >
1513 Type dumpName( const String& rName, const NameListWrapper& rListWrp );
1514 template< typename Type >
1515 Type dumpDec( const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1516 template< typename Type >
1517 Type dumpHex( const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1518 template< typename Type >
1519 Type dumpBin( const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1520 template< typename Type >
1521 Type dumpFix( const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1522 template< typename Type >
1523 Type dumpBool( const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1524 template< typename Type >
1525 Type dumpValue( const ItemFormat& rItemFmt );
1527 template< typename Type1, typename Type2 >
1528 Type1 dumpName( bool bType1, const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1529 template< typename Type1, typename Type2 >
1530 Type1 dumpDec( bool bType1, const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1531 template< typename Type1, typename Type2 >
1532 Type1 dumpHex( bool bType1, const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1533 template< typename Type1, typename Type2 >
1534 Type1 dumpBin( bool bType1, const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1535 template< typename Type1, typename Type2 >
1536 Type1 dumpFix( bool bType1, const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1537 template< typename Type1, typename Type2 >
1538 Type1 dumpBool( bool bType1, const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1539 template< typename Type1, typename Type2 >
1540 Type1 dumpValue( bool bType1, const ItemFormat& rItemFmt );
1542 template< typename Type >
1543 void dumpDecPair( const String& rName, sal_Unicode cSep = ',' );
1544 template< typename Type >
1545 void dumpHexPair( const String& rName, sal_Unicode cSep = ',' );
1547 protected:
1548 BinaryInputStreamRef mxStrm;
1554 template< typename Type >
1555 Type InputObjectBase::dumpName( const String& rName, const NameListWrapper& rListWrp )
1557 Type nData = mxStrm->readValue<Type>();
1558 writeNameItem( rName, nData, rListWrp );
1559 return nData;
1562 template< typename Type >
1563 Type InputObjectBase::dumpDec( const String& rName, const NameListWrapper& rListWrp )
1565 Type nData = mxStrm->readValue<Type>();
1566 writeDecItem( rName, nData, rListWrp );
1567 return nData;
1570 template< typename Type >
1571 Type InputObjectBase::dumpHex( const String& rName, const NameListWrapper& rListWrp )
1573 Type nData = mxStrm->readValue<Type>();
1574 writeHexItem( rName, nData, rListWrp );
1575 return nData;
1578 template< typename Type >
1579 Type InputObjectBase::dumpBin( const String& rName, const NameListWrapper& rListWrp )
1581 Type nData = mxStrm->readValue<Type>();
1582 writeBinItem( rName, nData, rListWrp );
1583 return nData;
1586 template< typename Type >
1587 Type InputObjectBase::dumpFix( const String& rName, const NameListWrapper& rListWrp )
1589 Type nData = mxStrm->readValue<Type>();
1590 writeFixItem( rName, nData, rListWrp );
1591 return nData;
1594 template< typename Type >
1595 Type InputObjectBase::dumpBool( const String& rName, const NameListWrapper& rListWrp )
1597 Type nData = mxStrm->readValue<Type>();
1598 writeDecBoolItem( rName, nData, rListWrp );
1599 return nData;
1602 template< typename Type >
1603 Type InputObjectBase::dumpValue( const ItemFormat& rItemFmt )
1605 Type nData = mxStrm->readValue<Type>();
1606 writeValueItem( rItemFmt, nData );
1607 return nData;
1610 template< typename Type1, typename Type2 >
1611 Type1 InputObjectBase::dumpName( bool bType1, const String& rName, const NameListWrapper& rListWrp )
1613 return bType1 ? dumpName< Type1 >( rName, rListWrp ) : static_cast< Type1 >( dumpName< Type2 >( rName, rListWrp ) );
1616 template< typename Type1, typename Type2 >
1617 Type1 InputObjectBase::dumpDec( bool bType1, const String& rName, const NameListWrapper& rListWrp )
1619 return bType1 ? dumpDec< Type1 >( rName, rListWrp ) : static_cast< Type1 >( dumpDec< Type2 >( rName, rListWrp ) );
1622 template< typename Type1, typename Type2 >
1623 Type1 InputObjectBase::dumpHex( bool bType1, const String& rName, const NameListWrapper& rListWrp )
1625 return bType1 ? dumpHex< Type1 >( rName, rListWrp ) : static_cast< Type1 >( dumpHex< Type2 >( rName, rListWrp ) );
1628 template< typename Type1, typename Type2 >
1629 Type1 InputObjectBase::dumpBin( bool bType1, const String& rName, const NameListWrapper& rListWrp )
1631 return bType1 ? dumpBin< Type1 >( rName, rListWrp ) : static_cast< Type1 >( dumpBin< Type2 >( rName, rListWrp ) );
1634 template< typename Type1, typename Type2 >
1635 Type1 InputObjectBase::dumpFix( bool bType1, const String& rName, const NameListWrapper& rListWrp )
1637 return bType1 ? dumpFix< Type1 >( rName, rListWrp ) : static_cast< Type1 >( dumpFix< Type2 >( rName, rListWrp ) );
1640 template< typename Type1, typename Type2 >
1641 Type1 InputObjectBase::dumpBool( bool bType1, const String& rName, const NameListWrapper& rListWrp )
1643 return bType1 ? dumpBool< Type1 >( rName, rListWrp ) : static_cast< Type1 >( dumpBool< Type2 >( rName, rListWrp ) );
1646 template< typename Type1, typename Type2 >
1647 Type1 InputObjectBase::dumpValue( bool bType1, const ItemFormat& rItemFmt )
1649 return bType1 ? dumpValue< Type1 >( rItemFmt ) : static_cast< Type1 >( dumpValue< Type2 >( rItemFmt ) );
1652 template< typename Type >
1653 void InputObjectBase::dumpDecPair( const String& rName, sal_Unicode cSep )
1655 Type nData1, nData2;
1656 *mxStrm >> nData1 >> nData2;
1657 writeDecPairItem( rName, nData1, nData2, cSep );
1660 template< typename Type >
1661 void InputObjectBase::dumpHexPair( const String& rName, sal_Unicode cSep )
1663 Type nData1, nData2;
1664 *mxStrm >> nData1 >> nData2;
1665 writeHexPairItem( rName, nData1, nData2, cSep );
1671 class BinaryStreamObject : public InputObjectBase
1673 public:
1674 explicit BinaryStreamObject(
1675 const ObjectBase& rParent,
1676 const BinaryInputStreamRef& rxStrm,
1677 const OUString& rSysFileName );
1679 protected:
1680 void dumpBinaryStream( bool bShowOffset = true );
1682 virtual void implDump() SAL_OVERRIDE;
1688 class TextStreamObjectBase : public InputObjectBase
1690 protected:
1691 TextStreamObjectBase() {}
1693 using InputObjectBase::construct;
1694 void construct(
1695 const ObjectBase& rParent,
1696 const BinaryInputStreamRef& rxStrm,
1697 rtl_TextEncoding eTextEnc,
1698 const OUString& rSysFileName );
1699 void construct(
1700 const OutputObjectBase& rParent,
1701 const BinaryInputStreamRef& rxStrm,
1702 rtl_TextEncoding eTextEnc );
1704 virtual bool implIsValid() const SAL_OVERRIDE;
1705 virtual void implDump() SAL_OVERRIDE;
1707 virtual void implDumpText( TextInputStream& rTextStrm ) = 0;
1709 private:
1710 void constructTextStrmObj( rtl_TextEncoding eTextEnc );
1712 protected:
1713 std::shared_ptr< TextInputStream > mxTextStrm;
1718 class TextLineStreamObject : public TextStreamObjectBase
1720 public:
1721 explicit TextLineStreamObject(
1722 const ObjectBase& rParent,
1723 const BinaryInputStreamRef& rxStrm,
1724 rtl_TextEncoding eTextEnc,
1725 const OUString& rSysFileName );
1727 explicit TextLineStreamObject(
1728 const OutputObjectBase& rParent,
1729 const BinaryInputStreamRef& rxStrm,
1730 rtl_TextEncoding eTextEnc );
1732 protected:
1733 virtual void implDumpText( TextInputStream& rTextStrm ) SAL_OVERRIDE;
1734 void implDumpLine( const OUString& rLine, sal_uInt32 nLine );
1739 class XmlStreamObject : public TextStreamObjectBase
1741 public:
1742 explicit XmlStreamObject(
1743 const ObjectBase& rParent,
1744 const BinaryInputStreamRef& rxStrm,
1745 const OUString& rSysFileName );
1747 protected:
1748 virtual void implDumpText( TextInputStream& rTextStrm ) SAL_OVERRIDE;
1754 class RecordObjectBase : public InputObjectBase
1756 protected:
1757 RecordObjectBase() {}
1759 using InputObjectBase::construct;
1760 void construct(
1761 const ObjectBase& rParent,
1762 const BinaryInputStreamRef& rxBaseStrm,
1763 const OUString& rSysFileName,
1764 const BinaryInputStreamRef& rxRecStrm,
1765 const String& rRecNames,
1766 const String& rSimpleRecs = EMPTY_STRING );
1768 sal_Int64 getRecPos() const { return mnRecPos; }
1769 sal_Int64 getRecId() const { return mnRecId; }
1770 sal_Int64 getRecSize() const { return mnRecSize; }
1771 NameListRef getRecNames() const { return maRecNames.getNameList( cfg() ); }
1773 void setBinaryOnlyMode( bool bBinaryOnly ) { mbBinaryOnly = bBinaryOnly; }
1774 bool isBinaryOnlyMode() const { return mbBinaryOnly; }
1776 virtual bool implIsValid() const SAL_OVERRIDE;
1777 virtual void implDump() SAL_OVERRIDE;
1779 virtual bool implStartRecord( BinaryInputStream& rBaseStrm, sal_Int64& ornRecPos, sal_Int64& ornRecId, sal_Int64& ornRecSize ) = 0;
1780 virtual void implWriteExtHeader();
1781 virtual void implDumpRecordBody();
1783 private:
1784 void constructRecObjBase(
1785 const BinaryInputStreamRef& rxBaseStrm,
1786 const String& rRecNames,
1787 const String& rSimpleRecs );
1789 void writeHeader();
1791 private:
1792 BinaryInputStreamRef mxBaseStrm;
1793 NameListWrapper maRecNames;
1794 NameListWrapper maSimpleRecs;
1795 sal_Int64 mnRecPos;
1796 sal_Int64 mnRecId;
1797 sal_Int64 mnRecSize;
1798 bool mbShowRecPos;
1799 bool mbBinaryOnly;
1804 class SequenceRecordObjectBase : public RecordObjectBase
1806 protected:
1807 SequenceRecordObjectBase() : mxRecData( new StreamDataSequence ) {}
1809 StreamDataSequence& getRecordDataSequence() { return *mxRecData; }
1811 using RecordObjectBase::construct;
1812 void construct(
1813 const ObjectBase& rParent,
1814 const BinaryInputStreamRef& rxBaseStrm,
1815 const OUString& rSysFileName,
1816 const String& rRecNames,
1817 const String& rSimpleRecs = EMPTY_STRING );
1819 virtual bool implStartRecord( BinaryInputStream& rBaseStrm, sal_Int64& ornRecPos, sal_Int64& ornRecId, sal_Int64& ornRecSize ) SAL_OVERRIDE;
1820 virtual bool implReadRecordHeader( BinaryInputStream& rBaseStrm, sal_Int64& ornRecId, sal_Int64& ornRecSize ) = 0;
1822 private:
1823 typedef std::shared_ptr< StreamDataSequence > StreamDataSeqRef;
1824 StreamDataSeqRef mxRecData;
1830 /** Base class for a file dumper. Derived classes implement the implDump()
1831 function to add functionality.
1833 class DumperBase : public ObjectBase
1835 public:
1836 virtual ~DumperBase();
1838 bool isImportEnabled() const;
1839 bool isImportCancelled() const;
1841 protected:
1842 DumperBase() {}
1844 using ObjectBase::construct;
1845 void construct( const ConfigRef& rxConfig );
1851 } // namespace dump
1852 } // namespace oox
1854 #define OOX_DUMP_FILE( DumperClassName ) \
1855 do { \
1856 DumperClassName aDumper( *this ); \
1857 aDumper.dump(); \
1858 bool bCancelled = aDumper.isImportCancelled(); \
1859 if( !aDumper.isImportEnabled() || bCancelled ) \
1860 return aDumper.isValid() && !bCancelled; \
1861 } while( false )
1863 #else // OOX_INCLUDE_DUMPER
1865 #define OOX_DUMP_FILE( DumperClassName ) (void)0
1867 #endif // OOX_INCLUDE_DUMPER
1868 #endif
1870 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */