xref: /AOO41X/main/package/source/zippackage/zipfileaccess.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_package.hxx"
30*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
31*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_LANG_INVALIDARGUMENTEXCEPTION_HPP_
32*cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp>
33*cdf0e10cSrcweir #endif
34*cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandEnvironment.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/io/XStream.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hpp>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include <zipfileaccess.hxx>
40*cdf0e10cSrcweir #include <ZipEnumeration.hxx>
41*cdf0e10cSrcweir #include <ZipPackageSink.hxx>
42*cdf0e10cSrcweir #include <EncryptionData.hxx>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #include <ucbhelper/content.hxx>
45*cdf0e10cSrcweir #include <rtl/ref.hxx>
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #include <memory>
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir using namespace ::com::sun::star;
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir // ----------------------------------------------------------------
53*cdf0e10cSrcweir OZipFileAccess::OZipFileAccess( const uno::Reference< lang::XMultiServiceFactory >& xFactory )
54*cdf0e10cSrcweir : m_aMutexHolder( new SotMutexHolder )
55*cdf0e10cSrcweir , m_xFactory( xFactory )
56*cdf0e10cSrcweir , m_pZipFile( NULL )
57*cdf0e10cSrcweir , m_pListenersContainer( NULL )
58*cdf0e10cSrcweir , m_bDisposed( sal_False )
59*cdf0e10cSrcweir {
60*cdf0e10cSrcweir 	if ( !xFactory.is() )
61*cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
62*cdf0e10cSrcweir }
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir // ----------------------------------------------------------------
65*cdf0e10cSrcweir OZipFileAccess::~OZipFileAccess()
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir 	{
68*cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() );
69*cdf0e10cSrcweir 		if ( !m_bDisposed )
70*cdf0e10cSrcweir 		{
71*cdf0e10cSrcweir 			try {
72*cdf0e10cSrcweir 				m_refCount++; // dispose will use refcounting so the further distruction must be avoided
73*cdf0e10cSrcweir 				dispose();
74*cdf0e10cSrcweir 			} catch( uno::Exception& )
75*cdf0e10cSrcweir 			{}
76*cdf0e10cSrcweir 		}
77*cdf0e10cSrcweir 	}
78*cdf0e10cSrcweir }
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir // ----------------------------------------------------------------
81*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > OZipFileAccess::GetPatternsFromString_Impl( const ::rtl::OUString& aString )
82*cdf0e10cSrcweir {
83*cdf0e10cSrcweir     if ( !aString.getLength() )
84*cdf0e10cSrcweir         return uno::Sequence< ::rtl::OUString >();
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > aPattern( 1 );
87*cdf0e10cSrcweir 	sal_Int32 nInd = 0;
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 	const sal_Unicode* pString = aString.getStr();
90*cdf0e10cSrcweir 	while( *pString )
91*cdf0e10cSrcweir 	{
92*cdf0e10cSrcweir 		if ( *pString == (sal_Unicode)'\\' )
93*cdf0e10cSrcweir 		{
94*cdf0e10cSrcweir 			pString++;
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir 			if ( *pString == (sal_Unicode)'\\' )
97*cdf0e10cSrcweir 			{
98*cdf0e10cSrcweir 				aPattern[nInd] += ::rtl::OUString::valueOf( (sal_Unicode)'\\' );
99*cdf0e10cSrcweir 				pString++;
100*cdf0e10cSrcweir 			}
101*cdf0e10cSrcweir 			else if ( *pString == (sal_Unicode)'*' )
102*cdf0e10cSrcweir 			{
103*cdf0e10cSrcweir 				aPattern[nInd] += ::rtl::OUString::valueOf( (sal_Unicode)'*' );
104*cdf0e10cSrcweir 				pString++;
105*cdf0e10cSrcweir 			}
106*cdf0e10cSrcweir 			else
107*cdf0e10cSrcweir 			{
108*cdf0e10cSrcweir 				OSL_ENSURE( sal_False, "The backslash is not guarded!\n" );
109*cdf0e10cSrcweir 				aPattern[nInd] += ::rtl::OUString::valueOf( (sal_Unicode)'\\' );
110*cdf0e10cSrcweir 			}
111*cdf0e10cSrcweir 		}
112*cdf0e10cSrcweir 		else if ( *pString == (sal_Unicode)'*' )
113*cdf0e10cSrcweir 		{
114*cdf0e10cSrcweir 			aPattern.realloc( ( ++nInd ) + 1 );
115*cdf0e10cSrcweir 			pString++;
116*cdf0e10cSrcweir 		}
117*cdf0e10cSrcweir 		else
118*cdf0e10cSrcweir 		{
119*cdf0e10cSrcweir 			aPattern[nInd] += ::rtl::OUString::valueOf( *pString );
120*cdf0e10cSrcweir 			pString++;
121*cdf0e10cSrcweir 		}
122*cdf0e10cSrcweir 	}
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir     return aPattern;
125*cdf0e10cSrcweir }
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir // ----------------------------------------------------------------
128*cdf0e10cSrcweir sal_Bool OZipFileAccess::StringGoodForPattern_Impl( const ::rtl::OUString& aString,
129*cdf0e10cSrcweir 													const uno::Sequence< ::rtl::OUString >& aPattern )
130*cdf0e10cSrcweir {
131*cdf0e10cSrcweir     sal_Int32 nInd = aPattern.getLength() - 1;
132*cdf0e10cSrcweir     if ( nInd < 0 )
133*cdf0e10cSrcweir         return sal_False;
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir     if ( nInd == 0 )
136*cdf0e10cSrcweir 	{
137*cdf0e10cSrcweir 		if ( !aPattern[0].getLength() )
138*cdf0e10cSrcweir 			return sal_True;
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir         return aString.equals( aPattern[0] );
141*cdf0e10cSrcweir 	}
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir     sal_Int32 nBeginInd = aPattern[0].getLength();
144*cdf0e10cSrcweir     sal_Int32 nEndInd = aString.getLength() - aPattern[nInd].getLength();
145*cdf0e10cSrcweir     if ( nEndInd >= nBeginInd
146*cdf0e10cSrcweir       && ( nEndInd == aString.getLength() || aString.copy( nEndInd ).equals( aPattern[nInd] ) )
147*cdf0e10cSrcweir 	  && ( nBeginInd == 0 || aString.copy( 0, nBeginInd ).equals( aPattern[0] ) ) )
148*cdf0e10cSrcweir     {
149*cdf0e10cSrcweir         for ( sal_Int32 nCurInd = aPattern.getLength() - 2; nCurInd > 0; nCurInd-- )
150*cdf0e10cSrcweir         {
151*cdf0e10cSrcweir 			if ( !aPattern[nCurInd].getLength() )
152*cdf0e10cSrcweir 				continue;
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 			if ( nEndInd == nBeginInd )
155*cdf0e10cSrcweir 				return sal_False;
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir             // check that search does not use nEndInd position
158*cdf0e10cSrcweir             sal_Int32 nLastInd = aString.lastIndexOf( aPattern[nCurInd], nEndInd - 1 );
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir             if ( nLastInd == -1 )
161*cdf0e10cSrcweir                 return sal_False;
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir             if ( nLastInd < nBeginInd )
164*cdf0e10cSrcweir                 return sal_False;
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir             nEndInd = nLastInd;
167*cdf0e10cSrcweir         }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 		return sal_True;
170*cdf0e10cSrcweir     }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir     return sal_False;
173*cdf0e10cSrcweir }
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir // XInitialization
176*cdf0e10cSrcweir // ----------------------------------------------------------------
177*cdf0e10cSrcweir void SAL_CALL OZipFileAccess::initialize( const uno::Sequence< uno::Any >& aArguments )
178*cdf0e10cSrcweir 	throw ( uno::Exception,
179*cdf0e10cSrcweir 			uno::RuntimeException )
180*cdf0e10cSrcweir {
181*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() );
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir 	if ( m_bDisposed )
184*cdf0e10cSrcweir 		throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir 	if ( m_pZipFile )
187*cdf0e10cSrcweir 		throw uno::Exception( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() ); // initialization is allowed only one time
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 	if ( !aArguments.getLength() )
190*cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 );
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir 	OSL_ENSURE( aArguments.getLength() == 1, "Too meny arguments are provided, only the first one will be used!\n" );
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 	::rtl::OUString aParamURL;
195*cdf0e10cSrcweir 	uno::Reference< io::XStream > xStream;
196*cdf0e10cSrcweir 	uno::Reference< io::XSeekable > xSeekable;
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir 	if ( ( aArguments[0] >>= aParamURL ) )
199*cdf0e10cSrcweir 	{
200*cdf0e10cSrcweir 		::ucbhelper::Content aContent ( aParamURL, uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >() );
201*cdf0e10cSrcweir 		uno::Reference < io::XActiveDataSink > xSink = new ZipPackageSink;
202*cdf0e10cSrcweir 		if ( aContent.openStream ( xSink ) )
203*cdf0e10cSrcweir 		{
204*cdf0e10cSrcweir 			m_xContentStream = xSink->getInputStream();
205*cdf0e10cSrcweir 			xSeekable = uno::Reference< io::XSeekable >( m_xContentStream, uno::UNO_QUERY );
206*cdf0e10cSrcweir 		}
207*cdf0e10cSrcweir 	}
208*cdf0e10cSrcweir 	else if ( (aArguments[0] >>= xStream ) )
209*cdf0e10cSrcweir 	{
210*cdf0e10cSrcweir 		// a writable stream can implement both XStream & XInputStream
211*cdf0e10cSrcweir 		m_xContentStream = xStream->getInputStream();
212*cdf0e10cSrcweir 		xSeekable = uno::Reference< io::XSeekable >( xStream, uno::UNO_QUERY );
213*cdf0e10cSrcweir 	}
214*cdf0e10cSrcweir 	else if ( !( aArguments[0] >>= m_xContentStream ) )
215*cdf0e10cSrcweir 	{
216*cdf0e10cSrcweir 		xSeekable = uno::Reference< io::XSeekable >( m_xContentStream, uno::UNO_QUERY );
217*cdf0e10cSrcweir 	}
218*cdf0e10cSrcweir 	else
219*cdf0e10cSrcweir 		throw lang::IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >(), 1 );
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 	if ( !m_xContentStream.is() )
222*cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir 	if ( !xSeekable.is() )
225*cdf0e10cSrcweir 	{
226*cdf0e10cSrcweir 		// TODO: after fwkbugfix02 is integrated a helper class can be used to make the stream seekable
227*cdf0e10cSrcweir 		throw io::IOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
228*cdf0e10cSrcweir 	}
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir 	// TODO: in case xSeekable is implemented on separated XStream implementation a wrapper is required
231*cdf0e10cSrcweir 	m_pZipFile = new ZipFile(
232*cdf0e10cSrcweir 				m_xContentStream,
233*cdf0e10cSrcweir 				m_xFactory,
234*cdf0e10cSrcweir 				sal_True );
235*cdf0e10cSrcweir }
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir // XNameAccess
238*cdf0e10cSrcweir // ----------------------------------------------------------------
239*cdf0e10cSrcweir uno::Any SAL_CALL OZipFileAccess::getByName( const ::rtl::OUString& aName )
240*cdf0e10cSrcweir 	throw ( container::NoSuchElementException,
241*cdf0e10cSrcweir 			lang::WrappedTargetException,
242*cdf0e10cSrcweir 			uno::RuntimeException )
243*cdf0e10cSrcweir {
244*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() );
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir 	if ( m_bDisposed )
247*cdf0e10cSrcweir 		throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir 	if ( !m_pZipFile )
250*cdf0e10cSrcweir 		throw io::NotConnectedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir 	EntryHash::iterator aIter = m_pZipFile->GetEntryHash().find( aName );
253*cdf0e10cSrcweir 	if ( aIter == m_pZipFile->GetEntryHash().end() )
254*cdf0e10cSrcweir 		throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir 	uno::Reference< io::XInputStream > xEntryStream( m_pZipFile->getDataStream( (*aIter).second,
257*cdf0e10cSrcweir                                                                                 ::rtl::Reference< EncryptionData >(),
258*cdf0e10cSrcweir                                                                                 sal_False,
259*cdf0e10cSrcweir                                                                                 m_aMutexHolder ) );
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir 	if ( !xEntryStream.is() )
262*cdf0e10cSrcweir 		throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir 	return uno::makeAny ( xEntryStream );
265*cdf0e10cSrcweir }
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir // ----------------------------------------------------------------
268*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL OZipFileAccess::getElementNames()
269*cdf0e10cSrcweir 	throw ( uno::RuntimeException )
270*cdf0e10cSrcweir {
271*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() );
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir 	if ( m_bDisposed )
274*cdf0e10cSrcweir 		throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir 	if ( !m_pZipFile )
277*cdf0e10cSrcweir 		throw io::NotConnectedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir 	uno::Sequence< ::rtl::OUString > aNames( m_pZipFile->GetEntryHash().size() );
280*cdf0e10cSrcweir 	sal_Int32 nLen = 0;
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir 	for ( EntryHash::iterator aIter = m_pZipFile->GetEntryHash().begin(); aIter != m_pZipFile->GetEntryHash().end(); aIter++ )
283*cdf0e10cSrcweir 	{
284*cdf0e10cSrcweir 		if ( aNames.getLength() < ++nLen )
285*cdf0e10cSrcweir 		{
286*cdf0e10cSrcweir 			OSL_ENSURE( sal_False, "The size must be the same!\n" );
287*cdf0e10cSrcweir 			aNames.realloc( nLen );
288*cdf0e10cSrcweir 		}
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir 		aNames[nLen-1] = (*aIter).second.sPath;
291*cdf0e10cSrcweir 	}
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir 	if ( aNames.getLength() != nLen )
294*cdf0e10cSrcweir 	{
295*cdf0e10cSrcweir 		OSL_ENSURE( sal_False, "The size must be the same!\n" );
296*cdf0e10cSrcweir 		aNames.realloc( nLen );
297*cdf0e10cSrcweir 	}
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir 	return aNames;
300*cdf0e10cSrcweir }
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir // ----------------------------------------------------------------
303*cdf0e10cSrcweir sal_Bool SAL_CALL OZipFileAccess::hasByName( const ::rtl::OUString& aName )
304*cdf0e10cSrcweir 	throw (uno::RuntimeException)
305*cdf0e10cSrcweir {
306*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() );
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir 	if ( m_bDisposed )
309*cdf0e10cSrcweir 		throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir 	if ( !m_pZipFile )
312*cdf0e10cSrcweir 		throw io::NotConnectedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir 	EntryHash::iterator aIter = m_pZipFile->GetEntryHash().find( aName );
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir 	return ( aIter != m_pZipFile->GetEntryHash().end() );
317*cdf0e10cSrcweir }
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir // ----------------------------------------------------------------
320*cdf0e10cSrcweir uno::Type SAL_CALL OZipFileAccess::getElementType()
321*cdf0e10cSrcweir 	throw ( uno::RuntimeException )
322*cdf0e10cSrcweir {
323*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() );
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir 	if ( m_bDisposed )
326*cdf0e10cSrcweir 		throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir 	if ( !m_pZipFile )
329*cdf0e10cSrcweir 		throw io::NotConnectedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir 	return getCppuType( ( const uno::Reference< io::XInputStream >* )NULL );
332*cdf0e10cSrcweir }
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir // ----------------------------------------------------------------
335*cdf0e10cSrcweir sal_Bool SAL_CALL OZipFileAccess::hasElements()
336*cdf0e10cSrcweir 	throw ( uno::RuntimeException )
337*cdf0e10cSrcweir {
338*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() );
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir 	if ( m_bDisposed )
341*cdf0e10cSrcweir 		throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir 	if ( !m_pZipFile )
344*cdf0e10cSrcweir 		throw io::NotConnectedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir 	return ( m_pZipFile->GetEntryHash().size() != 0 );
347*cdf0e10cSrcweir }
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir // XZipFileAccess
350*cdf0e10cSrcweir // ----------------------------------------------------------------
351*cdf0e10cSrcweir uno::Reference< io::XInputStream > SAL_CALL OZipFileAccess::getStreamByPattern( const ::rtl::OUString& aPatternString )
352*cdf0e10cSrcweir 	throw ( container::NoSuchElementException,
353*cdf0e10cSrcweir 			io::IOException,
354*cdf0e10cSrcweir 			uno::RuntimeException )
355*cdf0e10cSrcweir {
356*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() );
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir 	if ( m_bDisposed )
359*cdf0e10cSrcweir 		throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir 	if ( !m_pZipFile )
362*cdf0e10cSrcweir 		throw io::NotConnectedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir     // Code to compare strings by patterns
365*cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > aPattern = GetPatternsFromString_Impl( aPatternString );
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir 	for ( EntryHash::iterator aIter = m_pZipFile->GetEntryHash().begin(); aIter != m_pZipFile->GetEntryHash().end(); aIter++ )
368*cdf0e10cSrcweir 	{
369*cdf0e10cSrcweir 		if ( StringGoodForPattern_Impl( (*aIter).second.sPath, aPattern ) )
370*cdf0e10cSrcweir 		{
371*cdf0e10cSrcweir 			uno::Reference< io::XInputStream > xEntryStream( m_pZipFile->getDataStream( (*aIter).second,
372*cdf0e10cSrcweir                                                                                         ::rtl::Reference< EncryptionData >(),
373*cdf0e10cSrcweir                                                                                         sal_False,
374*cdf0e10cSrcweir                                                                                         m_aMutexHolder ) );
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir 			if ( !xEntryStream.is() )
377*cdf0e10cSrcweir 				throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
378*cdf0e10cSrcweir 			return xEntryStream;
379*cdf0e10cSrcweir 		}
380*cdf0e10cSrcweir 	}
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir 	throw container::NoSuchElementException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
383*cdf0e10cSrcweir }
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir // XComponent
386*cdf0e10cSrcweir // ----------------------------------------------------------------
387*cdf0e10cSrcweir void SAL_CALL OZipFileAccess::dispose()
388*cdf0e10cSrcweir 	throw ( uno::RuntimeException )
389*cdf0e10cSrcweir {
390*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() );
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir 	if ( m_bDisposed )
393*cdf0e10cSrcweir 		throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir 	if ( m_pListenersContainer )
396*cdf0e10cSrcweir 	{
397*cdf0e10cSrcweir    		lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) );
398*cdf0e10cSrcweir 		m_pListenersContainer->disposeAndClear( aSource );
399*cdf0e10cSrcweir 		delete m_pListenersContainer;
400*cdf0e10cSrcweir 		m_pListenersContainer = NULL;
401*cdf0e10cSrcweir 	}
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir 	if ( m_pZipFile )
404*cdf0e10cSrcweir 	{
405*cdf0e10cSrcweir 		delete m_pZipFile;
406*cdf0e10cSrcweir 		m_pZipFile = NULL;
407*cdf0e10cSrcweir 	}
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir 	if ( m_xContentStream.is() )
410*cdf0e10cSrcweir 		try {
411*cdf0e10cSrcweir 			m_xContentStream->closeInput();
412*cdf0e10cSrcweir 		} catch( uno::Exception& )
413*cdf0e10cSrcweir 		{}
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir 	m_bDisposed = sal_True;
416*cdf0e10cSrcweir }
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir // ----------------------------------------------------------------
419*cdf0e10cSrcweir void SAL_CALL OZipFileAccess::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
420*cdf0e10cSrcweir 	throw ( uno::RuntimeException )
421*cdf0e10cSrcweir {
422*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() );
423*cdf0e10cSrcweir 
424*cdf0e10cSrcweir 	if ( m_bDisposed )
425*cdf0e10cSrcweir 		throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir 	if ( !m_pListenersContainer )
428*cdf0e10cSrcweir 		m_pListenersContainer = new ::cppu::OInterfaceContainerHelper( m_aMutexHolder->GetMutex() );
429*cdf0e10cSrcweir 	m_pListenersContainer->addInterface( xListener );
430*cdf0e10cSrcweir }
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir // ----------------------------------------------------------------
433*cdf0e10cSrcweir void SAL_CALL OZipFileAccess::removeEventListener( const uno::Reference< lang::XEventListener >& xListener )
434*cdf0e10cSrcweir 	throw ( uno::RuntimeException )
435*cdf0e10cSrcweir {
436*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() );
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir 	if ( m_bDisposed )
439*cdf0e10cSrcweir 		throw lang::DisposedException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ), uno::Reference< uno::XInterface >() );
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir 	if ( m_pListenersContainer )
442*cdf0e10cSrcweir 		m_pListenersContainer->removeInterface( xListener );
443*cdf0e10cSrcweir }
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir //-------------------------------------------------------------------------
446*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL OZipFileAccess::impl_staticGetSupportedServiceNames()
447*cdf0e10cSrcweir {
448*cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > aRet(2);
449*cdf0e10cSrcweir     aRet[0] = ::rtl::OUString::createFromAscii("com.sun.star.packages.zip.ZipFileAccess");
450*cdf0e10cSrcweir     aRet[1] = ::rtl::OUString::createFromAscii("com.sun.star.comp.packages.zip.ZipFileAccess");
451*cdf0e10cSrcweir     return aRet;
452*cdf0e10cSrcweir }
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir //-------------------------------------------------------------------------
455*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OZipFileAccess::impl_staticGetImplementationName()
456*cdf0e10cSrcweir {
457*cdf0e10cSrcweir     return ::rtl::OUString::createFromAscii("com.sun.star.comp.package.zip.ZipFileAccess");
458*cdf0e10cSrcweir }
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir //-------------------------------------------------------------------------
461*cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL OZipFileAccess::impl_staticCreateSelfInstance(
462*cdf0e10cSrcweir 			const uno::Reference< lang::XMultiServiceFactory >& xServiceManager )
463*cdf0e10cSrcweir {
464*cdf0e10cSrcweir 	return uno::Reference< uno::XInterface >( *new OZipFileAccess( xServiceManager ) );
465*cdf0e10cSrcweir }
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir //-------------------------------------------------------------------------
468*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OZipFileAccess::getImplementationName()
469*cdf0e10cSrcweir 	throw ( uno::RuntimeException )
470*cdf0e10cSrcweir {
471*cdf0e10cSrcweir 	return impl_staticGetImplementationName();
472*cdf0e10cSrcweir }
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir //-------------------------------------------------------------------------
475*cdf0e10cSrcweir sal_Bool SAL_CALL OZipFileAccess::supportsService( const ::rtl::OUString& ServiceName )
476*cdf0e10cSrcweir 	throw ( uno::RuntimeException )
477*cdf0e10cSrcweir {
478*cdf0e10cSrcweir 	uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames();
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir 	for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ )
481*cdf0e10cSrcweir     	if ( ServiceName.compareTo( aSeq[nInd] ) == 0 )
482*cdf0e10cSrcweir         	return sal_True;
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir 	return sal_False;
485*cdf0e10cSrcweir }
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir //-------------------------------------------------------------------------
488*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL OZipFileAccess::getSupportedServiceNames()
489*cdf0e10cSrcweir 	throw ( uno::RuntimeException )
490*cdf0e10cSrcweir {
491*cdf0e10cSrcweir 	return impl_staticGetSupportedServiceNames();
492*cdf0e10cSrcweir }
493*cdf0e10cSrcweir 
494