1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 #ifndef OOX_DUMP_DUMPERBASE_HXX
25 #define OOX_DUMP_DUMPERBASE_HXX
26
27 #include <math.h>
28 #include <vector>
29 #include <stack>
30 #include <set>
31 #include <map>
32 #include <boost/shared_ptr.hpp>
33 #include <rtl/strbuf.hxx>
34 #include <rtl/ustrbuf.hxx>
35 #include <com/sun/star/uno/Reference.hxx>
36 #include <com/sun/star/util/DateTime.hpp>
37 #include <comphelper/mediadescriptor.hxx>
38 #include "oox/helper/binaryinputstream.hxx"
39 #include "oox/helper/helper.hxx"
40 #include "oox/helper/storagebase.hxx"
41
42 #define OOX_INCLUDE_DUMPER (OSL_DEBUG_LEVEL > 0)
43
44 #if OOX_INCLUDE_DUMPER
45
46 namespace com { namespace sun { namespace star {
47 namespace io { class XInputStream; }
48 namespace io { class XOutputStream; }
49 namespace io { class XTextOutputStream; }
50 namespace uno { class XComponentContext; }
51 } } }
52
53 namespace comphelper {
54 class IDocPasswordVerifier;
55 }
56
57 namespace oox {
58 class BinaryOutputStream;
59 class TextInputStream;
60 }
61
62 namespace oox { namespace core {
63 class FilterBase;
64 } }
65
66 namespace oox {
67 namespace dump {
68
69 // ============================================================================
70
71 #define OOX_DUMP_UNUSED "unused"
72 #define OOX_DUMP_UNKNOWN "?unknown"
73
74 #define OOX_DUMP_ERRASCII( ascii ) "?err:" ascii
75 #define OOX_DUMP_ERRSTRING( ascii ) CREATE_OUSTRING( OOX_DUMP_ERRASCII( ascii ) )
76
77 #define OOX_DUMP_ERR_NOMAP OOX_DUMP_ERRSTRING( "no-map" )
78 #define OOX_DUMP_ERR_NONAME OOX_DUMP_ERRSTRING( "no-name" )
79 #define OOX_DUMP_ERR_STREAM OOX_DUMP_ERRSTRING( "stream-error" )
80
81 #define OOX_DUMP_DUMPEXT CREATE_OUSTRING( ".dump" )
82
83 const sal_Unicode OOX_DUMP_STRQUOTE = '\'';
84 const sal_Unicode OOX_DUMP_FMLASTRQUOTE = '"';
85 const sal_Unicode OOX_DUMP_ADDRABS = '$';
86 const sal_Unicode OOX_DUMP_R1C1ROW = 'R';
87 const sal_Unicode OOX_DUMP_R1C1COL = 'C';
88 const sal_Unicode OOX_DUMP_R1C1OPEN = '[';
89 const sal_Unicode OOX_DUMP_R1C1CLOSE = ']';
90 const sal_Unicode OOX_DUMP_RANGESEP = ':';
91 const sal_Unicode OOX_DUMP_BASECLASS = 'B';
92 const sal_Unicode OOX_DUMP_FUNCSEP = ',';
93 const sal_Unicode OOX_DUMP_LISTSEP = ',';
94 const sal_Unicode OOX_DUMP_TABSEP = '!';
95 const sal_Unicode OOX_DUMP_ARRAYSEP = ';';
96 const sal_Unicode OOX_DUMP_EMPTYVALUE = '~';
97 const sal_Unicode OOX_DUMP_CMDPROMPT = '?';
98 const sal_Unicode OOX_DUMP_PLACEHOLDER = '\x01';
99
100 typedef ::std::pair< ::rtl::OUString, ::rtl::OUString > OUStringPair;
101 typedef ::std::pair< sal_Int64, sal_Int64 > Int64Pair;
102
103 typedef ::std::vector< ::rtl::OUString > OUStringVector;
104 typedef ::std::vector< sal_Int64 > Int64Vector;
105
106 // ============================================================================
107 // ============================================================================
108
109 /** Static helper functions for system file and stream access. */
110 class InputOutputHelper
111 {
112 public:
113 // file names -------------------------------------------------------------
114
115 static ::rtl::OUString convertFileNameToUrl( const ::rtl::OUString& rFileName );
116 static sal_Int32 getFileNamePos( const ::rtl::OUString& rFileUrl );
117 static ::rtl::OUString getFileNameExtension( const ::rtl::OUString& rFileUrl );
118
119 // input streams ----------------------------------------------------------
120
121 static ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
122 openInputStream(
123 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
124 const ::rtl::OUString& rFileName );
125
126 // output streams ---------------------------------------------------------
127
128 static ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >
129 openOutputStream(
130 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
131 const ::rtl::OUString& rFileName );
132
133 static ::com::sun::star::uno::Reference< ::com::sun::star::io::XTextOutputStream >
134 openTextOutputStream(
135 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
136 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& rxOutStrm,
137 rtl_TextEncoding eTextEnc );
138
139 static ::com::sun::star::uno::Reference< ::com::sun::star::io::XTextOutputStream >
140 openTextOutputStream(
141 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
142 const ::rtl::OUString& rFileName,
143 rtl_TextEncoding eTextEnc );
144 };
145
146 // ============================================================================
147
148 class BinaryInputStreamRef : public ::oox::BinaryInputStreamRef
149 {
150 public:
BinaryInputStreamRef()151 inline BinaryInputStreamRef() {}
152
BinaryInputStreamRef(BinaryInputStream * pInStrm)153 inline /*implicit*/ BinaryInputStreamRef( BinaryInputStream* pInStrm ) :
154 ::oox::BinaryInputStreamRef( pInStrm ) {}
155
BinaryInputStreamRef(const::com::sun::star::uno::Reference<::com::sun::star::io::XInputStream> & rxInStrm)156 inline /*implicit*/ BinaryInputStreamRef( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxInStrm ) :
157 ::oox::BinaryInputStreamRef( new BinaryXInputStream( rxInStrm, true ) ) {}
158
159 template< typename StreamType >
BinaryInputStreamRef(const::boost::shared_ptr<StreamType> & rxInStrm)160 inline /*implicit*/ BinaryInputStreamRef( const ::boost::shared_ptr< StreamType >& rxInStrm ) :
161 ::oox::BinaryInputStreamRef( rxInStrm ) {}
162 };
163
164 // ============================================================================
165 // ============================================================================
166
167 /** Specifiers for atomic data types. */
168 enum DataType
169 {
170 DATATYPE_VOID, /// No data type.
171 DATATYPE_INT8, /// Signed 8-bit integer.
172 DATATYPE_UINT8, /// Unsigned 8-bit integer.
173 DATATYPE_INT16, /// Signed 16-bit integer.
174 DATATYPE_UINT16, /// Unsigned 16-bit integer.
175 DATATYPE_INT32, /// Signed 32-bit integer.
176 DATATYPE_UINT32, /// Unsigned 32-bit integer.
177 DATATYPE_INT64, /// Signed 64-bit integer.
178 DATATYPE_UINT64, /// Unsigned 64-bit integer.
179 DATATYPE_FLOAT, /// Floating-point, single precision.
180 DATATYPE_DOUBLE /// Floating-point, double precision.
181 };
182
183 // ----------------------------------------------------------------------------
184
185 /** Specifiers for the output format of values. */
186 enum FormatType
187 {
188 FORMATTYPE_NONE, /// No numeric format (e.g. show name only).
189 FORMATTYPE_DEC, /// Decimal.
190 FORMATTYPE_HEX, /// Hexadecimal.
191 FORMATTYPE_SHORTHEX, /// Hexadecimal, as short as possible (no leading zeros).
192 FORMATTYPE_BIN, /// Binary.
193 FORMATTYPE_FIX, /// Fixed-point.
194 FORMATTYPE_BOOL /// Boolean ('true' or 'false').
195 };
196
197 // ----------------------------------------------------------------------------
198
199 /** Describes the output format of a data item.
200
201 Data items are written in the following format:
202
203 <NAME>=<VALUE>=<NAME-FROM-LIST>
204
205 NAME is the name of the data item. The name is contained in the member
206 maItemName. If the name is empty, only the value is written (without a
207 leading equality sign).
208
209 VALUE is the numeric value of the data item. Its format is dependent on the
210 output format given in the member meFmtType. If the format type is
211 FORMATTYPE_NONE, no value is written.
212
213 NAME-FROM-LIST is a symbolic name for the current value of the data item.
214 Various types of name lists produce different names for values, which can
215 be used for enumerations or names for single bits in bitfields (see class
216 NameListBase and derived classes). The name of the list is given in the
217 member maListName. If it is empty, no name is written for the value.
218 */
219 struct ItemFormat
220 {
221 DataType meDataType; /// Data type of the item.
222 FormatType meFmtType; /// Output format for the value.
223 ::rtl::OUString maItemName; /// Name of the item.
224 ::rtl::OUString maListName; /// Name of a name list to be used for this item.
225
226 explicit ItemFormat();
227
228 void set( DataType eDataType, FormatType eFmtType, const ::rtl::OUString& rItemName );
229 void set( DataType eDataType, FormatType eFmtType, const ::rtl::OUString& rItemName, const ::rtl::OUString& rListName );
230
231 /** Initializes the struct from a vector of strings containing the item format.
232
233 The vector must contain at least 2 strings. The struct is filled from
234 the strings in the vector in the following order:
235 1) Data type (one of: [u]int8, [u]int16, [u]int32, [u]int64, float, double).
236 2) Format type (one of: dec, hex, shorthex, bin, fix, bool, unused, unknown).
237 3) Item name (optional).
238 4) Name list name (optional).
239
240 @return Iterator pointing to the first unhandled string.
241 */
242 OUStringVector::const_iterator parse( const OUStringVector& rFormatVec );
243
244 /** Initializes the struct from a string containing the item format.
245
246 The string must have the following format:
247 DATATYPE,FORMATTYPE[,ITEMNAME[,LISTNAME]]
248
249 DATATYPE is the data type of the item (see above for possible values).
250 FORMATTYPE is the format type of the item (see above for possible values).
251 ITEMNAME is the name of the item (optional).
252 LISTNAME is the name of a name list (optional).
253
254 @return List containing remaining unhandled format strings.
255 */
256 OUStringVector parse( const ::rtl::OUString& rFormatStr );
257 };
258
259 // ============================================================================
260 // ============================================================================
261
262 struct Address
263 {
264 sal_Int32 mnCol;
265 sal_Int32 mnRow;
Addressoox::dump::Address266 inline explicit Address() : mnCol( 0 ), mnRow( 0 ) {}
Addressoox::dump::Address267 inline explicit Address( sal_Int32 nCol, sal_Int32 nRow ) : mnCol( nCol ), mnRow( nRow ) {}
268 };
269
270 // ----------------------------------------------------------------------------
271
272 struct Range
273 {
274 Address maFirst;
275 Address maLast;
Rangeoox::dump::Range276 inline explicit Range() {}
277 };
278
279 // ----------------------------------------------------------------------------
280
281 typedef ::std::vector< Range > RangeList;
282
283 // ============================================================================
284
285 struct TokenAddress : public Address
286 {
287 bool mbRelCol;
288 bool mbRelRow;
TokenAddressoox::dump::TokenAddress289 inline explicit TokenAddress() : mbRelCol( false ), mbRelRow( false ) {}
290 };
291
292 // ----------------------------------------------------------------------------
293
294 struct TokenRange
295 {
296 TokenAddress maFirst;
297 TokenAddress maLast;
TokenRangeoox::dump::TokenRange298 inline explicit TokenRange() {}
299 };
300
301 // ============================================================================
302 // ============================================================================
303
304 /** Static helper functions for formatted output to strings. */
305 class StringHelper
306 {
307 public:
308 // append string to string ------------------------------------------------
309
310 static void appendChar( ::rtl::OUStringBuffer& rStr, sal_Unicode cChar, sal_Int32 nCount = 1 );
311 static void appendString( ::rtl::OUStringBuffer& rStr, const ::rtl::OUString& rData, sal_Int32 nWidth = 0, sal_Unicode cFill = ' ' );
312
313 // append decimal ---------------------------------------------------------
314
315 static void appendDec( ::rtl::OUStringBuffer& rStr, sal_uInt8 nData, sal_Int32 nWidth = 0, sal_Unicode cFill = ' ' );
316 static void appendDec( ::rtl::OUStringBuffer& rStr, sal_Int8 nData, sal_Int32 nWidth = 0, sal_Unicode cFill = ' ' );
317 static void appendDec( ::rtl::OUStringBuffer& rStr, sal_uInt16 nData, sal_Int32 nWidth = 0, sal_Unicode cFill = ' ' );
318 static void appendDec( ::rtl::OUStringBuffer& rStr, sal_Int16 nData, sal_Int32 nWidth = 0, sal_Unicode cFill = ' ' );
319 static void appendDec( ::rtl::OUStringBuffer& rStr, sal_uInt32 nData, sal_Int32 nWidth = 0, sal_Unicode cFill = ' ' );
320 static void appendDec( ::rtl::OUStringBuffer& rStr, sal_Int32 nData, sal_Int32 nWidth = 0, sal_Unicode cFill = ' ' );
321 static void appendDec( ::rtl::OUStringBuffer& rStr, sal_uInt64 nData, sal_Int32 nWidth = 0, sal_Unicode cFill = ' ' );
322 static void appendDec( ::rtl::OUStringBuffer& rStr, sal_Int64 nData, sal_Int32 nWidth = 0, sal_Unicode cFill = ' ' );
323 static void appendDec( ::rtl::OUStringBuffer& rStr, double fData, sal_Int32 nWidth = 0, sal_Unicode cFill = ' ' );
324
325 // append hexadecimal -----------------------------------------------------
326
327 static void appendHex( ::rtl::OUStringBuffer& rStr, sal_uInt8 nData, bool bPrefix = true );
328 static void appendHex( ::rtl::OUStringBuffer& rStr, sal_Int8 nData, bool bPrefix = true );
329 static void appendHex( ::rtl::OUStringBuffer& rStr, sal_uInt16 nData, bool bPrefix = true );
330 static void appendHex( ::rtl::OUStringBuffer& rStr, sal_Int16 nData, bool bPrefix = true );
331 static void appendHex( ::rtl::OUStringBuffer& rStr, sal_uInt32 nData, bool bPrefix = true );
332 static void appendHex( ::rtl::OUStringBuffer& rStr, sal_Int32 nData, bool bPrefix = true );
333 static void appendHex( ::rtl::OUStringBuffer& rStr, sal_uInt64 nData, bool bPrefix = true );
334 static void appendHex( ::rtl::OUStringBuffer& rStr, sal_Int64 nData, bool bPrefix = true );
335 static void appendHex( ::rtl::OUStringBuffer& rStr, double fData, bool bPrefix = true );
336
337 // append shortened hexadecimal -------------------------------------------
338
339 static void appendShortHex( ::rtl::OUStringBuffer& rStr, sal_uInt8 nData, bool bPrefix = true );
340 static void appendShortHex( ::rtl::OUStringBuffer& rStr, sal_Int8 nData, bool bPrefix = true );
341 static void appendShortHex( ::rtl::OUStringBuffer& rStr, sal_uInt16 nData, bool bPrefix = true );
342 static void appendShortHex( ::rtl::OUStringBuffer& rStr, sal_Int16 nData, bool bPrefix = true );
343 static void appendShortHex( ::rtl::OUStringBuffer& rStr, sal_uInt32 nData, bool bPrefix = true );
344 static void appendShortHex( ::rtl::OUStringBuffer& rStr, sal_Int32 nData, bool bPrefix = true );
345 static void appendShortHex( ::rtl::OUStringBuffer& rStr, sal_uInt64 nData, bool bPrefix = true );
346 static void appendShortHex( ::rtl::OUStringBuffer& rStr, sal_Int64 nData, bool bPrefix = true );
347 static void appendShortHex( ::rtl::OUStringBuffer& rStr, double fData, bool bPrefix = true );
348
349 // append binary ----------------------------------------------------------
350
351 static void appendBin( ::rtl::OUStringBuffer& rStr, sal_uInt8 nData, bool bDots = true );
352 static void appendBin( ::rtl::OUStringBuffer& rStr, sal_Int8 nData, bool bDots = true );
353 static void appendBin( ::rtl::OUStringBuffer& rStr, sal_uInt16 nData, bool bDots = true );
354 static void appendBin( ::rtl::OUStringBuffer& rStr, sal_Int16 nData, bool bDots = true );
355 static void appendBin( ::rtl::OUStringBuffer& rStr, sal_uInt32 nData, bool bDots = true );
356 static void appendBin( ::rtl::OUStringBuffer& rStr, sal_Int32 nData, bool bDots = true );
357 static void appendBin( ::rtl::OUStringBuffer& rStr, sal_uInt64 nData, bool bDots = true );
358 static void appendBin( ::rtl::OUStringBuffer& rStr, sal_Int64 nData, bool bDots = true );
359 static void appendBin( ::rtl::OUStringBuffer& rStr, double fData, bool bDots = true );
360
361 // append fixed-point decimal ---------------------------------------------
362
363 template< typename Type >
364 static void appendFix( ::rtl::OUStringBuffer& rStr, Type nData, sal_Int32 nWidth = 0 );
365
366 // append formatted value -------------------------------------------------
367
368 static void appendBool( ::rtl::OUStringBuffer& rStr, bool bData );
369 template< typename Type >
370 static void appendValue( ::rtl::OUStringBuffer& rStr, Type nData, FormatType eFmtType );
371
372 // append columns, rows, addresses ----------------------------------------
373
374 static void appendAddrCol( ::rtl::OUStringBuffer& rStr, sal_Int32 nCol, bool bRel );
375 static void appendAddrRow( ::rtl::OUStringBuffer& rStr, sal_Int32 nRow, bool bRel );
376 static void appendAddrName( ::rtl::OUStringBuffer& rStr, sal_Unicode cPrefix, sal_Int32 nColRow, bool bRel );
377
378 static void appendAddress( ::rtl::OUStringBuffer& rStr, const Address& rPos );
379 static void appendRange( ::rtl::OUStringBuffer& rStr, const Range& rRange );
380 static void appendRangeList( ::rtl::OUStringBuffer& rStr, const RangeList& rRanges );
381
382 static void appendAddress( ::rtl::OUStringBuffer& rStr, const TokenAddress& rPos, bool bR1C1 );
383 static void appendRange( ::rtl::OUStringBuffer& rStr, const TokenRange& rRange, bool bR1C1 );
384
385 // encoded text output ----------------------------------------------------
386
387 static void appendCChar( ::rtl::OUStringBuffer& rStr, sal_Unicode cChar, bool bPrefix = true );
388 static void appendEncChar( ::rtl::OUStringBuffer& rStr, sal_Unicode cChar, sal_Int32 nCount = 1, bool bPrefix = true );
389 static void appendEncString( ::rtl::OUStringBuffer& rStr, const ::rtl::OUString& rData, bool bPrefix = true );
390
391 // token list -------------------------------------------------------------
392
393 static void appendToken( ::rtl::OUStringBuffer& rStr, const ::rtl::OUString& rToken, sal_Unicode cSep = OOX_DUMP_LISTSEP );
394 static void appendToken( ::rtl::OUStringBuffer& rStr, sal_Int64 nToken, sal_Unicode cSep = OOX_DUMP_LISTSEP );
395 static void prependToken( ::rtl::OUStringBuffer& rStr, const ::rtl::OUString& rToken, sal_Unicode cSep = OOX_DUMP_LISTSEP );
396 static void prependToken( ::rtl::OUStringBuffer& rStr, sal_Int64 nToken, sal_Unicode cSep = OOX_DUMP_LISTSEP );
397
398 static void appendIndex( ::rtl::OUStringBuffer& rStr, const ::rtl::OUString& rIdx );
399 static void appendIndex( ::rtl::OUStringBuffer& rStr, sal_Int64 nIdx );
400 static void appendIndexedText( ::rtl::OUStringBuffer& rStr, const ::rtl::OUString& rData, const ::rtl::OUString& rIdx );
401 static void appendIndexedText( ::rtl::OUStringBuffer& rStr, const ::rtl::OUString& rData, sal_Int64 nIdx );
402
403 static ::rtl::OUString getToken( const ::rtl::OUString& rData, sal_Int32& rnPos, sal_Unicode cSep = OOX_DUMP_LISTSEP );
404
405 /** Encloses the passed string with the passed characters. Uses cOpen, if cClose is NUL. */
406 static void enclose( ::rtl::OUStringBuffer& rStr, sal_Unicode cOpen, sal_Unicode cClose = '\0' );
407
408 // string conversion ------------------------------------------------------
409
410 static ::rtl::OUString trimSpaces( const ::rtl::OUString& rStr );
411 static ::rtl::OUString trimTrailingNul( const ::rtl::OUString& rStr );
412
413 static ::rtl::OString convertToUtf8( const ::rtl::OUString& rStr );
414 static DataType convertToDataType( const ::rtl::OUString& rStr );
415 static FormatType convertToFormatType( const ::rtl::OUString& rStr );
416
417 static bool convertFromDec( sal_Int64& ornData, const ::rtl::OUString& rData );
418 static bool convertFromHex( sal_Int64& ornData, const ::rtl::OUString& rData );
419
420 static bool convertStringToInt( sal_Int64& ornData, const ::rtl::OUString& rData );
421 static bool convertStringToDouble( double& orfData, const ::rtl::OUString& rData );
422 static bool convertStringToBool( const ::rtl::OUString& rData );
423
424 static OUStringPair convertStringToPair( const ::rtl::OUString& rString, sal_Unicode cSep = '=' );
425
426 // string to list conversion ----------------------------------------------
427
428 static void convertStringToStringList( OUStringVector& orVec, const ::rtl::OUString& rData, bool bIgnoreEmpty );
429 static void convertStringToIntList( Int64Vector& orVec, const ::rtl::OUString& rData, bool bIgnoreEmpty );
430 };
431
432 // ----------------------------------------------------------------------------
433
434 template< typename Type >
appendFix(::rtl::OUStringBuffer & rStr,Type nData,sal_Int32 nWidth)435 void StringHelper::appendFix( ::rtl::OUStringBuffer& rStr, Type nData, sal_Int32 nWidth )
436 {
437 appendDec( rStr, static_cast< double >( nData ) / pow( 2.0, 4.0 * sizeof( Type ) ), nWidth );
438 }
439
440 template< typename Type >
appendValue(::rtl::OUStringBuffer & rStr,Type nData,FormatType eFmtType)441 void StringHelper::appendValue( ::rtl::OUStringBuffer& rStr, Type nData, FormatType eFmtType )
442 {
443 switch( eFmtType )
444 {
445 case FORMATTYPE_DEC: appendDec( rStr, nData ); break;
446 case FORMATTYPE_HEX: appendHex( rStr, nData ); break;
447 case FORMATTYPE_SHORTHEX: appendShortHex( rStr, nData ); break;
448 case FORMATTYPE_BIN: appendBin( rStr, nData ); break;
449 case FORMATTYPE_FIX: appendFix( rStr, nData ); break;
450 case FORMATTYPE_BOOL: appendBool( rStr, nData ); break;
451 default:;
452 }
453 }
454
455 // ============================================================================
456
457 class String : public ::rtl::OUString
458 {
459 public:
String()460 inline String() {}
String(const::rtl::OUString & rStr)461 inline /*implicit*/ String( const ::rtl::OUString& rStr ) : ::rtl::OUString( rStr ) {}
String(const sal_Char * pcStr)462 inline /*implicit*/ String( const sal_Char* pcStr ) : ::rtl::OUString( ::rtl::OUString::createFromAscii( pcStr ? pcStr : "" ) ) {}
String(sal_Unicode cChar)463 inline /*implicit*/ String( sal_Unicode cChar ) : ::rtl::OUString( cChar ) {}
464
has() const465 inline bool has() const { return getLength() > 0; }
operator ()(const sal_Char * pcDefault) const466 inline ::rtl::OUString operator()( const sal_Char* pcDefault ) const { if( has() ) return *this; return String( pcDefault ); }
467 };
468
469 static const String EMPTY_STRING;
470
471 // ============================================================================
472 // ============================================================================
473
474 /** Stack to create a human readable formula string from a UPN token array. */
475 class FormulaStack
476 {
477 public:
478 explicit FormulaStack();
479
getFormulaString() const480 inline const ::rtl::OUString& getFormulaString() const { return getString( maFmlaStack ); }
getClassesString() const481 inline const ::rtl::OUString& getClassesString() const { return getString( maClassStack ); }
482
483 void pushOperand( const String& rOp, const ::rtl::OUString& rTokClass );
484 void pushOperand( const String& rOp );
485 void pushUnaryOp( const String& rLOp, const String& rROp );
486 void pushBinaryOp( const String& rOp );
487 void pushFuncOp( const String& rFunc, const ::rtl::OUString& rTokClass, sal_uInt8 nParamCount );
488
setError()489 inline void setError() { mbError = true; }
490 void replaceOnTop( const ::rtl::OUString& rOld, const ::rtl::OUString& rNew );
491
492 private:
493 typedef ::std::stack< ::rtl::OUString > StringStack;
494
check(bool bCond)495 inline bool check( bool bCond ) { return (mbError |= !bCond) == false; }
496
497 const ::rtl::OUString& getString( const StringStack& rStack ) const;
498 void pushUnaryOp( StringStack& rStack, const ::rtl::OUString& rLOp, const ::rtl::OUString& rROp );
499 void pushBinaryOp( StringStack& rStack, const ::rtl::OUString& rOp );
500 void pushFuncOp( StringStack& rStack, const ::rtl::OUString& rOp, sal_uInt8 nParamCount );
501
502 private:
503 StringStack maFmlaStack;
504 StringStack maClassStack;
505 bool mbError;
506 };
507
508 // ============================================================================
509 // ============================================================================
510
511 class Base;
512 typedef ::boost::shared_ptr< Base > BaseRef;
513
514 /** Base class for all dumper classes.
515
516 Derived classes implement the virtual function implIsValid(). It should
517 check all members the other functions rely on. If the function
518 implIsValid() returns true, all references and pointers can be used without
519 further checking.
520
521 Overview of all classes in this header file based on this Base class:
522
523 Base
524 |
525 +----> NameListBase
526 | |
527 | +----> ConstList ------> MultiList
528 | |
529 | +----> FlagsList ------> CombiList
530 | |
531 | +----> UnitConverter
532 |
533 +----> SharedConfigData
534 |
535 +----> Config
536 |
537 +----> Output
538 |
539 +----> StorageIterator
540 |
541 +----> ObjectBase
542 |
543 +----> StorageObjectBase
544 |
545 +----> OutputObjectBase
546 | |
547 | +----> InputObjectBase
548 | |
549 | +----> BinaryStreamObject
550 | |
551 | +----> TextStreamObjectBase
552 | | |
553 | | +----> TextStreamObject
554 | | |
555 | | +----> XmlStreamObject
556 | |
557 | +----> RecordObjectBase
558 | |
559 | +----> SequenceRecordObjectBase
560 |
561 +----> DumperBase
562 */
563 class Base
564 {
565 public:
566 virtual ~Base();
567
isValid() const568 inline bool isValid() const { return implIsValid(); }
isValid(const BaseRef & rxBase)569 inline static bool isValid( const BaseRef& rxBase ) { return rxBase.get() && rxBase->isValid(); }
570
571 protected:
Base()572 inline explicit Base() {}
573
574 virtual bool implIsValid() const = 0;
575 };
576
577 // ============================================================================
578 // ============================================================================
579
580 class ConfigItemBase
581 {
582 public:
583 virtual ~ConfigItemBase();
584 void readConfigBlock( TextInputStream& rStrm );
585
586 protected:
ConfigItemBase()587 inline explicit ConfigItemBase() {}
588
589 virtual void implProcessConfigItemStr(
590 TextInputStream& rStrm,
591 const ::rtl::OUString& rKey,
592 const ::rtl::OUString& rData );
593
594 virtual void implProcessConfigItemInt(
595 TextInputStream& rStrm,
596 sal_Int64 nKey,
597 const ::rtl::OUString& rData );
598
599 void readConfigBlockContents(
600 TextInputStream& rStrm );
601
602 private:
603 enum LineType { LINETYPE_DATA, LINETYPE_END };
604
605 LineType readConfigLine(
606 TextInputStream& rStrm,
607 ::rtl::OUString& orKey,
608 ::rtl::OUString& orData ) const;
609
610 LineType readConfigLine(
611 TextInputStream& rStrm ) const;
612
613 void processConfigItem(
614 TextInputStream& rStrm,
615 const ::rtl::OUString& rKey,
616 const ::rtl::OUString& rData );
617 };
618
619 // ============================================================================
620
621 class SharedConfigData;
622 class Config;
623
624 class NameListBase;
625 typedef ::boost::shared_ptr< NameListBase > NameListRef;
626
627 /** Base class of all classes providing names for specific values (name lists).
628
629 The idea is to provide a unique interfase for all different methods to
630 write specific names for any values. This can be enumerations (dedicated
631 names for a subset of values), or names for bits in bit fields. Classes
632 derived from this base class implement the specific behaviour for the
633 desired purpose.
634 */
635 class NameListBase : public Base, public ConfigItemBase
636 {
637 public:
638 typedef ::std::map< sal_Int64, ::rtl::OUString > OUStringMap;
639 typedef OUStringMap::const_iterator const_iterator;
640
641 public:
642 virtual ~NameListBase();
643
644 /** Sets a name for the specified key. */
645 void setName( sal_Int64 nKey, const String& rName );
646
647 /** Include all names of the passed list. */
648 void includeList( const NameListRef& rxList );
649
650 /** Returns true, if the map contains an entry for the passed key. */
651 template< typename Type >
hasName(Type nKey) const652 inline bool hasName( Type nKey ) const
653 { return maMap.count( static_cast< sal_Int64 >( nKey ) ) != 0; }
654
655 /** Returns the name for the passed key. */
656 template< typename Type >
getName(const Config & rCfg,Type nKey) const657 inline ::rtl::OUString getName( const Config& rCfg, Type nKey ) const
658 { return implGetName( rCfg, static_cast< sal_Int64 >( nKey ) ); }
659
660 /** Returns a display name for the passed double value. */
getName(const Config & rCfg,double fValue) const661 inline ::rtl::OUString getName( const Config& rCfg, double fValue ) const
662 { return implGetNameDbl( rCfg, fValue ); }
663
664 /** Returns a map iterator pointing to the first contained name. */
begin() const665 inline const_iterator begin() const { return maMap.begin(); }
666 /** Returns a map iterator pointing one past the last contained name. */
end() const667 inline const_iterator end() const { return maMap.end(); }
668
669 protected:
NameListBase(const SharedConfigData & rCfgData)670 inline explicit NameListBase( const SharedConfigData& rCfgData ) : mrCfgData( rCfgData ) {}
671
672 virtual bool implIsValid() const;
673
674 virtual void implProcessConfigItemStr(
675 TextInputStream& rStrm,
676 const ::rtl::OUString& rKey,
677 const ::rtl::OUString& rData );
678
679 virtual void implProcessConfigItemInt(
680 TextInputStream& rStrm,
681 sal_Int64 nKey,
682 const ::rtl::OUString& rData );
683
684 /** Derived classes set the name for the passed key. */
685 virtual void implSetName( sal_Int64 nKey, const ::rtl::OUString& rName ) = 0;
686 /** Derived classes generate and return the name for the passed key. */
687 virtual ::rtl::OUString implGetName( const Config& rCfg, sal_Int64 nKey ) const = 0;
688 /** Derived classes generate and return the name for the passed double value. */
689 virtual ::rtl::OUString implGetNameDbl( const Config& rCfg, double fValue ) const = 0;
690 /** Derived classes insert all names and other settings from the passed list. */
691 virtual void implIncludeList( const NameListBase& rList ) = 0;
692
693 /** Inserts the passed name into the internal map. */
694 void insertRawName( sal_Int64 nKey, const ::rtl::OUString& rName );
695 /** Returns the name for the passed key, or 0, if nothing found. */
696 const ::rtl::OUString* findRawName( sal_Int64 nKey ) const;
697
698 private:
699 /** Includes name lists, given in a comma separated list of names of the lists. */
700 void include( const ::rtl::OUString& rListKeys );
701 /** Excludes names from the list, given in a comma separated list of their keys. */
702 void exclude( const ::rtl::OUString& rKeys );
703
704 private:
705 OUStringMap maMap;
706 const SharedConfigData& mrCfgData;
707 };
708
709 // ============================================================================
710
711 class ConstList : public NameListBase
712 {
713 public:
714 explicit ConstList( const SharedConfigData& rCfgData );
715
716 /** Sets a default name for unknown keys. */
setDefaultName(const String & rDefName)717 inline void setDefaultName( const String& rDefName ) { maDefName = rDefName; }
718 /** Enables or disables automatic quotation of returned names. */
setQuoteNames(bool bQuoteNames)719 inline void setQuoteNames( bool bQuoteNames ) { mbQuoteNames = bQuoteNames; }
720
721 protected:
722 virtual void implProcessConfigItemStr(
723 TextInputStream& rStrm,
724 const ::rtl::OUString& rKey,
725 const ::rtl::OUString& rData );
726
727 /** Sets the name for the passed key. */
728 virtual void implSetName( sal_Int64 nKey, const ::rtl::OUString& rName );
729 /** Returns the name for the passed key, or the default name, if key is not contained. */
730 virtual ::rtl::OUString implGetName( const Config& rCfg, sal_Int64 nKey ) const;
731 /** Returns the name for the passed double value. */
732 virtual ::rtl::OUString implGetNameDbl( const Config& rCfg, double fValue ) const;
733 /** Inserts all names from the passed list. */
734 virtual void implIncludeList( const NameListBase& rList );
735
736 private:
737 ::rtl::OUString maDefName;
738 bool mbQuoteNames;
739 };
740
741 // ============================================================================
742
743 class MultiList : public ConstList
744 {
745 public:
746 explicit MultiList( const SharedConfigData& rCfgData );
747
748 void setNamesFromVec( sal_Int64 nStartKey, const OUStringVector& rNames );
749
750 protected:
751 virtual void implProcessConfigItemStr(
752 TextInputStream& rStrm,
753 const ::rtl::OUString& rKey,
754 const ::rtl::OUString& rData );
755
756 virtual void implSetName( sal_Int64 nKey, const ::rtl::OUString& rName );
757
758 private:
759 void insertNames( sal_Int64 nStartKey, const ::rtl::OUString& rData );
760
761 private:
762 bool mbIgnoreEmpty;
763 };
764
765 // ============================================================================
766
767 class FlagsList : public NameListBase
768 {
769 public:
770 explicit FlagsList( const SharedConfigData& rCfgData );
771
772 /** Returns the flags to be ignored on output. */
getIgnoreFlags() const773 inline sal_Int64 getIgnoreFlags() const { return mnIgnore; }
774 /** Sets flags to be ignored on output. */
setIgnoreFlags(sal_Int64 nIgnore)775 inline void setIgnoreFlags( sal_Int64 nIgnore ) { mnIgnore = nIgnore; }
776
777 protected:
778 virtual void implProcessConfigItemStr(
779 TextInputStream& rStrm,
780 const ::rtl::OUString& rKey,
781 const ::rtl::OUString& rData );
782
783 /** Sets the name for the passed key. */
784 virtual void implSetName( sal_Int64 nKey, const ::rtl::OUString& rName );
785 /** Returns the name for the passed key. */
786 virtual ::rtl::OUString implGetName( const Config& rCfg, sal_Int64 nKey ) const;
787 /** Returns the name for the passed double value. */
788 virtual ::rtl::OUString implGetNameDbl( const Config& rCfg, double fValue ) const;
789 /** Inserts all flags from the passed list. */
790 virtual void implIncludeList( const NameListBase& rList );
791
792 private:
793 sal_Int64 mnIgnore;
794 };
795
796 // ============================================================================
797
798 class CombiList : public FlagsList
799 {
800 public:
801 explicit CombiList( const SharedConfigData& rCfgData );
802
803 protected:
804 /** Sets the name for the passed key. */
805 virtual void implSetName( sal_Int64 nKey, const ::rtl::OUString& rName );
806 /** Returns the name for the passed key. */
807 virtual ::rtl::OUString implGetName( const Config& rCfg, sal_Int64 nKey ) const;
808 /** Inserts all flags from the passed list. */
809 virtual void implIncludeList( const NameListBase& rList );
810
811 private:
812 struct ExtItemFormatKey
813 {
814 sal_Int64 mnKey;
815 Int64Pair maFilter;
ExtItemFormatKeyoox::dump::CombiList::ExtItemFormatKey816 inline explicit ExtItemFormatKey( sal_Int64 nKey ) : mnKey( nKey ), maFilter( 0, 0 ) {}
817 bool operator<( const ExtItemFormatKey& rRight ) const;
818
819 };
820 struct ExtItemFormat : public ItemFormat
821 {
822 bool mbShiftValue;
ExtItemFormatoox::dump::CombiList::ExtItemFormat823 inline explicit ExtItemFormat() : mbShiftValue( true ) {}
824 };
825 typedef ::std::map< ExtItemFormatKey, ExtItemFormat > ExtItemFormatMap;
826 ExtItemFormatMap maFmtMap;
827 };
828
829 // ============================================================================
830
831 class UnitConverter : public NameListBase
832 {
833 public:
834 explicit UnitConverter( const SharedConfigData& rCfgData );
835
setUnitName(const String & rUnitName)836 inline void setUnitName( const String& rUnitName ) { maUnitName = rUnitName; }
setFactor(double fFactor)837 inline void setFactor( double fFactor ) { mfFactor = fFactor; }
838
839 protected:
840 /** Sets the name for the passed key. */
841 virtual void implSetName( sal_Int64 nKey, const ::rtl::OUString& rName );
842 /** Returns the converted value with appended unit name. */
843 virtual ::rtl::OUString implGetName( const Config& rCfg, sal_Int64 nKey ) const;
844 /** Returns the converted value with appended unit name. */
845 virtual ::rtl::OUString implGetNameDbl( const Config& rCfg, double fValue ) const;
846 /** Empty implementation. */
847 virtual void implIncludeList( const NameListBase& rList );
848
849 private:
850 ::rtl::OUString maUnitName;
851 double mfFactor;
852 };
853
854 // ============================================================================
855
856 class NameListWrapper
857 {
858 public:
NameListWrapper()859 inline NameListWrapper() {}
NameListWrapper(const::rtl::OUString & rListName)860 inline /*implicit*/ NameListWrapper( const ::rtl::OUString& rListName ) : maName( rListName ) {}
NameListWrapper(const sal_Char * pcListName)861 inline /*implicit*/ NameListWrapper( const sal_Char* pcListName ) : maName( pcListName ) {}
NameListWrapper(const NameListRef & rxList)862 inline /*implicit*/ NameListWrapper( const NameListRef& rxList ) : mxList( rxList ) {}
863
isEmpty() const864 inline bool isEmpty() const { return !mxList && !maName.has(); }
865 NameListRef getNameList( const Config& rCfg ) const;
866
867 private:
868 String maName;
869 mutable NameListRef mxList;
870 };
871
872 static const NameListWrapper NO_LIST;
873
874 // ============================================================================
875
876 class ItemFormatMap : public ::std::map< sal_Int64, ItemFormat >
877 {
878 public:
ItemFormatMap()879 inline explicit ItemFormatMap() {}
ItemFormatMap(const NameListRef & rxNameList)880 inline explicit ItemFormatMap( const NameListRef& rxNameList ) { insertFormats( rxNameList ); }
881
882 void insertFormats( const NameListRef& rxNameList );
883 };
884
885 // ============================================================================
886 // ============================================================================
887
888 class SharedConfigData : public Base, public ConfigItemBase
889 {
890 public:
891 explicit SharedConfigData(
892 const ::rtl::OUString& rFileName,
893 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
894 const StorageRef& rxRootStrg,
895 const ::rtl::OUString& rSysFileName,
896 ::comphelper::MediaDescriptor& rMediaDesc );
897
898 virtual ~SharedConfigData();
899
getContext() const900 inline const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& getContext() const { return mxContext; }
getRootStorage() const901 inline const StorageRef& getRootStorage() const { return mxRootStrg; }
getSysFileName() const902 inline const ::rtl::OUString& getSysFileName() const { return maSysFileName; }
903
904 void setOption( const ::rtl::OUString& rKey, const ::rtl::OUString& rData );
905 const ::rtl::OUString* getOption( const ::rtl::OUString& rKey ) const;
906
907 template< typename ListType >
908 ::boost::shared_ptr< ListType > createNameList( const ::rtl::OUString& rListName );
909 void setNameList( const ::rtl::OUString& rListName, const NameListRef& rxList );
910 void eraseNameList( const ::rtl::OUString& rListName );
911 NameListRef getNameList( const ::rtl::OUString& rListName ) const;
912
913 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > requestEncryptionData( ::comphelper::IDocPasswordVerifier& rVerifier );
isPasswordCancelled() const914 inline bool isPasswordCancelled() const { return mbPwCancelled; }
915
916 protected:
917 virtual bool implIsValid() const;
918 virtual void implProcessConfigItemStr(
919 TextInputStream& rStrm,
920 const ::rtl::OUString& rKey,
921 const ::rtl::OUString& rData );
922
923 private:
924 bool readConfigFile( const ::rtl::OUString& rFileUrl );
925 template< typename ListType >
926 void readNameList( TextInputStream& rStrm, const ::rtl::OUString& rListName );
927 void createShortList( const ::rtl::OUString& rData );
928 void createUnitConverter( const ::rtl::OUString& rData );
929
930 private:
931 typedef ::std::set< ::rtl::OUString > ConfigFileSet;
932 typedef ::std::map< ::rtl::OUString, ::rtl::OUString > ConfigDataMap;
933 typedef ::std::map< ::rtl::OUString, NameListRef > NameListMap;
934
935 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > mxContext;
936 StorageRef mxRootStrg;
937 ::rtl::OUString maSysFileName;
938 ::comphelper::MediaDescriptor& mrMediaDesc;
939 ConfigFileSet maConfigFiles;
940 ConfigDataMap maConfigData;
941 NameListMap maNameLists;
942 ::rtl::OUString maConfigPath;
943 bool mbLoaded;
944 bool mbPwCancelled;
945 };
946
947 // ----------------------------------------------------------------------------
948
949 template< typename ListType >
createNameList(const::rtl::OUString & rListName)950 ::boost::shared_ptr< ListType > SharedConfigData::createNameList( const ::rtl::OUString& rListName )
951 {
952 ::boost::shared_ptr< ListType > xList;
953 if( rListName.getLength() > 0 )
954 {
955 xList.reset( new ListType( *this ) );
956 setNameList( rListName, xList );
957 }
958 return xList;
959 }
960
961 template< typename ListType >
readNameList(TextInputStream & rStrm,const::rtl::OUString & rListName)962 void SharedConfigData::readNameList( TextInputStream& rStrm, const ::rtl::OUString& rListName )
963 {
964 NameListRef xList = createNameList< ListType >( rListName );
965 if( xList.get() )
966 xList->readConfigBlock( rStrm );
967 }
968
969 // ============================================================================
970
971 class Config : public Base
972 {
973 public:
974 explicit Config( const Config& rParent );
975 explicit Config(
976 const sal_Char* pcEnvVar,
977 const ::oox::core::FilterBase& rFilter );
978 explicit Config(
979 const sal_Char* pcEnvVar,
980 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
981 const StorageRef& rxRootStrg,
982 const ::rtl::OUString& rSysFileName,
983 ::comphelper::MediaDescriptor& rMediaDesc );
984
985 virtual ~Config();
986
getContext() const987 inline const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& getContext() const { return mxCfgData->getContext(); }
getRootStorage() const988 inline const StorageRef& getRootStorage() const { return mxCfgData->getRootStorage(); }
getSysFileName() const989 inline const ::rtl::OUString& getSysFileName() const { return mxCfgData->getSysFileName(); }
990
991 void setStringOption( const String& rKey, const String& rData );
992
993 const ::rtl::OUString& getStringOption( const String& rKey, const ::rtl::OUString& rDefault ) const;
994 bool getBoolOption( const String& rKey, bool bDefault ) const;
995 template< typename Type >
996 Type getIntOption( const String& rKey, Type nDefault ) const;
997
998 bool isDumperEnabled() const;
999 bool isImportEnabled() const;
1000
1001 template< typename ListType >
1002 ::boost::shared_ptr< ListType > createNameList( const String& rListName );
1003 void setNameList( const String& rListName, const NameListRef& rxList );
1004 void eraseNameList( const String& rListName );
1005 NameListRef getNameList( const String& rListName ) const;
1006
1007 /** Returns the name for the passed key from the passed name list. */
1008 template< typename Type >
1009 ::rtl::OUString getName( const NameListWrapper& rListWrp, Type nKey ) const;
1010 /** Returns true, if the passed name list contains an entry for the passed key. */
1011 template< typename Type >
1012 bool hasName( const NameListWrapper& rListWrp, Type nKey ) const;
1013
1014 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > requestEncryptionData( ::comphelper::IDocPasswordVerifier& rVerifier );
1015 bool isPasswordCancelled() const;
1016
1017 protected:
Config()1018 inline explicit Config() {}
1019 void construct( const Config& rParent );
1020 void construct(
1021 const sal_Char* pcEnvVar,
1022 const ::oox::core::FilterBase& rFilter );
1023 void construct(
1024 const sal_Char* pcEnvVar,
1025 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
1026 const StorageRef& rxRootStrg,
1027 const ::rtl::OUString& rSysFileName,
1028 ::comphelper::MediaDescriptor& rMediaDesc );
1029
1030 virtual bool implIsValid() const;
1031 virtual const ::rtl::OUString* implGetOption( const ::rtl::OUString& rKey ) const;
1032 virtual NameListRef implGetNameList( const ::rtl::OUString& rListName ) const;
1033
1034 private:
1035 typedef ::boost::shared_ptr< SharedConfigData > SharedConfigDataRef;
1036 SharedConfigDataRef mxCfgData;
1037 };
1038
1039 typedef ::boost::shared_ptr< Config > ConfigRef;
1040
1041 // ----------------------------------------------------------------------------
1042
1043 template< typename Type >
getIntOption(const String & rKey,Type nDefault) const1044 Type Config::getIntOption( const String& rKey, Type nDefault ) const
1045 {
1046 sal_Int64 nRawData;
1047 const ::rtl::OUString* pData = implGetOption( rKey );
1048 return (pData && StringHelper::convertStringToInt( nRawData, *pData )) ?
1049 static_cast< Type >( nRawData ) : nDefault;
1050 }
1051
1052 template< typename ListType >
createNameList(const String & rListName)1053 ::boost::shared_ptr< ListType > Config::createNameList( const String& rListName )
1054 {
1055 return mxCfgData->createNameList< ListType >( rListName );
1056 }
1057
1058 template< typename Type >
getName(const NameListWrapper & rListWrp,Type nKey) const1059 ::rtl::OUString Config::getName( const NameListWrapper& rListWrp, Type nKey ) const
1060 {
1061 NameListRef xList = rListWrp.getNameList( *this );
1062 return xList.get() ? xList->getName( *this, nKey ) : OOX_DUMP_ERR_NOMAP;
1063 }
1064
1065 template< typename Type >
hasName(const NameListWrapper & rListWrp,Type nKey) const1066 bool Config::hasName( const NameListWrapper& rListWrp, Type nKey ) const
1067 {
1068 NameListRef xList = rListWrp.getNameList( *this );
1069 return xList.get() && xList->hasName( nKey );
1070 }
1071
1072 // ============================================================================
1073 // ============================================================================
1074
1075 class Output : public Base
1076 {
1077 public:
1078 explicit Output(
1079 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
1080 const ::rtl::OUString& rFileName );
1081
1082 // ------------------------------------------------------------------------
1083
1084 void newLine();
1085 void emptyLine( size_t nCount = 1 );
getLine()1086 inline ::rtl::OUStringBuffer& getLine() { return maLine; }
1087
1088 void incIndent();
1089 void decIndent();
1090 void resetIndent();
1091
1092 void startTable( sal_Int32 nW1 );
1093 void startTable( sal_Int32 nW1, sal_Int32 nW2 );
1094 void startTable( sal_Int32 nW1, sal_Int32 nW2, sal_Int32 nW3 );
1095 void startTable( sal_Int32 nW1, sal_Int32 nW2, sal_Int32 nW3, sal_Int32 nW4 );
1096 void startTable( size_t nColCount, const sal_Int32* pnColWidths );
1097 void tab();
1098 void tab( size_t nCol );
1099 void endTable();
1100
1101 void resetItemIndex( sal_Int64 nIdx = 0 );
1102 void startItem( const String& rItemName );
1103 void contItem();
1104 void endItem();
getLastItemValue() const1105 inline const ::rtl::OUString& getLastItemValue() const { return maLastItem; }
1106
1107 void startMultiItems();
1108 void endMultiItems();
1109
1110 // ------------------------------------------------------------------------
1111
1112 void writeChar( sal_Unicode cChar, sal_Int32 nCount = 1 );
1113 void writeAscii( const sal_Char* pcStr );
1114 void writeString( const ::rtl::OUString& rStr );
1115 void writeArray( const sal_uInt8* pnData, sal_Size nSize, sal_Unicode cSep = OOX_DUMP_LISTSEP );
1116 void writeBool( bool bData );
1117 void writeColorABGR( sal_Int32 nColor );
1118 void writeDateTime( const ::com::sun::star::util::DateTime& rDateTime );
1119 void writeColIndex( sal_Int32 nCol );
1120 void writeRowIndex( sal_Int32 nRow );
1121 void writeColRowRange( sal_Int32 nColRow1, sal_Int32 nColRow2 );
1122 void writeColRange( sal_Int32 nCol1, sal_Int32 nCol2 );
1123 void writeRowRange( sal_Int32 nRow1, sal_Int32 nRow2 );
1124 void writeAddress( const Address& rPos );
1125 void writeRange( const Range& rRange );
1126 void writeRangeList( const RangeList& rRanges );
1127
1128 template< typename Type >
writeDec(Type nData,sal_Int32 nWidth=0,sal_Unicode cFill=' ')1129 inline void writeDec( Type nData, sal_Int32 nWidth = 0, sal_Unicode cFill = ' ' )
1130 { StringHelper::appendDec( maLine, nData, nWidth, cFill ); }
1131 template< typename Type >
writeHex(Type nData,bool bPrefix=true)1132 inline void writeHex( Type nData, bool bPrefix = true )
1133 { StringHelper::appendHex( maLine, nData, bPrefix ); }
1134 template< typename Type >
writeShortHex(Type nData,bool bPrefix=true)1135 inline void writeShortHex( Type nData, bool bPrefix = true )
1136 { StringHelper::appendShortHex( maLine, nData, bPrefix ); }
1137 template< typename Type >
writeBin(Type nData,bool bDots=true)1138 inline void writeBin( Type nData, bool bDots = true )
1139 { StringHelper::appendBin( maLine, nData, bDots ); }
1140 template< typename Type >
writeFix(Type nData,sal_Int32 nWidth=0)1141 inline void writeFix( Type nData, sal_Int32 nWidth = 0 )
1142 { StringHelper::appendFix( maLine, nData, nWidth ); }
1143 template< typename Type >
writeValue(Type nData,FormatType eFmtType)1144 inline void writeValue( Type nData, FormatType eFmtType )
1145 { StringHelper::appendValue( maLine, nData, eFmtType ); }
1146 template< typename Type >
writeName(const Config & rCfg,Type nData,const NameListWrapper & rListWrp)1147 inline void writeName( const Config& rCfg, Type nData, const NameListWrapper& rListWrp )
1148 { writeString( rCfg.getName( rListWrp, nData ) ); }
1149
1150 // ------------------------------------------------------------------------
1151 protected:
1152 virtual bool implIsValid() const;
1153
1154 private:
1155 void writeItemName( const String& rItemName );
1156
1157 private:
1158 typedef ::std::vector< sal_Int32 > StringLenVec;
1159
1160 ::com::sun::star::uno::Reference< ::com::sun::star::io::XTextOutputStream > mxStrm;
1161 ::rtl::OUString maIndent;
1162 ::rtl::OUStringBuffer maLine;
1163 ::rtl::OUString maLastItem;
1164 StringLenVec maColPos;
1165 size_t mnCol;
1166 size_t mnItemLevel;
1167 size_t mnMultiLevel;
1168 sal_Int64 mnItemIdx;
1169 sal_Int32 mnLastItem;
1170 };
1171
1172 typedef ::boost::shared_ptr< Output > OutputRef;
1173
1174 // ============================================================================
1175
1176 class IndentGuard
1177 {
1178 public:
IndentGuard(const OutputRef & rxOut)1179 inline explicit IndentGuard( const OutputRef& rxOut ) : mrOut( *rxOut ) { mrOut.incIndent(); }
~IndentGuard()1180 inline ~IndentGuard() { mrOut.decIndent(); }
1181 private:
1182 IndentGuard( const IndentGuard& );
1183 IndentGuard& operator=( const IndentGuard& );
1184 private:
1185 Output& mrOut;
1186 };
1187
1188 // ----------------------------------------------------------------------------
1189
1190 class TableGuard
1191 {
1192 public:
TableGuard(const OutputRef & rxOut,sal_Int32 nW1)1193 inline explicit TableGuard( const OutputRef& rxOut, sal_Int32 nW1 ) :
1194 mrOut( *rxOut ) { mrOut.startTable( nW1 ); }
TableGuard(const OutputRef & rxOut,sal_Int32 nW1,sal_Int32 nW2)1195 inline explicit TableGuard( const OutputRef& rxOut, sal_Int32 nW1, sal_Int32 nW2 ) :
1196 mrOut( *rxOut ) { mrOut.startTable( nW1, nW2 ); }
TableGuard(const OutputRef & rxOut,sal_Int32 nW1,sal_Int32 nW2,sal_Int32 nW3)1197 inline explicit TableGuard( const OutputRef& rxOut, sal_Int32 nW1, sal_Int32 nW2, sal_Int32 nW3 ) :
1198 mrOut( *rxOut ) { mrOut.startTable( nW1, nW2, nW3 ); }
TableGuard(const OutputRef & rxOut,sal_Int32 nW1,sal_Int32 nW2,sal_Int32 nW3,sal_Int32 nW4)1199 inline explicit TableGuard( const OutputRef& rxOut, sal_Int32 nW1, sal_Int32 nW2, sal_Int32 nW3, sal_Int32 nW4 ) :
1200 mrOut( *rxOut ) { mrOut.startTable( nW1, nW2, nW3, nW4 ); }
TableGuard(const OutputRef & rxOut,size_t nColCount,const sal_Int32 * pnColWidths)1201 inline explicit TableGuard( const OutputRef& rxOut, size_t nColCount,
1202 const sal_Int32* pnColWidths ) :
1203 mrOut( *rxOut ) { mrOut.startTable( nColCount, pnColWidths ); }
~TableGuard()1204 inline ~TableGuard() { mrOut.endTable(); }
tab()1205 inline void tab() { mrOut.tab(); }
tab(size_t nCol)1206 inline void tab( size_t nCol ) { mrOut.tab( nCol ); }
1207 private:
1208 TableGuard( const TableGuard& );
1209 TableGuard& operator=( const TableGuard& );
1210 private:
1211 Output& mrOut;
1212 };
1213
1214 // ----------------------------------------------------------------------------
1215
1216 class ItemGuard
1217 {
1218 public:
ItemGuard(const OutputRef & rxOut,const String & rName=EMPTY_STRING)1219 inline explicit ItemGuard( const OutputRef& rxOut, const String& rName = EMPTY_STRING ) :
1220 mrOut( *rxOut ) { mrOut.startItem( rName ); }
~ItemGuard()1221 inline ~ItemGuard() { mrOut.endItem(); }
cont()1222 inline void cont() { mrOut.contItem(); }
1223 private:
1224 ItemGuard( const ItemGuard& );
1225 ItemGuard& operator=( const ItemGuard& );
1226 private:
1227 Output& mrOut;
1228 };
1229
1230 // ----------------------------------------------------------------------------
1231
1232 class MultiItemsGuard
1233 {
1234 public:
MultiItemsGuard(const OutputRef & rxOut)1235 inline explicit MultiItemsGuard( const OutputRef& rxOut ) : mrOut( *rxOut ) { mrOut.startMultiItems(); }
~MultiItemsGuard()1236 inline ~MultiItemsGuard() { mrOut.endMultiItems(); }
1237 private:
1238 MultiItemsGuard( const MultiItemsGuard& );
1239 MultiItemsGuard& operator=( const MultiItemsGuard& );
1240 private:
1241 Output& mrOut;
1242 };
1243
1244 // ============================================================================
1245
1246 class StorageIterator : public Base
1247 {
1248 public:
1249 explicit StorageIterator( const StorageRef& rxStrg );
1250 virtual ~StorageIterator();
1251
1252 size_t getElementCount() const;
1253
1254 StorageIterator& operator++();
1255
1256 ::rtl::OUString getName() const;
1257 bool isStream() const;
1258 bool isStorage() const;
1259
1260 private:
1261 virtual bool implIsValid() const;
1262
1263 private:
1264 StorageRef mxStrg;
1265 OUStringVector maNames;
1266 OUStringVector::const_iterator maIt;
1267 };
1268
1269 // ============================================================================
1270 // ============================================================================
1271
1272 class ObjectBase : public Base
1273 {
1274 public:
1275 virtual ~ObjectBase();
1276
1277 inline const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >&
getContext() const1278 getContext() const { return mxConfig->getContext(); }
1279
1280 void dump();
1281
1282 // ------------------------------------------------------------------------
1283 protected:
ObjectBase()1284 inline explicit ObjectBase() {}
1285
1286 void construct( const ConfigRef& rxConfig );
1287 void construct( const ObjectBase& rParent );
1288
1289 virtual bool implIsValid() const;
1290 virtual void implDump();
1291
1292 // ------------------------------------------------------------------------
1293
1294 void reconstructConfig( const ConfigRef& rxConfig );
1295
cfg() const1296 inline Config& cfg() const { return *mxConfig; }
1297
1298 private:
1299 ConfigRef mxConfig;
1300 };
1301
1302 typedef ::boost::shared_ptr< ObjectBase > ObjectRef;
1303
1304 // ============================================================================
1305 // ============================================================================
1306
1307 class StorageObjectBase : public ObjectBase
1308 {
1309 protected:
StorageObjectBase()1310 inline explicit StorageObjectBase() {}
1311
1312 protected:
1313 using ObjectBase::construct;
1314 void construct( const ObjectBase& rParent, const StorageRef& rxStrg, const ::rtl::OUString& rSysPath );
1315 void construct( const ObjectBase& rParent );
1316
1317 virtual bool implIsValid() const;
1318 virtual void implDump();
1319
1320 virtual void implDumpStream(
1321 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxStrm,
1322 const ::rtl::OUString& rStrgPath,
1323 const ::rtl::OUString& rStrmName,
1324 const ::rtl::OUString& rSysFileName );
1325
1326 virtual void implDumpStorage(
1327 const StorageRef& rxStrg,
1328 const ::rtl::OUString& rStrgPath,
1329 const ::rtl::OUString& rSysPath );
1330
1331 virtual void implDumpBaseStream(
1332 const BinaryInputStreamRef& rxStrm,
1333 const ::rtl::OUString& rSysFileName );
1334
1335 void addPreferredStream( const String& rStrmName );
1336 void addPreferredStorage( const String& rStrgPath );
1337
1338 private:
1339 ::rtl::OUString getSysFileName(
1340 const ::rtl::OUString& rStrmName,
1341 const ::rtl::OUString& rSysOutPath );
1342
1343 void extractStream(
1344 StorageBase& rStrg,
1345 const ::rtl::OUString& rStrgPath,
1346 const ::rtl::OUString& rStrmName,
1347 const ::rtl::OUString& rSysFileName );
1348 void extractStorage(
1349 const StorageRef& rxStrg,
1350 const ::rtl::OUString& rStrgPath,
1351 const ::rtl::OUString& rSysPath );
1352
1353 void extractItem(
1354 const StorageRef& rxStrg,
1355 const ::rtl::OUString& rStrgPath,
1356 const ::rtl::OUString& rItemName,
1357 const ::rtl::OUString& rSysPath,
1358 bool bIsStrg, bool bIsStrm );
1359
1360 private:
1361 struct PreferredItem
1362 {
1363 ::rtl::OUString maName;
1364 bool mbStorage;
1365
PreferredItemoox::dump::StorageObjectBase::PreferredItem1366 inline explicit PreferredItem( const ::rtl::OUString rName, bool bStorage ) :
1367 maName( rName ), mbStorage( bStorage ) {}
1368 };
1369 typedef ::std::vector< PreferredItem > PreferredItemVector;
1370
1371 StorageRef mxStrg;
1372 ::rtl::OUString maSysPath;
1373 PreferredItemVector maPreferred;
1374 };
1375
1376 typedef ::boost::shared_ptr< StorageObjectBase > StorageObjectRef;
1377
1378 // ============================================================================
1379 // ============================================================================
1380
1381 class OutputObjectBase : public ObjectBase
1382 {
1383 public:
1384 virtual ~OutputObjectBase();
1385
1386 // ------------------------------------------------------------------------
1387 protected:
OutputObjectBase()1388 inline explicit OutputObjectBase() {}
1389
1390 using ObjectBase::construct;
1391 void construct( const ObjectBase& rParent, const ::rtl::OUString& rSysFileName );
1392 void construct( const OutputObjectBase& rParent );
1393
1394 virtual bool implIsValid() const;
1395
1396 // ------------------------------------------------------------------------
1397
1398 void writeEmptyItem( const String& rName );
1399 void writeInfoItem( const String& rName, const String& rData );
1400 void writeCharItem( const String& rName, sal_Unicode cData );
1401 void writeStringItem( const String& rName, const ::rtl::OUString& rData );
1402 void writeArrayItem( const String& rName, const sal_uInt8* pnData, sal_Size nSize, sal_Unicode cSep = OOX_DUMP_LISTSEP );
1403 void writeBoolItem( const String& rName, bool bData );
1404 double writeRkItem( const String& rName, sal_Int32 nRk );
1405 void writeColorABGRItem( const String& rName, sal_Int32 nColor );
1406 void writeDateTimeItem( const String& rName, const ::com::sun::star::util::DateTime& rDateTime );
1407 void writeGuidItem( const String& rName, const ::rtl::OUString& rGuid );
1408 void writeColIndexItem( const String& rName, sal_Int32 nCol );
1409 void writeRowIndexItem( const String& rName, sal_Int32 nRow );
1410 void writeColRangeItem( const String& rName, sal_Int32 nCol1, sal_Int32 nCol2 );
1411 void writeRowRangeItem( const String& rName, sal_Int32 nRow1, sal_Int32 nRow2 );
1412 void writeAddressItem( const String& rName, const Address& rPos );
1413 void writeRangeItem( const String& rName, const Range& rRange );
1414 void writeRangeListItem( const String& rName, const RangeList& rRanges );
1415 void writeTokenAddressItem( const String& rName, const TokenAddress& rPos, bool bNameMode );
1416 void writeTokenAddress3dItem( const String& rName, const ::rtl::OUString& rRef, const TokenAddress& rPos, bool bNameMode );
1417 void writeTokenRangeItem( const String& rName, const TokenRange& rRange, bool bNameMode );
1418 void writeTokenRange3dItem( const String& rName, const ::rtl::OUString& rRef, const TokenRange& rRange, bool bNameMode );
1419
1420 template< typename Type >
1421 void addNameToItem( Type nData, const NameListWrapper& rListWrp );
1422
1423 template< typename Type >
1424 void writeNameItem( const String& rName, Type nData, const NameListWrapper& rListWrp );
1425 template< typename Type >
1426 void writeDecItem( const String& rName, Type nData, const NameListWrapper& rListWrp = NO_LIST );
1427 template< typename Type >
1428 void writeHexItem( const String& rName, Type nData, const NameListWrapper& rListWrp = NO_LIST );
1429 template< typename Type >
1430 void writeShortHexItem( const String& rName, Type nData, const NameListWrapper& rListWrp = NO_LIST );
1431 template< typename Type >
1432 void writeBinItem( const String& rName, Type nData, const NameListWrapper& rListWrp = NO_LIST );
1433 template< typename Type >
1434 void writeFixItem( const String& rName, Type nData, const NameListWrapper& rListWrp = NO_LIST );
1435 template< typename Type >
1436 void writeDecBoolItem( const String& rName, Type nData, const NameListWrapper& rListWrp = NO_LIST );
1437 template< typename Type >
1438 void writeValueItem( const String& rName, Type nData, FormatType eFmtType, const NameListWrapper& rListWrp = NO_LIST );
1439
1440 template< typename Type >
1441 void writeValueItem( const ItemFormat& rItemFmt, Type nData );
1442
1443 template< typename Type >
1444 void writeDecPairItem( const String& rName, Type nData1, Type nData2, sal_Unicode cSep = ',' );
1445 template< typename Type >
1446 void writeHexPairItem( const String& rName, Type nData1, Type nData2, sal_Unicode cSep = ',' );
1447
1448 protected:
1449 OutputRef mxOut;
1450 ::rtl::OUString maSysFileName;
1451 };
1452
1453 typedef ::boost::shared_ptr< OutputObjectBase > OutputObjectRef;
1454
1455 // ----------------------------------------------------------------------------
1456
1457 template< typename Type >
addNameToItem(Type nData,const NameListWrapper & rListWrp)1458 void OutputObjectBase::addNameToItem( Type nData, const NameListWrapper& rListWrp )
1459 {
1460 if( !rListWrp.isEmpty() )
1461 {
1462 mxOut->contItem();
1463 mxOut->writeName( cfg(), nData, rListWrp );
1464 }
1465 }
1466
1467 template< typename Type >
writeNameItem(const String & rName,Type nData,const NameListWrapper & rListWrp)1468 void OutputObjectBase::writeNameItem( const String& rName, Type nData, const NameListWrapper& rListWrp )
1469 {
1470 ItemGuard aItem( mxOut, rName );
1471 mxOut->writeName( cfg(), nData, rListWrp );
1472 }
1473
1474 template< typename Type >
writeDecItem(const String & rName,Type nData,const NameListWrapper & rListWrp)1475 void OutputObjectBase::writeDecItem( const String& rName, Type nData, const NameListWrapper& rListWrp )
1476 {
1477 ItemGuard aItem( mxOut, rName );
1478 mxOut->writeDec( nData );
1479 addNameToItem( nData, rListWrp );
1480 }
1481
1482 template< typename Type >
writeHexItem(const String & rName,Type nData,const NameListWrapper & rListWrp)1483 void OutputObjectBase::writeHexItem( const String& rName, Type nData, const NameListWrapper& rListWrp )
1484 {
1485 ItemGuard aItem( mxOut, rName );
1486 mxOut->writeHex( nData );
1487 addNameToItem( nData, rListWrp );
1488 }
1489
1490 template< typename Type >
writeShortHexItem(const String & rName,Type nData,const NameListWrapper & rListWrp)1491 void OutputObjectBase::writeShortHexItem( const String& rName, Type nData, const NameListWrapper& rListWrp )
1492 {
1493 ItemGuard aItem( mxOut, rName );
1494 mxOut->writeShortHex( nData );
1495 addNameToItem( nData, rListWrp );
1496 }
1497
1498 template< typename Type >
writeBinItem(const String & rName,Type nData,const NameListWrapper & rListWrp)1499 void OutputObjectBase::writeBinItem( const String& rName, Type nData, const NameListWrapper& rListWrp )
1500 {
1501 ItemGuard aItem( mxOut, rName );
1502 mxOut->writeBin( nData );
1503 addNameToItem( nData, rListWrp );
1504 }
1505
1506 template< typename Type >
writeFixItem(const String & rName,Type nData,const NameListWrapper & rListWrp)1507 void OutputObjectBase::writeFixItem( const String& rName, Type nData, const NameListWrapper& rListWrp )
1508 {
1509 ItemGuard aItem( mxOut, rName );
1510 mxOut->writeFix( nData );
1511 addNameToItem( nData, rListWrp );
1512 }
1513
1514 template< typename Type >
writeDecBoolItem(const String & rName,Type nData,const NameListWrapper & rListWrp)1515 void OutputObjectBase::writeDecBoolItem( const String& rName, Type nData, const NameListWrapper& rListWrp )
1516 {
1517 ItemGuard aItem( mxOut, rName );
1518 mxOut->writeDec( nData );
1519 aItem.cont();
1520 mxOut->writeBool( nData != 0 );
1521 addNameToItem( nData, rListWrp );
1522 }
1523
1524 template< typename Type >
writeValueItem(const String & rName,Type nData,FormatType eFmtType,const NameListWrapper & rListWrp)1525 void OutputObjectBase::writeValueItem( const String& rName, Type nData, FormatType eFmtType, const NameListWrapper& rListWrp )
1526 {
1527 if( eFmtType == FORMATTYPE_BOOL )
1528 writeDecBoolItem( rName, nData, rListWrp );
1529 else
1530 {
1531 ItemGuard aItem( mxOut, rName );
1532 mxOut->writeValue( nData, eFmtType );
1533 addNameToItem( nData, rListWrp );
1534 }
1535 }
1536
1537 template< typename Type >
writeValueItem(const ItemFormat & rItemFmt,Type nData)1538 void OutputObjectBase::writeValueItem( const ItemFormat& rItemFmt, Type nData )
1539 {
1540 ::rtl::OString aNameUtf8 = StringHelper::convertToUtf8( rItemFmt.maItemName );
1541 writeValueItem( aNameUtf8.getStr(), nData, rItemFmt.meFmtType, rItemFmt.maListName );
1542 }
1543
1544 template< typename Type >
writeDecPairItem(const String & rName,Type nData1,Type nData2,sal_Unicode cSep)1545 void OutputObjectBase::writeDecPairItem( const String& rName, Type nData1, Type nData2, sal_Unicode cSep )
1546 {
1547 ItemGuard aItem( mxOut, rName );
1548 mxOut->writeDec( nData1 );
1549 mxOut->writeChar( cSep );
1550 mxOut->writeDec( nData2 );
1551 }
1552
1553 template< typename Type >
writeHexPairItem(const String & rName,Type nData1,Type nData2,sal_Unicode cSep)1554 void OutputObjectBase::writeHexPairItem( const String& rName, Type nData1, Type nData2, sal_Unicode cSep )
1555 {
1556 ItemGuard aItem( mxOut, rName );
1557 mxOut->writeHex( nData1 );
1558 mxOut->writeChar( cSep );
1559 mxOut->writeHex( nData2 );
1560 }
1561
1562 // ============================================================================
1563 // ============================================================================
1564
1565 class InputObjectBase : public OutputObjectBase
1566 {
1567 public:
1568 virtual ~InputObjectBase();
1569
1570 // ------------------------------------------------------------------------
1571 protected:
InputObjectBase()1572 inline explicit InputObjectBase() {}
1573
1574 using OutputObjectBase::construct;
1575 void construct( const ObjectBase& rParent, const BinaryInputStreamRef& rxStrm, const ::rtl::OUString& rSysFileName );
1576 void construct( const OutputObjectBase& rParent, const BinaryInputStreamRef& rxStrm );
1577 void construct( const InputObjectBase& rParent );
1578
1579 virtual bool implIsValid() const;
1580
1581 // ------------------------------------------------------------------------
1582
1583 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
1584 getXInputStream() const;
1585
1586 // ------------------------------------------------------------------------
1587
1588 void skipBlock( sal_Int64 nBytes, bool bShowSize = true );
1589 void dumpRawBinary( sal_Int64 nBytes, bool bShowOffset = true, bool bStream = false );
1590
1591 void dumpBinary( const String& rName, sal_Int64 nBytes, bool bShowOffset = true );
1592 void dumpRemaining( sal_Int64 nBytes );
1593 void dumpRemainingTo( sal_Int64 nPos );
1594 void dumpRemainingStream();
1595
1596 void dumpArray( const String& rName, sal_Int32 nBytes, sal_Unicode cSep = OOX_DUMP_LISTSEP );
dumpUnused(sal_Int32 nBytes)1597 inline void dumpUnused( sal_Int32 nBytes ) { dumpArray( OOX_DUMP_UNUSED, nBytes ); }
dumpUnknown(sal_Int32 nBytes)1598 inline void dumpUnknown( sal_Int32 nBytes ) { dumpArray( OOX_DUMP_UNKNOWN, nBytes ); }
1599
1600 sal_Unicode dumpChar( const String& rName, rtl_TextEncoding eTextEnc );
1601 sal_Unicode dumpUnicode( const String& rName );
1602
1603 ::rtl::OUString dumpCharArray( const String& rName, sal_Int32 nLen, rtl_TextEncoding eTextEnc, bool bHideTrailingNul = false );
1604 ::rtl::OUString dumpUnicodeArray( const String& rName, sal_Int32 nLen, bool bHideTrailingNul = false );
1605
1606 ::rtl::OUString dumpNullCharArray( const String& rName, rtl_TextEncoding eTextEnc );
1607 ::rtl::OUString dumpNullUnicodeArray( const String& rName );
1608
1609 double dumpRk( const String& rName = EMPTY_STRING );
1610 sal_Int32 dumpColorABGR( const String& rName = EMPTY_STRING );
1611 ::com::sun::star::util::DateTime dumpFileTime( const String& rName = EMPTY_STRING );
1612 ::rtl::OUString dumpGuid( const String& rName = EMPTY_STRING );
1613
1614 void dumpItem( const ItemFormat& rItemFmt );
1615
1616 template< typename Type >
1617 Type dumpName( const String& rName, const NameListWrapper& rListWrp );
1618 template< typename Type >
1619 Type dumpDec( const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1620 template< typename Type >
1621 Type dumpHex( const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1622 template< typename Type >
1623 Type dumpBin( const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1624 template< typename Type >
1625 Type dumpFix( const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1626 template< typename Type >
1627 Type dumpBool( const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1628 template< typename Type >
1629 Type dumpValue( const ItemFormat& rItemFmt );
1630
1631 template< typename Type1, typename Type2 >
1632 Type1 dumpName( bool bType1, const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1633 template< typename Type1, typename Type2 >
1634 Type1 dumpDec( bool bType1, const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1635 template< typename Type1, typename Type2 >
1636 Type1 dumpHex( bool bType1, const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1637 template< typename Type1, typename Type2 >
1638 Type1 dumpBin( bool bType1, const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1639 template< typename Type1, typename Type2 >
1640 Type1 dumpFix( bool bType1, const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1641 template< typename Type1, typename Type2 >
1642 Type1 dumpBool( bool bType1, const String& rName, const NameListWrapper& rListWrp = NO_LIST );
1643 template< typename Type1, typename Type2 >
1644 Type1 dumpValue( bool bType1, const ItemFormat& rItemFmt );
1645
1646 template< typename Type >
1647 void dumpDecPair( const String& rName, sal_Unicode cSep = ',' );
1648 template< typename Type >
1649 void dumpHexPair( const String& rName, sal_Unicode cSep = ',' );
1650
1651 protected:
1652 BinaryInputStreamRef mxStrm;
1653 };
1654
1655 typedef ::boost::shared_ptr< InputObjectBase > InputObjectRef;
1656
1657 // ----------------------------------------------------------------------------
1658
1659 template< typename Type >
dumpName(const String & rName,const NameListWrapper & rListWrp)1660 Type InputObjectBase::dumpName( const String& rName, const NameListWrapper& rListWrp )
1661 {
1662 Type nData;
1663 *mxStrm >> nData;
1664 writeNameItem( rName, nData, rListWrp );
1665 return nData;
1666 }
1667
1668 template< typename Type >
dumpDec(const String & rName,const NameListWrapper & rListWrp)1669 Type InputObjectBase::dumpDec( const String& rName, const NameListWrapper& rListWrp )
1670 {
1671 Type nData;
1672 *mxStrm >> nData;
1673 writeDecItem( rName, nData, rListWrp );
1674 return nData;
1675 }
1676
1677 template< typename Type >
dumpHex(const String & rName,const NameListWrapper & rListWrp)1678 Type InputObjectBase::dumpHex( const String& rName, const NameListWrapper& rListWrp )
1679 {
1680 Type nData;
1681 *mxStrm >> nData;
1682 writeHexItem( rName, nData, rListWrp );
1683 return nData;
1684 }
1685
1686 template< typename Type >
dumpBin(const String & rName,const NameListWrapper & rListWrp)1687 Type InputObjectBase::dumpBin( const String& rName, const NameListWrapper& rListWrp )
1688 {
1689 Type nData;
1690 *mxStrm >> nData;
1691 writeBinItem( rName, nData, rListWrp );
1692 return nData;
1693 }
1694
1695 template< typename Type >
dumpFix(const String & rName,const NameListWrapper & rListWrp)1696 Type InputObjectBase::dumpFix( const String& rName, const NameListWrapper& rListWrp )
1697 {
1698 Type nData;
1699 *mxStrm >> nData;
1700 writeFixItem( rName, nData, rListWrp );
1701 return nData;
1702 }
1703
1704 template< typename Type >
dumpBool(const String & rName,const NameListWrapper & rListWrp)1705 Type InputObjectBase::dumpBool( const String& rName, const NameListWrapper& rListWrp )
1706 {
1707 Type nData;
1708 *mxStrm >> nData;
1709 writeDecBoolItem( rName, nData, rListWrp );
1710 return nData;
1711 }
1712
1713 template< typename Type >
dumpValue(const ItemFormat & rItemFmt)1714 Type InputObjectBase::dumpValue( const ItemFormat& rItemFmt )
1715 {
1716 Type nData;
1717 *mxStrm >> nData;
1718 writeValueItem( rItemFmt, nData );
1719 return nData;
1720 }
1721
1722 template< typename Type1, typename Type2 >
dumpName(bool bType1,const String & rName,const NameListWrapper & rListWrp)1723 Type1 InputObjectBase::dumpName( bool bType1, const String& rName, const NameListWrapper& rListWrp )
1724 {
1725 return bType1 ? dumpName< Type1 >( rName, rListWrp ) : static_cast< Type1 >( dumpName< Type2 >( rName, rListWrp ) );
1726 }
1727
1728 template< typename Type1, typename Type2 >
dumpDec(bool bType1,const String & rName,const NameListWrapper & rListWrp)1729 Type1 InputObjectBase::dumpDec( bool bType1, const String& rName, const NameListWrapper& rListWrp )
1730 {
1731 return bType1 ? dumpDec< Type1 >( rName, rListWrp ) : static_cast< Type1 >( dumpDec< Type2 >( rName, rListWrp ) );
1732 }
1733
1734 template< typename Type1, typename Type2 >
dumpHex(bool bType1,const String & rName,const NameListWrapper & rListWrp)1735 Type1 InputObjectBase::dumpHex( bool bType1, const String& rName, const NameListWrapper& rListWrp )
1736 {
1737 return bType1 ? dumpHex< Type1 >( rName, rListWrp ) : static_cast< Type1 >( dumpHex< Type2 >( rName, rListWrp ) );
1738 }
1739
1740 template< typename Type1, typename Type2 >
dumpBin(bool bType1,const String & rName,const NameListWrapper & rListWrp)1741 Type1 InputObjectBase::dumpBin( bool bType1, const String& rName, const NameListWrapper& rListWrp )
1742 {
1743 return bType1 ? dumpBin< Type1 >( rName, rListWrp ) : static_cast< Type1 >( dumpBin< Type2 >( rName, rListWrp ) );
1744 }
1745
1746 template< typename Type1, typename Type2 >
dumpFix(bool bType1,const String & rName,const NameListWrapper & rListWrp)1747 Type1 InputObjectBase::dumpFix( bool bType1, const String& rName, const NameListWrapper& rListWrp )
1748 {
1749 return bType1 ? dumpFix< Type1 >( rName, rListWrp ) : static_cast< Type1 >( dumpFix< Type2 >( rName, rListWrp ) );
1750 }
1751
1752 template< typename Type1, typename Type2 >
dumpBool(bool bType1,const String & rName,const NameListWrapper & rListWrp)1753 Type1 InputObjectBase::dumpBool( bool bType1, const String& rName, const NameListWrapper& rListWrp )
1754 {
1755 return bType1 ? dumpBool< Type1 >( rName, rListWrp ) : static_cast< Type1 >( dumpBool< Type2 >( rName, rListWrp ) );
1756 }
1757
1758 template< typename Type1, typename Type2 >
dumpValue(bool bType1,const ItemFormat & rItemFmt)1759 Type1 InputObjectBase::dumpValue( bool bType1, const ItemFormat& rItemFmt )
1760 {
1761 return bType1 ? dumpValue< Type1 >( rItemFmt ) : static_cast< Type1 >( dumpValue< Type2 >( rItemFmt ) );
1762 }
1763
1764 template< typename Type >
dumpDecPair(const String & rName,sal_Unicode cSep)1765 void InputObjectBase::dumpDecPair( const String& rName, sal_Unicode cSep )
1766 {
1767 Type nData1, nData2;
1768 *mxStrm >> nData1 >> nData2;
1769 writeDecPairItem( rName, nData1, nData2, cSep );
1770 }
1771
1772 template< typename Type >
dumpHexPair(const String & rName,sal_Unicode cSep)1773 void InputObjectBase::dumpHexPair( const String& rName, sal_Unicode cSep )
1774 {
1775 Type nData1, nData2;
1776 *mxStrm >> nData1 >> nData2;
1777 writeHexPairItem( rName, nData1, nData2, cSep );
1778 }
1779
1780 // ============================================================================
1781 // ============================================================================
1782
1783 class BinaryStreamObject : public InputObjectBase
1784 {
1785 public:
1786 explicit BinaryStreamObject(
1787 const ObjectBase& rParent,
1788 const BinaryInputStreamRef& rxStrm,
1789 const ::rtl::OUString& rSysFileName );
1790
1791 explicit BinaryStreamObject(
1792 const OutputObjectBase& rParent,
1793 const BinaryInputStreamRef& rxStrm );
1794
1795 protected:
1796 void dumpBinaryStream( bool bShowOffset = true );
1797
1798 virtual void implDump();
1799 };
1800
1801 // ============================================================================
1802 // ============================================================================
1803
1804 class TextStreamObjectBase : public InputObjectBase
1805 {
1806 protected:
TextStreamObjectBase()1807 inline TextStreamObjectBase() {}
1808
1809 using InputObjectBase::construct;
1810 void construct(
1811 const ObjectBase& rParent,
1812 const BinaryInputStreamRef& rxStrm,
1813 rtl_TextEncoding eTextEnc,
1814 const ::rtl::OUString& rSysFileName );
1815 void construct(
1816 const OutputObjectBase& rParent,
1817 const BinaryInputStreamRef& rxStrm,
1818 rtl_TextEncoding eTextEnc );
1819 void construct(
1820 const InputObjectBase& rParent,
1821 rtl_TextEncoding eTextEnc );
1822
1823 virtual bool implIsValid() const;
1824 virtual void implDump();
1825
1826 virtual void implDumpText( TextInputStream& rTextStrm ) = 0;
1827
1828 private:
1829 void constructTextStrmObj( rtl_TextEncoding eTextEnc );
1830
1831 protected:
1832 ::boost::shared_ptr< TextInputStream > mxTextStrm;
1833 };
1834
1835 // ============================================================================
1836
1837 class TextLineStreamObject : public TextStreamObjectBase
1838 {
1839 public:
1840 explicit TextLineStreamObject(
1841 const ObjectBase& rParent,
1842 const BinaryInputStreamRef& rxStrm,
1843 rtl_TextEncoding eTextEnc,
1844 const ::rtl::OUString& rSysFileName );
1845
1846 explicit TextLineStreamObject(
1847 const OutputObjectBase& rParent,
1848 const BinaryInputStreamRef& rxStrm,
1849 rtl_TextEncoding eTextEnc );
1850
1851 protected:
1852 virtual void implDumpText( TextInputStream& rTextStrm );
1853 virtual void implDumpLine( const ::rtl::OUString& rLine, sal_uInt32 nLine );
1854 };
1855
1856 // ============================================================================
1857
1858 class XmlStreamObject : public TextStreamObjectBase
1859 {
1860 public:
1861 explicit XmlStreamObject(
1862 const ObjectBase& rParent,
1863 const BinaryInputStreamRef& rxStrm,
1864 const ::rtl::OUString& rSysFileName );
1865
1866 explicit XmlStreamObject(
1867 const OutputObjectBase& rParent,
1868 const BinaryInputStreamRef& rxStrm );
1869
1870 protected:
1871 virtual void implDumpText( TextInputStream& rTextStrm );
1872 };
1873
1874 // ============================================================================
1875 // ============================================================================
1876
1877 class RecordObjectBase : public InputObjectBase
1878 {
1879 protected:
RecordObjectBase()1880 inline explicit RecordObjectBase() {}
1881
1882 using InputObjectBase::construct;
1883 void construct(
1884 const ObjectBase& rParent,
1885 const BinaryInputStreamRef& rxBaseStrm,
1886 const ::rtl::OUString& rSysFileName,
1887 const BinaryInputStreamRef& rxRecStrm,
1888 const String& rRecNames,
1889 const String& rSimpleRecs = EMPTY_STRING );
1890 void construct(
1891 const OutputObjectBase& rParent,
1892 const BinaryInputStreamRef& rxBaseStrm,
1893 const BinaryInputStreamRef& rxRecStrm,
1894 const String& rRecNames,
1895 const String& rSimpleRecs = EMPTY_STRING );
1896
getRecPos() const1897 inline sal_Int64 getRecPos() const { return mnRecPos; }
getRecId() const1898 inline sal_Int64 getRecId() const { return mnRecId; }
getRecSize() const1899 inline sal_Int64 getRecSize() const { return mnRecSize; }
getRecNames() const1900 inline NameListRef getRecNames() const { return maRecNames.getNameList( cfg() ); }
1901
setBinaryOnlyMode(bool bBinaryOnly)1902 inline void setBinaryOnlyMode( bool bBinaryOnly ) { mbBinaryOnly = bBinaryOnly; }
isBinaryOnlyMode() const1903 inline bool isBinaryOnlyMode() const { return mbBinaryOnly; }
1904
1905 virtual bool implIsValid() const;
1906 virtual void implDump();
1907
1908 virtual bool implStartRecord( BinaryInputStream& rBaseStrm, sal_Int64& ornRecPos, sal_Int64& ornRecId, sal_Int64& ornRecSize ) = 0;
1909 virtual void implWriteExtHeader();
1910 virtual void implDumpRecordBody();
1911
1912 private:
1913 void constructRecObjBase(
1914 const BinaryInputStreamRef& rxBaseStrm,
1915 const String& rRecNames,
1916 const String& rSimpleRecs );
1917
1918 void writeHeader();
1919
1920 private:
1921 BinaryInputStreamRef mxBaseStrm;
1922 NameListWrapper maRecNames;
1923 NameListWrapper maSimpleRecs;
1924 sal_Int64 mnRecPos;
1925 sal_Int64 mnRecId;
1926 sal_Int64 mnRecSize;
1927 bool mbShowRecPos;
1928 bool mbBinaryOnly;
1929 };
1930
1931 // ============================================================================
1932
1933 class SequenceRecordObjectBase : public RecordObjectBase
1934 {
1935 protected:
SequenceRecordObjectBase()1936 inline explicit SequenceRecordObjectBase() : mxRecData( new StreamDataSequence ) {}
1937
getRecordDataSequence()1938 inline StreamDataSequence& getRecordDataSequence() { return *mxRecData; }
1939
1940 using RecordObjectBase::construct;
1941 void construct(
1942 const ObjectBase& rParent,
1943 const BinaryInputStreamRef& rxBaseStrm,
1944 const ::rtl::OUString& rSysFileName,
1945 const String& rRecNames,
1946 const String& rSimpleRecs = EMPTY_STRING );
1947 void construct(
1948 const OutputObjectBase& rParent,
1949 const BinaryInputStreamRef& rxBaseStrm,
1950 const String& rRecNames,
1951 const String& rSimpleRecs = EMPTY_STRING );
1952
1953 virtual bool implStartRecord( BinaryInputStream& rBaseStrm, sal_Int64& ornRecPos, sal_Int64& ornRecId, sal_Int64& ornRecSize );
1954 virtual bool implReadRecordHeader( BinaryInputStream& rBaseStrm, sal_Int64& ornRecId, sal_Int64& ornRecSize ) = 0;
1955
1956 private:
1957 typedef ::boost::shared_ptr< StreamDataSequence > StreamDataSeqRef;
1958 StreamDataSeqRef mxRecData;
1959 };
1960
1961 // ============================================================================
1962 // ============================================================================
1963
1964 /** Base class for a file dumper. Derived classes implement the implDump()
1965 function to add functionality.
1966 */
1967 class DumperBase : public ObjectBase
1968 {
1969 public:
1970 virtual ~DumperBase();
1971
1972 bool isImportEnabled() const;
1973 bool isImportCancelled() const;
1974
1975 protected:
DumperBase()1976 inline explicit DumperBase() {}
1977
1978 using ObjectBase::construct;
1979 void construct( const ConfigRef& rxConfig );
1980 };
1981
1982 // ============================================================================
1983 // ============================================================================
1984
1985 } // namespace dump
1986 } // namespace oox
1987
1988 #define OOX_DUMP_FILE( DumperClassName ) \
1989 do { \
1990 DumperClassName aDumper( *this ); \
1991 aDumper.dump(); \
1992 bool bCancelled = aDumper.isImportCancelled(); \
1993 if( !aDumper.isImportEnabled() || bCancelled ) \
1994 return aDumper.isValid() && !bCancelled; \
1995 } while( false )
1996
1997 #else // OOX_INCLUDE_DUMPER
1998
1999 #define OOX_DUMP_FILE( DumperClassName ) (void)0
2000
2001 #endif // OOX_INCLUDE_DUMPER
2002 #endif
2003