25#include <com/sun/star/io/IOException.hpp>
26#include <com/sun/star/packages/zip/ZipConstants.hpp>
27#include <com/sun/star/packages/zip/ZipException.hpp>
28#include <com/sun/star/embed/StorageFormats.hpp>
33#include <com/sun/star/beans/PropertyValue.hpp>
36using namespace com::sun::star::packages::zip::ZipConstants;
37using namespace com::sun::star::packages::zip;
45#if OSL_DEBUG_LEVEL > 0
46#define THROW_WHERE SAL_WHERE
53 bool bAllowRemoveOnInsert )
57 mbAllowRemoveOnInsert = bAllowRemoveOnInsert;
61 aEntry.nMethod = STORED;
64 aEntry.nCompressedSize = 0;
75 bool bHasUnexpected =
false;
77 for (
const auto& [rShortName, rInfo] :
maContents)
81 if ( aPath ==
u"META-INF/" )
84 bHasUnexpected =
true;
88 OUString sOwnPath = aPath + rShortName +
"/";
89 bHasUnexpected = rInfo.pFolder->LookForUnexpectedODF12Streams( sOwnPath );
94 if ( aPath ==
u"META-INF/" )
96 if ( rShortName !=
"manifest.xml"
97 && rShortName.indexOf(
"signatures" ) == -1 )
100 bHasUnexpected =
true;
105 else if ( !rInfo.pStream->IsFromManifest() )
109 if ( !aPath.empty() || rShortName !=
"mimetype" )
112 bHasUnexpected =
true;
121 return bHasUnexpected;
127 if ( aPair.First.toChar() ==
'.' )
130 aExt =
"." + aPair.First;
132 for (
const auto& [rShortName, rInfo] :
maContents)
135 rInfo.pFolder->setChildStreamsTypeByExtension( aPair );
138 sal_Int32 nPathLength = rShortName.getLength();
139 sal_Int32 nExtLength = aExt.getLength();
140 if ( nPathLength >= nExtLength && rShortName.match( aExt, nPathLength - nExtLength ) )
141 rInfo.pStream->SetMediaType( aPair.Second );
152 uno::Reference < XInterface > xRef;
154 if ( !(aElement >>= xRef) )
155 throw IllegalArgumentException(
THROW_WHERE, uno::Reference< uno::XInterface >(), 0 );
161 throw IllegalArgumentException(
THROW_WHERE, uno::Reference< uno::XInterface >(), 0 );
195 return aIter->second;
221 const OUString &rPath,
222 std::vector < uno::Sequence < PropertyValue > > &rManList,
224 const uno::Sequence < sal_Int8 >& rEncryptionKey,
225 sal_Int32 nPBKDF2IterationCount,
229 OUString sTempName = rPath +
"/";
231 if ( !GetMediaType().isEmpty() )
233 auto pPropSet = aPropSet.getArray();
242 aPropSet.realloc( 0 );
244 saveContents( sTempName, rManList, rZipOut, rEncryptionKey, nPBKDF2IterationCount, rRandomPool);
247 if ( aPropSet.hasElements() && (
m_nFormat == embed::StorageFormats::PACKAGE ) )
248 rManList.push_back( aPropSet );
254 const OUString &rPath,
255 std::vector < uno::Sequence < PropertyValue > > &rManList,
257 const uno::Sequence < sal_Int8 >& rEncryptionKey,
258 sal_Int32 nPBKDF2IterationCount,
261 if (
maContents.empty() && !rPath.isEmpty() &&
m_nFormat != embed::StorageFormats::OFOPXML )
267 pTempEntry->
sPath = rPath;
285 bool bMimeTypeStreamStored =
false;
286 OUString aMimeTypeStreamName(
"mimetype");
287 if (
m_nFormat == embed::StorageFormats::ZIP && rPath.isEmpty() )
290 ContentHash::const_iterator aIter =
maContents.find ( aMimeTypeStreamName );
291 if ( aIter !=
maContents.end() && !(*aIter).second.bFolder )
293 bMimeTypeStreamStored =
true;
294 if( !aIter->second.pStream->saveChild(
295 rPath + aIter->first, rManList, rZipOut, rEncryptionKey, nPBKDF2IterationCount, rRandomPool ))
302 for (
const auto& [rShortName, rInfo] :
maContents)
304 if ( !bMimeTypeStreamStored || rShortName != aMimeTypeStreamName )
308 if( !rInfo.pFolder->saveChild(
309 rPath + rShortName, rManList, rZipOut, rEncryptionKey, nPBKDF2IterationCount, rRandomPool ))
316 if( !rInfo.pStream->saveChild(
317 rPath + rShortName, rManList, rZipOut, rEncryptionKey, nPBKDF2IterationCount, rRandomPool ))
328 if ( aPropertyName ==
"MediaType" )
334 aValue >>= msMediaType;
336 else if ( aPropertyName ==
"Version" )
338 else if ( aPropertyName ==
"Size" )
339 aValue >>= aEntry.nSize;
341 throw UnknownPropertyException(aPropertyName);
345 if ( PropertyName ==
"MediaType" )
353 else if ( PropertyName ==
"Version" )
355 else if ( PropertyName ==
"Size" )
358 throw UnknownPropertyException(PropertyName);
373 return "ZipPackageFolder";
378 return {
"com.sun.star.packages.PackageFolder" };
388: xPackageEntry ( pNewStream )
390, pStream ( pNewStream )
395: xPackageEntry ( pNewFolder )
397, pFolder ( pNewFolder )
Reference< XComponentContext > m_xContext
#define PKG_SIZE_NOENCR_MNFST
#define PKG_MNFST_MEDIATYPE
#define PKG_MNFST_VERSION
#define PKG_MNFST_FULLPATH
void writeLOC(ZipEntry *pEntry, bool bEncrypt=false)
void rawCloseEntry(bool bEncrypt=false)
static void setEntry(ZipEntry *pEntry)
virtual OUString SAL_CALL getName() override
virtual void SAL_CALL setParent(const css::uno::Reference< css::uno::XInterface > &Parent) override
virtual void SAL_CALL setName(const OUString &aName) override
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
void setChildStreamsTypeByExtension(const css::beans::StringPair &aPair)
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
virtual void SAL_CALL insertByName(const OUString &aName, const css::uno::Any &aElement) override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
virtual void SAL_CALL replaceByName(const OUString &aName, const css::uno::Any &aElement) override
void doInsertByName(ZipPackageEntry *pEntry, bool bSetParent)
virtual void SAL_CALL removeByName(const OUString &Name) override
virtual ~ZipPackageFolder() override
virtual OUString SAL_CALL getImplementationName() override
virtual bool saveChild(const OUString &rPath, std::vector< css::uno::Sequence< css::beans::PropertyValue > > &rManList, ZipOutputStream &rZipOut, const css::uno::Sequence< sal_Int8 > &rEncryptionKey, sal_Int32 nPBKDF2IterationCount, const rtlRandomPool &rRandomPool) override
ZipContentInfo & doGetByName(const OUString &aName)
void saveContents(const OUString &rPath, std::vector< css::uno::Sequence< css::beans::PropertyValue > > &rManList, ZipOutputStream &rZipOut, const css::uno::Sequence< sal_Int8 > &rEncryptionKey, sal_Int32 nPBKDF2IterationCount, const rtlRandomPool &rRandomPool) const
bool LookForUnexpectedODF12Streams(std::u16string_view aPath)
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Type SAL_CALL getElementType() override
ZipPackageFolder(const css::uno::Reference< css::uno::XComponentContext > &xContext, sal_Int32 nFormat, bool bAllowRemoveOnInsert)
const OUString & GetVersion() const
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Bool SAL_CALL hasElements() override
css::uno::Type const & get()
css::uno::Sequence< typename M::key_type > mapKeysToSequence(M const &map)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
sal_uInt16 const m_nFormat
ZipPackageFolder * pFolder
ZipContentInfo & operator=(const ZipContentInfo &)
ZipContentInfo(ZipPackageStream *pNewStream)
ZipPackageStream * pStream