1*a3872823SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*a3872823SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*a3872823SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*a3872823SAndrew Rist  * distributed with this work for additional information
6*a3872823SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*a3872823SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*a3872823SAndrew Rist  * "License"); you may not use this file except in compliance
9*a3872823SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*a3872823SAndrew Rist  *
11*a3872823SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*a3872823SAndrew Rist  *
13*a3872823SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*a3872823SAndrew Rist  * software distributed under the License is distributed on an
15*a3872823SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*a3872823SAndrew Rist  * KIND, either express or implied.  See the License for the
17*a3872823SAndrew Rist  * specific language governing permissions and limitations
18*a3872823SAndrew Rist  * under the License.
19*a3872823SAndrew Rist  *
20*a3872823SAndrew Rist  *************************************************************/
21*a3872823SAndrew Rist 
22*a3872823SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER( update_precomp.py ): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_package.hxx"
26cdf0e10cSrcweir #include <ZipPackage.hxx>
27cdf0e10cSrcweir #include <ZipPackageSink.hxx>
28cdf0e10cSrcweir #include <ZipEnumeration.hxx>
29cdf0e10cSrcweir #include <ZipPackageStream.hxx>
30cdf0e10cSrcweir #include <ZipPackageFolder.hxx>
31cdf0e10cSrcweir #include <ZipOutputStream.hxx>
32cdf0e10cSrcweir #include <ZipPackageBuffer.hxx>
33cdf0e10cSrcweir #include <ZipFile.hxx>
34cdf0e10cSrcweir #include <PackageConstants.hxx>
35cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
36cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
37cdf0e10cSrcweir #include <com/sun/star/packages/zip/ZipConstants.hpp>
38cdf0e10cSrcweir #include <com/sun/star/packages/manifest/XManifestReader.hpp>
39cdf0e10cSrcweir #include <com/sun/star/packages/manifest/XManifestWriter.hpp>
40cdf0e10cSrcweir #include <com/sun/star/io/XStream.hpp>
41cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
42cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp>
43cdf0e10cSrcweir #include <com/sun/star/io/XTruncate.hpp>
44cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hpp>
45cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
46cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
47cdf0e10cSrcweir #include <com/sun/star/ucb/IOErrorCode.hpp>
48cdf0e10cSrcweir #include <ucbhelper/content.hxx>
49cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
50cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
51cdf0e10cSrcweir #include <com/sun/star/ucb/TransferInfo.hpp>
52cdf0e10cSrcweir #include <com/sun/star/ucb/NameClash.hpp>
53cdf0e10cSrcweir #include <com/sun/star/ucb/OpenCommandArgument2.hpp>
54cdf0e10cSrcweir #include <com/sun/star/ucb/OpenMode.hpp>
55cdf0e10cSrcweir #include <com/sun/star/ucb/XProgressHandler.hpp>
56cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
57cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataStreamer.hpp>
58cdf0e10cSrcweir #include <com/sun/star/embed/XTransactedObject.hpp>
59cdf0e10cSrcweir #include <com/sun/star/embed/UseBackupException.hpp>
60cdf0e10cSrcweir #include <com/sun/star/embed/StorageFormats.hpp>
61cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
62cdf0e10cSrcweir #include <com/sun/star/xml/crypto/DigestID.hpp>
63cdf0e10cSrcweir #include <com/sun/star/xml/crypto/CipherID.hpp>
64cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
65cdf0e10cSrcweir #include <ContentInfo.hxx>
66cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
67cdf0e10cSrcweir #include <rtl/uri.hxx>
68cdf0e10cSrcweir #include <rtl/random.h>
69cdf0e10cSrcweir #include <rtl/logfile.hxx>
70cdf0e10cSrcweir #include <rtl/instance.hxx>
71cdf0e10cSrcweir #include <osl/time.h>
72cdf0e10cSrcweir #include <osl/file.hxx>
73cdf0e10cSrcweir #include "com/sun/star/io/XAsyncOutputMonitor.hpp"
74cdf0e10cSrcweir 
75cdf0e10cSrcweir #include <memory>
76cdf0e10cSrcweir #include <vector>
77cdf0e10cSrcweir 
78cdf0e10cSrcweir #include <ucbhelper/contentbroker.hxx>
79cdf0e10cSrcweir #include <ucbhelper/fileidentifierconverter.hxx>
80cdf0e10cSrcweir #include <comphelper/seekableinput.hxx>
81cdf0e10cSrcweir #include <comphelper/storagehelper.hxx>
82cdf0e10cSrcweir #include <comphelper/ofopxmlhelper.hxx>
83cdf0e10cSrcweir #include <comphelper/documentconstants.hxx>
84cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx>
85cdf0e10cSrcweir 
86cdf0e10cSrcweir using namespace rtl;
87cdf0e10cSrcweir using namespace std;
88cdf0e10cSrcweir using namespace osl;
89cdf0e10cSrcweir using namespace cppu;
90cdf0e10cSrcweir using namespace ucbhelper;
91cdf0e10cSrcweir using namespace com::sun::star;
92cdf0e10cSrcweir using namespace com::sun::star::io;
93cdf0e10cSrcweir using namespace com::sun::star::uno;
94cdf0e10cSrcweir using namespace com::sun::star::ucb;
95cdf0e10cSrcweir using namespace com::sun::star::util;
96cdf0e10cSrcweir using namespace com::sun::star::lang;
97cdf0e10cSrcweir using namespace com::sun::star::task;
98cdf0e10cSrcweir using namespace com::sun::star::beans;
99cdf0e10cSrcweir using namespace com::sun::star::packages;
100cdf0e10cSrcweir using namespace com::sun::star::container;
101cdf0e10cSrcweir using namespace com::sun::star::packages::zip;
102cdf0e10cSrcweir using namespace com::sun::star::packages::manifest;
103cdf0e10cSrcweir using namespace com::sun::star::packages::zip::ZipConstants;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir #define LOGFILE_AUTHOR "mg115289"
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 
108cdf0e10cSrcweir namespace {
109cdf0e10cSrcweir 
isLocalFile_Impl(::rtl::OUString aURL)110cdf0e10cSrcweir sal_Bool isLocalFile_Impl( ::rtl::OUString aURL )
111cdf0e10cSrcweir {
112cdf0e10cSrcweir 	::rtl::OUString aSystemPath;
113cdf0e10cSrcweir     ContentBroker* pBroker = ContentBroker::get();
114cdf0e10cSrcweir     if ( !pBroker )
115cdf0e10cSrcweir     {
116cdf0e10cSrcweir 		::rtl::OUString aRet;
117cdf0e10cSrcweir         if ( FileBase::getSystemPathFromFileURL( aURL, aRet ) == FileBase::E_None )
118cdf0e10cSrcweir 			aSystemPath = aRet;
119cdf0e10cSrcweir     }
120cdf0e10cSrcweir     else
121cdf0e10cSrcweir     {
122cdf0e10cSrcweir         uno::Reference< XContentProviderManager > xManager =
123cdf0e10cSrcweir 				pBroker->getContentProviderManagerInterface();
124cdf0e10cSrcweir         try
125cdf0e10cSrcweir         {
126cdf0e10cSrcweir            	aSystemPath = getSystemPathFromFileURL( xManager, aURL );
127cdf0e10cSrcweir         }
128cdf0e10cSrcweir         catch ( Exception& )
129cdf0e10cSrcweir         {
130cdf0e10cSrcweir         }
131cdf0e10cSrcweir     }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     return ( aSystemPath.getLength() != 0 );
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir //===========================================================================
139cdf0e10cSrcweir 
140cdf0e10cSrcweir class ActiveDataStreamer : public ::cppu::WeakImplHelper1< XActiveDataStreamer >
141cdf0e10cSrcweir {
142cdf0e10cSrcweir 	uno::Reference< XStream > mStream;
143cdf0e10cSrcweir public:
144cdf0e10cSrcweir 
getStream()145cdf0e10cSrcweir 	virtual uno::Reference< XStream > SAL_CALL getStream()
146cdf0e10cSrcweir 			throw( RuntimeException )
147cdf0e10cSrcweir 			{ return mStream; }
148cdf0e10cSrcweir 
setStream(const uno::Reference<XStream> & stream)149cdf0e10cSrcweir 	virtual void SAL_CALL setStream( const uno::Reference< XStream >& stream )
150cdf0e10cSrcweir 			throw( RuntimeException )
151cdf0e10cSrcweir 			{ mStream = stream; }
152cdf0e10cSrcweir };
153cdf0e10cSrcweir 
154cdf0e10cSrcweir class DummyInputStream : public ::cppu::WeakImplHelper1< XInputStream >
155cdf0e10cSrcweir {
readBytes(uno::Sequence<sal_Int8> &,sal_Int32)156cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL readBytes( uno::Sequence< sal_Int8 >&, sal_Int32 )
157cdf0e10cSrcweir 			throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException )
158cdf0e10cSrcweir 		{ return 0; }
159cdf0e10cSrcweir 
readSomeBytes(uno::Sequence<sal_Int8> &,sal_Int32)160cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL readSomeBytes( uno::Sequence< sal_Int8 >&, sal_Int32 )
161cdf0e10cSrcweir 			throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException )
162cdf0e10cSrcweir 		{ return 0; }
163cdf0e10cSrcweir 
skipBytes(sal_Int32)164cdf0e10cSrcweir     virtual void SAL_CALL skipBytes( sal_Int32 )
165cdf0e10cSrcweir 			throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException )
166cdf0e10cSrcweir 		{}
167cdf0e10cSrcweir 
available()168cdf0e10cSrcweir     virtual sal_Int32 SAL_CALL available()
169cdf0e10cSrcweir 			throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException )
170cdf0e10cSrcweir 		{ return 0; }
171cdf0e10cSrcweir 
closeInput()172cdf0e10cSrcweir     virtual void SAL_CALL closeInput()
173cdf0e10cSrcweir 			throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException )
174cdf0e10cSrcweir 		{}
175cdf0e10cSrcweir };
176cdf0e10cSrcweir 
177cdf0e10cSrcweir //===========================================================================
178cdf0e10cSrcweir 
ZipPackage(const uno::Reference<XMultiServiceFactory> & xNewFactory)179cdf0e10cSrcweir ZipPackage::ZipPackage ( const uno::Reference < XMultiServiceFactory > &xNewFactory )
180cdf0e10cSrcweir : m_aMutexHolder( new SotMutexHolder )
181cdf0e10cSrcweir , m_nStartKeyGenerationID( xml::crypto::DigestID::SHA1 )
182cdf0e10cSrcweir , m_nChecksumDigestID( xml::crypto::DigestID::SHA1_1K )
183cdf0e10cSrcweir , m_nCommonEncryptionID( xml::crypto::CipherID::BLOWFISH_CFB_8 )
184cdf0e10cSrcweir , m_bHasEncryptedEntries ( sal_False )
185cdf0e10cSrcweir , m_bHasNonEncryptedEntries ( sal_False )
186cdf0e10cSrcweir , m_bInconsistent ( sal_False )
187cdf0e10cSrcweir , m_bForceRecovery ( sal_False )
188cdf0e10cSrcweir , m_bMediaTypeFallbackUsed ( sal_False )
189cdf0e10cSrcweir , m_nFormat( embed::StorageFormats::PACKAGE ) // package is the default format
190cdf0e10cSrcweir , m_bAllowRemoveOnInsert( sal_True )
191cdf0e10cSrcweir , m_eMode ( e_IMode_None )
192cdf0e10cSrcweir , m_xFactory( xNewFactory )
193cdf0e10cSrcweir , m_pRootFolder( NULL )
194cdf0e10cSrcweir , m_pZipFile( NULL )
195cdf0e10cSrcweir {
196cdf0e10cSrcweir 	m_xRootFolder = m_pRootFolder = new ZipPackageFolder( m_xFactory, m_nFormat, m_bAllowRemoveOnInsert );
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
~ZipPackage(void)199cdf0e10cSrcweir ZipPackage::~ZipPackage( void )
200cdf0e10cSrcweir {
201cdf0e10cSrcweir 	delete m_pZipFile;
202cdf0e10cSrcweir 
203cdf0e10cSrcweir 	// All folders and streams contain pointers to their parents, when a parent diappeares
204cdf0e10cSrcweir 	// it should disconnect all the children from itself during destruction automatically.
205cdf0e10cSrcweir 	// So there is no need in explicit m_pRootFolder->releaseUpwardRef() call here any more
206cdf0e10cSrcweir 	// since m_pRootFolder has no parent and cleaning of it's children will be done automatically
207cdf0e10cSrcweir 	// during m_pRootFolder dieing by refcount.
208cdf0e10cSrcweir }
209cdf0e10cSrcweir 
210cdf0e10cSrcweir //--------------------------------------------------------
parseManifest()211cdf0e10cSrcweir void ZipPackage::parseManifest()
212cdf0e10cSrcweir {
213cdf0e10cSrcweir 	if ( m_nFormat == embed::StorageFormats::PACKAGE )
214cdf0e10cSrcweir 	{
215cdf0e10cSrcweir 		sal_Bool bManifestParsed = sal_False;
216cdf0e10cSrcweir         bool bDifferentStartKeyAlgorithm = false;
217cdf0e10cSrcweir 		const OUString sMeta ( RTL_CONSTASCII_USTRINGPARAM ( "META-INF" ) );
218cdf0e10cSrcweir 		if ( m_xRootFolder->hasByName( sMeta ) )
219cdf0e10cSrcweir 		{
220cdf0e10cSrcweir 			const OUString sManifest ( RTL_CONSTASCII_USTRINGPARAM( "manifest.xml" ) );
221cdf0e10cSrcweir 
222cdf0e10cSrcweir 			try {
223cdf0e10cSrcweir 				uno::Reference< XUnoTunnel > xTunnel;
224cdf0e10cSrcweir 				Any aAny = m_xRootFolder->getByName( sMeta );
225cdf0e10cSrcweir 				aAny >>= xTunnel;
226cdf0e10cSrcweir 				uno::Reference< XNameContainer > xMetaInfFolder( xTunnel, UNO_QUERY );
227cdf0e10cSrcweir 				if ( xMetaInfFolder.is() && xMetaInfFolder->hasByName( sManifest ) )
228cdf0e10cSrcweir 				{
229cdf0e10cSrcweir 					aAny = xMetaInfFolder->getByName( sManifest );
230cdf0e10cSrcweir 					aAny >>= xTunnel;
231cdf0e10cSrcweir 					uno::Reference < XActiveDataSink > xSink ( xTunnel, UNO_QUERY );
232cdf0e10cSrcweir 					if ( xSink.is() )
233cdf0e10cSrcweir 					{
234cdf0e10cSrcweir 						OUString sManifestReader ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.ManifestReader" ) );
235cdf0e10cSrcweir 						uno::Reference < XManifestReader > xReader ( m_xFactory->createInstance( sManifestReader ), UNO_QUERY );
236cdf0e10cSrcweir 						if ( xReader.is() )
237cdf0e10cSrcweir 						{
238cdf0e10cSrcweir 							const OUString sPropFullPath ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) );
239cdf0e10cSrcweir 							const OUString sPropVersion ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) );
240cdf0e10cSrcweir 							const OUString sPropMediaType ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) );
241cdf0e10cSrcweir 							const OUString sPropInitialisationVector ( RTL_CONSTASCII_USTRINGPARAM ( "InitialisationVector" ) );
242cdf0e10cSrcweir 							const OUString sPropSalt ( RTL_CONSTASCII_USTRINGPARAM ( "Salt" ) );
243cdf0e10cSrcweir 							const OUString sPropIterationCount ( RTL_CONSTASCII_USTRINGPARAM ( "IterationCount" ) );
244cdf0e10cSrcweir 							const OUString sPropSize ( RTL_CONSTASCII_USTRINGPARAM ( "Size" ) );
245cdf0e10cSrcweir 							const OUString sPropDigest ( RTL_CONSTASCII_USTRINGPARAM ( "Digest" ) );
246cdf0e10cSrcweir 							const OUString sPropDerivedKeySize ( RTL_CONSTASCII_USTRINGPARAM ( "DerivedKeySize" ) );
247cdf0e10cSrcweir 							const OUString sPropDigestAlgorithm ( RTL_CONSTASCII_USTRINGPARAM ( "DigestAlgorithm" ) );
248cdf0e10cSrcweir 							const OUString sPropEncryptionAlgorithm ( RTL_CONSTASCII_USTRINGPARAM ( "EncryptionAlgorithm" ) );
249cdf0e10cSrcweir 							const OUString sPropStartKeyAlgorithm ( RTL_CONSTASCII_USTRINGPARAM ( "StartKeyAlgorithm" ) );
250cdf0e10cSrcweir 
251cdf0e10cSrcweir 							uno::Sequence < uno::Sequence < PropertyValue > > aManifestSequence = xReader->readManifestSequence ( xSink->getInputStream() );
252cdf0e10cSrcweir 							sal_Int32 nLength = aManifestSequence.getLength();
253cdf0e10cSrcweir 							const uno::Sequence < PropertyValue > *pSequence = aManifestSequence.getConstArray();
254cdf0e10cSrcweir 							ZipPackageStream *pStream = NULL;
255cdf0e10cSrcweir 							ZipPackageFolder *pFolder = NULL;
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 							for ( sal_Int32 i = 0; i < nLength ; i++, pSequence++ )
258cdf0e10cSrcweir 							{
259cdf0e10cSrcweir 								OUString sPath, sMediaType, sVersion;
260cdf0e10cSrcweir 								const PropertyValue *pValue = pSequence->getConstArray();
261cdf0e10cSrcweir 								const Any *pSalt = NULL, *pVector = NULL, *pCount = NULL, *pSize = NULL, *pDigest = NULL, *pDigestAlg = NULL, *pEncryptionAlg = NULL, *pStartKeyAlg = NULL, *pDerivedKeySize = NULL;
262cdf0e10cSrcweir 								for ( sal_Int32 j = 0, nNum = pSequence->getLength(); j < nNum; j++ )
263cdf0e10cSrcweir 								{
264cdf0e10cSrcweir 									if ( pValue[j].Name.equals( sPropFullPath ) )
265cdf0e10cSrcweir 										pValue[j].Value >>= sPath;
266cdf0e10cSrcweir 									else if ( pValue[j].Name.equals( sPropVersion ) )
267cdf0e10cSrcweir 										pValue[j].Value >>= sVersion;
268cdf0e10cSrcweir 									else if ( pValue[j].Name.equals( sPropMediaType ) )
269cdf0e10cSrcweir 										pValue[j].Value >>= sMediaType;
270cdf0e10cSrcweir 									else if ( pValue[j].Name.equals( sPropSalt ) )
271cdf0e10cSrcweir 										pSalt = &( pValue[j].Value );
272cdf0e10cSrcweir 									else if ( pValue[j].Name.equals( sPropInitialisationVector ) )
273cdf0e10cSrcweir 										pVector = &( pValue[j].Value );
274cdf0e10cSrcweir 									else if ( pValue[j].Name.equals( sPropIterationCount ) )
275cdf0e10cSrcweir 										pCount = &( pValue[j].Value );
276cdf0e10cSrcweir 									else if ( pValue[j].Name.equals( sPropSize ) )
277cdf0e10cSrcweir 										pSize = &( pValue[j].Value );
278cdf0e10cSrcweir 									else if ( pValue[j].Name.equals( sPropDigest ) )
279cdf0e10cSrcweir 										pDigest = &( pValue[j].Value );
280cdf0e10cSrcweir 									else if ( pValue[j].Name.equals( sPropDigestAlgorithm ) )
281cdf0e10cSrcweir 										pDigestAlg = &( pValue[j].Value );
282cdf0e10cSrcweir 									else if ( pValue[j].Name.equals( sPropEncryptionAlgorithm ) )
283cdf0e10cSrcweir 										pEncryptionAlg = &( pValue[j].Value );
284cdf0e10cSrcweir 									else if ( pValue[j].Name.equals( sPropStartKeyAlgorithm ) )
285cdf0e10cSrcweir 										pStartKeyAlg = &( pValue[j].Value );
286cdf0e10cSrcweir 									else if ( pValue[j].Name.equals( sPropDerivedKeySize ) )
287cdf0e10cSrcweir 										pDerivedKeySize = &( pValue[j].Value );
288cdf0e10cSrcweir 								}
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 								if ( sPath.getLength() && hasByHierarchicalName ( sPath ) )
291cdf0e10cSrcweir 								{
292cdf0e10cSrcweir 									aAny = getByHierarchicalName( sPath );
293cdf0e10cSrcweir 									uno::Reference < XUnoTunnel > xUnoTunnel;
294cdf0e10cSrcweir 									aAny >>= xUnoTunnel;
295cdf0e10cSrcweir 									sal_Int64 nTest=0;
296cdf0e10cSrcweir 									if ( (nTest = xUnoTunnel->getSomething( ZipPackageFolder::static_getImplementationId() )) != 0 )
297cdf0e10cSrcweir 									{
298cdf0e10cSrcweir 										pFolder = reinterpret_cast < ZipPackageFolder* > ( nTest );
299cdf0e10cSrcweir 										pFolder->SetMediaType ( sMediaType );
300cdf0e10cSrcweir 										pFolder->SetVersion ( sVersion );
301cdf0e10cSrcweir 									}
302cdf0e10cSrcweir 									else
303cdf0e10cSrcweir 									{
304cdf0e10cSrcweir 										pStream = reinterpret_cast < ZipPackageStream* > ( xUnoTunnel->getSomething( ZipPackageStream::static_getImplementationId() ));
305cdf0e10cSrcweir 										pStream->SetMediaType ( sMediaType );
306cdf0e10cSrcweir                                         pStream->SetFromManifest( sal_True );
307cdf0e10cSrcweir 
308cdf0e10cSrcweir 										if ( pSalt && pVector && pCount && pSize && pDigest && pDigestAlg && pEncryptionAlg )
309cdf0e10cSrcweir 										{
310cdf0e10cSrcweir 											uno::Sequence < sal_Int8 > aSequence;
311cdf0e10cSrcweir 											sal_Int32 nCount = 0, nSize = 0, nDigestAlg = 0, nEncryptionAlg = 0, nDerivedKeySize = 16, nStartKeyAlg = xml::crypto::DigestID::SHA1;
312cdf0e10cSrcweir 
313cdf0e10cSrcweir                                             pStream->SetToBeEncrypted ( sal_True );
314cdf0e10cSrcweir 
315cdf0e10cSrcweir 											*pSalt >>= aSequence;
316cdf0e10cSrcweir 											pStream->setSalt ( aSequence );
317cdf0e10cSrcweir 
318cdf0e10cSrcweir 											*pVector >>= aSequence;
319cdf0e10cSrcweir 											pStream->setInitialisationVector ( aSequence );
320cdf0e10cSrcweir 
321cdf0e10cSrcweir 											*pCount >>= nCount;
322cdf0e10cSrcweir 											pStream->setIterationCount ( nCount );
323cdf0e10cSrcweir 
324cdf0e10cSrcweir 											*pSize >>= nSize;
325cdf0e10cSrcweir 											pStream->setSize ( nSize );
326cdf0e10cSrcweir 
327cdf0e10cSrcweir                                             *pDigest >>= aSequence;
328cdf0e10cSrcweir                                             pStream->setDigest ( aSequence );
329cdf0e10cSrcweir 
330cdf0e10cSrcweir                                             *pDigestAlg >>= nDigestAlg;
331cdf0e10cSrcweir                                             pStream->SetImportedChecksumAlgorithm( nDigestAlg );
332cdf0e10cSrcweir 
333cdf0e10cSrcweir                                             *pEncryptionAlg >>= nEncryptionAlg;
334cdf0e10cSrcweir                                             pStream->SetImportedEncryptionAlgorithm( nEncryptionAlg );
335cdf0e10cSrcweir 
336cdf0e10cSrcweir                                             if ( pDerivedKeySize )
337cdf0e10cSrcweir                                                 *pDerivedKeySize >>= nDerivedKeySize;
338cdf0e10cSrcweir                                             pStream->SetImportedDerivedKeySize( nDerivedKeySize );
339cdf0e10cSrcweir 
340cdf0e10cSrcweir                                             if ( pStartKeyAlg )
341cdf0e10cSrcweir                                                 *pStartKeyAlg >>= nStartKeyAlg;
342cdf0e10cSrcweir                                             pStream->SetImportedStartKeyAlgorithm( nStartKeyAlg );
343cdf0e10cSrcweir 
344cdf0e10cSrcweir 											pStream->SetToBeCompressed ( sal_True );
345cdf0e10cSrcweir 											pStream->SetToBeEncrypted ( sal_True );
346cdf0e10cSrcweir 											pStream->SetIsEncrypted ( sal_True );
347cdf0e10cSrcweir 											if ( !m_bHasEncryptedEntries
348cdf0e10cSrcweir                                               && pStream->getName().equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "content.xml" ) ) ) )
349cdf0e10cSrcweir                                             {
350cdf0e10cSrcweir 												m_bHasEncryptedEntries = sal_True;
351cdf0e10cSrcweir                                                 m_nStartKeyGenerationID = nStartKeyAlg;
352cdf0e10cSrcweir                                                 m_nChecksumDigestID = nDigestAlg;
353cdf0e10cSrcweir                                                 m_nCommonEncryptionID = nEncryptionAlg;
354cdf0e10cSrcweir                                             }
355cdf0e10cSrcweir 										}
356cdf0e10cSrcweir                                         else
357cdf0e10cSrcweir                                             m_bHasNonEncryptedEntries = sal_True;
358cdf0e10cSrcweir 									}
359cdf0e10cSrcweir 								}
360cdf0e10cSrcweir 							}
361cdf0e10cSrcweir 
362cdf0e10cSrcweir 							bManifestParsed = sal_True;
363cdf0e10cSrcweir 						}
364cdf0e10cSrcweir 						else
365cdf0e10cSrcweir                             throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No manifes parser!" ) ), uno::Reference< uno::XInterface >() );
366cdf0e10cSrcweir 					}
367cdf0e10cSrcweir 
368cdf0e10cSrcweir 					// now hide the manifest.xml file from user
369cdf0e10cSrcweir 					xMetaInfFolder->removeByName( sManifest );
370cdf0e10cSrcweir 				}
371cdf0e10cSrcweir 			}
372cdf0e10cSrcweir 			catch( Exception& )
373cdf0e10cSrcweir 			{
374cdf0e10cSrcweir 				if ( !m_bForceRecovery )
375cdf0e10cSrcweir 					throw;
376cdf0e10cSrcweir 			}
377cdf0e10cSrcweir 		}
378cdf0e10cSrcweir 
379cdf0e10cSrcweir         if ( !bManifestParsed && !m_bForceRecovery )
380cdf0e10cSrcweir             throw ZipIOException(
381cdf0e10cSrcweir                 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Could not parse manifest.xml\n" ) ),
382cdf0e10cSrcweir                 uno::Reference< uno::XInterface >() );
383cdf0e10cSrcweir 
384cdf0e10cSrcweir 		const OUString sMimetype ( RTL_CONSTASCII_USTRINGPARAM ( "mimetype" ) );
385cdf0e10cSrcweir 		if ( m_xRootFolder->hasByName( sMimetype ) )
386cdf0e10cSrcweir 		{
387cdf0e10cSrcweir             // get mediatype from the "mimetype" stream
388cdf0e10cSrcweir             ::rtl::OUString aPackageMediatype;
389cdf0e10cSrcweir             uno::Reference< lang::XUnoTunnel > xMimeTypeTunnel;
390cdf0e10cSrcweir             m_xRootFolder->getByName( sMimetype ) >>= xMimeTypeTunnel;
391cdf0e10cSrcweir             uno::Reference < io::XActiveDataSink > xMimeSink( xMimeTypeTunnel, UNO_QUERY );
392cdf0e10cSrcweir             if ( xMimeSink.is() )
393cdf0e10cSrcweir             {
394cdf0e10cSrcweir                 uno::Reference< io::XInputStream > xMimeInStream = xMimeSink->getInputStream();
395cdf0e10cSrcweir                 if ( xMimeInStream.is() )
396cdf0e10cSrcweir                 {
397cdf0e10cSrcweir                     // Mediatypes longer than 1024 symbols should not appear here
398cdf0e10cSrcweir                     uno::Sequence< sal_Int8 > aData( 1024 );
399cdf0e10cSrcweir                     sal_Int32 nRead = xMimeInStream->readBytes( aData, 1024 );
400cdf0e10cSrcweir                     if ( nRead > aData.getLength() )
401cdf0e10cSrcweir                         nRead = aData.getLength();
402cdf0e10cSrcweir 
403cdf0e10cSrcweir                     if ( nRead )
404cdf0e10cSrcweir                         aPackageMediatype = ::rtl::OUString( ( sal_Char* )aData.getConstArray(), nRead, RTL_TEXTENCODING_ASCII_US );
405cdf0e10cSrcweir                 }
406cdf0e10cSrcweir             }
407cdf0e10cSrcweir 
408cdf0e10cSrcweir 
409cdf0e10cSrcweir             if ( !bManifestParsed )
410cdf0e10cSrcweir             {
411cdf0e10cSrcweir                 // the manifest.xml could not be successfuly parsed, this is an inconsistent package
412cdf0e10cSrcweir                 if ( aPackageMediatype.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "application/vnd." ) ) == 0 )
413cdf0e10cSrcweir                 {
414cdf0e10cSrcweir                     // accept only types that look similar to own mediatypes
415cdf0e10cSrcweir                     m_pRootFolder->SetMediaType( aPackageMediatype );
416cdf0e10cSrcweir                     m_bMediaTypeFallbackUsed = sal_True;
417cdf0e10cSrcweir                 }
418cdf0e10cSrcweir             }
419cdf0e10cSrcweir             else if ( !m_bForceRecovery )
420cdf0e10cSrcweir             {
421cdf0e10cSrcweir                 // the mimetype stream should contain the information from manifest.xml
422cdf0e10cSrcweir                 if ( !m_pRootFolder->GetMediaType().equals( aPackageMediatype ) )
423cdf0e10cSrcweir                     throw ZipIOException(
424cdf0e10cSrcweir                         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "mimetype conflicts with manifest.xml\n" ) ),
425cdf0e10cSrcweir                         uno::Reference< uno::XInterface >() );
426cdf0e10cSrcweir             }
427cdf0e10cSrcweir 
428cdf0e10cSrcweir             m_xRootFolder->removeByName( sMimetype );
429cdf0e10cSrcweir         }
430cdf0e10cSrcweir 
431cdf0e10cSrcweir         m_bInconsistent = m_pRootFolder->LookForUnexpectedODF12Streams( ::rtl::OUString() );
432cdf0e10cSrcweir 
433cdf0e10cSrcweir         sal_Bool bODF12AndNewer = ( m_pRootFolder->GetVersion().compareTo( ODFVER_012_TEXT ) >= 0 );
434cdf0e10cSrcweir         if ( !m_bForceRecovery && bODF12AndNewer )
435cdf0e10cSrcweir         {
436cdf0e10cSrcweir             if ( m_bInconsistent )
437cdf0e10cSrcweir             {
438cdf0e10cSrcweir                 // this is an ODF1.2 document that contains streams not referred in the manifest.xml;
439cdf0e10cSrcweir                 // in case of ODF1.2 documents without version in manifest.xml the property IsInconsistent
440cdf0e10cSrcweir                 // should be checked later
441cdf0e10cSrcweir                 throw ZipIOException(
442cdf0e10cSrcweir                     ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "there are streams not referred in manifest.xml\n" ) ),
443cdf0e10cSrcweir                     uno::Reference< uno::XInterface >() );
444cdf0e10cSrcweir             }
445cdf0e10cSrcweir             else if ( bDifferentStartKeyAlgorithm )
446cdf0e10cSrcweir             {
447cdf0e10cSrcweir                 // all the streams should be encrypted with the same StartKey in ODF1.2
448cdf0e10cSrcweir                 // TODO/LATER: in future the exception should be thrown
449cdf0e10cSrcweir                 OSL_ENSURE( false, "ODF1.2 contains different StartKey Algorithms" );
450cdf0e10cSrcweir                 // throw ZipIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "More than one Start Key Generation algorithm is specified!" ) ), uno::Reference< uno::XInterface >() );
451cdf0e10cSrcweir             }
452cdf0e10cSrcweir         }
453cdf0e10cSrcweir 
454cdf0e10cSrcweir         // in case it is a correct ODF1.2 document, the version must be set
455cdf0e10cSrcweir         // and the META-INF folder is reserved for package format
456cdf0e10cSrcweir         if ( bODF12AndNewer )
457cdf0e10cSrcweir             m_xRootFolder->removeByName( sMeta );
458cdf0e10cSrcweir 	}
459cdf0e10cSrcweir }
460cdf0e10cSrcweir 
461cdf0e10cSrcweir //--------------------------------------------------------
parseContentType()462cdf0e10cSrcweir void ZipPackage::parseContentType()
463cdf0e10cSrcweir {
464cdf0e10cSrcweir 	if ( m_nFormat == embed::StorageFormats::OFOPXML )
465cdf0e10cSrcweir 	{
466cdf0e10cSrcweir 		const ::rtl::OUString aContentTypes( RTL_CONSTASCII_USTRINGPARAM ( "[Content_Types].xml" ) );
467cdf0e10cSrcweir 		try {
468cdf0e10cSrcweir 			// the content type must exist in OFOPXML format!
469cdf0e10cSrcweir 			if ( !m_xRootFolder->hasByName( aContentTypes ) )
470cdf0e10cSrcweir 				throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Wrong format!" ) ),
471cdf0e10cSrcweir 										uno::Reference< uno::XInterface >() );
472cdf0e10cSrcweir 
473cdf0e10cSrcweir 			uno::Reference< lang::XUnoTunnel > xTunnel;
474cdf0e10cSrcweir 			uno::Any aAny = m_xRootFolder->getByName( aContentTypes );
475cdf0e10cSrcweir 			aAny >>= xTunnel;
476cdf0e10cSrcweir 			uno::Reference < io::XActiveDataSink > xSink( xTunnel, UNO_QUERY );
477cdf0e10cSrcweir 			if ( xSink.is() )
478cdf0e10cSrcweir 			{
479cdf0e10cSrcweir 				uno::Reference< io::XInputStream > xInStream = xSink->getInputStream();
480cdf0e10cSrcweir 				if ( xInStream.is() )
481cdf0e10cSrcweir 				{
482cdf0e10cSrcweir 					sal_Int32 nInd = 0;
483cdf0e10cSrcweir 					// here aContentTypeInfo[0] - Defaults, and aContentTypeInfo[1] - Overrides
484cdf0e10cSrcweir 					uno::Sequence< uno::Sequence< beans::StringPair > > aContentTypeInfo =
485cdf0e10cSrcweir 						::comphelper::OFOPXMLHelper::ReadContentTypeSequence( xInStream, m_xFactory );
486cdf0e10cSrcweir 
487cdf0e10cSrcweir 					if ( aContentTypeInfo.getLength() != 2 )
488cdf0e10cSrcweir 						throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
489cdf0e10cSrcweir 
490cdf0e10cSrcweir 					// set the implicit types fist
491cdf0e10cSrcweir 					for ( nInd = 0; nInd < aContentTypeInfo[0].getLength(); nInd++ )
492cdf0e10cSrcweir 						m_pRootFolder->setChildStreamsTypeByExtension( aContentTypeInfo[0][nInd] );
493cdf0e10cSrcweir 
494cdf0e10cSrcweir 					// now set the explicit types
495cdf0e10cSrcweir 					for ( nInd = 0; nInd < aContentTypeInfo[1].getLength(); nInd++ )
496cdf0e10cSrcweir 					{
497cdf0e10cSrcweir 						::rtl::OUString aPath;
498cdf0e10cSrcweir 						if ( aContentTypeInfo[1][nInd].First.toChar() == ( sal_Unicode )'/' )
499cdf0e10cSrcweir 							aPath = aContentTypeInfo[1][nInd].First.copy( 1 );
500cdf0e10cSrcweir 						else
501cdf0e10cSrcweir 							aPath = aContentTypeInfo[1][nInd].First;
502cdf0e10cSrcweir 
503cdf0e10cSrcweir 						if ( aPath.getLength() && hasByHierarchicalName( aPath ) )
504cdf0e10cSrcweir 						{
505cdf0e10cSrcweir 							uno::Any aIterAny = getByHierarchicalName( aPath );
506cdf0e10cSrcweir 							uno::Reference < lang::XUnoTunnel > xIterTunnel;
507cdf0e10cSrcweir 							aIterAny >>= xIterTunnel;
508cdf0e10cSrcweir 							sal_Int64 nTest = xIterTunnel->getSomething( ZipPackageStream::static_getImplementationId() );
509cdf0e10cSrcweir 							if ( nTest != 0 )
510cdf0e10cSrcweir 							{
511cdf0e10cSrcweir 								// this is a package stream, in OFOPXML format only streams can have mediatype
512cdf0e10cSrcweir 								ZipPackageStream *pStream = reinterpret_cast < ZipPackageStream* > ( nTest );
513cdf0e10cSrcweir 								pStream->SetMediaType( aContentTypeInfo[1][nInd].Second );
514cdf0e10cSrcweir 							}
515cdf0e10cSrcweir 						}
516cdf0e10cSrcweir 					}
517cdf0e10cSrcweir 				}
518cdf0e10cSrcweir 			}
519cdf0e10cSrcweir 
520cdf0e10cSrcweir 			m_xRootFolder->removeByName( aContentTypes );
521cdf0e10cSrcweir 		}
522cdf0e10cSrcweir 		catch( uno::Exception& )
523cdf0e10cSrcweir 		{
524cdf0e10cSrcweir 			if ( !m_bForceRecovery )
525cdf0e10cSrcweir 				throw;
526cdf0e10cSrcweir 		}
527cdf0e10cSrcweir 	}
528cdf0e10cSrcweir }
529cdf0e10cSrcweir 
530cdf0e10cSrcweir //--------------------------------------------------------
getZipFileContents()531cdf0e10cSrcweir void ZipPackage::getZipFileContents()
532cdf0e10cSrcweir {
533cdf0e10cSrcweir 	auto_ptr < ZipEnumeration > pEnum ( m_pZipFile->entries() );
534cdf0e10cSrcweir 	ZipPackageStream *pPkgStream;
535cdf0e10cSrcweir 	ZipPackageFolder *pPkgFolder, *pCurrent;
536cdf0e10cSrcweir 	OUString sTemp, sDirName;
537cdf0e10cSrcweir 	sal_Int32 nOldIndex, nIndex, nStreamIndex;
538cdf0e10cSrcweir 	FolderHash::iterator aIter;
539cdf0e10cSrcweir 
540cdf0e10cSrcweir 	while ( pEnum->hasMoreElements() )
541cdf0e10cSrcweir 	{
542cdf0e10cSrcweir 		nIndex = nOldIndex = 0;
543cdf0e10cSrcweir 		pCurrent = m_pRootFolder;
544cdf0e10cSrcweir 		const ZipEntry & rEntry = *pEnum->nextElement();
545cdf0e10cSrcweir 		OUString rName = rEntry.sPath;
546cdf0e10cSrcweir 
547cdf0e10cSrcweir         if ( m_bForceRecovery )
548cdf0e10cSrcweir         {
549cdf0e10cSrcweir             // the PKZIP Application note version 6.2 does not allows to use '\' as separator
550cdf0e10cSrcweir             // unfortunately it is used by some implementations, so we have to support it in recovery mode
551cdf0e10cSrcweir             rName = rName.replace( '\\', '/' );
552cdf0e10cSrcweir         }
553cdf0e10cSrcweir 
554cdf0e10cSrcweir 		nStreamIndex = rName.lastIndexOf ( '/' );
555cdf0e10cSrcweir 		if ( nStreamIndex != -1 )
556cdf0e10cSrcweir 		{
557cdf0e10cSrcweir 			sDirName = rName.copy ( 0, nStreamIndex );
558cdf0e10cSrcweir 			aIter = m_aRecent.find ( sDirName );
559cdf0e10cSrcweir 			if ( aIter != m_aRecent.end() )
560cdf0e10cSrcweir 				pCurrent = ( *aIter ).second;
561cdf0e10cSrcweir 		}
562cdf0e10cSrcweir 
563cdf0e10cSrcweir 		if ( pCurrent == m_pRootFolder )
564cdf0e10cSrcweir 		{
565cdf0e10cSrcweir 			while ( ( nIndex = rName.indexOf( '/', nOldIndex ) ) != -1 )
566cdf0e10cSrcweir 			{
567cdf0e10cSrcweir 				sTemp = rName.copy ( nOldIndex, nIndex - nOldIndex );
568cdf0e10cSrcweir 				if ( nIndex == nOldIndex )
569cdf0e10cSrcweir 					break;
570cdf0e10cSrcweir 				if ( !pCurrent->hasByName( sTemp ) )
571cdf0e10cSrcweir 				{
572cdf0e10cSrcweir 					pPkgFolder = new ZipPackageFolder( m_xFactory, m_nFormat, m_bAllowRemoveOnInsert );
573cdf0e10cSrcweir 					pPkgFolder->setName( sTemp );
574cdf0e10cSrcweir 					pPkgFolder->doSetParent( pCurrent, sal_True );
575cdf0e10cSrcweir 					pCurrent = pPkgFolder;
576cdf0e10cSrcweir 				}
577cdf0e10cSrcweir 				else
578cdf0e10cSrcweir 					pCurrent = pCurrent->doGetByName( sTemp ).pFolder;
579cdf0e10cSrcweir 				nOldIndex = nIndex+1;
580cdf0e10cSrcweir 			}
581cdf0e10cSrcweir 			if ( nStreamIndex != -1 && sDirName.getLength() )
582cdf0e10cSrcweir 				m_aRecent [ sDirName ] = pCurrent;
583cdf0e10cSrcweir 		}
584cdf0e10cSrcweir 		if ( rName.getLength() -1 != nStreamIndex )
585cdf0e10cSrcweir 		{
586cdf0e10cSrcweir 			nStreamIndex++;
587cdf0e10cSrcweir 			sTemp = rName.copy( nStreamIndex, rName.getLength() - nStreamIndex );
588cdf0e10cSrcweir 			pPkgStream = new ZipPackageStream( *this, m_xFactory, m_bAllowRemoveOnInsert );
589cdf0e10cSrcweir 			pPkgStream->SetPackageMember( sal_True );
590cdf0e10cSrcweir 			pPkgStream->setZipEntryOnLoading( rEntry );
591cdf0e10cSrcweir 			pPkgStream->setName( sTemp );
592cdf0e10cSrcweir 			pPkgStream->doSetParent( pCurrent, sal_True );
593cdf0e10cSrcweir 		}
594cdf0e10cSrcweir 	}
595cdf0e10cSrcweir 
596cdf0e10cSrcweir 	if ( m_nFormat == embed::StorageFormats::PACKAGE )
597cdf0e10cSrcweir 		parseManifest();
598cdf0e10cSrcweir 	else if ( m_nFormat == embed::StorageFormats::OFOPXML )
599cdf0e10cSrcweir 		parseContentType();
600cdf0e10cSrcweir }
601cdf0e10cSrcweir 
602cdf0e10cSrcweir //--------------------------------------------------------
initialize(const uno::Sequence<Any> & aArguments)603cdf0e10cSrcweir void SAL_CALL ZipPackage::initialize( const uno::Sequence< Any >& aArguments )
604cdf0e10cSrcweir 		throw( Exception, RuntimeException )
605cdf0e10cSrcweir {
606cdf0e10cSrcweir 	RTL_LOGFILE_TRACE_AUTHOR ( "package", LOGFILE_AUTHOR, "{ ZipPackage::initialize" );
607cdf0e10cSrcweir 	sal_Bool bBadZipFile = sal_False, bHaveZipFile = sal_True;
608cdf0e10cSrcweir 	uno::Reference< XProgressHandler > xProgressHandler;
609cdf0e10cSrcweir 	beans::NamedValue aNamedValue;
610cdf0e10cSrcweir 
611cdf0e10cSrcweir 	if ( aArguments.getLength() )
612cdf0e10cSrcweir 	{
613cdf0e10cSrcweir 		for( int ind = 0; ind < aArguments.getLength(); ind++ )
614cdf0e10cSrcweir 		{
615cdf0e10cSrcweir 			OUString aParamUrl;
616cdf0e10cSrcweir 			if ( ( aArguments[ind] >>= aParamUrl ))
617cdf0e10cSrcweir 			{
618cdf0e10cSrcweir 				m_eMode = e_IMode_URL;
619cdf0e10cSrcweir 				try
620cdf0e10cSrcweir 				{
621cdf0e10cSrcweir 					sal_Int32 nParam = aParamUrl.indexOf( '?' );
622cdf0e10cSrcweir 					if ( nParam >= 0 )
623cdf0e10cSrcweir 					{
624cdf0e10cSrcweir 						m_aURL = aParamUrl.copy( 0, nParam );
625cdf0e10cSrcweir 						OUString aParam = aParamUrl.copy( nParam + 1 );
626cdf0e10cSrcweir 
627cdf0e10cSrcweir               			sal_Int32 nIndex = 0;
628cdf0e10cSrcweir 						do
629cdf0e10cSrcweir 						{
630cdf0e10cSrcweir 							::rtl::OUString aCommand = aParam.getToken( 0, '&', nIndex );
631cdf0e10cSrcweir 							if ( aCommand.equals( OUString::createFromAscii( "repairpackage" ) ) )
632cdf0e10cSrcweir 							{
633cdf0e10cSrcweir 								m_bForceRecovery = sal_True;
634cdf0e10cSrcweir 								break;
635cdf0e10cSrcweir 							}
636cdf0e10cSrcweir 							else if ( aCommand.equals( OUString::createFromAscii( "purezip" ) ) )
637cdf0e10cSrcweir 							{
638cdf0e10cSrcweir 								m_nFormat = embed::StorageFormats::ZIP;
639cdf0e10cSrcweir 								m_pRootFolder->setPackageFormat_Impl( m_nFormat );
640cdf0e10cSrcweir 								break;
641cdf0e10cSrcweir 							}
642cdf0e10cSrcweir 							else if ( aCommand.equals( OUString::createFromAscii( "ofopxml" ) ) )
643cdf0e10cSrcweir 							{
644cdf0e10cSrcweir 								m_nFormat = embed::StorageFormats::OFOPXML;
645cdf0e10cSrcweir 								m_pRootFolder->setPackageFormat_Impl( m_nFormat );
646cdf0e10cSrcweir 								break;
647cdf0e10cSrcweir 							}
648cdf0e10cSrcweir 						}
649cdf0e10cSrcweir 						while ( nIndex >= 0 );
650cdf0e10cSrcweir 					}
651cdf0e10cSrcweir 					else
652cdf0e10cSrcweir 						m_aURL = aParamUrl;
653cdf0e10cSrcweir 
654cdf0e10cSrcweir 					Content aContent ( m_aURL, uno::Reference < XCommandEnvironment >() );
655cdf0e10cSrcweir 					Any aAny = aContent.getPropertyValue( OUString::createFromAscii( "Size" ) );
656cdf0e10cSrcweir 					sal_uInt64 aSize = 0;
657cdf0e10cSrcweir 					// kind of optimisation: treat empty files as nonexistent files
658cdf0e10cSrcweir 					// and write to such files directly. Note that "Size" property is optional.
659cdf0e10cSrcweir 					bool bHasSizeProperty = aAny >>= aSize;
660cdf0e10cSrcweir 					if( !bHasSizeProperty || ( bHasSizeProperty && aSize ) )
661cdf0e10cSrcweir 					{
662cdf0e10cSrcweir 						uno::Reference < XActiveDataSink > xSink = new ZipPackageSink;
663cdf0e10cSrcweir 						if ( aContent.openStream ( xSink ) )
664cdf0e10cSrcweir 							m_xContentStream = xSink->getInputStream();
665cdf0e10cSrcweir 					}
666cdf0e10cSrcweir 					else
667cdf0e10cSrcweir 						bHaveZipFile = sal_False;
668cdf0e10cSrcweir 				}
669cdf0e10cSrcweir 				catch ( com::sun::star::uno::Exception& )
670cdf0e10cSrcweir 				{
671cdf0e10cSrcweir 					// Exception derived from uno::Exception thrown. This probably
672cdf0e10cSrcweir 					// means the file doesn't exist...we'll create it at
673cdf0e10cSrcweir 					// commitChanges time
674cdf0e10cSrcweir 					bHaveZipFile = sal_False;
675cdf0e10cSrcweir 				}
676cdf0e10cSrcweir 			}
677cdf0e10cSrcweir 			else if ( ( aArguments[ind] >>= m_xStream ) )
678cdf0e10cSrcweir 			{
679cdf0e10cSrcweir 				// a writable stream can implement both XStream & XInputStream
680cdf0e10cSrcweir 				m_eMode = e_IMode_XStream;
681cdf0e10cSrcweir 				m_xContentStream = m_xStream->getInputStream();
682cdf0e10cSrcweir 			}
683cdf0e10cSrcweir 			else if ( ( aArguments[ind] >>= m_xContentStream ) )
684cdf0e10cSrcweir 			{
685cdf0e10cSrcweir 				m_eMode = e_IMode_XInputStream;
686cdf0e10cSrcweir 			}
687cdf0e10cSrcweir 			else if ( ( aArguments[ind] >>= aNamedValue ) )
688cdf0e10cSrcweir 			{
689cdf0e10cSrcweir 				if ( aNamedValue.Name.equalsAscii( "RepairPackage" ) )
690cdf0e10cSrcweir 					aNamedValue.Value >>= m_bForceRecovery;
691cdf0e10cSrcweir 				else if ( aNamedValue.Name.equalsAscii( "PackageFormat" ) )
692cdf0e10cSrcweir 				{
693cdf0e10cSrcweir 					// setting this argument to true means Package format
694cdf0e10cSrcweir 					// setting it to false means plain Zip format
695cdf0e10cSrcweir 
696cdf0e10cSrcweir 					sal_Bool bPackFormat = sal_True;
697cdf0e10cSrcweir 					aNamedValue.Value >>= bPackFormat;
698cdf0e10cSrcweir 					if ( !bPackFormat )
699cdf0e10cSrcweir 						m_nFormat = embed::StorageFormats::ZIP;
700cdf0e10cSrcweir 
701cdf0e10cSrcweir 					m_pRootFolder->setPackageFormat_Impl( m_nFormat );
702cdf0e10cSrcweir 				}
703cdf0e10cSrcweir 				else if ( aNamedValue.Name.equalsAscii( "StorageFormat" ) )
704cdf0e10cSrcweir 				{
705cdf0e10cSrcweir 					::rtl::OUString aFormatName;
706cdf0e10cSrcweir                     sal_Int32 nFormatID = 0;
707cdf0e10cSrcweir                     if ( aNamedValue.Value >>= aFormatName )
708cdf0e10cSrcweir                     {
709cdf0e10cSrcweir                         if ( aFormatName.equals( PACKAGE_STORAGE_FORMAT_STRING ) )
710cdf0e10cSrcweir                             m_nFormat = embed::StorageFormats::PACKAGE;
711cdf0e10cSrcweir                         else if ( aFormatName.equals( ZIP_STORAGE_FORMAT_STRING ) )
712cdf0e10cSrcweir                             m_nFormat = embed::StorageFormats::ZIP;
713cdf0e10cSrcweir                         else if ( aFormatName.equals( OFOPXML_STORAGE_FORMAT_STRING ) )
714cdf0e10cSrcweir                             m_nFormat = embed::StorageFormats::OFOPXML;
715cdf0e10cSrcweir                         else
716cdf0e10cSrcweir                             throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 );
717cdf0e10cSrcweir                     }
718cdf0e10cSrcweir                     else if ( aNamedValue.Value >>= nFormatID )
719cdf0e10cSrcweir                     {
720cdf0e10cSrcweir                         if ( nFormatID != embed::StorageFormats::PACKAGE
721cdf0e10cSrcweir                           && nFormatID != embed::StorageFormats::ZIP
722cdf0e10cSrcweir                           && nFormatID != embed::StorageFormats::OFOPXML )
723cdf0e10cSrcweir                             throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 );
724cdf0e10cSrcweir 
725cdf0e10cSrcweir                         m_nFormat = nFormatID;
726cdf0e10cSrcweir                     }
727cdf0e10cSrcweir                     else
728cdf0e10cSrcweir                         throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 );
729cdf0e10cSrcweir 
730cdf0e10cSrcweir 					m_pRootFolder->setPackageFormat_Impl( m_nFormat );
731cdf0e10cSrcweir 				}
732cdf0e10cSrcweir 				else if ( aNamedValue.Name.equalsAscii( "AllowRemoveOnInsert" ) )
733cdf0e10cSrcweir 				{
734cdf0e10cSrcweir 					aNamedValue.Value >>= m_bAllowRemoveOnInsert;
735cdf0e10cSrcweir 					m_pRootFolder->setRemoveOnInsertMode_Impl( m_bAllowRemoveOnInsert );
736cdf0e10cSrcweir 				}
737cdf0e10cSrcweir 
738cdf0e10cSrcweir 				// for now the progress handler is not used, probably it will never be
739cdf0e10cSrcweir 				// if ( aNamedValue.Name.equalsAscii( "ProgressHandler" )
740cdf0e10cSrcweir 			}
741cdf0e10cSrcweir 			else
742cdf0e10cSrcweir 			{
743cdf0e10cSrcweir 				// The URL is not acceptable
744cdf0e10cSrcweir 				throw com::sun::star::uno::Exception ( OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "Bad arguments." ) ),
745cdf0e10cSrcweir 					static_cast < ::cppu::OWeakObject * > ( this ) );
746cdf0e10cSrcweir 			}
747cdf0e10cSrcweir 		}
748cdf0e10cSrcweir 
749cdf0e10cSrcweir 		try
750cdf0e10cSrcweir 		{
751cdf0e10cSrcweir 			if ( m_xContentStream.is() )
752cdf0e10cSrcweir 			{
753cdf0e10cSrcweir 				// the stream must be seekable, if it is not it will be wrapped
754cdf0e10cSrcweir 				m_xContentStream = ::comphelper::OSeekableInputWrapper::CheckSeekableCanWrap( m_xContentStream, m_xFactory );
755cdf0e10cSrcweir 				m_xContentSeek = uno::Reference < XSeekable > ( m_xContentStream, UNO_QUERY );
756cdf0e10cSrcweir 				if ( ! m_xContentSeek.is() )
757cdf0e10cSrcweir 					throw com::sun::star::uno::Exception ( OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "The package component _requires_ an XSeekable interface!" ) ),
758cdf0e10cSrcweir 							static_cast < ::cppu::OWeakObject * > ( this ) );
759cdf0e10cSrcweir 
760cdf0e10cSrcweir 				if ( !m_xContentSeek->getLength() )
761cdf0e10cSrcweir 					bHaveZipFile = sal_False;
762cdf0e10cSrcweir 			}
763cdf0e10cSrcweir 			else
764cdf0e10cSrcweir 				bHaveZipFile = sal_False;
765cdf0e10cSrcweir 		}
766cdf0e10cSrcweir 		catch ( com::sun::star::uno::Exception& )
767cdf0e10cSrcweir 		{
768cdf0e10cSrcweir 			// Exception derived from uno::Exception thrown. This probably
769cdf0e10cSrcweir 			// means the file doesn't exist...we'll create it at
770cdf0e10cSrcweir 			// commitChanges time
771cdf0e10cSrcweir 			bHaveZipFile = sal_False;
772cdf0e10cSrcweir 		}
773cdf0e10cSrcweir 		if ( bHaveZipFile )
774cdf0e10cSrcweir 		{
775cdf0e10cSrcweir 			try
776cdf0e10cSrcweir 			{
777cdf0e10cSrcweir 				m_pZipFile = new ZipFile ( m_xContentStream, m_xFactory, sal_True, m_bForceRecovery, xProgressHandler );
778cdf0e10cSrcweir 				getZipFileContents();
779cdf0e10cSrcweir 			}
780cdf0e10cSrcweir 			catch ( IOException & )
781cdf0e10cSrcweir 			{
782cdf0e10cSrcweir 				bBadZipFile = sal_True;
783cdf0e10cSrcweir 			}
784cdf0e10cSrcweir 			catch ( ZipException & )
785cdf0e10cSrcweir 			{
786cdf0e10cSrcweir 				bBadZipFile = sal_True;
787cdf0e10cSrcweir 			}
788cdf0e10cSrcweir 			catch ( Exception & )
789cdf0e10cSrcweir 			{
790cdf0e10cSrcweir 				if( m_pZipFile ) { delete m_pZipFile; m_pZipFile = NULL; }
791cdf0e10cSrcweir 				throw;
792cdf0e10cSrcweir 			}
793cdf0e10cSrcweir 
794cdf0e10cSrcweir 			if ( bBadZipFile )
795cdf0e10cSrcweir 			{
796cdf0e10cSrcweir 				// clean up the memory, and tell the UCB about the error
797cdf0e10cSrcweir 				if( m_pZipFile ) { delete m_pZipFile; m_pZipFile = NULL; }
798cdf0e10cSrcweir 
799cdf0e10cSrcweir 				throw com::sun::star::packages::zip::ZipIOException (
800cdf0e10cSrcweir 					OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "Bad Zip File." ) ),
801cdf0e10cSrcweir 					static_cast < ::cppu::OWeakObject * > ( this ) );
802cdf0e10cSrcweir 			}
803cdf0e10cSrcweir 		}
804cdf0e10cSrcweir 	}
805cdf0e10cSrcweir 
806cdf0e10cSrcweir 	RTL_LOGFILE_TRACE_AUTHOR ( "package", LOGFILE_AUTHOR, "} ZipPackage::initialize" );
807cdf0e10cSrcweir }
808cdf0e10cSrcweir 
809cdf0e10cSrcweir //--------------------------------------------------------
getByHierarchicalName(const OUString & aName)810cdf0e10cSrcweir Any SAL_CALL ZipPackage::getByHierarchicalName( const OUString& aName )
811cdf0e10cSrcweir 		throw( NoSuchElementException, RuntimeException )
812cdf0e10cSrcweir {
813cdf0e10cSrcweir 	OUString sTemp, sDirName;
814cdf0e10cSrcweir 	sal_Int32 nOldIndex, nIndex, nStreamIndex;
815cdf0e10cSrcweir 	FolderHash::iterator aIter;
816cdf0e10cSrcweir 
817cdf0e10cSrcweir 	if ( ( nIndex = aName.getLength() ) == 1 && *aName.getStr() == '/' )
818cdf0e10cSrcweir 		return makeAny ( uno::Reference < XUnoTunnel > ( m_pRootFolder ) );
819cdf0e10cSrcweir 	else
820cdf0e10cSrcweir 	{
821cdf0e10cSrcweir 		nStreamIndex = aName.lastIndexOf ( '/' );
822cdf0e10cSrcweir 		bool bFolder = nStreamIndex == nIndex-1;
823cdf0e10cSrcweir 		if ( nStreamIndex != -1 )
824cdf0e10cSrcweir 		{
825cdf0e10cSrcweir 			sDirName = aName.copy ( 0, nStreamIndex );
826cdf0e10cSrcweir 			aIter = m_aRecent.find ( sDirName );
827cdf0e10cSrcweir 			if ( aIter != m_aRecent.end() )
828cdf0e10cSrcweir 			{
829cdf0e10cSrcweir 				if ( bFolder )
830cdf0e10cSrcweir 				{
831cdf0e10cSrcweir 					sal_Int32 nDirIndex = aName.lastIndexOf ( '/', nStreamIndex );
832cdf0e10cSrcweir 					sTemp = aName.copy ( nDirIndex == -1 ? 0 : nDirIndex+1, nStreamIndex-nDirIndex-1 );
833cdf0e10cSrcweir 					if ( sTemp == ( *aIter ).second->getName() )
834cdf0e10cSrcweir 						return makeAny ( uno::Reference < XUnoTunnel > ( ( *aIter ).second ) );
835cdf0e10cSrcweir 					else
836cdf0e10cSrcweir 						m_aRecent.erase ( aIter );
837cdf0e10cSrcweir 				}
838cdf0e10cSrcweir 				else
839cdf0e10cSrcweir 				{
840cdf0e10cSrcweir 					sTemp = aName.copy ( nStreamIndex + 1 );
841cdf0e10cSrcweir 					if ( ( *aIter ).second->hasByName( sTemp ) )
842cdf0e10cSrcweir 						return ( *aIter ).second->getByName( sTemp );
843cdf0e10cSrcweir 					else
844cdf0e10cSrcweir 						m_aRecent.erase( aIter );
845cdf0e10cSrcweir 				}
846cdf0e10cSrcweir 			}
847cdf0e10cSrcweir 		}
848cdf0e10cSrcweir 		else
849cdf0e10cSrcweir 		{
850cdf0e10cSrcweir 			if ( m_pRootFolder->hasByName ( aName ) )
851cdf0e10cSrcweir 				return m_pRootFolder->getByName ( aName );
852cdf0e10cSrcweir 		}
853cdf0e10cSrcweir 		nOldIndex = 0;
854cdf0e10cSrcweir 		ZipPackageFolder * pCurrent = m_pRootFolder;
855cdf0e10cSrcweir 		ZipPackageFolder * pPrevious = NULL;
856cdf0e10cSrcweir 		while ( ( nIndex = aName.indexOf( '/', nOldIndex )) != -1 )
857cdf0e10cSrcweir 		{
858cdf0e10cSrcweir 			sTemp = aName.copy ( nOldIndex, nIndex - nOldIndex );
859cdf0e10cSrcweir 			if ( nIndex == nOldIndex )
860cdf0e10cSrcweir 				break;
861cdf0e10cSrcweir 			if ( pCurrent->hasByName( sTemp ) )
862cdf0e10cSrcweir 			{
863cdf0e10cSrcweir 				pPrevious = pCurrent;
864cdf0e10cSrcweir 				pCurrent = pCurrent->doGetByName( sTemp ).pFolder;
865cdf0e10cSrcweir 			}
866cdf0e10cSrcweir 			else
867cdf0e10cSrcweir 				throw NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
868cdf0e10cSrcweir 			nOldIndex = nIndex+1;
869cdf0e10cSrcweir 		}
870cdf0e10cSrcweir 		if ( bFolder )
871cdf0e10cSrcweir 		{
872cdf0e10cSrcweir 			if ( nStreamIndex != -1 )
873cdf0e10cSrcweir 				m_aRecent[sDirName] = pPrevious;
874cdf0e10cSrcweir 			return makeAny ( uno::Reference < XUnoTunnel > ( pCurrent ) );
875cdf0e10cSrcweir 		}
876cdf0e10cSrcweir 		else
877cdf0e10cSrcweir 		{
878cdf0e10cSrcweir 			sTemp = aName.copy( nOldIndex, aName.getLength() - nOldIndex );
879cdf0e10cSrcweir 			if ( pCurrent->hasByName ( sTemp ) )
880cdf0e10cSrcweir 			{
881cdf0e10cSrcweir 				if ( nStreamIndex != -1 )
882cdf0e10cSrcweir 					m_aRecent[sDirName] = pCurrent;
883cdf0e10cSrcweir 				return pCurrent->getByName( sTemp );
884cdf0e10cSrcweir 			}
885cdf0e10cSrcweir 			else
886cdf0e10cSrcweir 				throw NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
887cdf0e10cSrcweir 		}
888cdf0e10cSrcweir 	}
889cdf0e10cSrcweir }
890cdf0e10cSrcweir 
891cdf0e10cSrcweir //--------------------------------------------------------
hasByHierarchicalName(const OUString & aName)892cdf0e10cSrcweir sal_Bool SAL_CALL ZipPackage::hasByHierarchicalName( const OUString& aName )
893cdf0e10cSrcweir 		throw( RuntimeException )
894cdf0e10cSrcweir {
895cdf0e10cSrcweir 	OUString sTemp, sDirName;
896cdf0e10cSrcweir 	sal_Int32 nOldIndex, nIndex, nStreamIndex;
897cdf0e10cSrcweir 	FolderHash::iterator aIter;
898cdf0e10cSrcweir 
899cdf0e10cSrcweir 	if ( ( nIndex = aName.getLength() ) == 1 && *aName.getStr() == '/' )
900cdf0e10cSrcweir 		return sal_True;
901cdf0e10cSrcweir 	else
902cdf0e10cSrcweir 	{
903cdf0e10cSrcweir 		nStreamIndex = aName.lastIndexOf ( '/' );
904cdf0e10cSrcweir 		bool bFolder = nStreamIndex == nIndex-1;
905cdf0e10cSrcweir 		if ( nStreamIndex != -1 )
906cdf0e10cSrcweir 		{
907cdf0e10cSrcweir 			sDirName = aName.copy ( 0, nStreamIndex );
908cdf0e10cSrcweir 			aIter = m_aRecent.find ( sDirName );
909cdf0e10cSrcweir 			if ( aIter != m_aRecent.end() )
910cdf0e10cSrcweir 			{
911cdf0e10cSrcweir 				if ( bFolder )
912cdf0e10cSrcweir 				{
913cdf0e10cSrcweir 					sal_Int32 nDirIndex = aName.lastIndexOf ( '/', nStreamIndex );
914cdf0e10cSrcweir 					sTemp = aName.copy ( nDirIndex == -1 ? 0 : nDirIndex+1, nStreamIndex-nDirIndex-1 );
915cdf0e10cSrcweir 					if ( sTemp == ( *aIter ).second->getName() )
916cdf0e10cSrcweir 						return sal_True;
917cdf0e10cSrcweir 					else
918cdf0e10cSrcweir 						m_aRecent.erase ( aIter );
919cdf0e10cSrcweir 				}
920cdf0e10cSrcweir 				else
921cdf0e10cSrcweir 				{
922cdf0e10cSrcweir 					sTemp = aName.copy ( nStreamIndex + 1 );
923cdf0e10cSrcweir 					if ( ( *aIter ).second->hasByName( sTemp ) )
924cdf0e10cSrcweir 						return sal_True;
925cdf0e10cSrcweir 					else
926cdf0e10cSrcweir 						m_aRecent.erase( aIter );
927cdf0e10cSrcweir 				}
928cdf0e10cSrcweir 			}
929cdf0e10cSrcweir 		}
930cdf0e10cSrcweir 		else
931cdf0e10cSrcweir 		{
932cdf0e10cSrcweir 			if ( m_pRootFolder->hasByName ( aName ) )
933cdf0e10cSrcweir 				return sal_True;
934cdf0e10cSrcweir 		}
935cdf0e10cSrcweir 		ZipPackageFolder * pCurrent = m_pRootFolder;
936cdf0e10cSrcweir 		ZipPackageFolder * pPrevious = NULL;
937cdf0e10cSrcweir 		nOldIndex = 0;
938cdf0e10cSrcweir 		while ( ( nIndex = aName.indexOf( '/', nOldIndex )) != -1 )
939cdf0e10cSrcweir 		{
940cdf0e10cSrcweir 			sTemp = aName.copy ( nOldIndex, nIndex - nOldIndex );
941cdf0e10cSrcweir 			if ( nIndex == nOldIndex )
942cdf0e10cSrcweir 				break;
943cdf0e10cSrcweir 			if ( pCurrent->hasByName( sTemp ) )
944cdf0e10cSrcweir 			{
945cdf0e10cSrcweir 				pPrevious = pCurrent;
946cdf0e10cSrcweir 				pCurrent = pCurrent->doGetByName( sTemp ).pFolder;
947cdf0e10cSrcweir 			}
948cdf0e10cSrcweir 			else
949cdf0e10cSrcweir 				return sal_False;
950cdf0e10cSrcweir 			nOldIndex = nIndex+1;
951cdf0e10cSrcweir 		}
952cdf0e10cSrcweir 		if ( bFolder )
953cdf0e10cSrcweir 		{
954cdf0e10cSrcweir 			m_aRecent[sDirName] = pPrevious;
955cdf0e10cSrcweir 			return sal_True;
956cdf0e10cSrcweir 		}
957cdf0e10cSrcweir 		else
958cdf0e10cSrcweir 		{
959cdf0e10cSrcweir 			sTemp = aName.copy( nOldIndex, aName.getLength() - nOldIndex );
960cdf0e10cSrcweir 
961cdf0e10cSrcweir 			if ( pCurrent->hasByName( sTemp ) )
962cdf0e10cSrcweir 			{
963cdf0e10cSrcweir 				m_aRecent[sDirName] = pCurrent;
964cdf0e10cSrcweir 				return sal_True;
965cdf0e10cSrcweir 			}
966cdf0e10cSrcweir 		}
967cdf0e10cSrcweir 		return sal_False;
968cdf0e10cSrcweir 	}
969cdf0e10cSrcweir }
970cdf0e10cSrcweir 
971cdf0e10cSrcweir //--------------------------------------------------------
createInstance()972cdf0e10cSrcweir uno::Reference< XInterface > SAL_CALL ZipPackage::createInstance()
973cdf0e10cSrcweir 		throw( Exception, RuntimeException )
974cdf0e10cSrcweir {
975cdf0e10cSrcweir 	uno::Reference < XInterface > xRef = *( new ZipPackageStream ( *this, m_xFactory, m_bAllowRemoveOnInsert ) );
976cdf0e10cSrcweir 	return xRef;
977cdf0e10cSrcweir }
978cdf0e10cSrcweir //--------------------------------------------------------
createInstanceWithArguments(const uno::Sequence<Any> & aArguments)979cdf0e10cSrcweir uno::Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( const uno::Sequence< Any >& aArguments )
980cdf0e10cSrcweir 		throw( Exception, RuntimeException )
981cdf0e10cSrcweir {
982cdf0e10cSrcweir 	sal_Bool bArg = sal_False;
983cdf0e10cSrcweir 	uno::Reference < XInterface > xRef;
984cdf0e10cSrcweir 	if ( aArguments.getLength() )
985cdf0e10cSrcweir 		aArguments[0] >>= bArg;
986cdf0e10cSrcweir 	if ( bArg )
987cdf0e10cSrcweir 		xRef = *new ZipPackageFolder ( m_xFactory, m_nFormat, m_bAllowRemoveOnInsert );
988cdf0e10cSrcweir 	else
989cdf0e10cSrcweir 		xRef = *new ZipPackageStream ( *this, m_xFactory, m_bAllowRemoveOnInsert );
990cdf0e10cSrcweir 
991cdf0e10cSrcweir 	return xRef;
992cdf0e10cSrcweir }
993cdf0e10cSrcweir 
994cdf0e10cSrcweir //--------------------------------------------------------
WriteMimetypeMagicFile(ZipOutputStream & aZipOut)995cdf0e10cSrcweir void ZipPackage::WriteMimetypeMagicFile( ZipOutputStream& aZipOut )
996cdf0e10cSrcweir {
997cdf0e10cSrcweir 	const OUString sMime ( RTL_CONSTASCII_USTRINGPARAM ( "mimetype" ) );
998cdf0e10cSrcweir 	if ( m_xRootFolder->hasByName( sMime ) )
999cdf0e10cSrcweir 		m_xRootFolder->removeByName( sMime );
1000cdf0e10cSrcweir 
1001cdf0e10cSrcweir 	ZipEntry * pEntry = new ZipEntry;
1002cdf0e10cSrcweir 	sal_Int32 nBufferLength = m_pRootFolder->GetMediaType().getLength();
1003cdf0e10cSrcweir 	OString sMediaType = OUStringToOString( m_pRootFolder->GetMediaType(), RTL_TEXTENCODING_ASCII_US );
1004cdf0e10cSrcweir 	uno::Sequence< sal_Int8 > aType( ( sal_Int8* )sMediaType.getStr(),
1005cdf0e10cSrcweir 								nBufferLength );
1006cdf0e10cSrcweir 
1007cdf0e10cSrcweir 
1008cdf0e10cSrcweir 	pEntry->sPath = sMime;
1009cdf0e10cSrcweir 	pEntry->nMethod = STORED;
1010cdf0e10cSrcweir 	pEntry->nSize = pEntry->nCompressedSize = nBufferLength;
1011cdf0e10cSrcweir 	pEntry->nTime = ZipOutputStream::getCurrentDosTime();
1012cdf0e10cSrcweir 
1013cdf0e10cSrcweir 	CRC32 aCRC32;
1014cdf0e10cSrcweir 	aCRC32.update( aType );
1015cdf0e10cSrcweir 	pEntry->nCrc = aCRC32.getValue();
1016cdf0e10cSrcweir 
1017cdf0e10cSrcweir 	try
1018cdf0e10cSrcweir 	{
1019cdf0e10cSrcweir 		aZipOut.putNextEntry( *pEntry, NULL );
1020cdf0e10cSrcweir 		aZipOut.write( aType, 0, nBufferLength );
1021cdf0e10cSrcweir 		aZipOut.closeEntry();
1022cdf0e10cSrcweir 	}
1023cdf0e10cSrcweir 	catch ( ::com::sun::star::io::IOException & r )
1024cdf0e10cSrcweir 	{
1025cdf0e10cSrcweir 		throw WrappedTargetException(
1026cdf0e10cSrcweir 				OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "Error adding mimetype to the ZipOutputStream!" ) ),
1027cdf0e10cSrcweir 				static_cast < OWeakObject * > ( this ),
1028cdf0e10cSrcweir 				makeAny( r ) );
1029cdf0e10cSrcweir 	}
1030cdf0e10cSrcweir }
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir //--------------------------------------------------------
WriteManifest(ZipOutputStream & aZipOut,const vector<uno::Sequence<PropertyValue>> & aManList)1033cdf0e10cSrcweir void ZipPackage::WriteManifest( ZipOutputStream& aZipOut, const vector< uno::Sequence < PropertyValue > >& aManList )
1034cdf0e10cSrcweir {
1035cdf0e10cSrcweir     // Write the manifest
1036cdf0e10cSrcweir     uno::Reference < XOutputStream > xManOutStream;
1037cdf0e10cSrcweir     OUString sManifestWriter( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.ManifestWriter" ) );
1038cdf0e10cSrcweir     uno::Reference < XManifestWriter > xWriter ( m_xFactory->createInstance( sManifestWriter ), UNO_QUERY );
1039cdf0e10cSrcweir     if ( xWriter.is() )
1040cdf0e10cSrcweir     {
1041cdf0e10cSrcweir         ZipEntry * pEntry = new ZipEntry;
1042cdf0e10cSrcweir         ZipPackageBuffer *pBuffer = new ZipPackageBuffer( n_ConstBufferSize );
1043cdf0e10cSrcweir         xManOutStream = uno::Reference < XOutputStream > ( *pBuffer, UNO_QUERY );
1044cdf0e10cSrcweir 
1045cdf0e10cSrcweir         pEntry->sPath = OUString( RTL_CONSTASCII_USTRINGPARAM ( "META-INF/manifest.xml" ) );
1046cdf0e10cSrcweir         pEntry->nMethod = DEFLATED;
1047cdf0e10cSrcweir         pEntry->nCrc = pEntry->nSize = pEntry->nCompressedSize = -1;
1048cdf0e10cSrcweir         pEntry->nTime = ZipOutputStream::getCurrentDosTime();
1049cdf0e10cSrcweir 
1050cdf0e10cSrcweir         // Convert vector into a uno::Sequence
1051cdf0e10cSrcweir         uno::Sequence < uno::Sequence < PropertyValue > > aManifestSequence ( aManList.size() );
1052cdf0e10cSrcweir         sal_Int32 nInd = 0;
1053cdf0e10cSrcweir         for ( vector < uno::Sequence < PropertyValue > >::const_iterator aIter = aManList.begin(), aEnd = aManList.end();
1054cdf0e10cSrcweir              aIter != aEnd;
1055cdf0e10cSrcweir              aIter++, nInd++ )
1056cdf0e10cSrcweir         {
1057cdf0e10cSrcweir             aManifestSequence[nInd] = ( *aIter );
1058cdf0e10cSrcweir         }
1059cdf0e10cSrcweir         xWriter->writeManifestSequence ( xManOutStream,  aManifestSequence );
1060cdf0e10cSrcweir 
1061cdf0e10cSrcweir         sal_Int32 nBufferLength = static_cast < sal_Int32 > ( pBuffer->getPosition() );
1062cdf0e10cSrcweir         pBuffer->realloc( nBufferLength );
1063cdf0e10cSrcweir 
1064cdf0e10cSrcweir         // the manifest.xml is never encrypted - so pass an empty reference
1065cdf0e10cSrcweir         aZipOut.putNextEntry( *pEntry, NULL );
1066cdf0e10cSrcweir         aZipOut.write( pBuffer->getSequence(), 0, nBufferLength );
1067cdf0e10cSrcweir         aZipOut.closeEntry();
1068cdf0e10cSrcweir     }
1069cdf0e10cSrcweir     else
1070cdf0e10cSrcweir     {
1071cdf0e10cSrcweir         VOS_ENSURE ( 0, "Couldn't get a ManifestWriter!" );
1072cdf0e10cSrcweir         IOException aException;
1073cdf0e10cSrcweir         throw WrappedTargetException(
1074cdf0e10cSrcweir                 OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "Couldn't get a ManifestWriter!" ) ),
1075cdf0e10cSrcweir                 static_cast < OWeakObject * > ( this ),
1076cdf0e10cSrcweir                 makeAny( aException ) );
1077cdf0e10cSrcweir     }
1078cdf0e10cSrcweir }
1079cdf0e10cSrcweir 
1080cdf0e10cSrcweir //--------------------------------------------------------
WriteContentTypes(ZipOutputStream & aZipOut,const vector<uno::Sequence<PropertyValue>> & aManList)1081cdf0e10cSrcweir void ZipPackage::WriteContentTypes( ZipOutputStream& aZipOut, const vector< uno::Sequence < PropertyValue > >& aManList )
1082cdf0e10cSrcweir {
1083cdf0e10cSrcweir     const OUString sFullPath ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) );
1084cdf0e10cSrcweir     const OUString sMediaType ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) );
1085cdf0e10cSrcweir 
1086cdf0e10cSrcweir     ZipEntry* pEntry = new ZipEntry;
1087cdf0e10cSrcweir     ZipPackageBuffer *pBuffer = new ZipPackageBuffer( n_ConstBufferSize );
1088cdf0e10cSrcweir     uno::Reference< io::XOutputStream > xConTypeOutStream( *pBuffer, UNO_QUERY );
1089cdf0e10cSrcweir 
1090cdf0e10cSrcweir     pEntry->sPath = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "[Content_Types].xml" ) );
1091cdf0e10cSrcweir     pEntry->nMethod = DEFLATED;
1092cdf0e10cSrcweir     pEntry->nCrc = pEntry->nSize = pEntry->nCompressedSize = -1;
1093cdf0e10cSrcweir     pEntry->nTime = ZipOutputStream::getCurrentDosTime();
1094cdf0e10cSrcweir 
1095cdf0e10cSrcweir     // Convert vector into a uno::Sequence
1096cdf0e10cSrcweir     // TODO/LATER: use Defaulst entries in future
1097cdf0e10cSrcweir     uno::Sequence< beans::StringPair > aDefaultsSequence;
1098cdf0e10cSrcweir     uno::Sequence< beans::StringPair > aOverridesSequence( aManList.size() );
1099cdf0e10cSrcweir     sal_Int32 nSeqLength = 0;
1100cdf0e10cSrcweir     for ( vector< uno::Sequence< beans::PropertyValue > >::const_iterator aIter = aManList.begin(),
1101cdf0e10cSrcweir             aEnd = aManList.end();
1102cdf0e10cSrcweir          aIter != aEnd;
1103cdf0e10cSrcweir          aIter++ )
1104cdf0e10cSrcweir     {
1105cdf0e10cSrcweir         ::rtl::OUString aPath;
1106cdf0e10cSrcweir         ::rtl::OUString aType;
1107cdf0e10cSrcweir         OSL_ENSURE( ( *aIter )[PKG_MNFST_MEDIATYPE].Name.equals( sMediaType ) && ( *aIter )[PKG_MNFST_FULLPATH].Name.equals( sFullPath ),
1108cdf0e10cSrcweir                     "The mediatype sequence format is wrong!\n" );
1109cdf0e10cSrcweir         ( *aIter )[PKG_MNFST_MEDIATYPE].Value >>= aType;
1110cdf0e10cSrcweir         if ( aType.getLength() )
1111cdf0e10cSrcweir         {
1112cdf0e10cSrcweir             // only nonempty type makes sence here
1113cdf0e10cSrcweir             nSeqLength++;
1114cdf0e10cSrcweir             ( *aIter )[PKG_MNFST_FULLPATH].Value >>= aPath;
1115cdf0e10cSrcweir             aOverridesSequence[nSeqLength-1].First = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) ) + aPath;
1116cdf0e10cSrcweir             aOverridesSequence[nSeqLength-1].Second = aType;
1117cdf0e10cSrcweir         }
1118cdf0e10cSrcweir     }
1119cdf0e10cSrcweir     aOverridesSequence.realloc( nSeqLength );
1120cdf0e10cSrcweir 
1121cdf0e10cSrcweir     ::comphelper::OFOPXMLHelper::WriteContentSequence(
1122cdf0e10cSrcweir             xConTypeOutStream, aDefaultsSequence, aOverridesSequence, m_xFactory );
1123cdf0e10cSrcweir 
1124cdf0e10cSrcweir     sal_Int32 nBufferLength = static_cast < sal_Int32 > ( pBuffer->getPosition() );
1125cdf0e10cSrcweir     pBuffer->realloc( nBufferLength );
1126cdf0e10cSrcweir 
1127cdf0e10cSrcweir     // there is no encryption in this format currently
1128cdf0e10cSrcweir     aZipOut.putNextEntry( *pEntry, NULL );
1129cdf0e10cSrcweir     aZipOut.write( pBuffer->getSequence(), 0, nBufferLength );
1130cdf0e10cSrcweir     aZipOut.closeEntry();
1131cdf0e10cSrcweir }
1132cdf0e10cSrcweir 
1133cdf0e10cSrcweir //--------------------------------------------------------
ConnectTo(const uno::Reference<io::XInputStream> & xInStream)1134cdf0e10cSrcweir void ZipPackage::ConnectTo( const uno::Reference< io::XInputStream >& xInStream )
1135cdf0e10cSrcweir {
1136cdf0e10cSrcweir     m_xContentSeek.set( xInStream, uno::UNO_QUERY_THROW );
1137cdf0e10cSrcweir     m_xContentStream = xInStream;
1138cdf0e10cSrcweir 
1139cdf0e10cSrcweir     // seek back to the beginning of the temp file so we can read segments from it
1140cdf0e10cSrcweir     m_xContentSeek->seek( 0 );
1141cdf0e10cSrcweir     if ( m_pZipFile )
1142cdf0e10cSrcweir         m_pZipFile->setInputStream( m_xContentStream );
1143cdf0e10cSrcweir     else
1144cdf0e10cSrcweir         m_pZipFile = new ZipFile ( m_xContentStream, m_xFactory, sal_False );
1145cdf0e10cSrcweir }
1146cdf0e10cSrcweir 
1147cdf0e10cSrcweir //--------------------------------------------------------
writeTempFile()1148cdf0e10cSrcweir uno::Reference< io::XInputStream > ZipPackage::writeTempFile()
1149cdf0e10cSrcweir {
1150cdf0e10cSrcweir     // In case the target local file does not exist or empty
1151cdf0e10cSrcweir     // write directly to it otherwize create a temporary file to write to.
1152cdf0e10cSrcweir     // If a temporary file is created it is returned back by the method.
1153cdf0e10cSrcweir     // If the data written directly, xComponentStream will be switched here
1154cdf0e10cSrcweir 
1155cdf0e10cSrcweir     sal_Bool bUseTemp = sal_True;
1156cdf0e10cSrcweir     uno::Reference < io::XInputStream > xResult;
1157cdf0e10cSrcweir     uno::Reference < io::XInputStream > xTempIn;
1158cdf0e10cSrcweir 
1159cdf0e10cSrcweir     uno::Reference < io::XOutputStream > xTempOut;
1160cdf0e10cSrcweir     uno::Reference< io::XActiveDataStreamer > xSink;
1161cdf0e10cSrcweir 
1162cdf0e10cSrcweir     if ( m_eMode == e_IMode_URL && !m_pZipFile && isLocalFile_Impl( m_aURL ) )
1163cdf0e10cSrcweir     {
1164cdf0e10cSrcweir         xSink = openOriginalForOutput();
1165cdf0e10cSrcweir         if( xSink.is() )
1166cdf0e10cSrcweir         {
1167cdf0e10cSrcweir             uno::Reference< io::XStream > xStr = xSink->getStream();
1168cdf0e10cSrcweir             if( xStr.is() )
1169cdf0e10cSrcweir             {
1170cdf0e10cSrcweir                 xTempOut = xStr->getOutputStream();
1171cdf0e10cSrcweir                 if( xTempOut.is() )
1172cdf0e10cSrcweir                     bUseTemp = sal_False;
1173cdf0e10cSrcweir             }
1174cdf0e10cSrcweir         }
1175cdf0e10cSrcweir     }
1176cdf0e10cSrcweir     else if ( m_eMode == e_IMode_XStream && !m_pZipFile )
1177cdf0e10cSrcweir     {
1178cdf0e10cSrcweir         // write directly to an empty stream
1179cdf0e10cSrcweir         xTempOut = m_xStream->getOutputStream();
1180cdf0e10cSrcweir         if( xTempOut.is() )
1181cdf0e10cSrcweir             bUseTemp = sal_False;
1182cdf0e10cSrcweir     }
1183cdf0e10cSrcweir 
1184cdf0e10cSrcweir     if( bUseTemp )
1185cdf0e10cSrcweir     {
1186cdf0e10cSrcweir         // create temporary file
1187cdf0e10cSrcweir         const OUString sServiceName ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.io.TempFile" ) );
1188cdf0e10cSrcweir         uno::Reference < io::XStream > xTempFile( m_xFactory->createInstance ( sServiceName ), UNO_QUERY_THROW );
1189cdf0e10cSrcweir         xTempOut.set( xTempFile->getOutputStream(), UNO_SET_THROW );
1190cdf0e10cSrcweir         xTempIn.set( xTempFile->getInputStream(), UNO_SET_THROW );
1191cdf0e10cSrcweir     }
1192cdf0e10cSrcweir 
1193cdf0e10cSrcweir     // Hand it to the ZipOutputStream:
1194cdf0e10cSrcweir     ZipOutputStream aZipOut( m_xFactory, xTempOut );
1195cdf0e10cSrcweir     aZipOut.setMethod( DEFLATED );
1196cdf0e10cSrcweir     aZipOut.setLevel( DEFAULT_COMPRESSION );
1197cdf0e10cSrcweir 
1198cdf0e10cSrcweir     try
1199cdf0e10cSrcweir     {
1200cdf0e10cSrcweir         if ( m_nFormat == embed::StorageFormats::PACKAGE )
1201cdf0e10cSrcweir         {
1202cdf0e10cSrcweir             // Remove the old manifest.xml file as the
1203cdf0e10cSrcweir             // manifest will be re-generated and the
1204cdf0e10cSrcweir             // META-INF directory implicitly created if does not exist
1205cdf0e10cSrcweir             const OUString sMeta ( RTL_CONSTASCII_USTRINGPARAM ( "META-INF" ) );
1206cdf0e10cSrcweir 
1207cdf0e10cSrcweir             if ( m_xRootFolder->hasByName( sMeta ) )
1208cdf0e10cSrcweir             {
1209cdf0e10cSrcweir                 const OUString sManifest ( RTL_CONSTASCII_USTRINGPARAM( "manifest.xml" ) );
1210cdf0e10cSrcweir 
1211cdf0e10cSrcweir                 uno::Reference< XUnoTunnel > xTunnel;
1212cdf0e10cSrcweir                 Any aAny = m_xRootFolder->getByName( sMeta );
1213cdf0e10cSrcweir                 aAny >>= xTunnel;
1214cdf0e10cSrcweir                 uno::Reference< XNameContainer > xMetaInfFolder( xTunnel, UNO_QUERY );
1215cdf0e10cSrcweir                 if ( xMetaInfFolder.is() && xMetaInfFolder->hasByName( sManifest ) )
1216cdf0e10cSrcweir                     xMetaInfFolder->removeByName( sManifest );
1217cdf0e10cSrcweir             }
1218cdf0e10cSrcweir 
1219cdf0e10cSrcweir             // Write a magic file with mimetype
1220cdf0e10cSrcweir             WriteMimetypeMagicFile( aZipOut );
1221cdf0e10cSrcweir         }
1222cdf0e10cSrcweir         else if ( m_nFormat == embed::StorageFormats::OFOPXML )
1223cdf0e10cSrcweir         {
1224cdf0e10cSrcweir             // Remove the old [Content_Types].xml file as the
1225cdf0e10cSrcweir             // file will be re-generated
1226cdf0e10cSrcweir 
1227cdf0e10cSrcweir             const ::rtl::OUString aContentTypes( RTL_CONSTASCII_USTRINGPARAM ( "[Content_Types].xml" ) );
1228cdf0e10cSrcweir 
1229cdf0e10cSrcweir             if ( m_xRootFolder->hasByName( aContentTypes ) )
1230cdf0e10cSrcweir                 m_xRootFolder->removeByName( aContentTypes );
1231cdf0e10cSrcweir         }
1232cdf0e10cSrcweir 
1233cdf0e10cSrcweir         // Create a vector to store data for the manifest.xml file
1234cdf0e10cSrcweir         vector < uno::Sequence < PropertyValue > > aManList;
1235cdf0e10cSrcweir 
1236cdf0e10cSrcweir         const OUString sMediaType ( RTL_CONSTASCII_USTRINGPARAM ( "MediaType" ) );
1237cdf0e10cSrcweir         const OUString sVersion ( RTL_CONSTASCII_USTRINGPARAM ( "Version" ) );
1238cdf0e10cSrcweir         const OUString sFullPath ( RTL_CONSTASCII_USTRINGPARAM ( "FullPath" ) );
1239cdf0e10cSrcweir 
1240cdf0e10cSrcweir         if ( m_nFormat == embed::StorageFormats::PACKAGE )
1241cdf0e10cSrcweir         {
1242cdf0e10cSrcweir             uno::Sequence < PropertyValue > aPropSeq( PKG_SIZE_NOENCR_MNFST );
1243cdf0e10cSrcweir             aPropSeq [PKG_MNFST_MEDIATYPE].Name = sMediaType;
1244cdf0e10cSrcweir             aPropSeq [PKG_MNFST_MEDIATYPE].Value <<= m_pRootFolder->GetMediaType();
1245cdf0e10cSrcweir             aPropSeq [PKG_MNFST_VERSION].Name = sVersion;
1246cdf0e10cSrcweir             aPropSeq [PKG_MNFST_VERSION].Value <<= m_pRootFolder->GetVersion();
1247cdf0e10cSrcweir             aPropSeq [PKG_MNFST_FULLPATH].Name = sFullPath;
1248cdf0e10cSrcweir             aPropSeq [PKG_MNFST_FULLPATH].Value <<= OUString ( RTL_CONSTASCII_USTRINGPARAM ( "/" ) );
1249cdf0e10cSrcweir 
1250cdf0e10cSrcweir             aManList.push_back( aPropSeq );
1251cdf0e10cSrcweir         }
1252cdf0e10cSrcweir 
1253cdf0e10cSrcweir         // Get a random number generator and seed it with current timestamp
1254cdf0e10cSrcweir         // This will be used to generate random salt and initialisation vectors
1255cdf0e10cSrcweir         // for encrypted streams
1256cdf0e10cSrcweir         TimeValue aTime;
1257cdf0e10cSrcweir         osl_getSystemTime( &aTime );
1258cdf0e10cSrcweir         rtlRandomPool aRandomPool = rtl_random_createPool ();
1259cdf0e10cSrcweir         rtl_random_addBytes ( aRandomPool, &aTime, 8 );
1260cdf0e10cSrcweir 
1261cdf0e10cSrcweir         // call saveContents ( it will recursively save sub-directories
1262cdf0e10cSrcweir         OUString aEmptyString;
1263cdf0e10cSrcweir         m_pRootFolder->saveContents( aEmptyString, aManList, aZipOut, GetEncryptionKey(), aRandomPool );
1264cdf0e10cSrcweir 
1265cdf0e10cSrcweir         // Clean up random pool memory
1266cdf0e10cSrcweir         rtl_random_destroyPool ( aRandomPool );
1267cdf0e10cSrcweir 
1268cdf0e10cSrcweir         if( m_nFormat == embed::StorageFormats::PACKAGE )
1269cdf0e10cSrcweir         {
1270cdf0e10cSrcweir             WriteManifest( aZipOut, aManList );
1271cdf0e10cSrcweir         }
1272cdf0e10cSrcweir         else if( m_nFormat == embed::StorageFormats::OFOPXML )
1273cdf0e10cSrcweir         {
1274cdf0e10cSrcweir             WriteContentTypes( aZipOut, aManList );
1275cdf0e10cSrcweir         }
1276cdf0e10cSrcweir 
1277cdf0e10cSrcweir         aZipOut.finish();
1278cdf0e10cSrcweir 
1279cdf0e10cSrcweir         if( bUseTemp )
1280cdf0e10cSrcweir             xResult = xTempIn;
1281cdf0e10cSrcweir 
1282cdf0e10cSrcweir         // Update our References to point to the new temp file
1283cdf0e10cSrcweir         if( !bUseTemp )
1284cdf0e10cSrcweir         {
1285cdf0e10cSrcweir             // the case when the original contents were written directly
1286cdf0e10cSrcweir             xTempOut->flush();
1287cdf0e10cSrcweir 
1288cdf0e10cSrcweir             // in case the stream is based on a file it will implement the following interface
1289cdf0e10cSrcweir             // the call should be used to be sure that the contents are written to the file system
1290cdf0e10cSrcweir             uno::Reference< io::XAsyncOutputMonitor > asyncOutputMonitor( xTempOut, uno::UNO_QUERY );
1291cdf0e10cSrcweir             if ( asyncOutputMonitor.is() )
1292cdf0e10cSrcweir                 asyncOutputMonitor->waitForCompletion();
1293cdf0e10cSrcweir 
1294cdf0e10cSrcweir             // no need to postpone switching to the new stream since the target was written directly
1295cdf0e10cSrcweir             uno::Reference< io::XInputStream > xNewStream;
1296cdf0e10cSrcweir             if ( m_eMode == e_IMode_URL )
1297cdf0e10cSrcweir                 xNewStream = xSink->getStream()->getInputStream();
1298cdf0e10cSrcweir             else if ( m_eMode == e_IMode_XStream && m_xStream.is() )
1299cdf0e10cSrcweir                 xNewStream = m_xStream->getInputStream();
1300cdf0e10cSrcweir 
1301cdf0e10cSrcweir             if ( xNewStream.is() )
1302cdf0e10cSrcweir                 ConnectTo( xNewStream );
1303cdf0e10cSrcweir         }
1304cdf0e10cSrcweir     }
1305cdf0e10cSrcweir     catch ( uno::Exception& )
1306cdf0e10cSrcweir     {
1307cdf0e10cSrcweir         if( bUseTemp )
1308cdf0e10cSrcweir         {
1309cdf0e10cSrcweir             // no information loss appeares, thus no special handling is required
1310cdf0e10cSrcweir                uno::Any aCaught( ::cppu::getCaughtException() );
1311cdf0e10cSrcweir 
1312cdf0e10cSrcweir             // it is allowed to throw WrappedTargetException
1313cdf0e10cSrcweir             WrappedTargetException aException;
1314cdf0e10cSrcweir             if ( aCaught >>= aException )
1315cdf0e10cSrcweir                 throw aException;
1316cdf0e10cSrcweir 
1317cdf0e10cSrcweir             throw WrappedTargetException(
1318cdf0e10cSrcweir                     OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "Problem writing the original content!" ) ),
1319cdf0e10cSrcweir                     static_cast < OWeakObject * > ( this ),
1320cdf0e10cSrcweir                     aCaught );
1321cdf0e10cSrcweir         }
1322cdf0e10cSrcweir         else
1323cdf0e10cSrcweir         {
1324cdf0e10cSrcweir             // the document is written directly, although it was empty it is important to notify that the writing has failed
1325cdf0e10cSrcweir             // TODO/LATER: let the package be able to recover in this situation
1326cdf0e10cSrcweir             ::rtl::OUString aErrTxt( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "This package is unusable!" ) );
1327cdf0e10cSrcweir             embed::UseBackupException aException( aErrTxt, uno::Reference< uno::XInterface >(), ::rtl::OUString() );
1328cdf0e10cSrcweir             throw WrappedTargetException( aErrTxt,
1329cdf0e10cSrcweir                                             static_cast < OWeakObject * > ( this ),
1330cdf0e10cSrcweir                                             makeAny ( aException ) );
1331cdf0e10cSrcweir         }
1332cdf0e10cSrcweir     }
1333cdf0e10cSrcweir 
1334cdf0e10cSrcweir     return xResult;
1335cdf0e10cSrcweir }
1336cdf0e10cSrcweir 
1337cdf0e10cSrcweir //--------------------------------------------------------
openOriginalForOutput()1338cdf0e10cSrcweir uno::Reference< XActiveDataStreamer > ZipPackage::openOriginalForOutput()
1339cdf0e10cSrcweir {
1340cdf0e10cSrcweir 	// open and truncate the original file
1341cdf0e10cSrcweir 	Content aOriginalContent ( m_aURL, uno::Reference < XCommandEnvironment >() );
1342cdf0e10cSrcweir 	uno::Reference< XActiveDataStreamer > xSink = new ActiveDataStreamer;
1343cdf0e10cSrcweir 
1344cdf0e10cSrcweir 	if ( m_eMode == e_IMode_URL )
1345cdf0e10cSrcweir 	{
1346cdf0e10cSrcweir 		try
1347cdf0e10cSrcweir 		{
1348cdf0e10cSrcweir 			sal_Bool bTruncSuccess = sal_False;
1349cdf0e10cSrcweir 
1350cdf0e10cSrcweir 			try
1351cdf0e10cSrcweir 			{
1352cdf0e10cSrcweir 				Exception aDetect;
1353cdf0e10cSrcweir 				sal_Int64 aSize = 0;
1354cdf0e10cSrcweir 				Any aAny = aOriginalContent.setPropertyValue( OUString::createFromAscii( "Size" ), makeAny( aSize ) );
1355cdf0e10cSrcweir 				if( !( aAny >>= aDetect ) )
1356cdf0e10cSrcweir 					bTruncSuccess = sal_True;
1357cdf0e10cSrcweir 			}
1358cdf0e10cSrcweir 			catch( Exception& )
1359cdf0e10cSrcweir 			{
1360cdf0e10cSrcweir 			}
1361cdf0e10cSrcweir 
1362cdf0e10cSrcweir 			if( !bTruncSuccess )
1363cdf0e10cSrcweir 			{
1364cdf0e10cSrcweir 				// the file is not accessible
1365cdf0e10cSrcweir 				// just try to write an empty stream to it
1366cdf0e10cSrcweir 
1367cdf0e10cSrcweir 				uno::Reference< XInputStream > xTempIn = new DummyInputStream; //uno::Reference< XInputStream >( xTempOut, UNO_QUERY );
1368cdf0e10cSrcweir 				aOriginalContent.writeStream( xTempIn , sal_True );
1369cdf0e10cSrcweir 			}
1370cdf0e10cSrcweir 
1371cdf0e10cSrcweir 			OpenCommandArgument2 aArg;
1372cdf0e10cSrcweir 	   		aArg.Mode		= OpenMode::DOCUMENT;
1373cdf0e10cSrcweir 	   		aArg.Priority	= 0; // unused
1374cdf0e10cSrcweir    			aArg.Sink       = xSink;
1375cdf0e10cSrcweir    			aArg.Properties = uno::Sequence< Property >( 0 ); // unused
1376cdf0e10cSrcweir 
1377cdf0e10cSrcweir 			aOriginalContent.executeCommand( OUString::createFromAscii( "open" ), makeAny( aArg ) );
1378cdf0e10cSrcweir 		}
1379cdf0e10cSrcweir 		catch( Exception& )
1380cdf0e10cSrcweir 		{
1381cdf0e10cSrcweir 			// seems to be nonlocal file
1382cdf0e10cSrcweir 			// temporary file mechanics should be used
1383cdf0e10cSrcweir 		}
1384cdf0e10cSrcweir 	}
1385cdf0e10cSrcweir 
1386cdf0e10cSrcweir 	return xSink;
1387cdf0e10cSrcweir }
1388cdf0e10cSrcweir 
1389cdf0e10cSrcweir //--------------------------------------------------------
commitChanges()1390cdf0e10cSrcweir void SAL_CALL ZipPackage::commitChanges()
1391cdf0e10cSrcweir         throw( WrappedTargetException, RuntimeException )
1392cdf0e10cSrcweir {
1393cdf0e10cSrcweir     // lock the component for the time of commiting
1394cdf0e10cSrcweir     ::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() );
1395cdf0e10cSrcweir 
1396cdf0e10cSrcweir     if ( m_eMode == e_IMode_XInputStream )
1397cdf0e10cSrcweir     {
1398cdf0e10cSrcweir         IOException aException;
1399cdf0e10cSrcweir         throw WrappedTargetException( OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "This package is read only!" ) ),
1400cdf0e10cSrcweir                 static_cast < OWeakObject * > ( this ), makeAny ( aException ) );
1401cdf0e10cSrcweir     }
1402cdf0e10cSrcweir 
1403cdf0e10cSrcweir     RTL_LOGFILE_TRACE_AUTHOR ( "package", LOGFILE_AUTHOR, "{ ZipPackage::commitChanges" );
1404cdf0e10cSrcweir 
1405cdf0e10cSrcweir     // first the writeTempFile is called, if it returns a stream the stream should be written to the target
1406cdf0e10cSrcweir     // if no stream was returned, the file was written directly, nothing should be done
1407cdf0e10cSrcweir 
1408cdf0e10cSrcweir     uno::Reference< io::XInputStream > xTempInStream = writeTempFile();
1409cdf0e10cSrcweir     if ( xTempInStream.is() )
1410cdf0e10cSrcweir     {
1411cdf0e10cSrcweir         uno::Reference< io::XSeekable > xTempSeek( xTempInStream, uno::UNO_QUERY_THROW );
1412cdf0e10cSrcweir 
1413cdf0e10cSrcweir         try
1414cdf0e10cSrcweir         {
1415cdf0e10cSrcweir             xTempSeek->seek( 0 );
1416cdf0e10cSrcweir         }
1417cdf0e10cSrcweir         catch( uno::Exception& r )
1418cdf0e10cSrcweir         {
1419cdf0e10cSrcweir             throw WrappedTargetException( OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "Temporary file should be seekable!" ) ),
1420cdf0e10cSrcweir                     static_cast < OWeakObject * > ( this ), makeAny ( r ) );
1421cdf0e10cSrcweir         }
1422cdf0e10cSrcweir 
1423cdf0e10cSrcweir         // connect to the temporary stream
1424cdf0e10cSrcweir         ConnectTo( xTempInStream );
1425cdf0e10cSrcweir 
1426cdf0e10cSrcweir         if ( m_eMode == e_IMode_XStream )
1427cdf0e10cSrcweir         {
1428cdf0e10cSrcweir             // First truncate our output stream
1429cdf0e10cSrcweir             uno::Reference < XOutputStream > xOutputStream;
1430cdf0e10cSrcweir 
1431cdf0e10cSrcweir             // preparation for copy step
1432cdf0e10cSrcweir             try
1433cdf0e10cSrcweir             {
1434cdf0e10cSrcweir                 xOutputStream = m_xStream->getOutputStream();
1435cdf0e10cSrcweir                 uno::Reference < XTruncate > xTruncate ( xOutputStream, UNO_QUERY );
1436cdf0e10cSrcweir                 if ( !xTruncate.is() )
1437cdf0e10cSrcweir                     throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1438cdf0e10cSrcweir 
1439cdf0e10cSrcweir                 // after successful truncation the original file contents are already lost
1440cdf0e10cSrcweir                 xTruncate->truncate();
1441cdf0e10cSrcweir             }
1442cdf0e10cSrcweir             catch( uno::Exception& r )
1443cdf0e10cSrcweir             {
1444cdf0e10cSrcweir                 throw WrappedTargetException( OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "This package is read only!" ) ),
1445cdf0e10cSrcweir                         static_cast < OWeakObject * > ( this ), makeAny ( r ) );
1446cdf0e10cSrcweir             }
1447cdf0e10cSrcweir 
1448cdf0e10cSrcweir             try
1449cdf0e10cSrcweir             {
1450cdf0e10cSrcweir                 // then copy the contents of the tempfile to our output stream
1451cdf0e10cSrcweir                 ::comphelper::OStorageHelper::CopyInputToOutput( xTempInStream, xOutputStream );
1452cdf0e10cSrcweir                 xOutputStream->flush();
1453cdf0e10cSrcweir                 uno::Reference< io::XAsyncOutputMonitor > asyncOutputMonitor(
1454cdf0e10cSrcweir                     xOutputStream, uno::UNO_QUERY );
1455cdf0e10cSrcweir                 if ( asyncOutputMonitor.is() ) {
1456cdf0e10cSrcweir                     asyncOutputMonitor->waitForCompletion();
1457cdf0e10cSrcweir                 }
1458cdf0e10cSrcweir             }
1459cdf0e10cSrcweir             catch( uno::Exception& )
1460cdf0e10cSrcweir             {
1461cdf0e10cSrcweir                 // if anything goes wrong in this block the target file becomes corrupted
1462cdf0e10cSrcweir                 // so an exception should be thrown as a notification about it
1463cdf0e10cSrcweir                 // and the package must disconnect from the stream
1464cdf0e10cSrcweir                 DisconnectFromTargetAndThrowException_Impl( xTempInStream );
1465cdf0e10cSrcweir             }
1466cdf0e10cSrcweir         }
1467cdf0e10cSrcweir         else if ( m_eMode == e_IMode_URL )
1468cdf0e10cSrcweir         {
1469cdf0e10cSrcweir             uno::Reference< XOutputStream > aOrigFileStream;
1470cdf0e10cSrcweir             sal_Bool bCanBeCorrupted = sal_False;
1471cdf0e10cSrcweir 
1472cdf0e10cSrcweir             if( isLocalFile_Impl( m_aURL ) )
1473cdf0e10cSrcweir             {
1474cdf0e10cSrcweir                 // write directly in case of local file
1475cdf0e10cSrcweir                 uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > xSimpleAccess(
1476cdf0e10cSrcweir                     m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ),
1477cdf0e10cSrcweir                     uno::UNO_QUERY );
1478cdf0e10cSrcweir                 OSL_ENSURE( xSimpleAccess.is(), "Can't instatiate SimpleFileAccess service!\n" );
1479cdf0e10cSrcweir                 uno::Reference< io::XTruncate > xOrigTruncate;
1480cdf0e10cSrcweir                 if ( xSimpleAccess.is() )
1481cdf0e10cSrcweir                 {
1482cdf0e10cSrcweir                     try
1483cdf0e10cSrcweir                     {
1484cdf0e10cSrcweir                         aOrigFileStream = xSimpleAccess->openFileWrite( m_aURL );
1485cdf0e10cSrcweir                         xOrigTruncate = uno::Reference< io::XTruncate >( aOrigFileStream, uno::UNO_QUERY_THROW );
1486cdf0e10cSrcweir                         // after successful truncation the file is already corrupted
1487cdf0e10cSrcweir                         xOrigTruncate->truncate();
1488cdf0e10cSrcweir                     }
1489cdf0e10cSrcweir                     catch( uno::Exception& )
1490cdf0e10cSrcweir                     {}
1491cdf0e10cSrcweir                 }
1492cdf0e10cSrcweir 
1493cdf0e10cSrcweir                 if( xOrigTruncate.is() )
1494cdf0e10cSrcweir                 {
1495cdf0e10cSrcweir                     try
1496cdf0e10cSrcweir                     {
1497cdf0e10cSrcweir                         ::comphelper::OStorageHelper::CopyInputToOutput( xTempInStream, aOrigFileStream );
1498cdf0e10cSrcweir                         aOrigFileStream->closeOutput();
1499cdf0e10cSrcweir                     }
1500cdf0e10cSrcweir                     catch( uno::Exception& )
1501cdf0e10cSrcweir                     {
1502cdf0e10cSrcweir                         try {
1503cdf0e10cSrcweir                             aOrigFileStream->closeOutput();
1504cdf0e10cSrcweir                         } catch ( uno::Exception& ) {}
1505cdf0e10cSrcweir 
1506cdf0e10cSrcweir                         aOrigFileStream = uno::Reference< XOutputStream >();
1507cdf0e10cSrcweir                         // the original file can already be corrupted
1508cdf0e10cSrcweir                         bCanBeCorrupted = sal_True;
1509cdf0e10cSrcweir                     }
1510cdf0e10cSrcweir                 }
1511cdf0e10cSrcweir             }
1512cdf0e10cSrcweir 
1513cdf0e10cSrcweir             if( !aOrigFileStream.is() )
1514cdf0e10cSrcweir             {
1515cdf0e10cSrcweir                 try
1516cdf0e10cSrcweir                 {
1517cdf0e10cSrcweir                     uno::Reference < XPropertySet > xPropSet ( xTempInStream, UNO_QUERY );
1518cdf0e10cSrcweir                     OSL_ENSURE( xPropSet.is(), "This is a temporary file that must implement XPropertySet!\n" );
1519cdf0e10cSrcweir                     if ( !xPropSet.is() )
1520cdf0e10cSrcweir                         throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1521cdf0e10cSrcweir 
1522cdf0e10cSrcweir                     OUString sTargetFolder = m_aURL.copy ( 0, m_aURL.lastIndexOf ( static_cast < sal_Unicode > ( '/' ) ) );
1523cdf0e10cSrcweir                     Content aContent ( sTargetFolder, uno::Reference < XCommandEnvironment > () );
1524cdf0e10cSrcweir 
1525cdf0e10cSrcweir                     OUString sTempURL;
1526cdf0e10cSrcweir                     Any aAny = xPropSet->getPropertyValue ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Uri" ) ) );
1527cdf0e10cSrcweir                     aAny >>= sTempURL;
1528cdf0e10cSrcweir 
1529cdf0e10cSrcweir                     TransferInfo aInfo;
1530cdf0e10cSrcweir                     aInfo.NameClash = NameClash::OVERWRITE;
1531cdf0e10cSrcweir                     aInfo.MoveData = sal_False;
1532cdf0e10cSrcweir                     aInfo.SourceURL = sTempURL;
1533cdf0e10cSrcweir                     aInfo.NewTitle = rtl::Uri::decode ( m_aURL.copy ( 1 + m_aURL.lastIndexOf ( static_cast < sal_Unicode > ( '/' ) ) ),
1534cdf0e10cSrcweir                                                         rtl_UriDecodeWithCharset,
1535cdf0e10cSrcweir                                                         RTL_TEXTENCODING_UTF8 );
1536cdf0e10cSrcweir                     aAny <<= aInfo;
1537cdf0e10cSrcweir 
1538cdf0e10cSrcweir                     // if the file is still not corrupted, it can become after the next step
1539cdf0e10cSrcweir                     aContent.executeCommand ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "transfer" ) ), aAny );
1540cdf0e10cSrcweir                 }
1541cdf0e10cSrcweir                 catch ( ::com::sun::star::uno::Exception& r )
1542cdf0e10cSrcweir                 {
1543cdf0e10cSrcweir                     if ( bCanBeCorrupted )
1544cdf0e10cSrcweir                         DisconnectFromTargetAndThrowException_Impl( xTempInStream );
1545cdf0e10cSrcweir 
1546cdf0e10cSrcweir                     throw WrappedTargetException(
1547cdf0e10cSrcweir                                                 OUString( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "This package may be read only!" ) ),
1548cdf0e10cSrcweir                                                 static_cast < OWeakObject * > ( this ),
1549cdf0e10cSrcweir                                                 makeAny ( r ) );
1550cdf0e10cSrcweir                 }
1551cdf0e10cSrcweir             }
1552cdf0e10cSrcweir         }
1553cdf0e10cSrcweir     }
1554cdf0e10cSrcweir 
1555cdf0e10cSrcweir     // after successful storing it can be set to false
1556cdf0e10cSrcweir     m_bMediaTypeFallbackUsed = sal_False;
1557cdf0e10cSrcweir 
1558cdf0e10cSrcweir     RTL_LOGFILE_TRACE_AUTHOR ( "package", LOGFILE_AUTHOR, "} ZipPackage::commitChanges" );
1559cdf0e10cSrcweir }
1560cdf0e10cSrcweir 
1561cdf0e10cSrcweir //--------------------------------------------------------
DisconnectFromTargetAndThrowException_Impl(const uno::Reference<io::XInputStream> & xTempStream)1562cdf0e10cSrcweir void ZipPackage::DisconnectFromTargetAndThrowException_Impl( const uno::Reference< io::XInputStream >& xTempStream )
1563cdf0e10cSrcweir {
1564cdf0e10cSrcweir 	m_xStream = uno::Reference< io::XStream >( xTempStream, uno::UNO_QUERY );
1565cdf0e10cSrcweir 	if ( m_xStream.is() )
1566cdf0e10cSrcweir 		m_eMode = e_IMode_XStream;
1567cdf0e10cSrcweir 	else
1568cdf0e10cSrcweir 		m_eMode = e_IMode_XInputStream;
1569cdf0e10cSrcweir 
1570cdf0e10cSrcweir 	::rtl::OUString aTempURL;
1571cdf0e10cSrcweir 	try {
1572cdf0e10cSrcweir 		uno::Reference< beans::XPropertySet > xTempFile( xTempStream, uno::UNO_QUERY_THROW );
1573cdf0e10cSrcweir 		uno::Any aUrl = xTempFile->getPropertyValue( ::rtl::OUString::createFromAscii( "Uri" ) );
1574cdf0e10cSrcweir 		aUrl >>= aTempURL;
1575cdf0e10cSrcweir 		xTempFile->setPropertyValue( ::rtl::OUString::createFromAscii( "RemoveFile" ),
1576cdf0e10cSrcweir 									 uno::makeAny( sal_False ) );
1577cdf0e10cSrcweir 	}
1578cdf0e10cSrcweir 	catch ( uno::Exception& )
1579cdf0e10cSrcweir 	{
1580cdf0e10cSrcweir 		OSL_ENSURE( sal_False, "These calls are pretty simple, they should not fail!\n" );
1581cdf0e10cSrcweir 	}
1582cdf0e10cSrcweir 
1583cdf0e10cSrcweir 	::rtl::OUString aErrTxt( RTL_CONSTASCII_USTRINGPARAM ( OSL_LOG_PREFIX "This package is read only!" ) );
1584cdf0e10cSrcweir 	embed::UseBackupException aException( aErrTxt, uno::Reference< uno::XInterface >(), aTempURL );
1585cdf0e10cSrcweir 	throw WrappedTargetException( aErrTxt,
1586cdf0e10cSrcweir 									static_cast < OWeakObject * > ( this ),
1587cdf0e10cSrcweir 									makeAny ( aException ) );
1588cdf0e10cSrcweir }
1589cdf0e10cSrcweir 
1590cdf0e10cSrcweir //--------------------------------------------------------
GetEncryptionKey()1591cdf0e10cSrcweir const uno::Sequence< sal_Int8 > ZipPackage::GetEncryptionKey()
1592cdf0e10cSrcweir {
1593cdf0e10cSrcweir     uno::Sequence< sal_Int8 > aResult;
1594cdf0e10cSrcweir 
1595cdf0e10cSrcweir     if ( m_aStorageEncryptionKeys.getLength() )
1596cdf0e10cSrcweir     {
1597cdf0e10cSrcweir         ::rtl::OUString aNameToFind;
1598cdf0e10cSrcweir         if ( m_nStartKeyGenerationID == xml::crypto::DigestID::SHA256 )
1599cdf0e10cSrcweir             aNameToFind = PACKAGE_ENCRYPTIONDATA_SHA256UTF8;
1600cdf0e10cSrcweir         else if ( m_nStartKeyGenerationID == xml::crypto::DigestID::SHA1 )
1601cdf0e10cSrcweir             aNameToFind = PACKAGE_ENCRYPTIONDATA_SHA1UTF8;
1602cdf0e10cSrcweir         else
1603cdf0e10cSrcweir             throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No expected key is provided!" ) ), uno::Reference< uno::XInterface >() );
1604cdf0e10cSrcweir 
1605cdf0e10cSrcweir         for ( sal_Int32 nInd = 0; nInd < m_aStorageEncryptionKeys.getLength(); nInd++ )
1606cdf0e10cSrcweir             if ( m_aStorageEncryptionKeys[nInd].Name.equals( aNameToFind ) )
1607cdf0e10cSrcweir                 m_aStorageEncryptionKeys[nInd].Value >>= aResult;
1608cdf0e10cSrcweir 
1609cdf0e10cSrcweir         // empty keys are not allowed here
1610cdf0e10cSrcweir         // so it is not important whether there is no key, or the key is empty, it is an error
1611cdf0e10cSrcweir         if ( !aResult.getLength() )
1612cdf0e10cSrcweir             throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "No expected key is provided!" ) ), uno::Reference< uno::XInterface >() );
1613cdf0e10cSrcweir     }
1614cdf0e10cSrcweir     else
1615cdf0e10cSrcweir         aResult = m_aEncryptionKey;
1616cdf0e10cSrcweir 
1617cdf0e10cSrcweir     return aResult;
1618cdf0e10cSrcweir }
1619cdf0e10cSrcweir 
1620cdf0e10cSrcweir //--------------------------------------------------------
hasPendingChanges()1621cdf0e10cSrcweir sal_Bool SAL_CALL ZipPackage::hasPendingChanges()
1622cdf0e10cSrcweir 		throw( RuntimeException )
1623cdf0e10cSrcweir {
1624cdf0e10cSrcweir 	return sal_False;
1625cdf0e10cSrcweir }
1626cdf0e10cSrcweir //--------------------------------------------------------
getPendingChanges()1627cdf0e10cSrcweir Sequence< ElementChange > SAL_CALL ZipPackage::getPendingChanges()
1628cdf0e10cSrcweir 		throw( RuntimeException )
1629cdf0e10cSrcweir {
1630cdf0e10cSrcweir 	return uno::Sequence < ElementChange > ();
1631cdf0e10cSrcweir }
1632cdf0e10cSrcweir 
1633cdf0e10cSrcweir /**
1634cdf0e10cSrcweir  * Function to create a new component instance; is needed by factory helper implementation.
1635cdf0e10cSrcweir  * @param xMgr service manager to if the components needs other component instances
1636cdf0e10cSrcweir  */
ZipPackage_createInstance(const uno::Reference<XMultiServiceFactory> & xMgr)1637cdf0e10cSrcweir uno::Reference < XInterface >SAL_CALL ZipPackage_createInstance(
1638cdf0e10cSrcweir 	const uno::Reference< XMultiServiceFactory > & xMgr )
1639cdf0e10cSrcweir {
1640cdf0e10cSrcweir 	return uno::Reference< XInterface >( *new ZipPackage( xMgr ) );
1641cdf0e10cSrcweir }
1642cdf0e10cSrcweir 
1643cdf0e10cSrcweir //--------------------------------------------------------
static_getImplementationName()1644cdf0e10cSrcweir OUString ZipPackage::static_getImplementationName()
1645cdf0e10cSrcweir {
1646cdf0e10cSrcweir 	return OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.comp.ZipPackage" ) );
1647cdf0e10cSrcweir }
1648cdf0e10cSrcweir 
1649cdf0e10cSrcweir //--------------------------------------------------------
static_getSupportedServiceNames()1650cdf0e10cSrcweir Sequence< OUString > ZipPackage::static_getSupportedServiceNames()
1651cdf0e10cSrcweir {
1652cdf0e10cSrcweir 	uno::Sequence< OUString > aNames( 1 );
1653cdf0e10cSrcweir 	aNames[0] = OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.Package" ) );
1654cdf0e10cSrcweir 	return aNames;
1655cdf0e10cSrcweir }
1656cdf0e10cSrcweir //--------------------------------------------------------
static_supportsService(OUString const & rServiceName)1657cdf0e10cSrcweir sal_Bool SAL_CALL ZipPackage::static_supportsService( OUString const & rServiceName )
1658cdf0e10cSrcweir {
1659cdf0e10cSrcweir 	return rServiceName == getSupportedServiceNames()[0];
1660cdf0e10cSrcweir }
1661cdf0e10cSrcweir 
1662cdf0e10cSrcweir //--------------------------------------------------------
getImplementationName()1663cdf0e10cSrcweir OUString ZipPackage::getImplementationName()
1664cdf0e10cSrcweir 	throw ( RuntimeException )
1665cdf0e10cSrcweir {
1666cdf0e10cSrcweir 	return static_getImplementationName();
1667cdf0e10cSrcweir }
1668cdf0e10cSrcweir 
1669cdf0e10cSrcweir //--------------------------------------------------------
getSupportedServiceNames()1670cdf0e10cSrcweir Sequence< OUString > ZipPackage::getSupportedServiceNames()
1671cdf0e10cSrcweir 	throw ( RuntimeException )
1672cdf0e10cSrcweir {
1673cdf0e10cSrcweir 	return static_getSupportedServiceNames();
1674cdf0e10cSrcweir }
1675cdf0e10cSrcweir //--------------------------------------------------------
supportsService(OUString const & rServiceName)1676cdf0e10cSrcweir sal_Bool SAL_CALL ZipPackage::supportsService( OUString const & rServiceName )
1677cdf0e10cSrcweir 	throw ( RuntimeException )
1678cdf0e10cSrcweir {
1679cdf0e10cSrcweir 	return static_supportsService ( rServiceName );
1680cdf0e10cSrcweir }
1681cdf0e10cSrcweir //--------------------------------------------------------
createServiceFactory(uno::Reference<XMultiServiceFactory> const & rServiceFactory)1682cdf0e10cSrcweir uno::Reference < XSingleServiceFactory > ZipPackage::createServiceFactory( uno::Reference < XMultiServiceFactory > const & rServiceFactory )
1683cdf0e10cSrcweir {
1684cdf0e10cSrcweir 	return cppu::createSingleFactory ( rServiceFactory,
1685cdf0e10cSrcweir 										   static_getImplementationName(),
1686cdf0e10cSrcweir 										   ZipPackage_createInstance,
1687cdf0e10cSrcweir 										   static_getSupportedServiceNames() );
1688cdf0e10cSrcweir }
1689cdf0e10cSrcweir 
1690cdf0e10cSrcweir namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; }
1691cdf0e10cSrcweir 
1692cdf0e10cSrcweir //--------------------------------------------------------
getUnoTunnelImplementationId(void)1693cdf0e10cSrcweir Sequence< sal_Int8 > ZipPackage::getUnoTunnelImplementationId( void )
1694cdf0e10cSrcweir 	throw ( RuntimeException )
1695cdf0e10cSrcweir {
1696cdf0e10cSrcweir     ::cppu::OImplementationId &rId = lcl_ImplId::get();
1697cdf0e10cSrcweir     return rId.getImplementationId();
1698cdf0e10cSrcweir }
1699cdf0e10cSrcweir 
1700cdf0e10cSrcweir //--------------------------------------------------------
getSomething(const uno::Sequence<sal_Int8> & aIdentifier)1701cdf0e10cSrcweir sal_Int64 SAL_CALL ZipPackage::getSomething( const uno::Sequence< sal_Int8 >& aIdentifier )
1702cdf0e10cSrcweir 	throw( RuntimeException )
1703cdf0e10cSrcweir {
1704cdf0e10cSrcweir 	if ( aIdentifier.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelImplementationId().getConstArray(),  aIdentifier.getConstArray(), 16 ) )
1705cdf0e10cSrcweir 		return reinterpret_cast < sal_Int64 > ( this );
1706cdf0e10cSrcweir 	return 0;
1707cdf0e10cSrcweir }
1708cdf0e10cSrcweir 
1709cdf0e10cSrcweir //--------------------------------------------------------
getPropertySetInfo()1710cdf0e10cSrcweir uno::Reference< XPropertySetInfo > SAL_CALL ZipPackage::getPropertySetInfo()
1711cdf0e10cSrcweir 		throw( RuntimeException )
1712cdf0e10cSrcweir {
1713cdf0e10cSrcweir 	return uno::Reference < XPropertySetInfo > ();
1714cdf0e10cSrcweir }
1715cdf0e10cSrcweir 
1716cdf0e10cSrcweir //--------------------------------------------------------
setPropertyValue(const OUString & aPropertyName,const Any & aValue)1717cdf0e10cSrcweir void SAL_CALL ZipPackage::setPropertyValue( const OUString& aPropertyName, const Any& aValue )
1718cdf0e10cSrcweir 		throw( UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException )
1719cdf0e10cSrcweir {
1720cdf0e10cSrcweir 	if ( m_nFormat != embed::StorageFormats::PACKAGE )
1721cdf0e10cSrcweir 		throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1722cdf0e10cSrcweir 
1723cdf0e10cSrcweir 	if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( HAS_ENCRYPTED_ENTRIES_PROPERTY ) )
1724cdf0e10cSrcweir 	  ||aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( HAS_NONENCRYPTED_ENTRIES_PROPERTY ) )
1725cdf0e10cSrcweir 	  ||aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( IS_INCONSISTENT_PROPERTY ) )
1726cdf0e10cSrcweir 	  ||aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( MEDIATYPE_FALLBACK_USED_PROPERTY ) ) )
1727cdf0e10cSrcweir 		throw PropertyVetoException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1728cdf0e10cSrcweir 	else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_KEY_PROPERTY ) ) )
1729cdf0e10cSrcweir 	{
1730cdf0e10cSrcweir 		if ( !( aValue >>= m_aEncryptionKey ) )
1731cdf0e10cSrcweir 			throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 );
1732cdf0e10cSrcweir 
1733cdf0e10cSrcweir         m_aStorageEncryptionKeys.realloc( 0 );
1734cdf0e10cSrcweir 	}
1735cdf0e10cSrcweir 	else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) )
1736cdf0e10cSrcweir 	{
1737cdf0e10cSrcweir         // this property is only necessary to support raw passwords in storage API;
1738cdf0e10cSrcweir         // because of this support the storage has to operate with more than one key dependent on storage generation algorithm;
1739cdf0e10cSrcweir         // when this support is removed, the storage will get only one key from outside
1740cdf0e10cSrcweir         // TODO/LATER: Get rid of this property as well as of support of raw passwords in storages
1741cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aKeys;
1742cdf0e10cSrcweir 		if ( !( aValue >>= aKeys ) || ( aKeys.getLength() && aKeys.getLength() < 2 ) )
1743cdf0e10cSrcweir 			throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 2 );
1744cdf0e10cSrcweir 
1745cdf0e10cSrcweir         if ( aKeys.getLength() )
1746cdf0e10cSrcweir         {
1747cdf0e10cSrcweir             bool bHasSHA256 = false;
1748cdf0e10cSrcweir             bool bHasSHA1 = false;
1749cdf0e10cSrcweir             for ( sal_Int32 nInd = 0; nInd < aKeys.getLength(); nInd++ )
1750cdf0e10cSrcweir             {
1751cdf0e10cSrcweir                 if ( aKeys[nInd].Name.equals( PACKAGE_ENCRYPTIONDATA_SHA256UTF8 ) )
1752cdf0e10cSrcweir                     bHasSHA256 = true;
1753cdf0e10cSrcweir                 if ( aKeys[nInd].Name.equals( PACKAGE_ENCRYPTIONDATA_SHA1UTF8 ) )
1754cdf0e10cSrcweir                     bHasSHA1 = true;
1755cdf0e10cSrcweir             }
1756cdf0e10cSrcweir 
1757cdf0e10cSrcweir             if ( !bHasSHA256 || !bHasSHA1 )
1758cdf0e10cSrcweir                 throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Expected keys are not provided!" ) ), uno::Reference< uno::XInterface >(), 2 );
1759cdf0e10cSrcweir         }
1760cdf0e10cSrcweir 
1761cdf0e10cSrcweir         m_aStorageEncryptionKeys = aKeys;
1762cdf0e10cSrcweir         m_aEncryptionKey.realloc( 0 );
1763cdf0e10cSrcweir 	}
1764cdf0e10cSrcweir 	else if ( aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ) )
1765cdf0e10cSrcweir 	{
1766cdf0e10cSrcweir         uno::Sequence< beans::NamedValue > aAlgorithms;
1767cdf0e10cSrcweir 		if ( m_pZipFile || !( aValue >>= aAlgorithms ) || aAlgorithms.getLength() == 0 )
1768cdf0e10cSrcweir         {
1769cdf0e10cSrcweir             // the algorithms can not be changed if the file has a persistence based on the algorithms ( m_pZipFile )
1770cdf0e10cSrcweir 			throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "unexpected algorithms list is provided." ) ), uno::Reference< uno::XInterface >(), 2 );
1771cdf0e10cSrcweir         }
1772cdf0e10cSrcweir 
1773cdf0e10cSrcweir         for ( sal_Int32 nInd = 0; nInd < aAlgorithms.getLength(); nInd++ )
1774cdf0e10cSrcweir         {
1775cdf0e10cSrcweir             if ( aAlgorithms[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "StartKeyGenerationAlgorithm" ) ) )
1776cdf0e10cSrcweir             {
1777cdf0e10cSrcweir                 sal_Int32 nID = 0;
1778cdf0e10cSrcweir                 if ( !( aAlgorithms[nInd].Value >>= nID )
1779cdf0e10cSrcweir                   || ( nID != xml::crypto::DigestID::SHA256 && nID != xml::crypto::DigestID::SHA1 ) )
1780cdf0e10cSrcweir                     throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected start key generation algorithm is provided!" ) ), uno::Reference< uno::XInterface >(), 2 );
1781cdf0e10cSrcweir 
1782cdf0e10cSrcweir                 m_nStartKeyGenerationID = nID;
1783cdf0e10cSrcweir             }
1784cdf0e10cSrcweir             else if ( aAlgorithms[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "EncryptionAlgorithm" ) ) )
1785cdf0e10cSrcweir             {
1786cdf0e10cSrcweir                 sal_Int32 nID = 0;
1787cdf0e10cSrcweir                 if ( !( aAlgorithms[nInd].Value >>= nID )
1788cdf0e10cSrcweir                   || ( nID != xml::crypto::CipherID::AES_CBC_W3C_PADDING && nID != xml::crypto::CipherID::BLOWFISH_CFB_8 ) )
1789cdf0e10cSrcweir                     throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected start key generation algorithm is provided!" ) ), uno::Reference< uno::XInterface >(), 2 );
1790cdf0e10cSrcweir 
1791cdf0e10cSrcweir                 m_nCommonEncryptionID = nID;
1792cdf0e10cSrcweir             }
1793cdf0e10cSrcweir             else if ( aAlgorithms[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ChecksumAlgorithm" ) ) )
1794cdf0e10cSrcweir             {
1795cdf0e10cSrcweir                 sal_Int32 nID = 0;
1796cdf0e10cSrcweir                 if ( !( aAlgorithms[nInd].Value >>= nID )
1797cdf0e10cSrcweir                   || ( nID != xml::crypto::DigestID::SHA1_1K && nID != xml::crypto::DigestID::SHA256_1K ) )
1798cdf0e10cSrcweir                     throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Unexpected start key generation algorithm is provided!" ) ), uno::Reference< uno::XInterface >(), 2 );
1799cdf0e10cSrcweir 
1800cdf0e10cSrcweir                 m_nChecksumDigestID = nID;
1801cdf0e10cSrcweir             }
1802cdf0e10cSrcweir             else
1803cdf0e10cSrcweir             {
1804cdf0e10cSrcweir                 OSL_ENSURE( sal_False, "Unexpected encryption algorithm is provided!" );
1805cdf0e10cSrcweir                 throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "unexpected algorithms list is provided." ) ), uno::Reference< uno::XInterface >(), 2 );
1806cdf0e10cSrcweir             }
1807cdf0e10cSrcweir         }
1808cdf0e10cSrcweir 	}
1809cdf0e10cSrcweir 	else
1810cdf0e10cSrcweir 		throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1811cdf0e10cSrcweir }
1812cdf0e10cSrcweir 
1813cdf0e10cSrcweir //--------------------------------------------------------
getPropertyValue(const OUString & PropertyName)1814cdf0e10cSrcweir Any SAL_CALL ZipPackage::getPropertyValue( const OUString& PropertyName )
1815cdf0e10cSrcweir 		throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
1816cdf0e10cSrcweir {
1817cdf0e10cSrcweir 	// TODO/LATER: Activate the check when zip-ucp is ready
1818cdf0e10cSrcweir 	// if ( m_nFormat != embed::StorageFormats::PACKAGE )
1819cdf0e10cSrcweir 	//	throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1820cdf0e10cSrcweir 
1821cdf0e10cSrcweir 	Any aAny;
1822cdf0e10cSrcweir 	if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( ENCRYPTION_KEY_PROPERTY ) ) )
1823cdf0e10cSrcweir 	{
1824cdf0e10cSrcweir 		aAny <<= m_aEncryptionKey;
1825cdf0e10cSrcweir 		return aAny;
1826cdf0e10cSrcweir 	}
1827cdf0e10cSrcweir 	else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ENCRYPTION_ALGORITHMS_PROPERTY ) ) )
1828cdf0e10cSrcweir 	{
1829cdf0e10cSrcweir         ::comphelper::SequenceAsHashMap aAlgorithms;
1830cdf0e10cSrcweir         aAlgorithms[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StartKeyGenerationAlgorithm" ) ) ] <<= m_nStartKeyGenerationID;
1831cdf0e10cSrcweir         aAlgorithms[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionAlgorithm" ) ) ] <<= m_nCommonEncryptionID;
1832cdf0e10cSrcweir         aAlgorithms[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ChecksumAlgorithm" ) ) ] <<= m_nChecksumDigestID;
1833cdf0e10cSrcweir         aAny <<= aAlgorithms.getAsConstNamedValueList();
1834cdf0e10cSrcweir         return aAny;
1835cdf0e10cSrcweir     }
1836cdf0e10cSrcweir 	if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( STORAGE_ENCRYPTION_KEYS_PROPERTY ) ) )
1837cdf0e10cSrcweir 	{
1838cdf0e10cSrcweir 		aAny <<= m_aStorageEncryptionKeys;
1839cdf0e10cSrcweir 		return aAny;
1840cdf0e10cSrcweir 	}
1841cdf0e10cSrcweir 	else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( HAS_ENCRYPTED_ENTRIES_PROPERTY ) ) )
1842cdf0e10cSrcweir 	{
1843cdf0e10cSrcweir 		aAny <<= m_bHasEncryptedEntries;
1844cdf0e10cSrcweir 		return aAny;
1845cdf0e10cSrcweir 	}
1846cdf0e10cSrcweir 	else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( HAS_NONENCRYPTED_ENTRIES_PROPERTY ) ) )
1847cdf0e10cSrcweir 	{
1848cdf0e10cSrcweir 		aAny <<= m_bHasNonEncryptedEntries;
1849cdf0e10cSrcweir 		return aAny;
1850cdf0e10cSrcweir 	}
1851cdf0e10cSrcweir 	else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( IS_INCONSISTENT_PROPERTY ) ) )
1852cdf0e10cSrcweir 	{
1853cdf0e10cSrcweir 		aAny <<= m_bInconsistent;
1854cdf0e10cSrcweir 		return aAny;
1855cdf0e10cSrcweir 	}
1856cdf0e10cSrcweir 	else if ( PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( MEDIATYPE_FALLBACK_USED_PROPERTY ) ) )
1857cdf0e10cSrcweir 	{
1858cdf0e10cSrcweir 		aAny <<= m_bMediaTypeFallbackUsed;
1859cdf0e10cSrcweir 		return aAny;
1860cdf0e10cSrcweir 	}
1861cdf0e10cSrcweir 	throw UnknownPropertyException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
1862cdf0e10cSrcweir }
1863cdf0e10cSrcweir //--------------------------------------------------------
addPropertyChangeListener(const OUString &,const uno::Reference<XPropertyChangeListener> &)1864cdf0e10cSrcweir void SAL_CALL ZipPackage::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*xListener*/ )
1865cdf0e10cSrcweir 		throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
1866cdf0e10cSrcweir {
1867cdf0e10cSrcweir }
1868cdf0e10cSrcweir //--------------------------------------------------------
removePropertyChangeListener(const OUString &,const uno::Reference<XPropertyChangeListener> &)1869cdf0e10cSrcweir void SAL_CALL ZipPackage::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< XPropertyChangeListener >& /*aListener*/ )
1870cdf0e10cSrcweir 		throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
1871cdf0e10cSrcweir {
1872cdf0e10cSrcweir }
1873cdf0e10cSrcweir //--------------------------------------------------------
addVetoableChangeListener(const OUString &,const uno::Reference<XVetoableChangeListener> &)1874cdf0e10cSrcweir void SAL_CALL ZipPackage::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< XVetoableChangeListener >& /*aListener*/ )
1875cdf0e10cSrcweir 		throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
1876cdf0e10cSrcweir {
1877cdf0e10cSrcweir }
1878cdf0e10cSrcweir //--------------------------------------------------------
removeVetoableChangeListener(const OUString &,const uno::Reference<XVetoableChangeListener> &)1879cdf0e10cSrcweir void SAL_CALL ZipPackage::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< XVetoableChangeListener >& /*aListener*/ )
1880cdf0e10cSrcweir 		throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
1881cdf0e10cSrcweir {
1882cdf0e10cSrcweir }
1883