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
, sal_Int64 nIdx
);
325 static OUString
getToken( const OUString
& rData
, sal_Int32
& rnPos
, sal_Unicode cSep
= OOX_DUMP_LISTSEP
);
327 /** Encloses the passed string with the passed characters. Uses cOpen, if cClose is NUL. */
328 static void enclose( OUStringBuffer
& rStr
, sal_Unicode cOpen
, sal_Unicode cClose
= '\0' );
330 // string conversion ------------------------------------------------------
332 static OUString
trimSpaces( const OUString
& rStr
);
333 static OUString
trimTrailingNul( const OUString
& rStr
);
335 static OString
convertToUtf8( const OUString
& rStr
);
336 static DataType
convertToDataType( const OUString
& rStr
);
337 static FormatType
convertToFormatType( const OUString
& rStr
);
339 static bool convertFromDec( sal_Int64
& ornData
, const OUString
& rData
);
340 static bool convertFromHex( sal_Int64
& ornData
, const OUString
& rData
);
342 static bool convertStringToInt( sal_Int64
& ornData
, const OUString
& rData
);
343 static bool convertStringToDouble( double& orfData
, const OUString
& rData
);
344 static bool convertStringToBool( const OUString
& rData
);
346 static OUStringPair
convertStringToPair( const OUString
& rString
, sal_Unicode cSep
= '=' );
348 // string to list conversion ----------------------------------------------
350 static void convertStringToStringList( OUStringVector
& orVec
, const OUString
& rData
, bool bIgnoreEmpty
);
351 static void convertStringToIntList( Int64Vector
& orVec
, const OUString
& rData
, bool bIgnoreEmpty
);
355 template< typename Type
>
356 void StringHelper::appendFix( OUStringBuffer
& rStr
, Type nData
, sal_Int32 nWidth
)
358 appendDec( rStr
, static_cast< double >( nData
) / std::pow( 2.0, 4.0 * sizeof( Type
) ), nWidth
);
361 template< typename Type
>
362 void StringHelper::appendValue( OUStringBuffer
& rStr
, Type nData
, FormatType eFmtType
)
366 case FORMATTYPE_DEC
: appendDec( rStr
, nData
); break;
367 case FORMATTYPE_HEX
: appendHex( rStr
, nData
); break;
368 case FORMATTYPE_SHORTHEX
: appendShortHex( rStr
, nData
); break;
369 case FORMATTYPE_BIN
: appendBin( rStr
, nData
); break;
370 case FORMATTYPE_FIX
: appendFix( rStr
, nData
); break;
371 case FORMATTYPE_BOOL
: appendBool( rStr
, nData
); break;
377 class String
: public OUString
381 /*implicit*/ String( const OUString
& rStr
) : OUString( rStr
) {}
382 /*implicit*/ String( const sal_Char
* pcStr
) : OUString( OUString::createFromAscii( pcStr
? pcStr
: "" ) ) {}
383 /*implicit*/ String( sal_Unicode cChar
) : OUString( cChar
) {}
385 bool has() const { return getLength() > 0; }
386 OUString
operator()( const sal_Char
* pcDefault
) const { if( has() ) return *this; return String( pcDefault
); }
389 static const String EMPTY_STRING
;
392 /** Base class for all dumper classes.
394 Derived classes implement the virtual function implIsValid(). It should
395 check all members the other functions rely on. If the function
396 implIsValid() returns true, all references and pointers can be used without
399 Overview of all classes in this header file based on this Base class:
405 | +----> ConstList ------> MultiList
407 | +----> FlagsList ------> CombiList
409 | +----> UnitConverter
411 +----> SharedConfigData
417 +----> StorageIterator
421 +----> StorageObjectBase
423 +----> OutputObjectBase
425 | +----> InputObjectBase
427 | +----> BinaryStreamObject
429 | +----> TextStreamObjectBase
431 | | +----> TextStreamObject
433 | | +----> XmlStreamObject
435 | +----> RecordObjectBase
437 | +----> SequenceRecordObjectBase
446 bool isValid() const { return implIsValid(); }
447 static bool isValid( const std::shared_ptr
< Base
>& rxBase
) { return rxBase
.get() && rxBase
->isValid(); }
452 virtual bool implIsValid() const = 0;
459 virtual ~ConfigItemBase();
460 void readConfigBlock( TextInputStream
& rStrm
);
465 virtual void implProcessConfigItemStr(
466 TextInputStream
& rStrm
,
467 const OUString
& rKey
,
468 const OUString
& rData
);
470 virtual void implProcessConfigItemInt(
471 TextInputStream
& rStrm
,
473 const OUString
& rData
);
475 void readConfigBlockContents(
476 TextInputStream
& rStrm
);
479 enum LineType
{ LINETYPE_DATA
, LINETYPE_END
};
481 static LineType
readConfigLine(
482 TextInputStream
& rStrm
,
486 void processConfigItem(
487 TextInputStream
& rStrm
,
488 const OUString
& rKey
,
489 const OUString
& rData
);
493 class SharedConfigData
;
497 typedef std::shared_ptr
< NameListBase
> NameListRef
;
499 /** Base class of all classes providing names for specific values (name lists).
501 The idea is to provide a unique interface for all different methods to
502 write specific names for any values. This can be enumerations (dedicated
503 names for a subset of values), or names for bits in bit fields. Classes
504 derived from this base class implement the specific behaviour for the
507 class NameListBase
: public Base
, public ConfigItemBase
510 typedef ::std::map
< sal_Int64
, OUString
> OUStringMap
;
511 typedef OUStringMap::const_iterator const_iterator
;
514 virtual ~NameListBase() override
;
516 /** Sets a name for the specified key. */
517 void setName( sal_Int64 nKey
, const String
& rName
);
519 /** Include all names of the passed list. */
520 void includeList( const NameListRef
& rxList
);
522 /** Returns true, if the map contains an entry for the passed key. */
523 template< typename Type
>
524 bool hasName( Type nKey
) const
525 { return maMap
.count( static_cast< sal_Int64
>( nKey
) ) != 0; }
527 /** Returns the name for the passed key. */
528 template< typename Type
>
529 OUString
getName( const Config
& rCfg
, Type nKey
) const
530 { return implGetName( rCfg
, static_cast< sal_Int64
>( nKey
) ); }
532 /** Returns a display name for the passed double value. */
533 OUString
getName( const Config
& rCfg
, double fValue
) const
534 { return implGetNameDbl( rCfg
, fValue
); }
536 /** Returns a map iterator pointing to the first contained name. */
537 const_iterator
begin() const { return maMap
.begin(); }
538 /** Returns a map iterator pointing one past the last contained name. */
539 const_iterator
end() const { return maMap
.end(); }
542 explicit NameListBase( const SharedConfigData
& rCfgData
) : mrCfgData( rCfgData
) {}
544 virtual bool implIsValid() const override
;
546 virtual void implProcessConfigItemStr(
547 TextInputStream
& rStrm
,
548 const OUString
& rKey
,
549 const OUString
& rData
) override
;
551 virtual void implProcessConfigItemInt(
552 TextInputStream
& rStrm
,
554 const OUString
& rData
) override
;
556 /** Derived classes set the name for the passed key. */
557 virtual void implSetName( sal_Int64 nKey
, const OUString
& rName
) = 0;
558 /** Derived classes generate and return the name for the passed key. */
559 virtual OUString
implGetName( const Config
& rCfg
, sal_Int64 nKey
) const = 0;
560 /** Derived classes generate and return the name for the passed double value. */
561 virtual OUString
implGetNameDbl( const Config
& rCfg
, double fValue
) const = 0;
562 /** Derived classes insert all names and other settings from the passed list. */
563 virtual void implIncludeList( const NameListBase
& rList
) = 0;
565 /** Inserts the passed name into the internal map. */
566 void insertRawName( sal_Int64 nKey
, const OUString
& rName
);
567 /** Returns the name for the passed key, or 0, if nothing found. */
568 const OUString
* findRawName( sal_Int64 nKey
) const;
571 /** Includes name lists, given in a comma separated list of names of the lists. */
572 void include( const OUString
& rListKeys
);
573 /** Excludes names from the list, given in a comma separated list of their keys. */
574 void exclude( const OUString
& rKeys
);
578 const SharedConfigData
& mrCfgData
;
582 class ConstList
: public NameListBase
585 explicit ConstList( const SharedConfigData
& rCfgData
);
587 /** Enables or disables automatic quotation of returned names. */
588 void setQuoteNames( bool bQuoteNames
) { mbQuoteNames
= bQuoteNames
; }
591 virtual void implProcessConfigItemStr(
592 TextInputStream
& rStrm
,
593 const OUString
& rKey
,
594 const OUString
& rData
) override
;
596 /** Sets the name for the passed key. */
597 virtual void implSetName( sal_Int64 nKey
, const OUString
& rName
) override
;
598 /** Returns the name for the passed key, or the default name, if key is not contained. */
599 virtual OUString
implGetName( const Config
& rCfg
, sal_Int64 nKey
) const override
;
600 /** Returns the name for the passed double value. */
601 virtual OUString
implGetNameDbl( const Config
& rCfg
, double fValue
) const override
;
602 /** Inserts all names from the passed list. */
603 virtual void implIncludeList( const NameListBase
& rList
) override
;
611 class MultiList
: public ConstList
614 explicit MultiList( const SharedConfigData
& rCfgData
);
616 void setNamesFromVec( sal_Int64 nStartKey
, const OUStringVector
& rNames
);
619 virtual void implProcessConfigItemStr(
620 TextInputStream
& rStrm
,
621 const OUString
& rKey
,
622 const OUString
& rData
) override
;
624 virtual void implSetName( sal_Int64 nKey
, const OUString
& rName
) override
;
631 class FlagsList
: public NameListBase
634 explicit FlagsList( const SharedConfigData
& rCfgData
);
636 /** Returns the flags to be ignored on output. */
637 sal_Int64
getIgnoreFlags() const { return mnIgnore
; }
638 /** Sets flags to be ignored on output. */
639 void setIgnoreFlags( sal_Int64 nIgnore
) { mnIgnore
= nIgnore
; }
642 virtual void implProcessConfigItemStr(
643 TextInputStream
& rStrm
,
644 const OUString
& rKey
,
645 const OUString
& rData
) override
;
647 /** Sets the name for the passed key. */
648 virtual void implSetName( sal_Int64 nKey
, const OUString
& rName
) override
;
649 /** Returns the name for the passed key. */
650 virtual OUString
implGetName( const Config
& rCfg
, sal_Int64 nKey
) const override
;
651 /** Returns the name for the passed double value. */
652 virtual OUString
implGetNameDbl( const Config
& rCfg
, double fValue
) const override
;
653 /** Inserts all flags from the passed list. */
654 virtual void implIncludeList( const NameListBase
& rList
) override
;
661 class CombiList
: public FlagsList
664 explicit CombiList( const SharedConfigData
& rCfgData
);
667 /** Sets the name for the passed key. */
668 virtual void implSetName( sal_Int64 nKey
, const OUString
& rName
) override
;
669 /** Returns the name for the passed key. */
670 virtual OUString
implGetName( const Config
& rCfg
, sal_Int64 nKey
) const override
;
671 /** Inserts all flags from the passed list. */
672 virtual void implIncludeList( const NameListBase
& rList
) override
;
675 struct ExtItemFormatKey
678 ::std::pair
< sal_Int64
, sal_Int64
> maFilter
;
679 explicit ExtItemFormatKey( sal_Int64 nKey
) : mnKey( nKey
), maFilter( 0, 0 ) {}
680 bool operator<( const ExtItemFormatKey
& rRight
) const;
683 struct ExtItemFormat
: public ItemFormat
686 ExtItemFormat() : mbShiftValue( true ) {}
688 typedef ::std::map
< ExtItemFormatKey
, ExtItemFormat
> ExtItemFormatMap
;
689 ExtItemFormatMap maFmtMap
;
693 class UnitConverter
: public NameListBase
696 explicit UnitConverter( const SharedConfigData
& rCfgData
);
698 void setUnitName( const String
& rUnitName
) { maUnitName
= rUnitName
; }
699 void setFactor( double fFactor
) { mfFactor
= fFactor
; }
702 /** Sets the name for the passed key. */
703 virtual void implSetName( sal_Int64 nKey
, const OUString
& rName
) override
;
704 /** Returns the converted value with appended unit name. */
705 virtual OUString
implGetName( const Config
& rCfg
, sal_Int64 nKey
) const override
;
706 /** Returns the converted value with appended unit name. */
707 virtual OUString
implGetNameDbl( const Config
& rCfg
, double fValue
) const override
;
708 /** Empty implementation. */
709 virtual void implIncludeList( const NameListBase
& rList
) override
;
717 class NameListWrapper
721 /*implicit*/ NameListWrapper( const OUString
& rListName
) : maName( rListName
) {}
722 /*implicit*/ NameListWrapper( const sal_Char
* pcListName
) : maName( pcListName
) {}
723 /*implicit*/ NameListWrapper( const NameListRef
& rxList
) : mxList( rxList
) {}
725 bool isEmpty() const { return !mxList
&& !maName
.has(); }
726 NameListRef
getNameList( const Config
& rCfg
) const;
730 mutable NameListRef mxList
;
733 static const NameListWrapper NO_LIST
;
739 ::std::map
< sal_Int64
, ItemFormat
> maMap
;
742 ItemFormatMap() : maMap() {}
743 explicit ItemFormatMap( const NameListRef
& rxNameList
) { insertFormats( rxNameList
); }
745 ::std::map
< sal_Int64
, ItemFormat
>::const_iterator
end() const { return maMap
.end(); }
746 ::std::map
< sal_Int64
, ItemFormat
>::const_iterator
find(sal_Int64 nId
) const
748 return maMap
.find(nId
);
751 void insertFormats( const NameListRef
& rxNameList
);
755 class SharedConfigData
: public Base
, public ConfigItemBase
758 explicit SharedConfigData(
759 const OUString
& rFileName
,
760 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
761 const StorageRef
& rxRootStrg
,
762 const OUString
& rSysFileName
);
764 virtual ~SharedConfigData() override
;
766 const css::uno::Reference
< css::uno::XComponentContext
>& getContext() const { return mxContext
; }
767 const StorageRef
& getRootStorage() const { return mxRootStrg
; }
768 const OUString
& getSysFileName() const { return maSysFileName
; }
770 const OUString
* getOption( const OUString
& rKey
) const;
772 template< typename ListType
>
773 std::shared_ptr
< ListType
> createNameList( const OUString
& rListName
);
774 void setNameList( const OUString
& rListName
, const NameListRef
& rxList
);
775 void eraseNameList( const OUString
& rListName
);
776 NameListRef
getNameList( const OUString
& rListName
) const;
779 virtual bool implIsValid() const override
;
780 virtual void implProcessConfigItemStr(
781 TextInputStream
& rStrm
,
782 const OUString
& rKey
,
783 const OUString
& rData
) override
;
786 bool readConfigFile( const OUString
& rFileUrl
);
787 template< typename ListType
>
788 void readNameList( TextInputStream
& rStrm
, const OUString
& rListName
);
789 void createShortList( const OUString
& rData
);
790 void createUnitConverter( const OUString
& rData
);
793 typedef ::std::set
< OUString
> ConfigFileSet
;
794 typedef ::std::map
< OUString
, OUString
> ConfigDataMap
;
795 typedef ::std::map
< OUString
, NameListRef
> NameListMap
;
797 css::uno::Reference
< css::uno::XComponentContext
> mxContext
;
798 StorageRef mxRootStrg
;
799 OUString maSysFileName
;
800 ConfigFileSet maConfigFiles
;
801 ConfigDataMap maConfigData
;
802 NameListMap maNameLists
;
803 OUString maConfigPath
;
808 template< typename ListType
>
809 std::shared_ptr
< ListType
> SharedConfigData::createNameList( const OUString
& rListName
)
811 std::shared_ptr
< ListType
> xList
;
812 if( !rListName
.isEmpty() )
814 xList
.reset( new ListType( *this ) );
815 setNameList( rListName
, xList
);
820 template< typename ListType
>
821 void SharedConfigData::readNameList( TextInputStream
& rStrm
, const OUString
& rListName
)
823 NameListRef xList
= createNameList
< ListType
>( rListName
);
825 xList
->readConfigBlock( rStrm
);
829 class Config
: public Base
832 explicit Config( const Config
& rParent
);
834 const sal_Char
* pcEnvVar
,
835 const ::oox::core::FilterBase
& rFilter
);
837 const sal_Char
* pcEnvVar
,
838 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
839 const StorageRef
& rxRootStrg
,
840 const OUString
& rSysFileName
);
842 virtual ~Config() override
;
844 const css::uno::Reference
< css::uno::XComponentContext
>& getContext() const { return mxCfgData
->getContext(); }
845 const StorageRef
& getRootStorage() const { return mxCfgData
->getRootStorage(); }
846 const OUString
& getSysFileName() const { return mxCfgData
->getSysFileName(); }
848 const OUString
& getStringOption( const String
& rKey
, const OUString
& rDefault
) const;
849 bool getBoolOption( const String
& rKey
, bool bDefault
) const;
850 template< typename Type
>
851 Type
getIntOption( const String
& rKey
, Type nDefault
) const;
853 bool isDumperEnabled() const;
854 bool isImportEnabled() const;
856 template< typename ListType
>
857 std::shared_ptr
< ListType
> createNameList( const String
& rListName
);
858 void eraseNameList( const String
& rListName
);
859 NameListRef
getNameList( const String
& rListName
) const;
861 /** Returns the name for the passed key from the passed name list. */
862 template< typename Type
>
863 OUString
getName( const NameListWrapper
& rListWrp
, Type nKey
) const;
864 /** Returns true, if the passed name list contains an entry for the passed key. */
865 template< typename Type
>
866 bool hasName( const NameListWrapper
& rListWrp
, Type nKey
) const;
871 const sal_Char
* pcEnvVar
,
872 const ::oox::core::FilterBase
& rFilter
);
874 const sal_Char
* pcEnvVar
,
875 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
876 const StorageRef
& rxRootStrg
,
877 const OUString
& rSysFileName
);
879 virtual bool implIsValid() const override
;
880 const OUString
* implGetOption( const OUString
& rKey
) const;
883 typedef std::shared_ptr
< SharedConfigData
> SharedConfigDataRef
;
884 SharedConfigDataRef mxCfgData
;
887 typedef std::shared_ptr
< Config
> ConfigRef
;
890 template< typename Type
>
891 Type
Config::getIntOption( const String
& rKey
, Type nDefault
) const
894 const OUString
* pData
= implGetOption( rKey
);
895 return (pData
&& StringHelper::convertStringToInt( nRawData
, *pData
)) ?
896 static_cast< Type
>( nRawData
) : nDefault
;
899 template< typename ListType
>
900 std::shared_ptr
< ListType
> Config::createNameList( const String
& rListName
)
902 return mxCfgData
->createNameList
< ListType
>( rListName
);
905 template< typename Type
>
906 OUString
Config::getName( const NameListWrapper
& rListWrp
, Type nKey
) const
908 NameListRef xList
= rListWrp
.getNameList( *this );
909 return xList
.get() ? xList
->getName( *this, nKey
) : OOX_DUMP_ERR_NOMAP
;
912 template< typename Type
>
913 bool Config::hasName( const NameListWrapper
& rListWrp
, Type nKey
) const
915 NameListRef xList
= rListWrp
.getNameList( *this );
916 return xList
.get() && xList
->hasName( nKey
);
920 class Output
: public Base
924 const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
925 const OUString
& rFileName
);
929 void emptyLine( size_t nCount
= 1 );
934 void startTable( sal_Int32 nW1
);
935 void startTable( sal_Int32 nW1
, sal_Int32 nW2
);
936 void startTable( sal_Int32 nW1
, sal_Int32 nW2
, sal_Int32 nW3
, sal_Int32 nW4
);
937 void startTable( size_t nColCount
, const sal_Int32
* pnColWidths
);
939 void tab( size_t nCol
);
942 void resetItemIndex( sal_Int64 nIdx
= 0 );
943 void startItem( const String
& rItemName
);
947 void startMultiItems();
948 void endMultiItems();
950 void writeChar( sal_Unicode cChar
, sal_Int32 nCount
= 1 );
951 void writeAscii( const sal_Char
* pcStr
);
952 void writeString( const OUString
& rStr
);
953 void writeArray( const sal_uInt8
* pnData
, std::size_t nSize
, sal_Unicode cSep
= OOX_DUMP_LISTSEP
);
954 void writeBool( bool bData
);
955 void writeDateTime( const css::util::DateTime
& rDateTime
);
957 template< typename Type
>
958 void writeDec( Type nData
, sal_Int32 nWidth
= 0, sal_Unicode cFill
= ' ' )
959 { StringHelper::appendDec( maLine
, nData
, nWidth
, cFill
); }
960 template< typename Type
>
961 void writeHex( Type nData
, bool bPrefix
= true )
962 { StringHelper::appendHex( maLine
, nData
, bPrefix
); }
963 template< typename Type
>
964 void writeShortHex( Type nData
, bool bPrefix
= true )
965 { StringHelper::appendShortHex( maLine
, nData
, bPrefix
); }
966 template< typename Type
>
967 void writeBin( Type nData
, bool bDots
= true )
968 { StringHelper::appendBin( maLine
, nData
, bDots
); }
969 template< typename Type
>
970 void writeFix( Type nData
, sal_Int32 nWidth
= 0 )
971 { StringHelper::appendFix( maLine
, nData
, nWidth
); }
972 template< typename Type
>
973 void writeValue( Type nData
, FormatType eFmtType
)
974 { StringHelper::appendValue( maLine
, nData
, eFmtType
); }
975 template< typename Type
>
976 void writeName( const Config
& rCfg
, Type nData
, const NameListWrapper
& rListWrp
)
977 { writeString( rCfg
.getName( rListWrp
, nData
) ); }
981 virtual bool implIsValid() const override
;
984 void writeItemName( const String
& rItemName
);
987 typedef ::std::vector
< sal_Int32
> StringLenVec
;
989 css::uno::Reference
< css::io::XTextOutputStream2
> mxStrm
;
991 OUStringBuffer maLine
;
993 StringLenVec maColPos
;
998 sal_Int32 mnLastItem
;
1001 typedef std::shared_ptr
< Output
> OutputRef
;
1007 explicit IndentGuard( const OutputRef
& rxOut
) : mrOut( *rxOut
) { mrOut
.incIndent(); }
1008 ~IndentGuard() { mrOut
.decIndent(); }
1010 IndentGuard( const IndentGuard
& ) = delete;
1011 IndentGuard
& operator=( const IndentGuard
& ) = delete;
1020 explicit TableGuard( const OutputRef
& rxOut
, sal_Int32 nW1
) :
1021 mrOut( *rxOut
) { mrOut
.startTable( nW1
); }
1022 explicit TableGuard( const OutputRef
& rxOut
, sal_Int32 nW1
, sal_Int32 nW2
) :
1023 mrOut( *rxOut
) { mrOut
.startTable( nW1
, nW2
); }
1024 explicit TableGuard( const OutputRef
& rxOut
, sal_Int32 nW1
, sal_Int32 nW2
, sal_Int32 nW3
, sal_Int32 nW4
) :
1025 mrOut( *rxOut
) { mrOut
.startTable( nW1
, nW2
, nW3
, nW4
); }
1026 explicit TableGuard( const OutputRef
& rxOut
, size_t nColCount
,
1027 const sal_Int32
* pnColWidths
) :
1028 mrOut( *rxOut
) { mrOut
.startTable( nColCount
, pnColWidths
); }
1029 ~TableGuard() { mrOut
.endTable(); }
1030 void tab( size_t nCol
) { mrOut
.tab( nCol
); }
1032 TableGuard( const TableGuard
& ) = delete;
1033 TableGuard
& operator=( const TableGuard
& ) = delete;
1042 explicit ItemGuard( const OutputRef
& rxOut
, const String
& rName
) :
1043 mrOut( *rxOut
) { mrOut
.startItem( rName
); }
1044 ~ItemGuard() { mrOut
.endItem(); }
1045 void cont() { mrOut
.contItem(); }
1047 ItemGuard( const ItemGuard
& ) = delete;
1048 ItemGuard
& operator=( const ItemGuard
& ) = delete;
1054 class MultiItemsGuard
1057 explicit MultiItemsGuard( const OutputRef
& rxOut
) : mrOut( *rxOut
) { mrOut
.startMultiItems(); }
1058 ~MultiItemsGuard() { mrOut
.endMultiItems(); }
1060 MultiItemsGuard( const MultiItemsGuard
& ) = delete;
1061 MultiItemsGuard
& operator=( const MultiItemsGuard
& ) = delete;
1067 class StorageIterator
: public Base
1070 explicit StorageIterator( const StorageRef
& rxStrg
);
1071 virtual ~StorageIterator() override
;
1073 StorageIterator
& operator++();
1075 OUString
getName() const;
1076 bool isStream() const;
1077 bool isStorage() const;
1080 virtual bool implIsValid() const override
;
1084 OUStringVector maNames
;
1085 OUStringVector::const_iterator maIt
;
1089 class ObjectBase
: public Base
1092 virtual ~ObjectBase() override
;
1094 const css::uno::Reference
< css::uno::XComponentContext
>&
1095 getContext() const { return mxConfig
->getContext(); }
1103 void construct( const ConfigRef
& rxConfig
);
1104 void construct( const ObjectBase
& rParent
);
1106 virtual bool implIsValid() const override
;
1107 virtual void implDump();
1110 Config
& cfg() const { return *mxConfig
; }
1116 typedef std::shared_ptr
< ObjectBase
> ObjectRef
;
1119 class StorageObjectBase
: public ObjectBase
1122 StorageObjectBase() {}
1125 using ObjectBase::construct
;
1126 void construct( const ObjectBase
& rParent
, const StorageRef
& rxStrg
, const OUString
& rSysPath
);
1127 void construct( const ObjectBase
& rParent
);
1129 virtual bool implIsValid() const override
;
1130 virtual void implDump() override
;
1132 virtual void implDumpStream(
1133 const css::uno::Reference
< css::io::XInputStream
>& rxStrm
,
1134 const OUString
& rStrgPath
,
1135 const OUString
& rStrmName
,
1136 const OUString
& rSysFileName
);
1138 virtual void implDumpStorage(
1139 const StorageRef
& rxStrg
,
1140 const OUString
& rStrgPath
,
1141 const OUString
& rSysPath
);
1143 virtual void implDumpBaseStream(
1144 const BinaryInputStreamRef
& rxStrm
,
1145 const OUString
& rSysFileName
);
1147 void addPreferredStream( const String
& rStrmName
);
1148 void addPreferredStorage( const String
& rStrgPath
);
1151 static OUString
getSysFileName(
1152 const OUString
& rStrmName
,
1153 const OUString
& rSysOutPath
);
1157 const OUString
& rStrgPath
,
1158 const OUString
& rStrmName
,
1159 const OUString
& rSysFileName
);
1160 void extractStorage(
1161 const StorageRef
& rxStrg
,
1162 const OUString
& rStrgPath
,
1163 const OUString
& rSysPath
);
1166 const StorageRef
& rxStrg
,
1167 const OUString
& rStrgPath
,
1168 const OUString
& rItemName
,
1169 const OUString
& rSysPath
,
1170 bool bIsStrg
, bool bIsStrm
);
1173 struct PreferredItem
1178 explicit PreferredItem( const OUString
& rName
, bool bStorage
) :
1179 maName( rName
), mbStorage( bStorage
) {}
1181 typedef ::std::vector
< PreferredItem
> PreferredItemVector
;
1185 PreferredItemVector maPreferred
;
1189 class OutputObjectBase
: public ObjectBase
1192 virtual ~OutputObjectBase() override
;
1196 OutputObjectBase() {}
1198 using ObjectBase::construct
;
1199 void construct( const ObjectBase
& rParent
, const OUString
& rSysFileName
);
1200 void construct( const OutputObjectBase
& rParent
);
1202 virtual bool implIsValid() const override
;
1205 void writeEmptyItem( const String
& rName
);
1206 void writeInfoItem( const String
& rName
, const String
& rData
);
1207 void writeCharItem( const String
& rName
, sal_Unicode cData
);
1208 void writeStringItem( const String
& rName
, const OUString
& rData
);
1209 void writeArrayItem( const String
& rName
, const sal_uInt8
* pnData
, std::size_t nSize
, sal_Unicode cSep
= OOX_DUMP_LISTSEP
);
1210 void writeDateTimeItem( const String
& rName
, const css::util::DateTime
& rDateTime
);
1211 void writeGuidItem( const String
& rName
, const OUString
& rGuid
);
1213 template< typename Type
>
1214 void addNameToItem( Type nData
, const NameListWrapper
& rListWrp
);
1216 template< typename Type
>
1217 void writeNameItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
);
1218 template< typename Type
>
1219 void writeDecItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
= NO_LIST
);
1220 template< typename Type
>
1221 void writeHexItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
= NO_LIST
);
1222 template< typename Type
>
1223 void writeShortHexItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
= NO_LIST
);
1224 template< typename Type
>
1225 void writeBinItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
= NO_LIST
);
1226 template< typename Type
>
1227 void writeFixItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
= NO_LIST
);
1228 template< typename Type
>
1229 void writeDecBoolItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
= NO_LIST
);
1230 template< typename Type
>
1231 void writeValueItem( const String
& rName
, Type nData
, FormatType eFmtType
, const NameListWrapper
& rListWrp
= NO_LIST
);
1233 template< typename Type
>
1234 void writeValueItem( const ItemFormat
& rItemFmt
, Type nData
);
1236 template< typename Type
>
1237 void writeDecPairItem( const String
& rName
, Type nData1
, Type nData2
, sal_Unicode cSep
= ',' );
1238 template< typename Type
>
1239 void writeHexPairItem( const String
& rName
, Type nData1
, Type nData2
, sal_Unicode cSep
= ',' );
1243 OUString maSysFileName
;
1247 template< typename Type
>
1248 void OutputObjectBase::addNameToItem( Type nData
, const NameListWrapper
& rListWrp
)
1250 if( !rListWrp
.isEmpty() )
1253 mxOut
->writeName( cfg(), nData
, rListWrp
);
1257 template< typename Type
>
1258 void OutputObjectBase::writeNameItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
)
1260 ItemGuard
aItem( mxOut
, rName
);
1261 mxOut
->writeName( cfg(), nData
, rListWrp
);
1264 template< typename Type
>
1265 void OutputObjectBase::writeDecItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
)
1267 ItemGuard
aItem( mxOut
, rName
);
1268 mxOut
->writeDec( nData
);
1269 addNameToItem( nData
, rListWrp
);
1272 template< typename Type
>
1273 void OutputObjectBase::writeHexItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
)
1275 ItemGuard
aItem( mxOut
, rName
);
1276 mxOut
->writeHex( nData
);
1277 addNameToItem( nData
, rListWrp
);
1280 template< typename Type
>
1281 void OutputObjectBase::writeShortHexItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
)
1283 ItemGuard
aItem( mxOut
, rName
);
1284 mxOut
->writeShortHex( nData
);
1285 addNameToItem( nData
, rListWrp
);
1288 template< typename Type
>
1289 void OutputObjectBase::writeBinItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
)
1291 ItemGuard
aItem( mxOut
, rName
);
1292 mxOut
->writeBin( nData
);
1293 addNameToItem( nData
, rListWrp
);
1296 template< typename Type
>
1297 void OutputObjectBase::writeFixItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
)
1299 ItemGuard
aItem( mxOut
, rName
);
1300 mxOut
->writeFix( nData
);
1301 addNameToItem( nData
, rListWrp
);
1304 template< typename Type
>
1305 void OutputObjectBase::writeDecBoolItem( const String
& rName
, Type nData
, const NameListWrapper
& rListWrp
)
1307 ItemGuard
aItem( mxOut
, rName
);
1308 mxOut
->writeDec( nData
);
1310 mxOut
->writeBool( nData
!= 0 );
1311 addNameToItem( nData
, rListWrp
);
1314 template< typename Type
>
1315 void OutputObjectBase::writeValueItem( const String
& rName
, Type nData
, FormatType eFmtType
, const NameListWrapper
& rListWrp
)
1317 if( eFmtType
== FORMATTYPE_BOOL
)
1318 writeDecBoolItem( rName
, nData
, rListWrp
);
1321 ItemGuard
aItem( mxOut
, rName
);
1322 mxOut
->writeValue( nData
, eFmtType
);
1323 addNameToItem( nData
, rListWrp
);
1327 template< typename Type
>
1328 void OutputObjectBase::writeValueItem( const ItemFormat
& rItemFmt
, Type nData
)
1330 OString aNameUtf8
= StringHelper::convertToUtf8( rItemFmt
.maItemName
);
1331 writeValueItem( aNameUtf8
.getStr(), nData
, rItemFmt
.meFmtType
, rItemFmt
.maListName
);
1334 template< typename Type
>
1335 void OutputObjectBase::writeDecPairItem( const String
& rName
, Type nData1
, Type nData2
, sal_Unicode cSep
)
1337 ItemGuard
aItem( mxOut
, rName
);
1338 mxOut
->writeDec( nData1
);
1339 mxOut
->writeChar( cSep
);
1340 mxOut
->writeDec( nData2
);
1343 template< typename Type
>
1344 void OutputObjectBase::writeHexPairItem( const String
& rName
, Type nData1
, Type nData2
, sal_Unicode cSep
)
1346 ItemGuard
aItem( mxOut
, rName
);
1347 mxOut
->writeHex( nData1
);
1348 mxOut
->writeChar( cSep
);
1349 mxOut
->writeHex( nData2
);
1353 class InputObjectBase
: public OutputObjectBase
1356 virtual ~InputObjectBase() override
;
1360 InputObjectBase() {}
1362 using OutputObjectBase::construct
;
1363 void construct( const ObjectBase
& rParent
, const BinaryInputStreamRef
& rxStrm
, const OUString
& rSysFileName
);
1364 void construct( const OutputObjectBase
& rParent
, const BinaryInputStreamRef
& rxStrm
);
1365 void construct( const InputObjectBase
& rParent
);
1367 virtual bool implIsValid() const override
;
1369 void skipBlock( sal_Int64 nBytes
, bool bShowSize
= true );
1370 void dumpRawBinary( sal_Int64 nBytes
, bool bShowOffset
= true, bool bStream
= false );
1372 void dumpBinary( const String
& rName
, sal_Int64 nBytes
, bool bShowOffset
= true );
1373 void dumpRemaining( sal_Int64 nBytes
);
1374 void dumpRemainingTo( sal_Int64 nPos
);
1375 void dumpRemainingStream();
1377 void dumpArray( const String
& rName
, sal_Int32 nBytes
, sal_Unicode cSep
= OOX_DUMP_LISTSEP
);
1378 void dumpUnused( sal_Int32 nBytes
) { dumpArray( OOX_DUMP_UNUSED
, nBytes
); }
1379 void dumpUnknown( sal_Int32 nBytes
) { dumpArray( OOX_DUMP_UNKNOWN
, nBytes
); }
1381 sal_Unicode
dumpUnicode( const String
& rName
);
1383 OUString
dumpCharArray( const String
& rName
, sal_Int32 nLen
, rtl_TextEncoding eTextEnc
, bool bHideTrailingNul
= false );
1384 OUString
dumpUnicodeArray( const String
& rName
, sal_Int32 nLen
, bool bHideTrailingNul
= false );
1386 css::util::DateTime
dumpFileTime( const String
& rName
= EMPTY_STRING
);
1387 OUString
dumpGuid( const String
& rName
= EMPTY_STRING
);
1389 void dumpItem( const ItemFormat
& rItemFmt
);
1391 template< typename Type
>
1392 Type
dumpName( const String
& rName
, const NameListWrapper
& rListWrp
);
1393 template< typename Type
>
1394 Type
dumpDec( const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1395 template< typename Type
>
1396 Type
dumpHex( const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1397 template< typename Type
>
1398 Type
dumpBin( const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1399 template< typename Type
>
1400 Type
dumpFix( const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1401 template< typename Type
>
1402 Type
dumpBool( const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1403 template< typename Type
>
1404 Type
dumpValue( const ItemFormat
& rItemFmt
);
1406 template< typename Type1
, typename Type2
>
1407 Type1
dumpName( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1408 template< typename Type1
, typename Type2
>
1409 Type1
dumpDec( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1410 template< typename Type1
, typename Type2
>
1411 Type1
dumpHex( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1412 template< typename Type1
, typename Type2
>
1413 Type1
dumpBin( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1414 template< typename Type1
, typename Type2
>
1415 Type1
dumpFix( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1416 template< typename Type1
, typename Type2
>
1417 Type1
dumpBool( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
= NO_LIST
);
1418 template< typename Type1
, typename Type2
>
1419 Type1
dumpValue( bool bType1
, const ItemFormat
& rItemFmt
);
1421 template< typename Type
>
1422 void dumpDecPair( const String
& rName
, sal_Unicode cSep
= ',' );
1423 template< typename Type
>
1424 void dumpHexPair( const String
& rName
, sal_Unicode cSep
= ',' );
1427 BinaryInputStreamRef mxStrm
;
1431 template< typename Type
>
1432 Type
InputObjectBase::dumpName( const String
& rName
, const NameListWrapper
& rListWrp
)
1434 Type nData
= mxStrm
->readValue
<Type
>();
1435 writeNameItem( rName
, nData
, rListWrp
);
1439 template< typename Type
>
1440 Type
InputObjectBase::dumpDec( const String
& rName
, const NameListWrapper
& rListWrp
)
1442 Type nData
= mxStrm
->readValue
<Type
>();
1443 writeDecItem( rName
, nData
, rListWrp
);
1447 template< typename Type
>
1448 Type
InputObjectBase::dumpHex( const String
& rName
, const NameListWrapper
& rListWrp
)
1450 Type nData
= mxStrm
->readValue
<Type
>();
1451 writeHexItem( rName
, nData
, rListWrp
);
1455 template< typename Type
>
1456 Type
InputObjectBase::dumpBin( const String
& rName
, const NameListWrapper
& rListWrp
)
1458 Type nData
= mxStrm
->readValue
<Type
>();
1459 writeBinItem( rName
, nData
, rListWrp
);
1463 template< typename Type
>
1464 Type
InputObjectBase::dumpFix( const String
& rName
, const NameListWrapper
& rListWrp
)
1466 Type nData
= mxStrm
->readValue
<Type
>();
1467 writeFixItem( rName
, nData
, rListWrp
);
1471 template< typename Type
>
1472 Type
InputObjectBase::dumpBool( const String
& rName
, const NameListWrapper
& rListWrp
)
1474 Type nData
= mxStrm
->readValue
<Type
>();
1475 writeDecBoolItem( rName
, nData
, rListWrp
);
1479 template< typename Type
>
1480 Type
InputObjectBase::dumpValue( const ItemFormat
& rItemFmt
)
1482 Type nData
= mxStrm
->readValue
<Type
>();
1483 writeValueItem( rItemFmt
, nData
);
1487 template< typename Type1
, typename Type2
>
1488 Type1
InputObjectBase::dumpName( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
)
1490 return bType1
? dumpName
< Type1
>( rName
, rListWrp
) : static_cast< Type1
>( dumpName
< Type2
>( rName
, rListWrp
) );
1493 template< typename Type1
, typename Type2
>
1494 Type1
InputObjectBase::dumpDec( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
)
1496 return bType1
? dumpDec
< Type1
>( rName
, rListWrp
) : static_cast< Type1
>( dumpDec
< Type2
>( rName
, rListWrp
) );
1499 template< typename Type1
, typename Type2
>
1500 Type1
InputObjectBase::dumpHex( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
)
1502 return bType1
? dumpHex
< Type1
>( rName
, rListWrp
) : static_cast< Type1
>( dumpHex
< Type2
>( rName
, rListWrp
) );
1505 template< typename Type1
, typename Type2
>
1506 Type1
InputObjectBase::dumpBin( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
)
1508 return bType1
? dumpBin
< Type1
>( rName
, rListWrp
) : static_cast< Type1
>( dumpBin
< Type2
>( rName
, rListWrp
) );
1511 template< typename Type1
, typename Type2
>
1512 Type1
InputObjectBase::dumpFix( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
)
1514 return bType1
? dumpFix
< Type1
>( rName
, rListWrp
) : static_cast< Type1
>( dumpFix
< Type2
>( rName
, rListWrp
) );
1517 template< typename Type1
, typename Type2
>
1518 Type1
InputObjectBase::dumpBool( bool bType1
, const String
& rName
, const NameListWrapper
& rListWrp
)
1520 return bType1
? dumpBool
< Type1
>( rName
, rListWrp
) : static_cast< Type1
>( dumpBool
< Type2
>( rName
, rListWrp
) );
1523 template< typename Type1
, typename Type2
>
1524 Type1
InputObjectBase::dumpValue( bool bType1
, const ItemFormat
& rItemFmt
)
1526 return bType1
? dumpValue
< Type1
>( rItemFmt
) : static_cast< Type1
>( dumpValue
< Type2
>( rItemFmt
) );
1529 template< typename Type
>
1530 void InputObjectBase::dumpDecPair( const String
& rName
, sal_Unicode cSep
)
1532 Type nData1
, nData2
;
1533 *mxStrm
>> nData1
>> nData2
;
1534 writeDecPairItem( rName
, nData1
, nData2
, cSep
);
1537 template< typename Type
>
1538 void InputObjectBase::dumpHexPair( const String
& rName
, sal_Unicode cSep
)
1540 Type nData1
, nData2
;
1541 *mxStrm
>> nData1
>> nData2
;
1542 writeHexPairItem( rName
, nData1
, nData2
, cSep
);
1546 class BinaryStreamObject
: public InputObjectBase
1549 explicit BinaryStreamObject(
1550 const ObjectBase
& rParent
,
1551 const BinaryInputStreamRef
& rxStrm
,
1552 const OUString
& rSysFileName
);
1555 void dumpBinaryStream( bool bShowOffset
= true );
1557 virtual void implDump() override
;
1561 class TextStreamObjectBase
: public InputObjectBase
1564 TextStreamObjectBase() {}
1566 using InputObjectBase::construct
;
1568 const ObjectBase
& rParent
,
1569 const BinaryInputStreamRef
& rxStrm
,
1570 rtl_TextEncoding eTextEnc
,
1571 const OUString
& rSysFileName
);
1573 const OutputObjectBase
& rParent
,
1574 const BinaryInputStreamRef
& rxStrm
,
1575 rtl_TextEncoding eTextEnc
);
1577 virtual bool implIsValid() const override
;
1578 virtual void implDump() override
;
1580 virtual void implDumpText( TextInputStream
& rTextStrm
) = 0;
1583 void constructTextStrmObj( rtl_TextEncoding eTextEnc
);
1586 std::shared_ptr
< TextInputStream
> mxTextStrm
;
1590 class TextLineStreamObject
: public TextStreamObjectBase
1593 explicit TextLineStreamObject(
1594 const ObjectBase
& rParent
,
1595 const BinaryInputStreamRef
& rxStrm
,
1596 rtl_TextEncoding eTextEnc
,
1597 const OUString
& rSysFileName
);
1599 explicit TextLineStreamObject(
1600 const OutputObjectBase
& rParent
,
1601 const BinaryInputStreamRef
& rxStrm
,
1602 rtl_TextEncoding eTextEnc
);
1605 virtual void implDumpText( TextInputStream
& rTextStrm
) override
;
1606 void implDumpLine( const OUString
& rLine
, sal_uInt32 nLine
);
1610 class XmlStreamObject
: public TextStreamObjectBase
1613 explicit XmlStreamObject(
1614 const ObjectBase
& rParent
,
1615 const BinaryInputStreamRef
& rxStrm
,
1616 const OUString
& rSysFileName
);
1619 virtual void implDumpText( TextInputStream
& rTextStrm
) override
;
1623 class RecordObjectBase
: public InputObjectBase
1626 RecordObjectBase() {}
1628 using InputObjectBase::construct
;
1630 const ObjectBase
& rParent
,
1631 const BinaryInputStreamRef
& rxBaseStrm
,
1632 const OUString
& rSysFileName
,
1633 const BinaryInputStreamRef
& rxRecStrm
,
1634 const String
& rRecNames
,
1635 const String
& rSimpleRecs
);
1637 sal_Int64
getRecId() const { return mnRecId
; }
1638 sal_Int64
getRecSize() const { return mnRecSize
; }
1640 virtual bool implIsValid() const override
;
1641 virtual void implDump() override
;
1643 virtual bool implStartRecord( BinaryInputStream
& rBaseStrm
, sal_Int64
& ornRecPos
, sal_Int64
& ornRecId
, sal_Int64
& ornRecSize
) = 0;
1644 virtual void implWriteExtHeader();
1645 virtual void implDumpRecordBody();
1648 void constructRecObjBase(
1649 const BinaryInputStreamRef
& rxBaseStrm
,
1650 const String
& rRecNames
,
1651 const String
& rSimpleRecs
);
1656 BinaryInputStreamRef mxBaseStrm
;
1657 NameListWrapper maRecNames
;
1658 NameListWrapper maSimpleRecs
;
1661 sal_Int64 mnRecSize
;
1667 class SequenceRecordObjectBase
: public RecordObjectBase
1670 SequenceRecordObjectBase() : mxRecData( new StreamDataSequence
) {}
1672 using RecordObjectBase::construct
;
1674 const ObjectBase
& rParent
,
1675 const BinaryInputStreamRef
& rxBaseStrm
,
1676 const OUString
& rSysFileName
,
1677 const String
& rRecNames
,
1678 const String
& rSimpleRecs
);
1680 virtual bool implStartRecord( BinaryInputStream
& rBaseStrm
, sal_Int64
& ornRecPos
, sal_Int64
& ornRecId
, sal_Int64
& ornRecSize
) override
;
1681 virtual bool implReadRecordHeader( BinaryInputStream
& rBaseStrm
, sal_Int64
& ornRecId
, sal_Int64
& ornRecSize
) = 0;
1684 typedef std::shared_ptr
< StreamDataSequence
> StreamDataSeqRef
;
1685 StreamDataSeqRef mxRecData
;
1689 /** Base class for a file dumper. Derived classes implement the implDump()
1690 function to add functionality.
1692 class DumperBase
: public ObjectBase
1695 virtual ~DumperBase() override
;
1697 bool isImportEnabled() const;
1702 using ObjectBase::construct
;
1703 void construct( const ConfigRef
& rxConfig
);
1710 #define OOX_DUMP_FILE( DumperClassName ) \
1712 DumperClassName aDumper( *this ); \
1714 if( !aDumper.isImportEnabled() ) \
1715 return aDumper.isValid(); \
1718 #else // OOX_INCLUDE_DUMPER
1720 #define OOX_DUMP_FILE( DumperClassName ) (void)0
1722 #endif // OOX_INCLUDE_DUMPER
1725 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */