diff options
Diffstat (limited to 'oox/source/dump/dumperbase.cxx')
-rw-r--r-- | oox/source/dump/dumperbase.cxx | 371 |
1 files changed, 162 insertions, 209 deletions
diff --git a/oox/source/dump/dumperbase.cxx b/oox/source/dump/dumperbase.cxx index 8e0e9a4e1225..807a5ec74715 100644 --- a/oox/source/dump/dumperbase.cxx +++ b/oox/source/dump/dumperbase.cxx @@ -38,6 +38,7 @@ #include <osl/file.hxx> #include <comphelper/docpasswordhelper.hxx> #include "oox/helper/binaryoutputstream.hxx" +#include "oox/helper/textinputstream.hxx" #include "oox/core/filterbase.hxx" #include "oox/xls/biffhelper.hxx" @@ -1042,31 +1043,31 @@ ConfigItemBase::~ConfigItemBase() { } -void ConfigItemBase::readConfigBlock( const ConfigInputStreamRef& rxStrm ) +void ConfigItemBase::readConfigBlock( TextInputStream& rStrm ) { - readConfigBlockContents( rxStrm ); + readConfigBlockContents( rStrm ); } void ConfigItemBase::implProcessConfigItemStr( - const ConfigInputStreamRef& /*rxStrm*/, const OUString& /*rKey*/, const OUString& /*rData*/ ) + TextInputStream& /*rStrm*/, const OUString& /*rKey*/, const OUString& /*rData*/ ) { } void ConfigItemBase::implProcessConfigItemInt( - const ConfigInputStreamRef& /*rxStrm*/, sal_Int64 /*nKey*/, const OUString& /*rData*/ ) + TextInputStream& /*rStrm*/, sal_Int64 /*nKey*/, const OUString& /*rData*/ ) { } -void ConfigItemBase::readConfigBlockContents( const ConfigInputStreamRef& rxStrm ) +void ConfigItemBase::readConfigBlockContents( TextInputStream& rStrm ) { bool bLoop = true; - while( bLoop && !rxStrm->isEOF() ) + while( bLoop && !rStrm.isEof() ) { OUString aKey, aData; - switch( readConfigLine( rxStrm, aKey, aData ) ) + switch( readConfigLine( rStrm, aKey, aData ) ) { case LINETYPE_DATA: - processConfigItem( rxStrm, aKey, aData ); + processConfigItem( rStrm, aKey, aData ); break; case LINETYPE_END: bLoop = false; @@ -1076,12 +1077,12 @@ void ConfigItemBase::readConfigBlockContents( const ConfigInputStreamRef& rxStrm } ConfigItemBase::LineType ConfigItemBase::readConfigLine( - const ConfigInputStreamRef& rxStrm, OUString& orKey, OUString& orData ) const + TextInputStream& rStrm, OUString& orKey, OUString& orData ) const { OUString aLine; - while( !rxStrm->isEOF() && (aLine.getLength() == 0) ) + while( !rStrm.isEof() && (aLine.getLength() == 0) ) { - try { aLine = rxStrm->readLine(); } catch( Exception& ) { aLine = OUString(); } + aLine = rStrm.readLine(); if( (aLine.getLength() > 0) && (aLine[ 0 ] == OOX_DUMP_BOM) ) aLine = aLine.copy( 1 ); aLine = StringHelper::trimSpaces( aLine ); @@ -1101,20 +1102,20 @@ ConfigItemBase::LineType ConfigItemBase::readConfigLine( LINETYPE_DATA : LINETYPE_END; } -ConfigItemBase::LineType ConfigItemBase::readConfigLine( const ConfigInputStreamRef& rxStrm ) const +ConfigItemBase::LineType ConfigItemBase::readConfigLine( TextInputStream& rStrm ) const { OUString aKey, aData; - return readConfigLine( rxStrm, aKey, aData ); + return readConfigLine( rStrm, aKey, aData ); } void ConfigItemBase::processConfigItem( - const ConfigInputStreamRef& rxStrm, const OUString& rKey, const OUString& rData ) + TextInputStream& rStrm, const OUString& rKey, const OUString& rData ) { sal_Int64 nKey; if( StringHelper::convertStringToInt( nKey, rKey ) ) - implProcessConfigItemInt( rxStrm, nKey, rData ); + implProcessConfigItemInt( rStrm, nKey, rData ); else - implProcessConfigItemStr( rxStrm, rKey, rData ); + implProcessConfigItemStr( rStrm, rKey, rData ); } // ============================================================================ @@ -1144,18 +1145,18 @@ bool NameListBase::implIsValid() const } void NameListBase::implProcessConfigItemStr( - const ConfigInputStreamRef& rxStrm, const OUString& rKey, const OUString& rData ) + TextInputStream& rStrm, const OUString& rKey, const OUString& rData ) { if( rKey.equalsAscii( "include" ) ) include( rData ); else if( rKey.equalsAscii( "exclude" ) ) exclude( rData ); else - ConfigItemBase::implProcessConfigItemStr( rxStrm, rKey, rData ); + ConfigItemBase::implProcessConfigItemStr( rStrm, rKey, rData ); } void NameListBase::implProcessConfigItemInt( - const ConfigInputStreamRef& /*rxStrm*/, sal_Int64 nKey, const OUString& rData ) + TextInputStream& /*rStrm*/, sal_Int64 nKey, const OUString& rData ) { implSetName( nKey, rData ); } @@ -1206,14 +1207,14 @@ ConstList::ConstList( const SharedConfigData& rCfgData ) : } void ConstList::implProcessConfigItemStr( - const ConfigInputStreamRef& rxStrm, const OUString& rKey, const OUString& rData ) + TextInputStream& rStrm, const OUString& rKey, const OUString& rData ) { if( rKey.equalsAscii( "default" ) ) setDefaultName( rData ); else if( rKey.equalsAscii( "quote-names" ) ) setQuoteNames( StringHelper::convertStringToBool( rData ) ); else - NameListBase::implProcessConfigItemStr( rxStrm, rKey, rData ); + NameListBase::implProcessConfigItemStr( rStrm, rKey, rData ); } void ConstList::implSetName( sal_Int64 nKey, const OUString& rName ) @@ -1265,12 +1266,12 @@ void MultiList::setNamesFromVec( sal_Int64 nStartKey, const OUStringVector& rNam } void MultiList::implProcessConfigItemStr( - const ConfigInputStreamRef& rxStrm, const OUString& rKey, const OUString& rData ) + TextInputStream& rStrm, const OUString& rKey, const OUString& rData ) { if( rKey.equalsAscii( "ignore-empty" ) ) mbIgnoreEmpty = StringHelper::convertStringToBool( rData ); else - ConstList::implProcessConfigItemStr( rxStrm, rKey, rData ); + ConstList::implProcessConfigItemStr( rStrm, rKey, rData ); } void MultiList::implSetName( sal_Int64 nKey, const OUString& rName ) @@ -1289,7 +1290,7 @@ FlagsList::FlagsList( const SharedConfigData& rCfgData ) : } void FlagsList::implProcessConfigItemStr( - const ConfigInputStreamRef& rxStrm, const OUString& rKey, const OUString& rData ) + TextInputStream& rStrm, const OUString& rKey, const OUString& rData ) { if( rKey.equalsAscii( "ignore" ) ) { @@ -1299,7 +1300,7 @@ void FlagsList::implProcessConfigItemStr( } else { - NameListBase::implProcessConfigItemStr( rxStrm, rKey, rData ); + NameListBase::implProcessConfigItemStr( rStrm, rKey, rData ); } } @@ -1600,18 +1601,18 @@ bool SharedConfigData::implIsValid() const } void SharedConfigData::implProcessConfigItemStr( - const ConfigInputStreamRef& rxStrm, const OUString& rKey, const OUString& rData ) + TextInputStream& rStrm, const OUString& rKey, const OUString& rData ) { if( rKey.equalsAscii( "include-config-file" ) ) readConfigFile( maConfigPath + rData ); else if( rKey.equalsAscii( "constlist" ) ) - readNameList< ConstList >( rxStrm, rData ); + readNameList< ConstList >( rStrm, rData ); else if( rKey.equalsAscii( "multilist" ) ) - readNameList< MultiList >( rxStrm, rData ); + readNameList< MultiList >( rStrm, rData ); else if( rKey.equalsAscii( "flagslist" ) ) - readNameList< FlagsList >( rxStrm, rData ); + readNameList< FlagsList >( rStrm, rData ); else if( rKey.equalsAscii( "combilist" ) ) - readNameList< CombiList >( rxStrm, rData ); + readNameList< CombiList >( rStrm, rData ); else if( rKey.equalsAscii( "shortlist" ) ) createShortList( rData ); else if( rKey.equalsAscii( "unitconverter" ) ) @@ -1625,12 +1626,13 @@ bool SharedConfigData::readConfigFile( const OUString& rFileUrl ) bool bLoaded = maConfigFiles.count( rFileUrl ) > 0; if( !bLoaded ) { - Reference< XTextInputStream > xTextInStrm = - InputOutputHelper::openTextInputStream( mxFactory, rFileUrl, CREATE_OUSTRING( "UTF-8" ) ); - if( xTextInStrm.is() ) + Reference< XInputStream > xInStrm = InputOutputHelper::openInputStream( mxFactory, rFileUrl ); + BinaryXInputStream aInStrm( xInStrm, true ); + TextInputStream aTxtStrm( aInStrm, RTL_TEXTENCODING_UTF8 ); + if( !aTxtStrm.isEof() ) { maConfigFiles.insert( rFileUrl ); - readConfigBlockContents( xTextInStrm ); + readConfigBlockContents( aTxtStrm ); bLoaded = true; } } @@ -2220,20 +2222,38 @@ void StorageObjectBase::construct( const ObjectBase& rParent ) bool StorageObjectBase::implIsValid() const { - return mxStrg.get() && mxStrg->isStorage() && (maSysPath.getLength() > 0) && ObjectBase::implIsValid(); + return mxStrg.get() && (maSysPath.getLength() > 0) && ObjectBase::implIsValid(); } void StorageObjectBase::implDump() { - try + bool bIsStrg = mxStrg->isStorage(); + bool bIsRoot = mxStrg->isRootStorage(); + Reference< XInputStream > xBaseStrm; + if( !bIsStrg ) + xBaseStrm = mxStrg->openInputStream( OUString() ); + + OUString aSysOutPath = maSysPath; + if( bIsRoot ) try { + aSysOutPath += OOX_DUMP_DUMPEXT; Reference< XSimpleFileAccess > xFileAccess( getFactory()->createInstance( CREATE_OUSTRING( "com.sun.star.ucb.SimpleFileAccess" ) ), UNO_QUERY_THROW ); - xFileAccess->kill( maSysPath + OOX_DUMP_DUMPEXT ); + xFileAccess->kill( aSysOutPath ); } catch( Exception& ) { } - extractStorage( mxStrg, OUString(), maSysPath ); + + if( bIsStrg ) + { + extractStorage( mxStrg, OUString(), aSysOutPath ); + } + else if( xBaseStrm.is() ) + { + BinaryInputStreamRef xInStrm( new BinaryXInputStream( xBaseStrm, false ) ); + xInStrm->seekToStart(); + implDumpBaseStream( xInStrm, aSysOutPath ); + } } void StorageObjectBase::implDumpStream( const BinaryInputStreamRef&, const OUString&, const OUString&, const OUString& ) @@ -2245,6 +2265,10 @@ void StorageObjectBase::implDumpStorage( const StorageRef& rxStrg, const OUStrin extractStorage( rxStrg, rStrgPath, rSysPath ); } +void StorageObjectBase::implDumpBaseStream( const BinaryInputStreamRef&, const OUString& ) +{ +} + void StorageObjectBase::addPreferredStream( const String& rStrmName ) { if( rStrmName.has() ) @@ -2280,7 +2304,7 @@ void StorageObjectBase::extractStream( StorageBase& rStrg, const OUString& rStrg { BinaryXOutputStream aOutStrm( InputOutputHelper::openOutputStream( getFactory(), rSysFileName ), true ); if( !aOutStrm.isEof() ) - aOutStrm.copyStream( aInStrm ); + aInStrm.copyToStream( aOutStrm ); } BinaryXInputStreamRef xDumpStrm( new BinaryXInputStream( InputOutputHelper::openInputStream( getFactory(), rSysFileName ), true ) ); if( !xDumpStrm->isEof() ) @@ -2289,17 +2313,15 @@ void StorageObjectBase::extractStream( StorageBase& rStrg, const OUString& rStrg void StorageObjectBase::extractStorage( const StorageRef& rxStrg, const OUString& rStrgPath, const OUString& rSysPath ) { - OUString aSysOutPath = rSysPath + OOX_DUMP_DUMPEXT; - // create directory in file system - ::osl::FileBase::RC eRes = ::osl::Directory::create( aSysOutPath ); + ::osl::FileBase::RC eRes = ::osl::Directory::create( rSysPath ); if( (eRes != ::osl::FileBase::E_None) && (eRes != ::osl::FileBase::E_EXIST) ) return; // process preferred storages and streams in root storage first if( rStrgPath.getLength() == 0 ) for( PreferredItemVector::iterator aIt = maPreferred.begin(), aEnd = maPreferred.end(); aIt != aEnd; ++aIt ) - extractItem( rxStrg, rStrgPath, aIt->maName, aSysOutPath, aIt->mbStorage, !aIt->mbStorage ); + extractItem( rxStrg, rStrgPath, aIt->maName, rSysPath, aIt->mbStorage, !aIt->mbStorage ); // process children of the storage for( StorageIterator aIt( rxStrg ); aIt.isValid(); ++aIt ) @@ -2311,13 +2333,13 @@ void StorageObjectBase::extractStorage( const StorageRef& rxStrg, const OUString for( PreferredItemVector::iterator aIIt = maPreferred.begin(), aIEnd = maPreferred.end(); !bFound && (aIIt != aIEnd); ++aIIt ) bFound = aIIt->maName == aItemName; if( !bFound ) - extractItem( rxStrg, rStrgPath, aItemName, aSysOutPath, aIt.isStorage(), aIt.isStream() ); + extractItem( rxStrg, rStrgPath, aItemName, rSysPath, aIt.isStorage(), aIt.isStream() ); } } -void StorageObjectBase::extractItem( const StorageRef& rxStrg, const OUString& rStrgPath, const OUString& rItemName, const OUString& rSysOutPath, bool bIsStrg, bool bIsStrm ) +void StorageObjectBase::extractItem( const StorageRef& rxStrg, const OUString& rStrgPath, const OUString& rItemName, const OUString& rSysPath, bool bIsStrg, bool bIsStrm ) { - OUString aSysFileName = getSysFileName( rItemName, rSysOutPath ); + OUString aSysFileName = getSysFileName( rItemName, rSysPath ); if( bIsStrg ) { OUStringBuffer aStrgPath( rStrgPath ); @@ -2362,18 +2384,18 @@ bool OutputObjectBase::implIsValid() const void OutputObjectBase::writeEmptyItem( const String& rName ) { - ItemGuard aItem( *mxOut, rName ); + ItemGuard aItem( mxOut, rName ); } void OutputObjectBase::writeInfoItem( const String& rName, const String& rData ) { - ItemGuard aItem( *mxOut, rName ); + ItemGuard aItem( mxOut, rName ); mxOut->writeString( rData ); } void OutputObjectBase::writeCharItem( const String& rName, sal_Unicode cData ) { - ItemGuard aItem( *mxOut, rName ); + ItemGuard aItem( mxOut, rName ); mxOut->writeChar( OOX_DUMP_STRQUOTE ); mxOut->writeChar( cData ); mxOut->writeChar( OOX_DUMP_STRQUOTE ); @@ -2381,7 +2403,7 @@ void OutputObjectBase::writeCharItem( const String& rName, sal_Unicode cData ) void OutputObjectBase::writeStringItem( const String& rName, const OUString& rData ) { - ItemGuard aItem( *mxOut, rName ); + ItemGuard aItem( mxOut, rName ); mxOut->writeAscii( "(len=" ); mxOut->writeDec( rData.getLength() ); mxOut->writeAscii( ")," ); @@ -2394,19 +2416,19 @@ void OutputObjectBase::writeStringItem( const String& rName, const OUString& rDa void OutputObjectBase::writeArrayItem( const String& rName, const sal_uInt8* pnData, sal_Size nSize, sal_Unicode cSep ) { - ItemGuard aItem( *mxOut, rName ); + ItemGuard aItem( mxOut, rName ); mxOut->writeArray( pnData, nSize, cSep ); } void OutputObjectBase::writeBoolItem( const String& rName, bool bData ) { - ItemGuard aItem( *mxOut, rName ); + ItemGuard aItem( mxOut, rName ); mxOut->writeBool( bData ); } double OutputObjectBase::writeRkItem( const String& rName, sal_Int32 nRk ) { - MultiItemsGuard aMultiGuard( out() ); + MultiItemsGuard aMultiGuard( mxOut ); writeHexItem( rName, static_cast< sal_uInt32 >( nRk ), "RK-FLAGS" ); double fValue = ::oox::xls::BiffHelper::calcDoubleFromRk( nRk ); writeDecItem( "decoded", fValue ); @@ -2415,20 +2437,20 @@ double OutputObjectBase::writeRkItem( const String& rName, sal_Int32 nRk ) void OutputObjectBase::writeColorABGRItem( const String& rName, sal_Int32 nColor ) { - ItemGuard aItem( *mxOut, rName ); + ItemGuard aItem( mxOut, rName ); writeHexItem( rName, nColor ); mxOut->writeColorABGR( nColor ); } void OutputObjectBase::writeDateTimeItem( const String& rName, const DateTime& rDateTime ) { - ItemGuard aItem( *mxOut, rName ); + ItemGuard aItem( mxOut, rName ); mxOut->writeDateTime( rDateTime ); } void OutputObjectBase::writeGuidItem( const String& rName, const OUString& rGuid ) { - ItemGuard aItem( *mxOut, rName ); + ItemGuard aItem( mxOut, rName ); mxOut->writeString( rGuid ); aItem.cont(); mxOut->writeString( cfg().getStringOption( rGuid, OUString() ) ); @@ -2436,85 +2458,81 @@ void OutputObjectBase::writeGuidItem( const String& rName, const OUString& rGuid void OutputObjectBase::writeColIndexItem( const String& rName, sal_Int32 nCol ) { - Output& rOut = out(); - ItemGuard aItem( rOut, rName ); - rOut.writeDec( nCol ); + ItemGuard aItem( mxOut, rName ); + mxOut->writeDec( nCol ); aItem.cont(); - rOut.writeColIndex( nCol ); + mxOut->writeColIndex( nCol ); } void OutputObjectBase::writeRowIndexItem( const String& rName, sal_Int32 nRow ) { - Output& rOut = out(); - ItemGuard aItem( rOut, rName ); - rOut.writeDec( nRow ); + ItemGuard aItem( mxOut, rName ); + mxOut->writeDec( nRow ); aItem.cont(); - rOut.writeRowIndex( nRow ); + mxOut->writeRowIndex( nRow ); } void OutputObjectBase::writeColRangeItem( const String& rName, sal_Int32 nCol1, sal_Int32 nCol2 ) { - Output& rOut = out(); - ItemGuard aItem( rOut, rName ); - rOut.writeColRowRange( nCol1, nCol2 ); + ItemGuard aItem( mxOut, rName ); + mxOut->writeColRowRange( nCol1, nCol2 ); aItem.cont(); - rOut.writeColRange( nCol1, nCol2 ); + mxOut->writeColRange( nCol1, nCol2 ); } void OutputObjectBase::writeRowRangeItem( const String& rName, sal_Int32 nRow1, sal_Int32 nRow2 ) { - Output& rOut = out(); - ItemGuard aItem( rOut, rName ); - rOut.writeColRowRange( nRow1, nRow2 ); + ItemGuard aItem( mxOut, rName ); + mxOut->writeColRowRange( nRow1, nRow2 ); aItem.cont(); - rOut.writeRowRange( nRow1, nRow2 ); + mxOut->writeRowRange( nRow1, nRow2 ); } void OutputObjectBase::writeAddressItem( const String& rName, const Address& rPos ) { - ItemGuard aItem( out(), rName ); - StringHelper::appendAddress( out().getLine(), rPos ); + ItemGuard aItem( mxOut, rName ); + StringHelper::appendAddress( mxOut->getLine(), rPos ); } void OutputObjectBase::writeRangeItem( const String& rName, const Range& rRange ) { - ItemGuard aItem( out(), rName ); - StringHelper::appendRange( out().getLine(), rRange ); + ItemGuard aItem( mxOut, rName ); + StringHelper::appendRange( mxOut->getLine(), rRange ); } void OutputObjectBase::writeRangeListItem( const String& rName, const RangeList& rRanges ) { - MultiItemsGuard aMultiGuard( out() ); + MultiItemsGuard aMultiGuard( mxOut ); writeEmptyItem( rName ); writeDecItem( "count", static_cast< sal_uInt16 >( rRanges.size() ) ); - ItemGuard aItem( out(), "ranges" ); - StringHelper::appendRangeList( out().getLine(), rRanges ); + ItemGuard aItem( mxOut, "ranges" ); + StringHelper::appendRangeList( mxOut->getLine(), rRanges ); } void OutputObjectBase::writeTokenAddressItem( const String& rName, const TokenAddress& rPos, bool bNameMode ) { - ItemGuard aItem( out(), rName ); - StringHelper::appendAddress( out().getLine(), rPos, bNameMode ); + ItemGuard aItem( mxOut, rName ); + StringHelper::appendAddress( mxOut->getLine(), rPos, bNameMode ); } void OutputObjectBase::writeTokenAddress3dItem( const String& rName, const OUString& rRef, const TokenAddress& rPos, bool bNameMode ) { - ItemGuard aItem( out(), rName ); - out().writeString( rRef ); - StringHelper::appendAddress( out().getLine(), rPos, bNameMode ); + ItemGuard aItem( mxOut, rName ); + mxOut->writeString( rRef ); + StringHelper::appendAddress( mxOut->getLine(), rPos, bNameMode ); } void OutputObjectBase::writeTokenRangeItem( const String& rName, const TokenRange& rRange, bool bNameMode ) { - ItemGuard aItem( out(), rName ); - StringHelper::appendRange( out().getLine(), rRange, bNameMode ); + ItemGuard aItem( mxOut, rName ); + StringHelper::appendRange( mxOut->getLine(), rRange, bNameMode ); } void OutputObjectBase::writeTokenRange3dItem( const String& rName, const OUString& rRef, const TokenRange& rRange, bool bNameMode ) { - ItemGuard aItem( out(), rName ); - out().writeString( rRef ); - StringHelper::appendRange( out().getLine(), rRange, bNameMode ); + ItemGuard aItem( mxOut, rName ); + mxOut->writeString( rRef ); + StringHelper::appendRange( mxOut->getLine(), rRange, bNameMode ); } // ============================================================================ @@ -2565,8 +2583,7 @@ void InputObjectBase::skipBlock( sal_Int64 nBytes, bool bShowSize ) void InputObjectBase::dumpRawBinary( sal_Int64 nBytes, bool bShowOffset, bool bStream ) { - Output& rOut = out(); - TableGuard aTabGuard( rOut, + TableGuard aTabGuard( mxOut, bShowOffset ? 12 : 0, 3 * OOX_DUMP_BYTESPERLINE / 2 + 1, 3 * OOX_DUMP_BYTESPERLINE / 2 + 1, @@ -2583,8 +2600,8 @@ void InputObjectBase::dumpRawBinary( sal_Int64 nBytes, bool bShowOffset, bool bS while( bLoop && (nPos < nDumpEnd) ) { - rOut.writeHex( static_cast< sal_uInt32 >( nPos ) ); - rOut.tab(); + mxOut->writeHex( static_cast< sal_uInt32 >( nPos ) ); + mxOut->tab(); sal_uInt8 pnLineData[ OOX_DUMP_BYTESPERLINE ]; sal_Int32 nLineSize = bSeekable ? ::std::min( static_cast< sal_Int32 >( nDumpEnd - mxStrm->tell() ), OOX_DUMP_BYTESPERLINE ) : OOX_DUMP_BYTESPERLINE; @@ -2598,18 +2615,18 @@ void InputObjectBase::dumpRawBinary( sal_Int64 nBytes, bool bShowOffset, bool bS const sal_uInt8* pnEnd = 0; for( pnByte = pnLineData, pnEnd = pnLineData + nReadSize; pnByte != pnEnd; ++pnByte ) { - if( (pnByte - pnLineData) == (OOX_DUMP_BYTESPERLINE / 2) ) rOut.tab(); - rOut.writeHex( *pnByte, false ); - rOut.writeChar( ' ' ); + if( (pnByte - pnLineData) == (OOX_DUMP_BYTESPERLINE / 2) ) mxOut->tab(); + mxOut->writeHex( *pnByte, false ); + mxOut->writeChar( ' ' ); } aTabGuard.tab( 3 ); for( pnByte = pnLineData, pnEnd = pnLineData + nReadSize; pnByte != pnEnd; ++pnByte ) { - if( (pnByte - pnLineData) == (OOX_DUMP_BYTESPERLINE / 2) ) rOut.tab(); - rOut.writeChar( static_cast< sal_Unicode >( (*pnByte < 0x20) ? '.' : *pnByte ) ); + if( (pnByte - pnLineData) == (OOX_DUMP_BYTESPERLINE / 2) ) mxOut->tab(); + mxOut->writeChar( static_cast< sal_Unicode >( (*pnByte < 0x20) ? '.' : *pnByte ) ); } - rOut.newLine(); + mxOut->newLine(); } } @@ -2621,11 +2638,11 @@ void InputObjectBase::dumpRawBinary( sal_Int64 nBytes, bool bShowOffset, bool bS void InputObjectBase::dumpBinary( const String& rName, sal_Int64 nBytes, bool bShowOffset ) { { - MultiItemsGuard aMultiGuard( out() ); + MultiItemsGuard aMultiGuard( mxOut ); writeEmptyItem( rName ); writeDecItem( "size", nBytes ); } - IndentGuard aIndGuard( out() ); + IndentGuard aIndGuard( mxOut ); dumpRawBinary( nBytes, bShowOffset ); } @@ -2642,7 +2659,7 @@ void InputObjectBase::dumpRemaining( sal_Int64 nBytes ) void InputObjectBase::dumpRemainingTo( sal_Int64 nPos ) { - if( mxStrm->isEof() ) + if( mxStrm->isEof() || (mxStrm->tell() > nPos) ) writeInfoItem( "stream-state", OOX_DUMP_ERR_STREAM ); else dumpRemaining( nPos - mxStrm->tell() ); @@ -2760,7 +2777,7 @@ DateTime InputObjectBase::dumpFileTime( const String& rName ) { DateTime aDateTime; - ItemGuard aItem( out(), rName( "file-time" ) ); + ItemGuard aItem( mxOut, rName( "file-time" ) ); sal_Int64 nFileTime = dumpDec< sal_Int64 >( EMPTY_STRING ); // file time is in 10^-7 seconds (100 nanoseconds), convert to 1/100 seconds nFileTime /= 100000; @@ -2871,9 +2888,9 @@ BinaryStreamObject::BinaryStreamObject( const OutputObjectBase& rParent, const B void BinaryStreamObject::dumpBinaryStream( bool bShowOffset ) { - in().seek( 0 ); - dumpRawBinary( in().getLength(), bShowOffset, true ); - out().emptyLine(); + mxStrm->seekToStart(); + dumpRawBinary( mxStrm->getLength(), bShowOffset, true ); + mxOut->emptyLine(); } void BinaryStreamObject::implDump() @@ -2883,110 +2900,47 @@ void BinaryStreamObject::implDump() // ============================================================================ -namespace { - -bool lclIsEof( BinaryInputStream& rStrm ) -{ - return rStrm.isEof() || (rStrm.isSeekable() && (rStrm.tell() >= rStrm.getLength())); -} - -template< typename BufferType, typename CharType > -CharType lclAppendChar( BufferType& orBuffer, CharType cChar ) -{ - if( (cChar == 0x0A) || (cChar == 0x0D) ) - return cChar; - orBuffer.append( cChar ); - return 0; -} - -template< typename BufferType, typename CharType, typename StreamDataType > -bool lclReadLine( BufferType& orBuffer, sal_Unicode& orcNextLineChar, BinaryInputStream& rStrm ) -{ - CharType cLineEndChar = (orcNextLineChar == 0) ? 0 : lclAppendChar( orBuffer, static_cast< CharType >( orcNextLineChar ) ); - orcNextLineChar = 0; - - // read chars until EOF or line end character (LF or CR) - bool bIsEof = lclIsEof( rStrm ); - while( !bIsEof && (cLineEndChar == 0) ) - { - CharType cChar = static_cast< CharType >( rStrm.readValue< StreamDataType >() ); - bIsEof = rStrm.isEof(); - cLineEndChar = bIsEof ? 0 : lclAppendChar( orBuffer, cChar ); - } - - // try to skip LF following CR, or CR following LF - if( !lclIsEof( rStrm ) && (cLineEndChar != 0) ) - { - CharType cChar = static_cast< CharType >( rStrm.readValue< StreamDataType >() ); - bool bLineEnd = ((cChar == 0x0A) || (cChar == 0x0D)) && (cChar != cLineEndChar); - if( !rStrm.isEof() && !bLineEnd ) - orcNextLineChar = static_cast< sal_Unicode >( cChar ); - } - - return (cLineEndChar != 0) || (orBuffer.getLength() > 0); -} - -} // namespace - -// ---------------------------------------------------------------------------- - TextStreamObject::TextStreamObject( const ObjectBase& rParent, - const BinaryInputStreamRef& rxStrm, rtl_TextEncoding eTextEnc, const OUString& rSysFileName ) : - meTextEnc( eTextEnc ) + const BinaryInputStreamRef& rxStrm, rtl_TextEncoding eTextEnc, const OUString& rSysFileName ) { InputObjectBase::construct( rParent, rxStrm, rSysFileName ); + if( rxStrm.get() ) + mxTextStrm.reset( new TextInputStream( *rxStrm, eTextEnc ) ); } TextStreamObject::TextStreamObject( const OutputObjectBase& rParent, - const BinaryInputStreamRef& rxStrm, rtl_TextEncoding eTextEnc ) : - meTextEnc( eTextEnc ) + const BinaryInputStreamRef& rxStrm, rtl_TextEncoding eTextEnc ) { InputObjectBase::construct( rParent, rxStrm ); + if( rxStrm.get() ) + mxTextStrm.reset( new TextInputStream( *rxStrm, eTextEnc ) ); +} + +bool TextStreamObject::implIsValid() const +{ + return InputObjectBase::implIsValid() && mxTextStrm.get(); } void TextStreamObject::implDump() { OUString aLine; - sal_Unicode cNextLineChar = 0; sal_uInt32 nLine = 0; - while( readLine( aLine, cNextLineChar ) ) - implDumpLine( aLine, ++nLine ); - out().emptyLine(); + while( !mxTextStrm->isEof() ) + { + aLine = mxTextStrm->readLine(); + if( !mxTextStrm->isEof() ) + implDumpLine( aLine, ++nLine ); + } + mxOut->emptyLine(); } void TextStreamObject::implDumpLine( const OUString& rLine, sal_uInt32 nLine ) { - Output& rOut = out(); - TableGuard aTabGuard( rOut, 8 ); - rOut.writeDec( nLine, 6 ); - rOut.tab(); - rOut.writeString( rLine ); - rOut.newLine(); -} - -bool TextStreamObject::readCharLine( OUString& orLine, sal_Unicode& orcNextLineChar ) -{ - OStringBuffer aBuffer; - bool bHasData = lclReadLine< OStringBuffer, sal_Char, sal_uInt8 >( aBuffer, orcNextLineChar, in() ); - if( bHasData ) - orLine = OStringToOUString( aBuffer.makeStringAndClear(), meTextEnc ); - return bHasData; -} - -bool TextStreamObject::readUcs2Line( OUString& orLine, sal_Unicode& orcNextLineChar ) -{ - OUStringBuffer aBuffer; - bool bHasData = lclReadLine< OUStringBuffer, sal_Unicode, sal_uInt16 >( aBuffer, orcNextLineChar, in() ); - if( bHasData ) - orLine = aBuffer.makeStringAndClear(); - return bHasData; -} - -bool TextStreamObject::readLine( OUString& orLine, sal_Unicode& orcNextLineChar ) -{ - return (meTextEnc == RTL_TEXTENCODING_UCS2) ? - readUcs2Line( orLine, orcNextLineChar ) : - readCharLine( orLine, orcNextLineChar ); + TableGuard aTabGuard( mxOut, 8 ); + mxOut->writeDec( nLine, 6 ); + mxOut->tab(); + mxOut->writeString( rLine ); + mxOut->newLine(); } // ============================================================================ @@ -3002,9 +2956,9 @@ void XmlStreamObject::implDump() TextStreamObject::implDump(); if( maIncompleteLine.getLength() > 0 ) { - out().resetIndent(); - out().writeString( maIncompleteLine ); - out().emptyLine(); + mxOut->resetIndent(); + mxOut->writeString( maIncompleteLine ); + mxOut->emptyLine(); writeInfoItem( "stream-state", OOX_DUMP_ERR_STREAM ); } } @@ -3018,10 +2972,9 @@ void XmlStreamObject::implDumpLine( const OUString& rLine, sal_uInt32 ) aLine.append( rLine ); maIncompleteLine = OUString(); - Output& rOut = out(); if( aLine.getLength() == 0 ) { - rOut.newLine(); + mxOut->newLine(); return; } @@ -3092,10 +3045,10 @@ void XmlStreamObject::implDumpLine( const OUString& rLine, sal_uInt32 ) // flush output line if( maIncompleteLine.getLength() == 0 ) { - if( !bIsStartElement && bIsEndElement ) rOut.decIndent(); - rOut.writeString( aOutLine.makeStringAndClear() ); - rOut.newLine(); - if( bIsStartElement && !bIsEndElement ) rOut.incIndent(); + if( !bIsStartElement && bIsEndElement ) mxOut->decIndent(); + mxOut->writeString( aOutLine.makeStringAndClear() ); + mxOut->newLine(); + if( bIsStartElement && !bIsEndElement ) mxOut->incIndent(); } } } @@ -3131,11 +3084,11 @@ void RecordObjectBase::implDump() while( implStartRecord( *mxBaseStrm, mnRecPos, mnRecId, mnRecSize ) ) { // record header - out().emptyLine(); + mxOut->emptyLine(); writeHeader(); implWriteExtHeader(); - IndentGuard aIndGuard( out() ); - sal_Int64 nRecPos = in().tell(); + IndentGuard aIndGuard( mxOut ); + sal_Int64 nRecPos = mxStrm->tell(); // record body if( !mbBinaryOnly && cfg().hasName( xRecNames, mnRecId ) ) @@ -3148,7 +3101,7 @@ void RecordObjectBase::implDump() } // remaining undumped data - if( !in().isEof() && (in().tell() == nRecPos) ) + if( !mxStrm->isEof() && (mxStrm->tell() == nRecPos) ) dumpRawBinary( mnRecSize, false ); else dumpRemainingTo( nRecPos + mnRecSize ); @@ -3176,13 +3129,13 @@ void RecordObjectBase::constructRecObjBase( const BinaryInputStreamRef& rxBaseSt void RecordObjectBase::writeHeader() { - MultiItemsGuard aMultiGuard( out() ); + MultiItemsGuard aMultiGuard( mxOut ); writeEmptyItem( "REC" ); if( mbShowRecPos && mxBaseStrm->isSeekable() ) writeShortHexItem( "pos", mnRecPos, "CONV-DEC" ); writeShortHexItem( "size", mnRecSize, "CONV-DEC" ); - ItemGuard aItem( out(), "id" ); - out().writeShortHex( mnRecId ); + ItemGuard aItem( mxOut, "id" ); + mxOut->writeShortHex( mnRecId ); addNameToItem( mnRecId, "CONV-DEC" ); addNameToItem( mnRecId, maRecNames ); } @@ -3224,7 +3177,7 @@ bool SequenceRecordObjectBase::implStartRecord( BinaryInputStream& rBaseStrm, sa sal_Int32 nRecSize = static_cast< sal_Int32 >( ornRecSize ); mxRecData->realloc( nRecSize ); bValid = (nRecSize == 0) || (rBaseStrm.readData( *mxRecData, nRecSize ) == nRecSize); - in().seekToStart(); + mxStrm->seekToStart(); } return bValid; } |