summaryrefslogtreecommitdiff
path: root/oox/source/helper
diff options
context:
space:
mode:
authorRüdiger Timm <rt@openoffice.org>2008-01-17 07:06:10 +0000
committerRüdiger Timm <rt@openoffice.org>2008-01-17 07:06:10 +0000
commit3381981e76873304b171f7df900561dac681d2af (patch)
treef496d5a2006e8719b5783d5a8966a05858ed3014 /oox/source/helper
parent90e7bde2a1f3dd8c81e947578f14f40059961740 (diff)
#i10000# Bring module to HEAD.
Diffstat (limited to 'oox/source/helper')
-rw-r--r--oox/source/helper/attributelist.cxx111
-rw-r--r--oox/source/helper/binaryinputstream.cxx113
-rw-r--r--oox/source/helper/binaryoutputstream.cxx121
-rw-r--r--oox/source/helper/binarystreambase.cxx91
-rw-r--r--oox/source/helper/containerhelper.cxx173
-rw-r--r--oox/source/helper/makefile.mk68
-rw-r--r--oox/source/helper/olestorage.cxx186
-rw-r--r--oox/source/helper/progressbar.cxx193
-rw-r--r--oox/source/helper/propertymap.cxx286
-rw-r--r--oox/source/helper/propertysequence.cxx164
-rw-r--r--oox/source/helper/propertyset.cxx157
-rw-r--r--oox/source/helper/recordinputstream.cxx104
-rw-r--r--oox/source/helper/storagebase.cxx201
-rw-r--r--oox/source/helper/zipstorage.cxx174
14 files changed, 2142 insertions, 0 deletions
diff --git a/oox/source/helper/attributelist.cxx b/oox/source/helper/attributelist.cxx
new file mode 100644
index 000000000000..499e27e0751e
--- /dev/null
+++ b/oox/source/helper/attributelist.cxx
@@ -0,0 +1,111 @@
+/*************************************************************************
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: attributelist.cxx,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Author: rt $ $Date: 2008-01-17 08:05:59 $
+ *
+ * The Contents of this file are made available subject to
+ * the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2005 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ ************************************************************************/
+
+#include "oox/helper/attributelist.hxx"
+#include <osl/diagnose.h>
+
+using ::rtl::OUString;
+using ::com::sun::star::uno::Reference;
+using ::com::sun::star::xml::sax::XFastAttributeList;
+
+namespace oox {
+
+// ============================================================================
+
+AttributeList::AttributeList( const Reference< XFastAttributeList >& rxAttribs ) :
+ mxAttribs( rxAttribs )
+{
+ OSL_ENSURE( mxAttribs.is(), "AttributeList::AttributeList - missing attribute list interface" );
+}
+
+bool AttributeList::hasAttribute( sal_Int32 nElement ) const
+{
+ return mxAttribs->hasAttribute( nElement );
+}
+
+sal_Int32 AttributeList::getToken( sal_Int32 nElement, sal_Int32 nDefault ) const
+{
+ return mxAttribs->getOptionalValueToken( nElement, nDefault );
+}
+
+OUString AttributeList::getString( sal_Int32 nElement ) const
+{
+ return mxAttribs->getOptionalValue( nElement );
+}
+
+double AttributeList::getDouble( sal_Int32 nElement, double fDefault ) const
+{
+ OUString aValue = getString( nElement );
+ return (aValue.getLength() == 0) ? fDefault : aValue.toDouble();
+}
+
+sal_Int32 AttributeList::getInteger( sal_Int32 nElement, sal_Int32 nDefault ) const
+{
+ OUString aValue = getString( nElement );
+ return (aValue.getLength() == 0) ? nDefault : aValue.toInt32();
+}
+
+sal_uInt32 AttributeList::getUnsignedInteger( sal_Int32 nElement, sal_uInt32 nDefault ) const
+{
+ OUString aValue = getString( nElement );
+ if( aValue.getLength() == 0 )
+ return nDefault;
+ sal_Int64 nValue = aValue.toInt64();
+ return static_cast< sal_uInt32 >( ((nValue < 0) || (nValue > SAL_MAX_UINT32)) ? 0 : nValue );
+}
+
+sal_Int32 AttributeList::getHex( sal_Int32 nElement, sal_Int32 nDefault ) const
+{
+ OUString aValue = getString( nElement );
+ return (aValue.getLength() == 0) ? nDefault : aValue.toInt32( 16 );
+}
+
+bool AttributeList::getBool( sal_Int32 nElement, bool bDefault ) const
+{
+ // boolean attributes may be "true", "false", "on", "off", "1", or "0"
+ switch( getToken( nElement ) )
+ {
+ case XML_true: return true;
+ case XML_on: return true;
+ case XML_false: return false;
+ case XML_off: return false;
+ }
+ return getInteger( nElement, bDefault ? 1 : 0 ) != 0;
+}
+
+// ============================================================================
+
+} // namespace oox
+
diff --git a/oox/source/helper/binaryinputstream.cxx b/oox/source/helper/binaryinputstream.cxx
new file mode 100644
index 000000000000..d8eaae3ac163
--- /dev/null
+++ b/oox/source/helper/binaryinputstream.cxx
@@ -0,0 +1,113 @@
+/*************************************************************************
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: binaryinputstream.cxx,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Author: rt $ $Date: 2008-01-17 08:05:59 $
+ *
+ * The Contents of this file are made available subject to
+ * the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2005 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ ************************************************************************/
+
+#include "oox/helper/binaryinputstream.hxx"
+#include <com/sun/star/io/XInputStream.hpp>
+#include <osl/diagnose.h>
+
+using ::com::sun::star::uno::Reference;
+using ::com::sun::star::uno::Sequence;
+using ::com::sun::star::uno::Exception;
+using ::com::sun::star::io::XInputStream;
+
+namespace oox {
+
+// ============================================================================
+
+BinaryInputStream::BinaryInputStream( const Reference< XInputStream >& rxInStrm, bool bAutoClose ) :
+ BinaryStreamBase( rxInStrm ),
+ mxInStrm( rxInStrm ),
+ mbAutoClose( bAutoClose )
+{
+}
+
+BinaryInputStream::~BinaryInputStream()
+{
+ if( mbAutoClose )
+ close();
+}
+
+void BinaryInputStream::skip( sal_Int32 nBytes )
+{
+ try
+ {
+ OSL_ENSURE( mxInStrm.is(), "BinaryInputStream::skip - invalid call" );
+ mxInStrm->skipBytes( nBytes );
+ }
+ catch( Exception& )
+ {
+ OSL_ENSURE( false, "BinaryInputStream::skip - exception caught" );
+ }
+}
+
+sal_Int32 BinaryInputStream::read( Sequence< sal_Int8 >& orBuffer, sal_Int32 nBytes )
+{
+ sal_Int32 nRet = 0;
+ try
+ {
+ OSL_ENSURE( mxInStrm.is(), "BinaryInputStream::read - invalid call" );
+ nRet = mxInStrm->readBytes( orBuffer, nBytes );
+ }
+ catch( Exception& )
+ {
+ OSL_ENSURE( false, "BinaryInputStream::read - stream read error" );
+ }
+ return nRet;
+}
+
+sal_Int32 BinaryInputStream::read( void* opBuffer, sal_Int32 nBytes )
+{
+ sal_Int32 nRet = read( maBuffer, nBytes );
+ if( nRet > 0 )
+ memcpy( opBuffer, maBuffer.getConstArray(), static_cast< size_t >( nRet ) );
+ return nRet;
+}
+
+void BinaryInputStream::close()
+{
+ if( mxInStrm.is() ) try
+ {
+ mxInStrm->closeInput();
+ }
+ catch( Exception& )
+ {
+ OSL_ENSURE( false, "BinaryInputStream::close - closing input stream failed" );
+ }
+}
+
+// ============================================================================
+
+} // namespace oox
+
diff --git a/oox/source/helper/binaryoutputstream.cxx b/oox/source/helper/binaryoutputstream.cxx
new file mode 100644
index 000000000000..c6e4bb2c9ad5
--- /dev/null
+++ b/oox/source/helper/binaryoutputstream.cxx
@@ -0,0 +1,121 @@
+/*************************************************************************
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: binaryoutputstream.cxx,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Author: rt $ $Date: 2008-01-17 08:05:59 $
+ *
+ * The Contents of this file are made available subject to
+ * the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2005 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ ************************************************************************/
+
+#include "oox/helper/binaryoutputstream.hxx"
+#include <osl/diagnose.h>
+#include <com/sun/star/io/XOutputStream.hpp>
+#include "oox/helper/binaryinputstream.hxx"
+
+using ::com::sun::star::uno::Reference;
+using ::com::sun::star::uno::Sequence;
+using ::com::sun::star::uno::Exception;
+using ::com::sun::star::io::XOutputStream;
+
+namespace oox {
+
+// ============================================================================
+
+BinaryOutputStream::BinaryOutputStream( const Reference< XOutputStream >& rxOutStrm, bool bAutoClose ) :
+ BinaryStreamBase( rxOutStrm ),
+ mxOutStrm( rxOutStrm ),
+ mbAutoClose( bAutoClose )
+{
+}
+
+BinaryOutputStream::~BinaryOutputStream()
+{
+ if( mbAutoClose )
+ close();
+}
+
+void BinaryOutputStream::write( const Sequence< sal_Int8 >& rBuffer )
+{
+ try
+ {
+ OSL_ENSURE( mxOutStrm.is(), "BinaryOutputStream::write - invalid call" );
+ mxOutStrm->writeBytes( rBuffer );
+ }
+ catch( Exception& )
+ {
+ OSL_ENSURE( false, "BinaryOutputStream::write - stream read error" );
+ }
+}
+
+void BinaryOutputStream::write( const void* pBuffer, sal_Int32 nBytes )
+{
+ if( nBytes > 0 )
+ {
+ maBuffer.realloc( nBytes );
+ memcpy( maBuffer.getArray(), pBuffer, static_cast< size_t >( nBytes ) );
+ write( maBuffer );
+ }
+}
+
+void BinaryOutputStream::copy( BinaryInputStream& rInStrm, sal_Int64 nBytes )
+{
+ if( rInStrm.is() && (nBytes > 0) )
+ {
+ sal_Int32 nBufferSize = getLimitedValue< sal_Int32, sal_Int64 >( nBytes, 0, 0x8000 );
+ Sequence< sal_Int8 > aBuffer( nBufferSize );
+ while( nBytes > 0 )
+ {
+ sal_Int32 nReadSize = getLimitedValue< sal_Int32, sal_Int64 >( nBytes, 0, nBufferSize );
+ sal_Int32 nBytesRead = rInStrm.read( aBuffer, nReadSize );
+ write( aBuffer );
+ if( nReadSize == nBytesRead )
+ nBytes -= nReadSize;
+ else
+ nBytes = 0;
+ }
+ }
+}
+
+void BinaryOutputStream::close()
+{
+ if( mxOutStrm.is() ) try
+ {
+ mxOutStrm->flush();
+ mxOutStrm->closeOutput();
+ }
+ catch( Exception& )
+ {
+ OSL_ENSURE( false, "BinaryOutputStream::close - closing output stream failed" );
+ }
+}
+
+// ============================================================================
+
+} // namespace oox
+
diff --git a/oox/source/helper/binarystreambase.cxx b/oox/source/helper/binarystreambase.cxx
new file mode 100644
index 000000000000..4eb0bf45f645
--- /dev/null
+++ b/oox/source/helper/binarystreambase.cxx
@@ -0,0 +1,91 @@
+/*************************************************************************
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: binarystreambase.cxx,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Author: rt $ $Date: 2008-01-17 08:05:59 $
+ *
+ * The Contents of this file are made available subject to
+ * the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2005 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ ************************************************************************/
+
+#include "oox/helper/binarystreambase.hxx"
+#include <osl/diagnose.h>
+
+using ::com::sun::star::uno::Exception;
+
+namespace oox {
+
+// ============================================================================
+
+BinaryStreamBase::~BinaryStreamBase()
+{
+}
+
+sal_Int64 BinaryStreamBase::getLength() const
+{
+ try
+ {
+ return mxSeekable.is() ? mxSeekable->getLength() : -1;
+ }
+ catch( Exception& )
+ {
+ OSL_ENSURE( false, "BinaryStreamBase::getLength - exception caught" );
+ }
+ return -1;
+}
+
+sal_Int64 BinaryStreamBase::tell() const
+{
+ try
+ {
+ return mxSeekable.is() ? mxSeekable->getPosition() : -1;
+ }
+ catch( Exception& )
+ {
+ OSL_ENSURE( false, "BinaryStreamBase::tell - exception caught" );
+ }
+ return -1;
+}
+
+void BinaryStreamBase::seek( sal_Int64 nPos )
+{
+ try
+ {
+ if( mxSeekable.is() )
+ mxSeekable->seek( nPos );
+ }
+ catch( Exception& )
+ {
+ OSL_ENSURE( false, "BinaryStreamBase::seek - exception caught" );
+ }
+}
+
+// ============================================================================
+
+} // namespace oox
+
diff --git a/oox/source/helper/containerhelper.cxx b/oox/source/helper/containerhelper.cxx
new file mode 100644
index 000000000000..bb45b86ea561
--- /dev/null
+++ b/oox/source/helper/containerhelper.cxx
@@ -0,0 +1,173 @@
+/*************************************************************************
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: containerhelper.cxx,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Author: rt $ $Date: 2008-01-17 08:05:59 $
+ *
+ * The Contents of this file are made available subject to
+ * the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2005 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ ************************************************************************/
+
+#include "oox/helper/containerhelper.hxx"
+#include <rtl/ustrbuf.hxx>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/container/XIndexContainer.hpp>
+#include <com/sun/star/container/XNameContainer.hpp>
+#include <comphelper/processfactory.hxx>
+#include "oox/helper/helper.hxx"
+
+using ::rtl::OUString;
+using ::rtl::OUStringBuffer;
+using ::com::sun::star::uno::Any;
+using ::com::sun::star::uno::Reference;
+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::lang::XMultiServiceFactory;
+using ::com::sun::star::container::XIndexContainer;
+using ::com::sun::star::container::XNameAccess;
+using ::com::sun::star::container::XNameContainer;
+
+namespace oox {
+
+// ============================================================================
+
+Reference< XIndexContainer > ContainerHelper::createIndexContainer()
+{
+ Reference< XIndexContainer > xContainer;
+ try
+ {
+ Reference< XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
+ xContainer.set( xFactory->createInstance( CREATE_OUSTRING( "com.sun.star.document.IndexedPropertyValues" ) ), UNO_QUERY_THROW );
+ }
+ catch( Exception& )
+ {
+ }
+ OSL_ENSURE( xContainer.is(), "ContainerHelper::createIndexContainer - cannot create container" );
+ return xContainer;
+}
+
+bool ContainerHelper::insertByIndex(
+ const Reference< XIndexContainer >& rxIndexContainer,
+ sal_Int32 nIndex, const Any& rObject )
+{
+ OSL_ENSURE( rxIndexContainer.is(), "ContainerHelper::insertByIndex - missing XIndexContainer interface" );
+ bool bRet = false;
+ try
+ {
+ rxIndexContainer->insertByIndex( nIndex, rObject );
+ bRet = true;
+ }
+ catch( Exception& )
+ {
+ }
+ OSL_ENSURE( bRet, "ContainerHelper::insertByIndex - cannot insert object" );
+ return bRet;
+}
+
+Reference< XNameContainer > ContainerHelper::createNameContainer()
+{
+ Reference< XNameContainer > xContainer;
+ try
+ {
+ Reference< XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory();
+ xContainer.set( xFactory->createInstance( CREATE_OUSTRING( "com.sun.star.document.NamedPropertyValues" ) ), UNO_QUERY_THROW );
+ }
+ catch( Exception& )
+ {
+ }
+ OSL_ENSURE( xContainer.is(), "ContainerHelper::createNameContainer - cannot create container" );
+ return xContainer;
+}
+
+OUString ContainerHelper::getUnusedName(
+ const Reference< XNameAccess >& rxNameAccess, const OUString& rSuggestedName,
+ sal_Unicode cSeparator, sal_Int32 nFirstIndexToAppend )
+{
+ OSL_ENSURE( rxNameAccess.is(), "ContainerHelper::getUnusedName - missing XNameAccess interface" );
+
+ OUString aNewName = rSuggestedName;
+ sal_Int32 nIndex = nFirstIndexToAppend;
+ while( rxNameAccess->hasByName( aNewName ) )
+ aNewName = OUStringBuffer( rSuggestedName ).append( cSeparator ).append( nIndex++ ).makeStringAndClear();
+ return aNewName;
+}
+
+bool ContainerHelper::insertByName(
+ const Reference< XNameContainer >& rxNameContainer,
+ const OUString& rName, const Any& rObject )
+{
+ OSL_ENSURE( rxNameContainer.is(), "ContainerHelper::insertByName - missing XNameContainer interface" );
+ bool bRet = false;
+ try
+ {
+ rxNameContainer->insertByName( rName, rObject );
+ bRet = true;
+ }
+ catch( Exception& )
+ {
+ }
+ OSL_ENSURE( bRet, "ContainerHelper::insertByName - cannot insert object" );
+ return bRet;
+}
+
+OUString ContainerHelper::insertByUnusedName(
+ const Reference< XNameContainer >& rxNameContainer, const Any& rObject,
+ const OUString& rSuggestedName, sal_Unicode cSeparator, bool bRenameOldExisting )
+{
+ OSL_ENSURE( rxNameContainer.is(), "ContainerHelper::insertByUnusedName - missing XNameContainer interface" );
+
+ // find an unused name
+ Reference< XNameAccess > xNameAccess( rxNameContainer, UNO_QUERY );
+ OUString aNewName = getUnusedName( xNameAccess, rSuggestedName, cSeparator );
+
+ // rename existing object
+ if( bRenameOldExisting && rxNameContainer->hasByName( rSuggestedName ) )
+ {
+ try
+ {
+ Any aOldObject = rxNameContainer->getByName( rSuggestedName );
+ rxNameContainer->removeByName( rSuggestedName );
+ rxNameContainer->insertByName( aNewName, aOldObject );
+ aNewName = rSuggestedName;
+ }
+ catch( Exception& )
+ {
+ OSL_ENSURE( false, "ContainerHelper::insertByUnusedName - cannot rename old object" );
+ }
+ }
+
+ // insert the new object and return its resulting name
+ insertByName( rxNameContainer, aNewName, rObject );
+ return aNewName;
+}
+
+// ============================================================================
+
+} // namespace oox
+
diff --git a/oox/source/helper/makefile.mk b/oox/source/helper/makefile.mk
new file mode 100644
index 000000000000..d35a5ca1ef45
--- /dev/null
+++ b/oox/source/helper/makefile.mk
@@ -0,0 +1,68 @@
+#*************************************************************************
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# $RCSfile: makefile.mk,v $
+#
+# $Revision: 1.2 $
+#
+# last change: $Author: rt $ $Date: 2008-01-17 08:05:59 $
+#
+# The Contents of this file are made available subject to
+# the terms of GNU Lesser General Public License Version 2.1.
+#
+#
+# GNU Lesser General Public License Version 2.1
+# =============================================
+# Copyright 2005 by Sun Microsystems, Inc.
+# 901 San Antonio Road, Palo Alto, CA 94303, USA
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library 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 for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+#
+#*************************************************************************
+
+PRJ=..$/..
+
+PRJNAME=oox
+TARGET=helper
+AUTOSEG=true
+
+ENABLE_EXCEPTIONS=TRUE
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : settings.mk
+.INCLUDE: $(PRJ)$/util$/makefile.pmk
+
+# --- Files --------------------------------------------------------
+
+SLOFILES = \
+ $(SLO)$/attributelist.obj \
+ $(SLO)$/binaryinputstream.obj \
+ $(SLO)$/binaryoutputstream.obj \
+ $(SLO)$/binarystreambase.obj \
+ $(SLO)$/containerhelper.obj \
+ $(SLO)$/olestorage.obj \
+ $(SLO)$/progressbar.obj \
+ $(SLO)$/propertymap.obj \
+ $(SLO)$/propertysequence.obj \
+ $(SLO)$/propertyset.obj \
+ $(SLO)$/recordinputstream.obj \
+ $(SLO)$/storagebase.obj \
+ $(SLO)$/zipstorage.obj
+
+# --- Targets -------------------------------------------------------
+
+.INCLUDE : target.mk
diff --git a/oox/source/helper/olestorage.cxx b/oox/source/helper/olestorage.cxx
new file mode 100644
index 000000000000..f68a9647697c
--- /dev/null
+++ b/oox/source/helper/olestorage.cxx
@@ -0,0 +1,186 @@
+/*************************************************************************
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: olestorage.cxx,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Author: rt $ $Date: 2008-01-17 08:05:59 $
+ *
+ * The Contents of this file are made available subject to
+ * the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2005 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ ************************************************************************/
+
+#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 "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;
+
+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< XOutputStream >& rxOutStream,
+ bool bBaseStreamAccess ) :
+ StorageBase( rxOutStream, 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( mxStorage.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/progressbar.cxx b/oox/source/helper/progressbar.cxx
new file mode 100644
index 000000000000..b811eca2b3e9
--- /dev/null
+++ b/oox/source/helper/progressbar.cxx
@@ -0,0 +1,193 @@
+/*************************************************************************
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: progressbar.cxx,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Author: rt $ $Date: 2008-01-17 08:05:59 $
+ *
+ * The Contents of this file are made available subject to
+ * the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2005 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ ************************************************************************/
+
+#include "oox/helper/progressbar.hxx"
+#include <com/sun/star/task/XStatusIndicator.hpp>
+#include "oox/helper/helper.hxx"
+
+using ::rtl::OUString;
+using ::com::sun::star::uno::Reference;
+using ::com::sun::star::task::XStatusIndicator;
+
+namespace oox {
+
+// ============================================================================
+
+namespace {
+
+const sal_Int32 PROGRESS_RANGE = 1000000;
+
+} // namespace
+
+// ============================================================================
+
+IProgressBar::~IProgressBar()
+{
+}
+
+// ----------------------------------------------------------------------------
+
+ISegmentProgressBar::~ISegmentProgressBar()
+{
+}
+
+// ============================================================================
+// ============================================================================
+
+ProgressBar::ProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) :
+ mxIndicator( rxIndicator ),
+ mfPosition( 0 )
+{
+ if( mxIndicator.is() )
+ mxIndicator->start( rText, PROGRESS_RANGE );
+}
+
+ProgressBar::~ProgressBar()
+{
+ if( mxIndicator.is() )
+ mxIndicator->end();
+}
+
+double ProgressBar::getPosition() const
+{
+ return mfPosition;
+}
+
+void ProgressBar::setPosition( double fPosition )
+{
+ OSL_ENSURE( (mfPosition <= fPosition) && (fPosition <= 1.0), "ProgressBar::setPosition - invalid position" );
+ mfPosition = getLimitedValue< double >( fPosition, mfPosition, 1.0 );
+ if( mxIndicator.is() )
+ mxIndicator->setValue( static_cast< sal_Int32 >( mfPosition * PROGRESS_RANGE ) );
+}
+
+// ============================================================================
+
+namespace prv {
+
+class SubSegment : public ISegmentProgressBar
+{
+public:
+ explicit SubSegment( IProgressBar& rParentProgress, double fStartPos, double fLength );
+
+ virtual double getPosition() const;
+ virtual void setPosition( double fPosition );
+
+ virtual double getFreeLength() const;
+ virtual ISegmentProgressBarRef createSegment( double fLength );
+
+private:
+ IProgressBar& mrParentProgress;
+ double mfStartPos;
+ double mfLength;
+ double mfPosition;
+ double mfFreeStart;
+};
+
+// ----------------------------------------------------------------------------
+
+SubSegment::SubSegment( IProgressBar& rParentProgress, double fStartPos, double fLength ) :
+ mrParentProgress( rParentProgress ),
+ mfStartPos( fStartPos ),
+ mfLength( fLength ),
+ mfPosition( 0.0 ),
+ mfFreeStart( 0.0 )
+{
+}
+
+double SubSegment::getPosition() const
+{
+ return mfPosition;
+}
+
+void SubSegment::setPosition( double fPosition )
+{
+ OSL_ENSURE( (mfPosition <= fPosition) && (fPosition <= 1.0), "SubSegment::setPosition - invalid position" );
+ mfPosition = getLimitedValue< double >( fPosition, mfPosition, 1.0 );
+ mrParentProgress.setPosition( mfStartPos + mfPosition * mfLength );
+}
+
+double SubSegment::getFreeLength() const
+{
+ return 1.0 - mfFreeStart;
+}
+
+ISegmentProgressBarRef SubSegment::createSegment( double fLength )
+{
+ OSL_ENSURE( (0.0 < fLength) && (fLength <= getFreeLength()), "SubSegment::createSegment - invalid length" );
+ fLength = getLimitedValue< double >( fLength, 0.0, getFreeLength() );
+ ISegmentProgressBarRef xSegment( new prv::SubSegment( *this, mfFreeStart, fLength ) );
+ mfFreeStart += fLength;
+ return xSegment;
+}
+
+} // namespace prv
+
+// ============================================================================
+
+SegmentProgressBar::SegmentProgressBar( const Reference< XStatusIndicator >& rxIndicator, const OUString& rText ) :
+ maProgress( rxIndicator, rText ),
+ mfFreeStart( 0.0 )
+{
+}
+
+double SegmentProgressBar::getPosition() const
+{
+ return maProgress.getPosition();
+}
+
+void SegmentProgressBar::setPosition( double fPosition )
+{
+ maProgress.setPosition( fPosition );
+}
+
+double SegmentProgressBar::getFreeLength() const
+{
+ return 1.0 - mfFreeStart;
+}
+
+ISegmentProgressBarRef SegmentProgressBar::createSegment( double fLength )
+{
+ OSL_ENSURE( (0.0 < fLength) && (fLength <= getFreeLength()), "SegmentProgressBar::createSegment - invalid length" );
+ fLength = getLimitedValue< double >( fLength, 0.0, getFreeLength() );
+ ISegmentProgressBarRef xSegment( new prv::SubSegment( maProgress, mfFreeStart, fLength ) );
+ mfFreeStart += fLength;
+ return xSegment;
+}
+
+// ============================================================================
+
+} // namespace oox
+
diff --git a/oox/source/helper/propertymap.cxx b/oox/source/helper/propertymap.cxx
new file mode 100644
index 000000000000..d6c8dd0b1cec
--- /dev/null
+++ b/oox/source/helper/propertymap.cxx
@@ -0,0 +1,286 @@
+/*************************************************************************
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: propertymap.cxx,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Author: rt $ $Date: 2008-01-17 08:05:59 $
+ *
+ * The Contents of this file are made available subject to
+ * the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2005 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ ************************************************************************/
+
+#include "oox/helper/propertymap.hxx"
+
+#include <string>
+#include <stdio.h>
+#include <osl/mutex.hxx>
+#include <cppuhelper/implbase2.hxx>
+
+using ::rtl::OUString;
+using ::osl::MutexGuard;
+using ::osl::Mutex;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::lang;
+
+namespace oox {
+
+bool PropertyMap::hasProperty( const ::rtl::OUString& rName ) const
+{
+ return find( rName ) != end();
+}
+
+const Any* PropertyMap::getPropertyValue( const ::rtl::OUString& rName ) const
+{
+ PropertyMapBase::const_iterator aIter( find( rName ) );
+ return aIter != end() ? &((*aIter).second) : NULL;
+}
+
+void PropertyMap::makeSequence( Sequence< NamedValue >& rSequence ) const
+{
+ rSequence.realloc( size() );
+ NamedValue* pValues = rSequence.getArray();
+ const_iterator aIter( begin() );
+ const_iterator aEnd( end() );
+
+ for( ; aIter != aEnd; aIter++, pValues++ )
+ {
+ pValues->Name = (*aIter).first;
+ pValues->Value = (*aIter).second;
+ }
+}
+
+
+void PropertyMap::makeSequence( Sequence< PropertyValue >& rSequence ) const
+{
+ rSequence.realloc( size() );
+ PropertyValue* pValues = rSequence.getArray();
+ const_iterator aIter( begin() );
+ const_iterator aEnd( end() );
+
+ for( ; aIter != aEnd; aIter++, pValues++ )
+ {
+ pValues->Name = (*aIter).first;
+ pValues->Value = (*aIter).second;
+ pValues->State = PropertyState_DIRECT_VALUE;
+ }
+}
+
+void PropertyMap::makeSequence( Sequence< OUString >& rNames, Sequence< Any >& rValues ) const
+{
+ rNames.realloc( size() );
+ rValues.realloc( size() );
+ OUString* pNames = rNames.getArray();
+ Any* pValues = rValues.getArray();
+ const_iterator aIter( begin() );
+ const_iterator aEnd( end() );
+
+ for( ; aIter != aEnd; aIter++, pNames++, pValues++ )
+ {
+ *pNames = (*aIter).first;
+ *pValues = (*aIter).second;
+ }
+}
+
+
+void PropertyMap::dump_debug(const char *pMessage)
+{
+ const_iterator aIter( begin() );
+ const_iterator aEnd( end() );
+
+ if( pMessage != NULL)
+ {
+ OSL_TRACE("OOX: %s", pMessage);
+ }
+
+ if(aIter == aEnd)
+ {
+ OSL_TRACE("OOX: Properties empty");
+ return;
+ }
+
+ OSL_TRACE("OOX: Properties");
+
+ for( ; aIter != aEnd; aIter++ )
+ {
+ std::string value;
+ const Any & any = (*aIter).second;
+ try {
+ char buffer[256];
+ if(!any.hasValue() )
+ {
+ value = "*empty*";
+ }
+ else if(any.has<OUString>() )
+ {
+ OUString aStr;
+ any >>= aStr;
+ value = OUStringToOString( aStr, RTL_TEXTENCODING_ASCII_US ).getStr();
+ }
+ else if(any.has<sal_Int16>())
+ {
+ sal_Int16 v = 0;
+ any >>= v;
+ sprintf(buffer, "%d", (int)v);
+ value = buffer;
+ }
+ else if(any.has<sal_Int32>())
+ {
+ sal_Int32 v = 0;
+ any >>= v;
+ sprintf(buffer, "%d", (int)v);
+ value = buffer;
+ }
+ else if(any.has<sal_Bool>())
+ {
+ sal_Bool v = sal_False;
+ any >>= v;
+ sprintf(buffer, "%d", (int)v);
+ value = buffer;
+ }
+ else
+ {
+ value = "contains a: ";
+ value += OUStringToOString(any.getValueTypeName(), RTL_TEXTENCODING_ASCII_US ).getStr();
+ }
+ }
+ catch( ... )
+ {
+ value = "unable to convert from ";
+ value += OUStringToOString(any.getValueTypeName(), RTL_TEXTENCODING_ASCII_US ).getStr();
+ }
+ OSL_TRACE("OOX: -> %s = %s", OUStringToOString( (*aIter).first, RTL_TEXTENCODING_ASCII_US ).getStr(),
+ value.c_str());
+ }
+}
+
+/** this class implements a generic XPropertySet
+ Properties of all names and types can be set and later retrieved
+ TODO: move this to comphelper or better find an existing implementation */
+class GenericPropertySet : public ::cppu::WeakImplHelper2< XPropertySet, XPropertySetInfo >,
+ private PropertyMapBase,
+ private Mutex
+{
+public:
+ GenericPropertySet();
+ GenericPropertySet( const PropertyMapBase& rProperties );
+
+ // XPropertySet
+ virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw (RuntimeException);
+ virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException);
+ virtual Any SAL_CALL getPropertyValue( const OUString& PropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
+ virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& xListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
+ virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
+ virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
+ virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const Reference< XVetoableChangeListener >& aListener ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException);
+
+ // XPropertySetInfo
+ virtual Sequence< Property > SAL_CALL getProperties( ) throw (RuntimeException);
+ virtual Property SAL_CALL getPropertyByName( const OUString& aName ) throw (UnknownPropertyException, RuntimeException);
+ virtual ::sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) throw (RuntimeException);
+};
+
+GenericPropertySet::GenericPropertySet()
+{
+}
+
+GenericPropertySet::GenericPropertySet( const PropertyMapBase& rProperties )
+: PropertyMapBase( rProperties )
+{
+}
+
+Reference< XPropertySetInfo > SAL_CALL GenericPropertySet::getPropertySetInfo() throw (RuntimeException)
+{
+ return this;
+}
+
+void SAL_CALL GenericPropertySet::setPropertyValue( const OUString& aPropertyName, const Any& aValue ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
+{
+ MutexGuard aGuard( *this );
+ (*this)[ aPropertyName ] = aValue;
+}
+
+Any SAL_CALL GenericPropertySet::getPropertyValue( const OUString& PropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
+{
+ iterator aIter( find( PropertyName ) );
+ if( aIter == end() )
+ throw UnknownPropertyException();
+
+ return (*aIter).second;
+}
+
+void SAL_CALL GenericPropertySet::addPropertyChangeListener( const OUString& , const Reference< XPropertyChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
+void SAL_CALL GenericPropertySet::removePropertyChangeListener( const OUString& , const Reference< XPropertyChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
+void SAL_CALL GenericPropertySet::addVetoableChangeListener( const OUString& , const Reference< XVetoableChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
+void SAL_CALL GenericPropertySet::removeVetoableChangeListener( const OUString& , const Reference< XVetoableChangeListener >& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException) {}
+
+// XPropertySetInfo
+Sequence< Property > SAL_CALL GenericPropertySet::getProperties( ) throw (RuntimeException)
+{
+ Sequence< Property > aRet( size() );
+ Property* pProperty = aRet.getArray();
+
+ for( iterator aIter = begin(); aIter != end(); aIter++, pProperty++ )
+ {
+ pProperty->Name = (*aIter).first;
+ pProperty->Handle = 0;
+ pProperty->Type = (*aIter).second.getValueType();
+ pProperty->Attributes = 0;
+ }
+
+ return aRet;
+}
+
+Property SAL_CALL GenericPropertySet::getPropertyByName( const OUString& aName ) throw (UnknownPropertyException, RuntimeException)
+{
+ iterator aIter( find( aName ) );
+ if( aIter == end() )
+ throw UnknownPropertyException();
+
+ Property aProperty;
+ aProperty.Name = (*aIter).first;
+ aProperty.Handle = 0;
+ aProperty.Type = (*aIter).second.getValueType();
+ aProperty.Attributes = 0;
+
+ return aProperty;
+}
+
+::sal_Bool SAL_CALL GenericPropertySet::hasPropertyByName( const OUString& Name ) throw (RuntimeException)
+{
+ return find( Name ) != end();
+}
+
+
+Reference< XPropertySet > PropertyMap::makePropertySet() const
+{
+ Reference< XPropertySet > xSet( new GenericPropertySet(*this) );
+ return xSet;
+}
+
+}
+
diff --git a/oox/source/helper/propertysequence.cxx b/oox/source/helper/propertysequence.cxx
new file mode 100644
index 000000000000..becf2549f757
--- /dev/null
+++ b/oox/source/helper/propertysequence.cxx
@@ -0,0 +1,164 @@
+/*************************************************************************
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: propertysequence.cxx,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Author: rt $ $Date: 2008-01-17 08:05:59 $
+ *
+ * The Contents of this file are made available subject to
+ * the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2005 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ ************************************************************************/
+
+#include "oox/helper/propertysequence.hxx"
+#include "oox/helper/propertyset.hxx"
+#include <algorithm>
+#include <osl/diagnose.h>
+#include <com/sun/star/beans/PropertyValue.hpp>
+
+using ::rtl::OUString;
+using ::com::sun::star::uno::Any;
+using ::com::sun::star::uno::Sequence;
+using ::com::sun::star::beans::PropertyValue;
+
+namespace oox {
+
+// ============================================================================
+
+PropertySequence::PropertySequence( const sal_Char* const* ppcPropNames,
+ const sal_Char* const* ppcPropNames2, const sal_Char* const* ppcPropNames3 ) :
+ mnNextIndex( 0 )
+{
+ OSL_ENSURE( ppcPropNames, "PropertySequence::PropertySequence - no strings found" );
+
+ // create OUStrings from ASCII property names
+ typedef ::std::pair< OUString, size_t > IndexedOUString;
+ typedef ::std::vector< IndexedOUString > IndexedOUStringVec;
+ IndexedOUStringVec aPropNameVec;
+ size_t nVecIdx = 0;
+ while( *ppcPropNames )
+ {
+ OUString aPropName = OUString::createFromAscii( *ppcPropNames++ );
+ aPropNameVec.push_back( IndexedOUString( aPropName, nVecIdx++ ) );
+ }
+ if( ppcPropNames2 ) while( *ppcPropNames2 )
+ {
+ OUString aPropName = OUString::createFromAscii( *ppcPropNames2++ );
+ aPropNameVec.push_back( IndexedOUString( aPropName, nVecIdx++ ) );
+ }
+ if( ppcPropNames3 ) while( *ppcPropNames3 )
+ {
+ OUString aPropName = OUString::createFromAscii( *ppcPropNames3++ );
+ aPropNameVec.push_back( IndexedOUString( aPropName, nVecIdx++ ) );
+ }
+
+ // sorts the pairs, which will be sorted by first component (the property name)
+ ::std::sort( aPropNameVec.begin(), aPropNameVec.end() );
+
+ // resize member sequences
+ size_t nSize = aPropNameVec.size();
+ maNameSeq.realloc( static_cast< sal_Int32 >( nSize ) );
+ maValueSeq.realloc( static_cast< sal_Int32 >( nSize ) );
+ maNameOrder.resize( nSize );
+
+ // fill the property name sequence and store original sort order
+ sal_Int32 nSeqIdx = 0;
+ for( IndexedOUStringVec::const_iterator aIt = aPropNameVec.begin(),
+ aEnd = aPropNameVec.end(); aIt != aEnd; ++aIt, ++nSeqIdx )
+ {
+ maNameSeq[ nSeqIdx ] = aIt->first;
+ maNameOrder[ aIt->second ] = nSeqIdx;
+ }
+}
+
+void PropertySequence::clearAllAnys()
+{
+ for( sal_Int32 nIdx = 0, nLen = maValueSeq.getLength(); nIdx < nLen; ++nIdx )
+ maValueSeq[ nIdx ].clear();
+}
+
+// read properties ------------------------------------------------------------
+
+void PropertySequence::readFromPropertySet( const PropertySet& rPropSet )
+{
+ rPropSet.getProperties( maValueSeq, maNameSeq );
+ mnNextIndex = 0;
+}
+
+bool PropertySequence::readValue( Any& rAny )
+{
+ Any* pAny = getNextAny();
+ if( pAny ) rAny = *pAny;
+ return pAny != 0;
+}
+
+// write properties -----------------------------------------------------------
+
+void PropertySequence::writeValue( const Any& rAny )
+{
+ if( Any* pAny = getNextAny() )
+ *pAny = rAny;
+}
+
+void PropertySequence::writeToPropertySet( PropertySet& rPropSet )
+{
+ OSL_ENSURE( mnNextIndex == maNameOrder.size(), "PropertySequence::writeToPropertySet - sequence not complete" );
+ rPropSet.setProperties( maNameSeq, maValueSeq );
+ mnNextIndex = 0;
+}
+
+Sequence< PropertyValue > PropertySequence::createPropertySequence()
+{
+ OSL_ENSURE( mnNextIndex == maNameOrder.size(), "PropertySequence::createPropertySequence - sequence not complete" );
+ Sequence< PropertyValue > aPropSeq( maNameSeq.getLength() );
+ PropertyValue* pProp = aPropSeq.getArray();
+ PropertyValue* pPropEnd = pProp + aPropSeq.getLength();
+ const OUString* pName = maNameSeq.getConstArray();
+ const Any* pValue = maValueSeq.getConstArray();
+ for( ; pProp != pPropEnd; ++pProp, ++pName, ++pValue )
+ {
+ pProp->Name = *pName;
+ pProp->Value = *pValue;
+ }
+ mnNextIndex = 0;
+ return aPropSeq;
+}
+
+// private --------------------------------------------------------------------
+
+Any* PropertySequence::getNextAny()
+{
+ OSL_ENSURE( mnNextIndex < maNameOrder.size(), "PropertySequence::getNextAny - sequence overflow" );
+ Any* pAny = 0;
+ if( mnNextIndex < maNameOrder.size() )
+ pAny = &maValueSeq[ maNameOrder[ mnNextIndex++ ] ];
+ return pAny;
+}
+
+// ============================================================================
+
+} // namespace oox
+
diff --git a/oox/source/helper/propertyset.cxx b/oox/source/helper/propertyset.cxx
new file mode 100644
index 000000000000..0b5af8269e6d
--- /dev/null
+++ b/oox/source/helper/propertyset.cxx
@@ -0,0 +1,157 @@
+/*************************************************************************
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: propertyset.cxx,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Author: rt $ $Date: 2008-01-17 08:05:59 $
+ *
+ * The Contents of this file are made available subject to
+ * the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2005 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ ************************************************************************/
+
+#include "oox/helper/propertyset.hxx"
+#include <rtl/strbuf.hxx>
+#include <osl/diagnose.h>
+
+using ::rtl::OUString;
+using ::rtl::OStringBuffer;
+using ::rtl::OUStringToOString;
+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::beans::XPropertySet;
+
+namespace oox {
+
+// ============================================================================
+
+void PropertySet::set( const Reference< XPropertySet >& rxPropSet )
+{
+ mxPropSet = rxPropSet;
+ mxMultiPropSet.set( mxPropSet, UNO_QUERY );
+}
+
+// Get properties -------------------------------------------------------------
+
+bool PropertySet::getAnyProperty( Any& orValue, const OUString& rPropName ) const
+{
+ bool bHasValue = false;
+ try
+ {
+ if( mxPropSet.is() )
+ {
+ orValue = mxPropSet->getPropertyValue( rPropName );
+ bHasValue = true;
+ }
+ }
+ catch( Exception& )
+ {
+ OSL_ENSURE( false, OStringBuffer( "PropertySet::getAnyProperty - cannot get property \"" ).
+ append( OUStringToOString( rPropName, RTL_TEXTENCODING_ASCII_US ) ).append( '"' ).getStr() );
+ }
+ return bHasValue;
+}
+
+bool PropertySet::getBoolProperty( const OUString& rPropName ) const
+{
+ Any aAny;
+ bool bValue = false;
+ return getAnyProperty( aAny, rPropName ) && (aAny >>= bValue) && bValue;
+}
+
+void PropertySet::getProperties( Sequence< Any >& orValues, const Sequence< OUString >& rPropNames ) const
+{
+ try
+ {
+ if( mxMultiPropSet.is() ) // first try the XMultiPropertySet
+ {
+ orValues = mxMultiPropSet->getPropertyValues( rPropNames );
+ }
+ else if( mxPropSet.is() )
+ {
+ sal_Int32 nLen = rPropNames.getLength();
+ const OUString* pPropName = rPropNames.getConstArray();
+ const OUString* pPropNameEnd = pPropName + nLen;
+ orValues.realloc( nLen );
+ Any* pValue = orValues.getArray();
+ for( ; pPropName != pPropNameEnd; ++pPropName, ++pValue )
+ *pValue = mxPropSet->getPropertyValue( *pPropName );
+ }
+ }
+ catch( Exception& )
+ {
+ OSL_ENSURE( false, "PropertySet::getProperties - cannot get all property values" );
+ }
+}
+
+// Set properties -------------------------------------------------------------
+
+void PropertySet::setAnyProperty( const OUString& rPropName, const Any& rValue )
+{
+ try
+ {
+ if( mxPropSet.is() )
+ mxPropSet->setPropertyValue( rPropName, rValue );
+ }
+ catch( Exception& )
+ {
+ OSL_ENSURE( false, OStringBuffer( "PropertySet::setAnyProperty - cannot set property \"" ).
+ append( OUStringToOString( rPropName, RTL_TEXTENCODING_ASCII_US ) ).append( '"' ).getStr() );
+ }
+}
+
+void PropertySet::setProperties( const Sequence< OUString >& rPropNames, const Sequence< Any >& rValues )
+{
+ OSL_ENSURE( rPropNames.getLength() == rValues.getLength(),
+ "PropertySet::setProperties - length of sequences different" );
+ try
+ {
+ if( mxMultiPropSet.is() ) // first try the XMultiPropertySet
+ {
+ mxMultiPropSet->setPropertyValues( rPropNames, rValues );
+ }
+ else if( mxPropSet.is() )
+ {
+ const OUString* pPropName = rPropNames.getConstArray();
+ const OUString* pPropNameEnd = pPropName + rPropNames.getLength();
+ const Any* pValue = rValues.getConstArray();
+ for( ; pPropName != pPropNameEnd; ++pPropName, ++pValue )
+ mxPropSet->setPropertyValue( *pPropName, *pValue );
+ }
+ }
+ catch( Exception& )
+ {
+ OSL_ENSURE( false, "PropertySet::setAnyProperty - cannot set all property values" );
+ }
+}
+
+// ============================================================================
+
+} // namespace oox
+
diff --git a/oox/source/helper/recordinputstream.cxx b/oox/source/helper/recordinputstream.cxx
new file mode 100644
index 000000000000..66f414b36de5
--- /dev/null
+++ b/oox/source/helper/recordinputstream.cxx
@@ -0,0 +1,104 @@
+/*************************************************************************
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: recordinputstream.cxx,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Author: rt $ $Date: 2008-01-17 08:05:59 $
+ *
+ * The Contents of this file are made available subject to
+ * the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2005 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ ************************************************************************/
+
+#include "oox/helper/recordinputstream.hxx"
+#include <vector>
+
+using ::rtl::OUString;
+
+namespace oox {
+
+// ============================================================================
+
+RecordInputStream::RecordInputStream( const RecordDataSequence& rData ) :
+ maData( rData ),
+ mnRecSize( rData.getLength() ),
+ mnRecPos( 0 ),
+ mbValid( true )
+{
+}
+
+sal_Int32 RecordInputStream::read( void* opData, sal_Int32 nBytes )
+{
+ sal_Int32 nReadSize = ::std::min( nBytes, getRecLeft() );
+ OSL_ENSURE( !mbValid || (nReadSize == nBytes), "RecordInputStream::read - buffer overflow" );
+ mbValid = nReadSize == nBytes;
+ if( mbValid && opData && (nReadSize > 0) )
+ memcpy( opData, maData.getConstArray() + mnRecPos, nReadSize );
+ mnRecPos += nReadSize;
+ return nReadSize;
+}
+
+OUString RecordInputStream::readString( bool b32BitLen )
+{
+ OUString aString;
+ sal_Int32 nCharCount = b32BitLen ? readValue< sal_Int32 >() : readValue< sal_Int16 >();
+ // string length -1 is often used to indicate a missing string
+ OSL_ENSURE( !mbValid || (nCharCount >= -1), "RecordInputStream::readString - invalid string length" );
+ if( mbValid && (nCharCount >= 0) )
+ {
+ ::std::vector< sal_Unicode > aBuffer;
+ aBuffer.reserve( getLimitedValue< size_t, sal_Int32 >( nCharCount + 1, 0, 0xFFFF ) );
+ for( sal_Int32 nCharIdx = 0; mbValid && (nCharIdx < nCharCount); ++nCharIdx )
+ {
+ sal_uInt16 nChar;
+ readValue( nChar );
+ aBuffer.push_back( static_cast< sal_Unicode >( nChar ) );
+ }
+ aBuffer.push_back( 0 );
+ aString = OUString( &aBuffer.front() );
+ }
+ return aString;
+}
+
+void RecordInputStream::seek( sal_Int32 nRecPos )
+{
+ mnRecPos = getLimitedValue< sal_Int32, sal_Int32 >( nRecPos, 0, mnRecSize );
+ OSL_ENSURE( !mbValid || (nRecPos == mnRecPos), "RecordInputStream::seek - invalid position" );
+ mbValid = nRecPos == mnRecPos;
+}
+
+void RecordInputStream::skip( sal_Int32 nBytes )
+{
+ sal_Int32 nSkipSize = getLimitedValue< sal_Int32, sal_Int32 >( nBytes, 0, getRecLeft() );
+ OSL_ENSURE( !mbValid || (nSkipSize == nBytes), "RecordInputStream::skip - buffer overflow" );
+ mbValid = nSkipSize == nBytes;
+ mnRecPos += nSkipSize;
+}
+
+// ============================================================================
+
+} // namespace oox
+
diff --git a/oox/source/helper/storagebase.cxx b/oox/source/helper/storagebase.cxx
new file mode 100644
index 000000000000..8fd7f1c25e80
--- /dev/null
+++ b/oox/source/helper/storagebase.cxx
@@ -0,0 +1,201 @@
+/*************************************************************************
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: storagebase.cxx,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Author: rt $ $Date: 2008-01-17 08:05:59 $
+ *
+ * The Contents of this file are made available subject to
+ * the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2005 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ ************************************************************************/
+
+#include "oox/helper/storagebase.hxx"
+#include <rtl/ustrbuf.hxx>
+
+using ::rtl::OUString;
+using ::rtl::OUStringBuffer;
+using ::com::sun::star::uno::Reference;
+using ::com::sun::star::embed::XStorage;
+using ::com::sun::star::io::XInputStream;
+using ::com::sun::star::io::XOutputStream;
+
+namespace oox {
+
+// ============================================================================
+
+namespace {
+
+void lclSplitFirstElement( OUString& orElement, OUString& orRemainder, const OUString& rFullName )
+{
+ sal_Int32 nSlashPos = rFullName.indexOf( '/' );
+ if( (0 <= nSlashPos) && (nSlashPos < rFullName.getLength()) )
+ {
+ orElement = rFullName.copy( 0, nSlashPos );
+ orRemainder = rFullName.copy( nSlashPos + 1 );
+ }
+ else
+ {
+ orElement = rFullName;
+ }
+}
+
+} // namespace
+
+// ----------------------------------------------------------------------------
+
+StorageBase::StorageBase( const Reference< XInputStream >& rxInStream, bool bBaseStreamAccess ) :
+ mxInStream( rxInStream ),
+ mpParentStorage( 0 ),
+ mbBaseStreamAccess( bBaseStreamAccess )
+{
+ OSL_ENSURE( mxInStream.is(), "StorageBase::StorageBase - missing base input stream" );
+}
+
+StorageBase::StorageBase( const Reference< XOutputStream >& rxOutStream, bool bBaseStreamAccess ) :
+ mxOutStream( rxOutStream ),
+ mpParentStorage( 0 ),
+ mbBaseStreamAccess( bBaseStreamAccess )
+{
+ OSL_ENSURE( mxOutStream.is(), "StorageBase::StorageBase - missing base output stream" );
+}
+
+StorageBase::StorageBase( const StorageBase& rParentStorage, const OUString& rStorageName ) :
+ maStorageName( rStorageName ),
+ mpParentStorage( &rParentStorage ),
+ mbBaseStreamAccess( false )
+{
+}
+
+StorageBase::~StorageBase()
+{
+}
+
+bool StorageBase::isStorage() const
+{
+ return implIsStorage();
+}
+
+Reference< XStorage > StorageBase::getXStorage() const
+{
+ return implGetXStorage();
+}
+
+const OUString& StorageBase::getName() const
+{
+ return maStorageName;
+}
+
+OUString StorageBase::getPath() const
+{
+ OUStringBuffer aBuffer;
+ if( mpParentStorage )
+ aBuffer.append( mpParentStorage->getPath() );
+ if( aBuffer.getLength() > 0 )
+ aBuffer.append( sal_Unicode( '/' ) );
+ aBuffer.append( maStorageName );
+ return aBuffer.makeStringAndClear();
+}
+
+void StorageBase::getElementNames( ::std::vector< OUString >& orElementNames ) const
+{
+ orElementNames.clear();
+ implGetElementNames( orElementNames );
+}
+
+StorageRef StorageBase::openSubStorage( const OUString& rStorageName, bool bCreate )
+{
+ 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 );
+ return xSubStorage;
+}
+
+Reference< XInputStream > StorageBase::openInputStream( const OUString& rStreamName )
+{
+ Reference< XInputStream > xInStream;
+ OUString aElement, aRemainder;
+ lclSplitFirstElement( aElement, aRemainder, rStreamName );
+ if( aElement.getLength() > 0 )
+ {
+ if( aRemainder.getLength() > 0 )
+ {
+ StorageRef xSubStorage = getSubStorage( aElement, false );
+ if( xSubStorage.get() )
+ xInStream = xSubStorage->openInputStream( aRemainder );
+ }
+ else
+ {
+ xInStream = implOpenInputStream( aElement );
+ }
+ }
+ else if( mbBaseStreamAccess )
+ {
+ xInStream = mxInStream;
+ }
+ return xInStream;
+}
+
+Reference< XOutputStream > StorageBase::openOutputStream( const OUString& rStreamName )
+{
+ Reference< XOutputStream > xOutStream;
+ OUString aElement, aRemainder;
+ lclSplitFirstElement( aElement, aRemainder, rStreamName );
+ if( aElement.getLength() > 0 )
+ {
+ if( aRemainder.getLength() > 0 )
+ {
+ StorageRef xSubStorage = getSubStorage( aElement, true );
+ if( xSubStorage.get() )
+ xOutStream = xSubStorage->openOutputStream( aRemainder );
+ }
+ else
+ {
+ xOutStream = implOpenOutputStream( aElement );
+ }
+ }
+ else if( mbBaseStreamAccess )
+ {
+ xOutStream = mxOutStream;
+ }
+ return xOutStream;
+}
+
+StorageRef StorageBase::getSubStorage( const OUString& rElementName, bool bCreate )
+{
+ SubStorageMap::iterator aIt = maSubStorages.find( rElementName );
+ return (aIt == maSubStorages.end()) ?
+ (maSubStorages[ rElementName ] = implOpenSubStorage( rElementName, bCreate )) : aIt->second;
+}
+
+// ============================================================================
+
+} // namespace oox
+
diff --git a/oox/source/helper/zipstorage.cxx b/oox/source/helper/zipstorage.cxx
new file mode 100644
index 000000000000..f9a11da3196b
--- /dev/null
+++ b/oox/source/helper/zipstorage.cxx
@@ -0,0 +1,174 @@
+/*************************************************************************
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: zipstorage.cxx,v $
+ *
+ * $Revision: 1.2 $
+ *
+ * last change: $Author: rt $ $Date: 2008-01-17 08:05:59 $
+ *
+ * The Contents of this file are made available subject to
+ * the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ * GNU Lesser General Public License Version 2.1
+ * =============================================
+ * Copyright 2005 by Sun Microsystems, Inc.
+ * 901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software Foundation.
+ *
+ * This library 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 for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ ************************************************************************/
+
+#include "oox/helper/zipstorage.hxx"
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/embed/XStorage.hpp>
+#include <com/sun/star/io/XInputStream.hpp>
+#include <com/sun/star/io/XOutputStream.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::embed::XStorage;
+using ::com::sun::star::io::XInputStream;
+using ::com::sun::star::io::XOutputStream;
+
+namespace oox {
+
+// ============================================================================
+
+ZipStorage::ZipStorage(
+ const Reference< XMultiServiceFactory >& rxFactory,
+ const Reference< XInputStream >& rxInStream ) :
+ StorageBase( rxInStream, false )
+{
+ OSL_ENSURE( rxFactory.is(), "ZipStorage::ZipStorage - missing service factory" );
+ // create base storage object
+ try
+ {
+ mxStorage = ::comphelper::OStorageHelper::GetStorageFromInputStream( rxInStream, rxFactory );
+ }
+ catch( Exception& )
+ {
+ OSL_ENSURE( false, "ZipStorage::ZipStorage - cannot open input storage" );
+ }
+}
+
+ZipStorage::ZipStorage(
+ const Reference< XMultiServiceFactory >& rxFactory,
+ const Reference< XOutputStream >& rxOutStream ) :
+ StorageBase( rxOutStream, false )
+{
+ OSL_ENSURE( rxFactory.is(), "ZipStorage::ZipStorage - missing service factory" );
+ (void)rxFactory; // prevent compiler warning
+ OSL_ENSURE( false, "ZipStorage::ZipStorage - not implemented" );
+}
+
+ZipStorage::ZipStorage( const ZipStorage& rParentStorage, const Reference< XStorage >& rxStorage, const OUString& rElementName ) :
+ StorageBase( rParentStorage, rElementName ),
+ mxStorage( rxStorage )
+{
+ OSL_ENSURE( mxStorage.is(), "ZipStorage::ZipStorage - missing storage" );
+}
+
+ZipStorage::~ZipStorage()
+{
+}
+
+bool ZipStorage::implIsStorage() const
+{
+ return mxStorage.is();
+}
+
+Reference< XStorage > ZipStorage::implGetXStorage() const
+{
+ return mxStorage;
+}
+
+void ZipStorage::implGetElementNames( ::std::vector< OUString >& orElementNames ) const
+{
+ Sequence< OUString > aNames;
+ if( mxStorage.is() ) try
+ {
+ aNames = mxStorage->getElementNames();
+ if( aNames.getLength() > 0 )
+ orElementNames.insert( orElementNames.end(), aNames.getConstArray(), aNames.getConstArray() + aNames.getLength() );
+ }
+ catch( Exception& )
+ {
+ }
+}
+
+StorageRef ZipStorage::implOpenSubStorage( const OUString& rElementName, bool bCreate )
+{
+ OSL_ENSURE( !bCreate, "ZipStorage::implOpenSubStorage - creating new sub storages not implemented" );
+ (void)bCreate; // prevent compiler warning
+
+ Reference< XStorage > xSubXStorage;
+ try
+ {
+ // XStorage::isStorageElement may throw various exceptions...
+ if( mxStorage->isStorageElement( rElementName ) )
+ xSubXStorage = mxStorage->openStorageElement(
+ rElementName, ::com::sun::star::embed::ElementModes::READ );
+ }
+ catch( Exception& )
+ {
+ }
+
+ StorageRef xSubStorage;
+ if( xSubXStorage.is() )
+ xSubStorage.reset( new ZipStorage( *this, xSubXStorage, rElementName ) );
+ return xSubStorage;
+}
+
+Reference< XInputStream > ZipStorage::implOpenInputStream( const OUString& rElementName )
+{
+ Reference< XInputStream > xInStream;
+ if( mxStorage.is() ) try
+ {
+ xInStream.set( mxStorage->openStreamElement( rElementName, ::com::sun::star::embed::ElementModes::READ ), UNO_QUERY );
+ }
+ catch( Exception& )
+ {
+ }
+ return xInStream;
+}
+
+Reference< XOutputStream > ZipStorage::implOpenOutputStream( const OUString& rElementName )
+{
+ Reference< XOutputStream > xOutStream;
+ if( mxStorage.is() ) try
+ {
+ (void)rElementName;
+ OSL_ENSURE( false, "ZipStorage::implOpenOutputStream - not implemented" );
+ }
+ catch( Exception& )
+ {
+ }
+ return xOutStream;
+}
+
+// ============================================================================
+
+} // namespace oox
+