diff options
Diffstat (limited to 'package/source/xstor')
22 files changed, 0 insertions, 14502 deletions
diff --git a/package/source/xstor/disposelistener.cxx b/package/source/xstor/disposelistener.cxx deleted file mode 100644 index 312c77d04..000000000 --- a/package/source/xstor/disposelistener.cxx +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" - -#include "disposelistener.hxx" -#include "xstorage.hxx" - -using namespace ::com::sun::star; - -OChildDispListener_Impl::OChildDispListener_Impl( OStorage& aStorage ) -: m_pStorage( &aStorage ) -{} - -OChildDispListener_Impl::~OChildDispListener_Impl() -{} - -void OChildDispListener_Impl::OwnerIsDisposed() -{ - ::osl::MutexGuard aGuard( m_aMutex ); - m_pStorage = NULL; -} - -void SAL_CALL OChildDispListener_Impl::disposing( const lang::EventObject& Source ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - // ObjectIsDisposed must not contain any locking! - if ( m_pStorage && Source.Source.is() ) - m_pStorage->ChildIsDisposed( Source.Source ); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/disposelistener.hxx b/package/source/xstor/disposelistener.hxx deleted file mode 100644 index 54b336688..000000000 --- a/package/source/xstor/disposelistener.hxx +++ /dev/null @@ -1,53 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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. - * - ************************************************************************/ - -#ifndef __DISPOSELISTENER_HXX_ -#define __DISPOSELISTENER_HXX_ - -#include <com/sun/star/lang/XEventListener.hpp> -#include <cppuhelper/implbase1.hxx> -#include <osl/mutex.hxx> - -class OStorage; -class OChildDispListener_Impl : public ::cppu::WeakImplHelper1 < ::com::sun::star::lang::XEventListener > -{ - ::osl::Mutex m_aMutex; - OStorage* m_pStorage; - -public: - OChildDispListener_Impl( OStorage& aStorage ); - virtual ~OChildDispListener_Impl(); - - void OwnerIsDisposed(); - - virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/makefile.mk b/package/source/xstor/makefile.mk deleted file mode 100644 index 5c381ba4c..000000000 --- a/package/source/xstor/makefile.mk +++ /dev/null @@ -1,83 +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. -# -#************************************************************************* - -PRJ=..$/.. - -PRJNAME=package -TARGET=xstor - -ENABLE_EXCEPTIONS=TRUE - -# --- Settings ----------------------------------------------------- - -.INCLUDE : settings.mk - -# --- Files -------------------------------------------------------- - -.IF "$(L10N_framework)"=="" - -SLOFILES = \ - $(SLO)$/ohierarchyholder.obj\ - $(SLO)$/ocompinstream.obj\ - $(SLO)$/oseekinstream.obj\ - $(SLO)$/owriteablestream.obj\ - $(SLO)$/xstorage.obj\ - $(SLO)$/xfactory.obj\ - $(SLO)$/disposelistener.obj\ - $(SLO)$/selfterminatefilestream.obj\ - $(SLO)$/switchpersistencestream.obj\ - $(SLO)$/register.obj - -SHL1TARGET=$(TARGET) -SHL1STDLIBS=\ - $(SALLIB) \ - $(CPPULIB) \ - $(CPPUHELPERLIB) \ - $(COMPHELPERLIB) - -SHL1OBJS=$(SLOFILES) -SHL1DEF=$(MISC)$/$(TARGET).def - -SHL1IMPLIB=i$(SHL1TARGET) - -DEF1NAME=$(SHL1TARGET) -DEF1EXPORTFILE=$(SHL1TARGET).dxp - -.ENDIF # L10N_framework - -# --- Targets ------------------------------------------------------- - -.INCLUDE : target.mk - - -ALLTAR : $(MISC)/xstor.component - -$(MISC)/xstor.component .ERRREMOVE : $(SOLARENV)/bin/createcomponent.xslt \ - xstor.component - $(XSLTPROC) --nonet --stringparam uri \ - '$(COMPONENTPREFIX_BASIS_NATIVE)$(SHL1TARGETN:f)' -o $@ \ - $(SOLARENV)/bin/createcomponent.xslt xstor.component diff --git a/package/source/xstor/ocompinstream.cxx b/package/source/xstor/ocompinstream.cxx deleted file mode 100644 index 5134d4f56..000000000 --- a/package/source/xstor/ocompinstream.cxx +++ /dev/null @@ -1,761 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" - -#include "ocompinstream.hxx" -#include <com/sun/star/embed/StorageFormats.hpp> -#include <com/sun/star/lang/DisposedException.hpp> -#include <osl/diagnose.h> - -#include "owriteablestream.hxx" -#include "xstorage.hxx" - -using namespace ::com::sun::star; - -//----------------------------------------------- -OInputCompStream::OInputCompStream( OWriteStream_Impl& aImpl, - uno::Reference < io::XInputStream > xStream, - const uno::Sequence< beans::PropertyValue >& aProps, - sal_Int32 nStorageType ) -: m_pImpl( &aImpl ) -, m_rMutexRef( m_pImpl->m_rMutexRef ) -, m_xStream( xStream ) -, m_pInterfaceContainer( NULL ) -, m_aProperties( aProps ) -, m_bDisposed( sal_False ) -, m_nStorageType( nStorageType ) -{ - OSL_ENSURE( m_pImpl->m_rMutexRef.Is(), "No mutex is provided!\n" ); - if ( !m_pImpl->m_rMutexRef.Is() ) - throw uno::RuntimeException(); // just a disaster - - OSL_ENSURE( xStream.is(), "No stream is provided!\n" ); -} - -//----------------------------------------------- -OInputCompStream::OInputCompStream( uno::Reference < io::XInputStream > xStream, - const uno::Sequence< beans::PropertyValue >& aProps, - sal_Int32 nStorageType ) -: m_pImpl( NULL ) -, m_rMutexRef( new SotMutexHolder ) -, m_xStream( xStream ) -, m_pInterfaceContainer( NULL ) -, m_aProperties( aProps ) -, m_bDisposed( sal_False ) -, m_nStorageType( nStorageType ) -{ - OSL_ENSURE( xStream.is(), "No stream is provided!\n" ); -} - -//----------------------------------------------- -OInputCompStream::~OInputCompStream() -{ - { - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( !m_bDisposed ) - { - m_refCount++; - dispose(); - } - - if ( m_pInterfaceContainer ) - delete m_pInterfaceContainer; - } -} - -//----------------------------------------------- -uno::Any SAL_CALL OInputCompStream::queryInterface( const uno::Type& rType ) - throw( uno::RuntimeException ) -{ - uno::Any aReturn; - - // common interfaces - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<io::XInputStream*> ( this ) - , static_cast<io::XStream*> ( this ) - , static_cast<lang::XComponent*> ( this ) - , static_cast<beans::XPropertySet*> ( this ) - , static_cast<embed::XExtendedStorageStream*> ( this ) ); - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - - if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - { - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<embed::XRelationshipAccess*> ( this ) ); - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - } - - return OWeakObject::queryInterface( rType ); -} - -//----------------------------------------------- -sal_Int32 SAL_CALL OInputCompStream::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xStream.is() ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No stream!" ) ) ); - throw uno::RuntimeException(); - } - - return m_xStream->readBytes( aData, nBytesToRead ); -} - -//----------------------------------------------- -sal_Int32 SAL_CALL OInputCompStream::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xStream.is() ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No stream!" ) ) ); - throw uno::RuntimeException(); - } - - return m_xStream->readSomeBytes( aData, nMaxBytesToRead ); - -} - -//----------------------------------------------- -void SAL_CALL OInputCompStream::skipBytes( sal_Int32 nBytesToSkip ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xStream.is() ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No stream!" ) ) ); - throw uno::RuntimeException(); - } - - m_xStream->skipBytes( nBytesToSkip ); - -} - -//----------------------------------------------- -sal_Int32 SAL_CALL OInputCompStream::available( ) - throw ( io::NotConnectedException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xStream.is() ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No stream!" ) ) ); - throw uno::RuntimeException(); - } - - return m_xStream->available(); - -} - -//----------------------------------------------- -void SAL_CALL OInputCompStream::closeInput( ) - throw ( io::NotConnectedException, - io::IOException, - uno::RuntimeException ) -{ - dispose(); -} - -//----------------------------------------------- -uno::Reference< io::XInputStream > SAL_CALL OInputCompStream::getInputStream() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xStream.is() ) - return uno::Reference< io::XInputStream >(); - - return uno::Reference< io::XInputStream >( static_cast< io::XInputStream* >( this ), uno::UNO_QUERY ); -} - -//----------------------------------------------- -uno::Reference< io::XOutputStream > SAL_CALL OInputCompStream::getOutputStream() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - return uno::Reference< io::XOutputStream >(); -} - -//----------------------------------------------- -void OInputCompStream::InternalDispose() -{ - // can be called only by OWriteStream_Impl - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - // the source object is also a kind of locker for the current object - // since the listeners could dispose the object while being notified - lang::EventObject aSource( static_cast< ::cppu::OWeakObject*>( this ) ); - - if ( m_pInterfaceContainer ) - m_pInterfaceContainer->disposeAndClear( aSource ); - - try - { - m_xStream->closeInput(); - } - catch( uno::Exception& ) - {} - - m_pImpl = NULL; - m_bDisposed = sal_True; -} - -//----------------------------------------------- -void SAL_CALL OInputCompStream::dispose( ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pInterfaceContainer ) - { - lang::EventObject aSource( static_cast< ::cppu::OWeakObject*>( this ) ); - m_pInterfaceContainer->disposeAndClear( aSource ); - } - - m_xStream->closeInput(); - - if ( m_pImpl ) - { - m_pImpl->InputStreamDisposed( this ); - m_pImpl = NULL; - } - - m_bDisposed = sal_True; -} - -//----------------------------------------------- -void SAL_CALL OInputCompStream::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_pInterfaceContainer ) - m_pInterfaceContainer = new ::cppu::OInterfaceContainerHelper( m_rMutexRef->GetMutex() ); - - m_pInterfaceContainer->addInterface( xListener ); -} - -//----------------------------------------------- -void SAL_CALL OInputCompStream::removeEventListener( const uno::Reference< lang::XEventListener >& xListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pInterfaceContainer ) - m_pInterfaceContainer->removeInterface( xListener ); -} - -//----------------------------------------------- -sal_Bool SAL_CALL OInputCompStream::hasByID( const ::rtl::OUString& sID ) - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - try - { - getRelationshipByID( sID ); - return sal_True; - } - catch( container::NoSuchElementException& ) - {} - - return sal_False; -} - -//----------------------------------------------- -::rtl::OUString SAL_CALL OInputCompStream::getTargetByID( const ::rtl::OUString& sID ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - uno::Sequence< beans::StringPair > aSeq = getRelationshipByID( sID ); - for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ ) - if ( aSeq[nInd].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Target" ) ) ) - return aSeq[nInd].Second; - - return ::rtl::OUString(); -} - -//----------------------------------------------- -::rtl::OUString SAL_CALL OInputCompStream::getTypeByID( const ::rtl::OUString& sID ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - uno::Sequence< beans::StringPair > aSeq = getRelationshipByID( sID ); - for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ ) - if ( aSeq[nInd].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Type" ) ) ) - return aSeq[nInd].Second; - - return ::rtl::OUString(); -} - -//----------------------------------------------- -uno::Sequence< beans::StringPair > SAL_CALL OInputCompStream::getRelationshipByID( const ::rtl::OUString& sID ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - // TODO/LATER: in future the unification of the ID could be checked - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ ) - for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ ) - if ( aSeq[nInd1][nInd2].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Id" ) ) ) - { - if ( aSeq[nInd1][nInd2].Second.equals( sID ) ) - return aSeq[nInd1]; - break; - } - - throw container::NoSuchElementException(); -} - -//----------------------------------------------- -uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OInputCompStream::getRelationshipsByType( const ::rtl::OUString& sType ) - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - uno::Sequence< uno::Sequence< beans::StringPair > > aResult; - sal_Int32 nEntriesNum = 0; - - // TODO/LATER: in future the unification of the ID could be checked - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ ) - for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ ) - if ( aSeq[nInd1][nInd2].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Type" ) ) ) - { - if ( aSeq[nInd1][nInd2].Second.equals( sType ) ) - { - aResult.realloc( nEntriesNum ); - aResult[nEntriesNum-1] = aSeq[nInd1]; - } - break; - } - - return aResult; -} - -//----------------------------------------------- -uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OInputCompStream::getAllRelationships() - throw (io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - // TODO/LATER: in future the information could be taken directly from m_pImpl when possible - uno::Sequence< uno::Sequence< beans::StringPair > > aResult; - for ( sal_Int32 aInd = 0; aInd < m_aProperties.getLength(); aInd++ ) - if ( m_aProperties[aInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RelationsInfo" ) ) ) - { - if ( m_aProperties[aInd].Value >>= aResult ) - return aResult; - - break; - } - - throw io::IOException(); // the relations info could not be read -} - -//----------------------------------------------- -void SAL_CALL OInputCompStream::insertRelationshipByID( const ::rtl::OUString& /*sID*/, const uno::Sequence< beans::StringPair >& /*aEntry*/, ::sal_Bool /*bReplace*/ ) - throw ( container::ElementExistException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - throw io::IOException(); // TODO: Access denied -} - -//----------------------------------------------- -void SAL_CALL OInputCompStream::removeRelationshipByID( const ::rtl::OUString& /*sID*/ ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - throw io::IOException(); // TODO: Access denied -} - -//----------------------------------------------- -void SAL_CALL OInputCompStream::insertRelationships( const uno::Sequence< uno::Sequence< beans::StringPair > >& /*aEntries*/, ::sal_Bool /*bReplace*/ ) - throw ( container::ElementExistException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - throw io::IOException(); // TODO: Access denied -} - -//----------------------------------------------- -void SAL_CALL OInputCompStream::clearRelationships() - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - throw io::IOException(); // TODO: Access denied -} - -//----------------------------------------------- -uno::Reference< beans::XPropertySetInfo > SAL_CALL OInputCompStream::getPropertySetInfo() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - //TODO: - return uno::Reference< beans::XPropertySetInfo >(); -} - -//----------------------------------------------- -void SAL_CALL OInputCompStream::setPropertyValue( const ::rtl::OUString& aPropertyName, const uno::Any& /*aValue*/ ) - throw ( beans::UnknownPropertyException, - beans::PropertyVetoException, - lang::IllegalArgumentException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - // all the provided properties are accessible - for ( sal_Int32 aInd = 0; aInd < m_aProperties.getLength(); aInd++ ) - { - if ( m_aProperties[aInd].Name.equals( aPropertyName ) ) - { - throw beans::PropertyVetoException(); // TODO - } - } - - throw beans::UnknownPropertyException(); // TODO -} - - -//----------------------------------------------- -uno::Any SAL_CALL OInputCompStream::getPropertyValue( const ::rtl::OUString& aProp ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - ::rtl::OUString aPropertyName; - if ( aProp.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsEncrypted" ) ) ) - aPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Encrypted" ) ); - else - aPropertyName = aProp; - - if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RelationsInfo" ) ) ) - throw beans::UnknownPropertyException(); // TODO - - // all the provided properties are accessible - for ( sal_Int32 aInd = 0; aInd < m_aProperties.getLength(); aInd++ ) - { - if ( m_aProperties[aInd].Name.equals( aPropertyName ) ) - { - return m_aProperties[aInd].Value; - } - } - - throw beans::UnknownPropertyException(); // TODO -} - - -//----------------------------------------------- -void SAL_CALL OInputCompStream::addPropertyChangeListener( - const ::rtl::OUString& /*aPropertyName*/, - const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - //TODO: -} - - -//----------------------------------------------- -void SAL_CALL OInputCompStream::removePropertyChangeListener( - const ::rtl::OUString& /*aPropertyName*/, - const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - //TODO: -} - - -//----------------------------------------------- -void SAL_CALL OInputCompStream::addVetoableChangeListener( - const ::rtl::OUString& /*PropertyName*/, - const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - //TODO: -} - - -//----------------------------------------------- -void SAL_CALL OInputCompStream::removeVetoableChangeListener( - const ::rtl::OUString& /*PropertyName*/, - const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - //TODO: -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/ocompinstream.hxx b/package/source/xstor/ocompinstream.hxx deleted file mode 100644 index c585f18fc..000000000 --- a/package/source/xstor/ocompinstream.hxx +++ /dev/null @@ -1,130 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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. - * - ************************************************************************/ - -#ifndef _INPUTCOMPSTREAM_HXX_ -#define _INPUTCOMPSTREAM_HXX_ - -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/io/XStream.hpp> -#include <com/sun/star/lang/XComponent.hpp> -#include <com/sun/star/beans/XPropertySet.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/embed/XExtendedStorageStream.hpp> -#include <com/sun/star/embed/XRelationshipAccess.hpp> -#include <cppuhelper/implbase4.hxx> -#include <cppuhelper/interfacecontainer.h> - -#include "mutexholder.hxx" - -struct OWriteStream_Impl; - -class OInputCompStream : public cppu::WeakImplHelper4 < ::com::sun::star::io::XInputStream - ,::com::sun::star::embed::XExtendedStorageStream - ,::com::sun::star::embed::XRelationshipAccess - ,::com::sun::star::beans::XPropertySet > -{ -protected: - OWriteStream_Impl* m_pImpl; - - SotMutexHolderRef m_rMutexRef; - - ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > m_xStream; - - ::cppu::OInterfaceContainerHelper* m_pInterfaceContainer; - - ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue > m_aProperties; - - sal_Bool m_bDisposed; - - sal_Int32 m_nStorageType; - -public: - OInputCompStream( OWriteStream_Impl& pImpl, - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xStream, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps, - sal_Int32 nStorageType ); - - OInputCompStream( ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xStream, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps, - sal_Int32 nStorageType ); - - virtual ~OInputCompStream(); - - void InternalDispose(); - - // XInterface - virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& rType ) - throw( ::com::sun::star::uno::RuntimeException ); - - // XInputStream - virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL available( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL closeInput( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - //XStream - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( ) throw (::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL getOutputStream( ) throw (::com::sun::star::uno::RuntimeException); - - //XComponent - virtual void SAL_CALL dispose( ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); - - //XRelationshipAccess - virtual ::sal_Bool SAL_CALL hasByID( const ::rtl::OUString& sID ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::rtl::OUString SAL_CALL getTargetByID( const ::rtl::OUString& sID ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::rtl::OUString SAL_CALL getTypeByID( const ::rtl::OUString& sID ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > SAL_CALL getRelationshipByID( const ::rtl::OUString& sID ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > SAL_CALL getRelationshipsByType( const ::rtl::OUString& sType ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > SAL_CALL getAllRelationships( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL insertRelationshipByID( const ::rtl::OUString& sID, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aEntry, ::sal_Bool bReplace ) throw (::com::sun::star::container::ElementExistException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeRelationshipByID( const ::rtl::OUString& sID ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL insertRelationships( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > >& aEntries, ::sal_Bool bReplace ) throw (::com::sun::star::container::ElementExistException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL clearRelationships( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - //XPropertySet - virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() throw ( ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); - virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); - -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/ohierarchyholder.cxx b/package/source/xstor/ohierarchyholder.cxx deleted file mode 100644 index 250e4bb59..000000000 --- a/package/source/xstor/ohierarchyholder.cxx +++ /dev/null @@ -1,361 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <com/sun/star/uno/Reference.hxx> -#include <com/sun/star/embed/ElementModes.hpp> -#include <com/sun/star/embed/XHierarchicalStorageAccess2.hpp> -#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> - -#include "ohierarchyholder.hxx" - -using namespace ::com::sun::star; - -//=============================================== -// OHierarchyHolder_Impl -//=============================================== - -//----------------------------------------------- -uno::Reference< embed::XExtendedStorageStream > OHierarchyHolder_Impl::GetStreamHierarchically( sal_Int32 nStorageMode, OStringList_Impl& aListPath, sal_Int32 nStreamMode, const ::comphelper::SequenceAsHashMap& aEncryptionData ) -{ - uno::Reference< embed::XStorage > xOwnStor( m_xWeakOwnStorage.get(), uno::UNO_QUERY_THROW ); - - if ( !( nStorageMode & embed::ElementModes::WRITE ) && ( nStreamMode & embed::ElementModes::WRITE ) ) - throw io::IOException(); - - uno::Reference< embed::XExtendedStorageStream > xResult = - m_xChild->GetStreamHierarchically( nStorageMode, aListPath, nStreamMode, aEncryptionData ); - if ( !xResult.is() ) - throw uno::RuntimeException(); - - return xResult; -} - -//----------------------------------------------- -void OHierarchyHolder_Impl::RemoveStreamHierarchically( OStringList_Impl& aListPath ) -{ - uno::Reference< embed::XStorage > xOwnStor( m_xWeakOwnStorage.get(), uno::UNO_QUERY_THROW ); - - m_xChild->RemoveStreamHierarchically( aListPath ); -} - -//----------------------------------------------- -// static -OStringList_Impl OHierarchyHolder_Impl::GetListPathFromString( const ::rtl::OUString& aPath ) -{ - OStringList_Impl aResult; - sal_Int32 nIndex = 0; - do - { - ::rtl::OUString aName = aPath.getToken( 0, '/', nIndex ); - if ( !aName.getLength() ) - throw lang::IllegalArgumentException(); - - aResult.push_back( aName ); - } - while ( nIndex >= 0 ); - - return aResult; -} - -//=============================================== -// OHierarchyElement_Impl -//=============================================== - -//----------------------------------------------- -uno::Reference< embed::XExtendedStorageStream > OHierarchyElement_Impl::GetStreamHierarchically( sal_Int32 nStorageMode, OStringList_Impl& aListPath, sal_Int32 nStreamMode, const ::comphelper::SequenceAsHashMap& aEncryptionData ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !( nStorageMode & embed::ElementModes::WRITE ) && ( nStreamMode & embed::ElementModes::WRITE ) ) - throw io::IOException(); - - if ( !aListPath.size() ) - throw uno::RuntimeException(); - - ::rtl::OUString aNextName = *(aListPath.begin()); - aListPath.erase( aListPath.begin() ); - - uno::Reference< embed::XExtendedStorageStream > xResult; - - uno::Reference< embed::XStorage > xOwnStor = m_xOwnStorage.is() ? m_xOwnStorage - : uno::Reference< embed::XStorage >( m_xWeakOwnStorage.get(), uno::UNO_QUERY ); - if ( !xOwnStor.is() ) - throw uno::RuntimeException(); - - if ( !aListPath.size() ) - { - if ( !aEncryptionData.size() ) - { - uno::Reference< embed::XHierarchicalStorageAccess > xHStorage( xOwnStor, uno::UNO_QUERY_THROW ); - xResult = xHStorage->openStreamElementByHierarchicalName( aNextName, nStreamMode ); - } - else - { - uno::Reference< embed::XHierarchicalStorageAccess2 > xHStorage( xOwnStor, uno::UNO_QUERY_THROW ); - xResult = xHStorage->openEncryptedStreamByHierarchicalName( aNextName, nStreamMode, aEncryptionData.getAsConstNamedValueList() ); - } - - uno::Reference< embed::XTransactedObject > xTransact( xResult, uno::UNO_QUERY ); - if ( xTransact.is() ) - { - // the existance of the transacted object means that the stream is opened for writing also - // so the whole chain must be commited - uno::Reference< embed::XTransactionBroadcaster > xTrBroadcast( xTransact, uno::UNO_QUERY_THROW ); - xTrBroadcast->addTransactionListener( static_cast< embed::XTransactionListener* >( this ) ); - } - else - { - uno::Reference< lang::XComponent > xStreamComp( xResult, uno::UNO_QUERY_THROW ); - xStreamComp->addEventListener( static_cast< lang::XEventListener* >( this ) ); - } - - m_aOpenStreams.push_back( uno::WeakReference< embed::XExtendedStorageStream >( xResult ) ); - } - else - { - sal_Bool bNewElement = sal_False; - ::rtl::Reference< OHierarchyElement_Impl > aElement; - OHierarchyElementList_Impl::iterator aIter = m_aChildren.find( aNextName ); - if ( aIter != m_aChildren.end() ) - aElement = aIter->second; - - if ( !aElement.is() ) - { - bNewElement = sal_True; - uno::Reference< embed::XStorage > xChildStorage = xOwnStor->openStorageElement( aNextName, nStorageMode ); - if ( !xChildStorage.is() ) - throw uno::RuntimeException(); - - aElement = new OHierarchyElement_Impl( NULL, xChildStorage ); - } - - xResult = aElement->GetStreamHierarchically( nStorageMode, aListPath, nStreamMode, aEncryptionData ); - if ( !xResult.is() ) - throw uno::RuntimeException(); - - if ( bNewElement ) - { - m_aChildren[aNextName] = aElement; - aElement->SetParent( this ); - } - } - - // the subelement was opened successfuly, remember the storage to let it be locked - m_xOwnStorage = xOwnStor; - - return xResult; -} - -//----------------------------------------------- -void OHierarchyElement_Impl::RemoveStreamHierarchically( OStringList_Impl& aListPath ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !aListPath.size() ) - throw uno::RuntimeException(); - - ::rtl::OUString aNextName = *(aListPath.begin()); - aListPath.erase( aListPath.begin() ); - - uno::Reference< embed::XExtendedStorageStream > xResult; - - uno::Reference< embed::XStorage > xOwnStor = m_xOwnStorage.is() ? m_xOwnStorage - : uno::Reference< embed::XStorage >( m_xWeakOwnStorage.get(), uno::UNO_QUERY ); - if ( !xOwnStor.is() ) - throw uno::RuntimeException(); - - if ( !aListPath.size() ) - { - xOwnStor->removeElement( aNextName ); - } - else - { - ::rtl::Reference< OHierarchyElement_Impl > aElement; - OHierarchyElementList_Impl::iterator aIter = m_aChildren.find( aNextName ); - if ( aIter != m_aChildren.end() ) - aElement = aIter->second; - - if ( !aElement.is() ) - { - uno::Reference< embed::XStorage > xChildStorage = xOwnStor->openStorageElement( aNextName, - embed::ElementModes::READWRITE ); - if ( !xChildStorage.is() ) - throw uno::RuntimeException(); - - aElement = new OHierarchyElement_Impl( NULL, xChildStorage ); - } - - aElement->RemoveStreamHierarchically( aListPath ); - } - - uno::Reference< embed::XTransactedObject > xTransact( xOwnStor, uno::UNO_QUERY ); - if ( xTransact.is() ) - xTransact->commit(); - - TestForClosing(); -} - -//----------------------------------------------- -void OHierarchyElement_Impl::Commit() -{ - ::rtl::Reference< OHierarchyElement_Impl > aLocker( this ); - ::rtl::Reference< OHierarchyElement_Impl > aParent; - uno::Reference< embed::XStorage > xOwnStor; - - { - ::osl::MutexGuard aGuard( m_aMutex ); - aParent = m_rParent; - xOwnStor = m_xOwnStorage; - } - - if ( xOwnStor.is() ) - { - uno::Reference< embed::XTransactedObject > xTransact( xOwnStor, uno::UNO_QUERY_THROW ); - xTransact->commit(); - if ( aParent.is() ) - aParent->Commit(); - } -} - -//----------------------------------------------- -void OHierarchyElement_Impl::TestForClosing() -{ - ::rtl::Reference< OHierarchyElement_Impl > aLocker( this ); - { - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_aOpenStreams.size() && !m_aChildren.size() ) - { - if ( m_rParent.is() ) - { - // only the root storage should not be disposed, other storages can be disposed - if ( m_xOwnStorage.is() ) - { - try - { - m_xOwnStorage->dispose(); - } - catch( uno::Exception& ) - {} - } - - m_rParent->RemoveElement( this ); - } - - m_xOwnStorage = uno::Reference< embed::XStorage >(); - } - } -} - -//----------------------------------------------- -void SAL_CALL OHierarchyElement_Impl::disposing( const lang::EventObject& Source ) - throw ( uno::RuntimeException ) -{ - uno::Sequence< embed::XStorage > aStoragesToCommit; - - try - { - ::osl::ClearableMutexGuard aGuard( m_aMutex ); - uno::Reference< embed::XExtendedStorageStream > xStream( Source.Source, uno::UNO_QUERY ); - - for ( OWeakStorRefList_Impl::iterator pStorageIter = m_aOpenStreams.begin(); - pStorageIter != m_aOpenStreams.end(); ) - { - OWeakStorRefList_Impl::iterator pTmp = pStorageIter++; - if ( !pTmp->get().is() || pTmp->get() == xStream ) - m_aOpenStreams.erase( pTmp ); - } - - aGuard.clear(); - - TestForClosing(); - } - catch( uno::Exception& ) - { - throw uno::RuntimeException(); // no exception must happen here, usually an exception means disaster - } -} - -//----------------------------------------------- -void OHierarchyElement_Impl::RemoveElement( const ::rtl::Reference< OHierarchyElement_Impl >& aRef ) -{ - { - ::osl::MutexGuard aGuard( m_aMutex ); - for ( OHierarchyElementList_Impl::iterator aIter = m_aChildren.begin(); - aIter != m_aChildren.end(); /* increment is done in body */) - { - OHierarchyElementList_Impl::iterator aTmpIter = aIter; - aIter++; - - if ( aTmpIter->second == aRef ) - m_aChildren.erase( aTmpIter ); - } - } - - TestForClosing(); -} - -// XTransactionListener -//----------------------------------------------- -void SAL_CALL OHierarchyElement_Impl::preCommit( const ::com::sun::star::lang::EventObject& /*aEvent*/ ) - throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) -{ -} - -//----------------------------------------------- -void SAL_CALL OHierarchyElement_Impl::commited( const ::com::sun::star::lang::EventObject& /*aEvent*/ ) - throw (::com::sun::star::uno::RuntimeException) -{ - try - { - Commit(); - } - catch( uno::Exception& e ) - { - throw lang::WrappedTargetRuntimeException( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can not commit storage sequence!" ) ), - uno::Reference< uno::XInterface >(), - uno::makeAny( e ) ); - } -} - -//----------------------------------------------- -void SAL_CALL OHierarchyElement_Impl::preRevert( const ::com::sun::star::lang::EventObject& /*aEvent*/ ) - throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) -{ -} - -//----------------------------------------------- -void SAL_CALL OHierarchyElement_Impl::reverted( const ::com::sun::star::lang::EventObject& /*aEvent*/ ) - throw (::com::sun::star::uno::RuntimeException) -{ -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/ohierarchyholder.hxx b/package/source/xstor/ohierarchyholder.hxx deleted file mode 100644 index 9fffdc5af..000000000 --- a/package/source/xstor/ohierarchyholder.hxx +++ /dev/null @@ -1,143 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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. - * - ************************************************************************/ - -#ifndef _OHIERARCHYHOLDER_HXX_ -#define _OHIERARCHYHOLDER_HXX_ - -#include <com/sun/star/embed/XStorage.hpp> -#include <com/sun/star/embed/XTransactionListener.hpp> -#include <com/sun/star/embed/XExtendedStorageStream.hpp> -#include <cppuhelper/implbase1.hxx> - -#include <comphelper/sequenceashashmap.hxx> - -#include <rtl/ref.hxx> - -#include <boost/unordered_map.hpp> -#include <list> -#include <vector> - -struct OHierarchyElement_Impl; - -struct eqFunc -{ - sal_Bool operator()( const rtl::OUString &r1, - const rtl::OUString &r2) const - { - return r1 == r2; - } -}; -typedef ::boost::unordered_map< ::rtl::OUString, - ::rtl::Reference< OHierarchyElement_Impl >, - ::rtl::OUStringHash, - eqFunc > OHierarchyElementList_Impl; - -typedef ::std::vector< ::rtl::OUString > OStringList_Impl; -typedef ::std::list< ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XExtendedStorageStream > > - OWeakStorRefList_Impl; - -struct OHierarchyElement_Impl : public cppu::WeakImplHelper1< ::com::sun::star::embed::XTransactionListener > -{ - ::osl::Mutex m_aMutex; - - ::rtl::Reference< OHierarchyElement_Impl > m_rParent; - ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > m_xOwnStorage; - ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage > m_xWeakOwnStorage; - - OHierarchyElementList_Impl m_aChildren; - - OWeakStorRefList_Impl m_aOpenStreams; - -public: - OHierarchyElement_Impl( OHierarchyElement_Impl* pParent, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage ) - : m_rParent( pParent ) - , m_xOwnStorage( xStorage ) - {} - - OHierarchyElement_Impl( const ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage >& xWeakStorage ) - : m_rParent( NULL ) - , m_xWeakOwnStorage( xWeakStorage ) - {} - - void Commit(); - - void SetParent( const ::rtl::Reference< OHierarchyElement_Impl >& rParent ) { m_rParent = rParent; } - - void TestForClosing(); - - void RemoveElement( const ::rtl::Reference< OHierarchyElement_Impl >& aRef ); - - ::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream > - GetStreamHierarchically( sal_Int32 nStorageMode, - OStringList_Impl& aPath, - sal_Int32 nStreamMode, - const ::comphelper::SequenceAsHashMap& aEncryptionData = ::comphelper::SequenceAsHashMap() ); - - void RemoveStreamHierarchically( OStringList_Impl& aListPath ); - - // XEventListener - virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) - throw (::com::sun::star::uno::RuntimeException); - - - // XTransactionListener - virtual void SAL_CALL preCommit( const ::com::sun::star::lang::EventObject& aEvent ) - throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL commited( const ::com::sun::star::lang::EventObject& aEvent ) - throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL preRevert( const ::com::sun::star::lang::EventObject& aEvent ) - throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL reverted( const ::com::sun::star::lang::EventObject& aEvent ) - throw (::com::sun::star::uno::RuntimeException); - -}; - -class OHierarchyHolder_Impl : public ::cppu::OWeakObject -{ - ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage > m_xWeakOwnStorage; - ::rtl::Reference< OHierarchyElement_Impl > m_xChild; -public: - OHierarchyHolder_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xOwnStorage ) - : m_xWeakOwnStorage( xOwnStorage ) - , m_xChild( new OHierarchyElement_Impl( ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage >( xOwnStorage ) ) ) - {} - - static OStringList_Impl GetListPathFromString( const ::rtl::OUString& aPath ); - - ::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream > - GetStreamHierarchically( sal_Int32 nStorageMode, - OStringList_Impl& aListPath, - sal_Int32 nStreamMode, - const ::comphelper::SequenceAsHashMap& aEncryptionData = ::comphelper::SequenceAsHashMap() ); - - void RemoveStreamHierarchically( OStringList_Impl& aListPath ); -}; - -#endif // _OHIERARCHYHOLDER - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/oseekinstream.cxx b/package/source/xstor/oseekinstream.cxx deleted file mode 100644 index 229bba9eb..000000000 --- a/package/source/xstor/oseekinstream.cxx +++ /dev/null @@ -1,182 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <com/sun/star/lang/DisposedException.hpp> -#include <cppuhelper/typeprovider.hxx> -#include <osl/diagnose.h> - -#include "oseekinstream.hxx" -#include "owriteablestream.hxx" - -using namespace ::com::sun::star; - -OInputSeekStream::OInputSeekStream( OWriteStream_Impl& pImpl, - uno::Reference < io::XInputStream > xStream, - const uno::Sequence< beans::PropertyValue >& aProps, - sal_Int32 nStorageType ) -: OInputCompStream( pImpl, xStream, aProps, nStorageType ) -{ - if ( m_xStream.is() ) - { - m_xSeekable = uno::Reference< io::XSeekable >( m_xStream, uno::UNO_QUERY ); - OSL_ENSURE( m_xSeekable.is(), "No seeking support!\n" ); - } -} - -OInputSeekStream::OInputSeekStream( uno::Reference < io::XInputStream > xStream, - const uno::Sequence< beans::PropertyValue >& aProps, - sal_Int32 nStorageType ) -: OInputCompStream( xStream, aProps, nStorageType ) -{ - if ( m_xStream.is() ) - { - m_xSeekable = uno::Reference< io::XSeekable >( m_xStream, uno::UNO_QUERY ); - OSL_ENSURE( m_xSeekable.is(), "No seeking support!\n" ); - } -} - -OInputSeekStream::~OInputSeekStream() -{ -} - -uno::Sequence< uno::Type > SAL_CALL OInputSeekStream::getTypes() - throw ( uno::RuntimeException ) -{ - static ::cppu::OTypeCollection* pTypeCollection = NULL ; - - if ( pTypeCollection == NULL ) - { - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - if ( pTypeCollection == NULL ) - { - static ::cppu::OTypeCollection aTypeCollection( - ::getCppuType(( const uno::Reference< io::XSeekable >* )NULL ), - OInputCompStream::getTypes() ); - - pTypeCollection = &aTypeCollection ; - } - } - - return pTypeCollection->getTypes() ; -} - -uno::Any SAL_CALL OInputSeekStream::queryInterface( const uno::Type& rType ) - throw( uno::RuntimeException ) -{ - // Attention: - // Don't use mutex or guard in this method!!! Is a method of XInterface. - - uno::Any aReturn( ::cppu::queryInterface( rType, - static_cast< io::XSeekable* >( this ) ) ); - - if ( aReturn.hasValue() == sal_True ) - { - return aReturn ; - } - - return OInputCompStream::queryInterface( rType ) ; -} - -void SAL_CALL OInputSeekStream::acquire() - throw() -{ - OInputCompStream::acquire(); -} - -void SAL_CALL OInputSeekStream::release() - throw() -{ - OInputCompStream::release(); -} - - -void SAL_CALL OInputSeekStream::seek( sal_Int64 location ) - throw ( lang::IllegalArgumentException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xSeekable.is() ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No seekable!" ) ) ); - throw uno::RuntimeException(); - } - - m_xSeekable->seek( location ); -} - -sal_Int64 SAL_CALL OInputSeekStream::getPosition() - throw ( io::IOException, - uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xSeekable.is() ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No seekable!" ) ) ); - throw uno::RuntimeException(); - } - - return m_xSeekable->getPosition(); -} - -sal_Int64 SAL_CALL OInputSeekStream::getLength() - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_bDisposed ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xSeekable.is() ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No seekable!" ) ) ); - throw uno::RuntimeException(); - } - - return m_xSeekable->getLength(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/oseekinstream.hxx b/package/source/xstor/oseekinstream.hxx deleted file mode 100644 index b605d25e8..000000000 --- a/package/source/xstor/oseekinstream.hxx +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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. - * - ************************************************************************/ - -#ifndef _INPUTSEEKSTREAM_HXX_ -#define _INPUTSEEKSTREAM_HXX_ - -#include <com/sun/star/io/XSeekable.hpp> - -#include "ocompinstream.hxx" - -class OInputSeekStream : public OInputCompStream - , public ::com::sun::star::io::XSeekable -{ -protected: - ::com::sun::star::uno::Reference < ::com::sun::star::io::XSeekable > m_xSeekable; - -public: - OInputSeekStream( OWriteStream_Impl& pImpl, - ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > xStream, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps, - sal_Int32 nStorageType ); - - OInputSeekStream( ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > xStream, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps, - sal_Int32 nStorageType ); - - virtual ~OInputSeekStream(); - - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException); - - // XInterface - virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& rType ) throw( ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL acquire() throw(); - virtual void SAL_CALL release() throw(); - - //XSeekable - virtual void SAL_CALL seek( sal_Int64 location ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getPosition() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getLength() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/owriteablestream.cxx b/package/source/xstor/owriteablestream.cxx deleted file mode 100644 index 2c94e3c8a..000000000 --- a/package/source/xstor/owriteablestream.cxx +++ /dev/null @@ -1,3623 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <com/sun/star/ucb/XSimpleFileAccess.hpp> -#include <com/sun/star/ucb/XCommandEnvironment.hpp> -#include <com/sun/star/lang/DisposedException.hpp> -#include <com/sun/star/lang/XUnoTunnel.hpp> -#include <com/sun/star/lang/XTypeProvider.hpp> -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/io/IOException.hpp> -#include <com/sun/star/embed/ElementModes.hpp> -#include <com/sun/star/embed/StorageFormats.hpp> -#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> -#include <cppuhelper/typeprovider.hxx> -#include <cppuhelper/exc_hlp.hxx> -#include <osl/diagnose.h> - -#include <comphelper/processfactory.hxx> -#include <comphelper/componentcontext.hxx> -#include <comphelper/storagehelper.hxx> -#include <comphelper/ofopxmlhelper.hxx> - -#include <rtl/digest.h> -#include <rtl/logfile.hxx> -#include <rtl/instance.hxx> - -#include <PackageConstants.hxx> -#include <mutexholder.hxx> - -#include "selfterminatefilestream.hxx" -#include "owriteablestream.hxx" -#include "oseekinstream.hxx" -#include "xstorage.hxx" - -// since the copying uses 32000 blocks usually, it makes sense to have a smaller size -#define MAX_STORCACHE_SIZE 30000 - - -using namespace ::com::sun::star; - -namespace package -{ -//----------------------------------------------- -bool PackageEncryptionDatasEqual( const ::comphelper::SequenceAsHashMap& aHash1, const ::comphelper::SequenceAsHashMap& aHash2 ) -{ - bool bResult = ( aHash1.size() && aHash1.size() == aHash2.size() ); - for ( ::comphelper::SequenceAsHashMap::const_iterator aIter = aHash1.begin(); - bResult && aIter != aHash1.end(); - aIter++ ) - { - uno::Sequence< sal_Int8 > aKey1; - bResult = ( ( aIter->second >>= aKey1 ) && aKey1.getLength() ); - if ( bResult ) - { - uno::Sequence< sal_Int8 > aKey2 = aHash2.getUnpackedValueOrDefault( aIter->first, uno::Sequence< sal_Int8 >() ); - bResult = ( aKey1.getLength() == aKey2.getLength() ); - for ( sal_Int32 nInd = 0; bResult && nInd < aKey1.getLength(); nInd++ ) - bResult = ( aKey1[nInd] == aKey2[nInd] ); - } - } - - return bResult; -} - -//----------------------------------------------- -void StaticAddLog( const ::rtl::OUString& aMessage ) -{ - try - { - ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); - if ( aContext.is() ) - { - uno::Reference< logging::XSimpleLogRing > xLogRing( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), uno::UNO_QUERY_THROW ); - xLogRing->logString( aMessage ); - } - } - catch( const uno::Exception& ) - { - // No log - } -} -} // namespace package - -// ================================================================ -namespace -{ -//----------------------------------------------- -void SetEncryptionKeyProperty_Impl( const uno::Reference< beans::XPropertySet >& xPropertySet, - const uno::Sequence< beans::NamedValue >& aKey ) -{ - OSL_ENSURE( xPropertySet.is(), "No property set is provided!\n" ); - if ( !xPropertySet.is() ) - throw uno::RuntimeException(); - - try { - xPropertySet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ), uno::makeAny( aKey ) ); - } - catch ( const uno::Exception& rException ) - { - ::package::StaticAddLog( rException.Message ); - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't set encryption") ) ); - OSL_FAIL( "Can't write encryption related properties!\n" ); - throw io::IOException(); // TODO - } -} - -//----------------------------------------------- -uno::Any GetEncryptionKeyProperty_Impl( const uno::Reference< beans::XPropertySet >& xPropertySet ) -{ - OSL_ENSURE( xPropertySet.is(), "No property set is provided!\n" ); - if ( !xPropertySet.is() ) - throw uno::RuntimeException(); - - try { - return xPropertySet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) ); - } - catch ( const uno::Exception& rException ) - { - ::package::StaticAddLog( rException.Message ); - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't get encryption property" ) ) ); - - OSL_FAIL( "Can't get encryption related properties!\n" ); - throw io::IOException(); // TODO - } -} - -//----------------------------------------------- -bool SequencesEqual( const uno::Sequence< sal_Int8 >& aSequence1, const uno::Sequence< sal_Int8 >& aSequence2 ) -{ - if ( aSequence1.getLength() != aSequence2.getLength() ) - return false; - - for ( sal_Int32 nInd = 0; nInd < aSequence1.getLength(); nInd++ ) - if ( aSequence1[nInd] != aSequence2[nInd] ) - return false; - - return true; -} - -//----------------------------------------------- -bool SequencesEqual( const uno::Sequence< beans::NamedValue >& aSequence1, const uno::Sequence< beans::NamedValue >& aSequence2 ) -{ - if ( aSequence1.getLength() != aSequence2.getLength() ) - return false; - - for ( sal_Int32 nInd = 0; nInd < aSequence1.getLength(); nInd++ ) - { - bool bHasMember = false; - uno::Sequence< sal_Int8 > aMember1; - sal_Int32 nMember1 = 0; - if ( ( aSequence1[nInd].Value >>= aMember1 ) ) - { - for ( sal_Int32 nInd2 = 0; nInd2 < aSequence2.getLength(); nInd2++ ) - { - if ( aSequence1[nInd].Name.equals( aSequence2[nInd2].Name ) ) - { - bHasMember = true; - - uno::Sequence< sal_Int8 > aMember2; - if ( !( aSequence2[nInd2].Value >>= aMember2 ) || !SequencesEqual( aMember1, aMember2 ) ) - return false; - } - } - } - else if ( ( aSequence1[nInd].Value >>= nMember1 ) ) - { - for ( sal_Int32 nInd2 = 0; nInd2 < aSequence2.getLength(); nInd2++ ) - { - if ( aSequence1[nInd].Name.equals( aSequence2[nInd2].Name ) ) - { - bHasMember = true; - - sal_Int32 nMember2 = 0; - if ( !( aSequence2[nInd2].Value >>= nMember2 ) || nMember1 != nMember2 ) - return false; - } - } - } - else - return false; - - if ( !bHasMember ) - return false; - } - - return true; -} - -//----------------------------------------------- -sal_Bool KillFile( const ::rtl::OUString& aURL, const uno::Reference< lang::XMultiServiceFactory >& xFactory ) -{ - if ( !xFactory.is() ) - return sal_False; - - sal_Bool bRet = sal_False; - - try - { - uno::Reference < ucb::XSimpleFileAccess > xAccess( - xFactory->createInstance ( - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess" ) ) ), - uno::UNO_QUERY ); - - if ( xAccess.is() ) - { - xAccess->kill( aURL ); - bRet = sal_True; - } - } - catch( const uno::Exception& rException ) - { - ::package::StaticAddLog( rException.Message ); - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception") ) ); - } - - return bRet; -} - -const sal_Int32 n_ConstBufferSize = 32000; - -//----------------------------------------------- -::rtl::OUString GetNewTempFileURL( const uno::Reference< lang::XMultiServiceFactory > xFactory ) -{ - ::rtl::OUString aTempURL; - - uno::Reference < beans::XPropertySet > xTempFile( - xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.TempFile") ) ), - uno::UNO_QUERY ); - - if ( !xTempFile.is() ) - throw uno::RuntimeException(); // TODO - - try { - xTempFile->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RemoveFile") ), uno::makeAny( sal_False ) ); - uno::Any aUrl = xTempFile->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Uri") ) ); - aUrl >>= aTempURL; - } - catch ( const uno::Exception& rException ) - { - ::package::StaticAddLog( rException.Message ); - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception") ) ); - } - - if ( !aTempURL.getLength() ) - throw uno::RuntimeException(); // TODO: can not create tempfile - - return aTempURL; -} - -//----------------------------------------------- -uno::Reference< io::XStream > CreateMemoryStream( const uno::Reference< lang::XMultiServiceFactory >& xFactory ) -{ - if ( !xFactory.is() ) - throw uno::RuntimeException(); - - return uno::Reference< io::XStream >( xFactory->createInstance (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.MemoryStream") ) ), uno::UNO_QUERY_THROW); -} - -} // anonymous namespace -// ================================================================ - -//----------------------------------------------- -OWriteStream_Impl::OWriteStream_Impl( OStorage_Impl* pParent, - const uno::Reference< packages::XDataSinkEncrSupport >& xPackageStream, - const uno::Reference< lang::XSingleServiceFactory >& xPackage, - const uno::Reference< lang::XMultiServiceFactory >& xFactory, - sal_Bool bForceEncrypted, - sal_Int32 nStorageType, - sal_Bool bDefaultCompress, - const uno::Reference< io::XInputStream >& xRelInfoStream ) -: m_pAntiImpl( NULL ) -, m_bHasDataToFlush( sal_False ) -, m_bFlushed( sal_False ) -, m_xPackageStream( xPackageStream ) -, m_xFactory( xFactory ) -, m_pParent( pParent ) -, m_bForceEncrypted( bForceEncrypted ) -, m_bUseCommonEncryption( !bForceEncrypted && nStorageType == embed::StorageFormats::PACKAGE ) -, m_bHasCachedEncryptionData( sal_False ) -, m_bCompressedSetExplicit( !bDefaultCompress ) -, m_xPackage( xPackage ) -, m_bHasInsertedStreamOptimization( sal_False ) -, m_nStorageType( nStorageType ) -, m_xOrigRelInfoStream( xRelInfoStream ) -, m_bOrigRelInfoBroken( sal_False ) -, m_nRelInfoStatus( RELINFO_NO_INIT ) -, m_nRelId( 1 ) -{ - OSL_ENSURE( xPackageStream.is(), "No package stream is provided!\n" ); - OSL_ENSURE( xPackage.is(), "No package component is provided!\n" ); - OSL_ENSURE( m_xFactory.is(), "No package stream is provided!\n" ); - OSL_ENSURE( pParent, "No parent storage is provided!\n" ); - OSL_ENSURE( m_nStorageType == embed::StorageFormats::OFOPXML || !m_xOrigRelInfoStream.is(), "The Relations info makes sence only for OFOPXML format!\n" ); -} - -//----------------------------------------------- -OWriteStream_Impl::~OWriteStream_Impl() -{ - DisposeWrappers(); - - if ( m_aTempURL.getLength() ) - { - KillFile( m_aTempURL, GetServiceFactory() ); - m_aTempURL = ::rtl::OUString(); - } - - CleanCacheStream(); -} - -//----------------------------------------------- -void OWriteStream_Impl::CleanCacheStream() -{ - if ( m_xCacheStream.is() ) - { - try - { - uno::Reference< io::XInputStream > xInputCache = m_xCacheStream->getInputStream(); - if ( xInputCache.is() ) - xInputCache->closeInput(); - } - catch( const uno::Exception& ) - {} - - try - { - uno::Reference< io::XOutputStream > xOutputCache = m_xCacheStream->getOutputStream(); - if ( xOutputCache.is() ) - xOutputCache->closeOutput(); - } - catch( const uno::Exception& ) - {} - - m_xCacheStream = uno::Reference< io::XStream >(); - m_xCacheSeek = uno::Reference< io::XSeekable >(); - } -} - -//----------------------------------------------- -void OWriteStream_Impl::AddLog( const ::rtl::OUString& aMessage ) -{ - if ( !m_xLogRing.is() ) - { - try - { - ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); - if ( aContext.is() ) - m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), uno::UNO_QUERY_THROW ); - } - catch( const uno::Exception& ) - { - // No log - } - } - - if ( m_xLogRing.is() ) - m_xLogRing->logString( aMessage ); -} - - -//----------------------------------------------- -void OWriteStream_Impl::InsertIntoPackageFolder( const ::rtl::OUString& aName, - const uno::Reference< container::XNameContainer >& xParentPackageFolder ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - OSL_ENSURE( m_bFlushed, "This method must not be called for nonflushed streams!\n" ); - if ( m_bFlushed ) - { - OSL_ENSURE( m_xPackageStream.is(), "An inserted stream is incomplete!\n" ); - uno::Reference< lang::XUnoTunnel > xTunnel( m_xPackageStream, uno::UNO_QUERY ); - if ( !xTunnel.is() ) - throw uno::RuntimeException(); // TODO - - xParentPackageFolder->insertByName( aName, uno::makeAny( xTunnel ) ); - - m_bFlushed = sal_False; - m_bHasInsertedStreamOptimization = sal_False; - } -} -//----------------------------------------------- -sal_Bool OWriteStream_Impl::IsEncrypted() -{ - if ( m_nStorageType != embed::StorageFormats::PACKAGE ) - return sal_False; - - if ( m_bForceEncrypted || m_bHasCachedEncryptionData ) - return sal_True; - - if ( m_aTempURL.getLength() || m_xCacheStream.is() ) - return sal_False; - - GetStreamProperties(); - - // the following value can not be cached since it can change after root commit - sal_Bool bWasEncr = sal_False; - uno::Reference< beans::XPropertySet > xPropSet( m_xPackageStream, uno::UNO_QUERY ); - if ( xPropSet.is() ) - { - uno::Any aValue = xPropSet->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("WasEncrypted") ) ); - if ( !( aValue >>= bWasEncr ) ) - { - OSL_FAIL( "The property WasEncrypted has wrong type!\n" ); - } - } - - sal_Bool bToBeEncr = sal_False; - for ( sal_Int32 nInd = 0; nInd < m_aProps.getLength(); nInd++ ) - { - if ( m_aProps[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Encrypted" ) ) ) - { - if ( !( m_aProps[nInd].Value >>= bToBeEncr ) ) - { - OSL_FAIL( "The property has wrong type!\n" ); - } - } - } - - // since a new key set to the package stream it should not be removed except the case when - // the stream becomes nonencrypted - uno::Sequence< beans::NamedValue > aKey; - if ( bToBeEncr ) - GetEncryptionKeyProperty_Impl( xPropSet ) >>= aKey; - - // If the properties must be investigated the stream is either - // was never changed or was changed, the parent was commited - // and the stream was closed. - // That means that if it is intended to use common storage key - // it is already has no encryption but is marked to be stored - // encrypted and the key is empty. - if ( !bWasEncr && bToBeEncr && !aKey.getLength() ) - { - // the stream is intended to use common storage password - m_bUseCommonEncryption = sal_True; - return sal_False; - } - else - return bToBeEncr; -} - -//----------------------------------------------- -void OWriteStream_Impl::SetDecrypted() -{ - OSL_ENSURE( m_nStorageType == embed::StorageFormats::PACKAGE, "The encryption is supported only for package storages!\n" ); - if ( m_nStorageType != embed::StorageFormats::PACKAGE ) - throw uno::RuntimeException(); - - GetStreamProperties(); - - // let the stream be modified - FillTempGetFileName(); - m_bHasDataToFlush = sal_True; - - // remove encryption - m_bForceEncrypted = sal_False; - m_bHasCachedEncryptionData = sal_False; - m_aEncryptionData.clear(); - - for ( sal_Int32 nInd = 0; nInd < m_aProps.getLength(); nInd++ ) - { - if ( m_aProps[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Encrypted" ) ) ) - m_aProps[nInd].Value <<= sal_False; - } -} - -//----------------------------------------------- -void OWriteStream_Impl::SetEncrypted( const ::comphelper::SequenceAsHashMap& aEncryptionData ) -{ - OSL_ENSURE( m_nStorageType == embed::StorageFormats::PACKAGE, "The encryption is supported only for package storages!\n" ); - if ( m_nStorageType != embed::StorageFormats::PACKAGE ) - throw uno::RuntimeException(); - - if ( !aEncryptionData.size() ) - throw uno::RuntimeException(); - - GetStreamProperties(); - - // let the stream be modified - FillTempGetFileName(); - m_bHasDataToFlush = sal_True; - - // introduce encryption info - for ( sal_Int32 nInd = 0; nInd < m_aProps.getLength(); nInd++ ) - { - if ( m_aProps[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Encrypted" ) ) ) - m_aProps[nInd].Value <<= sal_True; - } - - m_bUseCommonEncryption = sal_False; // very important to set it to false - - m_bHasCachedEncryptionData = sal_True; - m_aEncryptionData = aEncryptionData; -} - -//----------------------------------------------- -void OWriteStream_Impl::DisposeWrappers() -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_pAntiImpl ) - { - try { - m_pAntiImpl->dispose(); - } - catch ( const uno::RuntimeException& rRuntimeException ) - { - AddLog( rRuntimeException.Message ); - AddLog( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(OSL_LOG_PREFIX "Quiet exception") ) ); - } - - m_pAntiImpl = NULL; - } - m_pParent = NULL; - - if ( !m_aInputStreamsList.empty() ) - { - for ( InputStreamsList_Impl::iterator pStreamIter = m_aInputStreamsList.begin(); - pStreamIter != m_aInputStreamsList.end(); pStreamIter++ ) - { - if ( (*pStreamIter) ) - { - (*pStreamIter)->InternalDispose(); - (*pStreamIter) = NULL; - } - } - - m_aInputStreamsList.clear(); - } -} - -//----------------------------------------------- -uno::Reference< lang::XMultiServiceFactory > OWriteStream_Impl::GetServiceFactory() -{ - if ( m_xFactory.is() ) - return m_xFactory; - - return ::comphelper::getProcessServiceFactory(); -} - -//----------------------------------------------- -::rtl::OUString OWriteStream_Impl::GetFilledTempFileIfNo( const uno::Reference< io::XInputStream >& xStream ) -{ - if ( !m_aTempURL.getLength() ) - { - ::rtl::OUString aTempURL = GetNewTempFileURL( GetServiceFactory() ); - - try { - if ( aTempURL.getLength() && xStream.is() ) - { - uno::Reference < ucb::XSimpleFileAccess > xTempAccess( - GetServiceFactory()->createInstance ( - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess") ) ), - uno::UNO_QUERY ); - - if ( !xTempAccess.is() ) - throw uno::RuntimeException(); // TODO: - - uno::Reference< io::XOutputStream > xTempOutStream = xTempAccess->openFileWrite( aTempURL ); - if ( xTempOutStream.is() ) - { - // the current position of the original stream should be still OK, copy further - ::comphelper::OStorageHelper::CopyInputToOutput( xStream, xTempOutStream ); - xTempOutStream->closeOutput(); - xTempOutStream = uno::Reference< io::XOutputStream >(); - } - else - throw io::IOException(); // TODO: - } - } - catch( const packages::WrongPasswordException& rWrongPasswordException ) - { - AddLog( rWrongPasswordException.Message ); - AddLog( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow") ) ); - - KillFile( aTempURL, GetServiceFactory() ); - throw; - } - catch( const uno::Exception& rException ) - { - AddLog( rException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow") ) ); - - KillFile( aTempURL, GetServiceFactory() ); - throw; - } - - if ( aTempURL.getLength() ) - CleanCacheStream(); - - m_aTempURL = aTempURL; - } - - return m_aTempURL; -} - -//----------------------------------------------- -::rtl::OUString OWriteStream_Impl::FillTempGetFileName() -{ - // should try to create cache first, if the amount of contents is too big, the temp file should be taken - if ( !m_xCacheStream.is() && !m_aTempURL.getLength() ) - { - uno::Reference< io::XInputStream > xOrigStream = m_xPackageStream->getDataStream(); - if ( !xOrigStream.is() ) - { - // in case of new inserted package stream it is possible that input stream still was not set - uno::Reference< io::XStream > xCacheStream = CreateMemoryStream( GetServiceFactory() ); - OSL_ENSURE( xCacheStream.is(), "If the stream can not be created an exception must be thrown!\n" ); - m_xCacheSeek.set( xCacheStream, uno::UNO_QUERY_THROW ); - m_xCacheStream = xCacheStream; - } - else - { - sal_Int32 nRead = 0; - uno::Sequence< sal_Int8 > aData( MAX_STORCACHE_SIZE + 1 ); - nRead = xOrigStream->readBytes( aData, MAX_STORCACHE_SIZE + 1 ); - if ( aData.getLength() > nRead ) - aData.realloc( nRead ); - - if ( nRead <= MAX_STORCACHE_SIZE ) - { - uno::Reference< io::XStream > xCacheStream = CreateMemoryStream( GetServiceFactory() ); - OSL_ENSURE( xCacheStream.is(), "If the stream can not be created an exception must be thrown!\n" ); - - if ( nRead ) - { - uno::Reference< io::XOutputStream > xOutStream( xCacheStream->getOutputStream(), uno::UNO_SET_THROW ); - xOutStream->writeBytes( aData ); - } - m_xCacheSeek.set( xCacheStream, uno::UNO_QUERY_THROW ); - m_xCacheStream = xCacheStream; - m_xCacheSeek->seek( 0 ); - } - else if ( !m_aTempURL.getLength() ) - { - m_aTempURL = GetNewTempFileURL( GetServiceFactory() ); - - try { - if ( m_aTempURL.getLength() ) - { - uno::Reference < ucb::XSimpleFileAccess > xTempAccess( - GetServiceFactory()->createInstance ( - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess") ) ), - uno::UNO_QUERY ); - - if ( !xTempAccess.is() ) - throw uno::RuntimeException(); // TODO: - - - uno::Reference< io::XOutputStream > xTempOutStream = xTempAccess->openFileWrite( m_aTempURL ); - if ( xTempOutStream.is() ) - { - // copy stream contents to the file - xTempOutStream->writeBytes( aData ); - - // the current position of the original stream should be still OK, copy further - ::comphelper::OStorageHelper::CopyInputToOutput( xOrigStream, xTempOutStream ); - xTempOutStream->closeOutput(); - xTempOutStream = uno::Reference< io::XOutputStream >(); - } - else - throw io::IOException(); // TODO: - } - } - catch( const packages::WrongPasswordException& ) - { - KillFile( m_aTempURL, GetServiceFactory() ); - m_aTempURL = ::rtl::OUString(); - - throw; - } - catch( const uno::Exception& ) - { - KillFile( m_aTempURL, GetServiceFactory() ); - m_aTempURL = ::rtl::OUString(); - } - } - } - } - - return m_aTempURL; -} - -//----------------------------------------------- -uno::Reference< io::XStream > OWriteStream_Impl::GetTempFileAsStream() -{ - uno::Reference< io::XStream > xTempStream; - - if ( !m_xCacheStream.is() ) - { - if ( !m_aTempURL.getLength() ) - m_aTempURL = FillTempGetFileName(); - - if ( m_aTempURL.getLength() ) - { - // the temporary file is not used if the cache is used - uno::Reference < ucb::XSimpleFileAccess > xTempAccess( - GetServiceFactory()->createInstance ( - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess") ) ), - uno::UNO_QUERY ); - - if ( !xTempAccess.is() ) - throw uno::RuntimeException(); // TODO: - - try - { - xTempStream = xTempAccess->openFileReadWrite( m_aTempURL ); - } - catch( const uno::Exception& rException ) - { - AddLog( rException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - } - } - } - - if ( m_xCacheStream.is() ) - xTempStream = m_xCacheStream; - - // the method must always return a stream - // in case the stream can not be open - // an exception should be thrown - if ( !xTempStream.is() ) - throw io::IOException(); //TODO: - - return xTempStream; -} - -//----------------------------------------------- -uno::Reference< io::XInputStream > OWriteStream_Impl::GetTempFileAsInputStream() -{ - uno::Reference< io::XInputStream > xInputStream; - - if ( !m_xCacheStream.is() ) - { - if ( !m_aTempURL.getLength() ) - m_aTempURL = FillTempGetFileName(); - - if ( m_aTempURL.getLength() ) - { - // the temporary file is not used if the cache is used - uno::Reference < ucb::XSimpleFileAccess > xTempAccess( - GetServiceFactory()->createInstance ( - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess") ) ), - uno::UNO_QUERY ); - - if ( !xTempAccess.is() ) - throw uno::RuntimeException(); // TODO: - - try - { - xInputStream = xTempAccess->openFileRead( m_aTempURL ); - } - catch( const uno::Exception& rException ) - { - AddLog( rException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - } - } - } - - if ( m_xCacheStream.is() ) - xInputStream = m_xCacheStream->getInputStream(); - - // the method must always return a stream - // in case the stream can not be open - // an exception should be thrown - if ( !xInputStream.is() ) - throw io::IOException(); // TODO: - - return xInputStream; -} - -// ================================================================================================= - -//----------------------------------------------- -void OWriteStream_Impl::InsertStreamDirectly( const uno::Reference< io::XInputStream >& xInStream, - const uno::Sequence< beans::PropertyValue >& aProps ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - // this call can be made only during parent storage commit - // the parent storage is responsible for the correct handling - // of deleted and renamed contents - - OSL_ENSURE( m_xPackageStream.is(), "No package stream is set!\n" ); - - if ( m_bHasDataToFlush ) - throw io::IOException(); - - OSL_ENSURE( !m_aTempURL.getLength() && !m_xCacheStream.is(), "The temporary must not exist!\n" ); - - // use new file as current persistent representation - // the new file will be removed after it's stream is closed - m_xPackageStream->setDataStream( xInStream ); - - // copy properties to the package stream - uno::Reference< beans::XPropertySet > xPropertySet( m_xPackageStream, uno::UNO_QUERY ); - if ( !xPropertySet.is() ) - throw uno::RuntimeException(); - - // The storage-package communication has a problem - // the storage caches properties, thus if the package changes one of them itself - // the storage does not know about it - - // Depending from MediaType value the package can change the compressed property itself - // Thus if Compressed property is provided it must be set as the latest one - sal_Bool bCompressedIsSet = sal_False; - sal_Bool bCompressed = sal_False; - ::rtl::OUString aComprPropName( RTL_CONSTASCII_USTRINGPARAM( "Compressed" ) ); - ::rtl::OUString aMedTypePropName( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ); - for ( sal_Int32 nInd = 0; nInd < aProps.getLength(); nInd++ ) - { - if ( aProps[nInd].Name.equals( aComprPropName ) ) - { - bCompressedIsSet = sal_True; - aProps[nInd].Value >>= bCompressed; - } - else if ( ( m_nStorageType == embed::StorageFormats::OFOPXML || m_nStorageType == embed::StorageFormats::PACKAGE ) - && aProps[nInd].Name.equals( aMedTypePropName ) ) - { - xPropertySet->setPropertyValue( aProps[nInd].Name, aProps[nInd].Value ); - } - else if ( m_nStorageType == embed::StorageFormats::PACKAGE && aProps[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "UseCommonStoragePasswordEncryption" ) ) ) - aProps[nInd].Value >>= m_bUseCommonEncryption; - else - throw lang::IllegalArgumentException(); - - // if there are cached properties update them - if ( aProps[nInd].Name.equals( aMedTypePropName ) || aProps[nInd].Name.equals( aComprPropName ) ) - for ( sal_Int32 nMemInd = 0; nMemInd < m_aProps.getLength(); nMemInd++ ) - { - if ( aProps[nInd].Name.equals( m_aProps[nMemInd].Name ) ) - m_aProps[nMemInd].Value = aProps[nInd].Value; - } - } - - if ( bCompressedIsSet ) - { - xPropertySet->setPropertyValue( aComprPropName, uno::makeAny( (sal_Bool)bCompressed ) ); - m_bCompressedSetExplicit = sal_True; - } - - if ( m_bUseCommonEncryption ) - { - if ( m_nStorageType != embed::StorageFormats::PACKAGE ) - throw uno::RuntimeException(); - - // set to be encrypted but do not use encryption key - xPropertySet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ), - uno::makeAny( uno::Sequence< beans::NamedValue >() ) ); - xPropertySet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Encrypted") ), - uno::makeAny( sal_True ) ); - } - - // the stream should be free soon, after package is stored - m_bHasDataToFlush = sal_False; - m_bFlushed = sal_True; // will allow to use transaction on stream level if will need it - m_bHasInsertedStreamOptimization = sal_True; -} - -//----------------------------------------------- -void OWriteStream_Impl::Commit() -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - OSL_ENSURE( m_xPackageStream.is(), "No package stream is set!\n" ); - - if ( !m_bHasDataToFlush ) - return; - - uno::Reference< packages::XDataSinkEncrSupport > xNewPackageStream; - uno::Sequence< uno::Any > aSeq( 1 ); - aSeq[0] <<= sal_False; - - if ( m_xCacheStream.is() ) - { - if ( m_pAntiImpl ) - m_pAntiImpl->DeInit(); - - uno::Reference< io::XInputStream > xInStream( m_xCacheStream->getInputStream(), uno::UNO_SET_THROW ); - - xNewPackageStream = uno::Reference< packages::XDataSinkEncrSupport >( - m_xPackage->createInstanceWithArguments( aSeq ), - uno::UNO_QUERY_THROW ); - - xNewPackageStream->setDataStream( xInStream ); - - m_xCacheStream = uno::Reference< io::XStream >(); - m_xCacheSeek = uno::Reference< io::XSeekable >(); - - } - else if ( m_aTempURL.getLength() ) - { - if ( m_pAntiImpl ) - m_pAntiImpl->DeInit(); - - uno::Reference< io::XInputStream > xInStream; - try - { - xInStream.set( static_cast< io::XInputStream* >( new OSelfTerminateFileStream( GetServiceFactory(), m_aTempURL ) ), uno::UNO_QUERY ); - } - catch( const uno::Exception& ) - { - } - - if ( !xInStream.is() ) - throw io::IOException(); - - xNewPackageStream = uno::Reference< packages::XDataSinkEncrSupport >( - m_xPackage->createInstanceWithArguments( aSeq ), - uno::UNO_QUERY_THROW ); - - // TODO/NEW: Let the temporary file be removed after commit - xNewPackageStream->setDataStream( xInStream ); - m_aTempURL = ::rtl::OUString(); - } - else // if ( m_bHasInsertedStreamOptimization ) - { - // if the optimization is used the stream can be accessed directly - xNewPackageStream = m_xPackageStream; - } - - // copy properties to the package stream - uno::Reference< beans::XPropertySet > xPropertySet( xNewPackageStream, uno::UNO_QUERY ); - if ( !xPropertySet.is() ) - throw uno::RuntimeException(); - - for ( sal_Int32 nInd = 0; nInd < m_aProps.getLength(); nInd++ ) - { - if ( m_aProps[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Size" ) ) ) - { - if ( m_pAntiImpl && !m_bHasInsertedStreamOptimization && m_pAntiImpl->m_xSeekable.is() ) - { - m_aProps[nInd].Value <<= ((sal_Int32)m_pAntiImpl->m_xSeekable->getLength()); - xPropertySet->setPropertyValue( m_aProps[nInd].Name, m_aProps[nInd].Value ); - } - } - else - xPropertySet->setPropertyValue( m_aProps[nInd].Name, m_aProps[nInd].Value ); - } - - if ( m_bUseCommonEncryption ) - { - if ( m_nStorageType != embed::StorageFormats::PACKAGE ) - throw uno::RuntimeException(); - - // set to be encrypted but do not use encryption key - xPropertySet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ), - uno::makeAny( uno::Sequence< beans::NamedValue >() ) ); - xPropertySet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Encrypted") ), - uno::makeAny( sal_True ) ); - } - else if ( m_bHasCachedEncryptionData ) - { - if ( m_nStorageType != embed::StorageFormats::PACKAGE ) - throw uno::RuntimeException(); - - xPropertySet->setPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ), - uno::makeAny( m_aEncryptionData.getAsConstNamedValueList() ) ); - } - - // the stream should be free soon, after package is stored - m_xPackageStream = xNewPackageStream; - m_bHasDataToFlush = sal_False; - m_bFlushed = sal_True; // will allow to use transaction on stream level if will need it -} - -//----------------------------------------------- -void OWriteStream_Impl::Revert() -{ - // can be called only from parent storage - // means complete reload of the stream - - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - if ( !m_bHasDataToFlush ) - return; // nothing to do - - OSL_ENSURE( m_aTempURL.getLength() || m_xCacheStream.is(), "The temporary must exist!\n" ); - - if ( m_xCacheStream.is() ) - { - m_xCacheStream = uno::Reference< io::XStream >(); - m_xCacheSeek = uno::Reference< io::XSeekable >(); - } - - if ( m_aTempURL.getLength() ) - { - KillFile( m_aTempURL, GetServiceFactory() ); - m_aTempURL = ::rtl::OUString(); - } - - m_aProps.realloc( 0 ); - - m_bHasDataToFlush = sal_False; - - m_bUseCommonEncryption = sal_True; - m_bHasCachedEncryptionData = sal_False; - m_aEncryptionData.clear(); - - if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - { - // currently the relations storage is changed only on commit - m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_aNewRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >(); - if ( m_xOrigRelInfoStream.is() ) - { - // the original stream is still here, that means that it was not parsed - m_aOrigRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >(); - m_nRelInfoStatus = RELINFO_NO_INIT; - } - else - { - // the original stream was aready parsed - if ( !m_bOrigRelInfoBroken ) - m_nRelInfoStatus = RELINFO_READ; - else - m_nRelInfoStatus = RELINFO_BROKEN; - } - } -} - -//----------------------------------------------- -uno::Sequence< beans::PropertyValue > OWriteStream_Impl::GetStreamProperties() -{ - if ( !m_aProps.getLength() ) - m_aProps = ReadPackageStreamProperties(); - - return m_aProps; -} - -//----------------------------------------------- -uno::Sequence< beans::PropertyValue > OWriteStream_Impl::InsertOwnProps( - const uno::Sequence< beans::PropertyValue >& aProps, - sal_Bool bUseCommonEncryption ) -{ - uno::Sequence< beans::PropertyValue > aResult( aProps ); - sal_Int32 nLen = aResult.getLength(); - - if ( m_nStorageType == embed::StorageFormats::PACKAGE ) - { - for ( sal_Int32 nInd = 0; nInd < nLen; nInd++ ) - if ( aResult[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "UseCommonStoragePasswordEncryption" ) ) ) - { - aResult[nInd].Value <<= bUseCommonEncryption; - return aResult; - } - - aResult.realloc( ++nLen ); - aResult[nLen - 1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseCommonStoragePasswordEncryption") ); - aResult[nLen - 1].Value <<= bUseCommonEncryption; - } - else if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - { - ReadRelInfoIfNecessary(); - - uno::Any aValue; - if ( m_nRelInfoStatus == RELINFO_READ ) - aValue <<= m_aOrigRelInfo; - else if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ || m_nRelInfoStatus == RELINFO_CHANGED ) - aValue <<= m_aNewRelInfo; - else // m_nRelInfoStatus == RELINFO_CHANGED_BROKEN || m_nRelInfoStatus == RELINFO_BROKEN - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Wrong relinfo stream!" ) ), - uno::Reference< uno::XInterface >() ); - - for ( sal_Int32 nInd = 0; nInd < nLen; nInd++ ) - if ( aResult[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RelationsInfo" ) ) ) - { - aResult[nInd].Value = aValue; - return aResult; - } - - aResult.realloc( ++nLen ); - aResult[nLen - 1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RelationsInfo") ); - aResult[nLen - 1].Value = aValue; - } - - return aResult; -} - -//----------------------------------------------- -sal_Bool OWriteStream_Impl::IsTransacted() -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - return ( m_pAntiImpl && m_pAntiImpl->m_bTransacted ); -} - -void OWriteStream_Impl::ReadRelInfoIfNecessary() -{ - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - return; - - if ( m_nRelInfoStatus == RELINFO_NO_INIT ) - { - try - { - // Init from original stream - if ( m_xOrigRelInfoStream.is() ) - m_aOrigRelInfo = ::comphelper::OFOPXMLHelper::ReadRelationsInfoSequence( - m_xOrigRelInfoStream, - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels/*.rels" ) ), - m_xFactory ); - - // in case of success the stream must be thrown away, that means that the OrigRelInfo is initialized - // the reason for this is that the original stream might not be seekable ( at the same time the new - // provided stream must be seekable ), so it must be read only once - m_xOrigRelInfoStream = uno::Reference< io::XInputStream >(); - m_nRelInfoStatus = RELINFO_READ; - } - catch( const uno::Exception& rException ) - { - AddLog( rException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - - m_nRelInfoStatus = RELINFO_BROKEN; - m_bOrigRelInfoBroken = sal_True; - } - } - else if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM ) - { - // Init from the new stream - try - { - if ( m_xNewRelInfoStream.is() ) - m_aNewRelInfo = ::comphelper::OFOPXMLHelper::ReadRelationsInfoSequence( - m_xNewRelInfoStream, - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels/*.rels" ) ), - m_xFactory ); - - m_nRelInfoStatus = RELINFO_CHANGED_STREAM_READ; - } - catch( const uno::Exception& ) - { - m_nRelInfoStatus = RELINFO_CHANGED_BROKEN; - } - } -} - -//----------------------------------------------- -uno::Sequence< beans::PropertyValue > OWriteStream_Impl::ReadPackageStreamProperties() -{ - sal_Int32 nPropNum = 0; - if ( m_nStorageType == embed::StorageFormats::ZIP ) - nPropNum = 2; - else if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - nPropNum = 3; - else if ( m_nStorageType == embed::StorageFormats::PACKAGE ) - nPropNum = 4; - uno::Sequence< beans::PropertyValue > aResult( nPropNum ); - - // The "Compressed" property must be set after "MediaType" property, - // since the setting of the last one can change the value of the first one - - if ( m_nStorageType == embed::StorageFormats::OFOPXML || m_nStorageType == embed::StorageFormats::PACKAGE ) - { - aResult[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MediaType") ); - aResult[1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Compressed") ); - aResult[2].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Size") ); - - if ( m_nStorageType == embed::StorageFormats::PACKAGE ) - aResult[3].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Encrypted") ); - } - else - { - aResult[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Compressed") ); - aResult[1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Size") ); - - } - - // TODO: may be also raw stream should be marked - - uno::Reference< beans::XPropertySet > xPropSet( m_xPackageStream, uno::UNO_QUERY ); - if ( xPropSet.is() ) - { - for ( sal_Int32 nInd = 0; nInd < aResult.getLength(); nInd++ ) - { - try { - aResult[nInd].Value = xPropSet->getPropertyValue( aResult[nInd].Name ); - } - catch( const uno::Exception& rException ) - { - AddLog( rException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - - OSL_FAIL( "A property can't be retrieved!\n" ); - } - } - } - else - { - OSL_FAIL( "Can not get properties from a package stream!\n" ); - throw uno::RuntimeException(); - } - - return aResult; -} - -//----------------------------------------------- -void OWriteStream_Impl::CopyInternallyTo_Impl( const uno::Reference< io::XStream >& xDestStream, - const ::comphelper::SequenceAsHashMap& aEncryptionData ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - OSL_ENSURE( !m_bUseCommonEncryption, "The stream can not be encrypted!" ); - - if ( m_nStorageType != embed::StorageFormats::PACKAGE ) - throw packages::NoEncryptionException(); - - if ( m_pAntiImpl ) - { - m_pAntiImpl->CopyToStreamInternally_Impl( xDestStream ); - } - else - { - uno::Reference< io::XStream > xOwnStream = GetStream( embed::ElementModes::READ, aEncryptionData, sal_False ); - if ( !xOwnStream.is() ) - throw io::IOException(); // TODO - - OStorage_Impl::completeStorageStreamCopy_Impl( xOwnStream, xDestStream, m_nStorageType, GetAllRelationshipsIfAny() ); - } - - uno::Reference< embed::XEncryptionProtectedSource2 > xEncr( xDestStream, uno::UNO_QUERY ); - if ( xEncr.is() ) - xEncr->setEncryptionData( aEncryptionData.getAsConstNamedValueList() ); -} - -//----------------------------------------------- -uno::Sequence< uno::Sequence< beans::StringPair > > OWriteStream_Impl::GetAllRelationshipsIfAny() -{ - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - return uno::Sequence< uno::Sequence< beans::StringPair > >(); - - ReadRelInfoIfNecessary(); - - if ( m_nRelInfoStatus == RELINFO_READ ) - return m_aOrigRelInfo; - else if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ || m_nRelInfoStatus == RELINFO_CHANGED ) - return m_aNewRelInfo; - else // m_nRelInfoStatus == RELINFO_CHANGED_BROKEN || m_nRelInfoStatus == RELINFO_BROKEN - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Wrong relinfo stream!" ) ), - uno::Reference< uno::XInterface >() ); -} - -//----------------------------------------------- -void OWriteStream_Impl::CopyInternallyTo_Impl( const uno::Reference< io::XStream >& xDestStream ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - if ( m_pAntiImpl ) - { - m_pAntiImpl->CopyToStreamInternally_Impl( xDestStream ); - } - else - { - uno::Reference< io::XStream > xOwnStream = GetStream( embed::ElementModes::READ, sal_False ); - if ( !xOwnStream.is() ) - throw io::IOException(); // TODO - - OStorage_Impl::completeStorageStreamCopy_Impl( xOwnStream, xDestStream, m_nStorageType, GetAllRelationshipsIfAny() ); - } -} - -//----------------------------------------------- -uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMode, const ::comphelper::SequenceAsHashMap& aEncryptionData, sal_Bool bHierarchyAccess ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - OSL_ENSURE( m_xPackageStream.is(), "No package stream is set!\n" ); - - if ( m_pAntiImpl ) - throw io::IOException(); // TODO: - - if ( !IsEncrypted() ) - throw packages::NoEncryptionException(); - - uno::Reference< io::XStream > xResultStream; - - uno::Reference< beans::XPropertySet > xPropertySet( m_xPackageStream, uno::UNO_QUERY ); - if ( !xPropertySet.is() ) - throw uno::RuntimeException(); - - if ( m_bHasCachedEncryptionData ) - { - if ( !::package::PackageEncryptionDatasEqual( m_aEncryptionData, aEncryptionData ) ) - throw packages::WrongPasswordException(); - - // the correct key must be set already - xResultStream = GetStream_Impl( nStreamMode, bHierarchyAccess ); - } - else - { - SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getAsConstNamedValueList() ); - - try { - xResultStream = GetStream_Impl( nStreamMode, bHierarchyAccess ); - - m_bUseCommonEncryption = sal_False; // very important to set it to false - m_bHasCachedEncryptionData = sal_True; - m_aEncryptionData = aEncryptionData; - } - catch( const packages::WrongPasswordException& rWrongPasswordException ) - { - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() ); - AddLog( rWrongPasswordException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch ( const uno::Exception& rException ) - { - AddLog( rException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - - OSL_FAIL( "Can't write encryption related properties!\n" ); - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() ); - throw io::IOException(); // TODO: - } - } - - OSL_ENSURE( xResultStream.is(), "In case stream can not be retrieved an exception must be thrown!\n" ); - - return xResultStream; -} - -//----------------------------------------------- -uno::Reference< io::XStream > OWriteStream_Impl::GetStream( sal_Int32 nStreamMode, sal_Bool bHierarchyAccess ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - OSL_ENSURE( m_xPackageStream.is(), "No package stream is set!\n" ); - - if ( m_pAntiImpl ) - throw io::IOException(); // TODO: - - uno::Reference< io::XStream > xResultStream; - - if ( IsEncrypted() ) - { - ::comphelper::SequenceAsHashMap aGlobalEncryptionData; - try - { - aGlobalEncryptionData = GetCommonRootEncryptionData(); - } - catch( const packages::NoEncryptionException& rNoEncryptionException ) - { - AddLog( rNoEncryptionException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - throw packages::WrongPasswordException(); - } - - xResultStream = GetStream( nStreamMode, aGlobalEncryptionData, bHierarchyAccess ); - } - else - xResultStream = GetStream_Impl( nStreamMode, bHierarchyAccess ); - - return xResultStream; -} - -//----------------------------------------------- -uno::Reference< io::XStream > OWriteStream_Impl::GetStream_Impl( sal_Int32 nStreamMode, sal_Bool bHierarchyAccess ) -{ - // private method, no mutex is used - GetStreamProperties(); - - // TODO/LATER: this info might be read later, on demand in future - ReadRelInfoIfNecessary(); - - if ( ( nStreamMode & embed::ElementModes::READWRITE ) == embed::ElementModes::READ ) - { - uno::Reference< io::XInputStream > xInStream; - if ( m_xCacheStream.is() || m_aTempURL.getLength() ) - xInStream = GetTempFileAsInputStream(); //TODO: - else - xInStream = m_xPackageStream->getDataStream(); - - // The stream does not exist in the storage - if ( !xInStream.is() ) - throw io::IOException(); - - OInputCompStream* pStream = new OInputCompStream( *this, xInStream, InsertOwnProps( m_aProps, m_bUseCommonEncryption ), m_nStorageType ); - uno::Reference< io::XStream > xCompStream( - static_cast< ::cppu::OWeakObject* >( pStream ), - uno::UNO_QUERY ); - OSL_ENSURE( xCompStream.is(), - "OInputCompStream MUST provide XStream interfaces!\n" ); - - m_aInputStreamsList.push_back( pStream ); - return xCompStream; - } - else if ( ( nStreamMode & embed::ElementModes::READWRITE ) == embed::ElementModes::SEEKABLEREAD ) - { - if ( !m_xCacheStream.is() && !m_aTempURL.getLength() && !( m_xPackageStream->getDataStream().is() ) ) - { - // The stream does not exist in the storage - throw io::IOException(); - } - - uno::Reference< io::XInputStream > xInStream; - - xInStream = GetTempFileAsInputStream(); //TODO: - - if ( !xInStream.is() ) - throw io::IOException(); - - OInputSeekStream* pStream = new OInputSeekStream( *this, xInStream, InsertOwnProps( m_aProps, m_bUseCommonEncryption ), m_nStorageType ); - uno::Reference< io::XStream > xSeekStream( - static_cast< ::cppu::OWeakObject* >( pStream ), - uno::UNO_QUERY ); - OSL_ENSURE( xSeekStream.is(), - "OInputSeekStream MUST provide XStream interfaces!\n" ); - - m_aInputStreamsList.push_back( pStream ); - return xSeekStream; - } - else if ( ( nStreamMode & embed::ElementModes::WRITE ) == embed::ElementModes::WRITE ) - { - if ( !m_aInputStreamsList.empty() ) - throw io::IOException(); // TODO: - - uno::Reference< io::XStream > xStream; - if ( ( nStreamMode & embed::ElementModes::TRUNCATE ) == embed::ElementModes::TRUNCATE ) - { - if ( m_aTempURL.getLength() ) - { - KillFile( m_aTempURL, GetServiceFactory() ); - m_aTempURL = ::rtl::OUString(); - } - if ( m_xCacheStream.is() ) - CleanCacheStream(); - - m_bHasDataToFlush = sal_True; - - // this call is triggered by the parent and it will recognize the change of the state - if ( m_pParent ) - m_pParent->m_bIsModified = sal_True; - - xStream = CreateMemoryStream( GetServiceFactory() ); - m_xCacheSeek.set( xStream, uno::UNO_QUERY_THROW ); - m_xCacheStream = xStream; - } - else if ( !m_bHasInsertedStreamOptimization ) - { - if ( !m_aTempURL.getLength() && !m_xCacheStream.is() && !( m_xPackageStream->getDataStream().is() ) ) - { - // The stream does not exist in the storage - m_bHasDataToFlush = sal_True; - - // this call is triggered by the parent and it will recognize the change of the state - if ( m_pParent ) - m_pParent->m_bIsModified = sal_True; - xStream = GetTempFileAsStream(); - } - - // if the stream exists the temporary file is created on demand - // xStream = GetTempFileAsStream(); - } - - if ( !xStream.is() ) - m_pAntiImpl = new OWriteStream( this, bHierarchyAccess ); - else - m_pAntiImpl = new OWriteStream( this, xStream, bHierarchyAccess ); - - uno::Reference< io::XStream > xWriteStream = - uno::Reference< io::XStream >( static_cast< ::cppu::OWeakObject* >( m_pAntiImpl ), - uno::UNO_QUERY ); - - OSL_ENSURE( xWriteStream.is(), "OWriteStream MUST implement XStream && XComponent interfaces!\n" ); - - return xWriteStream; - } - - throw lang::IllegalArgumentException(); // TODO -} - -//----------------------------------------------- -uno::Reference< io::XInputStream > OWriteStream_Impl::GetPlainRawInStream() -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - OSL_ENSURE( m_xPackageStream.is(), "No package stream is set!\n" ); - - // this method is used only internally, this stream object should not go outside of this implementation - // if ( m_pAntiImpl ) - // throw io::IOException(); // TODO: - - return m_xPackageStream->getPlainRawStream(); -} - -//----------------------------------------------- -uno::Reference< io::XInputStream > OWriteStream_Impl::GetRawInStream() -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - OSL_ENSURE( m_xPackageStream.is(), "No package stream is set!\n" ); - - if ( m_pAntiImpl ) - throw io::IOException(); // TODO: - - OSL_ENSURE( IsEncrypted(), "Impossible to get raw representation for nonencrypted stream!\n" ); - if ( !IsEncrypted() ) - throw packages::NoEncryptionException(); - - return m_xPackageStream->getRawStream(); -} - -//----------------------------------------------- -::comphelper::SequenceAsHashMap OWriteStream_Impl::GetCommonRootEncryptionData() - throw ( packages::NoEncryptionException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - if ( m_nStorageType != embed::StorageFormats::PACKAGE || !m_pParent ) - throw packages::NoEncryptionException(); - - return m_pParent->GetCommonRootEncryptionData(); -} - -//----------------------------------------------- -void OWriteStream_Impl::InputStreamDisposed( OInputCompStream* pStream ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - m_aInputStreamsList.remove( pStream ); -} - -//----------------------------------------------- -void OWriteStream_Impl::CreateReadonlyCopyBasedOnData( const uno::Reference< io::XInputStream >& xDataToCopy, const uno::Sequence< beans::PropertyValue >& aProps, sal_Bool, uno::Reference< io::XStream >& xTargetStream ) -{ - uno::Reference < io::XStream > xTempFile; - if ( !xTargetStream.is() ) - xTempFile = uno::Reference < io::XStream >( - m_xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.TempFile") ) ), - uno::UNO_QUERY ); - else - xTempFile = xTargetStream; - - uno::Reference < io::XSeekable > xTempSeek( xTempFile, uno::UNO_QUERY ); - if ( !xTempSeek.is() ) - throw uno::RuntimeException(); // TODO - - uno::Reference < io::XOutputStream > xTempOut = xTempFile->getOutputStream(); - if ( !xTempOut.is() ) - throw uno::RuntimeException(); - - if ( xDataToCopy.is() ) - ::comphelper::OStorageHelper::CopyInputToOutput( xDataToCopy, xTempOut ); - - xTempOut->closeOutput(); - xTempSeek->seek( 0 ); - - uno::Reference< io::XInputStream > xInStream = xTempFile->getInputStream(); - if ( !xInStream.is() ) - throw io::IOException(); - - // TODO: remember last state of m_bUseCommonEncryption - if ( !xTargetStream.is() ) - xTargetStream = uno::Reference< io::XStream > ( - static_cast< ::cppu::OWeakObject* >( - new OInputSeekStream( xInStream, InsertOwnProps( aProps, m_bUseCommonEncryption ), m_nStorageType ) ), - uno::UNO_QUERY_THROW ); -} - -//----------------------------------------------- -void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTargetStream ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - OSL_ENSURE( m_xPackageStream.is(), "The source stream for copying is incomplete!\n" ); - if ( !m_xPackageStream.is() ) - throw uno::RuntimeException(); - - uno::Reference< io::XInputStream > xDataToCopy; - if ( IsEncrypted() ) - { - // an encrypted stream must contain input stream - ::comphelper::SequenceAsHashMap aGlobalEncryptionData; - try - { - aGlobalEncryptionData = GetCommonRootEncryptionData(); - } - catch( const packages::NoEncryptionException& rNoEncryptionException ) - { - AddLog( rNoEncryptionException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No Element" ) ) ); - - throw packages::WrongPasswordException(); - } - - GetCopyOfLastCommit( xTargetStream, aGlobalEncryptionData ); - } - else - { - xDataToCopy = m_xPackageStream->getDataStream(); - - // in case of new inserted package stream it is possible that input stream still was not set - GetStreamProperties(); - - CreateReadonlyCopyBasedOnData( xDataToCopy, m_aProps, m_bUseCommonEncryption, xTargetStream ); - } -} - -//----------------------------------------------- -void OWriteStream_Impl::GetCopyOfLastCommit( uno::Reference< io::XStream >& xTargetStream, const ::comphelper::SequenceAsHashMap& aEncryptionData ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - OSL_ENSURE( m_xPackageStream.is(), "The source stream for copying is incomplete!\n" ); - if ( !m_xPackageStream.is() ) - throw uno::RuntimeException(); - - if ( !IsEncrypted() ) - throw packages::NoEncryptionException(); - - uno::Reference< io::XInputStream > xDataToCopy; - - if ( m_bHasCachedEncryptionData ) - { - // TODO: introduce last commited cashed password information and use it here - // that means "use common pass" also should be remembered on flash - uno::Sequence< beans::NamedValue > aKey = aEncryptionData.getAsConstNamedValueList(); - - uno::Reference< beans::XPropertySet > xProps( m_xPackageStream, uno::UNO_QUERY ); - if ( !xProps.is() ) - throw uno::RuntimeException(); - - sal_Bool bEncr = sal_False; - xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Encrypted") ) ) >>= bEncr; - if ( !bEncr ) - throw packages::NoEncryptionException(); - - uno::Sequence< beans::NamedValue > aPackKey; - xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) ) >>= aPackKey; - if ( !SequencesEqual( aKey, aPackKey ) ) - throw packages::WrongPasswordException(); - - // the correct key must be set already - xDataToCopy = m_xPackageStream->getDataStream(); - } - else - { - uno::Reference< beans::XPropertySet > xPropertySet( m_xPackageStream, uno::UNO_QUERY ); - SetEncryptionKeyProperty_Impl( xPropertySet, aEncryptionData.getAsConstNamedValueList() ); - - try { - xDataToCopy = m_xPackageStream->getDataStream(); - - if ( !xDataToCopy.is() ) - { - OSL_FAIL( "Encrypted ZipStream must already have input stream inside!\n" ); - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() ); - } - } - catch( const uno::Exception& rException ) - { - OSL_FAIL( "Can't open encrypted stream!\n" ); - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() ); - AddLog( rException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - - SetEncryptionKeyProperty_Impl( xPropertySet, uno::Sequence< beans::NamedValue >() ); - } - - // in case of new inserted package stream it is possible that input stream still was not set - GetStreamProperties(); - - CreateReadonlyCopyBasedOnData( xDataToCopy, m_aProps, m_bUseCommonEncryption, xTargetStream ); -} - -//----------------------------------------------- -void OWriteStream_Impl::CommitStreamRelInfo( const uno::Reference< embed::XStorage >& xRelStorage, const ::rtl::OUString& aOrigStreamName, const ::rtl::OUString& aNewStreamName ) -{ - // at this point of time the old stream must be already cleaned - OSL_ENSURE( m_nStorageType == embed::StorageFormats::OFOPXML, "The method should be used only with OFOPXML format!\n" ); - - if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - { - OSL_ENSURE( aOrigStreamName.getLength() && aNewStreamName.getLength() && xRelStorage.is(), - "Wrong relation persistence information is provided!\n" ); - - if ( !xRelStorage.is() || !aOrigStreamName.getLength() || !aNewStreamName.getLength() ) - throw uno::RuntimeException(); - - if ( m_nRelInfoStatus == RELINFO_BROKEN || m_nRelInfoStatus == RELINFO_CHANGED_BROKEN ) - throw io::IOException(); // TODO: - - ::rtl::OUString aOrigRelStreamName = aOrigStreamName; - aOrigRelStreamName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".rels" ) ); - - ::rtl::OUString aNewRelStreamName = aNewStreamName; - aNewRelStreamName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".rels" ) ); - - sal_Bool bRenamed = !aOrigRelStreamName.equals( aNewRelStreamName ); - if ( m_nRelInfoStatus == RELINFO_CHANGED - || m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ - || m_nRelInfoStatus == RELINFO_CHANGED_STREAM ) - { - if ( bRenamed && xRelStorage->hasByName( aOrigRelStreamName ) ) - xRelStorage->removeElement( aOrigRelStreamName ); - - if ( m_nRelInfoStatus == RELINFO_CHANGED ) - { - if ( m_aNewRelInfo.getLength() ) - { - uno::Reference< io::XStream > xRelsStream = - xRelStorage->openStreamElement( aNewRelStreamName, - embed::ElementModes::TRUNCATE | embed::ElementModes::READWRITE ); - - uno::Reference< io::XOutputStream > xOutStream = xRelsStream->getOutputStream(); - if ( !xOutStream.is() ) - throw uno::RuntimeException(); - - ::comphelper::OFOPXMLHelper::WriteRelationsInfoSequence( xOutStream, m_aNewRelInfo, m_xFactory ); - - // set the mediatype - uno::Reference< beans::XPropertySet > xPropSet( xRelsStream, uno::UNO_QUERY_THROW ); - xPropSet->setPropertyValue( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ), - uno::makeAny( ::rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM( "application/vnd.openxmlformats-package.relationships+xml" ) ) ) ); - - m_nRelInfoStatus = RELINFO_READ; - } - } - else if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ - || m_nRelInfoStatus == RELINFO_CHANGED_STREAM ) - { - uno::Reference< io::XStream > xRelsStream = - xRelStorage->openStreamElement( aNewRelStreamName, - embed::ElementModes::TRUNCATE | embed::ElementModes::READWRITE ); - - uno::Reference< io::XOutputStream > xOutputStream = xRelsStream->getOutputStream(); - if ( !xOutputStream.is() ) - throw uno::RuntimeException(); - - uno::Reference< io::XSeekable > xSeek( m_xNewRelInfoStream, uno::UNO_QUERY_THROW ); - xSeek->seek( 0 ); - ::comphelper::OStorageHelper::CopyInputToOutput( m_xNewRelInfoStream, xOutputStream ); - xSeek->seek( 0 ); - - // set the mediatype - uno::Reference< beans::XPropertySet > xPropSet( xRelsStream, uno::UNO_QUERY_THROW ); - xPropSet->setPropertyValue( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ), - uno::makeAny( ::rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM( "application/vnd.openxmlformats-package.relationships+xml" ) ) ) ); - - if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM ) - m_nRelInfoStatus = RELINFO_NO_INIT; - else - { - // the information is already parsed and the stream is stored, no need in temporary stream any more - m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_nRelInfoStatus = RELINFO_READ; - } - } - - // the original stream makes no sence after this step - m_xOrigRelInfoStream = m_xNewRelInfoStream; - m_aOrigRelInfo = m_aNewRelInfo; - m_bOrigRelInfoBroken = sal_False; - m_aNewRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >(); - m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - } - else - { - // the stream is not changed but it might be renamed - if ( bRenamed && xRelStorage->hasByName( aOrigRelStreamName ) ) - xRelStorage->renameElement( aOrigRelStreamName, aNewRelStreamName ); - } - } -} - -//=============================================== -// OWriteStream implementation -//=============================================== - -//----------------------------------------------- -OWriteStream::OWriteStream( OWriteStream_Impl* pImpl, sal_Bool bTransacted ) -: m_pImpl( pImpl ) -, m_bInStreamDisconnected( sal_False ) -, m_bInitOnDemand( sal_True ) -, m_nInitPosition( 0 ) -, m_bTransacted( bTransacted ) -{ - OSL_ENSURE( pImpl, "No base implementation!\n" ); - OSL_ENSURE( m_pImpl->m_rMutexRef.Is(), "No mutex!\n" ); - - if ( !m_pImpl || !m_pImpl->m_rMutexRef.Is() ) - throw uno::RuntimeException(); // just a disaster - - m_pData = new WSInternalData_Impl( pImpl->m_rMutexRef, m_pImpl->m_nStorageType ); -} - -//----------------------------------------------- -OWriteStream::OWriteStream( OWriteStream_Impl* pImpl, uno::Reference< io::XStream > xStream, sal_Bool bTransacted ) -: m_pImpl( pImpl ) -, m_bInStreamDisconnected( sal_False ) -, m_bInitOnDemand( sal_False ) -, m_nInitPosition( 0 ) -, m_bTransacted( bTransacted ) -{ - OSL_ENSURE( pImpl && xStream.is(), "No base implementation!\n" ); - OSL_ENSURE( m_pImpl->m_rMutexRef.Is(), "No mutex!\n" ); - - if ( !m_pImpl || !m_pImpl->m_rMutexRef.Is() ) - throw uno::RuntimeException(); // just a disaster - - m_pData = new WSInternalData_Impl( pImpl->m_rMutexRef, m_pImpl->m_nStorageType ); - - if ( xStream.is() ) - { - m_xInStream = xStream->getInputStream(); - m_xOutStream = xStream->getOutputStream(); - m_xSeekable = uno::Reference< io::XSeekable >( xStream, uno::UNO_QUERY ); - OSL_ENSURE( m_xInStream.is() && m_xOutStream.is() && m_xSeekable.is(), "Stream implementation is incomplete!\n" ); - } -} - -//----------------------------------------------- -OWriteStream::~OWriteStream() -{ - { - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - if ( m_pImpl ) - { - m_refCount++; - try { - dispose(); - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - } - } - } - - if ( m_pData && m_pData->m_pTypeCollection ) - delete m_pData->m_pTypeCollection; - - if ( m_pData ) - delete m_pData; -} - -//----------------------------------------------- -void OWriteStream::DeInit() -{ - if ( !m_pImpl ) - return; // do nothing - - if ( m_xSeekable.is() ) - m_nInitPosition = m_xSeekable->getPosition(); - - m_xInStream = uno::Reference< io::XInputStream >(); - m_xOutStream = uno::Reference< io::XOutputStream >(); - m_xSeekable = uno::Reference< io::XSeekable >(); - m_bInitOnDemand = sal_True; -} - -//----------------------------------------------- -void OWriteStream::CheckInitOnDemand() -{ - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_bInitOnDemand ) - { - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OWriteStream::CheckInitOnDemand, initializing" ); - uno::Reference< io::XStream > xStream = m_pImpl->GetTempFileAsStream(); - if ( xStream.is() ) - { - m_xInStream.set( xStream->getInputStream(), uno::UNO_SET_THROW ); - m_xOutStream.set( xStream->getOutputStream(), uno::UNO_SET_THROW ); - m_xSeekable.set( xStream, uno::UNO_QUERY_THROW ); - m_xSeekable->seek( m_nInitPosition ); - - m_nInitPosition = 0; - m_bInitOnDemand = sal_False; - } - } -} - -//----------------------------------------------- -void OWriteStream::CopyToStreamInternally_Impl( const uno::Reference< io::XStream >& xDest ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_xInStream.is() ) - throw uno::RuntimeException(); - - if ( !m_xSeekable.is() ) - throw uno::RuntimeException(); - - uno::Reference< beans::XPropertySet > xDestProps( xDest, uno::UNO_QUERY ); - if ( !xDestProps.is() ) - throw uno::RuntimeException(); //TODO - - uno::Reference< io::XOutputStream > xDestOutStream = xDest->getOutputStream(); - if ( !xDestOutStream.is() ) - throw io::IOException(); // TODO - - sal_Int64 nCurPos = m_xSeekable->getPosition(); - m_xSeekable->seek( 0 ); - - uno::Exception eThrown; - sal_Bool bThrown = sal_False; - try { - ::comphelper::OStorageHelper::CopyInputToOutput( m_xInStream, xDestOutStream ); - } - catch ( const uno::Exception& e ) - { - eThrown = e; - bThrown = sal_True; - } - - // position-related section below is critical - // if it fails the stream will become invalid - try { - m_xSeekable->seek( nCurPos ); - } - catch ( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - - // TODO: set the stoream in invalid state or dispose - OSL_FAIL( "The stream become invalid during copiing!\n" ); - throw uno::RuntimeException(); - } - - if ( bThrown ) - throw eThrown; - - // now the properties can be copied - // the order of the properties setting is not important for StorageStream API - ::rtl::OUString aPropName (RTL_CONSTASCII_USTRINGPARAM("Compressed") ); - xDestProps->setPropertyValue( aPropName, getPropertyValue( aPropName ) ); - if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE || m_pData->m_nStorageType == embed::StorageFormats::OFOPXML ) - { - aPropName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MediaType" ) ); - xDestProps->setPropertyValue( aPropName, getPropertyValue( aPropName ) ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE ) - { - aPropName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseCommonStoragePasswordEncryption") ); - xDestProps->setPropertyValue( aPropName, getPropertyValue( aPropName ) ); - } - } -} - -//----------------------------------------------- -void OWriteStream::ModifyParentUnlockMutex_Impl( ::osl::ResettableMutexGuard& aGuard ) -{ - if ( m_pImpl->m_pParent ) - { - if ( m_pImpl->m_pParent->m_pAntiImpl ) - { - uno::Reference< util::XModifiable > xParentModif( (util::XModifiable*)(m_pImpl->m_pParent->m_pAntiImpl) ); - aGuard.clear(); - xParentModif->setModified( sal_True ); - } - else - m_pImpl->m_pParent->m_bIsModified = sal_True; - } -} - -//----------------------------------------------- -uno::Any SAL_CALL OWriteStream::queryInterface( const uno::Type& rType ) - throw( uno::RuntimeException ) -{ - uno::Any aReturn; - - // common interfaces - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<lang::XTypeProvider*> ( this ) - , static_cast<io::XInputStream*> ( this ) - , static_cast<io::XOutputStream*> ( this ) - , static_cast<io::XStream*> ( this ) - , static_cast<embed::XExtendedStorageStream*> ( this ) - , static_cast<io::XSeekable*> ( this ) - , static_cast<io::XTruncate*> ( this ) - , static_cast<lang::XComponent*> ( this ) - , static_cast<beans::XPropertySet*> ( this ) ); - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - - if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE ) - { - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<embed::XEncryptionProtectedSource2*> ( this ) - , static_cast<embed::XEncryptionProtectedSource*> ( this ) ); - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML ) - { - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<embed::XRelationshipAccess*> ( this ) ); - } - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - - if ( m_bTransacted ) - { - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<embed::XTransactedObject*> ( this ) - , static_cast<embed::XTransactionBroadcaster*> ( this ) ); - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - } - - return OWeakObject::queryInterface( rType ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::acquire() throw() -{ - OWeakObject::acquire(); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::release() throw() -{ - OWeakObject::release(); -} - -//----------------------------------------------- -uno::Sequence< uno::Type > SAL_CALL OWriteStream::getTypes() - throw( uno::RuntimeException ) -{ - if ( m_pData->m_pTypeCollection == NULL ) - { - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( m_pData->m_pTypeCollection == NULL ) - { - if ( m_bTransacted ) - { - if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE ) - { - ::cppu::OTypeCollection aTmpCollection - ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL ) - , ::getCppuType( ( const uno::Reference< lang::XComponent >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource2 >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XExtendedStorageStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL ) ); - - m_pData->m_pTypeCollection = new ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) - , aTmpCollection.getTypes() ); - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML ) - { - m_pData->m_pTypeCollection = new ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL ) - , ::getCppuType( ( const uno::Reference< lang::XComponent >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XRelationshipAccess >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XExtendedStorageStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL ) - , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); - } - else // if ( m_pData->m_nStorageType == embed::StorageFormats::ZIP ) - { - m_pData->m_pTypeCollection = new ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL ) - , ::getCppuType( ( const uno::Reference< lang::XComponent >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XExtendedStorageStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL ) - , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); - } - } - else - { - if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE ) - { - m_pData->m_pTypeCollection = new ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL ) - , ::getCppuType( ( const uno::Reference< lang::XComponent >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource2 >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource >* )NULL ) - , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML ) - { - m_pData->m_pTypeCollection = new ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL ) - , ::getCppuType( ( const uno::Reference< lang::XComponent >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XRelationshipAccess >* )NULL ) - , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); - } - else // if ( m_pData->m_nStorageType == embed::StorageFormats::ZIP ) - { - m_pData->m_pTypeCollection = new ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XStream >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL ) - , ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL ) - , ::getCppuType( ( const uno::Reference< lang::XComponent >* )NULL ) - , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); - } - } - } - } - - return m_pData->m_pTypeCollection->getTypes() ; -} - -namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; } - -//----------------------------------------------- -uno::Sequence< sal_Int8 > SAL_CALL OWriteStream::getImplementationId() - throw( uno::RuntimeException ) -{ - ::cppu::OImplementationId &rId = lcl_ImplId::get(); - return rId.getImplementationId(); -} - -//----------------------------------------------- -sal_Int32 SAL_CALL OWriteStream::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xInStream.is() ) - throw io::NotConnectedException(); - - return m_xInStream->readBytes( aData, nBytesToRead ); -} - -//----------------------------------------------- -sal_Int32 SAL_CALL OWriteStream::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xInStream.is() ) - throw io::NotConnectedException(); - - return m_xInStream->readSomeBytes( aData, nMaxBytesToRead ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::skipBytes( sal_Int32 nBytesToSkip ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xInStream.is() ) - throw io::NotConnectedException(); - - m_xInStream->skipBytes( nBytesToSkip ); -} - -//----------------------------------------------- -sal_Int32 SAL_CALL OWriteStream::available( ) - throw ( io::NotConnectedException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xInStream.is() ) - throw io::NotConnectedException(); - - return m_xInStream->available(); - -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::closeInput( ) - throw ( io::NotConnectedException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_bInitOnDemand && ( m_bInStreamDisconnected || !m_xInStream.is() ) ) - throw io::NotConnectedException(); - - // the input part of the stream stays open for internal purposes ( to allow reading during copiing ) - // since it can not be reopened until output part is closed, it will be closed with output part. - m_bInStreamDisconnected = sal_True; - // m_xInStream->closeInput(); - // m_xInStream = uno::Reference< io::XInputStream >(); - - if ( !m_xOutStream.is() ) - dispose(); -} - -//----------------------------------------------- -uno::Reference< io::XInputStream > SAL_CALL OWriteStream::getInputStream() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_bInitOnDemand && ( m_bInStreamDisconnected || !m_xInStream.is() ) ) - return uno::Reference< io::XInputStream >(); - - return uno::Reference< io::XInputStream >( static_cast< io::XInputStream* >( this ), uno::UNO_QUERY ); -} - -//----------------------------------------------- -uno::Reference< io::XOutputStream > SAL_CALL OWriteStream::getOutputStream() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xOutStream.is() ) - return uno::Reference< io::XOutputStream >(); - - return uno::Reference< io::XOutputStream >( static_cast< io::XOutputStream* >( this ), uno::UNO_QUERY ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::writeBytes( const uno::Sequence< sal_Int8 >& aData ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - // the write method makes initialization itself, since it depends from the aData length - // NO CheckInitOnDemand()! - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_bInitOnDemand ) - { - if ( !m_xOutStream.is() || !m_xSeekable.is()) - throw io::NotConnectedException(); - - if ( m_pImpl->m_xCacheStream.is() ) - { - // check whether the cache should be turned off - sal_Int64 nPos = m_xSeekable->getPosition(); - if ( nPos + aData.getLength() > MAX_STORCACHE_SIZE ) - { - // disconnect the cache and copy the data to the temporary file - m_xSeekable->seek( 0 ); - - // it is enough to copy the cached stream, the cache should already contain everything - if ( m_pImpl->GetFilledTempFileIfNo( m_xInStream ).getLength() ) - { - DeInit(); - // the last position is known and it is differs from the current stream position - m_nInitPosition = nPos; - } - } - } - } - - if ( m_bInitOnDemand ) - { - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OWriteStream::CheckInitOnDemand, initializing" ); - uno::Reference< io::XStream > xStream = m_pImpl->GetTempFileAsStream(); - if ( xStream.is() ) - { - m_xInStream.set( xStream->getInputStream(), uno::UNO_SET_THROW ); - m_xOutStream.set( xStream->getOutputStream(), uno::UNO_SET_THROW ); - m_xSeekable.set( xStream, uno::UNO_QUERY_THROW ); - m_xSeekable->seek( m_nInitPosition ); - - m_nInitPosition = 0; - m_bInitOnDemand = sal_False; - } - } - - - if ( !m_xOutStream.is() ) - throw io::NotConnectedException(); - - m_xOutStream->writeBytes( aData ); - m_pImpl->m_bHasDataToFlush = sal_True; - - ModifyParentUnlockMutex_Impl( aGuard ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::flush() - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - // In case stream is flushed it's current version becomes visible - // to the parent storage. Usually parent storage flushes the stream - // during own commit but a user can explicitly flush the stream - // so the changes will be available through cloning functionality. - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_bInitOnDemand ) - { - if ( !m_xOutStream.is() ) - throw io::NotConnectedException(); - - m_xOutStream->flush(); - m_pImpl->Commit(); - } -} - -//----------------------------------------------- -void OWriteStream::CloseOutput_Impl() -{ - // all the checks must be done in calling method - - m_xOutStream->closeOutput(); - m_xOutStream = uno::Reference< io::XOutputStream >(); - - if ( !m_bInitOnDemand ) - { - // after the stream is disposed it can be commited - // so transport correct size property - if ( !m_xSeekable.is() ) - throw uno::RuntimeException(); - - for ( sal_Int32 nInd = 0; nInd < m_pImpl->m_aProps.getLength(); nInd++ ) - { - if ( m_pImpl->m_aProps[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Size" ) ) ) - m_pImpl->m_aProps[nInd].Value <<= ((sal_Int32)m_xSeekable->getLength()); - } - } -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::closeOutput() - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xOutStream.is() ) - throw io::NotConnectedException(); - - CloseOutput_Impl(); - - if ( m_bInStreamDisconnected || !m_xInStream.is() ) - dispose(); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::seek( sal_Int64 location ) - throw ( lang::IllegalArgumentException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xSeekable.is() ) - throw uno::RuntimeException(); - - m_xSeekable->seek( location ); -} - -//----------------------------------------------- -sal_Int64 SAL_CALL OWriteStream::getPosition() - throw ( io::IOException, - uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xSeekable.is() ) - throw uno::RuntimeException(); - - return m_xSeekable->getPosition(); -} - -//----------------------------------------------- -sal_Int64 SAL_CALL OWriteStream::getLength() - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xSeekable.is() ) - throw uno::RuntimeException(); - - return m_xSeekable->getLength(); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::truncate() - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_xOutStream.is() ) - throw uno::RuntimeException(); - - uno::Reference< io::XTruncate > xTruncate( m_xOutStream, uno::UNO_QUERY ); - - if ( !xTruncate.is() ) - { - OSL_FAIL( "The output stream must support XTruncate interface!\n" ); - throw uno::RuntimeException(); - } - - xTruncate->truncate(); - - m_pImpl->m_bHasDataToFlush = sal_True; - - ModifyParentUnlockMutex_Impl( aGuard ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::dispose() - throw ( uno::RuntimeException ) -{ - // should be an internal method since it can be called only from parent storage - { - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_xOutStream.is() ) - CloseOutput_Impl(); - - if ( m_xInStream.is() ) - { - m_xInStream->closeInput(); - m_xInStream = uno::Reference< io::XInputStream >(); - } - - m_xSeekable = uno::Reference< io::XSeekable >(); - - m_pImpl->m_pAntiImpl = NULL; - - if ( !m_bInitOnDemand ) - { - try - { - if ( !m_bTransacted ) - { - m_pImpl->Commit(); - } - else - { - // throw away all the changes - m_pImpl->Revert(); - } - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetRuntimeException( - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can not commit/revert the storage!\n") ), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } - } - - m_pImpl = NULL; - } - - // the listener might try to get rid of parent storage, and the storage would delete this object; - // for now the listener is just notified at the end of the method to workaround the problem - // in future a more elegant way should be found - - lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) ); - m_pData->m_aListenersContainer.disposeAndClear( aSource ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::addEventListener( - const uno::Reference< lang::XEventListener >& xListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - m_pData->m_aListenersContainer.addInterface( ::getCppuType((const uno::Reference< lang::XEventListener >*)0), - xListener ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::removeEventListener( - const uno::Reference< lang::XEventListener >& xListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - m_pData->m_aListenersContainer.removeInterface( ::getCppuType((const uno::Reference< lang::XEventListener >*)0), - xListener ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::setEncryptionPassword( const ::rtl::OUString& aPass ) - throw ( uno::RuntimeException, - io::IOException ) -{ - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - OSL_ENSURE( m_pImpl->m_xPackageStream.is(), "No package stream is set!\n" ); - - m_pImpl->SetEncrypted( ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass ) ); - - ModifyParentUnlockMutex_Impl( aGuard ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::removeEncryption() - throw ( uno::RuntimeException, - io::IOException ) -{ - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - OSL_ENSURE( m_pImpl->m_xPackageStream.is(), "No package stream is set!\n" ); - - m_pImpl->SetDecrypted(); - - ModifyParentUnlockMutex_Impl( aGuard ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::setEncryptionData( const uno::Sequence< beans::NamedValue >& aEncryptionData ) - throw (io::IOException, uno::RuntimeException) -{ - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - CheckInitOnDemand(); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - OSL_ENSURE( m_pImpl->m_xPackageStream.is(), "No package stream is set!\n" ); - - m_pImpl->SetEncrypted( aEncryptionData ); - - ModifyParentUnlockMutex_Impl( aGuard ); -} - -//----------------------------------------------- -sal_Bool SAL_CALL OWriteStream::hasByID( const ::rtl::OUString& sID ) - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - try - { - getRelationshipByID( sID ); - return sal_True; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No Element" ) ) ); - } - - return sal_False; -} - -//----------------------------------------------- -::rtl::OUString SAL_CALL OWriteStream::getTargetByID( const ::rtl::OUString& sID ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - uno::Sequence< beans::StringPair > aSeq = getRelationshipByID( sID ); - for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ ) - if ( aSeq[nInd].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Target" ) ) ) - return aSeq[nInd].Second; - - return ::rtl::OUString(); -} - -//----------------------------------------------- -::rtl::OUString SAL_CALL OWriteStream::getTypeByID( const ::rtl::OUString& sID ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - uno::Sequence< beans::StringPair > aSeq = getRelationshipByID( sID ); - for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ ) - if ( aSeq[nInd].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Type" ) ) ) - return aSeq[nInd].Second; - - return ::rtl::OUString(); -} - -//----------------------------------------------- -uno::Sequence< beans::StringPair > SAL_CALL OWriteStream::getRelationshipByID( const ::rtl::OUString& sID ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - // TODO/LATER: in future the unification of the ID could be checked - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ ) - for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ ) - if ( aSeq[nInd1][nInd2].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Id" ) ) ) - { - if ( aSeq[nInd1][nInd2].Second.equals( sID ) ) - return aSeq[nInd1]; - break; - } - - throw container::NoSuchElementException(); -} - -//----------------------------------------------- -uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OWriteStream::getRelationshipsByType( const ::rtl::OUString& sType ) - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - uno::Sequence< uno::Sequence< beans::StringPair > > aResult; - sal_Int32 nEntriesNum = 0; - - // TODO/LATER: in future the unification of the ID could be checked - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ ) - for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ ) - if ( aSeq[nInd1][nInd2].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Type" ) ) ) - { - if ( aSeq[nInd1][nInd2].Second.equals( sType ) ) - { - aResult.realloc( nEntriesNum ); - aResult[nEntriesNum-1] = aSeq[nInd1]; - } - break; - } - - return aResult; -} - -//----------------------------------------------- -uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OWriteStream::getAllRelationships() - throw (io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - return m_pImpl->GetAllRelationshipsIfAny(); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::insertRelationshipByID( const ::rtl::OUString& sID, const uno::Sequence< beans::StringPair >& aEntry, ::sal_Bool bReplace ) - throw ( container::ElementExistException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - ::rtl::OUString aIDTag( RTL_CONSTASCII_USTRINGPARAM( "Id" ) ); - - sal_Int32 nIDInd = -1; - - // TODO/LATER: in future the unification of the ID could be checked - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ ) - for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ ) - if ( aSeq[nInd1][nInd2].First.equals( aIDTag ) ) - { - if ( aSeq[nInd1][nInd2].Second.equals( sID ) ) - nIDInd = nInd1; - - break; - } - - if ( nIDInd == -1 || bReplace ) - { - if ( nIDInd == -1 ) - { - nIDInd = aSeq.getLength(); - aSeq.realloc( nIDInd + 1 ); - } - - aSeq[nIDInd].realloc( aEntry.getLength() + 1 ); - - aSeq[nIDInd][0].First = aIDTag; - aSeq[nIDInd][0].Second = sID; - sal_Int32 nIndTarget = 1; - for ( sal_Int32 nIndOrig = 0; - nIndOrig < aEntry.getLength(); - nIndOrig++ ) - { - if ( !aEntry[nIndOrig].First.equals( aIDTag ) ) - aSeq[nIDInd][nIndTarget++] = aEntry[nIndOrig]; - } - - aSeq[nIDInd].realloc( nIndTarget ); - } - else - throw container::ElementExistException(); // TODO - - - m_pImpl->m_aNewRelInfo = aSeq; - m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED; -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::removeRelationshipByID( const ::rtl::OUString& sID ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ ) - for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ ) - if ( aSeq[nInd1][nInd2].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Id" ) ) ) - { - if ( aSeq[nInd1][nInd2].Second.equals( sID ) ) - { - sal_Int32 nLength = aSeq.getLength(); - aSeq[nInd1] = aSeq[nLength-1]; - aSeq.realloc( nLength - 1 ); - - m_pImpl->m_aNewRelInfo = aSeq; - m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED; - - // TODO/LATER: in future the unification of the ID could be checked - return; - } - - break; - } - - throw container::NoSuchElementException(); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::insertRelationships( const uno::Sequence< uno::Sequence< beans::StringPair > >& aEntries, ::sal_Bool bReplace ) - throw ( container::ElementExistException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - ::rtl::OUString aIDTag( RTL_CONSTASCII_USTRINGPARAM( "Id" ) ); - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - uno::Sequence< uno::Sequence< beans::StringPair > > aResultSeq( aSeq.getLength() + aEntries.getLength() ); - sal_Int32 nResultInd = 0; - - for ( sal_Int32 nIndTarget1 = 0; nIndTarget1 < aSeq.getLength(); nIndTarget1++ ) - for ( sal_Int32 nIndTarget2 = 0; nIndTarget2 < aSeq[nIndTarget1].getLength(); nIndTarget2++ ) - if ( aSeq[nIndTarget1][nIndTarget2].First.equals( aIDTag ) ) - { - sal_Int32 nIndSourceSame = -1; - - for ( sal_Int32 nIndSource1 = 0; nIndSource1 < aEntries.getLength(); nIndSource1++ ) - for ( sal_Int32 nIndSource2 = 0; nIndSource2 < aEntries[nIndSource1].getLength(); nIndSource2++ ) - { - if ( aEntries[nIndSource1][nIndSource2].First.equals( aIDTag ) ) - { - if ( aEntries[nIndSource1][nIndSource2].Second.equals( aSeq[nIndTarget1][nIndTarget2].Second ) ) - { - if ( !bReplace ) - throw container::ElementExistException(); - - nIndSourceSame = nIndSource1; - } - - break; - } - } - - if ( nIndSourceSame == -1 ) - { - // no such element in the provided sequence - aResultSeq[nResultInd++] = aSeq[nIndTarget1]; - } - - break; - } - - for ( sal_Int32 nIndSource1 = 0; nIndSource1 < aEntries.getLength(); nIndSource1++ ) - { - aResultSeq[nResultInd].realloc( aEntries[nIndSource1].getLength() ); - sal_Bool bHasID = sal_False; - sal_Int32 nResInd2 = 1; - - for ( sal_Int32 nIndSource2 = 0; nIndSource2 < aEntries[nIndSource1].getLength(); nIndSource2++ ) - if ( aEntries[nIndSource1][nIndSource2].First.equals( aIDTag ) ) - { - aResultSeq[nResultInd][0] = aEntries[nIndSource1][nIndSource2]; - bHasID = sal_True; - } - else if ( nResInd2 < aResultSeq[nResultInd].getLength() ) - aResultSeq[nResultInd][nResInd2++] = aEntries[nIndSource1][nIndSource2]; - else - throw io::IOException(); // TODO: illegal relation ( no ID ) - - if ( !bHasID ) - throw io::IOException(); // TODO: illegal relations - - nResultInd++; - } - - aResultSeq.realloc( nResultInd ); - m_pImpl->m_aNewRelInfo = aResultSeq; - m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED; -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::clearRelationships() - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException(); - - m_pImpl->m_aNewRelInfo.realloc( 0 ); - m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED; -} - -//----------------------------------------------- -uno::Reference< beans::XPropertySetInfo > SAL_CALL OWriteStream::getPropertySetInfo() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - //TODO: - return uno::Reference< beans::XPropertySetInfo >(); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::setPropertyValue( const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) - throw ( beans::UnknownPropertyException, - beans::PropertyVetoException, - lang::IllegalArgumentException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - m_pImpl->GetStreamProperties(); - ::rtl::OUString aCompressedString( RTL_CONSTASCII_USTRINGPARAM( "Compressed" ) ); - ::rtl::OUString aMediaTypeString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ); - if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE && aPropertyName.equals( aMediaTypeString ) ) - { - // if the "Compressed" property is not set explicitly, the MediaType can change the default value - sal_Bool bCompressedValueFromType = sal_True; - ::rtl::OUString aType; - aValue >>= aType; - - if ( !m_pImpl->m_bCompressedSetExplicit ) - { - if ( aType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "image/jpeg" ) ) ) - || aType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "image/png" ) ) ) - || aType.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "image/gif" ) ) ) ) - bCompressedValueFromType = sal_False; - } - - for ( sal_Int32 nInd = 0; nInd < m_pImpl->m_aProps.getLength(); nInd++ ) - { - if ( aPropertyName.equals( m_pImpl->m_aProps[nInd].Name ) ) - m_pImpl->m_aProps[nInd].Value = aValue; - else if ( !m_pImpl->m_bCompressedSetExplicit && aCompressedString.equals( m_pImpl->m_aProps[nInd].Name ) ) - m_pImpl->m_aProps[nInd].Value <<= bCompressedValueFromType; - } - } - else if ( aPropertyName.equals( aCompressedString ) ) - { - // if the "Compressed" property is not set explicitly, the MediaType can change the default value - m_pImpl->m_bCompressedSetExplicit = sal_True; - for ( sal_Int32 nInd = 0; nInd < m_pImpl->m_aProps.getLength(); nInd++ ) - { - if ( aPropertyName.equals( m_pImpl->m_aProps[nInd].Name ) ) - m_pImpl->m_aProps[nInd].Value = aValue; - } - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE - && aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "UseCommonStoragePasswordEncryption" ) ) ) - { - sal_Bool bUseCommonEncryption = sal_False; - if ( aValue >>= bUseCommonEncryption ) - { - if ( m_bInitOnDemand && m_pImpl->m_bHasInsertedStreamOptimization ) - { - // the data stream is provided to the packagestream directly - m_pImpl->m_bUseCommonEncryption = bUseCommonEncryption; - } - else if ( bUseCommonEncryption ) - { - if ( !m_pImpl->m_bUseCommonEncryption ) - { - m_pImpl->SetDecrypted(); - m_pImpl->m_bUseCommonEncryption = sal_True; - } - } - else - m_pImpl->m_bUseCommonEncryption = sal_False; - } - else - throw lang::IllegalArgumentException(); //TODO - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aPropertyName.equals( aMediaTypeString ) ) - { - for ( sal_Int32 nInd = 0; nInd < m_pImpl->m_aProps.getLength(); nInd++ ) - { - if ( aPropertyName.equals( m_pImpl->m_aProps[nInd].Name ) ) - m_pImpl->m_aProps[nInd].Value = aValue; - } - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RelationsInfoStream" ) ) ) - { - uno::Reference< io::XInputStream > xInRelStream; - if ( ( aValue >>= xInRelStream ) && xInRelStream.is() ) - { - uno::Reference< io::XSeekable > xSeek( xInRelStream, uno::UNO_QUERY ); - if ( !xSeek.is() ) - { - // currently this is an internal property that is used for optimization - // and the stream must support XSeekable interface - // TODO/LATER: in future it can be changed if property is used from outside - throw lang::IllegalArgumentException(); // TODO - } - - m_pImpl->m_xNewRelInfoStream = xInRelStream; - m_pImpl->m_aNewRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >(); - m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED_STREAM; - } - else - throw lang::IllegalArgumentException(); // TODO - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML && aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RelationsInfo" ) ) ) - { - if ( aValue >>= m_pImpl->m_aNewRelInfo ) - { - } - else - throw lang::IllegalArgumentException(); // TODO - } - else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Size" ) ) ) - throw beans::PropertyVetoException(); // TODO - else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE - && ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsEncrypted" ) ) || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Encrypted" ) ) ) ) - throw beans::PropertyVetoException(); // TODO - else - throw beans::UnknownPropertyException(); // TODO - - m_pImpl->m_bHasDataToFlush = sal_True; - ModifyParentUnlockMutex_Impl( aGuard ); -} - - -//----------------------------------------------- -uno::Any SAL_CALL OWriteStream::getPropertyValue( const ::rtl::OUString& aProp ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( aProp.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RelId" ) ) ) - { - return uno::makeAny( m_pImpl->GetNewRelId() ); - } - - ::rtl::OUString aPropertyName; - if ( aProp.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsEncrypted" ) ) ) - aPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Encrypted" ) ); - else - aPropertyName = aProp; - - if ( ( ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE || m_pData->m_nStorageType == embed::StorageFormats::OFOPXML ) - && aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) ) - || ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE && aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Encrypted" ) ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Compressed" ) ) ) - { - m_pImpl->GetStreamProperties(); - - for ( sal_Int32 nInd = 0; nInd < m_pImpl->m_aProps.getLength(); nInd++ ) - { - if ( aPropertyName.equals( m_pImpl->m_aProps[nInd].Name ) ) - return m_pImpl->m_aProps[nInd].Value; - } - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE - && aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "UseCommonStoragePasswordEncryption" ) ) ) - return uno::makeAny( m_pImpl->m_bUseCommonEncryption ); - else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Size" ) ) ) - { - CheckInitOnDemand(); - - if ( !m_xSeekable.is() ) - throw uno::RuntimeException(); - - return uno::makeAny( (sal_Int32)m_xSeekable->getLength() ); - } - - throw beans::UnknownPropertyException(); // TODO -} - - -//----------------------------------------------- -void SAL_CALL OWriteStream::addPropertyChangeListener( - const ::rtl::OUString& /*aPropertyName*/, - const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - //TODO: -} - - -//----------------------------------------------- -void SAL_CALL OWriteStream::removePropertyChangeListener( - const ::rtl::OUString& /*aPropertyName*/, - const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - //TODO: -} - - -//----------------------------------------------- -void SAL_CALL OWriteStream::addVetoableChangeListener( - const ::rtl::OUString& /*PropertyName*/, - const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - //TODO: -} - - -//----------------------------------------------- -void SAL_CALL OWriteStream::removeVetoableChangeListener( - const ::rtl::OUString& /*PropertyName*/, - const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - //TODO: -} - -//____________________________________________________________________________________________________ -// XTransactedObject -//____________________________________________________________________________________________________ - -//----------------------------------------------- -void OWriteStream::BroadcastTransaction( sal_Int8 nMessage ) -/* - 1 - preCommit - 2 - commited - 3 - preRevert - 4 - reverted -*/ -{ - // no need to lock mutex here for the checking of m_pImpl, and m_pData is alive until the object is destructed - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) ); - - ::cppu::OInterfaceContainerHelper* pContainer = - m_pData->m_aListenersContainer.getContainer( - ::getCppuType( ( const uno::Reference< embed::XTransactionListener >*) NULL ) ); - if ( pContainer ) - { - ::cppu::OInterfaceIteratorHelper pIterator( *pContainer ); - while ( pIterator.hasMoreElements( ) ) - { - OSL_ENSURE( nMessage >= 1 && nMessage <= 4, "Wrong internal notification code is used!\n" ); - - switch( nMessage ) - { - case STOR_MESS_PRECOMMIT: - ( ( embed::XTransactionListener* )pIterator.next( ) )->preCommit( aSource ); - break; - case STOR_MESS_COMMITED: - ( ( embed::XTransactionListener* )pIterator.next( ) )->commited( aSource ); - break; - case STOR_MESS_PREREVERT: - ( ( embed::XTransactionListener* )pIterator.next( ) )->preRevert( aSource ); - break; - case STOR_MESS_REVERTED: - ( ( embed::XTransactionListener* )pIterator.next( ) )->reverted( aSource ); - break; - } - } - } -} -//----------------------------------------------- -void SAL_CALL OWriteStream::commit() - throw ( io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OWriteStream::commit" ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_bTransacted ) - throw uno::RuntimeException(); - - try { - BroadcastTransaction( STOR_MESS_PRECOMMIT ); - - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - m_pImpl->Commit(); - - // when the storage is commited the parent is modified - ModifyParentUnlockMutex_Impl( aGuard ); - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Problems on commit!") ), - uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ), - aCaught ); - } - - BroadcastTransaction( STOR_MESS_COMMITED ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::revert() - throw ( io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OWriteStream::revert" ); - - // the method removes all the changes done after last commit - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_bTransacted ) - throw uno::RuntimeException(); - - BroadcastTransaction( STOR_MESS_PREREVERT ); - - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - try { - m_pImpl->Revert(); - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Problems on revert!") ), - uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ), - aCaught ); - } - - aGuard.clear(); - - BroadcastTransaction( STOR_MESS_REVERTED ); -} - -//____________________________________________________________________________________________________ -// XTransactionBroadcaster -//____________________________________________________________________________________________________ - -//----------------------------------------------- -void SAL_CALL OWriteStream::addTransactionListener( const uno::Reference< embed::XTransactionListener >& aListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_bTransacted ) - throw uno::RuntimeException(); - - m_pData->m_aListenersContainer.addInterface( ::getCppuType((const uno::Reference< embed::XTransactionListener >*)0), - aListener ); -} - -//----------------------------------------------- -void SAL_CALL OWriteStream::removeTransactionListener( const uno::Reference< embed::XTransactionListener >& aListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException(); - } - - if ( !m_bTransacted ) - throw uno::RuntimeException(); - - m_pData->m_aListenersContainer.removeInterface( ::getCppuType((const uno::Reference< embed::XTransactionListener >*)0), - aListener ); -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/owriteablestream.hxx b/package/source/xstor/owriteablestream.hxx deleted file mode 100644 index ab5a2c07f..000000000 --- a/package/source/xstor/owriteablestream.hxx +++ /dev/null @@ -1,419 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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. - * - ************************************************************************/ - -#ifndef _WRITESTREAM_HXX_ -#define _WRITESTREAM_HXX_ - -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/io/XOutputStream.hpp> -#include <com/sun/star/io/XStream.hpp> -#include <com/sun/star/io/XSeekable.hpp> -#include <com/sun/star/io/XTruncate.hpp> -#include <com/sun/star/packages/XDataSinkEncrSupport.hpp> -#include <com/sun/star/packages/NoEncryptionException.hpp> -#include <com/sun/star/lang/XEventListener.hpp> -#include <com/sun/star/lang/XSingleServiceFactory.hpp> -#include <com/sun/star/lang/XComponent.hpp> -#include <com/sun/star/embed/XEncryptionProtectedSource2.hpp> -#include <com/sun/star/embed/XStorage.hpp> -#include <com/sun/star/embed/XRelationshipAccess.hpp> -#include <com/sun/star/embed/XExtendedStorageStream.hpp> -#include <com/sun/star/embed/XTransactedObject.hpp> -#include <com/sun/star/embed/XTransactionBroadcaster.hpp> -#include <com/sun/star/container/XNameContainer.hpp> -#include <com/sun/star/beans/StringPair.hpp> -#include <com/sun/star/logging/XSimpleLogRing.hpp> - - -#include <cppuhelper/implbase1.hxx> -#include <cppuhelper/weak.hxx> -#include <cppuhelper/interfacecontainer.h> - -#include <comphelper/sequenceashashmap.hxx> - -#include <list> - -#include "ocompinstream.hxx" -#include "mutexholder.hxx" - - -struct PreCreationStruct -{ - SotMutexHolderRef m_rMutexRef; - - PreCreationStruct() - : m_rMutexRef( new SotMutexHolder ) - {} - -}; - -namespace cppu { - class OTypeCollection; -} - -namespace package { - void StaticAddLog( const ::rtl::OUString& aMessage ); - bool PackageEncryptionDatasEqual( const ::comphelper::SequenceAsHashMap& aHash1, const ::comphelper::SequenceAsHashMap& aHash2 ); -} - -struct WSInternalData_Impl -{ - SotMutexHolderRef m_rSharedMutexRef; - ::cppu::OTypeCollection* m_pTypeCollection; - ::cppu::OMultiTypeInterfaceContainerHelper m_aListenersContainer; // list of listeners - sal_Int32 m_nStorageType; - - // the mutex reference MUST NOT be empty - WSInternalData_Impl( const SotMutexHolderRef rMutexRef, sal_Int32 nStorageType ) - : m_rSharedMutexRef( rMutexRef ) - , m_pTypeCollection( NULL ) - , m_aListenersContainer( rMutexRef->GetMutex() ) - , m_nStorageType( nStorageType ) - {} -}; - -typedef ::std::list< OInputCompStream* > InputStreamsList_Impl; - -struct OStorage_Impl; -class OWriteStream; - -struct OWriteStream_Impl : public PreCreationStruct -{ - friend struct OStorage_Impl; - friend class OWriteStream; - friend class OInputCompStream; - - OWriteStream* m_pAntiImpl; - ::rtl::OUString m_aTempURL; - - ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > m_xCacheStream; - ::com::sun::star::uno::Reference< ::com::sun::star::io::XSeekable > m_xCacheSeek; - - InputStreamsList_Impl m_aInputStreamsList; - - sal_Bool m_bHasDataToFlush; // only modified elements will be sent to the original content - sal_Bool m_bFlushed; // sending the streams is coordinated by the root storage of the package - - ::com::sun::star::uno::Reference< ::com::sun::star::packages::XDataSinkEncrSupport > m_xPackageStream; - ::com::sun::star::uno::Reference< ::com::sun::star::logging::XSimpleLogRing > m_xLogRing; - - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory; - - OStorage_Impl* m_pParent; - - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_aProps; - - sal_Bool m_bForceEncrypted; - - sal_Bool m_bUseCommonEncryption; - sal_Bool m_bHasCachedEncryptionData; - ::comphelper::SequenceAsHashMap m_aEncryptionData; - - sal_Bool m_bCompressedSetExplicit; - - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > m_xPackage; - - sal_Bool m_bHasInsertedStreamOptimization; - - sal_Int32 m_nStorageType; - - // Relations info related data, stored in *.rels file in OFOPXML format - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xOrigRelInfoStream; - ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > m_aOrigRelInfo; - sal_Bool m_bOrigRelInfoBroken; - - ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > m_aNewRelInfo; - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xNewRelInfoStream; - sal_Int16 m_nRelInfoStatus; - sal_Int32 m_nRelId; - - -private: - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > GetServiceFactory(); - - ::rtl::OUString GetFilledTempFileIfNo( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xStream ); - ::rtl::OUString FillTempGetFileName(); - ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > GetTempFileAsStream(); - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetTempFileAsInputStream(); - - ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > GetStream_Impl( sal_Int32 nStreamMode, - sal_Bool bHierarchyAccess ); - - ::comphelper::SequenceAsHashMap GetCommonRootEncryptionData() throw ( ::com::sun::star::packages::NoEncryptionException ); - - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > ReadPackageStreamProperties(); - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > InsertOwnProps( - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps, - sal_Bool bUseCommonEncryption ); - -public: - OWriteStream_Impl( - OStorage_Impl* pParent, - const ::com::sun::star::uno::Reference< ::com::sun::star::packages::XDataSinkEncrSupport >& xPackageStream, - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory >& xPackage, - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, - sal_Bool bForceEncrypted, - sal_Int32 nStorageType, - sal_Bool bDefaultCompress, - const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xRelInfoStream = - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >() ); - - ~OWriteStream_Impl(); - - void CleanCacheStream(); - - void AddLog( const ::rtl::OUString& aMessage ); - - sal_Bool UsesCommonEncryption_Impl() { return m_bUseCommonEncryption; } - sal_Bool HasTempFile_Impl() const { return ( m_aTempURL.getLength() != 0 ); } - sal_Bool IsTransacted(); - - sal_Bool HasWriteOwner_Impl() const { return ( m_pAntiImpl != NULL ); } - - void InsertIntoPackageFolder( - const ::rtl::OUString& aName, - const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& xParentPackageFolder ); - - void SetToBeCommited() { m_bFlushed = sal_True; } - - sal_Bool HasCachedEncryptionData() { return m_bHasCachedEncryptionData; } - ::comphelper::SequenceAsHashMap& GetCachedEncryptionData() { return m_aEncryptionData; } - - sal_Bool IsModified() { return m_bHasDataToFlush || m_bFlushed; } - - sal_Bool IsEncrypted(); - void SetDecrypted(); - void SetEncrypted( const ::comphelper::SequenceAsHashMap& aEncryptionData ); - - void DisposeWrappers(); - - void InsertStreamDirectly( - const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps ); - - void Commit(); - void Revert(); - - void Free( sal_Bool bMust ); // allows to try to disconnect from the temporary stream - // in case bMust is set to sal_True the method - // will throw exception in case the file is still busy - - void SetModified(); // can be done only by parent storage after renaming - - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > GetStreamProperties(); - - ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > GetAllRelationshipsIfAny(); - - void CopyInternallyTo_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xDestStream, - const ::comphelper::SequenceAsHashMap& aEncryptionData ); - void CopyInternallyTo_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xDestStream ); - - ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > GetStream( - sal_Int32 nStreamMode, - const ::comphelper::SequenceAsHashMap& aEncryptionData, - sal_Bool bHierarchyAccess ); - - ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > GetStream( - sal_Int32 nStreamMode, - sal_Bool bHierarchyAccess ); - - - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetRawInStream(); - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetPlainRawInStream(); - - void InputStreamDisposed( OInputCompStream* pStream ); - - void CreateReadonlyCopyBasedOnData( - const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xDataToCopy, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps, - sal_Bool bUseCommonEncryption, - ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xTargetStream ); - - void GetCopyOfLastCommit( ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xTargetStream ); - void GetCopyOfLastCommit( - ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xTargetStream, - const ::comphelper::SequenceAsHashMap& aEncryptionData ); - - - void CommitStreamRelInfo( - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xRelStorage, - const ::rtl::OUString& aOrigStreamName, - const ::rtl::OUString& aNewStreamName ); - - void ReadRelInfoIfNecessary(); - - sal_Int32 GetNewRelId() { return m_nRelId ++; } -}; - -class OWriteStream : ::com::sun::star::lang::XTypeProvider - , public ::com::sun::star::io::XInputStream - , public ::com::sun::star::io::XOutputStream - , public ::com::sun::star::embed::XExtendedStorageStream - , public ::com::sun::star::io::XSeekable - , public ::com::sun::star::io::XTruncate - , public ::com::sun::star::embed::XEncryptionProtectedSource2 - , public ::com::sun::star::embed::XRelationshipAccess - , public ::com::sun::star::embed::XTransactedObject - , public ::com::sun::star::embed::XTransactionBroadcaster - , public ::com::sun::star::beans::XPropertySet - , public ::cppu::OWeakObject -{ - friend struct OWriteStream_Impl; - -protected: - ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > m_xInStream; - ::com::sun::star::uno::Reference < ::com::sun::star::io::XOutputStream > m_xOutStream; - ::com::sun::star::uno::Reference < ::com::sun::star::io::XSeekable > m_xSeekable; - - OWriteStream_Impl* m_pImpl; - WSInternalData_Impl* m_pData; - - sal_Bool m_bInStreamDisconnected; - sal_Bool m_bInitOnDemand; - sal_Int64 m_nInitPosition; - - sal_Bool m_bTransacted; - - OWriteStream( OWriteStream_Impl* pImpl, sal_Bool bTransacted ); - OWriteStream( OWriteStream_Impl* pImpl, ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > xStream, sal_Bool bTransacted ); - - void CloseOutput_Impl(); - - void CopyToStreamInternally_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xStream ); - - void ModifyParentUnlockMutex_Impl( ::osl::ResettableMutexGuard& aGuard ); - - void BroadcastTransaction( sal_Int8 nMessage ); - -public: - - virtual ~OWriteStream(); - - void CheckInitOnDemand(); - void DeInit(); - - // XInterface - virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& rType ) - throw( ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL acquire() throw(); - virtual void SAL_CALL release() throw(); - - // XTypeProvider - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() - throw( ::com::sun::star::uno::RuntimeException ); - virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() - throw( ::com::sun::star::uno::RuntimeException ); - - // XInputStream - virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL available( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL closeInput( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - // XOutputStream - virtual void SAL_CALL writeBytes( const ::com::sun::star::uno::Sequence< sal_Int8 >& aData ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL flush( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL closeOutput( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - //XSeekable - virtual void SAL_CALL seek( sal_Int64 location ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getPosition() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getLength() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - //XStream - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( ) throw (::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL getOutputStream( ) throw (::com::sun::star::uno::RuntimeException); - - // XTruncate - virtual void SAL_CALL truncate() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - //XComponent - virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); - - //XEncryptionProtectedSource - virtual void SAL_CALL setEncryptionPassword( const ::rtl::OUString& aPass ) - throw ( ::com::sun::star::uno::RuntimeException, - ::com::sun::star::io::IOException ); - virtual void SAL_CALL removeEncryption() - throw ( ::com::sun::star::uno::RuntimeException, - ::com::sun::star::io::IOException ); - - //XEncryptionProtectedSource2 - virtual void SAL_CALL setEncryptionData( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - //XRelationshipAccess - virtual ::sal_Bool SAL_CALL hasByID( const ::rtl::OUString& sID ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::rtl::OUString SAL_CALL getTargetByID( const ::rtl::OUString& sID ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::rtl::OUString SAL_CALL getTypeByID( const ::rtl::OUString& sID ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > SAL_CALL getRelationshipByID( const ::rtl::OUString& sID ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > SAL_CALL getRelationshipsByType( const ::rtl::OUString& sType ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > SAL_CALL getAllRelationships( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL insertRelationshipByID( const ::rtl::OUString& sID, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aEntry, ::sal_Bool bReplace ) throw (::com::sun::star::container::ElementExistException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeRelationshipByID( const ::rtl::OUString& sID ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL insertRelationships( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > >& aEntries, ::sal_Bool bReplace ) throw (::com::sun::star::container::ElementExistException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL clearRelationships( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - //XPropertySet - virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() throw ( ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); - virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException ); - - // XTransactedObject - virtual void SAL_CALL commit() - throw ( ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL revert() - throw ( ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - // XTransactionBroadcaster - virtual void SAL_CALL addTransactionListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XTransactionListener >& aListener ) - throw ( ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL removeTransactionListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XTransactionListener >& aListener ) - throw ( ::com::sun::star::uno::RuntimeException ); - -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/register.cxx b/package/source/xstor/register.cxx deleted file mode 100644 index 480a11732..000000000 --- a/package/source/xstor/register.cxx +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" - - -#include <com/sun/star/registry/XRegistryKey.hpp> -#include <com/sun/star/registry/InvalidRegistryException.hpp> -#include <cppuhelper/factory.hxx> - -#include "xfactory.hxx" - -using namespace ::com::sun::star; - - -extern "C" { - -SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ ) -{ - void * pRet = 0; - - ::rtl::OUString aImplName( ::rtl::OUString::createFromAscii( pImplName ) ); - uno::Reference< lang::XSingleServiceFactory > xFactory; - - if ( pServiceManager && aImplName.equals( OStorageFactory::impl_staticGetImplementationName() ) ) - { - xFactory= ::cppu::createOneInstanceFactory( reinterpret_cast< lang::XMultiServiceFactory*>( pServiceManager ), - OStorageFactory::impl_staticGetImplementationName(), - OStorageFactory::impl_staticCreateSelfInstance, - OStorageFactory::impl_staticGetSupportedServiceNames() ); - } - - if ( xFactory.is() ) - { - xFactory->acquire(); - pRet = xFactory.get(); - } - - return pRet; -} - -} // extern "C" - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/selfterminatefilestream.cxx b/package/source/xstor/selfterminatefilestream.cxx deleted file mode 100644 index 3a2dd7530..000000000 --- a/package/source/xstor/selfterminatefilestream.cxx +++ /dev/null @@ -1,155 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" - -#include <com/sun/star/ucb/XSimpleFileAccess.hpp> - -#include "selfterminatefilestream.hxx" -#include <comphelper/processfactory.hxx> - -using namespace ::com::sun::star; - -//----------------------------------------------- -OSelfTerminateFileStream::OSelfTerminateFileStream( const uno::Reference< lang::XMultiServiceFactory > xFactory, const ::rtl::OUString& aURL ) -: m_aURL( aURL ) -{ - uno::Reference< lang::XMultiServiceFactory > xOwnFactory = xFactory; - if ( !xOwnFactory.is() ) - xOwnFactory.set( ::comphelper::getProcessServiceFactory(), uno::UNO_SET_THROW ); - - // IMPORTANT: The implementation is based on idea that m_xFileAccess, m_xInputStream and m_xSeekable are always set - // otherwise an exception is thrown in constructor - - m_xFileAccess.set( xOwnFactory->createInstance ( - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess") ) ), - uno::UNO_QUERY_THROW ); - - m_xInputStream.set( m_xFileAccess->openFileRead( aURL ), uno::UNO_SET_THROW ); - m_xSeekable.set( m_xInputStream, uno::UNO_QUERY_THROW ); -} - -//----------------------------------------------- -OSelfTerminateFileStream::~OSelfTerminateFileStream() -{ - CloseStreamDeleteFile(); -} - -//----------------------------------------------- -void OSelfTerminateFileStream::CloseStreamDeleteFile() -{ - try - { - m_xInputStream->closeInput(); - } - catch( uno::Exception& ) - {} - - try - { - m_xFileAccess->kill( m_aURL ); - } - catch( uno::Exception& ) - {} -} - -//----------------------------------------------- -sal_Int32 SAL_CALL OSelfTerminateFileStream::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - return m_xInputStream->readBytes( aData, nBytesToRead ); -} - -//----------------------------------------------- -sal_Int32 SAL_CALL OSelfTerminateFileStream::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - return m_xInputStream->readSomeBytes( aData, nMaxBytesToRead ); -} - -//----------------------------------------------- -void SAL_CALL OSelfTerminateFileStream::skipBytes( sal_Int32 nBytesToSkip ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - return m_xInputStream->skipBytes( nBytesToSkip ); -} - -//----------------------------------------------- -sal_Int32 SAL_CALL OSelfTerminateFileStream::available( ) - throw ( io::NotConnectedException, - io::IOException, - uno::RuntimeException ) -{ - return m_xInputStream->available(); -} - -//----------------------------------------------- -void SAL_CALL OSelfTerminateFileStream::closeInput( ) - throw ( io::NotConnectedException, - io::IOException, - uno::RuntimeException ) -{ - CloseStreamDeleteFile(); -} - -//----------------------------------------------- -void SAL_CALL OSelfTerminateFileStream::seek( sal_Int64 location ) - throw ( lang::IllegalArgumentException, - io::IOException, - uno::RuntimeException ) -{ - m_xSeekable->seek( location ); -} - -//----------------------------------------------- -sal_Int64 SAL_CALL OSelfTerminateFileStream::getPosition() - throw ( io::IOException, - uno::RuntimeException) -{ - return m_xSeekable->getPosition(); -} - -//----------------------------------------------- -sal_Int64 SAL_CALL OSelfTerminateFileStream::getLength() - throw ( io::IOException, - uno::RuntimeException ) -{ - return m_xSeekable->getLength(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/selfterminatefilestream.hxx b/package/source/xstor/selfterminatefilestream.hxx deleted file mode 100644 index a9d28f0a6..000000000 --- a/package/source/xstor/selfterminatefilestream.hxx +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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. - * - ************************************************************************/ - -#ifndef _SELFTERMINATEFILESTREAM_HXX_ -#define _SELFTERMINATEFILESTREAM_HXX_ - -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/io/XSeekable.hpp> -#include <com/sun/star/ucb/XSimpleFileAccess.hpp> -#include <cppuhelper/implbase2.hxx> - -struct OWriteStream_Impl; - -class OSelfTerminateFileStream : public cppu::WeakImplHelper2< ::com::sun::star::io::XInputStream, - ::com::sun::star::io::XSeekable > -{ -protected: - ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > m_xFileAccess; - - ::rtl::OUString m_aURL; - - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xInputStream; - ::com::sun::star::uno::Reference< ::com::sun::star::io::XSeekable > m_xSeekable; - -public: - OSelfTerminateFileStream( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory, const ::rtl::OUString& aURL ); - - virtual ~OSelfTerminateFileStream(); - - void CloseStreamDeleteFile(); - - // XInputStream - virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL available() - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL closeInput() - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - //XSeekable - virtual void SAL_CALL seek( sal_Int64 location ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getPosition() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getLength() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/switchpersistencestream.cxx b/package/source/xstor/switchpersistencestream.cxx deleted file mode 100644 index a03e63892..000000000 --- a/package/source/xstor/switchpersistencestream.cxx +++ /dev/null @@ -1,490 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <osl/diagnose.h> - -#include <comphelper/storagehelper.hxx> -#include <switchpersistencestream.hxx> - -using namespace ::com::sun::star; - -// ======================================================================== -struct SPStreamData_Impl -{ - uno::Reference< lang::XMultiServiceFactory > m_xFactory; - - sal_Bool m_bInStreamBased; - - // the streams below are not visible from outside so there is no need to remember position - - // original stream related members - uno::Reference< io::XStream > m_xOrigStream; - uno::Reference< io::XTruncate > m_xOrigTruncate; - uno::Reference< io::XSeekable > m_xOrigSeekable; - uno::Reference< io::XInputStream > m_xOrigInStream; - uno::Reference< io::XOutputStream > m_xOrigOutStream; - - sal_Bool m_bInOpen; - sal_Bool m_bOutOpen; - - - SPStreamData_Impl( - const uno::Reference< lang::XMultiServiceFactory >& xFactory, - sal_Bool bInStreamBased, - const uno::Reference< io::XStream >& xOrigStream, - const uno::Reference< io::XTruncate >& xOrigTruncate, - const uno::Reference< io::XSeekable >& xOrigSeekable, - const uno::Reference< io::XInputStream >& xOrigInStream, - const uno::Reference< io::XOutputStream >& xOrigOutStream, - sal_Bool bInOpen, - sal_Bool bOutOpen ) - : m_xFactory( xFactory ) - , m_bInStreamBased( bInStreamBased ) - , m_xOrigStream( xOrigStream ) - , m_xOrigTruncate( xOrigTruncate ) - , m_xOrigSeekable( xOrigSeekable ) - , m_xOrigInStream( xOrigInStream ) - , m_xOrigOutStream( xOrigOutStream ) - , m_bInOpen( bInOpen ) - , m_bOutOpen( bOutOpen ) - { - } -}; - -// ======================================================================== -// ------------------------------------------------------------------------ -SwitchablePersistenceStream::SwitchablePersistenceStream( - const uno::Reference< lang::XMultiServiceFactory >& xFactory, - const uno::Reference< io::XStream >& xStream ) -: m_xFactory( xFactory ) -, m_pStreamData( NULL ) -{ - SwitchPersistenceTo( xStream ); -} - -// ------------------------------------------------------------------------ -SwitchablePersistenceStream::SwitchablePersistenceStream( - const uno::Reference< lang::XMultiServiceFactory >& xFactory, - const uno::Reference< io::XInputStream >& xInputStream ) -: m_xFactory( xFactory ) -, m_pStreamData( NULL ) -{ - SwitchPersistenceTo( xInputStream ); -} - -// ------------------------------------------------------------------------ -SwitchablePersistenceStream::~SwitchablePersistenceStream() -{ - CloseAll_Impl(); -} - -// ------------------------------------------------------------------------ -void SwitchablePersistenceStream::SwitchPersistenceTo( const uno::Reference< io::XStream >& xStream ) -{ - uno::Reference< io::XTruncate > xNewTruncate( xStream, uno::UNO_QUERY_THROW ); - uno::Reference< io::XSeekable > xNewSeekable( xStream, uno::UNO_QUERY_THROW ); - uno::Reference< io::XInputStream > xNewInStream = xStream->getInputStream(); - uno::Reference< io::XOutputStream > xNewOutStream = xStream->getOutputStream(); - if ( !xNewInStream.is() || !xNewOutStream.is() ) - throw uno::RuntimeException(); - - sal_Int64 nPos = 0; - sal_Bool bInOpen = sal_False; - sal_Bool bOutOpen = sal_False; - - if ( m_pStreamData && m_pStreamData->m_xOrigSeekable.is() ) - { - // check that the length is the same - if ( m_pStreamData->m_xOrigSeekable->getLength() != xNewSeekable->getLength() ) - throw uno::RuntimeException(); - - // get the current position - nPos = m_pStreamData->m_xOrigSeekable->getPosition(); - bInOpen = m_pStreamData->m_bInOpen; - bOutOpen = m_pStreamData->m_bOutOpen; - } - - xNewSeekable->seek( nPos ); - - CloseAll_Impl(); - - m_pStreamData = new SPStreamData_Impl( m_xFactory, sal_False, - xStream, xNewTruncate, xNewSeekable, xNewInStream, xNewOutStream, - bInOpen, bOutOpen ); -} - -// ------------------------------------------------------------------------ -void SwitchablePersistenceStream::SwitchPersistenceTo( const uno::Reference< io::XInputStream >& xInputStream ) -{ - uno::Reference< io::XStream > xNewStream; - uno::Reference< io::XTruncate > xNewTruncate; - uno::Reference< io::XSeekable > xNewSeekable( xInputStream, uno::UNO_QUERY_THROW ); - uno::Reference< io::XOutputStream > xNewOutStream; - if ( !xInputStream.is() ) - throw uno::RuntimeException(); - - sal_Int64 nPos = 0; - sal_Bool bInOpen = sal_False; - sal_Bool bOutOpen = sal_False; - - if ( m_pStreamData && m_pStreamData->m_xOrigSeekable.is() ) - { - // check that the length is the same - if ( m_pStreamData->m_xOrigSeekable->getLength() != xNewSeekable->getLength() ) - throw uno::RuntimeException(); - - // get the current position - nPos = m_pStreamData->m_xOrigSeekable->getPosition(); - bInOpen = m_pStreamData->m_bInOpen; - bOutOpen = m_pStreamData->m_bOutOpen; - } - - xNewSeekable->seek( nPos ); - - CloseAll_Impl(); - - m_pStreamData = new SPStreamData_Impl( m_xFactory, sal_True, - xNewStream, xNewTruncate, xNewSeekable, xInputStream, xNewOutStream, - bInOpen, bOutOpen ); - -} - -// ------------------------------------------------------------------------ -void SwitchablePersistenceStream::CopyAndSwitchPersistenceTo( const uno::Reference< io::XStream >& xStream ) -{ - uno::Reference< io::XStream > xTargetStream = xStream; - uno::Reference< io::XSeekable > xTargetSeek; - - if ( !xTargetStream.is() ) - { - xTargetStream = uno::Reference < io::XStream >( - m_xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.TempFile") ) ), - uno::UNO_QUERY_THROW ); - - xTargetSeek = uno::Reference< io::XSeekable >( xTargetStream, uno::UNO_QUERY_THROW ); - } - else - { - // the provided stream must be empty - xTargetSeek = uno::Reference< io::XSeekable >( xTargetStream, uno::UNO_QUERY_THROW ); - if ( xTargetSeek->getLength() ) - throw io::IOException(); - } - - uno::Reference< io::XTruncate > xTargetTruncate( xTargetStream, uno::UNO_QUERY_THROW ); - uno::Reference< io::XInputStream > xTargetInStream = xTargetStream->getInputStream(); - uno::Reference< io::XOutputStream > xTargetOutStream = xTargetStream->getOutputStream(); - if ( !xTargetInStream.is() || !xTargetOutStream.is() ) - throw uno::RuntimeException(); - - if ( !m_pStreamData->m_xOrigInStream.is() || !m_pStreamData->m_xOrigSeekable.is() ) - throw uno::RuntimeException(); - - sal_Int64 nPos = m_pStreamData->m_xOrigSeekable->getPosition(); - m_pStreamData->m_xOrigSeekable->seek( 0 ); - ::comphelper::OStorageHelper::CopyInputToOutput( m_pStreamData->m_xOrigInStream, xTargetOutStream ); - xTargetOutStream->flush(); - xTargetSeek->seek( nPos ); - - sal_Bool bInOpen = m_pStreamData->m_bInOpen; - sal_Bool bOutOpen = m_pStreamData->m_bOutOpen; - - CloseAll_Impl(); - - m_pStreamData = new SPStreamData_Impl( m_xFactory, sal_False, - xTargetStream, xTargetTruncate, xTargetSeek, xTargetInStream, xTargetOutStream, - bInOpen, bOutOpen ); -} - -// ------------------------------------------------------------------------ -void SwitchablePersistenceStream::CloseAll_Impl() -{ - if ( m_pStreamData ) - { - delete m_pStreamData; - m_pStreamData = NULL; - } -} - -// com::sun::star::io::XStream -// ------------------------------------------------------------------------ -uno::Reference< io::XInputStream > SAL_CALL SwitchablePersistenceStream::getInputStream( ) - throw (uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_pStreamData ) - m_pStreamData->m_bInOpen = sal_True; - return static_cast< io::XInputStream* >( this ); -} - - -// ------------------------------------------------------------------------ -uno::Reference< io::XOutputStream > SAL_CALL SwitchablePersistenceStream::getOutputStream( ) - throw (uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_pStreamData ) - m_pStreamData->m_bOutOpen = sal_True; - return static_cast< io::XOutputStream* >( this ); -} - - - -// com::sun::star::io::XInputStream -// ------------------------------------------------------------------------ -::sal_Int32 SAL_CALL SwitchablePersistenceStream::readBytes( uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nBytesToRead ) - throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigInStream.is() ) - throw uno::RuntimeException(); - - return m_pStreamData->m_xOrigInStream->readBytes( aData, nBytesToRead ); -} - - -// ------------------------------------------------------------------------ -::sal_Int32 SAL_CALL SwitchablePersistenceStream::readSomeBytes( uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nMaxBytesToRead ) - throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigInStream.is() ) - throw uno::RuntimeException(); - - return m_pStreamData->m_xOrigInStream->readBytes( aData, nMaxBytesToRead ); -} - -// ------------------------------------------------------------------------ -void SAL_CALL SwitchablePersistenceStream::skipBytes( ::sal_Int32 nBytesToSkip ) - throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigInStream.is() ) - throw uno::RuntimeException(); - - m_pStreamData->m_xOrigInStream->skipBytes( nBytesToSkip ); -} - - -// ------------------------------------------------------------------------ -::sal_Int32 SAL_CALL SwitchablePersistenceStream::available( ) - throw (io::NotConnectedException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigInStream.is() ) - throw uno::RuntimeException(); - - return m_pStreamData->m_xOrigInStream->available(); -} - - -// ------------------------------------------------------------------------ -void SAL_CALL SwitchablePersistenceStream::closeInput() - throw (io::NotConnectedException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - m_pStreamData->m_bInOpen = sal_False; - if ( !m_pStreamData->m_bOutOpen ) - CloseAll_Impl(); -} - - - -// com::sun::star::io::XOutputStream -// ------------------------------------------------------------------------ -void SAL_CALL SwitchablePersistenceStream::writeBytes( const uno::Sequence< ::sal_Int8 >& aData ) - throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - if ( m_pStreamData->m_bInStreamBased ) - throw io::IOException(); - - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigOutStream.is() ) - throw uno::RuntimeException(); - - m_pStreamData->m_xOrigOutStream->writeBytes( aData ); -} - - -// ------------------------------------------------------------------------ -void SAL_CALL SwitchablePersistenceStream::flush( ) - throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData || m_pStreamData->m_bInStreamBased ) - { - OSL_FAIL( "flush() is not acceptable!\n" ); - return; - // in future throw exception, for now some code might call flush() on closed stream - // since file ucp implementation allows it - // throw io::NotConnectedException(); - } - - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigOutStream.is() ) - throw uno::RuntimeException(); - - m_pStreamData->m_xOrigOutStream->flush(); -} - - -// ------------------------------------------------------------------------ -void SAL_CALL SwitchablePersistenceStream::closeOutput( ) - throw (io::NotConnectedException, io::BufferSizeExceededException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - m_pStreamData->m_bOutOpen = sal_False; - if ( !m_pStreamData->m_bInOpen ) - CloseAll_Impl(); -} - - - -// com::sun::star::io::XTruncate -// ------------------------------------------------------------------------ -void SAL_CALL SwitchablePersistenceStream::truncate( ) - throw (io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - if ( m_pStreamData->m_bInStreamBased ) - throw io::IOException(); - - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigTruncate.is() ) - throw uno::RuntimeException(); - - m_pStreamData->m_xOrigTruncate->truncate(); -} - - -// com::sun::star::io::XSeekable -// ------------------------------------------------------------------------ -void SAL_CALL SwitchablePersistenceStream::seek( ::sal_Int64 location ) - throw (lang::IllegalArgumentException, io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigSeekable.is() ) - throw uno::RuntimeException(); - - m_pStreamData->m_xOrigSeekable->seek( location ); -} - - -// ------------------------------------------------------------------------ -::sal_Int64 SAL_CALL SwitchablePersistenceStream::getPosition( ) - throw (io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigSeekable.is() ) - throw uno::RuntimeException(); - - return m_pStreamData->m_xOrigSeekable->getPosition(); -} - - -// ------------------------------------------------------------------------ -::sal_Int64 SAL_CALL SwitchablePersistenceStream::getLength( ) - throw (io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - // the original stream data should be provided - if ( !m_pStreamData->m_xOrigSeekable.is() ) - throw uno::RuntimeException(); - - return m_pStreamData->m_xOrigSeekable->getLength(); -} - -// ------------------------------------------------------------------------ -void SAL_CALL SwitchablePersistenceStream::waitForCompletion() - throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) -{ - if ( !m_pStreamData ) - throw io::NotConnectedException(); - - uno::Reference< io::XAsyncOutputMonitor > asyncOutputMonitor( m_pStreamData->m_xOrigOutStream, uno::UNO_QUERY ); - if ( asyncOutputMonitor.is() ) - asyncOutputMonitor->waitForCompletion(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/switchpersistencestream.hxx b/package/source/xstor/switchpersistencestream.hxx deleted file mode 100644 index 730aca1bf..000000000 --- a/package/source/xstor/switchpersistencestream.hxx +++ /dev/null @@ -1,122 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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. - * - ************************************************************************/ -#ifndef _SPSTREAM_HXX -#define _SPSTREAM_HXX - -#include <com/sun/star/uno/Sequence.hxx> -#include <com/sun/star/uno/Reference.hxx> -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/io/XOutputStream.hpp> -#include <com/sun/star/io/XSeekable.hpp> -#include <com/sun/star/io/XTruncate.hpp> -#include <com/sun/star/io/XStream.hpp> -#include <com/sun/star/embed/XTransactedObject.hpp> -#include <com/sun/star/beans/XPropertySetInfo.hpp> -#include <com/sun/star/beans/XPropertySet.hpp> -#include <com/sun/star/ucb/XSimpleFileAccess.hpp> -#include <com/sun/star/io/XAsyncOutputMonitor.hpp> -#include <osl/mutex.hxx> -#include <cppuhelper/implbase6.hxx> - -//================================================================== -// SwitchablePersistenceStream -// -// Allows to switch the stream persistence on the fly. The target -// stream ( if not filled by the implementation ) MUST have the same -// size as the original one! -//================================================================== - -struct SPStreamData_Impl; -class SwitchablePersistenceStream - : public ::cppu::WeakImplHelper6 < - ::com::sun::star::io::XStream, - ::com::sun::star::io::XInputStream, - ::com::sun::star::io::XOutputStream, - ::com::sun::star::io::XTruncate, - ::com::sun::star::io::XSeekable, - ::com::sun::star::io::XAsyncOutputMonitor > -{ - ::osl::Mutex m_aMutex; - - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory; - - SPStreamData_Impl* m_pStreamData; - - void CloseAll_Impl(); - -public: - - SwitchablePersistenceStream( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, - const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xStream ); - - SwitchablePersistenceStream( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory, - const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream ); - - ~SwitchablePersistenceStream(); - - void SwitchPersistenceTo( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xStream ); - - void SwitchPersistenceTo( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInputStream ); - - void CopyAndSwitchPersistenceTo( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xStream ); - -// com::sun::star::io::XStream - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( ) throw (::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL getOutputStream( ) throw (::com::sun::star::uno::RuntimeException); - -// com::sun::star::io::XInputStream - virtual ::sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nBytesToRead ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData, ::sal_Int32 nMaxBytesToRead ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL skipBytes( ::sal_Int32 nBytesToSkip ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::sal_Int32 SAL_CALL available( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL closeInput( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - -// com::sun::star::io::XOutputStream - virtual void SAL_CALL writeBytes( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aData ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL flush( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL closeOutput( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - -// com::sun::star::io::XTruncate - virtual void SAL_CALL truncate( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - -// com::sun::star::io::XSeekable - virtual void SAL_CALL seek( ::sal_Int64 location ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::sal_Int64 SAL_CALL getPosition( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual ::sal_Int64 SAL_CALL getLength( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - -// ::com::sun::star::io::XAsyncOutputMonitor - virtual void SAL_CALL waitForCompletion( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - -}; - -#endif //_SPSTREAM_HXX - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/xfactory.cxx b/package/source/xstor/xfactory.cxx deleted file mode 100644 index 3ab16c53c..000000000 --- a/package/source/xstor/xfactory.cxx +++ /dev/null @@ -1,326 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <com/sun/star/ucb/XSimpleFileAccess.hpp> -#include <com/sun/star/embed/ElementModes.hpp> -#include <com/sun/star/embed/StorageFormats.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/io/XSeekable.hpp> - -#include <comphelper/storagehelper.hxx> - -#include "xfactory.hxx" -#include "xstorage.hxx" - - -using namespace ::com::sun::star; - -//------------------------------------------------------------------------- -sal_Bool CheckPackageSignature_Impl( const uno::Reference< io::XInputStream >& xInputStream, - const uno::Reference< io::XSeekable >& xSeekable ) -{ - if ( !xInputStream.is() || !xSeekable.is() ) - throw uno::RuntimeException(); - - if ( xSeekable->getLength() ) - { - uno::Sequence< sal_Int8 > aData( 4 ); - xSeekable->seek( 0 ); - sal_Int32 nRead = xInputStream->readBytes( aData, 4 ); - xSeekable->seek( 0 ); - - // TODO/LATER: should the disk spanned files be supported? - // 0x50, 0x4b, 0x07, 0x08 - return ( nRead == 4 && aData[0] == 0x50 && aData[1] == 0x4b && aData[2] == 0x03 && aData[3] == 0x04 ); - } - else - return sal_True; // allow to create a storage based on empty stream -} - -//------------------------------------------------------------------------- -uno::Sequence< ::rtl::OUString > SAL_CALL OStorageFactory::impl_staticGetSupportedServiceNames() -{ - uno::Sequence< ::rtl::OUString > aRet(2); - aRet[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.StorageFactory") ); - aRet[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.embed.StorageFactory") ); - return aRet; -} - -//------------------------------------------------------------------------- -::rtl::OUString SAL_CALL OStorageFactory::impl_staticGetImplementationName() -{ - return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.embed.StorageFactory") ); -} - -//------------------------------------------------------------------------- -uno::Reference< uno::XInterface > SAL_CALL OStorageFactory::impl_staticCreateSelfInstance( - const uno::Reference< lang::XMultiServiceFactory >& xServiceManager ) -{ - return uno::Reference< uno::XInterface >( *new OStorageFactory( xServiceManager ) ); -} - -//------------------------------------------------------------------------- -uno::Reference< uno::XInterface > SAL_CALL OStorageFactory::createInstance() - throw ( uno::Exception, - uno::RuntimeException ) -{ - // TODO: reimplement TempStream service to support XStream interface - uno::Reference < io::XStream > xTempStream( - m_xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.TempFile") ) ), - uno::UNO_QUERY ); - - if ( !xTempStream.is() ) - throw uno::RuntimeException(); // TODO: - - return uno::Reference< uno::XInterface >( - static_cast< OWeakObject* >( new OStorage( xTempStream, - embed::ElementModes::READWRITE, - uno::Sequence< beans::PropertyValue >(), - m_xFactory, - embed::StorageFormats::PACKAGE ) ), - uno::UNO_QUERY ); -} - -//------------------------------------------------------------------------- -uno::Reference< uno::XInterface > SAL_CALL OStorageFactory::createInstanceWithArguments( - const uno::Sequence< uno::Any >& aArguments ) - throw ( uno::Exception, - uno::RuntimeException ) -{ - // The request for storage can be done with up to three arguments - - // The first argument specifies a source for the storage - // it can be URL, XStream, XInputStream. - // The second value is a mode the storage should be open in. - // And the third value is a media descriptor. - - sal_Int32 nArgNum = aArguments.getLength(); - OSL_ENSURE( nArgNum < 4, "Wrong parameter number" ); - - if ( !nArgNum ) - return createInstance(); - - // first try to retrieve storage open mode if any - // by default the storage will be open in readonly mode - sal_Int32 nStorageMode = embed::ElementModes::READ; - if ( nArgNum >= 2 ) - { - if( !( aArguments[1] >>= nStorageMode ) ) - { - OSL_FAIL( "Wrong second argument!\n" ); - throw lang::IllegalArgumentException(); // TODO: - } - // it's allways possible to read written storage in this implementation - nStorageMode |= embed::ElementModes::READ; - } - - if ( ( nStorageMode & embed::ElementModes::TRUNCATE ) == embed::ElementModes::TRUNCATE - && ( nStorageMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE ) - throw lang::IllegalArgumentException(); // TODO: - - // retrieve storage source stream - ::rtl::OUString aURL; - uno::Reference< io::XStream > xStream; - uno::Reference< io::XInputStream > xInputStream; - - if ( aArguments[0] >>= aURL ) - { - if ( !aURL.getLength() ) - { - OSL_FAIL( "Empty URL is provided!\n" ); - throw lang::IllegalArgumentException(); // TODO: - } - - if ( aURL.equalsIgnoreAsciiCaseAsciiL( "vnd.sun.star.pkg", 16 ) ) - { - OSL_FAIL( "Packages URL's are not valid for storages!\n" ); // ??? - throw lang::IllegalArgumentException(); // TODO: - } - - uno::Reference < ::com::sun::star::ucb::XSimpleFileAccess > xTempAccess( - m_xFactory->createInstance ( - ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess") ) ), - uno::UNO_QUERY ); - - if ( !xTempAccess.is() ) - throw uno::RuntimeException(); // TODO: - - if ( nStorageMode & embed::ElementModes::WRITE ) - xStream = xTempAccess->openFileReadWrite( aURL ); - else - xInputStream = xTempAccess->openFileRead( aURL ); - } - else if ( !( aArguments[0] >>= xStream ) && !( aArguments[0] >>= xInputStream ) ) - { - OSL_FAIL( "Wrong first argument!\n" ); - throw uno::Exception(); // TODO: Illegal argument - } - - // retrieve mediadescriptor and set storage properties - uno::Sequence< beans::PropertyValue > aDescr; - uno::Sequence< beans::PropertyValue > aPropsToSet; - - sal_Int32 nStorageType = embed::StorageFormats::PACKAGE; - - if ( nArgNum >= 3 ) - { - if( aArguments[2] >>= aDescr ) - { - if ( aURL.getLength() ) - { - aPropsToSet.realloc(1); - aPropsToSet[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("URL") ); - aPropsToSet[0].Value <<= aURL; - } - - for ( sal_Int32 nInd = 0, nNumArgs = 1; nInd < aDescr.getLength(); nInd++ ) - { - if ( aDescr[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "InteractionHandler" ) ) - || aDescr[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Password" ) ) - || aDescr[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RepairPackage" ) ) - || aDescr[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "StatusIndicator" ) ) ) - // || aDescr[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Unpacked" ) ) // TODO: - { - aPropsToSet.realloc( ++nNumArgs ); - aPropsToSet[nNumArgs-1].Name = aDescr[nInd].Name; - aPropsToSet[nNumArgs-1].Value = aDescr[nInd].Value; - } - else if ( aDescr[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "StorageFormat" ) ) ) - { - ::rtl::OUString aFormatName; - sal_Int32 nFormatID = 0; - if ( aDescr[nInd].Value >>= aFormatName ) - { - if ( aFormatName.equals( PACKAGE_STORAGE_FORMAT_STRING ) ) - nStorageType = embed::StorageFormats::PACKAGE; - else if ( aFormatName.equals( ZIP_STORAGE_FORMAT_STRING ) ) - nStorageType = embed::StorageFormats::ZIP; - else if ( aFormatName.equals( OFOPXML_STORAGE_FORMAT_STRING ) ) - nStorageType = embed::StorageFormats::OFOPXML; - else - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - } - else if ( aDescr[nInd].Value >>= nFormatID ) - { - if ( nFormatID != embed::StorageFormats::PACKAGE - && nFormatID != embed::StorageFormats::ZIP - && nFormatID != embed::StorageFormats::OFOPXML ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - - nStorageType = nFormatID; - } - else - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - } - else - OSL_FAIL( "Unacceptable property, will be ignored!\n" ); - } - } - else - { - OSL_FAIL( "Wrong third argument!\n" ); - throw uno::Exception(); // TODO: Illegal argument - } - - } - - // create storage based on source - if ( xInputStream.is() ) - { - // if xInputStream is set the storage should be open from it - if ( ( nStorageMode & embed::ElementModes::WRITE ) ) - throw uno::Exception(); // TODO: access denied - - uno::Reference< io::XSeekable > xSeekable( xInputStream, uno::UNO_QUERY ); - if ( !xSeekable.is() ) - { - // TODO: wrap stream to let it be seekable - OSL_FAIL( "Nonseekable streams are not supported for now!\n" ); - } - - if ( !CheckPackageSignature_Impl( xInputStream, xSeekable ) ) - throw io::IOException(); // TODO: this is not a package file - - return uno::Reference< uno::XInterface >( - static_cast< OWeakObject* >( new OStorage( xInputStream, nStorageMode, aPropsToSet, m_xFactory, nStorageType ) ), - uno::UNO_QUERY ); - } - else if ( xStream.is() ) - { - if ( ( ( nStorageMode & embed::ElementModes::WRITE ) && !xStream->getOutputStream().is() ) - || !xStream->getInputStream().is() ) - throw uno::Exception(); // TODO: access denied - - uno::Reference< io::XSeekable > xSeekable( xStream, uno::UNO_QUERY ); - if ( !xSeekable.is() ) - { - // TODO: wrap stream to let it be seekable - OSL_FAIL( "Nonseekable streams are not supported for now!\n" ); - } - - if ( !CheckPackageSignature_Impl( xStream->getInputStream(), xSeekable ) ) - throw io::IOException(); // TODO: this is not a package file - - return uno::Reference< uno::XInterface >( - static_cast< OWeakObject* >( new OStorage( xStream, nStorageMode, aPropsToSet, m_xFactory, nStorageType ) ), - uno::UNO_QUERY ); - } - - throw uno::Exception(); // general error during creation -} - -//------------------------------------------------------------------------- -::rtl::OUString SAL_CALL OStorageFactory::getImplementationName() - throw ( uno::RuntimeException ) -{ - return impl_staticGetImplementationName(); -} - -//------------------------------------------------------------------------- -sal_Bool SAL_CALL OStorageFactory::supportsService( const ::rtl::OUString& ServiceName ) - throw ( uno::RuntimeException ) -{ - uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames(); - - for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ ) - if ( ServiceName.compareTo( aSeq[nInd] ) == 0 ) - return sal_True; - - return sal_False; -} - -//------------------------------------------------------------------------- -uno::Sequence< ::rtl::OUString > SAL_CALL OStorageFactory::getSupportedServiceNames() - throw ( uno::RuntimeException ) -{ - return impl_staticGetSupportedServiceNames(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/xfactory.hxx b/package/source/xstor/xfactory.hxx deleted file mode 100644 index 0a6a5fad7..000000000 --- a/package/source/xstor/xfactory.hxx +++ /dev/null @@ -1,76 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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. - * - ************************************************************************/ - -#ifndef __XFACTORY_HXX_ -#define __XFACTORY_HXX_ - -#include <com/sun/star/lang/XSingleServiceFactory.hpp> -#include <com/sun/star/lang/XServiceInfo.hpp> - - -#include <cppuhelper/implbase2.hxx> - - -class OStorage; - -class OStorageFactory : public ::cppu::WeakImplHelper2< ::com::sun::star::lang::XSingleServiceFactory, - ::com::sun::star::lang::XServiceInfo > -{ - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory; - -public: - OStorageFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory ) - : m_xFactory( xFactory ) - { - OSL_ENSURE( xFactory.is(), "No service manager is provided!\n" ); - } - - static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL - impl_staticGetSupportedServiceNames(); - - static ::rtl::OUString SAL_CALL impl_staticGetImplementationName(); - - static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL - impl_staticCreateSelfInstance( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ); - - - // XSingleServiceFactory - virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance() throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceWithArguments( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); - - // XServiceInfo - virtual ::rtl::OUString SAL_CALL getImplementationName() throw (::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (::com::sun::star::uno::RuntimeException); - -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/xstor.component b/package/source/xstor/xstor.component deleted file mode 100644 index f338d6a54..000000000 --- a/package/source/xstor/xstor.component +++ /dev/null @@ -1,35 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!--********************************************************************** -* -* 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. -* -**********************************************************************--> - -<component loader="com.sun.star.loader.SharedLibrary" - xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="com.sun.star.comp.embed.StorageFactory"> - <service name="com.sun.star.comp.embed.StorageFactory"/> - <service name="com.sun.star.embed.StorageFactory"/> - </implementation> -</component> diff --git a/package/source/xstor/xstor.dxp b/package/source/xstor/xstor.dxp deleted file mode 100644 index 700330789..000000000 --- a/package/source/xstor/xstor.dxp +++ /dev/null @@ -1 +0,0 @@ -component_getFactory diff --git a/package/source/xstor/xstorage.cxx b/package/source/xstor/xstorage.cxx deleted file mode 100644 index e05eac0b6..000000000 --- a/package/source/xstor/xstorage.cxx +++ /dev/null @@ -1,6405 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_package.hxx" -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/embed/ElementModes.hpp> -#include <com/sun/star/embed/UseBackupException.hpp> -#include <com/sun/star/embed/StorageFormats.hpp> -#include <com/sun/star/ucb/XProgressHandler.hpp> -#include <com/sun/star/container/XHierarchicalNameAccess.hpp> -#include <com/sun/star/container/XEnumerationAccess.hpp> -#include <com/sun/star/container/XNamed.hpp> -#include <com/sun/star/util/XChangesBatch.hpp> -#include <com/sun/star/util/XCloneable.hpp> - - -#include <com/sun/star/lang/XUnoTunnel.hpp> -#include <com/sun/star/lang/XComponent.hpp> -#include <com/sun/star/lang/DisposedException.hpp> -#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> -#include <com/sun/star/beans/NamedValue.hpp> - -#include <PackageConstants.hxx> - -#include <cppuhelper/typeprovider.hxx> -#include <cppuhelper/exc_hlp.hxx> -#include <rtl/logfile.hxx> -#include <rtl/instance.hxx> - -#include <comphelper/processfactory.hxx> -#include <comphelper/componentcontext.hxx> -#include <comphelper/storagehelper.hxx> -#include <comphelper/ofopxmlhelper.hxx> - -#include "xstorage.hxx" -#include "owriteablestream.hxx" -#include "disposelistener.hxx" -#include "switchpersistencestream.hxx" -#include "ohierarchyholder.hxx" - -using namespace ::com::sun::star; - -//========================================================= - -typedef ::std::list< uno::WeakReference< lang::XComponent > > WeakComponentList; - -struct StorInternalData_Impl -{ - SotMutexHolderRef m_rSharedMutexRef; - ::cppu::OMultiTypeInterfaceContainerHelper m_aListenersContainer; // list of listeners - ::cppu::OTypeCollection* m_pTypeCollection; - sal_Bool m_bIsRoot; - sal_Int32 m_nStorageType; // the mode in wich the storage is used - sal_Bool m_bReadOnlyWrap; - - OChildDispListener_Impl* m_pSubElDispListener; - - WeakComponentList m_aOpenSubComponentsList; - - ::rtl::Reference< OHierarchyHolder_Impl > m_rHierarchyHolder; - - // the mutex reference MUST NOT be empty - StorInternalData_Impl( const SotMutexHolderRef& rMutexRef, sal_Bool bRoot, sal_Int32 nStorageType, sal_Bool bReadOnlyWrap ) - : m_rSharedMutexRef( rMutexRef ) - , m_aListenersContainer( rMutexRef->GetMutex() ) - , m_pTypeCollection( NULL ) - , m_bIsRoot( bRoot ) - , m_nStorageType( nStorageType ) - , m_bReadOnlyWrap( bReadOnlyWrap ) - , m_pSubElDispListener( NULL ) - {} - - ~StorInternalData_Impl(); -}; - -//========================================================= -::rtl::OUString GetNewTempFileURL( const uno::Reference< lang::XMultiServiceFactory > xFactory ); - -// static -void OStorage_Impl::completeStorageStreamCopy_Impl( - const uno::Reference< io::XStream >& xSource, - const uno::Reference< io::XStream >& xDest, - sal_Int32 nStorageType, - const uno::Sequence< uno::Sequence< beans::StringPair > >& aRelInfo ) -{ - uno::Reference< beans::XPropertySet > xSourceProps( xSource, uno::UNO_QUERY ); - uno::Reference< beans::XPropertySet > xDestProps( xDest, uno::UNO_QUERY ); - if ( !xSourceProps.is() || !xDestProps.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< io::XOutputStream > xDestOutStream = xDest->getOutputStream(); - if ( !xDestOutStream.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< io::XInputStream > xSourceInStream = xSource->getInputStream(); - if ( !xSourceInStream.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // TODO: headers of encripted streams should be copied also - ::comphelper::OStorageHelper::CopyInputToOutput( xSourceInStream, xDestOutStream ); - - uno::Sequence< ::rtl::OUString > aPropNames( 1 ); - aPropNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Compressed" ) ); - - if ( nStorageType == embed::StorageFormats::PACKAGE ) - { - aPropNames.realloc( 3 ); - aPropNames[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ); - aPropNames[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseCommonStoragePasswordEncryption" ) ); - } - else if ( nStorageType == embed::StorageFormats::OFOPXML ) - { - // TODO/LATER: in future it might make sence to provide the stream if there is one - uno::Reference< embed::XRelationshipAccess > xRelAccess( xDest, uno::UNO_QUERY_THROW ); - xRelAccess->clearRelationships(); - xRelAccess->insertRelationships( aRelInfo, sal_False ); - - aPropNames.realloc( 2 ); - aPropNames[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ); - } - - for ( int ind = 0; ind < aPropNames.getLength(); ind++ ) - xDestProps->setPropertyValue( aPropNames[ind], xSourceProps->getPropertyValue( aPropNames[ind] ) ); -} - -uno::Reference< io::XInputStream > GetSeekableTempCopy( uno::Reference< io::XInputStream > xInStream, - uno::Reference< lang::XMultiServiceFactory > xFactory ) -{ - uno::Reference < io::XOutputStream > xTempOut( - xFactory->createInstance ( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ), - uno::UNO_QUERY ); - uno::Reference < io::XInputStream > xTempIn( xTempOut, uno::UNO_QUERY ); - - if ( !xTempOut.is() || !xTempIn.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - ::comphelper::OStorageHelper::CopyInputToOutput( xInStream, xTempOut ); - xTempOut->closeOutput(); - - return xTempIn; -} - -StorInternalData_Impl::~StorInternalData_Impl() -{ - if ( m_pTypeCollection ) - delete m_pTypeCollection; -} - - -SotElement_Impl::SotElement_Impl( const ::rtl::OUString& rName, sal_Bool bStor, sal_Bool bNew ) -: m_aName( rName ) -, m_aOriginalName( rName ) -, m_bIsRemoved( sal_False ) -, m_bIsInserted( bNew ) -, m_bIsStorage( bStor ) -, m_pStorage( NULL ) -, m_pStream( NULL ) -{ -} - -SotElement_Impl::~SotElement_Impl() -{ - if ( m_pStorage ) - delete m_pStorage; - - if ( m_pStream ) - delete m_pStream; -} - -//----------------------------------------------- -// most of properties are holt by the storage but are not used -OStorage_Impl::OStorage_Impl( uno::Reference< io::XInputStream > xInputStream, - sal_Int32 nMode, - uno::Sequence< beans::PropertyValue > xProperties, - uno::Reference< lang::XMultiServiceFactory > xFactory, - sal_Int32 nStorageType ) -: m_rMutexRef( new SotMutexHolder ) -, m_pAntiImpl( NULL ) -, m_nStorageMode( nMode & ~embed::ElementModes::SEEKABLE ) -, m_bIsModified( ( nMode & ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) ) == ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) ) -, m_bBroadcastModified( sal_False ) -, m_bCommited( sal_False ) -, m_bIsRoot( sal_True ) -, m_bListCreated( sal_False ) -, m_xFactory( xFactory ) -, m_xProperties( xProperties ) -, m_bHasCommonEncryptionData( sal_False ) -, m_pParent( NULL ) -, m_bControlMediaType( sal_False ) -, m_bMTFallbackUsed( sal_False ) -, m_bControlVersion( sal_False ) -, m_pSwitchStream( NULL ) -, m_nStorageType( nStorageType ) -, m_pRelStorElement( NULL ) -, m_nRelInfoStatus( RELINFO_NO_INIT ) -{ - // all the checks done below by assertion statements must be done by factory - OSL_ENSURE( xInputStream.is(), "No input stream is provided!\n" ); - - m_pSwitchStream = (SwitchablePersistenceStream*) new SwitchablePersistenceStream( xFactory, xInputStream ); - m_xInputStream = m_pSwitchStream->getInputStream(); - - if ( m_nStorageMode & embed::ElementModes::WRITE ) - { - // check that the stream allows to write - OSL_FAIL( "No stream for writing is provided!\n" ); - } -} - -//----------------------------------------------- -// most of properties are holt by the storage but are not used -OStorage_Impl::OStorage_Impl( uno::Reference< io::XStream > xStream, - sal_Int32 nMode, - uno::Sequence< beans::PropertyValue > xProperties, - uno::Reference< lang::XMultiServiceFactory > xFactory, - sal_Int32 nStorageType ) -: m_rMutexRef( new SotMutexHolder ) -, m_pAntiImpl( NULL ) -, m_nStorageMode( nMode & ~embed::ElementModes::SEEKABLE ) -, m_bIsModified( ( nMode & ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) ) == ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) ) -, m_bBroadcastModified( sal_False ) -, m_bCommited( sal_False ) -, m_bIsRoot( sal_True ) -, m_bListCreated( sal_False ) -, m_xFactory( xFactory ) -, m_xProperties( xProperties ) -, m_bHasCommonEncryptionData( sal_False ) -, m_pParent( NULL ) -, m_bControlMediaType( sal_False ) -, m_bMTFallbackUsed( sal_False ) -, m_bControlVersion( sal_False ) -, m_pSwitchStream( NULL ) -, m_nStorageType( nStorageType ) -, m_pRelStorElement( NULL ) -, m_nRelInfoStatus( RELINFO_NO_INIT ) -{ - // all the checks done below by assertion statements must be done by factory - OSL_ENSURE( xStream.is(), "No stream is provided!\n" ); - - if ( m_nStorageMode & embed::ElementModes::WRITE ) - { - m_pSwitchStream = (SwitchablePersistenceStream*) new SwitchablePersistenceStream( xFactory, xStream ); - m_xStream = static_cast< io::XStream* >( m_pSwitchStream ); - } - else - { - m_pSwitchStream = (SwitchablePersistenceStream*) new SwitchablePersistenceStream( xFactory, - xStream->getInputStream() ); - m_xInputStream = m_pSwitchStream->getInputStream(); - } -} - -//----------------------------------------------- -OStorage_Impl::OStorage_Impl( OStorage_Impl* pParent, - sal_Int32 nMode, - uno::Reference< container::XNameContainer > xPackageFolder, - uno::Reference< lang::XSingleServiceFactory > xPackage, - uno::Reference< lang::XMultiServiceFactory > xFactory, - sal_Int32 nStorageType ) -: m_rMutexRef( new SotMutexHolder ) -, m_pAntiImpl( NULL ) -, m_nStorageMode( nMode & ~embed::ElementModes::SEEKABLE ) -, m_bIsModified( ( nMode & ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) ) == ( embed::ElementModes::WRITE | embed::ElementModes::TRUNCATE ) ) -, m_bBroadcastModified( sal_False ) -, m_bCommited( sal_False ) -, m_bIsRoot( sal_False ) -, m_bListCreated( sal_False ) -, m_xPackageFolder( xPackageFolder ) -, m_xPackage( xPackage ) -, m_xFactory( xFactory ) -, m_bHasCommonEncryptionData( sal_False ) -, m_pParent( pParent ) // can be empty in case of temporary readonly substorages and relation storage -, m_bControlMediaType( sal_False ) -, m_bMTFallbackUsed( sal_False ) -, m_bControlVersion( sal_False ) -, m_pSwitchStream( NULL ) -, m_nStorageType( nStorageType ) -, m_pRelStorElement( NULL ) -, m_nRelInfoStatus( RELINFO_NO_INIT ) -{ - OSL_ENSURE( xPackageFolder.is(), "No package folder!\n" ); -} - -//----------------------------------------------- -OStorage_Impl::~OStorage_Impl() -{ - { - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - if ( m_pAntiImpl ) // root storage wrapper must set this member to NULL before destruction of object - { - OSL_ENSURE( !m_bIsRoot, "The root storage wrapper must be disposed already" ); - - try { - m_pAntiImpl->InternalDispose( sal_False ); - } - catch ( const uno::Exception& rException ) - { - AddLog( rException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - } - m_pAntiImpl = NULL; - } - else if ( !m_aReadOnlyWrapList.empty() ) - { - for ( OStorageList_Impl::iterator pStorageIter = m_aReadOnlyWrapList.begin(); - pStorageIter != m_aReadOnlyWrapList.end(); pStorageIter++ ) - { - uno::Reference< embed::XStorage > xTmp = pStorageIter->m_xWeakRef; - if ( xTmp.is() ) - try { - pStorageIter->m_pPointer->InternalDispose( sal_False ); - } catch( const uno::Exception& rException ) - { - AddLog( rException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - } - } - - m_aReadOnlyWrapList.clear(); - } - - m_pParent = NULL; - } - - for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin(); - pElementIter != m_aChildrenList.end(); pElementIter++ ) - delete *pElementIter; - - m_aChildrenList.clear(); - - for ( SotElementList_Impl::iterator pDeletedIter = m_aDeletedList.begin(); - pDeletedIter != m_aDeletedList.end(); pDeletedIter++ ) - delete *pDeletedIter; - - m_aDeletedList.clear(); - - if ( m_nStorageType == embed::StorageFormats::OFOPXML && m_pRelStorElement ) - { - delete m_pRelStorElement; - m_pRelStorElement = NULL; - } - - m_xPackageFolder = uno::Reference< container::XNameContainer >(); - m_xPackage = uno::Reference< lang::XSingleServiceFactory >(); - - ::rtl::OUString aPropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ); - for ( sal_Int32 aInd = 0; aInd < m_xProperties.getLength(); aInd++ ) - { - if ( m_xProperties[aInd].Name.equals( aPropertyName ) ) - { - // the storage is URL based so all the streams are opened by factory and should be closed - try - { - if ( m_xInputStream.is() ) - { - m_xInputStream->closeInput(); - m_xInputStream = uno::Reference< io::XInputStream >(); - } - - if ( m_xStream.is() ) - { - uno::Reference< io::XInputStream > xInStr = m_xStream->getInputStream(); - if ( xInStr.is() ) - xInStr->closeInput(); - - uno::Reference< io::XOutputStream > xOutStr = m_xStream->getOutputStream(); - if ( xOutStr.is() ) - xOutStr->closeOutput(); - - m_xStream = uno::Reference< io::XStream >(); - } - } - catch( const uno::Exception& rException ) - { - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - AddLog( rException.Message ); - } - } - } -} - -//----------------------------------------------- -void OStorage_Impl::AddLog( const ::rtl::OUString& aMessage ) -{ - if ( !m_xLogRing.is() ) - { - try - { - ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); - if ( aContext.is() ) - m_xLogRing.set( aContext.getSingleton( "com.sun.star.logging.DocumentIOLogRing" ), uno::UNO_QUERY_THROW ); - } - catch( const uno::Exception& ) - { - // No log - } - } - - if ( m_xLogRing.is() ) - m_xLogRing->logString( aMessage ); -} - -//----------------------------------------------- -void OStorage_Impl::SetReadOnlyWrap( OStorage& aStorage ) -{ - // Weak reference is used inside the holder so the refcount must not be zero at this point - OSL_ENSURE( aStorage.GetRefCount_Impl(), "There must be a reference alive to use this method!\n" ); - m_aReadOnlyWrapList.push_back( StorageHolder_Impl( &aStorage ) ); -} - -//----------------------------------------------- -void OStorage_Impl::RemoveReadOnlyWrap( OStorage& aStorage ) -{ - for ( OStorageList_Impl::iterator pStorageIter = m_aReadOnlyWrapList.begin(); - pStorageIter != m_aReadOnlyWrapList.end();) - { - uno::Reference< embed::XStorage > xTmp = pStorageIter->m_xWeakRef; - if ( !xTmp.is() || pStorageIter->m_pPointer == &aStorage ) - { - try { - pStorageIter->m_pPointer->InternalDispose( sal_False ); - } catch( const uno::Exception& rException ) - { - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - AddLog( rException.Message ); - } - - OStorageList_Impl::iterator pIterToDelete( pStorageIter ); - pStorageIter++; - m_aReadOnlyWrapList.erase( pIterToDelete ); - } - else - pStorageIter++; - } -} - -//----------------------------------------------- -void OStorage_Impl::OpenOwnPackage() -{ - OSL_ENSURE( m_bIsRoot, "Opening of the package has no sence!\n" ); - - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( !m_xPackageFolder.is() ) - { - if ( !m_xPackage.is() ) - { - uno::Sequence< uno::Any > aArguments( 2 ); - if ( m_nStorageMode & embed::ElementModes::WRITE ) - aArguments[ 0 ] <<= m_xStream; - else - { - OSL_ENSURE( m_xInputStream.is(), "Input stream must be set for readonly access!\n" ); - aArguments[ 0 ] <<= m_xInputStream; - // TODO: if input stream is not seekable or XSeekable interface is supported - // on XStream object a wrapper must be used - } - - // do not allow elements to remove themself from the old container in case of insertion to another container - aArguments[ 1 ] <<= beans::NamedValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AllowRemoveOnInsert" ) ), - uno::makeAny( (sal_Bool)sal_False ) ); - - sal_Int32 nArgNum = 2; - for ( sal_Int32 aInd = 0; aInd < m_xProperties.getLength(); aInd++ ) - { - if ( m_xProperties[aInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RepairPackage" ) ) - || m_xProperties[aInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ProgressHandler" ) ) ) - { - beans::NamedValue aNamedValue( m_xProperties[aInd].Name, - m_xProperties[aInd].Value ); - aArguments.realloc( ++nArgNum ); - aArguments[nArgNum-1] <<= aNamedValue; - } - else if ( m_xProperties[aInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Password" ) ) ) - { - // TODO: implement password setting for documents - // the password entry must be removed after setting - } - } - - if ( m_nStorageType == embed::StorageFormats::ZIP ) - { - // let the package support only plain zip format - beans::NamedValue aNamedValue; - aNamedValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StorageFormat" ) ); - aNamedValue.Value <<= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ZipFormat" ) ); - aArguments.realloc( ++nArgNum ); - aArguments[nArgNum-1] <<= aNamedValue; - } - else if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - { - // let the package support OFOPXML media type handling - beans::NamedValue aNamedValue; - aNamedValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StorageFormat" ) ); - aNamedValue.Value <<= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OFOPXMLFormat" ) ); - aArguments.realloc( ++nArgNum ); - aArguments[nArgNum-1] <<= aNamedValue; - } - - m_xPackage = uno::Reference< lang::XSingleServiceFactory > ( - GetServiceFactory()->createInstanceWithArguments( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.packages.comp.ZipPackage" ) ), - aArguments ), - uno::UNO_QUERY ); - } - - uno::Reference< container::XHierarchicalNameAccess > xHNameAccess( m_xPackage, uno::UNO_QUERY ); - OSL_ENSURE( xHNameAccess.is(), "The package could not be created!\n" ); - - if ( xHNameAccess.is() ) - { - uno::Any aFolder = xHNameAccess->getByHierarchicalName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) ); - aFolder >>= m_xPackageFolder; - } - } - - OSL_ENSURE( m_xPackageFolder.is(), "The package root folder can not be opened!\n" ); - if ( !m_xPackageFolder.is() ) - throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} - -//----------------------------------------------- -uno::Reference< lang::XMultiServiceFactory > OStorage_Impl::GetServiceFactory() -{ - if ( m_xFactory.is() ) - return m_xFactory; - - return ::comphelper::getProcessServiceFactory(); -} - -//----------------------------------------------- -SotElementList_Impl& OStorage_Impl::GetChildrenList() -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - ReadContents(); - return m_aChildrenList; -} - -//----------------------------------------------- -void OStorage_Impl::GetStorageProperties() -{ - if ( m_nStorageType == embed::StorageFormats::PACKAGE ) - { - uno::Reference< beans::XPropertySet > xProps( m_xPackageFolder, uno::UNO_QUERY_THROW ); - - if ( !m_bControlMediaType ) - { - uno::Reference< beans::XPropertySet > xPackageProps( m_xPackage, uno::UNO_QUERY_THROW ); - xPackageProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MEDIATYPE_FALLBACK_USED_PROPERTY ) ) ) >>= m_bMTFallbackUsed; - - xProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ) ) >>= m_aMediaType; - m_bControlMediaType = sal_True; - } - - if ( !m_bControlVersion ) - { - xProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) >>= m_aVersion; - m_bControlVersion = sal_True; - } - } - - // the properties of OFOPXML will be handled directly -} - -//----------------------------------------------- -void OStorage_Impl::ReadRelInfoIfNecessary() -{ - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - return; - - if ( m_nRelInfoStatus == RELINFO_NO_INIT ) - { - // Init from original stream - uno::Reference< io::XInputStream > xRelInfoStream = GetRelInfoStreamForName( ::rtl::OUString() ); - if ( xRelInfoStream.is() ) - m_aRelInfo = ::comphelper::OFOPXMLHelper::ReadRelationsInfoSequence( - xRelInfoStream, - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels/.rels" ) ), - m_xFactory ); - - m_nRelInfoStatus = RELINFO_READ; - } - else if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM ) - { - // Init from the new stream - try - { - if ( m_xNewRelInfoStream.is() ) - m_aRelInfo = ::comphelper::OFOPXMLHelper::ReadRelationsInfoSequence( - m_xNewRelInfoStream, - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels/.rels" ) ), - m_xFactory ); - - m_nRelInfoStatus = RELINFO_CHANGED_STREAM_READ; - } - catch( const uno::Exception& ) - { - m_nRelInfoStatus = RELINFO_CHANGED_BROKEN; - } - } -} - -//----------------------------------------------- -void OStorage_Impl::ReadContents() -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( m_bListCreated ) - return; - - if ( m_bIsRoot ) - OpenOwnPackage(); - - uno::Reference< container::XEnumerationAccess > xEnumAccess( m_xPackageFolder, uno::UNO_QUERY ); - if ( !xEnumAccess.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< container::XEnumeration > xEnum = xEnumAccess->createEnumeration(); - if ( !xEnum.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - m_bListCreated = sal_True; - - while( xEnum->hasMoreElements() ) - { - try { - uno::Reference< container::XNamed > xNamed; - xEnum->nextElement() >>= xNamed; - - if ( !xNamed.is() ) - { - OSL_FAIL( "XNamed is not supported!\n" ); - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - ::rtl::OUString aName = xNamed->getName(); - OSL_ENSURE( aName.getLength(), "Empty name!\n" ); - - uno::Reference< container::XNameContainer > xNameContainer( xNamed, uno::UNO_QUERY ); - - SotElement_Impl* pNewElement = new SotElement_Impl( aName, xNameContainer.is(), sal_False ); - if ( m_nStorageType == embed::StorageFormats::OFOPXML && aName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - { - if ( !pNewElement->m_bIsStorage ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: Unexpected format - - m_pRelStorElement = pNewElement; - CreateRelStorage(); - } - else - { - if ( ( m_nStorageMode & embed::ElementModes::TRUNCATE ) == embed::ElementModes::TRUNCATE ) - { - // if a storage is truncated all of it elements are marked as deleted - pNewElement->m_bIsRemoved = sal_True; - } - - m_aChildrenList.push_back( pNewElement ); - } - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - AddLog( rNoSuchElementException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "NoSuchElement" ) ) ); - - OSL_FAIL( "hasMoreElements() implementation has problems!\n" ); - break; - } - } - if ( ( m_nStorageMode & embed::ElementModes::TRUNCATE ) == embed::ElementModes::TRUNCATE ) - { - // if a storage is truncated the relations information should be cleaned - m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_aRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >(); - m_nRelInfoStatus = RELINFO_CHANGED; - } - - // cache changeable folder properties - GetStorageProperties(); -} - -//----------------------------------------------- -void OStorage_Impl::CopyToStorage( const uno::Reference< embed::XStorage >& xDest, sal_Bool bDirect ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - uno::Reference< beans::XPropertySet > xPropSet( xDest, uno::UNO_QUERY ); - if ( !xPropSet.is() ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - - sal_Int32 nDestMode = embed::ElementModes::READ; - xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenMode" ) ) ) >>= nDestMode; - - if ( !( nDestMode & embed::ElementModes::WRITE ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied - - ReadContents(); - - if ( !m_xPackageFolder.is() ) - throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin(); - pElementIter != m_aChildrenList.end(); pElementIter++ ) - { - if ( !(*pElementIter)->m_bIsRemoved ) - CopyStorageElement( *pElementIter, xDest, (*pElementIter)->m_aName, bDirect ); - } - - // move storage properties to the destination one ( means changeable properties ) - if ( m_nStorageType == embed::StorageFormats::PACKAGE ) - { - ::rtl::OUString aMediaTypeString = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ); - ::rtl::OUString aVersionString = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ); - xPropSet->setPropertyValue( aMediaTypeString, uno::makeAny( m_aMediaType ) ); - xPropSet->setPropertyValue( aVersionString, uno::makeAny( m_aVersion ) ); - } - - if ( m_nStorageType == embed::StorageFormats::PACKAGE ) - { - // if this is a root storage, the common key from current one should be moved there - sal_Bool bIsRoot = sal_False; - ::rtl::OUString aRootString = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsRoot" ) ); - if ( ( xPropSet->getPropertyValue( aRootString ) >>= bIsRoot ) && bIsRoot ) - { - try - { - uno::Reference< embed::XEncryptionProtectedStorage > xEncr( xDest, uno::UNO_QUERY ); - if ( xEncr.is() ) - { - xEncr->setEncryptionData( GetCommonRootEncryptionData().getAsConstNamedValueList() ); - - uno::Sequence< beans::NamedValue > aAlgorithms; - uno::Reference< beans::XPropertySet > xPackPropSet( m_xPackage, uno::UNO_QUERY_THROW ); - xPackPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ) ) - >>= aAlgorithms; - xEncr->setEncryptionAlgorithms( aAlgorithms ); - } - } - catch( const packages::NoEncryptionException& rNoEncryptionException ) - { - AddLog( rNoEncryptionException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No Encryption" ) ) ); - } - } - } - else if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - { - - // TODO/LATER: currently the optimization is not active - // uno::Reference< io::XInputStream > xRelInfoStream = GetRelInfoStreamForName( ::rtl::OUString() ); // own stream - // if ( xRelInfoStream.is() ) - // { - // // Relations info stream is a writeonly property, introduced only to optimyze copying - // // Should be used carefuly since no check for stream consistency is done, and the stream must not stay locked - // - // ::rtl::OUString aRelInfoString = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RelationsInfoStream" ) ); - // xPropSet->setPropertyValue( aRelInfoString, uno::makeAny( GetSeekableTempCopy( xRelInfoStream, m_xFactory ) ) ); - // } - - uno::Reference< embed::XRelationshipAccess > xRels( xDest, uno::UNO_QUERY ); - if ( !xRels.is() ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - - xRels->insertRelationships( GetAllRelationshipsIfAny(), sal_False ); - } - - // if possible the destination storage should be commited after successful copying - uno::Reference< embed::XTransactedObject > xObjToCommit( xDest, uno::UNO_QUERY ); - if ( xObjToCommit.is() ) - xObjToCommit->commit(); -} - -//----------------------------------------------- -void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement, - uno::Reference< embed::XStorage > xDest, - ::rtl::OUString aName, - sal_Bool bDirect ) -{ - OSL_ENSURE( xDest.is(), "No destination storage!\n" ); - OSL_ENSURE( aName.getLength(), "Empty element name!\n" ); - - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - uno::Reference< container::XNameAccess > xDestAccess( xDest, uno::UNO_QUERY ); - if ( !xDestAccess.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( xDestAccess->hasByName( aName ) - && !( pElement->m_bIsStorage && xDest->isStorageElement( aName ) ) ) - xDest->removeElement( aName ); - - if ( pElement->m_bIsStorage ) - { - uno::Reference< embed::XStorage > xSubDest = - xDest->openStorageElement( aName, - embed::ElementModes::WRITE ); - - OSL_ENSURE( xSubDest.is(), "No destination substorage!\n" ); - - if ( !pElement->m_pStorage ) - { - OpenSubStorage( pElement, embed::ElementModes::READ ); - if ( !pElement->m_pStorage ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - pElement->m_pStorage->CopyToStorage( xSubDest, bDirect ); - } - else - { - if ( !pElement->m_pStream ) - { - OpenSubStream( pElement ); - if ( !pElement->m_pStream ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !pElement->m_pStream->IsEncrypted() ) - { - if ( bDirect ) - { - // fill in the properties for the stream - uno::Sequence< beans::PropertyValue > aStrProps(0); - uno::Sequence< beans::PropertyValue > aSrcPkgProps = pElement->m_pStream->GetStreamProperties(); - sal_Int32 nNum = 0; - for ( int ind = 0; ind < aSrcPkgProps.getLength(); ind++ ) - { - if ( aSrcPkgProps[ind].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) ) ) - || aSrcPkgProps[ind].Name.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "Compressed" ) ) ) ) - { - aStrProps.realloc( ++nNum ); - aStrProps[nNum-1].Name = aSrcPkgProps[ind].Name; - aStrProps[nNum-1].Value = aSrcPkgProps[ind].Value; - } - } - - if ( m_nStorageType == embed::StorageFormats::PACKAGE ) - { - aStrProps.realloc( ++nNum ); - aStrProps[nNum-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseCommonStoragePasswordEncryption" ) ); - aStrProps[nNum-1].Value <<= (sal_Bool)( pElement->m_pStream->UsesCommonEncryption_Impl() ); - } - else if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - { - // TODO/LATER: currently the optimization is not active - // uno::Reference< io::XInputStream > xInStream = GetRelInfoStreamForName( ::rtl::OUString() ); // own rels stream - // if ( xInStream.is() ) - // { - // aStrProps.realloc( ++nNum ); - // aStrProps[nNum-1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "RelationsInfoStream" ) ); - // aStrProps[nNum-1].Value <<= GetSeekableTempCopy( xInStream, m_xFactory ); - // } - - uno::Reference< embed::XRelationshipAccess > xRels( xDest, uno::UNO_QUERY ); - if ( !xRels.is() ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); - - xRels->insertRelationships( GetAllRelationshipsIfAny(), sal_False ); - } - - uno::Reference< embed::XOptimizedStorage > xOptDest( xDest, uno::UNO_QUERY_THROW ); - uno::Reference < io::XInputStream > xInputToInsert; - - if ( pElement->m_pStream->HasTempFile_Impl() || !pElement->m_pStream->m_xPackageStream.is() ) - { - OSL_ENSURE( pElement->m_pStream->m_xPackageStream.is(), "No package stream!" ); - - // if the stream is modified - the temporary file must be used for insertion - xInputToInsert = pElement->m_pStream->GetTempFileAsInputStream(); - } - else - { - // for now get just nonseekable access to the stream - // TODO/LATER: the raw stream can be used - - xInputToInsert = pElement->m_pStream->m_xPackageStream->getDataStream(); - } - - if ( !xInputToInsert.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - xOptDest->insertStreamElementDirect( aName, xInputToInsert, aStrProps ); - } - else - { - uno::Reference< io::XStream > xSubStr = - xDest->openStreamElement( aName, - embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE ); - OSL_ENSURE( xSubStr.is(), "No destination substream!\n" ); - - pElement->m_pStream->CopyInternallyTo_Impl( xSubStr ); - } - } - else if ( m_nStorageType != embed::StorageFormats::PACKAGE ) - { - OSL_FAIL( "Encryption is only supported in package storage!\n" ); - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - else if ( pElement->m_pStream->HasCachedEncryptionData() - && ( pElement->m_pStream->IsModified() || pElement->m_pStream->HasWriteOwner_Impl() ) ) - { - ::comphelper::SequenceAsHashMap aCommonEncryptionData; - sal_Bool bHasCommonEncryptionData = sal_False; - try - { - aCommonEncryptionData = GetCommonRootEncryptionData(); - bHasCommonEncryptionData = sal_True; - } - catch( const packages::NoEncryptionException& rNoEncryptionException ) - { - AddLog( rNoEncryptionException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No Encryption" ) ) ); - } - - if ( bHasCommonEncryptionData && ::package::PackageEncryptionDatasEqual( pElement->m_pStream->GetCachedEncryptionData(), aCommonEncryptionData ) ) - { - // If the stream can be opened with the common storage password - // it must be stored with the common storage password as well - uno::Reference< io::XStream > xDestStream = - xDest->openStreamElement( aName, - embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE ); - - pElement->m_pStream->CopyInternallyTo_Impl( xDestStream ); - - uno::Reference< beans::XPropertySet > xProps( xDestStream, uno::UNO_QUERY_THROW ); - xProps->setPropertyValue( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseCommonStoragePasswordEncryption" ) ), - uno::Any( (sal_Bool) sal_True ) ); - } - else - { - // the stream is already opened for writing or was changed - uno::Reference< embed::XStorage2 > xDest2( xDest, uno::UNO_QUERY_THROW ); - uno::Reference< io::XStream > xSubStr = - xDest2->openEncryptedStream( aName, - embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE, - pElement->m_pStream->GetCachedEncryptionData().getAsConstNamedValueList() ); - OSL_ENSURE( xSubStr.is(), "No destination substream!\n" ); - - pElement->m_pStream->CopyInternallyTo_Impl( xSubStr, pElement->m_pStream->GetCachedEncryptionData() ); - } - } - else - { - // the stream is not opened at all, so it can be just opened for reading - try - { - // If the stream can be opened with the common storage password - // it must be stored with the common storage password as well - - uno::Reference< io::XStream > xOwnStream = pElement->m_pStream->GetStream( embed::ElementModes::READ, - sal_False ); - uno::Reference< io::XStream > xDestStream = - xDest->openStreamElement( aName, - embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE ); - OSL_ENSURE( xDestStream.is(), "No destination substream!\n" ); - completeStorageStreamCopy_Impl( xOwnStream, xDestStream, m_nStorageType, GetAllRelationshipsIfAny() ); - - uno::Reference< beans::XPropertySet > xProps( xDestStream, uno::UNO_QUERY_THROW ); - xProps->setPropertyValue( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseCommonStoragePasswordEncryption" ) ), - uno::Any( (sal_Bool) sal_True ) ); - } - catch( const packages::WrongPasswordException& rWrongPasswordException ) - { - AddLog( rWrongPasswordException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Handled exception" ) ) ); - - // If the common storage password does not allow to open the stream - // it could be copyed in raw way, the problem is that the StartKey should be the same - // in the ODF1.2 package, so an invalid package could be produced if the stream - // is copied from ODF1.1 package, where it is allowed to have different StartKeys - uno::Reference< embed::XStorageRawAccess > xRawDest( xDest, uno::UNO_QUERY_THROW ); - uno::Reference< io::XInputStream > xRawInStream = pElement->m_pStream->GetRawInStream(); - xRawDest->insertRawEncrStreamElement( aName, xRawInStream ); - } - } - } -} - -//----------------------------------------------- -uno::Sequence< uno::Sequence< beans::StringPair > > OStorage_Impl::GetAllRelationshipsIfAny() -{ - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - return uno::Sequence< uno::Sequence< beans::StringPair > >(); - - ReadRelInfoIfNecessary(); - - if ( m_nRelInfoStatus == RELINFO_READ - || m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ || m_nRelInfoStatus == RELINFO_CHANGED ) - return m_aRelInfo; - else // m_nRelInfoStatus == RELINFO_CHANGED_BROKEN || m_nRelInfoStatus == RELINFO_BROKEN - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong relinfo stream!" ) ), - uno::Reference< uno::XInterface >() ); -} - -//----------------------------------------------- -void OStorage_Impl::CopyLastCommitTo( const uno::Reference< embed::XStorage >& xNewStor ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - OSL_ENSURE( m_xPackageFolder.is(), "A commited storage is incomplete!\n" ); - if ( !m_xPackageFolder.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - OStorage_Impl aTempRepresent( NULL, - embed::ElementModes::READ, - m_xPackageFolder, - m_xPackage, - m_xFactory, - m_nStorageType); - - // TODO/LATER: could use direct copying - aTempRepresent.CopyToStorage( xNewStor, sal_False ); -} - -//----------------------------------------------- -void OStorage_Impl::InsertIntoPackageFolder( const ::rtl::OUString& aName, - const uno::Reference< container::XNameContainer >& xParentPackageFolder ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - OSL_ENSURE( m_xPackageFolder.is(), "An inserted storage is incomplete!\n" ); - uno::Reference< lang::XUnoTunnel > xTunnel( m_xPackageFolder, uno::UNO_QUERY ); - if ( !xTunnel.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - xParentPackageFolder->insertByName( aName, uno::makeAny( xTunnel ) ); - - m_bCommited = sal_False; -} - -//----------------------------------------------- -void OStorage_Impl::Commit() -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( !m_bIsModified ) - return; - - // in case of a new empty storage it is possible that the contents are still not read - // ( the storage of course has no contents, but the initialization is postponed till the first use, - // thus if a new storage was created and commited immediatelly it must be initialized here ) - ReadContents(); - - // if storage is commited it should have a valid Package representation - OSL_ENSURE( m_xPackageFolder.is(), "The package representation should exist!\n" ); - if ( !m_xPackageFolder.is() ) - throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - OSL_ENSURE( m_nStorageMode & embed::ElementModes::WRITE, - "Commit of readonly storage, should be detected before!\n" ); - - uno::Reference< container::XNameContainer > xNewPackageFolder; - - // here the storage will switch to the temporary package folder - // if the storage was already commited and the parent was not commited after that - // the switch should not be done since the package folder in use is a temporary one; - // it can be detected by m_bCommited flag ( root storage doesn't need temporary representation ) - if ( !m_bCommited && !m_bIsRoot ) - { - uno::Sequence< uno::Any > aSeq( 1 ); - aSeq[0] <<= sal_True; - - xNewPackageFolder = uno::Reference< container::XNameContainer >( - m_xPackage->createInstanceWithArguments( aSeq ), - uno::UNO_QUERY ); - } - else - xNewPackageFolder = m_xPackageFolder; - - // remove replaced removed elements - for ( SotElementList_Impl::iterator pDeletedIter = m_aDeletedList.begin(); - pDeletedIter != m_aDeletedList.end(); - pDeletedIter++ ) - { - - if ( m_nStorageType == embed::StorageFormats::OFOPXML && !(*pDeletedIter)->m_bIsStorage ) - RemoveStreamRelInfo( (*pDeletedIter)->m_aOriginalName ); - - // the removed elements are not in new temporary storage - if ( m_bCommited || m_bIsRoot ) - xNewPackageFolder->removeByName( (*pDeletedIter)->m_aOriginalName ); - delete *pDeletedIter; - *pDeletedIter = NULL; - } - m_aDeletedList.clear(); - - // remove removed elements - SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin(); - while ( pElementIter != m_aChildrenList.end() ) - { - // renamed and inserted elements must be really inserted to package later - // since thay can conflict with removed elements - - if ( (*pElementIter)->m_bIsRemoved ) - { - if ( m_nStorageType == embed::StorageFormats::OFOPXML && !(*pElementIter)->m_bIsStorage ) - RemoveStreamRelInfo( (*pElementIter)->m_aOriginalName ); - - // the removed elements are not in new temporary storage - if ( m_bCommited || m_bIsRoot ) - xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName ); - - SotElement_Impl* pToDelete = *pElementIter; - - pElementIter++; // to let the iterator be valid it should be increased before removing - - m_aChildrenList.remove( pToDelete ); - delete pToDelete; - } - else - pElementIter++; - } - - // there should be no more deleted elements - for ( pElementIter = m_aChildrenList.begin(); pElementIter != m_aChildrenList.end(); pElementIter++ ) - { - // if it is a 'duplicate commit' inserted elements must be really inserted to package later - // since thay can conflict with renamed elements - - if ( !(*pElementIter)->m_bIsInserted ) - { - // for now stream is opened in direct mode that means that in case - // storage is commited all the streams from it are commited in current state. - // following two steps are separated to allow easily implement transacted mode - // for streams if we need it in future. - // Only hierarchical access uses transacted streams currently - if ( !(*pElementIter)->m_bIsStorage && (*pElementIter)->m_pStream - && !(*pElementIter)->m_pStream->IsTransacted() ) - (*pElementIter)->m_pStream->Commit(); - - // if the storage was not open, there is no need to commit it ??? - // the storage should be checked that it is commited - if ( (*pElementIter)->m_bIsStorage && (*pElementIter)->m_pStorage && (*pElementIter)->m_pStorage->m_bCommited ) - { - // it's temporary PackageFolder should be inserted instead of current one - // also the new copy of PackageFolder should be used by the children storages - - // the renamed elements are not in new temporary storage - if ( m_bCommited || m_bIsRoot ) - xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName ); - - (*pElementIter)->m_pStorage->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder ); - } - else if ( !(*pElementIter)->m_bIsStorage && (*pElementIter)->m_pStream && (*pElementIter)->m_pStream->m_bFlushed ) - { - if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - CommitStreamRelInfo( *pElementIter ); - - // the renamed elements are not in new temporary storage - if ( m_bCommited || m_bIsRoot ) - xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName ); - - (*pElementIter)->m_pStream->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder ); - } - else if ( !m_bCommited && !m_bIsRoot ) - { - // the element must be just copied to the new temporary package folder - // the connection with the original package should not be lost just because - // the element is still refered by the folder in the original hierarchy - uno::Any aPackageElement = m_xPackageFolder->getByName( (*pElementIter)->m_aOriginalName ); - xNewPackageFolder->insertByName( (*pElementIter)->m_aName, aPackageElement ); - } - else if ( (*pElementIter)->m_aName.compareTo( (*pElementIter)->m_aOriginalName ) ) - { - // this is the case when xNewPackageFolder refers to m_xPackageFolder - // in case the name was changed and it is not a changed storage - rename the element - uno::Reference< container::XNamed > xNamed; - uno::Any aPackageElement = xNewPackageFolder->getByName( (*pElementIter)->m_aOriginalName ); - xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName ); - xNewPackageFolder->insertByName( (*pElementIter)->m_aName, aPackageElement ); - - if ( m_nStorageType == embed::StorageFormats::OFOPXML && !(*pElementIter)->m_bIsStorage ) - { - if ( !(*pElementIter)->m_pStream ) - { - OpenSubStream( *pElementIter ); - if ( !(*pElementIter)->m_pStream ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - CommitStreamRelInfo( *pElementIter ); - } - } - - (*pElementIter)->m_aOriginalName = (*pElementIter)->m_aName; - } - } - - for ( pElementIter = m_aChildrenList.begin(); pElementIter != m_aChildrenList.end(); pElementIter++ ) - { - // now inserted elements can be inserted to the package - if ( (*pElementIter)->m_bIsInserted ) - { - (*pElementIter)->m_aOriginalName = (*pElementIter)->m_aName; - uno::Reference< lang::XUnoTunnel > xNewElement; - - if ( (*pElementIter)->m_bIsStorage ) - { - if ( (*pElementIter)->m_pStorage->m_bCommited ) - { - OSL_ENSURE( (*pElementIter)->m_pStorage, "An inserted storage is incomplete!\n" ); - if ( !(*pElementIter)->m_pStorage ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - (*pElementIter)->m_pStorage->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder ); - - (*pElementIter)->m_bIsInserted = sal_False; - } - } - else - { - OSL_ENSURE( (*pElementIter)->m_pStream, "An inserted stream is incomplete!\n" ); - if ( !(*pElementIter)->m_pStream ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !(*pElementIter)->m_pStream->IsTransacted() ) - (*pElementIter)->m_pStream->Commit(); - - if ( (*pElementIter)->m_pStream->m_bFlushed ) - { - if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - CommitStreamRelInfo( *pElementIter ); - - (*pElementIter)->m_pStream->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder ); - - (*pElementIter)->m_bIsInserted = sal_False; - } - } - } - } - - if ( m_nStorageType == embed::StorageFormats::PACKAGE ) - { - // move properties to the destination package folder - uno::Reference< beans::XPropertySet > xProps( xNewPackageFolder, uno::UNO_QUERY ); - if ( !xProps.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - xProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ), uno::makeAny( m_aMediaType ) ); - xProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ), uno::makeAny( m_aVersion ) ); - } - - if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - CommitRelInfo( xNewPackageFolder ); // store own relations and commit complete relations storage - - if ( m_bIsRoot ) - { - uno::Reference< util::XChangesBatch > xChangesBatch( m_xPackage, uno::UNO_QUERY ); - - OSL_ENSURE( xChangesBatch.is(), "Impossible to commit package!\n" ); - if ( !xChangesBatch.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - try - { - xChangesBatch->commitChanges(); - } - catch( const lang::WrappedTargetException& r ) - { - // the wrapped UseBackupException means that the target medium can be corrupted - embed::UseBackupException aException; - if ( r.TargetException >>= aException ) - { - m_xStream = uno::Reference< io::XStream >(); - m_xInputStream = uno::Reference< io::XInputStream >(); - throw aException; - } - - AddLog( aException.Message ); - AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - } - else if ( !m_bCommited ) - { - m_xPackageFolder = xNewPackageFolder; - m_bCommited = sal_True; - } - - // after commit the mediatype treated as the correct one - m_bMTFallbackUsed = sal_False; -} - -//----------------------------------------------- -void OStorage_Impl::Revert() -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( !( m_nStorageMode & embed::ElementModes::WRITE ) ) - return; // nothing to do - - // all the children must be removed - // they will be created later on demand - - SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin(); - while ( pElementIter != m_aChildrenList.end() ) - { - if ( (*pElementIter)->m_bIsInserted ) - { - SotElement_Impl* pToDelete = *pElementIter; - - pElementIter++; // to let the iterator be valid it should be increased before removing - - m_aChildrenList.remove( pToDelete ); - delete pToDelete; - } - else - { - ClearElement( *pElementIter ); - - (*pElementIter)->m_aName = (*pElementIter)->m_aOriginalName; - (*pElementIter)->m_bIsRemoved = sal_False; - - pElementIter++; - } - } - - // return replaced removed elements - for ( SotElementList_Impl::iterator pDeletedIter = m_aDeletedList.begin(); - pDeletedIter != m_aDeletedList.end(); - pDeletedIter++ ) - { - m_aChildrenList.push_back( (*pDeletedIter) ); - - ClearElement( *pDeletedIter ); - - (*pDeletedIter)->m_aName = (*pDeletedIter)->m_aOriginalName; - (*pDeletedIter)->m_bIsRemoved = sal_False; - } - m_aDeletedList.clear(); - - m_bControlMediaType = sal_False; - m_bControlVersion = sal_False; - - GetStorageProperties(); - - if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - { - // currently the relations storage is changed only on commit - m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_aRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >(); - m_nRelInfoStatus = RELINFO_NO_INIT; - } -} - -//----------------------------------------------- -::comphelper::SequenceAsHashMap OStorage_Impl::GetCommonRootEncryptionData() - throw ( packages::NoEncryptionException ) -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ) ; - - if ( m_nStorageType != embed::StorageFormats::PACKAGE ) - throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( m_bIsRoot ) - { - if ( !m_bHasCommonEncryptionData ) - throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - return m_aCommonEncryptionData; - } - else - { - if ( !m_pParent ) - throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - return m_pParent->GetCommonRootEncryptionData(); - } -} - -//----------------------------------------------- -SotElement_Impl* OStorage_Impl::FindElement( const ::rtl::OUString& rName ) -{ - OSL_ENSURE( rName.getLength(), "Name is empty!" ); - - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - ReadContents(); - - for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin(); - pElementIter != m_aChildrenList.end(); pElementIter++ ) - { - if ( (*pElementIter)->m_aName == rName && !(*pElementIter)->m_bIsRemoved ) - return *pElementIter; - } - - return NULL; -} - -//----------------------------------------------- -SotElement_Impl* OStorage_Impl::InsertStream( ::rtl::OUString aName, sal_Bool bEncr ) -{ - OSL_ENSURE( m_xPackage.is(), "Not possible to refer to package as to factory!\n" ); - if ( !m_xPackage.is() ) - throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Sequence< uno::Any > aSeq( 1 ); - aSeq[0] <<= sal_False; - uno::Reference< lang::XUnoTunnel > xNewElement( m_xPackage->createInstanceWithArguments( aSeq ), - uno::UNO_QUERY ); - - OSL_ENSURE( xNewElement.is(), "Not possible to create a new stream!\n" ); - if ( !xNewElement.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< packages::XDataSinkEncrSupport > xPackageSubStream( xNewElement, uno::UNO_QUERY ); - if ( !xPackageSubStream.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - OSL_ENSURE( m_nStorageType == embed::StorageFormats::PACKAGE || !bEncr, "Only package storage supports encryption!\n" ); - if ( m_nStorageType != embed::StorageFormats::PACKAGE && bEncr ) - throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // the mode is not needed for storage stream internal implementation - SotElement_Impl* pNewElement = InsertElement( aName, sal_False ); - pNewElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xFactory, bEncr, m_nStorageType, sal_True ); - - m_aChildrenList.push_back( pNewElement ); - m_bIsModified = sal_True; - m_bBroadcastModified = sal_True; - - return pNewElement; -} - -//----------------------------------------------- -SotElement_Impl* OStorage_Impl::InsertRawStream( ::rtl::OUString aName, const uno::Reference< io::XInputStream >& xInStream ) -{ - // insert of raw stream means insert and commit - OSL_ENSURE( m_xPackage.is(), "Not possible to refer to package as to factory!\n" ); - if ( !m_xPackage.is() ) - throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( m_nStorageType != embed::StorageFormats::PACKAGE ) - throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< io::XSeekable > xSeek( xInStream, uno::UNO_QUERY ); - uno::Reference< io::XInputStream > xInStrToInsert = xSeek.is() ? xInStream : - GetSeekableTempCopy( xInStream, GetServiceFactory() ); - - uno::Sequence< uno::Any > aSeq( 1 ); - aSeq[0] <<= sal_False; - uno::Reference< lang::XUnoTunnel > xNewElement( m_xPackage->createInstanceWithArguments( aSeq ), - uno::UNO_QUERY ); - - OSL_ENSURE( xNewElement.is(), "Not possible to create a new stream!\n" ); - if ( !xNewElement.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< packages::XDataSinkEncrSupport > xPackageSubStream( xNewElement, uno::UNO_QUERY ); - if ( !xPackageSubStream.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - xPackageSubStream->setRawStream( xInStrToInsert ); - - // the mode is not needed for storage stream internal implementation - SotElement_Impl* pNewElement = InsertElement( aName, sal_False ); - pNewElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xFactory, sal_True, m_nStorageType, sal_False ); - // the stream is inserted and must be treated as a commited one - pNewElement->m_pStream->SetToBeCommited(); - - m_aChildrenList.push_back( pNewElement ); - m_bIsModified = sal_True; - m_bBroadcastModified = sal_True; - - return pNewElement; -} - -//----------------------------------------------- -OStorage_Impl* OStorage_Impl::CreateNewStorageImpl( sal_Int32 nStorageMode ) -{ - OSL_ENSURE( m_xPackage.is(), "Not possible to refer to package as to factory!\n" ); - if ( !m_xPackage.is() ) - throw embed::InvalidStorageException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Sequence< uno::Any > aSeq( 1 ); - aSeq[0] <<= sal_True; - uno::Reference< lang::XUnoTunnel > xNewElement( m_xPackage->createInstanceWithArguments( aSeq ), - uno::UNO_QUERY ); - - OSL_ENSURE( xNewElement.is(), "Not possible to create a new storage!\n" ); - if ( !xNewElement.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< container::XNameContainer > xPackageSubFolder( xNewElement, uno::UNO_QUERY ); - if ( !xPackageSubFolder.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - OStorage_Impl* pResult = - new OStorage_Impl( this, nStorageMode, xPackageSubFolder, m_xPackage, m_xFactory, m_nStorageType ); - pResult->m_bIsModified = sal_True; - - return pResult; -} - -//----------------------------------------------- -SotElement_Impl* OStorage_Impl::InsertStorage( ::rtl::OUString aName, sal_Int32 nStorageMode ) -{ - SotElement_Impl* pNewElement = InsertElement( aName, sal_True ); - - pNewElement->m_pStorage = CreateNewStorageImpl( nStorageMode ); - - m_aChildrenList.push_back( pNewElement ); - - return pNewElement; -} - -//----------------------------------------------- -SotElement_Impl* OStorage_Impl::InsertElement( ::rtl::OUString aName, sal_Bool bIsStorage ) -{ - OSL_ENSURE( FindElement( aName ) == NULL, "Should not try to insert existing element" ); - - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - SotElement_Impl* pDeletedElm = NULL; - - for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin(); - pElementIter != m_aChildrenList.end(); pElementIter++ ) - { - if ( (*pElementIter)->m_aName == aName ) - { - OSL_ENSURE( (*pElementIter)->m_bIsRemoved, "Try to insert an element instead of existing one!\n" ); - if ( (*pElementIter)->m_bIsRemoved ) - { - OSL_ENSURE( !(*pElementIter)->m_bIsInserted, "Inserted elements must be deleted immediatelly!\n" ); - pDeletedElm = *pElementIter; - break; - } - } - } - - if ( pDeletedElm ) - { - if ( pDeletedElm->m_bIsStorage ) - OpenSubStorage( pDeletedElm, embed::ElementModes::READWRITE ); - else - OpenSubStream( pDeletedElm ); - - m_aChildrenList.remove( pDeletedElm ); // correct usage of list ??? - m_aDeletedList.push_back( pDeletedElm ); - } - - // create new element - return new SotElement_Impl( aName, bIsStorage, sal_True ); -} - -//----------------------------------------------- -void OStorage_Impl::OpenSubStorage( SotElement_Impl* pElement, sal_Int32 nStorageMode ) -{ - OSL_ENSURE( pElement, "pElement is not set!\n" ); - OSL_ENSURE( pElement->m_bIsStorage, "Storage flag is not set!\n" ); - - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( !pElement->m_pStorage ) - { - OSL_ENSURE( !pElement->m_bIsInserted, "Inserted element must be created already!\n" ); - - uno::Reference< lang::XUnoTunnel > xTunnel; - m_xPackageFolder->getByName( pElement->m_aOriginalName ) >>= xTunnel; - if ( !xTunnel.is() ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< container::XNameContainer > xPackageSubFolder( xTunnel, uno::UNO_QUERY ); - - OSL_ENSURE( xPackageSubFolder.is(), "Can not get XNameContainer interface from folder!\n" ); - - if ( !xPackageSubFolder.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - pElement->m_pStorage = new OStorage_Impl( this, nStorageMode, xPackageSubFolder, m_xPackage, m_xFactory, m_nStorageType ); - } -} - -//----------------------------------------------- -void OStorage_Impl::OpenSubStream( SotElement_Impl* pElement ) -{ - OSL_ENSURE( pElement, "pElement is not set!\n" ); - OSL_ENSURE( !pElement->m_bIsStorage, "Storage flag is set!\n" ); - - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - if ( !pElement->m_pStream ) - { - OSL_ENSURE( !pElement->m_bIsInserted, "Inserted element must be created already!\n" ); - - uno::Reference< lang::XUnoTunnel > xTunnel; - m_xPackageFolder->getByName( pElement->m_aOriginalName ) >>= xTunnel; - if ( !xTunnel.is() ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< packages::XDataSinkEncrSupport > xPackageSubStream( xTunnel, uno::UNO_QUERY ); - if ( !xPackageSubStream.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // the stream can never be inserted here, because inserted stream element holds the stream till commit or destruction - pElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xFactory, sal_False, m_nStorageType, sal_False, GetRelInfoStreamForName( pElement->m_aOriginalName ) ); - } -} - -//----------------------------------------------- -uno::Sequence< ::rtl::OUString > OStorage_Impl::GetElementNames() -{ - ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() ); - - ReadContents(); - - sal_uInt32 nSize = m_aChildrenList.size(); - uno::Sequence< ::rtl::OUString > aElementNames( nSize ); - - sal_uInt32 nInd = 0; - for ( SotElementList_Impl::iterator pElementIter = m_aChildrenList.begin(); - pElementIter != m_aChildrenList.end(); pElementIter++ ) - { - if ( !(*pElementIter)->m_bIsRemoved ) - aElementNames[nInd++] = (*pElementIter)->m_aName; - } - - aElementNames.realloc( nInd ); - return aElementNames; -} - -//----------------------------------------------- -void OStorage_Impl::RemoveElement( SotElement_Impl* pElement ) -{ - OSL_ENSURE( pElement, "Element must be provided!" ); - - if ( !pElement ) - return; - - if ( (pElement->m_pStorage && ( pElement->m_pStorage->m_pAntiImpl || !pElement->m_pStorage->m_aReadOnlyWrapList.empty() )) - || (pElement->m_pStream && ( pElement->m_pStream->m_pAntiImpl || !pElement->m_pStream->m_aInputStreamsList.empty() )) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: Access denied - - if ( pElement->m_bIsInserted ) - { - m_aChildrenList.remove( pElement ); - delete pElement; // ??? - } - else - { - pElement->m_bIsRemoved = sal_True; - ClearElement( pElement ); - } - - // TODO/OFOPXML: the rel stream should be removed as well -} - -//----------------------------------------------- -void OStorage_Impl::ClearElement( SotElement_Impl* pElement ) -{ - if ( pElement->m_pStorage ) - { - delete pElement->m_pStorage; - pElement->m_pStorage = NULL; - } - - if ( pElement->m_pStream ) - { - delete pElement->m_pStream; - pElement->m_pStream = NULL; - } -} - -//----------------------------------------------- -void OStorage_Impl::CloneStreamElement( const ::rtl::OUString& aStreamName, - sal_Bool bEncryptionDataProvided, - const ::comphelper::SequenceAsHashMap& aEncryptionData, - uno::Reference< io::XStream >& xTargetStream ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - SotElement_Impl *pElement = FindElement( aStreamName ); - if ( !pElement ) - { - // element does not exist, throw exception - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied - } - else if ( pElement->m_bIsStorage ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !pElement->m_pStream ) - OpenSubStream( pElement ); - - if ( pElement->m_pStream && pElement->m_pStream->m_xPackageStream.is() ) - { - // the existence of m_pAntiImpl of the child is not interesting, - // the copy will be created internally - - // usual copying is not applicable here, only last flushed version of the - // child stream should be used for copiing. Probably the childs m_xPackageStream - // can be used as a base of a new stream, that would be copied to result - // storage. The only problem is that some package streams can be accessed from outside - // at the same time ( now solwed by wrappers that remember own position ). - - if ( bEncryptionDataProvided ) - pElement->m_pStream->GetCopyOfLastCommit( xTargetStream, aEncryptionData ); - else - pElement->m_pStream->GetCopyOfLastCommit( xTargetStream ); - } - else - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: general_error -} - -//----------------------------------------------- -void OStorage_Impl::RemoveStreamRelInfo( const ::rtl::OUString& aOriginalName ) -{ - // this method should be used only in OStorage_Impl::Commit() method - // the aOriginalName can be empty, in this case the storage relation info should be removed - - if ( m_nStorageType == embed::StorageFormats::OFOPXML && m_xRelStorage.is() ) - { - ::rtl::OUString aRelStreamName = aOriginalName; - aRelStreamName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".rels" ) ); - - if ( m_xRelStorage->hasByName( aRelStreamName ) ) - m_xRelStorage->removeElement( aRelStreamName ); - } -} - -//----------------------------------------------- -void OStorage_Impl::CreateRelStorage() -{ - if ( m_nStorageType != embed::StorageFormats::OFOPXML ) - return; - - if ( !m_xRelStorage.is() ) - { - if ( !m_pRelStorElement ) - { - m_pRelStorElement = new SotElement_Impl( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ), sal_True, sal_True ); - m_pRelStorElement->m_pStorage = CreateNewStorageImpl( embed::ElementModes::WRITE ); - if ( m_pRelStorElement->m_pStorage ) - m_pRelStorElement->m_pStorage->m_pParent = NULL; // the relation storage is completely controlled by parent - } - - if ( !m_pRelStorElement->m_pStorage ) - OpenSubStorage( m_pRelStorElement, embed::ElementModes::WRITE ); - - if ( !m_pRelStorElement->m_pStorage ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - OStorage* pResultStorage = new OStorage( m_pRelStorElement->m_pStorage, sal_False ); - m_xRelStorage = uno::Reference< embed::XStorage >( (embed::XStorage*) pResultStorage ); - } -} - -//----------------------------------------------- -void OStorage_Impl::CommitStreamRelInfo( SotElement_Impl* pStreamElement ) -{ - // this method should be used only in OStorage_Impl::Commit() method - - // the stream element must be provided - if ( !pStreamElement ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( m_nStorageType == embed::StorageFormats::OFOPXML && pStreamElement->m_pStream ) - { - OSL_ENSURE( pStreamElement->m_aName.getLength(), "The name must not be empty!\n" ); - - if ( !m_xRelStorage.is() ) - { - // Create new rels storage, this is commit scenario so it must be possible - CreateRelStorage(); - } - - pStreamElement->m_pStream->CommitStreamRelInfo( m_xRelStorage, pStreamElement->m_aOriginalName, pStreamElement->m_aName ); - } -} - -//----------------------------------------------- -uno::Reference< io::XInputStream > OStorage_Impl::GetRelInfoStreamForName( const ::rtl::OUString& aName ) -{ - if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - { - ReadContents(); - if ( m_xRelStorage.is() ) - { - ::rtl::OUString aRelStreamName = aName; - aRelStreamName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".rels" ) ); - if ( m_xRelStorage->hasByName( aRelStreamName ) ) - { - uno::Reference< io::XStream > xStream = m_xRelStorage->openStreamElement( aRelStreamName, embed::ElementModes::READ ); - if ( xStream.is() ) - return xStream->getInputStream(); - } - } - } - - return uno::Reference< io::XInputStream >(); -} - -//----------------------------------------------- -void OStorage_Impl::CommitRelInfo( const uno::Reference< container::XNameContainer >& xNewPackageFolder ) -{ - // this method should be used only in OStorage_Impl::Commit() method - ::rtl::OUString aRelsStorName( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ); - - if ( !xNewPackageFolder.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( m_nStorageType == embed::StorageFormats::OFOPXML ) - { - if ( m_nRelInfoStatus == RELINFO_BROKEN || m_nRelInfoStatus == RELINFO_CHANGED_BROKEN ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( m_nRelInfoStatus == RELINFO_CHANGED - || m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ - || m_nRelInfoStatus == RELINFO_CHANGED_STREAM ) - { - if ( m_nRelInfoStatus == RELINFO_CHANGED ) - { - if ( m_aRelInfo.getLength() ) - { - CreateRelStorage(); - - uno::Reference< io::XStream > xRelsStream = - m_xRelStorage->openStreamElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".rels" ) ), - embed::ElementModes::TRUNCATE | embed::ElementModes::READWRITE ); - - uno::Reference< io::XOutputStream > xOutStream = xRelsStream->getOutputStream(); - if ( !xOutStream.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - ::comphelper::OFOPXMLHelper::WriteRelationsInfoSequence( xOutStream, m_aRelInfo, m_xFactory ); - - // set the mediatype - uno::Reference< beans::XPropertySet > xPropSet( xRelsStream, uno::UNO_QUERY_THROW ); - xPropSet->setPropertyValue( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ), - uno::makeAny( ::rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM( "application/vnd.openxmlformats-package.relationships+xml" ) ) ) ); - - m_nRelInfoStatus = RELINFO_READ; - } - else if ( m_xRelStorage.is() ) - RemoveStreamRelInfo( ::rtl::OUString() ); // remove own rel info - } - else if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM_READ - || m_nRelInfoStatus == RELINFO_CHANGED_STREAM ) - { - CreateRelStorage(); - - uno::Reference< io::XStream > xRelsStream = - m_xRelStorage->openStreamElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".rels" ) ), - embed::ElementModes::TRUNCATE | embed::ElementModes::READWRITE ); - - uno::Reference< io::XOutputStream > xOutputStream = xRelsStream->getOutputStream(); - if ( !xOutputStream.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< io::XSeekable > xSeek( m_xNewRelInfoStream, uno::UNO_QUERY_THROW ); - xSeek->seek( 0 ); - ::comphelper::OStorageHelper::CopyInputToOutput( m_xNewRelInfoStream, xOutputStream ); - - // set the mediatype - uno::Reference< beans::XPropertySet > xPropSet( xRelsStream, uno::UNO_QUERY_THROW ); - xPropSet->setPropertyValue( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MediaType" ) ), - uno::makeAny( ::rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM( "application/vnd.openxmlformats-package.relationships+xml" ) ) ) ); - - m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - if ( m_nRelInfoStatus == RELINFO_CHANGED_STREAM ) - { - m_aRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >(); - m_nRelInfoStatus = RELINFO_NO_INIT; - } - else - m_nRelInfoStatus = RELINFO_READ; - } - } - - if ( m_xRelStorage.is() ) - { - if ( m_xRelStorage->hasElements() ) - { - uno::Reference< embed::XTransactedObject > xTrans( m_xRelStorage, uno::UNO_QUERY_THROW ); - if ( xTrans.is() ) - xTrans->commit(); - } - - if ( xNewPackageFolder.is() && xNewPackageFolder->hasByName( aRelsStorName ) ) - xNewPackageFolder->removeByName( aRelsStorName ); - - if ( !m_xRelStorage->hasElements() ) - { - // the empty relations storage should not be created - delete m_pRelStorElement; - m_pRelStorElement = NULL; - m_xRelStorage = uno::Reference< embed::XStorage >(); - } - else if ( m_pRelStorElement && m_pRelStorElement->m_pStorage && xNewPackageFolder.is() ) - m_pRelStorElement->m_pStorage->InsertIntoPackageFolder( aRelsStorName, xNewPackageFolder ); - } - } -} - -//===================================================== -// OStorage implementation -//===================================================== - -//----------------------------------------------- -OStorage::OStorage( uno::Reference< io::XInputStream > xInputStream, - sal_Int32 nMode, - uno::Sequence< beans::PropertyValue > xProperties, - uno::Reference< lang::XMultiServiceFactory > xFactory, - sal_Int32 nStorageType ) -: m_pImpl( new OStorage_Impl( xInputStream, nMode, xProperties, xFactory, nStorageType ) ) -{ - m_pImpl->m_pAntiImpl = this; - m_pData = new StorInternalData_Impl( m_pImpl->m_rMutexRef, m_pImpl->m_bIsRoot, m_pImpl->m_nStorageType, sal_False ); -} - -//----------------------------------------------- -OStorage::OStorage( uno::Reference< io::XStream > xStream, - sal_Int32 nMode, - uno::Sequence< beans::PropertyValue > xProperties, - uno::Reference< lang::XMultiServiceFactory > xFactory, - sal_Int32 nStorageType ) -: m_pImpl( new OStorage_Impl( xStream, nMode, xProperties, xFactory, nStorageType ) ) -{ - m_pImpl->m_pAntiImpl = this; - m_pData = new StorInternalData_Impl( m_pImpl->m_rMutexRef, m_pImpl->m_bIsRoot, m_pImpl->m_nStorageType, sal_False ); -} - -//----------------------------------------------- -OStorage::OStorage( OStorage_Impl* pImpl, sal_Bool bReadOnlyWrap ) -: m_pImpl( pImpl ) -{ - // this call can be done only from OStorage_Impl implementation to create child storage - OSL_ENSURE( m_pImpl && m_pImpl->m_rMutexRef.Is(), "The provided pointer & mutex MUST NOT be empty!\n" ); - - m_pData = new StorInternalData_Impl( m_pImpl->m_rMutexRef, m_pImpl->m_bIsRoot, m_pImpl->m_nStorageType, bReadOnlyWrap ); - - OSL_ENSURE( ( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) == embed::ElementModes::WRITE || - m_pData->m_bReadOnlyWrap, - "The wrapper can not allow writing in case implementation does not!\n" ); - - if ( !bReadOnlyWrap ) - m_pImpl->m_pAntiImpl = this; -} - -//----------------------------------------------- -OStorage::~OStorage() -{ - { - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - if ( m_pImpl ) - { - m_refCount++; // to call dispose - try { - dispose(); - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Handled exception" ) ) ); - } - } - } - - if ( m_pData ) - { - if ( m_pData->m_pSubElDispListener ) - { - m_pData->m_pSubElDispListener->release(); - m_pData->m_pSubElDispListener = NULL; - } - - if ( m_pData->m_pTypeCollection ) - { - delete m_pData->m_pTypeCollection; - m_pData->m_pTypeCollection = NULL; - } - - delete m_pData; - } -} - -//----------------------------------------------- -void SAL_CALL OStorage::InternalDispose( sal_Bool bNotifyImpl ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::InternalDispose" ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - // the source object is also a kind of locker for the current object - // since the listeners could dispose the object while being notified - lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) ); - m_pData->m_aListenersContainer.disposeAndClear( aSource ); - - if ( m_pData->m_bReadOnlyWrap ) - { - OSL_ENSURE( !m_pData->m_aOpenSubComponentsList.size() || m_pData->m_pSubElDispListener, - "If any subelements are open the listener must exist!\n" ); - - if ( m_pData->m_pSubElDispListener ) - { - m_pData->m_pSubElDispListener->OwnerIsDisposed(); - - // iterate through m_pData->m_aOpenSubComponentsList - // deregister m_pData->m_pSubElDispListener and dispose all of them - if ( !m_pData->m_aOpenSubComponentsList.empty() ) - { - for ( WeakComponentList::iterator pCompIter = m_pData->m_aOpenSubComponentsList.begin(); - pCompIter != m_pData->m_aOpenSubComponentsList.end(); pCompIter++ ) - { - uno::Reference< lang::XComponent > xTmp = (*pCompIter); - if ( xTmp.is() ) - { - xTmp->removeEventListener( uno::Reference< lang::XEventListener >( - static_cast< lang::XEventListener* >( m_pData->m_pSubElDispListener ) ) ); - - try { - xTmp->dispose(); - } catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - } - } - } - - m_pData->m_aOpenSubComponentsList.clear(); - } - } - - if ( bNotifyImpl ) - m_pImpl->RemoveReadOnlyWrap( *this ); - } - else - { - m_pImpl->m_pAntiImpl = NULL; - - if ( bNotifyImpl ) - { - if ( m_pData->m_bIsRoot ) - delete m_pImpl; - else - { - // the noncommited changes for the storage must be removed - m_pImpl->Revert(); - } - } - } - - m_pImpl = NULL; -} - -//----------------------------------------------- -void OStorage::ChildIsDisposed( const uno::Reference< uno::XInterface >& xChild ) -{ - // this method can only be called by child disposing listener - - // this method must not contain any locking - // the locking is done in the listener - - if ( !m_pData->m_aOpenSubComponentsList.empty() ) - { - for ( WeakComponentList::iterator pCompIter = m_pData->m_aOpenSubComponentsList.begin(); - pCompIter != m_pData->m_aOpenSubComponentsList.end(); ) - { - uno::Reference< lang::XComponent > xTmp = (*pCompIter); - if ( !xTmp.is() || xTmp == xChild ) - { - WeakComponentList::iterator pIterToRemove = pCompIter; - pCompIter++; - m_pData->m_aOpenSubComponentsList.erase( pIterToRemove ); - } - else - pCompIter++; - } - } -} - -//----------------------------------------------- -void OStorage::BroadcastModifiedIfNecessary() -{ - // no need to lock mutex here for the checking of m_pImpl, and m_pData is alive until the object is destructed - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !m_pImpl->m_bBroadcastModified ) - return; - - m_pImpl->m_bBroadcastModified = sal_False; - - OSL_ENSURE( !m_pData->m_bReadOnlyWrap, "The storage can not be modified at all!\n" ); - - lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) ); - - ::cppu::OInterfaceContainerHelper* pContainer = - m_pData->m_aListenersContainer.getContainer( - ::getCppuType( ( const uno::Reference< util::XModifyListener >*) NULL ) ); - if ( pContainer ) - { - ::cppu::OInterfaceIteratorHelper pIterator( *pContainer ); - while ( pIterator.hasMoreElements( ) ) - { - ( ( util::XModifyListener* )pIterator.next( ) )->modified( aSource ); - } - } -} - -//----------------------------------------------- -void OStorage::BroadcastTransaction( sal_Int8 nMessage ) -/* - 1 - preCommit - 2 - commited - 3 - preRevert - 4 - reverted -*/ -{ - // no need to lock mutex here for the checking of m_pImpl, and m_pData is alive until the object is destructed - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - OSL_ENSURE( !m_pData->m_bReadOnlyWrap, "The storage can not be modified at all!\n" ); - - lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) ); - - ::cppu::OInterfaceContainerHelper* pContainer = - m_pData->m_aListenersContainer.getContainer( - ::getCppuType( ( const uno::Reference< embed::XTransactionListener >*) NULL ) ); - if ( pContainer ) - { - ::cppu::OInterfaceIteratorHelper pIterator( *pContainer ); - while ( pIterator.hasMoreElements( ) ) - { - OSL_ENSURE( nMessage >= 1 && nMessage <= 4, "Wrong internal notification code is used!\n" ); - - switch( nMessage ) - { - case STOR_MESS_PRECOMMIT: - ( ( embed::XTransactionListener* )pIterator.next( ) )->preCommit( aSource ); - break; - case STOR_MESS_COMMITED: - ( ( embed::XTransactionListener* )pIterator.next( ) )->commited( aSource ); - break; - case STOR_MESS_PREREVERT: - ( ( embed::XTransactionListener* )pIterator.next( ) )->preRevert( aSource ); - break; - case STOR_MESS_REVERTED: - ( ( embed::XTransactionListener* )pIterator.next( ) )->reverted( aSource ); - break; - } - } - } -} - -//----------------------------------------------- -SotElement_Impl* OStorage::OpenStreamElement_Impl( const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode, sal_Bool bEncr ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - OSL_ENSURE( !m_pData->m_bReadOnlyWrap || ( nOpenMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE, - "An element can not be opened for writing in readonly storage!\n" ); - - SotElement_Impl *pElement = m_pImpl->FindElement( aStreamName ); - if ( !pElement ) - { - // element does not exist, check if creation is allowed - if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) - || (( nOpenMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE ) - || ( nOpenMode & embed::ElementModes::NOCREATE ) == embed::ElementModes::NOCREATE ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied - - // create a new StreamElement and insert it into the list - pElement = m_pImpl->InsertStream( aStreamName, bEncr ); - } - else if ( pElement->m_bIsStorage ) - { - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - OSL_ENSURE( pElement, "In case element can not be created an exception must be thrown!" ); - - if ( !pElement->m_pStream ) - m_pImpl->OpenSubStream( pElement ); - - if ( !pElement->m_pStream ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - return pElement; -} - -//----------------------------------------------- -void OStorage::MakeLinkToSubComponent_Impl( const uno::Reference< lang::XComponent >& xComponent ) -{ - if ( !xComponent.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !m_pData->m_pSubElDispListener ) - { - m_pData->m_pSubElDispListener = new OChildDispListener_Impl( *this ); - m_pData->m_pSubElDispListener->acquire(); - } - - xComponent->addEventListener( uno::Reference< lang::XEventListener >( - static_cast< ::cppu::OWeakObject* >( m_pData->m_pSubElDispListener ), uno::UNO_QUERY ) ); - - m_pData->m_aOpenSubComponentsList.push_back( xComponent ); -} - -//____________________________________________________________________________________________________ -// XInterface -//____________________________________________________________________________________________________ - -//----------------------------------------------- -uno::Any SAL_CALL OStorage::queryInterface( const uno::Type& rType ) - throw( uno::RuntimeException ) -{ - uno::Any aReturn; - - // common interfaces - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<lang::XTypeProvider*> ( this ) - , static_cast<embed::XStorage*> ( this ) - , static_cast<embed::XStorage2*> ( this ) - , static_cast<embed::XTransactedObject*> ( this ) - , static_cast<embed::XTransactionBroadcaster*> ( this ) - , static_cast<util::XModifiable*> ( this ) - , static_cast<container::XNameAccess*> ( this ) - , static_cast<container::XElementAccess*> ( this ) - , static_cast<lang::XComponent*> ( this ) - , static_cast<beans::XPropertySet*> ( this ) - , static_cast<embed::XOptimizedStorage*> ( this ) ); - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<embed::XHierarchicalStorageAccess*> ( this ) - , static_cast<embed::XHierarchicalStorageAccess2*> ( this ) ); - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - - if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE ) - { - if ( m_pData->m_bIsRoot ) - { - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<embed::XStorageRawAccess*> ( this ) - , static_cast<embed::XEncryptionProtectedSource*> ( this ) - , static_cast<embed::XEncryptionProtectedSource2*> ( this ) - , static_cast<embed::XEncryptionProtectedStorage*> ( this ) ); - } - else - { - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<embed::XStorageRawAccess*> ( this ) ); - } - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML ) - { - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<embed::XRelationshipAccess*> ( this ) ); - } - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - - return OWeakObject::queryInterface( rType ); -} - -//----------------------------------------------- -void SAL_CALL OStorage::acquire() throw() -{ - OWeakObject::acquire(); -} - -//----------------------------------------------- -void SAL_CALL OStorage::release() throw() -{ - OWeakObject::release(); -} - -//____________________________________________________________________________________________________ -// XTypeProvider -//____________________________________________________________________________________________________ - -//----------------------------------------------- -uno::Sequence< uno::Type > SAL_CALL OStorage::getTypes() - throw( uno::RuntimeException ) -{ - if ( m_pData->m_pTypeCollection == NULL ) - { - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( m_pData->m_pTypeCollection == NULL ) - { - if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE ) - { - if ( m_pData->m_bIsRoot ) - { - m_pData->m_pTypeCollection = new ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XStorage2 >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XStorageRawAccess >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL ) - , ::getCppuType( ( const uno::Reference< util::XModifiable >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedStorage >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource2 >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XEncryptionProtectedSource >* )NULL ) - , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); - } - else - { - m_pData->m_pTypeCollection = new ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XStorage2 >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XStorageRawAccess >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL ) - , ::getCppuType( ( const uno::Reference< util::XModifiable >* )NULL ) - , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); - } - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML ) - { - m_pData->m_pTypeCollection = new ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL ) - , ::getCppuType( ( const uno::Reference< util::XModifiable >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XRelationshipAccess >* )NULL ) - , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); - } - else - { - m_pData->m_pTypeCollection = new ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactedObject >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XTransactionBroadcaster >* )NULL ) - , ::getCppuType( ( const uno::Reference< util::XModifiable >* )NULL ) - , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); - } - } - } - - return m_pData->m_pTypeCollection->getTypes() ; -} - -namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; } - -//----------------------------------------------- -uno::Sequence< sal_Int8 > SAL_CALL OStorage::getImplementationId() - throw( uno::RuntimeException ) -{ - ::cppu::OImplementationId &rID = lcl_ImplId::get(); - return rID.getImplementationId(); -} - -//____________________________________________________________________________________________________ -// XStorage -//____________________________________________________________________________________________________ - - -//----------------------------------------------- -void SAL_CALL OStorage::copyToStorage( const uno::Reference< embed::XStorage >& xDest ) - throw ( embed::InvalidStorageException, - io::IOException, - lang::IllegalArgumentException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::copyToStorage" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject*> ( this ), uno::UNO_QUERY ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - - try { - m_pImpl->CopyToStorage( xDest, sal_False ); - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy storage!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } -} - -//----------------------------------------------- -uno::Reference< io::XStream > SAL_CALL OStorage::openStreamElement( - const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::openStreamElement" ); - - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aStreamName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable element name - - if ( ( nOpenMode & embed::ElementModes::WRITE ) && m_pData->m_bReadOnlyWrap ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied - - uno::Reference< io::XStream > xResult; - try - { - SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamName, nOpenMode, sal_False ); - OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" ); - - xResult = pElement->m_pStream->GetStream( nOpenMode, sal_False ); - OSL_ENSURE( xResult.is(), "The method must throw exception instead of removing empty result!\n" ); - - if ( m_pData->m_bReadOnlyWrap ) - { - // before the storage disposes the stream it must deregister itself as listener - uno::Reference< lang::XComponent > xStreamComponent( xResult, uno::UNO_QUERY ); - if ( !xStreamComponent.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - MakeLinkToSubComponent_Impl( xStreamComponent ); - } - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const packages::WrongPasswordException& rWrongPasswordException ) - { - m_pImpl->AddLog( rWrongPasswordException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't open stream element!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - aGuard.clear(); - - BroadcastModifiedIfNecessary(); - - return xResult; -} - -//----------------------------------------------- -uno::Reference< io::XStream > SAL_CALL OStorage::openEncryptedStreamElement( - const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode, const ::rtl::OUString& aPass ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::NoEncryptionException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::openEncryptedStreamElement" ); - - return openEncryptedStream( aStreamName, nOpenMode, ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass ) ); -} - -//----------------------------------------------- -uno::Reference< embed::XStorage > SAL_CALL OStorage::openStorageElement( - const ::rtl::OUString& aStorName, sal_Int32 nStorageMode ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::openStorageElement" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aStorName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStorName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aStorName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable storage name - - if ( ( nStorageMode & embed::ElementModes::WRITE ) && m_pData->m_bReadOnlyWrap ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied - - if ( ( nStorageMode & embed::ElementModes::TRUNCATE ) - && !( nStorageMode & embed::ElementModes::WRITE ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied - - // it's allways possible to read written storage in this implementation - nStorageMode |= embed::ElementModes::READ; - - uno::Reference< embed::XStorage > xResult; - try - { - SotElement_Impl *pElement = m_pImpl->FindElement( aStorName ); - if ( !pElement ) - { - // element does not exist, check if creation is allowed - if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) - || (( nStorageMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE ) - || ( nStorageMode & embed::ElementModes::NOCREATE ) == embed::ElementModes::NOCREATE ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied - - // create a new StorageElement and insert it into the list - pElement = m_pImpl->InsertStorage( aStorName, nStorageMode ); - } - else if ( !pElement->m_bIsStorage ) - { - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - else if ( pElement->m_pStorage ) - { - // storage has already been opened; it may be opened another time, if it the mode allows to do so - if ( pElement->m_pStorage->m_pAntiImpl ) - { - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied - } - else if ( !pElement->m_pStorage->m_aReadOnlyWrapList.empty() - && ( nStorageMode & embed::ElementModes::WRITE ) ) - { - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied - } - else - { - // in case parent storage allows writing the readonly mode of the child storage is - // virtual, that means that it is just enough to change the flag to let it be writable - // and since there is no AntiImpl nobody should be notified about it - pElement->m_pStorage->m_nStorageMode = nStorageMode | embed::ElementModes::READ; - - if ( ( nStorageMode & embed::ElementModes::TRUNCATE ) ) - { - for ( SotElementList_Impl::iterator pElementIter = pElement->m_pStorage->m_aChildrenList.begin(); - pElementIter != pElement->m_pStorage->m_aChildrenList.end(); ) - { - SotElement_Impl* pElementToDel = (*pElementIter); - pElementIter++; - - m_pImpl->RemoveElement( pElementToDel ); - } - } - } - } - - if ( !pElement->m_pStorage ) - m_pImpl->OpenSubStorage( pElement, nStorageMode ); - - if ( !pElement->m_pStorage ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: general_error - - sal_Bool bReadOnlyWrap = ( ( nStorageMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE ); - OStorage* pResultStorage = new OStorage( pElement->m_pStorage, bReadOnlyWrap ); - xResult = uno::Reference< embed::XStorage >( (embed::XStorage*) pResultStorage ); - - if ( bReadOnlyWrap ) - { - // Before this call is done the object must be refcounted already - pElement->m_pStorage->SetReadOnlyWrap( *pResultStorage ); - - // before the storage disposes the stream it must deregister itself as listener - uno::Reference< lang::XComponent > xStorageComponent( xResult, uno::UNO_QUERY ); - if ( !xStorageComponent.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - MakeLinkToSubComponent_Impl( xStorageComponent ); - } - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't open storage!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - return xResult; -} - -//----------------------------------------------- -uno::Reference< io::XStream > SAL_CALL OStorage::cloneStreamElement( const ::rtl::OUString& aStreamName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::cloneStreamElement" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aStreamName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable storage name - - try - { - uno::Reference< io::XStream > xResult; - m_pImpl->CloneStreamElement( aStreamName, sal_False, ::comphelper::SequenceAsHashMap(), xResult ); - if ( !xResult.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - return xResult; - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const packages::WrongPasswordException& rWrongPasswordException ) - { - m_pImpl->AddLog( rWrongPasswordException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't clone stream!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } -} - -//----------------------------------------------- -uno::Reference< io::XStream > SAL_CALL OStorage::cloneEncryptedStreamElement( - const ::rtl::OUString& aStreamName, - const ::rtl::OUString& aPass ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::NoEncryptionException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::cloneEncryptedStreamElement" ); - - return cloneEncryptedStream( aStreamName, ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass ) ); -} - -//----------------------------------------------- -void SAL_CALL OStorage::copyLastCommitTo( - const uno::Reference< embed::XStorage >& xTargetStorage ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::copyLastCommitTo" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - try - { - m_pImpl->CopyLastCommitTo( xTargetStorage ); - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy last commit version!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - -} - -//----------------------------------------------- -void SAL_CALL OStorage::copyStorageElementLastCommitTo( - const ::rtl::OUString& aStorName, - const uno::Reference< embed::XStorage >& xTargetStorage ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::copyStorageElementLastCommitTo" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aStorName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStorName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aStorName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable storage name - - // it's allways possible to read written storage in this implementation - sal_Int32 nStorageMode = embed::ElementModes::READ; - - try - { - SotElement_Impl *pElement = m_pImpl->FindElement( aStorName ); - if ( !pElement ) - { - // element does not exist, throw exception - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied - } - else if ( !pElement->m_bIsStorage ) - { - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !pElement->m_pStorage ) - m_pImpl->OpenSubStorage( pElement, nStorageMode ); - - uno::Reference< embed::XStorage > xResult; - if ( pElement->m_pStorage ) - { - // the existence of m_pAntiImpl of the child is not interesting, - // the copy will be created internally - - pElement->m_pStorage->CopyLastCommitTo( xTargetStorage ); - } - else - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: general_error - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy last commit element version!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } -} - -//----------------------------------------------- -sal_Bool SAL_CALL OStorage::isStreamElement( const ::rtl::OUString& aElementName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable name - - SotElement_Impl* pElement = NULL; - - try - { - pElement = m_pImpl->FindElement( aElementName ); - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't detect whether it is a stream!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - if ( !pElement ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //??? - - return !pElement->m_bIsStorage; -} - -//----------------------------------------------- -sal_Bool SAL_CALL OStorage::isStorageElement( const ::rtl::OUString& aElementName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); - - SotElement_Impl* pElement = NULL; - - try - { - pElement = m_pImpl->FindElement( aElementName ); - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "can't detect whether it is a storage" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - if ( !pElement ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //??? - - return pElement->m_bIsStorage; -} - -//----------------------------------------------- -void SAL_CALL OStorage::removeElement( const ::rtl::OUString& aElementName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::removeElement" ); - - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // TODO: unacceptable name - - if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied - - try - { - SotElement_Impl* pElement = m_pImpl->FindElement( aElementName ); - - if ( !pElement ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //??? - - m_pImpl->RemoveElement( pElement ); - - m_pImpl->m_bIsModified = sal_True; - m_pImpl->m_bBroadcastModified = sal_True; - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't remove element!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - aGuard.clear(); - - BroadcastModifiedIfNecessary(); -} - -//----------------------------------------------- -void SAL_CALL OStorage::renameElement( const ::rtl::OUString& aElementName, const ::rtl::OUString& aNewName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - container::ElementExistException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::renameElement" ); - - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) - || !aNewName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && ( aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) - || aNewName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); // TODO: unacceptable element name - - if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied - - try - { - SotElement_Impl* pRefElement = m_pImpl->FindElement( aNewName ); - if ( pRefElement ) - throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //??? - - SotElement_Impl* pElement = m_pImpl->FindElement( aElementName ); - if ( !pElement ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //??? - - pElement->m_aName = aNewName; - - m_pImpl->m_bIsModified = sal_True; - m_pImpl->m_bBroadcastModified = sal_True; - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::ElementExistException& rElementExistException ) - { - m_pImpl->AddLog( rElementExistException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't rename element!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - aGuard.clear(); - - BroadcastModifiedIfNecessary(); -} - -//----------------------------------------------- -void SAL_CALL OStorage::copyElementTo( const ::rtl::OUString& aElementName, - const uno::Reference< embed::XStorage >& xDest, - const ::rtl::OUString& aNewName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - container::ElementExistException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::copyElementTo" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) - || !aNewName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( !xDest.is() ) - // || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && ( aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) - || aNewName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); // unacceptable element name - - try - { - SotElement_Impl* pElement = m_pImpl->FindElement( aElementName ); - if ( !pElement ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< XNameAccess > xNameAccess( xDest, uno::UNO_QUERY ); - if ( !xNameAccess.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( xNameAccess->hasByName( aNewName ) ) - throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - m_pImpl->CopyStorageElement( pElement, xDest, aNewName, sal_False ); - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::ElementExistException& rElementExistException ) - { - m_pImpl->AddLog( rElementExistException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy element!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } -} - - -//----------------------------------------------- -void SAL_CALL OStorage::moveElementTo( const ::rtl::OUString& aElementName, - const uno::Reference< embed::XStorage >& xDest, - const ::rtl::OUString& aNewName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - container::ElementExistException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::moveElementTo" ); - - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) - || !aNewName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && ( aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) - || aNewName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); // unacceptable element name - - if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied - - try - { - SotElement_Impl* pElement = m_pImpl->FindElement( aElementName ); - if ( !pElement ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); //??? - - uno::Reference< XNameAccess > xNameAccess( xDest, uno::UNO_QUERY ); - if ( !xNameAccess.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( xNameAccess->hasByName( aNewName ) ) - throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - m_pImpl->CopyStorageElement( pElement, xDest, aNewName, sal_False ); - - m_pImpl->RemoveElement( pElement ); - - m_pImpl->m_bIsModified = sal_True; - m_pImpl->m_bBroadcastModified = sal_True; - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::ElementExistException& rElementExistException ) - { - m_pImpl->AddLog( rElementExistException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't move element!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - aGuard.clear(); - - BroadcastModifiedIfNecessary(); -} - -//____________________________________________________________________________________________________ -// XStorage2 -//____________________________________________________________________________________________________ - -//----------------------------------------------- -uno::Reference< io::XStream > SAL_CALL OStorage::openEncryptedStream( - const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode, const uno::Sequence< beans::NamedValue >& aEncryptionData ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::NoEncryptionException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::openEncryptedStream" ); - - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) - packages::NoEncryptionException(); - - if ( ( nOpenMode & embed::ElementModes::WRITE ) && m_pData->m_bReadOnlyWrap ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied - - if ( !aEncryptionData.getLength() ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 3 ); - - uno::Reference< io::XStream > xResult; - try - { - SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamName, nOpenMode, sal_True ); - OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" ); - - xResult = pElement->m_pStream->GetStream( nOpenMode, aEncryptionData, sal_False ); - OSL_ENSURE( xResult.is(), "The method must throw exception instead of removing empty result!\n" ); - - if ( m_pData->m_bReadOnlyWrap ) - { - // before the storage disposes the stream it must deregister itself as listener - uno::Reference< lang::XComponent > xStreamComponent( xResult, uno::UNO_QUERY ); - if ( !xStreamComponent.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - MakeLinkToSubComponent_Impl( xStreamComponent ); - } - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const packages::NoEncryptionException& rNoEncryptionException ) - { - m_pImpl->AddLog( rNoEncryptionException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const packages::WrongPasswordException& rWrongPasswordException ) - { - m_pImpl->AddLog( rWrongPasswordException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't open encrypted stream stream!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - aGuard.clear(); - - BroadcastModifiedIfNecessary(); - - return xResult; -} - -//----------------------------------------------- -uno::Reference< io::XStream > SAL_CALL OStorage::cloneEncryptedStream( - const ::rtl::OUString& aStreamName, - const uno::Sequence< beans::NamedValue >& aEncryptionData ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::NoEncryptionException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::cloneEncryptedStream" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) - packages::NoEncryptionException(); - - if ( !aEncryptionData.getLength() ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); - - try - { - uno::Reference< io::XStream > xResult; - m_pImpl->CloneStreamElement( aStreamName, sal_True, aEncryptionData, xResult ); - if ( !xResult.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - return xResult; - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const packages::NoEncryptionException& rNoEncryptionException ) - { - m_pImpl->AddLog( rNoEncryptionException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const packages::WrongPasswordException& rWrongPasswordException ) - { - m_pImpl->AddLog( rWrongPasswordException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't clone encrypted stream!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } -} - - -//____________________________________________________________________________________________________ -// XStorageRawAccess -//____________________________________________________________________________________________________ - -//----------------------------------------------- -uno::Reference< io::XInputStream > SAL_CALL OStorage::getPlainRawStreamElement( - const ::rtl::OUString& sStreamName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getPlainRawStreamElement" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface is not supported and must not be accessible - - if ( !sStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( sStreamName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - uno::Reference < io::XInputStream > xTempIn; - try - { - SotElement_Impl* pElement = m_pImpl->FindElement( sStreamName ); - if ( !pElement ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !pElement->m_pStream ) - { - m_pImpl->OpenSubStream( pElement ); - if ( !pElement->m_pStream ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - uno::Reference< io::XInputStream > xRawInStream = pElement->m_pStream->GetPlainRawInStream(); - if ( !xRawInStream.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference < io::XOutputStream > xTempOut( - m_pImpl->GetServiceFactory()->createInstance ( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ), - uno::UNO_QUERY ); - xTempIn = uno::Reference < io::XInputStream >( xTempOut, uno::UNO_QUERY ); - uno::Reference < io::XSeekable > xSeek( xTempOut, uno::UNO_QUERY ); - - if ( !xTempOut.is() || !xTempIn.is() || !xSeek.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // Copy temporary file to a new one - ::comphelper::OStorageHelper::CopyInputToOutput( xRawInStream, xTempOut ); - xTempOut->closeOutput(); - xSeek->seek( 0 ); - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't get plain raw stream!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - return xTempIn; -} - -//----------------------------------------------- -uno::Reference< io::XInputStream > SAL_CALL OStorage::getRawEncrStreamElement( - const ::rtl::OUString& sStreamName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::NoEncryptionException, - container::NoSuchElementException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getRawEncrStreamElement" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) - throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !sStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( sStreamName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - uno::Reference < io::XInputStream > xTempIn; - try - { - SotElement_Impl* pElement = m_pImpl->FindElement( sStreamName ); - if ( !pElement ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !pElement->m_pStream ) - { - m_pImpl->OpenSubStream( pElement ); - if ( !pElement->m_pStream ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !pElement->m_pStream->IsEncrypted() ) - throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< io::XInputStream > xRawInStream = pElement->m_pStream->GetRawInStream(); - if ( !xRawInStream.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference < io::XOutputStream > xTempOut( - m_pImpl->GetServiceFactory()->createInstance ( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.io.TempFile" ) ) ), - uno::UNO_QUERY ); - xTempIn = uno::Reference < io::XInputStream >( xTempOut, uno::UNO_QUERY ); - uno::Reference < io::XSeekable > xSeek( xTempOut, uno::UNO_QUERY ); - - if ( !xTempOut.is() || !xTempIn.is() || !xSeek.is() ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // Copy temporary file to a new one - ::comphelper::OStorageHelper::CopyInputToOutput( xRawInStream, xTempOut ); - xTempOut->closeOutput(); - xSeek->seek( 0 ); - - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const packages::NoEncryptionException& rNoEncryptionException ) - { - m_pImpl->AddLog( rNoEncryptionException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't get raw stream!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - return xTempIn; -} - -//----------------------------------------------- -void SAL_CALL OStorage::insertRawEncrStreamElement( const ::rtl::OUString& aStreamName, - const uno::Reference< io::XInputStream >& xInStream ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::NoRawFormatException, - container::ElementExistException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::insertRawEncrStreamElement" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) - throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( !xInStream.is() ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); - - if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied - - try - { - SotElement_Impl* pElement = m_pImpl->FindElement( aStreamName ); - if ( pElement ) - throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - m_pImpl->InsertRawStream( aStreamName, xInStream ); - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const packages::NoRawFormatException& rNoRawFormatException ) - { - m_pImpl->AddLog( rNoRawFormatException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::ElementExistException& rElementExistException ) - { - m_pImpl->AddLog( rElementExistException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't insert raw stream!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } -} - -//____________________________________________________________________________________________________ -// XTransactedObject -//____________________________________________________________________________________________________ - -//----------------------------------------------- -void SAL_CALL OStorage::commit() - throw ( io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::commit" ); - - uno::Reference< util::XModifiable > xParentModif; - - try { - BroadcastTransaction( STOR_MESS_PRECOMMIT ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_bReadOnlyWrap ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access_denied - - m_pImpl->Commit(); // the root storage initiates the storing to source - - // when the storage is commited the parent is modified - if ( m_pImpl->m_pParent && m_pImpl->m_pParent->m_pAntiImpl ) - xParentModif = (util::XModifiable*)m_pImpl->m_pParent->m_pAntiImpl; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Problems on commit!" ) ), - uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ), - aCaught ); - } - - setModified( sal_False ); - if ( xParentModif.is() ) - xParentModif->setModified( sal_True ); - - BroadcastTransaction( STOR_MESS_COMMITED ); -} - -//----------------------------------------------- -void SAL_CALL OStorage::revert() - throw ( io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::revert" ); - - // the method removes all the changes done after last commit - - BroadcastTransaction( STOR_MESS_PREREVERT ); - - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - for ( SotElementList_Impl::iterator pElementIter = m_pImpl->m_aChildrenList.begin(); - pElementIter != m_pImpl->m_aChildrenList.end(); pElementIter++ ) - { - if ( ((*pElementIter)->m_pStorage - && ( (*pElementIter)->m_pStorage->m_pAntiImpl || !(*pElementIter)->m_pStorage->m_aReadOnlyWrapList.empty() )) - || ((*pElementIter)->m_pStream - && ( (*pElementIter)->m_pStream->m_pAntiImpl || !(*pElementIter)->m_pStream->m_aInputStreamsList.empty()) ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied - } - - if ( m_pData->m_bReadOnlyWrap || !m_pImpl->m_bListCreated ) - return; // nothing to do - - try { - m_pImpl->Revert(); - m_pImpl->m_bIsModified = sal_False; - m_pImpl->m_bBroadcastModified = sal_True; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Problems on revert!" ) ), - uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >( this ) ), - aCaught ); - } - - aGuard.clear(); - - setModified( sal_False ); - BroadcastTransaction( STOR_MESS_REVERTED ); -} - -//____________________________________________________________________________________________________ -// XTransactionBroadcaster -//____________________________________________________________________________________________________ - -//----------------------------------------------- -void SAL_CALL OStorage::addTransactionListener( const uno::Reference< embed::XTransactionListener >& aListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - m_pData->m_aListenersContainer.addInterface( ::getCppuType((const uno::Reference< embed::XTransactionListener >*)0), - aListener ); -} - -//----------------------------------------------- -void SAL_CALL OStorage::removeTransactionListener( const uno::Reference< embed::XTransactionListener >& aListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - m_pData->m_aListenersContainer.removeInterface( ::getCppuType((const uno::Reference< embed::XTransactionListener >*)0), - aListener ); -} - -//____________________________________________________________________________________________________ -// XModifiable -// TODO: if there will be no demand on this interface it will be removed from implementation, -// I do not want to remove it now since it is still possible that it will be inserted -// to the service back. -//____________________________________________________________________________________________________ - -//----------------------------------------------- -sal_Bool SAL_CALL OStorage::isModified() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - return m_pImpl->m_bIsModified; -} - - -//----------------------------------------------- -void SAL_CALL OStorage::setModified( sal_Bool bModified ) - throw ( beans::PropertyVetoException, - uno::RuntimeException ) -{ - ::osl::ResettableMutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_bReadOnlyWrap ) - throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied - - if ( m_pImpl->m_bIsModified != bModified ) - m_pImpl->m_bIsModified = bModified; - - aGuard.clear(); - if ( bModified ) - { - m_pImpl->m_bBroadcastModified = sal_True; - BroadcastModifiedIfNecessary(); - } -} - -//----------------------------------------------- -void SAL_CALL OStorage::addModifyListener( - const uno::Reference< util::XModifyListener >& aListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - m_pData->m_aListenersContainer.addInterface( - ::getCppuType( ( const uno::Reference< util::XModifyListener >* )0 ), aListener ); -} - - -//----------------------------------------------- -void SAL_CALL OStorage::removeModifyListener( - const uno::Reference< util::XModifyListener >& aListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - m_pData->m_aListenersContainer.removeInterface( - ::getCppuType( ( const uno::Reference< util::XModifyListener >* )0 ), aListener ); -} - -//____________________________________________________________________________________________________ -// XNameAccess -//____________________________________________________________________________________________________ - -//----------------------------------------------- -uno::Any SAL_CALL OStorage::getByName( const ::rtl::OUString& aName ) - throw ( container::NoSuchElementException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getByName" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable element name - - uno::Any aResult; - try - { - SotElement_Impl* pElement = m_pImpl->FindElement( aName ); - if ( !pElement ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( pElement->m_bIsStorage ) - aResult <<= openStorageElement( aName, embed::ElementModes::READ ); - else - aResult <<= openStreamElement( aName, embed::ElementModes::READ ); - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::WrappedTargetException& rWrappedTargetException ) - { - m_pImpl->AddLog( rWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open storage!\n" ) ), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } - - return aResult; -} - - -//----------------------------------------------- -uno::Sequence< ::rtl::OUString > SAL_CALL OStorage::getElementNames() - throw ( uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getElementNames" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - try - { - return m_pImpl->GetElementNames(); - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch ( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open storage!\n" ) ), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } -} - - -//----------------------------------------------- -sal_Bool SAL_CALL OStorage::hasByName( const ::rtl::OUString& aName ) - throw ( uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::hasByName" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aName.getLength() ) - return sal_False; - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - return sal_False; - - SotElement_Impl* pElement = NULL; - try - { - pElement = m_pImpl->FindElement( aName ); - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch ( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open storage!\n" ) ), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } - - return ( pElement != NULL ); -} - - -//----------------------------------------------- -uno::Type SAL_CALL OStorage::getElementType() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - // it is a multitype container - return uno::Type(); -} - - -//----------------------------------------------- -sal_Bool SAL_CALL OStorage::hasElements() - throw ( uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::hasElements" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - try - { - return ( m_pImpl->GetChildrenList().size() != 0 ); - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open storage!\n" ) ), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } -} - - -//____________________________________________________________________________________________________ -// XComponent -//____________________________________________________________________________________________________ - -//----------------------------------------------- -void SAL_CALL OStorage::dispose() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - try - { - InternalDispose( sal_True ); - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open storage!\n" ) ), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } -} - -//----------------------------------------------- -void SAL_CALL OStorage::addEventListener( - const uno::Reference< lang::XEventListener >& xListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - m_pData->m_aListenersContainer.addInterface( - ::getCppuType( ( const uno::Reference< lang::XEventListener >* )0 ), xListener ); -} - -//----------------------------------------------- -void SAL_CALL OStorage::removeEventListener( - const uno::Reference< lang::XEventListener >& xListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - m_pData->m_aListenersContainer.removeInterface( - ::getCppuType( ( const uno::Reference< lang::XEventListener >* )0 ), xListener ); -} - -//____________________________________________________________________________________________________ -// XEncryptionProtectedSource -//____________________________________________________________________________________________________ - -void SAL_CALL OStorage::setEncryptionPassword( const ::rtl::OUString& aPass ) - throw ( uno::RuntimeException, - io::IOException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::setEncryptionPassword" ); - setEncryptionData( ::comphelper::OStorageHelper::CreatePackageEncryptionData( aPass ) ); -} - -//----------------------------------------------- -void SAL_CALL OStorage::removeEncryption() - throw ( uno::RuntimeException, - io::IOException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::removeEncryption" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface must be visible only for package storage - - OSL_ENSURE( m_pData->m_bIsRoot, "removeEncryption() method is not available for nonroot storages!\n" ); - if ( m_pData->m_bIsRoot ) - { - try { - m_pImpl->ReadContents(); - } - catch ( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch ( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetRuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } - - // TODO: check if the password is valid - // update all streams that was encrypted with old password - - uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW ); - try - { - xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ), - uno::makeAny( uno::Sequence< beans::NamedValue >() ) ); - - m_pImpl->m_bHasCommonEncryptionData = sal_False; - m_pImpl->m_aCommonEncryptionData.clear(); - } - catch( const uno::RuntimeException& rRException ) - { - m_pImpl->AddLog( rRException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - OSL_ENSURE( sal_False, "The call must not fail, it is pretty simple!" ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - OSL_FAIL( "The call must not fail, it is pretty simple!" ); - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - } -} - -//____________________________________________________________________________________________________ -// XEncryptionProtectedSource2 -//____________________________________________________________________________________________________ - -void SAL_CALL OStorage::setEncryptionData( const uno::Sequence< beans::NamedValue >& aEncryptionData ) - throw ( io::IOException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::setEncryptionData" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface must be visible only for package storage - - if ( !aEncryptionData.getLength() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected empty encryption data!") ), uno::Reference< uno::XInterface >() ); - - OSL_ENSURE( m_pData->m_bIsRoot, "setEncryptionData() method is not available for nonroot storages!\n" ); - if ( m_pData->m_bIsRoot ) - { - try { - m_pImpl->ReadContents(); - } - catch ( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch ( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetRuntimeException( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ), - aCaught ); - } - - uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW ); - try - { - ::comphelper::SequenceAsHashMap aEncryptionMap( aEncryptionData ); - xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ), - uno::makeAny( aEncryptionMap.getAsConstNamedValueList() ) ); - - m_pImpl->m_bHasCommonEncryptionData = sal_True; - m_pImpl->m_aCommonEncryptionData = aEncryptionMap; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - } -} - -//____________________________________________________________________________________________________ -// XEncryptionProtectedStorage -//____________________________________________________________________________________________________ - -//----------------------------------------------- -void SAL_CALL OStorage::setEncryptionAlgorithms( const uno::Sequence< beans::NamedValue >& aAlgorithms ) - throw (lang::IllegalArgumentException, uno::RuntimeException) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::setEncryptionAlgorithms" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface must be visible only for package storage - - if ( !aAlgorithms.getLength() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected empty encryption algorithms list!") ), uno::Reference< uno::XInterface >() ); - - OSL_ENSURE( m_pData->m_bIsRoot, "setEncryptionAlgorithms() method is not available for nonroot storages!\n" ); - if ( m_pData->m_bIsRoot ) - { - try { - m_pImpl->ReadContents(); - } - catch ( uno::RuntimeException& aRuntimeException ) - { - m_pImpl->AddLog( aRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch ( uno::Exception& aException ) - { - m_pImpl->AddLog( aException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } - - uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW ); - try - { - xPackPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ), - uno::makeAny( aAlgorithms ) ); - } - catch ( uno::RuntimeException& aRuntimeException ) - { - m_pImpl->AddLog( aRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( lang::IllegalArgumentException& aIAException ) - { - m_pImpl->AddLog( aIAException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - throw; - } - catch( uno::Exception& aException ) - { - m_pImpl->AddLog( aException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - } -} - -//----------------------------------------------- -uno::Sequence< beans::NamedValue > SAL_CALL OStorage::getEncryptionAlgorithms() - throw (uno::RuntimeException) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getEncryptionAlgorithms" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // the interface must be visible only for package storage - - uno::Sequence< beans::NamedValue > aResult; - OSL_ENSURE( m_pData->m_bIsRoot, "getEncryptionAlgorithms() method is not available for nonroot storages!\n" ); - if ( m_pData->m_bIsRoot ) - { - try { - m_pImpl->ReadContents(); - } - catch ( uno::RuntimeException& aRuntimeException ) - { - m_pImpl->AddLog( aRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch ( uno::Exception& aException ) - { - m_pImpl->AddLog( aException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } - - uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY_THROW ); - try - { - xPackPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ) ) >>= aResult; - } - catch ( uno::RuntimeException& aRuntimeException ) - { - m_pImpl->AddLog( aRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( uno::Exception& aException ) - { - m_pImpl->AddLog( aException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - } - - return aResult; -} - - -//____________________________________________________________________________________________________ -// XPropertySet -//____________________________________________________________________________________________________ - -//----------------------------------------------- -uno::Reference< beans::XPropertySetInfo > SAL_CALL OStorage::getPropertySetInfo() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - //TODO: - return uno::Reference< beans::XPropertySetInfo >(); -} - - -//----------------------------------------------- -void SAL_CALL OStorage::setPropertyValue( const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) - throw ( beans::UnknownPropertyException, - beans::PropertyVetoException, - lang::IllegalArgumentException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::setPropertyValue" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - //TODO: think about interaction handler - - // WORKAROUND: - // The old document might have no version in the manifest.xml, so we have to allow to set the version - // even for readonly storages, so that the version from content.xml can be used. - if ( m_pData->m_bReadOnlyWrap && !aPropertyName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Version" ) ) ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: Access denied - - if ( m_pData->m_nStorageType == embed::StorageFormats::ZIP ) - throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE ) - { - if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) ) - { - aValue >>= m_pImpl->m_aMediaType; - m_pImpl->m_bControlMediaType = sal_True; - - m_pImpl->m_bBroadcastModified = sal_True; - m_pImpl->m_bIsModified = sal_True; - } - else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Version" ) ) ) - { - aValue >>= m_pImpl->m_aVersion; - m_pImpl->m_bControlVersion = sal_True; - - // this property can be set even for readonly storage - if ( !m_pData->m_bReadOnlyWrap ) - { - m_pImpl->m_bBroadcastModified = sal_True; - m_pImpl->m_bIsModified = sal_True; - } - } - else if ( ( m_pData->m_bIsRoot && ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( HAS_ENCRYPTED_ENTRIES_PROPERTY ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( HAS_NONENCRYPTED_ENTRIES_PROPERTY ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( IS_INCONSISTENT_PROPERTY ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "URL" ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RepairPackage" ) ) ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsRoot" ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MEDIATYPE_FALLBACK_USED_PROPERTY ) ) ) - throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - else - throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML ) - { - if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RelationsInfoStream" ) ) ) - { - uno::Reference< io::XInputStream > xInRelStream; - if ( ( aValue >>= xInRelStream ) && xInRelStream.is() ) - { - uno::Reference< io::XSeekable > xSeek( xInRelStream, uno::UNO_QUERY ); - if ( !xSeek.is() ) - { - // currently this is an internal property that is used for optimization - // and the stream must support XSeekable interface - // TODO/LATER: in future it can be changed if property is used from outside - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); - } - - m_pImpl->m_xNewRelInfoStream = xInRelStream; - m_pImpl->m_aRelInfo = uno::Sequence< uno::Sequence< beans::StringPair > >(); - m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED_STREAM; - m_pImpl->m_bBroadcastModified = sal_True; - m_pImpl->m_bIsModified = sal_True; - } - else - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); - } - else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RelationsInfo" ) ) ) - { - if ( aValue >>= m_pImpl->m_aRelInfo ) - { - m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED; - m_pImpl->m_bBroadcastModified = sal_True; - m_pImpl->m_bIsModified = sal_True; - } - else - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); - } - else if ( ( m_pData->m_bIsRoot && ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "URL" ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RepairPackage" ) ) ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsRoot" ) ) ) - throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - else - throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - else - throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - BroadcastModifiedIfNecessary(); -} - - -//----------------------------------------------- -uno::Any SAL_CALL OStorage::getPropertyValue( const ::rtl::OUString& aPropertyName ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getPropertyValue" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE - && ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MEDIATYPE_FALLBACK_USED_PROPERTY ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Version" ) ) ) ) - { - try - { - m_pImpl->ReadContents(); - } - catch ( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch ( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetException( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can't read contents!" ) ), - uno::Reference< XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ), - aCaught ); - } - - if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) ) - return uno::makeAny( m_pImpl->m_aMediaType ); - else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Version" ) ) ) - return uno::makeAny( m_pImpl->m_aVersion ); - else - return uno::makeAny( m_pImpl->m_bMTFallbackUsed ); - } - else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "IsRoot" ) ) ) - { - return uno::makeAny( m_pData->m_bIsRoot ); - } - else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "OpenMode" ) ) ) - { - return uno::makeAny( m_pImpl->m_nStorageMode ); - } - else if ( m_pData->m_bIsRoot ) - { - if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "URL" ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "RepairPackage" ) ) ) - { - for ( sal_Int32 aInd = 0; aInd < m_pImpl->m_xProperties.getLength(); aInd++ ) - { - if ( m_pImpl->m_xProperties[aInd].Name.equals( aPropertyName ) ) - return m_pImpl->m_xProperties[aInd].Value; - } - - if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "URL" ) ) ) - return uno::makeAny( ::rtl::OUString() ); - - return uno::makeAny( sal_False ); // RepairPackage - } - else if ( m_pData->m_nStorageType == embed::StorageFormats::PACKAGE - && ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( HAS_ENCRYPTED_ENTRIES_PROPERTY ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( HAS_NONENCRYPTED_ENTRIES_PROPERTY ) ) - || aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( IS_INCONSISTENT_PROPERTY ) ) ) ) - { - try { - m_pImpl->ReadContents(); - uno::Reference< beans::XPropertySet > xPackPropSet( m_pImpl->m_xPackage, uno::UNO_QUERY ); - if ( !xPackPropSet.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - return xPackPropSet->getPropertyValue( aPropertyName ); - } - catch ( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch ( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can not open package!\n" ) ), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } - } - } - - throw beans::UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} - - -//----------------------------------------------- -void SAL_CALL OStorage::addPropertyChangeListener( - const ::rtl::OUString& /*aPropertyName*/, - const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - //TODO: -} - - -//----------------------------------------------- -void SAL_CALL OStorage::removePropertyChangeListener( - const ::rtl::OUString& /*aPropertyName*/, - const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - //TODO: -} - - -//----------------------------------------------- -void SAL_CALL OStorage::addVetoableChangeListener( - const ::rtl::OUString& /*PropertyName*/, - const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - //TODO: -} - - -//----------------------------------------------- -void SAL_CALL OStorage::removeVetoableChangeListener( - const ::rtl::OUString& /*PropertyName*/, - const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - //TODO: -} - -//____________________________________________________________________________________________________ -// XRelationshipAccess -//____________________________________________________________________________________________________ - -// TODO/LATER: the storage and stream implementations of this interface are very similar, they could use a helper class - -//----------------------------------------------- -sal_Bool SAL_CALL OStorage::hasByID( const ::rtl::OUString& sID ) - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - try - { - getRelationshipByID( sID ); - return sal_True; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Quiet exception" ) ) ); - } - - return sal_False; -} - -//----------------------------------------------- -::rtl::OUString SAL_CALL OStorage::getTargetByID( const ::rtl::OUString& sID ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Sequence< beans::StringPair > aSeq = getRelationshipByID( sID ); - for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ ) - if ( aSeq[nInd].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Target" ) ) ) - return aSeq[nInd].Second; - - return ::rtl::OUString(); -} - -//----------------------------------------------- -::rtl::OUString SAL_CALL OStorage::getTypeByID( const ::rtl::OUString& sID ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Sequence< beans::StringPair > aSeq = getRelationshipByID( sID ); - for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ ) - if ( aSeq[nInd].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Type" ) ) ) - return aSeq[nInd].Second; - - return ::rtl::OUString(); -} - -//----------------------------------------------- -uno::Sequence< beans::StringPair > SAL_CALL OStorage::getRelationshipByID( const ::rtl::OUString& sID ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // TODO/LATER: in future the unification of the ID could be checked - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ ) - for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ ) - if ( aSeq[nInd1][nInd2].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Id" ) ) ) - { - if ( aSeq[nInd1][nInd2].Second.equals( sID ) ) - return aSeq[nInd1]; - break; - } - - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} - -//----------------------------------------------- -uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OStorage::getRelationshipsByType( const ::rtl::OUString& sType ) - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Sequence< uno::Sequence< beans::StringPair > > aResult; - sal_Int32 nEntriesNum = 0; - - // TODO/LATER: in future the unification of the ID could be checked - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ ) - for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ ) - if ( aSeq[nInd1][nInd2].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Type" ) ) ) - { - // the type is usually an URL, so the check should be case insensitive - if ( aSeq[nInd1][nInd2].Second.equalsIgnoreAsciiCase( sType ) ) - { - aResult.realloc( ++nEntriesNum ); - aResult[nEntriesNum-1] = aSeq[nInd1]; - } - break; - } - - return aResult; -} - -//----------------------------------------------- -uno::Sequence< uno::Sequence< beans::StringPair > > SAL_CALL OStorage::getAllRelationships() - throw (io::IOException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - return m_pImpl->GetAllRelationshipsIfAny(); -} - -//----------------------------------------------- -void SAL_CALL OStorage::insertRelationshipByID( const ::rtl::OUString& sID, const uno::Sequence< beans::StringPair >& aEntry, ::sal_Bool bReplace ) - throw ( container::ElementExistException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - ::rtl::OUString aIDTag( RTL_CONSTASCII_USTRINGPARAM( "Id" ) ); - - sal_Int32 nIDInd = -1; - - // TODO/LATER: in future the unification of the ID could be checked - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ ) - for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ ) - if ( aSeq[nInd1][nInd2].First.equals( aIDTag ) ) - { - if ( aSeq[nInd1][nInd2].Second.equals( sID ) ) - nIDInd = nInd1; - - break; - } - - if ( nIDInd == -1 || bReplace ) - { - if ( nIDInd == -1 ) - { - nIDInd = aSeq.getLength(); - aSeq.realloc( nIDInd + 1 ); - } - - aSeq[nIDInd].realloc( aEntry.getLength() + 1 ); - - aSeq[nIDInd][0].First = aIDTag; - aSeq[nIDInd][0].Second = sID; - sal_Int32 nIndTarget = 1; - for ( sal_Int32 nIndOrig = 0; - nIndOrig < aEntry.getLength(); - nIndOrig++ ) - { - if ( !aEntry[nIndOrig].First.equals( aIDTag ) ) - aSeq[nIDInd][nIndTarget++] = aEntry[nIndOrig]; - } - - aSeq[nIDInd].realloc( nIndTarget ); - } - else - throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - - m_pImpl->m_aRelInfo = aSeq; - m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED; -} - -//----------------------------------------------- -void SAL_CALL OStorage::removeRelationshipByID( const ::rtl::OUString& sID ) - throw ( container::NoSuchElementException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - for ( sal_Int32 nInd1 = 0; nInd1 < aSeq.getLength(); nInd1++ ) - for ( sal_Int32 nInd2 = 0; nInd2 < aSeq[nInd1].getLength(); nInd2++ ) - if ( aSeq[nInd1][nInd2].First.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Id" ) ) ) - { - if ( aSeq[nInd1][nInd2].Second.equals( sID ) ) - { - sal_Int32 nLength = aSeq.getLength(); - aSeq[nInd1] = aSeq[nLength-1]; - aSeq.realloc( nLength - 1 ); - - m_pImpl->m_aRelInfo = aSeq; - m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED; - - // TODO/LATER: in future the unification of the ID could be checked - return; - } - - break; - } - - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} - -//----------------------------------------------- -void SAL_CALL OStorage::insertRelationships( const uno::Sequence< uno::Sequence< beans::StringPair > >& aEntries, ::sal_Bool bReplace ) - throw ( container::ElementExistException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - ::rtl::OUString aIDTag( RTL_CONSTASCII_USTRINGPARAM( "Id" ) ); - uno::Sequence< uno::Sequence< beans::StringPair > > aSeq = getAllRelationships(); - uno::Sequence< uno::Sequence< beans::StringPair > > aResultSeq( aSeq.getLength() + aEntries.getLength() ); - sal_Int32 nResultInd = 0; - - for ( sal_Int32 nIndTarget1 = 0; nIndTarget1 < aSeq.getLength(); nIndTarget1++ ) - for ( sal_Int32 nIndTarget2 = 0; nIndTarget2 < aSeq[nIndTarget1].getLength(); nIndTarget2++ ) - if ( aSeq[nIndTarget1][nIndTarget2].First.equals( aIDTag ) ) - { - sal_Int32 nIndSourceSame = -1; - - for ( sal_Int32 nIndSource1 = 0; nIndSource1 < aEntries.getLength(); nIndSource1++ ) - for ( sal_Int32 nIndSource2 = 0; nIndSource2 < aEntries[nIndSource1].getLength(); nIndSource2++ ) - { - if ( aEntries[nIndSource1][nIndSource2].First.equals( aIDTag ) ) - { - if ( aEntries[nIndSource1][nIndSource2].Second.equals( aSeq[nIndTarget1][nIndTarget2].Second ) ) - { - if ( !bReplace ) - throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - nIndSourceSame = nIndSource1; - } - - break; - } - } - - if ( nIndSourceSame == -1 ) - { - // no such element in the provided sequence - aResultSeq[nResultInd++] = aSeq[nIndTarget1]; - } - - break; - } - - for ( sal_Int32 nIndSource1 = 0; nIndSource1 < aEntries.getLength(); nIndSource1++ ) - { - aResultSeq[nResultInd].realloc( aEntries[nIndSource1].getLength() ); - sal_Bool bHasID = sal_False; - sal_Int32 nResInd2 = 1; - - for ( sal_Int32 nIndSource2 = 0; nIndSource2 < aEntries[nIndSource1].getLength(); nIndSource2++ ) - if ( aEntries[nIndSource1][nIndSource2].First.equals( aIDTag ) ) - { - aResultSeq[nResultInd][0] = aEntries[nIndSource1][nIndSource2]; - bHasID = sal_True; - } - else if ( nResInd2 < aResultSeq[nResultInd].getLength() ) - aResultSeq[nResultInd][nResInd2++] = aEntries[nIndSource1][nIndSource2]; - else - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: illegal relation ( no ID ) - - if ( !bHasID ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: illegal relations - - nResultInd++; - } - - aResultSeq.realloc( nResultInd ); - m_pImpl->m_aRelInfo = aResultSeq; - m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED; -} - -//----------------------------------------------- -void SAL_CALL OStorage::clearRelationships() - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::OFOPXML ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - m_pImpl->m_aRelInfo.realloc( 0 ); - m_pImpl->m_xNewRelInfoStream = uno::Reference< io::XInputStream >(); - m_pImpl->m_nRelInfoStatus = RELINFO_CHANGED; -} - -//____________________________________________________________________________________________________ -// XOptimizedStorage -//____________________________________________________________________________________________________ -//----------------------------------------------- -void SAL_CALL OStorage::insertRawNonEncrStreamElementDirect( - const ::rtl::OUString& /*sStreamName*/, - const uno::Reference< io::XInputStream >& /*xInStream*/ ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::NoRawFormatException, - container::ElementExistException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - // not implemented currently because there is still no demand - // might need to be implemented if direct copying of compressed streams is used - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); -} - -//----------------------------------------------- -void SAL_CALL OStorage::insertStreamElementDirect( - const ::rtl::OUString& aStreamName, - const uno::Reference< io::XInputStream >& xInStream, - const uno::Sequence< beans::PropertyValue >& aProps ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::ElementExistException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::insertStreamElementDirect" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aStreamName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable storage name - - if ( m_pData->m_bReadOnlyWrap ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: access denied - - try - { - SotElement_Impl* pElement = m_pImpl->FindElement( aStreamName ); - - if ( pElement ) - throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - pElement = OpenStreamElement_Impl( aStreamName, embed::ElementModes::READWRITE, sal_False ); - OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" ); - - pElement->m_pStream->InsertStreamDirectly( xInStream, aProps ); - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::ElementExistException& rElementExistException ) - { - m_pImpl->AddLog( rElementExistException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't insert stream directly!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } -} - -//----------------------------------------------- -void SAL_CALL OStorage::copyElementDirectlyTo( - const ::rtl::OUString& aElementName, - const uno::Reference< embed::XOptimizedStorage >& xDest, - const ::rtl::OUString& aNewName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - container::ElementExistException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::copyElementDirectlyTo" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) - || !aNewName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aNewName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), uno::UNO_QUERY ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && ( aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) - || aNewName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); // unacceptable name - - try - { - SotElement_Impl* pElement = m_pImpl->FindElement( aElementName ); - if ( !pElement ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference< XNameAccess > xNameAccess( xDest, uno::UNO_QUERY ); - if ( !xNameAccess.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( xNameAccess->hasByName( aNewName ) ) - throw container::ElementExistException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // let the element be copied directly - uno::Reference< embed::XStorage > xStorDest( xDest, uno::UNO_QUERY_THROW ); - m_pImpl->CopyStorageElement( pElement, xStorDest, aNewName, sal_True ); - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::ElementExistException& rElementExistException ) - { - m_pImpl->AddLog( rElementExistException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy element direcly!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } -} - -//----------------------------------------------- -void SAL_CALL OStorage::writeAndAttachToStream( const uno::Reference< io::XStream >& xStream ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::writeAndAttachToStream" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !m_pData->m_bIsRoot ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); - - if ( !m_pImpl->m_pSwitchStream ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - try - { - m_pImpl->m_pSwitchStream->CopyAndSwitchPersistenceTo( xStream ); - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't write and attach to stream!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - -} - -//----------------------------------------------- -void SAL_CALL OStorage::attachToURL( const ::rtl::OUString& sURL, - sal_Bool bReadOnly ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::attachToURL" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !m_pData->m_bIsRoot ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 0 ); - - if ( !m_pImpl->m_pSwitchStream ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - uno::Reference < ucb::XSimpleFileAccess > xAccess( - m_pImpl->m_xFactory->createInstance ( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.SimpleFileAccess" ) ) ), - uno::UNO_QUERY_THROW ); - - try - { - if ( bReadOnly ) - { - uno::Reference< io::XInputStream > xInputStream = xAccess->openFileRead( sURL ); - m_pImpl->m_pSwitchStream->SwitchPersistenceTo( xInputStream ); - } - else - { - uno::Reference< io::XStream > xStream = xAccess->openFileReadWrite( sURL ); - m_pImpl->m_pSwitchStream->SwitchPersistenceTo( xStream ); - } - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't attach to URL!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } -} - -//----------------------------------------------- -uno::Any SAL_CALL OStorage::getElementPropertyValue( const ::rtl::OUString& aElementName, const ::rtl::OUString& aPropertyName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - io::IOException, - beans::UnknownPropertyException, - beans::PropertyVetoException, - embed::StorageWrappedTargetException, - uno::RuntimeException) -{ - RTL_LOGFILE_CONTEXT( aLog, "package (mv76033) OStorage::getElementPropertyValue" ); - - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aElementName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aElementName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aElementName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // TODO: unacceptable name - - try - { - SotElement_Impl *pElement = m_pImpl->FindElement( aElementName ); - if ( !pElement ) - throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - // TODO/LATER: Currently it is only implemented for MediaType property of substorages, might be changed in future - if ( !pElement->m_bIsStorage || m_pData->m_nStorageType != embed::StorageFormats::PACKAGE || !aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "MediaType" ) ) ) - throw beans::PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !pElement->m_pStorage ) - m_pImpl->OpenSubStorage( pElement, embed::ElementModes::READ ); - - if ( !pElement->m_pStorage ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // TODO: general_error - - pElement->m_pStorage->ReadContents(); - return uno::makeAny( pElement->m_pStorage->m_aMediaType ); - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const container::NoSuchElementException& rNoSuchElementException ) - { - m_pImpl->AddLog( rNoSuchElementException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const beans::UnknownPropertyException& rUnknownPropertyException ) - { - m_pImpl->AddLog( rUnknownPropertyException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const beans::PropertyVetoException& rPropertyVetoException ) - { - m_pImpl->AddLog( rPropertyVetoException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't get element property!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } -} - -//----------------------------------------------- -void SAL_CALL OStorage::copyStreamElementData( const ::rtl::OUString& aStreamName, const uno::Reference< io::XStream >& xTargetStream ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aStreamName.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamName, sal_False ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( m_pData->m_nStorageType == embed::StorageFormats::OFOPXML - && aStreamName.equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_rels" ) ) ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 ); // unacceptable name - - if ( !xTargetStream.is() ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 ); - - try - { - uno::Reference< io::XStream > xNonconstRef = xTargetStream; - m_pImpl->CloneStreamElement( aStreamName, sal_False, ::comphelper::SequenceAsHashMap(), xNonconstRef ); - - OSL_ENSURE( xNonconstRef == xTargetStream, "The provided stream reference seems not be filled in correctly!\n" ); - if ( xNonconstRef != xTargetStream ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // if the stream reference is set it must not be changed! - } - catch( const embed::InvalidStorageException& rInvalidStorageException ) - { - m_pImpl->AddLog( rInvalidStorageException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const lang::IllegalArgumentException& rIllegalArgumentException ) - { - m_pImpl->AddLog( rIllegalArgumentException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const packages::WrongPasswordException& rWrongPasswordException ) - { - m_pImpl->AddLog( rWrongPasswordException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const io::IOException& rIOException ) - { - m_pImpl->AddLog( rIOException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const embed::StorageWrappedTargetException& rStorageWrappedTargetException ) - { - m_pImpl->AddLog( rStorageWrappedTargetException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::RuntimeException& rRuntimeException ) - { - m_pImpl->AddLog( rRuntimeException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - throw; - } - catch( const uno::Exception& rException ) - { - m_pImpl->AddLog( rException.Message ); - m_pImpl->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Rethrow" ) ) ); - - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't copy stream data!" ) ), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - -} - -//____________________________________________________________________________________________________ -// XHierarchicalStorageAccess -//____________________________________________________________________________________________________ - -//----------------------------------------------- -uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openStreamElementByHierarchicalName( const ::rtl::OUString& aStreamPath, ::sal_Int32 nOpenMode ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aStreamPath.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, sal_True ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) - && ( nOpenMode & embed::ElementModes::WRITE ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // Access denied - - OStringList_Impl aListPath = OHierarchyHolder_Impl::GetListPathFromString( aStreamPath ); - OSL_ENSURE( aListPath.size(), "The result list must not be empty!" ); - - uno::Reference< embed::XExtendedStorageStream > xResult; - if ( aListPath.size() == 1 ) - { - // that must be a direct request for a stream - // the transacted version of the stream should be opened - - SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamPath, nOpenMode, sal_False ); - OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" ); - - xResult = uno::Reference< embed::XExtendedStorageStream >( - pElement->m_pStream->GetStream( nOpenMode, sal_True ), - uno::UNO_QUERY_THROW ); - } - else - { - // there are still storages in between - if ( !m_pData->m_rHierarchyHolder.is() ) - m_pData->m_rHierarchyHolder = new OHierarchyHolder_Impl( - uno::Reference< embed::XStorage >( static_cast< embed::XStorage* >( this ) ) ); - - xResult = m_pData->m_rHierarchyHolder->GetStreamHierarchically( - ( m_pImpl->m_nStorageMode & embed::ElementModes::READWRITE ), - aListPath, - nOpenMode ); - } - - if ( !xResult.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - return xResult; -} - -//----------------------------------------------- -uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncryptedStreamElementByHierarchicalName( const ::rtl::OUString& aStreamPath, ::sal_Int32 nOpenMode, const ::rtl::OUString& sPassword ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::NoEncryptionException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - return openEncryptedStreamByHierarchicalName( aStreamPath, nOpenMode, ::comphelper::OStorageHelper::CreatePackageEncryptionData( sPassword ) ); -} - -//----------------------------------------------- -void SAL_CALL OStorage::removeStreamElementByHierarchicalName( const ::rtl::OUString& aStreamPath ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( !aStreamPath.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, sal_True ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // Access denied - - OStringList_Impl aListPath = OHierarchyHolder_Impl::GetListPathFromString( aStreamPath ); - OSL_ENSURE( aListPath.size(), "The result list must not be empty!" ); - - if ( !m_pData->m_rHierarchyHolder.is() ) - m_pData->m_rHierarchyHolder = new OHierarchyHolder_Impl( - uno::Reference< embed::XStorage >( static_cast< embed::XStorage* >( this ) ) ); - - m_pData->m_rHierarchyHolder->RemoveStreamHierarchically( aListPath ); -} - -//____________________________________________________________________________________________________ -// XHierarchicalStorageAccess2 -//____________________________________________________________________________________________________ - -uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncryptedStreamByHierarchicalName( const ::rtl::OUString& aStreamPath, ::sal_Int32 nOpenMode, const uno::Sequence< beans::NamedValue >& aEncryptionData ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::NoEncryptionException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_pData->m_rSharedMutexRef->GetMutex() ); - - if ( !m_pImpl ) - { - ::package::StaticAddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Disposed!" ) ) ); - throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - } - - if ( m_pData->m_nStorageType != embed::StorageFormats::PACKAGE ) - throw packages::NoEncryptionException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - if ( !aStreamPath.getLength() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, sal_True ) ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected entry name syntax." ) ), uno::Reference< uno::XInterface >(), 1 ); - - if ( !aEncryptionData.getLength() ) - throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 3 ); - - if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) - && ( nOpenMode & embed::ElementModes::WRITE ) ) - throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // Access denied - - OStringList_Impl aListPath = OHierarchyHolder_Impl::GetListPathFromString( aStreamPath ); - OSL_ENSURE( aListPath.size(), "The result list must not be empty!" ); - - uno::Reference< embed::XExtendedStorageStream > xResult; - if ( aListPath.size() == 1 ) - { - // that must be a direct request for a stream - // the transacted version of the stream should be opened - - SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamPath, nOpenMode, sal_True ); - OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" ); - - xResult = uno::Reference< embed::XExtendedStorageStream >( - pElement->m_pStream->GetStream( nOpenMode, aEncryptionData, sal_True ), - uno::UNO_QUERY_THROW ); - } - else - { - // there are still storages in between - if ( !m_pData->m_rHierarchyHolder.is() ) - m_pData->m_rHierarchyHolder = new OHierarchyHolder_Impl( - uno::Reference< embed::XStorage >( static_cast< embed::XStorage* >( this ) ) ); - - xResult = m_pData->m_rHierarchyHolder->GetStreamHierarchically( - ( m_pImpl->m_nStorageMode & embed::ElementModes::READWRITE ), - aListPath, - nOpenMode, - aEncryptionData ); - } - - if ( !xResult.is() ) - throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); - - return xResult; -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/xstor/xstorage.hxx b/package/source/xstor/xstorage.hxx deleted file mode 100644 index 46de9361c..000000000 --- a/package/source/xstor/xstorage.hxx +++ /dev/null @@ -1,860 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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. - * - ************************************************************************/ - -#ifndef __XSTORAGE_HXX_ -#define __XSTORAGE_HXX_ - -#include <com/sun/star/uno/Sequence.hxx> -#include <com/sun/star/embed/XStorage2.hpp> -#include <com/sun/star/embed/XOptimizedStorage.hpp> -#include <com/sun/star/embed/XHierarchicalStorageAccess2.hpp> -#include <com/sun/star/embed/XStorageRawAccess.hpp> -#include <com/sun/star/embed/XTransactedObject.hpp> -#include <com/sun/star/embed/XTransactionBroadcaster.hpp> -#include <com/sun/star/embed/XClassifiedObject.hpp> -#include <com/sun/star/embed/XEncryptionProtectedStorage.hpp> -#include <com/sun/star/embed/XRelationshipAccess.hpp> -#include <com/sun/star/util/XModifiable.hpp> -#include <com/sun/star/container/XNameAccess.hpp> -#include <com/sun/star/container/XNameContainer.hpp> -#include <com/sun/star/util/XCloseable.hpp> -#include <com/sun/star/beans/XPropertySet.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/beans/StringPair.hpp> -#include <com/sun/star/io/XStream.hpp> -#include <com/sun/star/lang/XSingleServiceFactory.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <com/sun/star/lang/XTypeProvider.hpp> -#include <com/sun/star/lang/XComponent.hpp> -#include <com/sun/star/packages/NoEncryptionException.hpp> -#include <com/sun/star/logging/XSimpleLogRing.hpp> - -#include <cppuhelper/weak.hxx> -#include <cppuhelper/interfacecontainer.h> -#include <comphelper/sequenceashashmap.hxx> - -#include "mutexholder.hxx" - -#define RELINFO_NO_INIT 1 -#define RELINFO_READ 2 -#define RELINFO_CHANGED 3 -#define RELINFO_CHANGED_STREAM 4 -#define RELINFO_CHANGED_STREAM_READ 5 -#define RELINFO_BROKEN 6 -#define RELINFO_CHANGED_BROKEN 7 - -#define STOR_MESS_PRECOMMIT 1 -#define STOR_MESS_COMMITED 2 -#define STOR_MESS_PREREVERT 3 -#define STOR_MESS_REVERTED 4 - -namespace cppu -{ - class OTypeCollection; -} - -//================================================ -// a common implementation for an entry - -struct StorInternalData_Impl; -struct OStorage_Impl; -struct OWriteStream_Impl; - -struct SotElement_Impl -{ - ::rtl::OUString m_aName; - ::rtl::OUString m_aOriginalName; - sal_Bool m_bIsRemoved; - sal_Bool m_bIsInserted; - sal_Bool m_bIsStorage; - - OStorage_Impl* m_pStorage; - OWriteStream_Impl* m_pStream; - -public: - SotElement_Impl( const ::rtl::OUString& rName, sal_Bool bStor, sal_Bool bNew ); - ~SotElement_Impl(); -}; - -#include <list> -typedef ::std::list< SotElement_Impl* > SotElementList_Impl; - -//========================================================================= -// Main storage implementation - -class OStorage; - -struct StorageHolder_Impl -{ - OStorage* m_pPointer; - ::com::sun::star::uno::WeakReference< ::com::sun::star::embed::XStorage > m_xWeakRef; - - StorageHolder_Impl( OStorage* pStorage ) - : m_pPointer( pStorage ) - , m_xWeakRef( ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >( - (::com::sun::star::embed::XStorage*)pStorage ) ) - { - } - - StorageHolder_Impl( const StorageHolder_Impl& aSH ) - : m_pPointer( aSH.m_pPointer ) - , m_xWeakRef( aSH.m_xWeakRef ) - { - } -}; - -typedef ::std::list< StorageHolder_Impl > OStorageList_Impl; - -class SwitchablePersistenceStream; -struct OStorage_Impl -{ - SotMutexHolderRef m_rMutexRef; - - OStorage* m_pAntiImpl; // only valid if external references exists - OStorageList_Impl m_aReadOnlyWrapList; // only valid if readonly external reference exists - - sal_Int32 m_nStorageMode; // open mode ( read/write/trunc/nocreate ) - sal_Bool m_bIsModified; // only modified elements will be sent to the original content - sal_Bool m_bBroadcastModified; // will be set if notification is required - sal_Bool m_bCommited; // sending the streams is coordinated by the root storage of the package - - sal_Bool m_bIsRoot; // marks this storage as root storages that manages all commits and reverts - sal_Bool m_bListCreated; - - - SotElementList_Impl m_aChildrenList; - SotElementList_Impl m_aDeletedList; - - ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > m_xPackageFolder; - ::com::sun::star::uno::Reference< ::com::sun::star::logging::XSimpleLogRing > m_xLogRing; - - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > m_xPackage; - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory; - - // valid only for root storage - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xInputStream; // ??? may be stored in properties - ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > m_xStream; // ??? may be stored in properties - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_xProperties; - sal_Bool m_bHasCommonEncryptionData; - ::comphelper::SequenceAsHashMap m_aCommonEncryptionData; - - // must be empty in case of root storage - OStorage_Impl* m_pParent; - - sal_Bool m_bControlMediaType; - ::rtl::OUString m_aMediaType; - sal_Bool m_bMTFallbackUsed; - - sal_Bool m_bControlVersion; - ::rtl::OUString m_aVersion; - - SwitchablePersistenceStream* m_pSwitchStream; - - sal_Int32 m_nStorageType; // the mode in wich the storage is used - - // the _rels substorage that is handled in a special way in embed::StorageFormats::OFOPXML - SotElement_Impl* m_pRelStorElement; - ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > m_xRelStorage; - ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > m_aRelInfo; - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xNewRelInfoStream; - sal_Int16 m_nRelInfoStatus; - - ////////////////////////////////////////// - // Constructors - - OStorage_Impl( ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xInputStream, - sal_Int32 nMode, - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > xProperties, - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory, - sal_Int32 nStorageType ); - - OStorage_Impl( ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > xStream, - sal_Int32 nMode, - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > xProperties, - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory, - sal_Int32 nStorageType ); - - // constructor for a substorage - OStorage_Impl( OStorage_Impl* pParent, - sal_Int32 nMode, - ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer > xPackageFolder, - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > xPackage, - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory, - sal_Int32 nStorageType ); - - ~OStorage_Impl(); - - void AddLog( const ::rtl::OUString& aMessage ); - - void SetReadOnlyWrap( OStorage& aStorage ); - void RemoveReadOnlyWrap( OStorage& aStorage ); - - void OpenOwnPackage(); - void ReadContents(); - void ReadRelInfoIfNecessary(); - - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > GetServiceFactory(); - SotElementList_Impl& GetChildrenList(); - void GetStorageProperties(); - - ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > GetAllRelationshipsIfAny(); - void CopyLastCommitTo( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xNewStor ); - void CopyLastCommitTo( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xNewStor, - const ::rtl::OUString& aPass ); - - void InsertIntoPackageFolder( - const ::rtl::OUString& aName, - const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& xParentPackageFolder ); - - void Commit(); - void Revert(); - - ::comphelper::SequenceAsHashMap GetCommonRootEncryptionData() throw ( ::com::sun::star::packages::NoEncryptionException ); - - void CopyToStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xDest, - sal_Bool bDirect ); - void CopyStorageElement( SotElement_Impl* pElement, - ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > xDest, - ::rtl::OUString aName, - sal_Bool bDirect ); - - void SetModified( sal_Bool bModified ); - - SotElement_Impl* FindElement( const ::rtl::OUString& rName ); - - - SotElement_Impl* InsertStream( ::rtl::OUString aName, sal_Bool bEncr ); - SotElement_Impl* InsertRawStream( ::rtl::OUString aName, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream ); - - OStorage_Impl* CreateNewStorageImpl( sal_Int32 nStorageMode ); - SotElement_Impl* InsertStorage( ::rtl::OUString aName, sal_Int32 nStorageMode ); - SotElement_Impl* InsertElement( ::rtl::OUString aName, sal_Bool bIsStorage ); - - void OpenSubStorage( SotElement_Impl* pElement, sal_Int32 nStorageMode ); - void OpenSubStream( SotElement_Impl* pElement ); - - ::com::sun::star::uno::Sequence< ::rtl::OUString > GetElementNames(); - - void RemoveElement( SotElement_Impl* pElement ); - void ClearElement( SotElement_Impl* pElement ); - void DisposeChildren(); - - void CloneStreamElement( - const ::rtl::OUString& aStreamName, - sal_Bool bPassProvided, - const ::comphelper::SequenceAsHashMap& aEncryptionData, - ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xTargetStream ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - void RemoveStreamRelInfo( const ::rtl::OUString& aOriginalName ); - void CreateRelStorage(); - void CommitStreamRelInfo( SotElement_Impl* pStreamElement ); - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > GetRelInfoStreamForName( const ::rtl::OUString& aName ); - void CommitRelInfo( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >& xNewPackageFolder ); - - static void completeStorageStreamCopy_Impl( - const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xSource, - const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xDest, - sal_Int32 nStorageType, - const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > >& aRelInfo ); - -}; - - -class OStorage : public ::com::sun::star::lang::XTypeProvider - , public ::com::sun::star::embed::XStorage2 - , public ::com::sun::star::embed::XStorageRawAccess - , public ::com::sun::star::embed::XTransactedObject - , public ::com::sun::star::embed::XTransactionBroadcaster - , public ::com::sun::star::util::XModifiable - , public ::com::sun::star::embed::XEncryptionProtectedStorage - , public ::com::sun::star::beans::XPropertySet - , public ::com::sun::star::embed::XOptimizedStorage - , public ::com::sun::star::embed::XRelationshipAccess - , public ::com::sun::star::embed::XHierarchicalStorageAccess2 - , public ::cppu::OWeakObject -{ - OStorage_Impl* m_pImpl; - StorInternalData_Impl* m_pData; - -protected: - - void Commit_Impl(); - - SotElement_Impl* OpenStreamElement_Impl( const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode, sal_Bool bEncr ); - - void BroadcastModifiedIfNecessary(); - - void BroadcastTransaction( sal_Int8 nMessage ); - - void MakeLinkToSubComponent_Impl( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xComponent ); - -public: - - OStorage( ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xInputStream, - sal_Int32 nMode, - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > xProperties, - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory, - sal_Int32 nStorageType ); - - OStorage( ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > xStream, - sal_Int32 nMode, - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > xProperties, - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory, - sal_Int32 nStorageType ); - - OStorage( OStorage_Impl* pImpl, sal_Bool bReadOnlyWrap ); - - virtual ~OStorage(); - - void SAL_CALL InternalDispose( sal_Bool bNotifyImpl ); - - void ChildIsDisposed( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xChild ); - - sal_Int32 GetRefCount_Impl() { return m_refCount; } - - //____________________________________________________________________________________________________ - // XInterface - //____________________________________________________________________________________________________ - - virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& rType ) - throw( ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL acquire() throw(); - - virtual void SAL_CALL release() throw(); - - //____________________________________________________________________________________________________ - // XTypeProvider - //____________________________________________________________________________________________________ - - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() - throw( ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() - throw( ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XStorage - //____________________________________________________________________________________________________ - - virtual void SAL_CALL copyToStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xDest ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL openStreamElement( - const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL openEncryptedStreamElement( - const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode, const ::rtl::OUString& aPass ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::NoEncryptionException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > SAL_CALL openStorageElement( - const ::rtl::OUString& aStorName, sal_Int32 nStorageMode ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL cloneStreamElement( - const ::rtl::OUString& aStreamName ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL cloneEncryptedStreamElement( - const ::rtl::OUString& aStreamName, const ::rtl::OUString& aPass ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::NoEncryptionException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL copyLastCommitTo( - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xTargetStorage ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL copyStorageElementLastCommitTo( - const ::rtl::OUString& aStorName, - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xTargetStorage ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual sal_Bool SAL_CALL isStreamElement( const ::rtl::OUString& aElementName ) - throw ( ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::uno::RuntimeException ); - - virtual sal_Bool SAL_CALL isStorageElement( const ::rtl::OUString& aElementName ) - throw ( ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL removeElement( const ::rtl::OUString& aElementName ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL renameElement( const ::rtl::OUString& rEleName, const ::rtl::OUString& rNewName ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::container::ElementExistException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL copyElementTo( const ::rtl::OUString& aElementName, - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xDest, - const ::rtl::OUString& aNewName ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::container::ElementExistException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL moveElementTo( const ::rtl::OUString& aElementName, - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xDest, - const ::rtl::OUString& rNewName ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::container::ElementExistException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XStorage2 - //____________________________________________________________________________________________________ - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL openEncryptedStream( const ::rtl::OUString& sStreamName, ::sal_Int32 nOpenMode, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::NoEncryptionException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException); - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL cloneEncryptedStream( const ::rtl::OUString& sStreamName, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::NoEncryptionException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException); - - //____________________________________________________________________________________________________ - // XStorageRawAccess - //____________________________________________________________________________________________________ - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getPlainRawStreamElement( - const ::rtl::OUString& sStreamName ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getRawEncrStreamElement( - const ::rtl::OUString& sStreamName ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::NoEncryptionException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL insertRawEncrStreamElement( const ::rtl::OUString& aStreamName, - const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::NoRawFormatException, - ::com::sun::star::container::ElementExistException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException); - - //____________________________________________________________________________________________________ - // XTransactedObject - //____________________________________________________________________________________________________ - - virtual void SAL_CALL commit() - throw ( ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL revert() - throw ( ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XTransactionBroadcaster - //____________________________________________________________________________________________________ - - virtual void SAL_CALL addTransactionListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XTransactionListener >& aListener ) - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL removeTransactionListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XTransactionListener >& aListener ) - throw ( ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XModifiable - //____________________________________________________________________________________________________ - - virtual sal_Bool SAL_CALL isModified() - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL setModified( sal_Bool bModified ) - throw ( ::com::sun::star::beans::PropertyVetoException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL addModifyListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL removeModifyListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) - throw ( ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XNameAccess - //____________________________________________________________________________________________________ - - virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) - throw ( ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames() - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Type SAL_CALL getElementType() - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual sal_Bool SAL_CALL hasElements() - throw ( ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XComponent - //____________________________________________________________________________________________________ - - virtual void SAL_CALL dispose() - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL addEventListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL removeEventListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) - throw ( ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XEncryptionProtectedSource - //____________________________________________________________________________________________________ - - virtual void SAL_CALL setEncryptionPassword( const ::rtl::OUString& aPass ) - throw ( ::com::sun::star::uno::RuntimeException, - ::com::sun::star::io::IOException ); - - virtual void SAL_CALL removeEncryption() - throw ( ::com::sun::star::uno::RuntimeException, - ::com::sun::star::io::IOException ); - - //____________________________________________________________________________________________________ - // XEncryptionProtectedSource2 - //____________________________________________________________________________________________________ - - virtual void SAL_CALL setEncryptionData( - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData ) - throw ( ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XEncryptionProtectedStorage - //____________________________________________________________________________________________________ - - virtual void SAL_CALL setEncryptionAlgorithms( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aAlgorithms ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException); - - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > SAL_CALL getEncryptionAlgorithms() throw (::com::sun::star::uno::RuntimeException); - - //____________________________________________________________________________________________________ - // XPropertySet - //____________________________________________________________________________________________________ - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) - throw ( ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::beans::PropertyVetoException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) - throw ( ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL addPropertyChangeListener( - const ::rtl::OUString& aPropertyName, - const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) - throw ( ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL removePropertyChangeListener( - const ::rtl::OUString& aPropertyName, - const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) - throw ( ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL addVetoableChangeListener( - const ::rtl::OUString& PropertyName, - const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) - throw ( ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) - throw ( ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XOptimizedStorage - //____________________________________________________________________________________________________ - virtual void SAL_CALL insertRawNonEncrStreamElementDirect( const ::rtl::OUString& sStreamName, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::NoRawFormatException, - ::com::sun::star::container::ElementExistException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL insertStreamElementDirect( const ::rtl::OUString& sStreamName, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInStream, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProps ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::ElementExistException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL copyElementDirectlyTo( const ::rtl::OUString& sSourceName, const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XOptimizedStorage >& xTargetStorage, const ::rtl::OUString& sTargetName ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::container::ElementExistException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL writeAndAttachToStream( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xStream ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL attachToURL( const ::rtl::OUString& sURL, sal_Bool bReadOnly ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Any SAL_CALL getElementPropertyValue( const ::rtl::OUString& sElementName, const ::rtl::OUString& sPropertyName ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::io::IOException, - ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::beans::PropertyVetoException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException); - - virtual void SAL_CALL copyStreamElementData( const ::rtl::OUString& sStreamName, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& xTargetStream ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XRelationshipAccess - //____________________________________________________________________________________________________ - - virtual ::sal_Bool SAL_CALL hasByID( const ::rtl::OUString& sID ) - throw ( ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - - virtual ::rtl::OUString SAL_CALL getTargetByID( const ::rtl::OUString& sID ) - throw ( ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - - virtual ::rtl::OUString SAL_CALL getTypeByID( const ::rtl::OUString& sID ) - throw ( ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > SAL_CALL getRelationshipByID( const ::rtl::OUString& sID ) - throw ( ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > SAL_CALL getRelationshipsByType( const ::rtl::OUString& sType ) - throw ( ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > > SAL_CALL getAllRelationships( ) - throw ( ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - - virtual void SAL_CALL insertRelationshipByID( const ::rtl::OUString& sID, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair >& aEntry, ::sal_Bool bReplace ) - throw ( ::com::sun::star::container::ElementExistException, - ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - - virtual void SAL_CALL removeRelationshipByID( const ::rtl::OUString& sID ) - throw ( ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - - virtual void SAL_CALL insertRelationships( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::StringPair > >& aEntries, ::sal_Bool bReplace ) - throw ( ::com::sun::star::container::ElementExistException, - ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - - virtual void SAL_CALL clearRelationships( ) - throw ( ::com::sun::star::io::IOException, - ::com::sun::star::uno::RuntimeException); - - //____________________________________________________________________________________________________ - // XHierarchicalStorageAccess - //____________________________________________________________________________________________________ - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream > SAL_CALL openStreamElementByHierarchicalName( const ::rtl::OUString& sStreamPath, ::sal_Int32 nOpenMode ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException); - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream > SAL_CALL openEncryptedStreamElementByHierarchicalName( const ::rtl::OUString& sStreamName, ::sal_Int32 nOpenMode, const ::rtl::OUString& sPassword ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::NoEncryptionException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException); - - virtual void SAL_CALL removeStreamElementByHierarchicalName( const ::rtl::OUString& sElementPath ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException); - - //____________________________________________________________________________________________________ - // XHierarchicalStorageAccess2 - //____________________________________________________________________________________________________ - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream > SAL_CALL openEncryptedStreamByHierarchicalName( const ::rtl::OUString& sStreamName, ::sal_Int32 nOpenMode, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::NoEncryptionException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); -}; - - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |