20#include <com/sun/star/lang/DisposedException.hpp>
21#include <com/sun/star/lang/IllegalArgumentException.hpp>
22#include <com/sun/star/ucb/XCommandEnvironment.hpp>
23#include <com/sun/star/io/NotConnectedException.hpp>
24#include <com/sun/star/io/XActiveDataSink.hpp>
25#include <com/sun/star/io/XStream.hpp>
26#include <com/sun/star/io/XSeekable.hpp>
27#include <com/sun/star/beans/NamedValue.hpp>
38#include <osl/diagnose.h>
42#if OSL_DEBUG_LEVEL > 0
43#define THROW_WHERE SAL_WHERE
49: m_aMutexHolder( new
comphelper::RefCountedMutex )
52, m_bOwnContent( false )
54 if ( !rxContext.is() )
67 }
catch( uno::Exception& )
74 if ( aString.isEmpty() )
75 return uno::Sequence< OUString >();
77 uno::Sequence< OUString > aPattern( 1 );
78 auto pPattern = aPattern.getArray();
84 if ( *pString ==
'\\' )
88 if ( *pString ==
'\\' )
90 pPattern[nInd] +=
"\\";
93 else if ( *pString ==
'*' )
95 pPattern[nInd] +=
"*";
100 OSL_FAIL(
"The backslash is not guarded!" );
101 pPattern[nInd] +=
"\\";
104 else if ( *pString ==
'*' )
106 aPattern.realloc( ( ++nInd ) + 1 );
107 pPattern = aPattern.getArray();
112 pPattern[nInd] += OUStringChar( *pString );
121 const uno::Sequence< OUString >& aPattern )
123 sal_Int32 nInd = aPattern.getLength() - 1;
129 if ( aPattern[0].isEmpty() )
132 return aString == aPattern[0];
135 sal_Int32 nBeginInd = aPattern[0].getLength();
136 sal_Int32 nEndInd = aString.size() - aPattern[nInd].getLength();
137 if ( nEndInd < nBeginInd
138 || ( nEndInd != sal_Int32(aString.size()) && aString.substr( nEndInd ) != aPattern[nInd] )
139 || ( nBeginInd != 0 && aString.substr( 0, nBeginInd ) != aPattern[0] ) )
142 for ( sal_Int32 nCurInd = aPattern.getLength() - 2; nCurInd > 0; nCurInd-- )
144 if ( aPattern[nCurInd].isEmpty() )
147 if ( nEndInd == nBeginInd )
151 size_t nLastInd = aString.substr(0, nEndInd - 1).rfind( aPattern[nCurInd] );
153 if ( nLastInd == std::u16string_view::npos )
156 if ( sal_Int32(nLastInd) < nBeginInd )
177 throw lang::IllegalArgumentException(
THROW_WHERE, uno::Reference< uno::XInterface >(), 1 );
179 OSL_ENSURE(
aArguments.getLength() == 1,
"Too many arguments are provided, only the first one will be used!" );
182 uno::Reference< io::XStream >
xStream;
183 uno::Reference< io::XSeekable > xSeekable;
184 uno::Sequence<beans::NamedValue> aArgs;
186 auto openInputStream = [&]()
190 uno::Reference< css::ucb::XCommandEnvironment >(),
209 xSeekable.set(
xStream, uno::UNO_QUERY );
217 for (
const beans::NamedValue& rArg : std::as_const(aArgs))
219 if (rArg.Name ==
"URL")
220 rArg.Value >>= aParamURL;
223 if (aParamURL.isEmpty())
224 throw lang::IllegalArgumentException(
225 THROW_WHERE"required argument 'URL' is not given or invalid.",
226 uno::Reference<uno::XInterface>(), 1);
231 throw lang::IllegalArgumentException(
THROW_WHERE, uno::Reference< uno::XInterface >(), 1 );
236 if ( !xSeekable.is() )
262 if ( aIter ==
m_pZipFile->GetEntryHash().end() )
263 throw container::NoSuchElementException(
THROW_WHERE );
265 uno::Reference< io::XInputStream > xEntryStream;
268 xEntryStream =
m_pZipFile->getDataStream((*aIter).second,
273 catch (
const container::NoSuchElementException&)
277 catch (
const lang::WrappedTargetException&)
281 catch (
const uno::RuntimeException&)
285 catch (
const uno::Exception&)
288 throw lang::WrappedTargetException(
"This package is unusable!",
292 if ( !xEntryStream.is() )
308 uno::Sequence< OUString > aNames(
m_pZipFile->GetEntryHash().size() );
309 auto pNames = aNames.getArray();
312 for (
const auto& rEntry :
m_pZipFile->GetEntryHash() )
314 if ( aNames.getLength() < ++nLen )
316 OSL_FAIL(
"The size must be the same!" );
317 aNames.realloc( nLen );
318 pNames = aNames.getArray();
321 pNames[nLen-1] = rEntry.second.sPath;
324 if ( aNames.getLength() != nLen )
326 OSL_FAIL(
"The size must be the same!" );
327 aNames.realloc( nLen );
345 return ( aIter !=
m_pZipFile->GetEntryHash().end() );
371 return ( !
m_pZipFile->GetEntryHash().empty() );
389 [&aPattern](
const EntryHash::value_type& rEntry) { return StringGoodForPattern_Impl(rEntry.second.sPath, aPattern); });
390 if (aIter !=
m_pZipFile->GetEntryHash().end())
392 uno::Reference< io::XInputStream > xEntryStream(
m_pZipFile->getDataStream( (*aIter).second,
397 if ( !xEntryStream.is() )
402 throw container::NoSuchElementException(
THROW_WHERE );
415 lang::EventObject aSource( getXWeak() );
425 }
catch( uno::Exception& )
456 return "com.sun.star.comp.package.zip.ZipFileAccess";
466 return {
"com.sun.star.packages.zip.ZipFileAccess",
467 "com.sun.star.comp.packages.zip.ZipFileAccess" };
471extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
473 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any>
const&)
Reference< XComponentContext > m_xContext
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getStreamByPattern(const OUString &aPattern) override
OZipFileAccess(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
virtual ~OZipFileAccess() override
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual css::uno::Type SAL_CALL getElementType() override
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
virtual OUString SAL_CALL getImplementationName() override
static bool StringGoodForPattern_Impl(std::u16string_view, const css::uno::Sequence< OUString > &aPattern)
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
std::unique_ptr<::comphelper::OInterfaceContainerHelper3< css::lang::XEventListener > > m_pListenersContainer
static css::uno::Sequence< OUString > GetPatternsFromString_Impl(const OUString &aString)
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
std::optional< ZipFile > m_pZipFile
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
css::uno::Reference< css::io::XInputStream > m_xContentStream
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Bool SAL_CALL hasElements() override
rtl::Reference< comphelper::RefCountedMutex > m_aMutexHolder
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
virtual void SAL_CALL dispose() override
css::uno::Type const & get()
css::uno::Reference< css::io::XInputStream > openStream()
Sequence< PropertyValue > aArguments
tools::SvRef< SvBaseLink > xSink
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Any SAL_CALL getCaughtException()
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * package_OZipFileAccess_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)