diff options
author | Daniel Rentz <dr@openoffice.org> | 2010-04-14 17:31:33 +0200 |
---|---|---|
committer | Daniel Rentz <dr@openoffice.org> | 2010-04-14 17:31:33 +0200 |
commit | 319c08647f115aaba7f5633376531cbfb4746b2f (patch) | |
tree | ab588184dfebf4be0f369015c5c1434277f476f2 /oox/source/helper | |
parent | 62895872c7f5635b890d150dc6c2d8d4c58917e9 (diff) |
npower13_objectmodules: make vba import available in oox filters
Diffstat (limited to 'oox/source/helper')
-rw-r--r-- | oox/source/helper/binaryinputstream.cxx | 97 | ||||
-rw-r--r-- | oox/source/helper/binaryoutputstream.cxx | 20 | ||||
-rw-r--r-- | oox/source/helper/binarystreambase.cxx | 21 | ||||
-rw-r--r-- | oox/source/helper/graphichelper.cxx | 224 | ||||
-rw-r--r-- | oox/source/helper/makefile.mk | 2 | ||||
-rw-r--r-- | oox/source/helper/modelobjecthelper.cxx | 10 | ||||
-rw-r--r-- | oox/source/helper/olestorage.cxx | 180 | ||||
-rw-r--r-- | oox/source/helper/propertyset.cxx | 44 | ||||
-rw-r--r-- | oox/source/helper/storagebase.cxx | 145 | ||||
-rwxr-xr-x | oox/source/helper/textinputstream.cxx | 128 | ||||
-rw-r--r-- | oox/source/helper/zipstorage.cxx | 56 |
11 files changed, 620 insertions, 307 deletions
diff --git a/oox/source/helper/binaryinputstream.cxx b/oox/source/helper/binaryinputstream.cxx index 5ba4a8b0b73b..9ca6938f2ff1 100644 --- a/oox/source/helper/binaryinputstream.cxx +++ b/oox/source/helper/binaryinputstream.cxx @@ -30,6 +30,7 @@ #include <vector> #include <rtl/strbuf.hxx> #include <rtl/ustrbuf.hxx> +#include "oox/helper/binaryoutputstream.hxx" using ::rtl::OString; using ::rtl::OStringBuffer; @@ -102,6 +103,25 @@ OUString BinaryInputStream::readUnicodeArray( sal_Int32 nChars, bool bAllowNulCh return aBuffer.makeStringAndClear(); } +void BinaryInputStream::copyToStream( BinaryOutputStream& rOutStrm, sal_Int64 nBytes ) +{ + if( nBytes > 0 ) + { + sal_Int32 nBufferSize = getLimitedValue< sal_Int32, sal_Int64 >( nBytes, 0, INPUTSTREAM_BUFFERSIZE ); + StreamDataSequence aBuffer( nBufferSize ); + while( nBytes > 0 ) + { + sal_Int32 nReadSize = getLimitedValue< sal_Int32, sal_Int64 >( nBytes, 0, nBufferSize ); + sal_Int32 nBytesRead = readData( aBuffer, nReadSize ); + rOutStrm.writeData( aBuffer ); + if( nReadSize == nBytesRead ) + nBytes -= nReadSize; + else + nBytes = 0; + } + } +} + void BinaryInputStream::readAtom( void* opMem, sal_uInt8 nSize ) { readMemory( opMem, nSize ); @@ -214,7 +234,7 @@ sal_Int32 SequenceInputStream::readMemory( void* opMem, sal_Int32 nBytes ) sal_Int32 nReadBytes = 0; if( !mbEof ) { - nReadBytes = ::std::min< sal_Int32 >( nBytes, mrData.getLength() - mnPos ); + nReadBytes = getLimitedValue< sal_Int32, sal_Int32 >( nBytes, 0, mrData.getLength() - mnPos ); if( nReadBytes > 0 ) memcpy( opMem, mrData.getConstArray() + mnPos, static_cast< size_t >( nReadBytes ) ); mnPos += nReadBytes; @@ -227,7 +247,7 @@ void SequenceInputStream::skip( sal_Int32 nBytes ) { if( !mbEof ) { - sal_Int32 nSkipBytes = ::std::min< sal_Int32 >( nBytes, mrData.getLength() - mnPos ); + sal_Int32 nSkipBytes = getLimitedValue< sal_Int32, sal_Int32 >( nBytes, 0, mrData.getLength() - mnPos ); mnPos += nSkipBytes; mbEof = nSkipBytes < nBytes; } @@ -235,5 +255,78 @@ void SequenceInputStream::skip( sal_Int32 nBytes ) // ============================================================================ +RelativeInputStream::RelativeInputStream( BinaryInputStream& rInStrm, sal_Int64 nLength ) : + mrInStrm( rInStrm ), + mnStartPos( rInStrm.tell() ), + mnRelPos( 0 ) +{ + sal_Int64 nRemaining = rInStrm.getRemaining(); + mnLength = (nRemaining >= 0) ? ::std::min( nLength, nRemaining ) : nLength; + mbEof = mnLength < 0; +} + +bool RelativeInputStream::isSeekable() const +{ + return mrInStrm.isSeekable(); +} + +sal_Int64 RelativeInputStream::getLength() const +{ + return mnLength; +} + +sal_Int64 RelativeInputStream::tell() const +{ + return mnRelPos; +} + +void RelativeInputStream::seek( sal_Int64 nPos ) +{ + if( mrInStrm.isSeekable() && (mnStartPos >= 0) ) + { + mnRelPos = getLimitedValue< sal_Int64, sal_Int64 >( nPos, 0, mnLength ); + mrInStrm.seek( mnStartPos + mnRelPos ); + mbEof = (mnRelPos != nPos) || mrInStrm.isEof(); + } +} + +sal_Int32 RelativeInputStream::readData( StreamDataSequence& orData, sal_Int32 nBytes ) +{ + sal_Int32 nReadBytes = 0; + if( !mbEof ) + { + sal_Int32 nRealBytes = getLimitedValue< sal_Int32, sal_Int64 >( nBytes, 0, mnLength - mnRelPos ); + nReadBytes = mrInStrm.readData( orData, nRealBytes ); + mnRelPos += nReadBytes; + mbEof = (nRealBytes < nBytes) || mrInStrm.isEof(); + } + return nReadBytes; +} + +sal_Int32 RelativeInputStream::readMemory( void* opMem, sal_Int32 nBytes ) +{ + sal_Int32 nReadBytes = 0; + if( !mbEof ) + { + sal_Int32 nRealBytes = getLimitedValue< sal_Int32, sal_Int64 >( nBytes, 0, mnLength - mnRelPos ); + nReadBytes = mrInStrm.readMemory( opMem, nRealBytes ); + mnRelPos += nReadBytes; + mbEof = (nRealBytes < nBytes) || mrInStrm.isEof(); + } + return nReadBytes; +} + +void RelativeInputStream::skip( sal_Int32 nBytes ) +{ + if( !mbEof ) + { + sal_Int32 nSkipBytes = getLimitedValue< sal_Int32, sal_Int64 >( nBytes, 0, mnLength - mnRelPos ); + mnRelPos += nSkipBytes; + mbEof = nSkipBytes < nBytes; + } +} + +// ============================================================================ + } // namespace oox diff --git a/oox/source/helper/binaryoutputstream.cxx b/oox/source/helper/binaryoutputstream.cxx index be6bc6d67577..f39ac9d8f1b2 100644 --- a/oox/source/helper/binaryoutputstream.cxx +++ b/oox/source/helper/binaryoutputstream.cxx @@ -27,7 +27,6 @@ #include "oox/helper/binaryoutputstream.hxx" #include <osl/diagnose.h> -#include "oox/helper/binaryinputstream.hxx" #include <string.h> using ::com::sun::star::uno::UNO_QUERY; @@ -42,25 +41,6 @@ const sal_Int32 OUTPUTSTREAM_BUFFERSIZE = 0x8000; // ============================================================================ -void BinaryOutputStream::copyStream( BinaryInputStream& rInStrm, sal_Int64 nBytes ) -{ - if( nBytes > 0 ) - { - sal_Int32 nBufferSize = getLimitedValue< sal_Int32, sal_Int64 >( nBytes, 0, OUTPUTSTREAM_BUFFERSIZE ); - StreamDataSequence aBuffer( nBufferSize ); - while( nBytes > 0 ) - { - sal_Int32 nReadSize = getLimitedValue< sal_Int32, sal_Int64 >( nBytes, 0, nBufferSize ); - sal_Int32 nBytesRead = rInStrm.readData( aBuffer, nReadSize ); - writeData( aBuffer ); - if( nReadSize == nBytesRead ) - nBytes -= nReadSize; - else - nBytes = 0; - } - } -} - void BinaryOutputStream::writeAtom( const void* pMem, sal_uInt8 nSize ) { writeMemory( pMem, nSize ); diff --git a/oox/source/helper/binarystreambase.cxx b/oox/source/helper/binarystreambase.cxx index be6b17d3aab9..86eae793a3c1 100644 --- a/oox/source/helper/binarystreambase.cxx +++ b/oox/source/helper/binarystreambase.cxx @@ -61,7 +61,24 @@ void BinaryStreamBase::seek( sal_Int64 ) sal_Int64 BinaryStreamBase::getRemaining() const { - return isSeekable() ? ::std::max< sal_Int64 >( getLength() - tell(), 0 ) : -1; + // do not use isSeekable(), implementations may provide stream position and size even if not seekable + sal_Int64 nPos = tell(); + sal_Int64 nLen = getLength(); + return ((nPos >= 0) && (nLen >= 0)) ? ::std::max< sal_Int64 >( nLen - nPos, 0 ) : -1; +} + +void BinaryStreamBase::align( sal_Int32 nBlockSize, sal_Int64 nAnchorPos ) +{ + sal_Int64 nStrmPos = tell(); + // nothing to do, if stream is at anchor position + if( isSeekable() && (0 <= nAnchorPos) && (nAnchorPos != nStrmPos) && (nBlockSize > 1) ) + { + // prevent modulo with negative arguments... + sal_Int64 nSkipSize = (nAnchorPos < nStrmPos) ? + (nBlockSize - ((nStrmPos - nAnchorPos - 1) % nBlockSize) - 1) : + ((nAnchorPos - nStrmPos) % nBlockSize); + seek( nStrmPos + nSkipSize ); + } } // ============================================================================ @@ -135,7 +152,7 @@ sal_Int64 SequenceSeekableStream::tell() const void SequenceSeekableStream::seek( sal_Int64 nPos ) { mnPos = getLimitedValue< sal_Int32, sal_Int64 >( nPos, 0, mrData.getLength() ); - mbEof = mnPos < nPos; + mbEof = mnPos != nPos; } // ============================================================================ diff --git a/oox/source/helper/graphichelper.cxx b/oox/source/helper/graphichelper.cxx index 3e54cd16c2bc..6e57ac8f2b2f 100644 --- a/oox/source/helper/graphichelper.cxx +++ b/oox/source/helper/graphichelper.cxx @@ -26,42 +26,236 @@ ************************************************************************/ #include "oox/helper/graphichelper.hxx" +#include <com/sun/star/awt/Point.hpp> +#include <com/sun/star/awt/Size.hpp> +#include <com/sun/star/awt/XDevice.hpp> +#include <com/sun/star/awt/XUnitConversion.hpp> +#include <com/sun/star/frame/XFramesSupplier.hpp> #include <com/sun/star/graphic/GraphicObject.hpp> #include <com/sun/star/graphic/XGraphicProvider.hpp> +#include <com/sun/star/util/MeasureUnit.hpp> #include <comphelper/componentcontext.hxx> #include <comphelper/seqstream.hxx> +#include "tokens.hxx" +#include "oox/helper/containerhelper.hxx" using ::rtl::OUString; -using ::com::sun::star::uno::Exception; -using ::com::sun::star::uno::Reference; -using ::com::sun::star::uno::Sequence; -using ::com::sun::star::uno::UNO_QUERY; -using ::com::sun::star::uno::UNO_SET_THROW; +using ::com::sun::star::awt::DeviceInfo; +using ::com::sun::star::awt::Point; +using ::com::sun::star::awt::Size; +using ::com::sun::star::awt::XDevice; +using ::com::sun::star::awt::XUnitConversion; using ::com::sun::star::beans::PropertyValue; -using ::com::sun::star::io::XInputStream; -using ::com::sun::star::lang::XMultiServiceFactory; +using ::com::sun::star::frame::XFrame; +using ::com::sun::star::frame::XFramesSupplier; using ::com::sun::star::graphic::GraphicObject; using ::com::sun::star::graphic::XGraphic; using ::com::sun::star::graphic::XGraphicObject; using ::com::sun::star::graphic::XGraphicProvider; +using ::com::sun::star::io::XInputStream; +using ::com::sun::star::lang::XMultiServiceFactory; +using ::com::sun::star::uno::Exception; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::UNO_QUERY; +using ::com::sun::star::uno::UNO_QUERY_THROW; +using ::com::sun::star::uno::UNO_SET_THROW; namespace oox { // ============================================================================ -GraphicHelper::GraphicHelper( const Reference< XMultiServiceFactory >& rxFactory ) : - mxGraphicProvider( rxFactory->createInstance( CREATE_OUSTRING( "com.sun.star.graphic.GraphicProvider" ) ), UNO_QUERY ), +namespace { + +inline sal_Int32 lclConvertScreenPixelToHmm( double fPixel, double fPixelPerHmm ) +{ + return static_cast< sal_Int32 >( (fPixelPerHmm > 0.0) ? (fPixel / fPixelPerHmm + 0.5) : 0.0 ); +} + +} // namespace + +// ============================================================================ + +GraphicHelper::GraphicHelper( const Reference< XMultiServiceFactory >& rxGlobalFactory ) : + mxGraphicProvider( rxGlobalFactory->createInstance( CREATE_OUSTRING( "com.sun.star.graphic.GraphicProvider" ) ), UNO_QUERY ), maGraphicObjScheme( CREATE_OUSTRING( "vnd.sun.star.GraphicObject:" ) ) { - ::comphelper::ComponentContext aContext( rxFactory ); + ::comphelper::ComponentContext aContext( rxGlobalFactory ); mxCompContext = aContext.getUNOContext(); + + //! TODO: get colors from system + maSystemPalette[ XML_3dDkShadow ] = 0x716F64; + maSystemPalette[ XML_3dLight ] = 0xF1EFE2; + maSystemPalette[ XML_activeBorder ] = 0xD4D0C8; + maSystemPalette[ XML_activeCaption ] = 0x0054E3; + maSystemPalette[ XML_appWorkspace ] = 0x808080; + maSystemPalette[ XML_background ] = 0x004E98; + maSystemPalette[ XML_btnFace ] = 0xECE9D8; + maSystemPalette[ XML_btnHighlight ] = 0xFFFFFF; + maSystemPalette[ XML_btnShadow ] = 0xACA899; + maSystemPalette[ XML_btnText ] = 0x000000; + maSystemPalette[ XML_captionText ] = 0xFFFFFF; + maSystemPalette[ XML_gradientActiveCaption ] = 0x3D95FF; + maSystemPalette[ XML_gradientInactiveCaption ] = 0xD8E4F8; + maSystemPalette[ XML_grayText ] = 0xACA899; + maSystemPalette[ XML_highlight ] = 0x316AC5; + maSystemPalette[ XML_highlightText ] = 0xFFFFFF; + maSystemPalette[ XML_hotLight ] = 0x000080; + maSystemPalette[ XML_inactiveBorder ] = 0xD4D0C8; + maSystemPalette[ XML_inactiveCaption ] = 0x7A96DF; + maSystemPalette[ XML_inactiveCaptionText ] = 0xD8E4F8; + maSystemPalette[ XML_infoBk ] = 0xFFFFE1; + maSystemPalette[ XML_infoText ] = 0x000000; + maSystemPalette[ XML_menu ] = 0xFFFFFF; + maSystemPalette[ XML_menuBar ] = 0xECE9D8; + maSystemPalette[ XML_menuHighlight ] = 0x316AC5; + maSystemPalette[ XML_menuText ] = 0x000000; + maSystemPalette[ XML_scrollBar ] = 0xD4D0C8; + maSystemPalette[ XML_window ] = 0xFFFFFF; + maSystemPalette[ XML_windowFrame ] = 0x000000; + maSystemPalette[ XML_windowText ] = 0x000000; + + // get the metric of the output device + if( rxGlobalFactory.is() ) try + { + Reference< XFramesSupplier > xFramesSupp( rxGlobalFactory->createInstance( CREATE_OUSTRING( "com.sun.star.frame.Desktop" ) ), UNO_QUERY_THROW ); + Reference< XFrame > xFrame( xFramesSupp->getActiveFrame(), UNO_SET_THROW ); + Reference< XDevice > xDevice( xFrame->getContainerWindow(), UNO_QUERY_THROW ); + mxUnitConversion.set( xDevice, UNO_QUERY ); + maDeviceInfo = xDevice->getInfo(); + mfPixelPerHmmX = maDeviceInfo.PixelPerMeterX / 100000.0; + mfPixelPerHmmY = maDeviceInfo.PixelPerMeterY / 100000.0; + } + catch( Exception& ) + { + OSL_ENSURE( false, "GraphicHelper::GraphicHelper - cannot get output device info" ); + } } GraphicHelper::~GraphicHelper() { } -Reference< XGraphic > GraphicHelper::importGraphic( const Reference< XInputStream >& rxInStrm ) +sal_Int32 GraphicHelper::getSystemColor( sal_Int32 nToken, sal_Int32 nDefaultRgb ) const +{ + const sal_Int32* pnColor = ContainerHelper::getMapElement( maSystemPalette, nToken ); + return pnColor ? *pnColor : nDefaultRgb; +} + +sal_Int32 GraphicHelper::getSchemeColor( sal_Int32 /*nToken*/ ) const +{ + OSL_ENSURE( false, "GraphicHelper::getSchemeColor - scheme colors not implemented" ); + return API_RGB_TRANSPARENT; +} + +sal_Int32 GraphicHelper::getPaletteColor( sal_Int32 /*nPaletteIdx*/ ) const +{ + OSL_ENSURE( false, "GraphicHelper::getPaletteColor - palette colors not implemented" ); + return API_RGB_TRANSPARENT; +} + +const DeviceInfo& GraphicHelper::getDeviceInfo() const +{ + return maDeviceInfo; +} + +sal_Int32 GraphicHelper::convertScreenPixelXToHmm( double fPixelX ) const +{ + return lclConvertScreenPixelToHmm( fPixelX, mfPixelPerHmmX ); +} + +sal_Int32 GraphicHelper::convertScreenPixelYToHmm( double fPixelY ) const +{ + return lclConvertScreenPixelToHmm( fPixelY, mfPixelPerHmmY ); +} + +Point GraphicHelper::convertScreenPixelToHmm( const Point& rPixel ) const +{ + return Point( convertScreenPixelXToHmm( rPixel.X ), convertScreenPixelYToHmm( rPixel.Y ) ); +} + +Size GraphicHelper::convertScreenPixelToHmm( const Size& rPixel ) const +{ + return Size( convertScreenPixelXToHmm( rPixel.Width ), convertScreenPixelYToHmm( rPixel.Height ) ); +} + +double GraphicHelper::convertHmmToScreenPixelX( sal_Int32 nHmmX ) const +{ + return nHmmX * mfPixelPerHmmX; +} + +double GraphicHelper::convertHmmToScreenPixelY( sal_Int32 nHmmY ) const +{ + return nHmmY * mfPixelPerHmmY; +} + +Point GraphicHelper::convertHmmToScreenPixel( const Point& rHmm ) const +{ + return Point( + static_cast< sal_Int32 >( convertHmmToScreenPixelX( rHmm.X ) + 0.5 ), + static_cast< sal_Int32 >( convertHmmToScreenPixelY( rHmm.Y ) + 0.5 ) ); +} + +Size GraphicHelper::convertHmmToScreenPixel( const Size& rHmm ) const +{ + return Size( + static_cast< sal_Int32 >( convertHmmToScreenPixelX( rHmm.Width ) + 0.5 ), + static_cast< sal_Int32 >( convertHmmToScreenPixelY( rHmm.Height ) + 0.5 ) ); +} + +Point GraphicHelper::convertAppFontToHmm( const Point& rAppFont ) const +{ + if( mxUnitConversion.is() ) try + { + Point aPixel = mxUnitConversion->convertPointToPixel( rAppFont, ::com::sun::star::util::MeasureUnit::APPFONT ); + return convertScreenPixelToHmm( aPixel ); + } + catch( Exception& ) + { + } + return Point( 0, 0 ); +} + +Size GraphicHelper::convertAppFontToHmm( const Size& rAppFont ) const +{ + if( mxUnitConversion.is() ) try + { + Size aPixel = mxUnitConversion->convertSizeToPixel( rAppFont, ::com::sun::star::util::MeasureUnit::APPFONT ); + return convertScreenPixelToHmm( aPixel ); + } + catch( Exception& ) + { + } + return Size( 0, 0 ); +} + +Point GraphicHelper::convertHmmToAppFont( const Point& rHmm ) const +{ + if( mxUnitConversion.is() ) try + { + Point aPixel = convertHmmToScreenPixel( rHmm ); + return mxUnitConversion->convertPointToLogic( aPixel, ::com::sun::star::util::MeasureUnit::APPFONT ); + } + catch( Exception& ) + { + } + return Point( 0, 0 ); +} + +Size GraphicHelper::convertHmmToAppFont( const Size& rHmm ) const +{ + if( mxUnitConversion.is() ) try + { + Size aPixel = convertHmmToScreenPixel( rHmm ); + return mxUnitConversion->convertSizeToLogic( aPixel, ::com::sun::star::util::MeasureUnit::APPFONT ); + } + catch( Exception& ) + { + } + return Size( 0, 0 ); +} + +Reference< XGraphic > GraphicHelper::importGraphic( const Reference< XInputStream >& rxInStrm ) const { Reference< XGraphic > xGraphic; if( rxInStrm.is() && mxGraphicProvider.is() ) try @@ -77,7 +271,7 @@ Reference< XGraphic > GraphicHelper::importGraphic( const Reference< XInputStrea return xGraphic; } -Reference< XGraphic > GraphicHelper::importGraphic( const StreamDataSequence& rGraphicData ) +Reference< XGraphic > GraphicHelper::importGraphic( const StreamDataSequence& rGraphicData ) const { Reference< XGraphic > xGraphic; if( rGraphicData.hasElements() ) @@ -88,7 +282,7 @@ Reference< XGraphic > GraphicHelper::importGraphic( const StreamDataSequence& rG return xGraphic; } -OUString GraphicHelper::createGraphicObject( const Reference< XGraphic >& rxGraphic ) +OUString GraphicHelper::createGraphicObject( const Reference< XGraphic >& rxGraphic ) const { OUString aGraphicObjUrl; if( mxCompContext.is() && rxGraphic.is() ) try @@ -104,12 +298,12 @@ OUString GraphicHelper::createGraphicObject( const Reference< XGraphic >& rxGrap return aGraphicObjUrl; } -OUString GraphicHelper::importGraphicObject( const Reference< XInputStream >& rxInStrm ) +OUString GraphicHelper::importGraphicObject( const Reference< XInputStream >& rxInStrm ) const { return createGraphicObject( importGraphic( rxInStrm ) ); } -OUString GraphicHelper::importGraphicObject( const StreamDataSequence& rGraphicData ) +OUString GraphicHelper::importGraphicObject( const StreamDataSequence& rGraphicData ) const { return createGraphicObject( importGraphic( rGraphicData ) ); } diff --git a/oox/source/helper/makefile.mk b/oox/source/helper/makefile.mk index 4a91a7a47764..3518db0c6d7c 100644 --- a/oox/source/helper/makefile.mk +++ b/oox/source/helper/makefile.mk @@ -48,12 +48,12 @@ SLOFILES = \ $(SLO)$/containerhelper.obj \ $(SLO)$/graphichelper.obj \ $(SLO)$/modelobjecthelper.obj \ - $(SLO)$/olestorage.obj \ $(SLO)$/progressbar.obj \ $(SLO)$/propertymap.obj \ $(SLO)$/propertyset.obj \ $(SLO)$/recordinputstream.obj \ $(SLO)$/storagebase.obj \ + $(SLO)$/textinputstream.obj \ $(SLO)$/zipstorage.obj # --- Targets ------------------------------------------------------- diff --git a/oox/source/helper/modelobjecthelper.cxx b/oox/source/helper/modelobjecthelper.cxx index d1996991090a..6528fea5634d 100644 --- a/oox/source/helper/modelobjecthelper.cxx +++ b/oox/source/helper/modelobjecthelper.cxx @@ -44,11 +44,11 @@ namespace oox { // ============================================================================ -ModelObjectHelper::ModelObjectHelper( const Reference< XMultiServiceFactory >& rxFactory ) : - maMarkerContainer( rxFactory, CREATE_OUSTRING( "com.sun.star.drawing.MarkerTable" ) ), - maDashContainer( rxFactory, CREATE_OUSTRING( "com.sun.star.drawing.DashTable" ) ), - maGradientContainer( rxFactory, CREATE_OUSTRING( "com.sun.star.drawing.GradientTable" ) ), - maBitmapContainer( rxFactory, CREATE_OUSTRING( "com.sun.star.drawing.BitmapTable" ) ), +ModelObjectHelper::ModelObjectHelper( const Reference< XMultiServiceFactory >& rxModelFactory ) : + maMarkerContainer( rxModelFactory, CREATE_OUSTRING( "com.sun.star.drawing.MarkerTable" ) ), + maDashContainer( rxModelFactory, CREATE_OUSTRING( "com.sun.star.drawing.DashTable" ) ), + maGradientContainer( rxModelFactory, CREATE_OUSTRING( "com.sun.star.drawing.GradientTable" ) ), + maBitmapContainer( rxModelFactory, CREATE_OUSTRING( "com.sun.star.drawing.BitmapTable" ) ), maDashNameBase( CREATE_OUSTRING( "msLineDash " ) ), maGradientNameBase( CREATE_OUSTRING( "msFillGradient " ) ), maBitmapNameBase( CREATE_OUSTRING( "msFillBitmap " ) ) diff --git a/oox/source/helper/olestorage.cxx b/oox/source/helper/olestorage.cxx deleted file mode 100644 index fe660b27ff2b..000000000000 --- a/oox/source/helper/olestorage.cxx +++ /dev/null @@ -1,180 +0,0 @@ -/************************************************************************* - * - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * Copyright 2000, 2010 Oracle and/or its affiliates. - * - * OpenOffice.org - a multi-platform office productivity suite - * - * This file is part of OpenOffice.org. - * - * OpenOffice.org is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * only, as published by the Free Software Foundation. - * - * OpenOffice.org is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License version 3 for more details - * (a copy is included in the LICENSE file that accompanied this code). - * - * You should have received a copy of the GNU Lesser General Public License - * version 3 along with OpenOffice.org. If not, see - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -#include "oox/helper/olestorage.hxx" -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/container/XNameContainer.hpp> -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/io/XOutputStream.hpp> -#include <com/sun/star/io/XStream.hpp> -#include "oox/helper/helper.hxx" - -using ::rtl::OUString; -using ::com::sun::star::uno::Any; -using ::com::sun::star::uno::Reference; -using ::com::sun::star::uno::Sequence; -using ::com::sun::star::uno::Exception; -using ::com::sun::star::uno::UNO_QUERY; -using ::com::sun::star::uno::UNO_QUERY_THROW; -using ::com::sun::star::container::XNameAccess; -using ::com::sun::star::lang::XMultiServiceFactory; -using ::com::sun::star::beans::PropertyValue; -using ::com::sun::star::embed::XStorage; -using ::com::sun::star::io::XInputStream; -using ::com::sun::star::io::XOutputStream; -using ::com::sun::star::io::XStream; - -namespace oox { - -// ============================================================================ - -OleStorage::OleStorage( - const Reference< XMultiServiceFactory >& rxFactory, - const Reference< XInputStream >& rxInStream, - bool bBaseStreamAccess ) : - StorageBase( rxInStream, bBaseStreamAccess ) -{ - OSL_ENSURE( rxFactory.is(), "OleStorage::OleStorage - missing service factory" ); - // create base storage object - Sequence< Any > aArgs( 2 ); - aArgs[ 0 ] <<= rxInStream; - aArgs[ 1 ] <<= true; // true = do not create a copy of the input stream - mxStorage.set( rxFactory->createInstanceWithArguments( - CREATE_OUSTRING( "com.sun.star.embed.OLESimpleStorage" ), aArgs ), UNO_QUERY ); - mxElements.set( mxStorage, UNO_QUERY ); -} - -OleStorage::OleStorage( - const Reference< XMultiServiceFactory >& rxFactory, - const Reference< XStream >& rxStream, - bool bBaseStreamAccess ) : - StorageBase( rxStream, bBaseStreamAccess ) -{ - OSL_ENSURE( rxFactory.is(), "OleStorage::OleStorage - missing service factory" ); - (void)rxFactory; // prevent compiler warning - OSL_ENSURE( false, "OleStorage::OleStorage - not implemented" ); - mxElements.set( mxStorage, UNO_QUERY ); -} - -OleStorage::OleStorage( const OleStorage& rParentStorage, const Reference< XNameAccess >& rxElementsAccess, const OUString& rElementName ) : - StorageBase( rParentStorage, rElementName ), - mxStorage( rParentStorage.mxStorage ), - mxElements( rxElementsAccess ) -{ - OSL_ENSURE( mxElements.is(), "OleStorage::OleStorage - missing elements access" ); -} - -OleStorage::~OleStorage() -{ -} - -// StorageBase interface ------------------------------------------------------ - -bool OleStorage::implIsStorage() const -{ - if( mxStorage.is() && mxElements.is() ) try - { - /* If this is not a storage, hasElements() throws an exception. But we - do not return the result of hasElements(), because an empty storage - is a valid storage too. */ - mxElements->hasElements(); - return true; - } - catch( Exception& ) - { - } - return false; -} - -Reference< XStorage > OleStorage::implGetXStorage() const -{ - OSL_ENSURE( false, "OleStorage::getXStorage - not implemented" ); - return Reference< XStorage >(); -} - -void OleStorage::implGetElementNames( ::std::vector< OUString >& orElementNames ) const -{ - Sequence< OUString > aNames; - if( mxElements.is() ) try - { - aNames = mxElements->getElementNames(); - if( aNames.getLength() > 0 ) - orElementNames.insert( orElementNames.end(), aNames.getConstArray(), aNames.getConstArray() + aNames.getLength() ); - } - catch( Exception& ) - { - } -} - -StorageRef OleStorage::implOpenSubStorage( const OUString& rElementName, bool bCreate ) -{ - OSL_ENSURE( !bCreate, "OleStorage::implOpenSubStorage - creating substorages not implemented" ); - (void)bCreate; // prevent compiler warning - StorageRef xSubStorage; - if( mxElements.is() ) try - { - Reference< XNameAccess > xSubElements( mxElements->getByName( rElementName ), UNO_QUERY_THROW ); - xSubStorage.reset( new OleStorage( *this, xSubElements, rElementName ) ); - } - catch( Exception& ) - { - } - return xSubStorage; -} - -Reference< XInputStream > OleStorage::implOpenInputStream( const OUString& rElementName ) -{ - Reference< XInputStream > xInStream; - if( mxElements.is() ) try - { - xInStream.set( mxElements->getByName( rElementName ), UNO_QUERY ); - } - catch( Exception& ) - { - } - return xInStream; -} - -Reference< XOutputStream > OleStorage::implOpenOutputStream( const OUString& rElementName ) -{ - Reference< XOutputStream > xOutStream; - if( mxElements.is() && (rElementName.getLength() > 0) ) try - { - (void)rElementName; // prevent compiler warning - OSL_ENSURE( false, "OleStorage::implOpenOutputStream - not implemented" ); - } - catch( Exception& ) - { - } - return xOutStream; -} - -// ============================================================================ - -} // namespace oox - diff --git a/oox/source/helper/propertyset.cxx b/oox/source/helper/propertyset.cxx index 5477224b9461..c52872e50f2f 100644 --- a/oox/source/helper/propertyset.cxx +++ b/oox/source/helper/propertyset.cxx @@ -57,6 +57,12 @@ bool PropertySet::getAnyProperty( Any& orValue, sal_Int32 nPropId ) const return getAnyProperty( orValue, PropertyMap::getPropertyName( nPropId ) ); } +Any PropertySet::getAnyProperty( sal_Int32 nPropId ) const +{ + Any aValue; + return getAnyProperty( aValue, nPropId ) ? aValue : Any(); +} + bool PropertySet::getBoolProperty( sal_Int32 nPropId ) const { Any aAny; @@ -66,18 +72,17 @@ bool PropertySet::getBoolProperty( sal_Int32 nPropId ) const void PropertySet::getProperties( Sequence< Any >& orValues, const Sequence< OUString >& rPropNames ) const { - if( mxMultiPropSet.is() ) // first try the XMultiPropertySet + if( mxMultiPropSet.is() ) try { - try - { - orValues = mxMultiPropSet->getPropertyValues( rPropNames ); - } - catch( Exception& ) - { - OSL_ENSURE( false, "PropertySet::getProperties - cannot get all property values" ); - } + orValues = mxMultiPropSet->getPropertyValues( rPropNames ); + return; } - else if( mxPropSet.is() ) + catch( Exception& ) + { + OSL_ENSURE( false, "PropertySet::getProperties - cannot get all property values - fallback to single mode" ); + } + + if( mxPropSet.is() ) { sal_Int32 nLen = rPropNames.getLength(); const OUString* pPropName = rPropNames.getConstArray(); @@ -101,18 +106,17 @@ void PropertySet::setProperties( const Sequence< OUString >& rPropNames, const S OSL_ENSURE( rPropNames.getLength() == rValues.getLength(), "PropertySet::setProperties - length of sequences different" ); - if( mxMultiPropSet.is() ) // first try the XMultiPropertySet + if( mxMultiPropSet.is() ) try { - try - { - mxMultiPropSet->setPropertyValues( rPropNames, rValues ); - } - catch( Exception& ) - { - OSL_ENSURE( false, "PropertySet::setProperties - cannot set all property values" ); - } + mxMultiPropSet->setPropertyValues( rPropNames, rValues ); + return; } - else if( mxPropSet.is() ) + catch( Exception& ) + { + OSL_ENSURE( false, "PropertySet::setProperties - cannot set all property values, fallback to single mode" ); + } + + if( mxPropSet.is() ) { const OUString* pPropName = rPropNames.getConstArray(); const OUString* pPropNameEnd = pPropName + rPropNames.getLength(); diff --git a/oox/source/helper/storagebase.cxx b/oox/source/helper/storagebase.cxx index 6f174a74593c..4a05f66db81b 100644 --- a/oox/source/helper/storagebase.cxx +++ b/oox/source/helper/storagebase.cxx @@ -29,11 +29,14 @@ #include <com/sun/star/io/XStream.hpp> #include <com/sun/star/embed/XTransactedObject.hpp> #include <rtl/ustrbuf.hxx> +#include "oox/helper/binaryinputstream.hxx" +#include "oox/helper/binaryoutputstream.hxx" using ::rtl::OUString; using ::rtl::OUStringBuffer; +using ::com::sun::star::uno::Exception; using ::com::sun::star::uno::Reference; -using ::com::sun::star::uno::UNO_QUERY; +using ::com::sun::star::uno::UNO_SET_THROW; using ::com::sun::star::embed::XStorage; using ::com::sun::star::embed::XTransactedObject; using ::com::sun::star::io::XInputStream; @@ -66,24 +69,25 @@ void lclSplitFirstElement( OUString& orElement, OUString& orRemainder, const OUS StorageBase::StorageBase( const Reference< XInputStream >& rxInStream, bool bBaseStreamAccess ) : mxInStream( rxInStream ), - mpParentStorage( 0 ), - mbBaseStreamAccess( bBaseStreamAccess ) + mbBaseStreamAccess( bBaseStreamAccess ), + mbReadOnly( true ) { OSL_ENSURE( mxInStream.is(), "StorageBase::StorageBase - missing base input stream" ); } StorageBase::StorageBase( const Reference< XStream >& rxOutStream, bool bBaseStreamAccess ) : mxOutStream( rxOutStream ), - mpParentStorage( 0 ), - mbBaseStreamAccess( bBaseStreamAccess ) + mbBaseStreamAccess( bBaseStreamAccess ), + mbReadOnly( false ) { OSL_ENSURE( mxOutStream.is(), "StorageBase::StorageBase - missing base output stream" ); } -StorageBase::StorageBase( const StorageBase& rParentStorage, const OUString& rStorageName ) : +StorageBase::StorageBase( const StorageBase& rParentStorage, const OUString& rStorageName, bool bReadOnly ) : + maParentPath( rParentStorage.getPath() ), maStorageName( rStorageName ), - mpParentStorage( &rParentStorage ), - mbBaseStreamAccess( false ) + mbBaseStreamAccess( false ), + mbReadOnly( bReadOnly ) { } @@ -96,6 +100,16 @@ bool StorageBase::isStorage() const return implIsStorage(); } +bool StorageBase::isRootStorage() const +{ + return implIsStorage() && (maStorageName.getLength() == 0); +} + +bool StorageBase::isReadOnly() const +{ + return mbReadOnly; +} + Reference< XStorage > StorageBase::getXStorage() const { return implGetXStorage(); @@ -108,9 +122,7 @@ const OUString& StorageBase::getName() const OUString StorageBase::getPath() const { - OUStringBuffer aBuffer; - if( mpParentStorage ) - aBuffer.append( mpParentStorage->getPath() ); + OUStringBuffer aBuffer( maParentPath ); if( aBuffer.getLength() > 0 ) aBuffer.append( sal_Unicode( '/' ) ); aBuffer.append( maStorageName ); @@ -123,15 +135,19 @@ void StorageBase::getElementNames( ::std::vector< OUString >& orElementNames ) c implGetElementNames( orElementNames ); } -StorageRef StorageBase::openSubStorage( const OUString& rStorageName, bool bCreate ) +StorageRef StorageBase::openSubStorage( const OUString& rStorageName, bool bCreateMissing ) { StorageRef xSubStorage; - OUString aElement, aRemainder; - lclSplitFirstElement( aElement, aRemainder, rStorageName ); - if( aElement.getLength() > 0 ) - xSubStorage = getSubStorage( aElement, bCreate ); - if( xSubStorage.get() && (aRemainder.getLength() > 0) ) - xSubStorage = xSubStorage->openSubStorage( aRemainder, bCreate ); + OSL_ENSURE( !bCreateMissing || !mbReadOnly, "StorageBase::openSubStorage - cannot create substorage in read-only mode" ); + if( !bCreateMissing || !mbReadOnly ) + { + OUString aElement, aRemainder; + lclSplitFirstElement( aElement, aRemainder, rStorageName ); + if( aElement.getLength() > 0 ) + xSubStorage = getSubStorage( aElement, bCreateMissing ); + if( xSubStorage.get() && (aRemainder.getLength() > 0) ) + xSubStorage = xSubStorage->openSubStorage( aRemainder, bCreateMissing ); + } return xSubStorage; } @@ -163,47 +179,96 @@ Reference< XInputStream > StorageBase::openInputStream( const OUString& rStreamN Reference< XOutputStream > StorageBase::openOutputStream( const OUString& rStreamName ) { Reference< XOutputStream > xOutStream; - OUString aElement, aRemainder; - lclSplitFirstElement( aElement, aRemainder, rStreamName ); - if( aElement.getLength() > 0 ) + OSL_ENSURE( !mbReadOnly, "StorageBase::openOutputStream - cannot create output stream in read-only mode" ); + if( !mbReadOnly ) { - if( aRemainder.getLength() > 0 ) + OUString aElement, aRemainder; + lclSplitFirstElement( aElement, aRemainder, rStreamName ); + if( aElement.getLength() > 0 ) { - StorageRef xSubStorage = getSubStorage( aElement, true ); - if( xSubStorage.get() ) - xOutStream = xSubStorage->openOutputStream( aRemainder ); + if( aRemainder.getLength() > 0 ) + { + StorageRef xSubStorage = getSubStorage( aElement, true ); + if( xSubStorage.get() ) + xOutStream = xSubStorage->openOutputStream( aRemainder ); + } + else + { + xOutStream = implOpenOutputStream( aElement ); + } } - else + else if( mbBaseStreamAccess ) { - xOutStream = implOpenOutputStream( aElement ); + xOutStream = mxOutStream->getOutputStream(); } } - else if( mbBaseStreamAccess ) + return xOutStream; +} + +void StorageBase::copyToStorage( StorageBase& rDestStrg, const OUString& rElementName ) +{ + OSL_ENSURE( rDestStrg.isStorage() && !rDestStrg.isReadOnly(), "StorageBase::copyToStorage - invalid destination" ); + OSL_ENSURE( rElementName.getLength() > 0, "StorageBase::copyToStorage - invalid element name" ); + if( rDestStrg.isStorage() && !rDestStrg.isReadOnly() && (rElementName.getLength() > 0) ) { - xOutStream = mxOutStream->getOutputStream(); + StorageRef xSubStrg = openSubStorage( rElementName, false ); + if( xSubStrg.get() ) + { + StorageRef xDestSubStrg = rDestStrg.openSubStorage( rElementName, true ); + if( xDestSubStrg.get() ) + xSubStrg->copyStorageToStorage( *xDestSubStrg ); + } + else + { + Reference< XInputStream > xInStrm = openInputStream( rElementName ); + if( xInStrm.is() ) + { + Reference< XOutputStream > xOutStrm = rDestStrg.openOutputStream( rElementName ); + if( xOutStrm.is() ) + { + BinaryXInputStream aInStrm( xInStrm, true ); + BinaryXOutputStream aOutStrm( xOutStrm, true ); + aInStrm.copyToStream( aOutStrm ); + } + } + } } - return xOutStream; } -StorageRef StorageBase::getSubStorage( const OUString& rElementName, bool bCreate ) +void StorageBase::copyStorageToStorage( StorageBase& rDestStrg ) { - SubStorageMap::iterator aIt = maSubStorages.find( rElementName ); - return (aIt == maSubStorages.end()) ? - (maSubStorages[ rElementName ] = implOpenSubStorage( rElementName, bCreate )) : aIt->second; + OSL_ENSURE( rDestStrg.isStorage() && !rDestStrg.isReadOnly(), "StorageBase::copyToStorage - invalid destination" ); + if( rDestStrg.isStorage() && !rDestStrg.isReadOnly() ) + { + ::std::vector< OUString > aElements; + getElementNames( aElements ); + for( ::std::vector< OUString >::iterator aIt = aElements.begin(), aEnd = aElements.end(); aIt != aEnd; ++aIt ) + copyToStorage( rDestStrg, *aIt ); + } } void StorageBase::commit() { - for( SubStorageMap::iterator aIt = maSubStorages.begin(); aIt != maSubStorages.end(); aIt ++ ) - aIt->second->commit(); + OSL_ENSURE( !mbReadOnly, "StorageBase::commit - cannot commit in read-only mode" ); + if( !mbReadOnly ) + { + // commit all open substorages + maSubStorages.forEachMem( &StorageBase::commit ); + // commit this storage + implCommit(); + } +} - Reference< XTransactedObject > xTransactedObj( getXStorage(), UNO_QUERY ); +// private -------------------------------------------------------------------- - if( xTransactedObj.is() ) - xTransactedObj->commit(); +StorageRef StorageBase::getSubStorage( const OUString& rElementName, bool bCreateMissing ) +{ + StorageRef& rxSubStrg = maSubStorages[ rElementName ]; + if( !rxSubStrg ) + rxSubStrg = implOpenSubStorage( rElementName, bCreateMissing ); + return rxSubStrg; } // ============================================================================ } // namespace oox - diff --git a/oox/source/helper/textinputstream.cxx b/oox/source/helper/textinputstream.cxx new file mode 100755 index 000000000000..d6d4736f3ca2 --- /dev/null +++ b/oox/source/helper/textinputstream.cxx @@ -0,0 +1,128 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "oox/helper/textinputstream.hxx" +#include <rtl/strbuf.hxx> +#include <rtl/ustrbuf.hxx> +#include "oox/helper/binaryinputstream.hxx" + +using ::rtl::OStringBuffer; +using ::rtl::OStringToOUString; +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +namespace oox { + +// ============================================================================ + +namespace { + +/** Reads a text line from stream. First, tries to skip the second character of + a two-character line end sequence. Returns the new line-end character. */ +template< typename BufferType, typename CharType, typename StreamDataType > +sal_Unicode lclReadLine( BufferType& orBuffer, BinaryInputStream& rInStrm, sal_Unicode cLastEolChar ) +{ + // try to skip LF following CR, or CR following LF + if( !rInStrm.isEof() && (cLastEolChar != 0) ) + { + CharType cChar = static_cast< CharType >( rInStrm.readValue< StreamDataType >() ); + // return on EOF after line-end + if( rInStrm.isEof() ) + return 0; + // return on sequence of equal line-end characters + bool bIsEolChar = (cChar == 10) || (cChar == 13); + if( bIsEolChar && (cChar == cLastEolChar) ) + return cChar; + // append the character, if it is not the other line-end charcter + if( !bIsEolChar ) + orBuffer.append( cChar ); + } + + // read chars until EOF or line end character (LF or CR) + while( true ) + { + CharType cChar = static_cast< CharType >( rInStrm.readValue< StreamDataType >() ); + if( rInStrm.isEof() ) + return 0; + if( (cChar == 10) || (cChar == 13) ) + return cChar; + orBuffer.append( cChar ); + } +} + +} // namespace + +// ============================================================================ + +TextInputStream::TextInputStream( BinaryInputStream& rInStrm, rtl_TextEncoding eTextEnc ) : + mrInStrm( rInStrm ), + meTextEnc( eTextEnc ), + mcLastEolChar( 0 ) +{ +} + +bool TextInputStream::isEof() const +{ + // do not return EOF, if last text line missed line-end character (see below) + return mrInStrm.isEof() && (mcLastEolChar == 0); +} + +OUString TextInputStream::readLine() +{ + if( mrInStrm.isEof() ) + { + mcLastEolChar = 0; + return OUString(); + } + + OUString aLine; + if( meTextEnc == RTL_TEXTENCODING_UCS2 ) + { + // read 16-bit characters for UCS2 encoding + OUStringBuffer aBuffer; + mcLastEolChar = lclReadLine< OUStringBuffer, sal_Unicode, sal_uInt16 >( aBuffer, mrInStrm, mcLastEolChar ); + aLine = aBuffer.makeStringAndClear(); + } + else + { + // otherwise, read 8-bit characters and convert according to text encoding + OStringBuffer aBuffer; + mcLastEolChar = lclReadLine< OStringBuffer, sal_Char, sal_uInt8 >( aBuffer, mrInStrm, mcLastEolChar ); + aLine = OStringToOUString( aBuffer.makeStringAndClear(), meTextEnc ); + } + + // if last line is not empty but line-end character is missing, do not return EOF + if( mrInStrm.isEof() && (aLine.getLength() > 0) ) + mcLastEolChar = 10; + + return aLine; +} + +// ============================================================================ + +} // namespace oox + diff --git a/oox/source/helper/zipstorage.cxx b/oox/source/helper/zipstorage.cxx index c90b2071b133..72b6fcd1bff0 100644 --- a/oox/source/helper/zipstorage.cxx +++ b/oox/source/helper/zipstorage.cxx @@ -26,26 +26,29 @@ ************************************************************************/ #include "oox/helper/zipstorage.hxx" -#include <com/sun/star/container/XHierarchicalNameAccess.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <com/sun/star/embed/XStorage.hpp> #include <com/sun/star/embed/ElementModes.hpp> +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/embed/XTransactedObject.hpp> #include <com/sun/star/io/XInputStream.hpp> #include <com/sun/star/io/XOutputStream.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <comphelper/storagehelper.hxx> #include "oox/helper/helper.hxx" using ::rtl::OUString; -using ::com::sun::star::uno::Any; -using ::com::sun::star::uno::Reference; -using ::com::sun::star::uno::Sequence; -using ::com::sun::star::uno::Exception; -using ::com::sun::star::uno::UNO_QUERY; -using ::com::sun::star::lang::XMultiServiceFactory; +using ::com::sun::star::container::NoSuchElementException; using ::com::sun::star::embed::XStorage; +using ::com::sun::star::embed::XTransactedObject; using ::com::sun::star::io::XInputStream; using ::com::sun::star::io::XOutputStream; using ::com::sun::star::io::XStream; +using ::com::sun::star::lang::XMultiServiceFactory; +using ::com::sun::star::uno::Any; +using ::com::sun::star::uno::Exception; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::UNO_QUERY; +using ::com::sun::star::uno::UNO_QUERY_THROW; namespace oox { @@ -93,7 +96,7 @@ ZipStorage::ZipStorage( } ZipStorage::ZipStorage( const ZipStorage& rParentStorage, const Reference< XStorage >& rxStorage, const OUString& rElementName ) : - StorageBase( rParentStorage, rElementName ), + StorageBase( rParentStorage, rElementName, rParentStorage.isReadOnly() ), mxStorage( rxStorage ) { OSL_ENSURE( mxStorage.is(), "ZipStorage::ZipStorage - missing storage" ); @@ -127,7 +130,7 @@ void ZipStorage::implGetElementNames( ::std::vector< OUString >& orElementNames } } -StorageRef ZipStorage::implOpenSubStorage( const OUString& rElementName, bool bCreate ) +StorageRef ZipStorage::implOpenSubStorage( const OUString& rElementName, bool bCreateMissing ) { Reference< XStorage > xSubXStorage; bool bMissing = false; @@ -138,7 +141,7 @@ StorageRef ZipStorage::implOpenSubStorage( const OUString& rElementName, bool bC xSubXStorage = mxStorage->openStorageElement( rElementName, ::com::sun::star::embed::ElementModes::READ ); } - catch( ::com::sun::star::container::NoSuchElementException& ) + catch( NoSuchElementException& ) { bMissing = true; } @@ -146,15 +149,14 @@ StorageRef ZipStorage::implOpenSubStorage( const OUString& rElementName, bool bC { } - if( bMissing && bCreate ) - try - { - xSubXStorage = mxStorage->openStorageElement( - rElementName, ::com::sun::star::embed::ElementModes::READWRITE ); - } - catch( Exception& ) - { - } + if( bMissing && bCreateMissing ) try + { + xSubXStorage = mxStorage->openStorageElement( + rElementName, ::com::sun::star::embed::ElementModes::READWRITE ); + } + catch( Exception& ) + { + } StorageRef xSubStorage; if( xSubXStorage.is() ) @@ -188,7 +190,17 @@ Reference< XOutputStream > ZipStorage::implOpenOutputStream( const OUString& rEl return xOutStream; } +void ZipStorage::implCommit() const +{ + try + { + Reference< XTransactedObject >( mxStorage, UNO_QUERY_THROW )->commit(); + } + catch( Exception& ) + { + } +} + // ============================================================================ } // namespace oox - |