1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
31 #include <com/sun/star/uno/Reference.hxx>
32 #include <com/sun/star/uno/Sequence.hxx>
33 #include <com/sun/star/util/DateTime.hpp>
34 #include <oox/helper/binaryinputstream.hxx>
35 #include <oox/helper/binarystreambase.hxx>
36 #include <oox/helper/storagebase.hxx>
37 #include <rtl/string.hxx>
38 #include <rtl/textenc.h>
39 #include <rtl/ustring.hxx>
40 #include <rtl/ustrbuf.hxx>
41 #include <sal/types.h>
43 #define OOX_INCLUDE_DUMPER (OSL_DEBUG_LEVEL > 0)
45 #if OOX_INCLUDE_DUMPER
47 namespace com
{ namespace sun
{ namespace star
{
48 namespace io
{ class XInputStream
; }
49 namespace io
{ class XOutputStream
; }
50 namespace io
{ class XTextOutputStream2
; }
51 namespace uno
{ class XComponentContext
; }
55 class TextInputStream
;
58 namespace oox
{ namespace core
{
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
;
96 typedef ::std::vector
< OUString
> OUStringVector
;
97 typedef ::std::vector
< sal_Int64
> Int64Vector
;
100 /** Static helper functions for system file and stream access. */
101 class InputOutputHelper
104 // file names -------------------------------------------------------------
106 static OUString
convertFileNameToUrl( const OUString
& rFileName
);
107 static sal_Int32
getFileNamePos( const OUString
& rFileUrl
);
108 static OUString
getFileNameExtension( const OUString
& rFileUrl
);
110 // input streams ----------------------------------------------------------
112 static css::uno::Reference
< css::io::XInputStream
>
114 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
115 const OUString
& rFileName
);
117 // output streams ---------------------------------------------------------
119 static css::uno::Reference
< css::io::XOutputStream
>
121 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
122 const OUString
& rFileName
);
124 static css::uno::Reference
< css::io::XTextOutputStream2
>
125 openTextOutputStream(
126 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
127 const css::uno::Reference
< css::io::XOutputStream
>& rxOutStrm
,
128 rtl_TextEncoding eTextEnc
);
130 static css::uno::Reference
< css::io::XTextOutputStream2
>
131 openTextOutputStream(
132 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
133 const OUString
& rFileName
,
134 rtl_TextEncoding eTextEnc
);
138 class BinaryInputStreamRef
: public ::oox::BinaryInputStreamRef
141 BinaryInputStreamRef() {}
143 /*implicit*/ BinaryInputStreamRef( BinaryInputStream
* pInStrm
) :
144 ::oox::BinaryInputStreamRef( pInStrm
) {}
146 /*implicit*/ BinaryInputStreamRef( const css::uno::Reference
< css::io::XInputStream
>& rxInStrm
) :
147 ::oox::BinaryInputStreamRef( new BinaryXInputStream( rxInStrm
, true ) ) {}
149 template< typename StreamType
>
150 /*implicit*/ BinaryInputStreamRef( const std::shared_ptr
< StreamType
>& rxInStrm
) :
151 ::oox::BinaryInputStreamRef( rxInStrm
) {}
155 /** Specifiers for atomic data types. */
158 DATATYPE_VOID
, ///< No data type.
159 DATATYPE_INT8
, ///< Signed 8-bit integer.
160 DATATYPE_UINT8
, ///< Unsigned 8-bit integer.
161 DATATYPE_INT16
, ///< Signed 16-bit integer.
162 DATATYPE_UINT16
, ///< Unsigned 16-bit integer.
163 DATATYPE_INT32
, ///< Signed 32-bit integer.
164 DATATYPE_UINT32
, ///< Unsigned 32-bit integer.
165 DATATYPE_INT64
, ///< Signed 64-bit integer.
166 DATATYPE_UINT64
, ///< Unsigned 64-bit integer.
167 DATATYPE_FLOAT
, ///< Floating-point, single precision.
168 DATATYPE_DOUBLE
///< Floating-point, double precision.
172 /** Specifiers for the output format of values. */
175 FORMATTYPE_NONE
, ///< No numeric format (e.g. show name only).
176 FORMATTYPE_DEC
, ///< Decimal.
177 FORMATTYPE_HEX
, ///< Hexadecimal.
178 FORMATTYPE_SHORTHEX
, ///< Hexadecimal, as short as possible (no leading zeros).
179 FORMATTYPE_BIN
, ///< Binary.
180 FORMATTYPE_FIX
, ///< Fixed-point.
181 FORMATTYPE_BOOL
///< Boolean ('true' or 'false').
185 /** Describes the output format of a data item.
187 Data items are written in the following format:
189 <NAME>=<VALUE>=<NAME-FROM-LIST>
191 NAME is the name of the data item. The name is contained in the member
192 maItemName. If the name is empty, only the value is written (without a
193 leading equality sign).
195 VALUE is the numeric value of the data item. Its format is dependent on the
196 output format given in the member meFmtType. If the format type is
197 FORMATTYPE_NONE, no value is written.
199 NAME-FROM-LIST is a symbolic name for the current value of the data item.
200 Various types of name lists produce different names for values, which can
201 be used for enumerations or names for single bits in bitfields (see class
202 NameListBase and derived classes). The name of the list is given in the
203 member maListName. If it is empty, no name is written for the value.
207 DataType meDataType
; ///< Data type of the item.
208 FormatType meFmtType
; ///< Output format for the value.
209 OUString maItemName
; ///< Name of the item.
210 OUString maListName
; ///< Name of a name list to be used for this item.
212 explicit ItemFormat();
214 void set( DataType eDataType
, FormatType eFmtType
, const OUString
& rItemName
);
216 /** Initializes the struct from a vector of strings containing the item format.
218 The vector must contain at least 2 strings. The struct is filled from
219 the strings in the vector in the following order:
220 1) Data type (one of: [u]int8, [u]int16, [u]int32, [u]int64, float, double).
221 2) Format type (one of: dec, hex, shorthex, bin, fix, bool, unused, unknown).
222 3) Item name (optional).
223 4) Name list name (optional).
225 @return Iterator pointing to the first unhandled string.
227 OUStringVector::const_iterator
parse( const OUStringVector
& rFormatVec
);
229 /** Initializes the struct from a string containing the item format.
231 The string must have the following format:
232 DATATYPE,FORMATTYPE[,ITEMNAME[,LISTNAME]]
234 DATATYPE is the data type of the item (see above for possible values).
235 FORMATTYPE is the format type of the item (see above for possible values).
236 ITEMNAME is the name of the item (optional).
237 LISTNAME is the name of a name list (optional).
239 @return List containing remaining unhandled format strings.
241 OUStringVector
parse( const OUString
& rFormatStr
);
245 /** Static helper functions for formatted output to strings. */
249 // append string to string ------------------------------------------------
251 static void appendChar( OUStringBuffer
& rStr
, sal_Unicode cChar
, sal_Int32 nCount
= 1 );
252 static void appendString( OUStringBuffer
& rStr
, const OUString
& rData
, sal_Int32 nWidth
= 0, sal_Unicode cFill
= ' ' );
254 // append decimal ---------------------------------------------------------
256 static void appendDec( OUStringBuffer
& rStr
, sal_uInt8 nData
, sal_Int32 nWidth
= 0, sal_Unicode cFill
= ' ' );
257 static void appendDec( OUStringBuffer
& rStr
, sal_Int8 nData
, sal_Int32 nWidth
= 0, sal_Unicode cFill
= ' ' );
258 static void appendDec( OUStringBuffer
& rStr
, sal_uInt16 nData
, sal_Int32 nWidth
= 0, sal_Unicode cFill
= ' ' );
259 static void appendDec( OUStringBuffer
& rStr
, sal_Int16 nData
, sal_Int32 nWidth
= 0, sal_Unicode cFill
= ' ' );
260 static void appendDec( OUStringBuffer
& rStr
, sal_uInt32 nData
, sal_Int32 nWidth
= 0, sal_Unicode cFill
= ' ' );
261 static void appendDec( OUStringBuffer
& rStr
, sal_Int32 nData
, sal_Int32 nWidth
= 0, sal_Unicode cFill
= ' ' );
262 static void appendDec( OUStringBuffer
& rStr
, sal_uInt64 nData
, sal_Int32 nWidth
= 0, sal_Unicode cFill
= ' ' );
263 static void appendDec( OUStringBuffer
& rStr
, sal_Int64 nData
, sal_Int32 nWidth
= 0, sal_Unicode cFill
= ' ' );
264 static void appendDec( OUStringBuffer
& rStr
, double fData
, sal_Int32 nWidth
= 0, sal_Unicode cFill
= ' ' );
266 // append hexadecimal -----------------------------------------------------
268 static void appendHex( OUStringBuffer
& rStr
, sal_uInt8 nData
, bool bPrefix
= true );
269 static void appendHex( OUStringBuffer
& rStr
, sal_Int8 nData
, bool bPrefix
= true );
270 static void appendHex( OUStringBuffer
& rStr
, sal_uInt16 nData
, bool bPrefix
= true );
271 static void appendHex( OUStringBuffer
& rStr
, sal_Int16 nData
, bool bPrefix
= true );
272 static void appendHex( OUStringBuffer
& rStr
, sal_uInt32 nData
, bool bPrefix
= true );
273 static void appendHex( OUStringBuffer
& rStr
, sal_Int32 nData
, bool bPrefix
= true );
274 static void appendHex( OUStringBuffer
& rStr
, sal_uInt64 nData
, bool bPrefix
= true );
275 static void appendHex( OUStringBuffer
& rStr
, sal_Int64 nData
, bool bPrefix
= true );
276 static void appendHex( OUStringBuffer
& rStr
, double fData
, bool bPrefix
= true );
278 // append shortened hexadecimal -------------------------------------------
280 static void appendShortHex( OUStringBuffer
& rStr
, sal_uInt8 nData
, bool bPrefix
= true );
281 static void appendShortHex( OUStringBuffer
& rStr
, sal_Int8 nData
, bool bPrefix
= true );
282 static void appendShortHex( OUStringBuffer
& rStr
, sal_uInt16 nData
, bool bPrefix
= true );
283 static void appendShortHex( OUStringBuffer
& rStr
, sal_Int16 nData
, bool bPrefix
= true );
284 static void appendShortHex( OUStringBuffer
& rStr
, sal_uInt32 nData
, bool bPrefix
= true );
285 static void appendShortHex( OUStringBuffer
& rStr
, sal_Int32 nData
, bool bPrefix
= true );
286 static void appendShortHex( OUStringBuffer
& rStr
, sal_uInt64 nData
, bool bPrefix
= true );
287 static void appendShortHex( OUStringBuffer
& rStr
, sal_Int64 nData
, bool bPrefix
= true );
288 static void appendShortHex( OUStringBuffer
& rStr
, double fData
, bool bPrefix
= true );
290 // append binary ----------------------------------------------------------
292 static void appendBin( OUStringBuffer
& rStr
, sal_uInt8 nData
, bool bDots
= true );
293 static void appendBin( OUStringBuffer
& rStr
, sal_Int8 nData
, bool bDots
= true );
294 static void appendBin( OUStringBuffer
& rStr
, sal_uInt16 nData
, bool bDots
= true );
295 static void appendBin( OUStringBuffer
& rStr
, sal_Int16 nData
, bool bDots
= true );
296 static void appendBin( OUStringBuffer
& rStr
, sal_uInt32 nData
, bool bDots
= true );
297 static void appendBin( OUStringBuffer
& rStr
, sal_Int32 nData
, bool bDots
= true );
298 static void appendBin( OUStringBuffer
& rStr
, sal_uInt64 nData
, bool bDots
= true );
299 static void appendBin( OUStringBuffer
& rStr
, sal_Int64 nData
, bool bDots
= true );
300 static void appendBin( OUStringBuffer
& rStr
, double fData
, bool bDots
= true );
302 // append fixed-point decimal ---------------------------------------------
304 template< typename Type
>
305 static void appendFix( OUStringBuffer
& rStr
, Type nData
, sal_Int32 nWidth
= 0 );
307 // append formatted value -------------------------------------------------
309 static void appendBool( OUStringBuffer
& rStr
, bool bData
);
310 template< typename Type
>
311 static void appendValue( OUStringBuffer
& rStr
, Type nData
, FormatType eFmtType
);
313 // encoded text output ----------------------------------------------------
315 static void appendCChar( OUStringBuffer
& rStr
, sal_Unicode cChar
, bool bPrefix
= true );
316 static void appendEncChar( OUStringBuffer
& rStr
, sal_Unicode cChar
, sal_Int32 nCount
= 1, bool bPrefix
= true );
317 static void appendEncString( OUStringBuffer
& rStr
, const OUString
& rData
, bool bPrefix
= true );
319 // token list -------------------------------------------------------------
321 static void appendToken( OUStringBuffer
& rStr
, const OUString
& rToken
, sal_Unicode cSep
= OOX_DUMP_LISTSEP
);
323 static void appendIndex( OUStringBuffer
& rStr
, const OUString
& rIdx
);
324 static void appendIndex( OUStringBuffer
& rStr
, sal_Int64 nIdx
);
326 static OUString
getToken( const OUString
& rData
, sal_Int32
& rnPos
, sal_Unicode cSep
= OOX_DUMP_LISTSEP
);
328 /** Encloses the passed string with the passed characters. Uses cOpen, if cClose is NUL. */
329 static void enclose( OUStringBuffer
& rStr
, sal_Unicode cOpen
, sal_Unicode cClose
= '\0' );
331 // string conversion ------------------------------------------------------
333 static OUString
trimSpaces( const OUString
& rStr
);
334 static OUString
trimTrailingNul( const OUString
& rStr
);
336 static OString
convertToUtf8( const OUString
& rStr
);
337 static DataType
convertToDataType( const OUString
& rStr
);
338 static FormatType
convertToFormatType( const OUString
& rStr
);
340 static bool convertFromDec( sal_Int64
& ornData
, const OUString
& rData
);
341 static bool convertFromHex( sal_Int64
& ornData
, const OUString
& rData
);
343 static bool convertStringToInt( sal_Int64
& ornData
, const OUString
& rData
);
344 static bool convertStringToDouble( double& orfData
, const OUString
& rData
);
345 static bool convertStringToBool( const OUString
& rData
);
347 static OUStringPair
convertStringToPair( const OUString
& rString
, sal_Unicode cSep
= '=' );
349 // string to list conversion ----------------------------------------------
351 static void convertStringToStringList( OUStringVector
& orVec
, const OUString
& rData
, bool bIgnoreEmpty
);
352 static void convertStringToIntList( Int64Vector
& orVec
, const OUString
& rData
, bool bIgnoreEmpty
);
356 template< typename Type
>
357 void StringHelper::appendFix( OUStringBuffer
& rStr
, Type nData
, sal_Int32 nWidth
)
359 appendDec( rStr
, static_cast< double >( nData
) / std::pow( 2.0, 4.0 * sizeof( Type
) ), nWidth
);
362 template< typename Type
>
363 void StringHelper::appendValue( OUStringBuffer
& rStr
, Type nData
, FormatType eFmtType
)
367 case FORMATTYPE_DEC
: appendDec( rStr
, nData
); break;
368 case FORMATTYPE_HEX
: appendHex( rStr
, nData
); break;
369 case FORMATTYPE_SHORTHEX
: appendShortHex( rStr
, nData
); break;
370 case FORMATTYPE_BIN
: appendBin( rStr
, nData
); break;
371 case FORMATTYPE_FIX
: appendFix( rStr
, nData
); break;
372 case FORMATTYPE_BOOL
: appendBool( rStr
, nData
); break;
378 class String
: public OUString
382 /*implicit*/ String( const OUString
& rStr
) : OUString( rStr
) {}
383 /*implicit*/ String( const sal_Char
* pcStr
) : OUString( OUString::createFromAscii( pcStr
? pcStr
: "" ) ) {}
384 /*implicit*/ String( sal_Unicode cChar
) : OUString( cChar
) {}
386 bool has() const { return getLength() > 0; }
387 OUString
operator()( const sal_Char
* pcDefault
) const { if( has() ) return *this; return String( pcDefault
); }
390 static const String EMPTY_STRING
;
393 /** Base class for all dumper classes.
395 Derived classes implement the virtual function implIsValid(). It should
396 check all members the other functions rely on. If the function
397 implIsValid() returns true, all references and pointers can be used without
400 Overview of all classes in this header file based on this Base class:
406 | +----> ConstList ------> MultiList
408 | +----> FlagsList ------> CombiList
410 | +----> UnitConverter
412 +----> SharedConfigData
418 +----> StorageIterator
422 +----> StorageObjectBase
424 +----> OutputObjectBase
426 | +----> InputObjectBase
428 | +----> BinaryStreamObject
430 | +----> TextStreamObjectBase
432 | | +----> TextStreamObject
434 | | +----> XmlStreamObject
436 | +----> RecordObjectBase
438 | +----> SequenceRecordObjectBase
447 bool isValid() const { return implIsValid(); }
448 static bool isValid( const std::shared_ptr
< Base
>& rxBase
) { return rxBase
.get() && rxBase
->isValid(); }
453 virtual bool implIsValid() const = 0;
460 virtual ~ConfigItemBase();
461 void readConfigBlock( TextInputStream
& rStrm
);
466 virtual void implProcessConfigItemStr(
467 TextInputStream
& rStrm
,
468 const OUString
& rKey
,
469 const OUString
& rData
);
471 virtual void implProcessConfigItemInt(
472 TextInputStream
& rStrm
,
474 const OUString
& rData
);
476 void readConfigBlockContents(
477 TextInputStream
& rStrm
);
480 enum LineType
{ LINETYPE_DATA
, LINETYPE_END
};
482 static LineType
readConfigLine(
483 TextInputStream
& rStrm
,
487 void processConfigItem(
488 TextInputStream
& rStrm
,
489 const OUString
& rKey
,
490 const OUString
& rData
);
494 class SharedConfigData
;
498 typedef std::shared_ptr
< NameListBase
> NameListRef
;
500 /** Base class of all classes providing names for specific values (name lists).
502 The idea is to provide a unique interfase for all different methods to
503 write specific names for any values. This can be enumerations (dedicated
504 names for a subset of values), or names for bits in bit fields. Classes
505 derived from this base class implement the specific behaviour for the
508 class NameListBase
: public Base
, public ConfigItemBase
511 typedef ::std::map
< sal_Int64
, OUString
> OUStringMap
;
512 typedef OUStringMap::const_iterator const_iterator
;
515 virtual ~NameListBase();
517 /** Sets a name for the specified key. */
518 void setName( sal_Int64 nKey
, const String
& rName
);
520 /** Include all names of the passed list. */
521 void includeList( const NameListRef
& rxList
);
523 /** Returns true, if the map contains an entry for the passed key. */
524 template< typename Type
>
525 bool hasName( Type nKey
) const
526 { return maMap
.count( static_cast< sal_Int64
>( nKey
) ) != 0; }
528 /** Returns the name for the passed key. */
529 template< typename Type
>
530 OUString
getName( const Config
& rCfg
, Type nKey
) const
531 { return implGetName( rCfg
, static_cast< sal_Int64
>( nKey
) ); }
533 /** Returns a display name for the passed double value. */
534 OUString
getName( const Config
& rCfg
, double fValue
) const
535 { return implGetNameDbl( rCfg
, fValue
); }
537 /** Returns a map iterator pointing to the first contained name. */
538 const_iterator
begin() const { return maMap
.begin(); }
539 /** Returns a map iterator pointing one past the last contained name. */
540 const_iterator
end() const { return maMap
.end(); }
543 explicit NameListBase( const SharedConfigData
& rCfgData
) : mrCfgData( rCfgData
) {}
545 virtual bool implIsValid() const override
;
547 virtual void implProcessConfigItemStr(
548 TextInputStream
& rStrm
,
549 const OUString
& rKey
,
550 const OUString
& rData
) override
;
552 virtual void implProcessConfigItemInt(
553 TextInputStream
& rStrm
,
555 const OUString
& rData
) override
;
557 /** Derived classes set the name for the passed key. */
558 virtual void implSetName( sal_Int64 nKey
, const OUString
& rName
) = 0;
559 /** Derived classes generate and return the name for the passed key. */
560 virtual OUString
implGetName( const Config
& rCfg
, sal_Int64 nKey
) const = 0;
561 /** Derived classes generate and return the name for the passed double value. */
562 virtual OUString
implGetNameDbl( const Config
& rCfg
, double fValue
) const = 0;
563 /** Derived classes insert all names and other settings from the passed list. */
564 virtual void implIncludeList( const NameListBase
& rList
) = 0;
566 /** Inserts the passed name into the internal map. */
567 void insertRawName( sal_Int64 nKey
, const OUString
& rName
);
568 /** Returns the name for the passed key, or 0, if nothing found. */
569 const OUString
* findRawName( sal_Int64 nKey
) const;
572 /** Includes name lists, given in a comma separated list of names of the lists. */
573 void include( const OUString
& rListKeys
);
574 /** Excludes names from the list, given in a comma separated list of their keys. */
575 void exclude( const OUString
& rKeys
);
579 const SharedConfigData
& mrCfgData
;
583 class ConstList
: public NameListBase
586 explicit ConstList( const SharedConfigData
& rCfgData
);
588 /** Sets a default name for unknown keys. */
589 void setDefaultName( const String
& rDefName
) { maDefName
= rDefName
; }
590 /** Enables or disables automatic quotation of returned names. */
591 void setQuoteNames( bool bQuoteNames
) { mbQuoteNames
= bQuoteNames
; }
594 virtual void implProcessConfigItemStr(
595 TextInputStream
& rStrm
,
596 const OUString
& rKey
,
597 const OUString
& rData
) override
;
599 /** Sets the name for the passed key. */
600 virtual void implSetName( sal_Int64 nKey
, const OUString
& rName
) override
;
601 /** Returns the name for the passed key, or the default name, if key is not contained. */
602 virtual OUString
implGetName( const Config
& rCfg
, sal_Int64 nKey
) const override
;
603 /** Returns the name for the passed double value. */
604 virtual OUString
implGetNameDbl( const Config
& rCfg
, double fValue
) const override
;
605 /** Inserts all names from the passed list. */
606 virtual void implIncludeList( const NameListBase
& rList
) override
;
614 class MultiList
: public ConstList
617 explicit MultiList( const SharedConfigData
& rCfgData
);
619 void setNamesFromVec( sal_Int64 nStartKey
, const OUStringVector
& rNames
);
622 virtual void implProcessConfigItemStr(
623 TextInputStream
& rStrm
,
624 const OUString
& rKey
,
625 const OUString
& rData
) override
;
627 virtual void implSetName( sal_Int64 nKey
, const OUString
& rName
) override
;
634 class FlagsList
: public NameListBase
637 explicit FlagsList( const SharedConfigData
& rCfgData
);
639 /** Returns the flags to be ignored on output. */
640 sal_Int64
getIgnoreFlags() const { return mnIgnore
; }
641 /** Sets flags to be ignored on output. */
642 void setIgnoreFlags( sal_Int64 nIgnore
) { mnIgnore
= nIgnore
; }
645 virtual void implProcessConfigItemStr(
646 TextInputStream
& rStrm
,
647 const OUString
& rKey
,
648 const OUString
& rData
) override
;
650 /** Sets the name for the passed key. */
651 virtual void implSetName( sal_Int64 nKey
, const OUString
& rName
) override
;
652 /** Returns the name for the passed key. */
653 virtual OUString
implGetName( const Config
& rCfg
, sal_Int64 nKey
) const override
;
654 /** Returns the name for the passed double value. */
655 virtual OUString
implGetNameDbl( const Config
& rCfg
, double fValue
) const override
;
656 /** Inserts all flags from the passed list. */
657 virtual void implIncludeList( const NameListBase
& rList
) override
;
664 class CombiList
: public FlagsList
667 explicit CombiList( const SharedConfigData
& rCfgData
);
670 /** Sets the name for the passed key. */
671 virtual void implSetName( sal_Int64 nKey
, const OUString
& rName
) override
;
672 /** Returns the name for the passed key. */
673 virtual OUString
implGetName( const Config
& rCfg
, sal_Int64 nKey
) const override
;
674 /** Inserts all flags from the passed list. */
675 virtual void implIncludeList( const NameListBase
& rList
) override
;
678 struct ExtItemFormatKey
681 ::std::pair
< sal_Int64
, sal_Int64
> maFilter
;
682 explicit ExtItemFormatKey( sal_Int64 nKey
) : mnKey( nKey
), maFilter( 0, 0 ) {}
683 bool operator<( const ExtItemFormatKey
& rRight
) const;
686 struct ExtItemFormat
: public ItemFormat
689 ExtItemFormat() : mbShiftValue( true ) {}
691 typedef ::std::map
< ExtItemFormatKey
, ExtItemFormat
> ExtItemFormatMap
;
692 ExtItemFormatMap maFmtMap
;
696 class UnitConverter
: public NameListBase
699 explicit UnitConverter( const SharedConfigData
& rCfgData
);
701 void setUnitName( const String
& rUnitName
) { maUnitName
= rUnitName
; }
702 void setFactor( double fFactor
) { mfFactor
= fFactor
; }
705 /** Sets the name for the passed key. */
706 virtual void implSetName( sal_Int64 nKey
, const OUString
& rName
) override
;
707 /** Returns the converted value with appended unit name. */
708 virtual OUString
implGetName( const Config
& rCfg
, sal_Int64 nKey
) const override
;
709 /** Returns the converted value with appended unit name. */
710 virtual OUString
implGetNameDbl( const Config
& rCfg
, double fValue
) const override
;
711 /** Empty implementation. */
712 virtual void implIncludeList( const NameListBase
& rList
) override
;
720 class NameListWrapper
724 /*implicit*/ NameListWrapper( const OUString
& rListName
) : maName( rListName
) {}
725 /*implicit*/ NameListWrapper( const sal_Char
* pcListName
) : maName( pcListName
) {}
726 /*implicit*/ NameListWrapper( const NameListRef
& rxList
) : mxList( rxList
) {}
728 bool isEmpty() const { return !mxList
&& !maName
.has(); }
729 NameListRef
getNameList( const Config
& rCfg
) const;
733 mutable NameListRef mxList
;
736 static const NameListWrapper NO_LIST
;
742 ::std::map
< sal_Int64
, ItemFormat
> maMap
;
745 ItemFormatMap() : maMap() {}
746 explicit ItemFormatMap( const NameListRef
& rxNameList
) { insertFormats( rxNameList
); }
748 ::std::map
< sal_Int64
, ItemFormat
>::const_iterator
end() const { return maMap
.end(); }
749 ::std::map
< sal_Int64
, ItemFormat
>::const_iterator
find(sal_Int64 nId
) const
751 return maMap
.find(nId
);
754 void insertFormats( const NameListRef
& rxNameList
);
758 class SharedConfigData
: public Base
, public ConfigItemBase
761 explicit SharedConfigData(
762 const OUString
& rFileName
,
763 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
764 const StorageRef
& rxRootStrg
,
765 const OUString
& rSysFileName
);
767 virtual ~SharedConfigData();
769 const css::uno::Reference
< css::uno::XComponentContext
>& getContext() const { return mxContext
; }
770 const StorageRef
& getRootStorage() const { return mxRootStrg
; }
771 const OUString
& getSysFileName() const { return maSysFileName
; }
773 void setOption( const OUString
& rKey
, const OUString
& rData
);
774 const OUString
* getOption( const OUString
& rKey
) const;
776 template< typename ListType
>
777 std::shared_ptr
< ListType
> createNameList( const OUString
& rListName
);
778 void setNameList( const OUString
& rListName
, const NameListRef
& rxList
);
779 void eraseNameList( const OUString
& rListName
);
780 NameListRef
getNameList( const OUString
& rListName
) const;
782 bool isPasswordCancelled() const { return mbPwCancelled
; }
785 virtual bool implIsValid() const override
;
786 virtual void implProcessConfigItemStr(
787 TextInputStream
& rStrm
,
788 const OUString
& rKey
,
789 const OUString
& rData
) override
;
792 bool readConfigFile( const OUString
& rFileUrl
);
793 template< typename ListType
>
794 void readNameList( TextInputStream
& rStrm
, const OUString
& rListName
);
795 void createShortList( const OUString
& rData
);
796 void createUnitConverter( const OUString
& rData
);
799 typedef ::std::set
< OUString
> ConfigFileSet
;
800 typedef ::std::map
< OUString
, OUString
> ConfigDataMap
;
801 typedef ::std::map
< OUString
, NameListRef
> NameListMap
;
803 css::uno::Reference
< css::uno::XComponentContext
> mxContext
;
804 StorageRef mxRootStrg
;
805 OUString maSysFileName
;
806 ConfigFileSet maConfigFiles
;
807 ConfigDataMap maConfigData
;
808 NameListMap maNameLists
;
809 OUString maConfigPath
;
815 template< typename ListType
>
816 std::shared_ptr
< ListType
> SharedConfigData::createNameList( const OUString
& rListName
)
818 std::shared_ptr
< ListType
> xList
;
819 if( !rListName
.isEmpty() )
821 xList
.reset( new ListType( *this ) );
822 setNameList( rListName
, xList
);
827 template< typename ListType
>
828 void SharedConfigData::readNameList( TextInputStream
& rStrm
, const OUString
& rListName
)
830 NameListRef xList
= createNameList
< ListType
>( rListName
);
832 xList
->readConfigBlock( rStrm
);
836 class Config
: public Base
839 explicit Config( const Config
& rParent
);
841 const sal_Char
* pcEnvVar
,
842 const ::oox::core::FilterBase
& rFilter
);
844 const sal_Char
* pcEnvVar
,
845 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
846 const StorageRef
& rxRootStrg
,
847 const OUString
& rSysFileName
);
851 const css::uno::Reference
< css::uno::XComponentContext
>& getContext() const { return mxCfgData
->getContext(); }
852 const StorageRef
& getRootStorage() const { return mxCfgData
->getRootStorage(); }
853 const OUString
& getSysFileName() const { return mxCfgData
->getSysFileName(); }
855 const OUString
& getStringOption( const String
& rKey
, const OUString
& rDefault
) const;
856 bool getBoolOption( const String
& rKey
, bool bDefault
) const;
857 template< typename Type
>
858 Type
getIntOption( const String
& rKey
, Type nDefault
) const;
860 bool isDumperEnabled() const;
861 bool isImportEnabled() const;
863 template< typename ListType
>
864 std::shared_ptr
< ListType
> createNameList( const String
& rListName
);
865 void eraseNameList( const String
& rListName
);
866 NameListRef
getNameList( const String
& rListName
) const;
868 /** Returns the name for the passed key from the passed name list. */
869 template< typename Type
>
870 OUString
getName( const NameListWrapper
& rListWrp
, Type nKey
) const;
871 /** Returns true, if the passed name list contains an entry for the passed key. */
872 template< typename Type
>
873 bool hasName( const NameListWrapper
& rListWrp
, Type nKey
) const;
875 bool isPasswordCancelled() const;
879 void construct( const Config
& rParent
);
881 const sal_Char
* pcEnvVar
,
882 const ::oox::core::FilterBase
& rFilter
);
884 const sal_Char
* pcEnvVar
,
885 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
886 const StorageRef
& rxRootStrg
,
887 const OUString
& rSysFileName
);
889 virtual bool implIsValid() const override
;
890 const OUString
* implGetOption( const OUString
& rKey
) const;
891 NameListRef
implGetNameList( const OUString
& rListName
) const;
894 typedef std::shared_ptr
< SharedConfigData
> SharedConfigDataRef
;
895 SharedConfigDataRef mxCfgData
;
898 typedef std::shared_ptr
< Config
> ConfigRef
;
901 template< typename Type
>
902 Type
Config::getIntOption( const String
& rKey
, Type nDefault
) const
905 const OUString
* pData
= implGetOption( rKey
);
906 return (pData
&& StringHelper::convertStringToInt( nRawData
, *pData
)) ?
907 static_cast< Type
>( nRawData
) : nDefault
;
910 template< typename ListType
>
911 std::shared_ptr
< ListType
> Config::createNameList( const String
& rListName
)
913 return mxCfgData
->createNameList
< ListType
>( rListName
);
916 template< typename Type
>
917 OUString
Config::getName( const NameListWrapper
& rListWrp
, Type nKey
) const
919 NameListRef xList
= rListWrp
.getNameList( *this );
920 return xList
.get() ? xList
->getName( *this, nKey
) : OOX_DUMP_ERR_NOMAP
;
923 template< typename Type
>
924 bool Config::hasName( const NameListWrapper
& rListWrp
, Type nKey
) const
926 NameListRef xList
= rListWrp
.getNameList( *this );
927 return xList
.get() && xList
->hasName( nKey
);
931 class Output
: public Base
935 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
936 const OUString
& rFileName
);
940 void emptyLine( size_t nCount
= 1 );
945 void startTable( sal_Int32 nW1
);
946 void startTable( sal_Int32 nW1
, sal_Int32 nW2
);
947 void startTable( sal_Int32 nW1
, sal_Int32 nW2
, sal_Int32 nW3
, sal_Int32 nW4
);
948 void startTable( size_t nColCount
, const sal_Int32
* pnColWidths
);
950 void tab( size_t nCol
);
953 void resetItemIndex( sal_Int64 nIdx
= 0 );
954 void startItem( const String
& rItemName
);
958 void startMultiItems();
959 void endMultiItems();
961 void writeChar( sal_Unicode cChar
, sal_Int32 nCount
= 1 );
962 void writeAscii( const sal_Char
* pcStr
);
963 void writeString( const OUString
& rStr
);
964 void writeArray( const sal_uInt8
* pnData
, sal_Size nSize
, sal_Unicode cSep
= OOX_DUMP_LISTSEP
);
965 void writeBool( bool bData
);
966 void writeDateTime( const css::util::DateTime
& rDateTime
);
968 template< typename Type
>
969 void writeDec( Type nData
, sal_Int32 nWidth
= 0, sal_Unicode cFill
= ' ' )
970 { StringHelper::appendDec( maLine
, nData
, nWidth
, cFill
); }
971 template< typename Type
>
972 void writeHex( Type nData
, bool bPrefix
= true )
973 { StringHelper::appendHex( maLine
, nData
, bPrefix
); }
974 template< typename Type
>
975 void writeShortHex( Type nData
, bool bPrefix
= true )
976 { StringHelper::appendShortHex( maLine
, nData
, bPrefix
); }
977 template< typename Type
>
978 void writeBin( Type nData
, bool bDots
= true )
979 { StringHelper::appendBin( maLine
, nData
, bDots
); }
980 template< typename Type
>
981 void writeFix( Type nData
, sal_Int32 nWidth
= 0 )
982 { StringHelper::appendFix( maLine
, nData
, nWidth
); }
983 template< typename Type
>
984 void writeValue( Type nData
, FormatType eFmtType
)
985 { StringHelper::appendValue( maLine
, nData
, eFmtType
); }
986 template< typename Type
>
987 void writeName( const Config
& rCfg
, Type nData
, const NameListWrapper
& rListWrp
)
988 { writeString( rCfg
.getName( rListWrp
, nData
) ); }
992 virtual bool implIsValid() const override
;
995 void writeItemName( const String
& rItemName
);
998 typedef ::std::vector
< sal_Int32
> StringLenVec
;
1000 css::uno::Reference
< css::io::XTextOutputStream2
> mxStrm
;
1002 OUStringBuffer maLine
;
1003 OUString maLastItem
;
1004 StringLenVec maColPos
;
1007 size_t mnMultiLevel
;
1008 sal_Int64 mnItemIdx
;
1009 sal_Int32 mnLastItem
;
1012 typedef std::shared_ptr
< Output
> OutputRef
;
1018 explicit IndentGuard( const OutputRef
& rxOut
) : mrOut( *rxOut
) { mrOut
.incIndent(); }
1019 ~IndentGuard() { mrOut
.decIndent(); }
1021 IndentGuard( const IndentGuard
& ) = delete;
1022 IndentGuard
& operator=( const IndentGuard
& ) = delete;
1031 explicit TableGuard( const OutputRef
& rxOut
, sal_Int32 nW1
) :
1032 mrOut( *rxOut
) { mrOut
.startTable( nW1
); }
1033 explicit TableGuard( const OutputRef
& rxOut
, sal_Int32 nW1
, sal_Int32 nW2
) :
1034 mrOut( *rxOut
) { mrOut
.startTable( nW1
, nW2
); }
1035 explicit TableGuard( const OutputRef
& rxOut
, sal_Int32 nW1
, sal_Int32 nW2
, sal_Int32 nW3
, sal_Int32 nW4
) :
1036 mrOut( *rxOut
) { mrOut
.startTable( nW1
, nW2
, nW3
, nW4
); }
1037 explicit TableGuard( const OutputRef
& rxOut
, size_t nColCount
,
1038 const sal_Int32
* pnColWidths
) :
1039 mrOut( *rxOut
) { mrOut
.startTable( nColCount
, pnColWidths
); }
1040 ~TableGuard() { mrOut
.endTable(); }
1041 void tab( size_t nCol
) { mrOut
.tab( nCol
); }
1043 TableGuard( const TableGuard
& ) = delete;
1044 TableGuard
& operator=( const TableGuard
& ) = delete;
1053 explicit ItemGuard( const OutputRef
& rxOut
, const String
& rName
= EMPTY_STRING
) :
1054 mrOut( *rxOut
) { mrOut
.startItem( rName
); }
1055 ~ItemGuard() { mrOut
.endItem(); }
1056 void cont() { mrOut
.contItem(); }
1058 ItemGuard( const ItemGuard
& ) = delete;
1059 ItemGuard
& operator=( const ItemGuard
& ) = delete;
1065 class MultiItemsGuard
1068 explicit MultiItemsGuard( const OutputRef
& rxOut
) : mrOut( *rxOut
) { mrOut
.startMultiItems(); }
1069 ~MultiItemsGuard() { mrOut
.endMultiItems(); }
1071 MultiItemsGuard( const MultiItemsGuard
& ) = delete;
1072 MultiItemsGuard
& operator=( const MultiItemsGuard
& ) = delete;
1078 class StorageIterator
: public Base
1081 explicit StorageIterator( const StorageRef
& rxStrg
);
1082 virtual ~StorageIterator();
1084 StorageIterator
& operator++();
1086 OUString
getName() const;
1087 bool isStream() const;
1088 bool isStorage() const;
1091 virtual bool implIsValid() const override
;
1095 OUStringVector maNames
;
1096 OUStringVector::const_iterator maIt
;
1100 class ObjectBase
: public Base
1103 virtual ~ObjectBase();
1105 const css::uno::Reference
< css::uno::XComponentContext
>&
1106 getContext() const { return mxConfig
->getContext(); }
1114 void construct( const ConfigRef
& rxConfig
);
1115 void construct( const ObjectBase
& rParent
);
1117 virtual bool implIsValid() const override
;
1118 virtual void implDump();
1121 Config
& cfg() const { return *mxConfig
; }
1127 typedef std::shared_ptr
< ObjectBase
> ObjectRef
;
1130 class StorageObjectBase
: public ObjectBase
1133 StorageObjectBase() {}
1136 using ObjectBase::construct
;
1137 void construct( const ObjectBase
& rParent
, const StorageRef
& rxStrg
, const OUString
& rSysPath
);
1138 void construct( const ObjectBase
& rParent
);
1140 virtual bool implIsValid() const override
;
1141 virtual void implDump() override
;
1143 virtual void implDumpStream(
1144 const css::uno::Reference
< css::io::XInputStream
>& rxStrm
,
1145 const OUString
& rStrgPath
,
1146 const OUString
& rStrmName
,
1147 const OUString
& rSysFileName
);
1149 virtual void implDumpStorage(
1150 const StorageRef
& rxStrg
,
1151 const OUString
& rStrgPath
,
1152 const OUString
& rSysPath
);
1154 virtual void implDumpBaseStream(
1155 const BinaryInputStreamRef
& rxStrm
,
1156 const OUString
& rSysFileName
);
1158 void addPreferredStream( const String
& rStrmName
);
1159 void addPreferredStorage( const String
& rStrgPath
);
1162 static OUString
getSysFileName(
1163 const OUString
& rStrmName
,
1164 const OUString
& rSysOutPath
);
1168 const OUString
& rStrgPath
,
1169 const OUString
& rStrmName
,
1170 const OUString
& rSysFileName
);
1171 void extractStorage(
1172 const StorageRef
& rxStrg
,
1173 const OUString
& rStrgPath
,
1174 const OUString
& rSysPath
);
1177 const StorageRef
& rxStrg
,
1178 const OUString
& rStrgPath
,
1179 const OUString
& rItemName
,
1180 const OUString
& rSysPath
,
1181 bool bIsStrg
, bool bIsStrm
);
1184 struct PreferredItem
1189 explicit PreferredItem( const OUString
& rName
, bool bStorage
) :
1190 maName( rName
), mbStorage( bStorage
) {}
1192 typedef ::std::vector
< PreferredItem
> PreferredItemVector
;
1196 PreferredItemVector maPreferred
;
1200 class OutputObjectBase
: public ObjectBase
1203 virtual ~OutputObjectBase();
1207 OutputObjectBase() {}
1209 using ObjectBase::construct
;
1210 void construct( const ObjectBase
& rParent
, const OUString
& rSysFileName
);
1211 void construct( const OutputObjectBase
& rParent
);
1213 virtual bool implIsValid() const override
;
1216 void writeEmptyItem( const String
& rName
);
1217 void writeInfoItem( const String
& rName
, const String
& rData
);
1218 void writeCharItem( const String
& rName
, sal_Unicode cData
);
1219 void writeStringItem( const String
& rName
, const OUString
& rData
);
1220 void writeArrayItem( const String
& rName
, const sal_uInt8
* pnData
, sal_Size nSize
, sal_Unicode cSep
= OOX_DUMP_LISTSEP
);
1221 void writeDateTimeItem( const String
& rName
, const css::util::DateTime
& rDateTime
);
1222 void writeGuidItem( const String
& rName
, const OUString
& rGuid
);
1224 template< typename Type
>
1225 void addNameToItem( Type nData
, const NameListWrapper
& rListWrp
);
1227 template< typename Type
>
1228 void writeNameItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
);
1229 template< typename Type
>
1230 void writeDecItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
= NO_LIST
);
1231 template< typename Type
>
1232 void writeHexItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
= NO_LIST
);
1233 template< typename Type
>
1234 void writeShortHexItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
= NO_LIST
);
1235 template< typename Type
>
1236 void writeBinItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
= NO_LIST
);
1237 template< typename Type
>
1238 void writeFixItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
= NO_LIST
);
1239 template< typename Type
>
1240 void writeDecBoolItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
= NO_LIST
);
1241 template< typename Type
>
1242 void writeValueItem( const String
& rName
, Type nData
, FormatType eFmtType
, const NameListWrapper
& rListWrp
= NO_LIST
);
1244 template< typename Type
>
1245 void writeValueItem( const ItemFormat
& rItemFmt
, Type nData
);
1247 template< typename Type
>
1248 void writeDecPairItem( const String
& rName
, Type nData1
, Type nData2
, sal_Unicode cSep
= ',' );
1249 template< typename Type
>
1250 void writeHexPairItem( const String
& rName
, Type nData1
, Type nData2
, sal_Unicode cSep
= ',' );
1254 OUString maSysFileName
;
1258 template< typename Type
>
1259 void OutputObjectBase::addNameToItem( Type nData
, const NameListWrapper
& rListWrp
)
1261 if( !rListWrp
.isEmpty() )
1264 mxOut
->writeName( cfg(), nData
, rListWrp
);
1268 template< typename Type
>
1269 void OutputObjectBase::writeNameItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
)
1271 ItemGuard
aItem( mxOut
, rName
);
1272 mxOut
->writeName( cfg(), nData
, rListWrp
);
1275 template< typename Type
>
1276 void OutputObjectBase::writeDecItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
)
1278 ItemGuard
aItem( mxOut
, rName
);
1279 mxOut
->writeDec( nData
);
1280 addNameToItem( nData
, rListWrp
);
1283 template< typename Type
>
1284 void OutputObjectBase::writeHexItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
)
1286 ItemGuard
aItem( mxOut
, rName
);
1287 mxOut
->writeHex( nData
);
1288 addNameToItem( nData
, rListWrp
);
1291 template< typename Type
>
1292 void OutputObjectBase::writeShortHexItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
)
1294 ItemGuard
aItem( mxOut
, rName
);
1295 mxOut
->writeShortHex( nData
);
1296 addNameToItem( nData
, rListWrp
);
1299 template< typename Type
>
1300 void OutputObjectBase::writeBinItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
)
1302 ItemGuard
aItem( mxOut
, rName
);
1303 mxOut
->writeBin( nData
);
1304 addNameToItem( nData
, rListWrp
);
1307 template< typename Type
>
1308 void OutputObjectBase::writeFixItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
)
1310 ItemGuard
aItem( mxOut
, rName
);
1311 mxOut
->writeFix( nData
);
1312 addNameToItem( nData
, rListWrp
);
1315 template< typename Type
>
1316 void OutputObjectBase::writeDecBoolItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
)
1318 ItemGuard
aItem( mxOut
, rName
);
1319 mxOut
->writeDec( nData
);
1321 mxOut
->writeBool( nData
!= 0 );
1322 addNameToItem( nData
, rListWrp
);
1325 template< typename Type
>
1326 void OutputObjectBase::writeValueItem( const String
& rName
, Type nData
, FormatType eFmtType
, const NameListWrapper
& rListWrp
)
1328 if( eFmtType
== FORMATTYPE_BOOL
)
1329 writeDecBoolItem( rName
, nData
, rListWrp
);
1332 ItemGuard
aItem( mxOut
, rName
);
1333 mxOut
->writeValue( nData
, eFmtType
);
1334 addNameToItem( nData
, rListWrp
);
1338 template< typename Type
>
1339 void OutputObjectBase::writeValueItem( const ItemFormat
& rItemFmt
, Type nData
)
1341 OString aNameUtf8
= StringHelper::convertToUtf8( rItemFmt
.maItemName
);
1342 writeValueItem( aNameUtf8
.getStr(), nData
, rItemFmt
.meFmtType
, rItemFmt
.maListName
);
1345 template< typename Type
>
1346 void OutputObjectBase::writeDecPairItem( const String
& rName
, Type nData1
, Type nData2
, sal_Unicode cSep
)
1348 ItemGuard
aItem( mxOut
, rName
);
1349 mxOut
->writeDec( nData1
);
1350 mxOut
->writeChar( cSep
);
1351 mxOut
->writeDec( nData2
);
1354 template< typename Type
>
1355 void OutputObjectBase::writeHexPairItem( const String
& rName
, Type nData1
, Type nData2
, sal_Unicode cSep
)
1357 ItemGuard
aItem( mxOut
, rName
);
1358 mxOut
->writeHex( nData1
);
1359 mxOut
->writeChar( cSep
);
1360 mxOut
->writeHex( nData2
);
1364 class InputObjectBase
: public OutputObjectBase
1367 virtual ~InputObjectBase();
1371 InputObjectBase() {}
1373 using OutputObjectBase::construct
;
1374 void construct( const ObjectBase
& rParent
, const BinaryInputStreamRef
& rxStrm
, const OUString
& rSysFileName
);
1375 void construct( const OutputObjectBase
& rParent
, const BinaryInputStreamRef
& rxStrm
);
1376 void construct( const InputObjectBase
& rParent
);
1378 virtual bool implIsValid() const override
;
1380 void skipBlock( sal_Int64 nBytes
, bool bShowSize
= true );
1381 void dumpRawBinary( sal_Int64 nBytes
, bool bShowOffset
= true, bool bStream
= false );
1383 void dumpBinary( const String
& rName
, sal_Int64 nBytes
, bool bShowOffset
= true );
1384 void dumpRemaining( sal_Int64 nBytes
);
1385 void dumpRemainingTo( sal_Int64 nPos
);
1386 void dumpRemainingStream();
1388 void dumpArray( const String
& rName
, sal_Int32 nBytes
, sal_Unicode cSep
= OOX_DUMP_LISTSEP
);
1389 void dumpUnused( sal_Int32 nBytes
) { dumpArray( OOX_DUMP_UNUSED
, nBytes
); }
1390 void dumpUnknown( sal_Int32 nBytes
) { dumpArray( OOX_DUMP_UNKNOWN
, nBytes
); }
1392 sal_Unicode
dumpUnicode( const String
& rName
);
1394 OUString
dumpCharArray( const String
& rName
, sal_Int32 nLen
, rtl_TextEncoding eTextEnc
, bool bHideTrailingNul
= false );
1395 OUString
dumpUnicodeArray( const String
& rName
, sal_Int32 nLen
, bool bHideTrailingNul
= false );
1397 css::util::DateTime
dumpFileTime( const String
& rName
= EMPTY_STRING
);
1398 OUString
dumpGuid( const String
& rName
= EMPTY_STRING
);
1400 void dumpItem( const ItemFormat
& rItemFmt
);
1402 template< typename Type
>
1403 Type
dumpName( const String
& rName
, const NameListWrapper
& rListWrp
);
1404 template< typename Type
>
1405 Type
dumpDec( const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1406 template< typename Type
>
1407 Type
dumpHex( const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1408 template< typename Type
>
1409 Type
dumpBin( const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1410 template< typename Type
>
1411 Type
dumpFix( const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1412 template< typename Type
>
1413 Type
dumpBool( const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1414 template< typename Type
>
1415 Type
dumpValue( const ItemFormat
& rItemFmt
);
1417 template< typename Type1
, typename Type2
>
1418 Type1
dumpName( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1419 template< typename Type1
, typename Type2
>
1420 Type1
dumpDec( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1421 template< typename Type1
, typename Type2
>
1422 Type1
dumpHex( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1423 template< typename Type1
, typename Type2
>
1424 Type1
dumpBin( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1425 template< typename Type1
, typename Type2
>
1426 Type1
dumpFix( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1427 template< typename Type1
, typename Type2
>
1428 Type1
dumpBool( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1429 template< typename Type1
, typename Type2
>
1430 Type1
dumpValue( bool bType1
, const ItemFormat
& rItemFmt
);
1432 template< typename Type
>
1433 void dumpDecPair( const String
& rName
, sal_Unicode cSep
= ',' );
1434 template< typename Type
>
1435 void dumpHexPair( const String
& rName
, sal_Unicode cSep
= ',' );
1438 BinaryInputStreamRef mxStrm
;
1442 template< typename Type
>
1443 Type
InputObjectBase::dumpName( const String
& rName
, const NameListWrapper
& rListWrp
)
1445 Type nData
= mxStrm
->readValue
<Type
>();
1446 writeNameItem( rName
, nData
, rListWrp
);
1450 template< typename Type
>
1451 Type
InputObjectBase::dumpDec( const String
& rName
, const NameListWrapper
& rListWrp
)
1453 Type nData
= mxStrm
->readValue
<Type
>();
1454 writeDecItem( rName
, nData
, rListWrp
);
1458 template< typename Type
>
1459 Type
InputObjectBase::dumpHex( const String
& rName
, const NameListWrapper
& rListWrp
)
1461 Type nData
= mxStrm
->readValue
<Type
>();
1462 writeHexItem( rName
, nData
, rListWrp
);
1466 template< typename Type
>
1467 Type
InputObjectBase::dumpBin( const String
& rName
, const NameListWrapper
& rListWrp
)
1469 Type nData
= mxStrm
->readValue
<Type
>();
1470 writeBinItem( rName
, nData
, rListWrp
);
1474 template< typename Type
>
1475 Type
InputObjectBase::dumpFix( const String
& rName
, const NameListWrapper
& rListWrp
)
1477 Type nData
= mxStrm
->readValue
<Type
>();
1478 writeFixItem( rName
, nData
, rListWrp
);
1482 template< typename Type
>
1483 Type
InputObjectBase::dumpBool( const String
& rName
, const NameListWrapper
& rListWrp
)
1485 Type nData
= mxStrm
->readValue
<Type
>();
1486 writeDecBoolItem( rName
, nData
, rListWrp
);
1490 template< typename Type
>
1491 Type
InputObjectBase::dumpValue( const ItemFormat
& rItemFmt
)
1493 Type nData
= mxStrm
->readValue
<Type
>();
1494 writeValueItem( rItemFmt
, nData
);
1498 template< typename Type1
, typename Type2
>
1499 Type1
InputObjectBase::dumpName( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
)
1501 return bType1
? dumpName
< Type1
>( rName
, rListWrp
) : static_cast< Type1
>( dumpName
< Type2
>( rName
, rListWrp
) );
1504 template< typename Type1
, typename Type2
>
1505 Type1
InputObjectBase::dumpDec( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
)
1507 return bType1
? dumpDec
< Type1
>( rName
, rListWrp
) : static_cast< Type1
>( dumpDec
< Type2
>( rName
, rListWrp
) );
1510 template< typename Type1
, typename Type2
>
1511 Type1
InputObjectBase::dumpHex( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
)
1513 return bType1
? dumpHex
< Type1
>( rName
, rListWrp
) : static_cast< Type1
>( dumpHex
< Type2
>( rName
, rListWrp
) );
1516 template< typename Type1
, typename Type2
>
1517 Type1
InputObjectBase::dumpBin( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
)
1519 return bType1
? dumpBin
< Type1
>( rName
, rListWrp
) : static_cast< Type1
>( dumpBin
< Type2
>( rName
, rListWrp
) );
1522 template< typename Type1
, typename Type2
>
1523 Type1
InputObjectBase::dumpFix( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
)
1525 return bType1
? dumpFix
< Type1
>( rName
, rListWrp
) : static_cast< Type1
>( dumpFix
< Type2
>( rName
, rListWrp
) );
1528 template< typename Type1
, typename Type2
>
1529 Type1
InputObjectBase::dumpBool( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
)
1531 return bType1
? dumpBool
< Type1
>( rName
, rListWrp
) : static_cast< Type1
>( dumpBool
< Type2
>( rName
, rListWrp
) );
1534 template< typename Type1
, typename Type2
>
1535 Type1
InputObjectBase::dumpValue( bool bType1
, const ItemFormat
& rItemFmt
)
1537 return bType1
? dumpValue
< Type1
>( rItemFmt
) : static_cast< Type1
>( dumpValue
< Type2
>( rItemFmt
) );
1540 template< typename Type
>
1541 void InputObjectBase::dumpDecPair( const String
& rName
, sal_Unicode cSep
)
1543 Type nData1
, nData2
;
1544 *mxStrm
>> nData1
>> nData2
;
1545 writeDecPairItem( rName
, nData1
, nData2
, cSep
);
1548 template< typename Type
>
1549 void InputObjectBase::dumpHexPair( const String
& rName
, sal_Unicode cSep
)
1551 Type nData1
, nData2
;
1552 *mxStrm
>> nData1
>> nData2
;
1553 writeHexPairItem( rName
, nData1
, nData2
, cSep
);
1557 class BinaryStreamObject
: public InputObjectBase
1560 explicit BinaryStreamObject(
1561 const ObjectBase
& rParent
,
1562 const BinaryInputStreamRef
& rxStrm
,
1563 const OUString
& rSysFileName
);
1566 void dumpBinaryStream( bool bShowOffset
= true );
1568 virtual void implDump() override
;
1572 class TextStreamObjectBase
: public InputObjectBase
1575 TextStreamObjectBase() {}
1577 using InputObjectBase::construct
;
1579 const ObjectBase
& rParent
,
1580 const BinaryInputStreamRef
& rxStrm
,
1581 rtl_TextEncoding eTextEnc
,
1582 const OUString
& rSysFileName
);
1584 const OutputObjectBase
& rParent
,
1585 const BinaryInputStreamRef
& rxStrm
,
1586 rtl_TextEncoding eTextEnc
);
1588 virtual bool implIsValid() const override
;
1589 virtual void implDump() override
;
1591 virtual void implDumpText( TextInputStream
& rTextStrm
) = 0;
1594 void constructTextStrmObj( rtl_TextEncoding eTextEnc
);
1597 std::shared_ptr
< TextInputStream
> mxTextStrm
;
1601 class TextLineStreamObject
: public TextStreamObjectBase
1604 explicit TextLineStreamObject(
1605 const ObjectBase
& rParent
,
1606 const BinaryInputStreamRef
& rxStrm
,
1607 rtl_TextEncoding eTextEnc
,
1608 const OUString
& rSysFileName
);
1610 explicit TextLineStreamObject(
1611 const OutputObjectBase
& rParent
,
1612 const BinaryInputStreamRef
& rxStrm
,
1613 rtl_TextEncoding eTextEnc
);
1616 virtual void implDumpText( TextInputStream
& rTextStrm
) override
;
1617 void implDumpLine( const OUString
& rLine
, sal_uInt32 nLine
);
1621 class XmlStreamObject
: public TextStreamObjectBase
1624 explicit XmlStreamObject(
1625 const ObjectBase
& rParent
,
1626 const BinaryInputStreamRef
& rxStrm
,
1627 const OUString
& rSysFileName
);
1630 virtual void implDumpText( TextInputStream
& rTextStrm
) override
;
1634 class RecordObjectBase
: public InputObjectBase
1637 RecordObjectBase() {}
1639 using InputObjectBase::construct
;
1641 const ObjectBase
& rParent
,
1642 const BinaryInputStreamRef
& rxBaseStrm
,
1643 const OUString
& rSysFileName
,
1644 const BinaryInputStreamRef
& rxRecStrm
,
1645 const String
& rRecNames
,
1646 const String
& rSimpleRecs
= EMPTY_STRING
);
1648 sal_Int64
getRecId() const { return mnRecId
; }
1649 sal_Int64
getRecSize() const { return mnRecSize
; }
1650 NameListRef
getRecNames() const { return maRecNames
.getNameList( cfg() ); }
1652 virtual bool implIsValid() const override
;
1653 virtual void implDump() override
;
1655 virtual bool implStartRecord( BinaryInputStream
& rBaseStrm
, sal_Int64
& ornRecPos
, sal_Int64
& ornRecId
, sal_Int64
& ornRecSize
) = 0;
1656 virtual void implWriteExtHeader();
1657 virtual void implDumpRecordBody();
1660 void constructRecObjBase(
1661 const BinaryInputStreamRef
& rxBaseStrm
,
1662 const String
& rRecNames
,
1663 const String
& rSimpleRecs
);
1668 BinaryInputStreamRef mxBaseStrm
;
1669 NameListWrapper maRecNames
;
1670 NameListWrapper maSimpleRecs
;
1673 sal_Int64 mnRecSize
;
1679 class SequenceRecordObjectBase
: public RecordObjectBase
1682 SequenceRecordObjectBase() : mxRecData( new StreamDataSequence
) {}
1684 using RecordObjectBase::construct
;
1686 const ObjectBase
& rParent
,
1687 const BinaryInputStreamRef
& rxBaseStrm
,
1688 const OUString
& rSysFileName
,
1689 const String
& rRecNames
,
1690 const String
& rSimpleRecs
= EMPTY_STRING
);
1692 virtual bool implStartRecord( BinaryInputStream
& rBaseStrm
, sal_Int64
& ornRecPos
, sal_Int64
& ornRecId
, sal_Int64
& ornRecSize
) override
;
1693 virtual bool implReadRecordHeader( BinaryInputStream
& rBaseStrm
, sal_Int64
& ornRecId
, sal_Int64
& ornRecSize
) = 0;
1696 typedef std::shared_ptr
< StreamDataSequence
> StreamDataSeqRef
;
1697 StreamDataSeqRef mxRecData
;
1701 /** Base class for a file dumper. Derived classes implement the implDump()
1702 function to add functionality.
1704 class DumperBase
: public ObjectBase
1707 virtual ~DumperBase();
1709 bool isImportEnabled() const;
1710 bool isImportCancelled() const;
1715 using ObjectBase::construct
;
1716 void construct( const ConfigRef
& rxConfig
);
1723 #define OOX_DUMP_FILE( DumperClassName ) \
1725 DumperClassName aDumper( *this ); \
1727 bool bCancelled = aDumper.isImportCancelled(); \
1728 if( !aDumper.isImportEnabled() || bCancelled ) \
1729 return aDumper.isValid() && !bCancelled; \
1732 #else // OOX_INCLUDE_DUMPER
1734 #define OOX_DUMP_FILE( DumperClassName ) (void)0
1736 #endif // OOX_INCLUDE_DUMPER
1739 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */