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