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