1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_PACKAGE_INC_ZIPPACKAGEFOLDER_HXX
20 #define INCLUDED_PACKAGE_INC_ZIPPACKAGEFOLDER_HXX
22 #include <com/sun/star/container/XNameContainer.hpp>
23 #include <com/sun/star/container/XEnumerationAccess.hpp>
24 #include <com/sun/star/beans/StringPair.hpp>
25 #include <com/sun/star/uno/XComponentContext.hpp>
26 #include "ZipPackageEntry.hxx"
27 #include <cppuhelper/implbase.hxx>
28 #include <rtl/ref.hxx>
30 #include <string_view>
31 #include <unordered_map>
34 class ZipOutputStream
;
36 class ZipPackageFolder
;
37 class ZipPackageStream
;
41 rtl::Reference
< ZipPackageEntry
> xPackageEntry
;
45 ZipPackageFolder
*pFolder
;
46 ZipPackageStream
*pStream
;
48 ZipContentInfo( ZipPackageStream
* pNewStream
);
49 ZipContentInfo( ZipPackageFolder
* pNewFolder
);
50 ZipContentInfo( const ZipContentInfo
& );
51 ZipContentInfo( ZipContentInfo
&& );
52 ZipContentInfo
& operator=( const ZipContentInfo
& );
53 ZipContentInfo
& operator=( ZipContentInfo
&& );
58 typedef std::unordered_map
< OUString
,
59 ZipContentInfo
> ContentHash
;
61 class ZipPackageFolder final
: public cppu::ImplInheritanceHelper
64 css::container::XNameContainer
,
65 css::container::XEnumerationAccess
69 ContentHash maContents
;
74 ZipPackageFolder( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
,
76 bool bAllowRemoveOnInsert
);
77 virtual ~ZipPackageFolder() override
;
79 const OUString
& GetVersion() const { return m_sVersion
; }
80 void SetVersion( const OUString
& aVersion
) { m_sVersion
= aVersion
; }
82 bool LookForUnexpectedODF12Streams(std::u16string_view aPath
, bool isWholesomeEncryption
);
84 void setChildStreamsTypeByExtension( const css::beans::StringPair
& aPair
);
86 /// @throws css::lang::IllegalArgumentException
87 /// @throws css::container::ElementExistException
88 /// @throws css::lang::WrappedTargetException
89 /// @throws css::uno::RuntimeException
90 void doInsertByName ( ZipPackageEntry
*pEntry
, bool bSetParent
);
92 ZipContentInfo
& doGetByName( const OUString
& aName
);
94 void setPackageFormat_Impl( sal_Int32 nFormat
) { m_nFormat
= nFormat
; }
95 void setRemoveOnInsertMode_Impl( bool bRemove
) { mbAllowRemoveOnInsert
= bRemove
; }
97 virtual bool saveChild( const OUString
&rPath
,
98 std::vector
< css::uno::Sequence
< css::beans::PropertyValue
> > &rManList
,
99 ZipOutputStream
& rZipOut
,
100 const css::uno::Sequence
< sal_Int8
>& rEncryptionKey
,
101 ::std::optional
<sal_Int32
> oPBKDF2IterationCount
,
102 ::std::optional
<::std::tuple
<sal_Int32
, sal_Int32
, sal_Int32
>> oArgon2Args
) override
;
104 // Recursive functions
105 /// @throws css::uno::RuntimeException
107 const OUString
&rPath
,
108 std::vector
< css::uno::Sequence
< css::beans::PropertyValue
> > &rManList
,
109 ZipOutputStream
& rZipOut
,
110 const css::uno::Sequence
< sal_Int8
> &rEncryptionKey
,
111 ::std::optional
<sal_Int32
> oPBKDF2IterationCount
,
112 ::std::optional
<::std::tuple
<sal_Int32
, sal_Int32
, sal_Int32
>> oArgon2Args
) const;
115 virtual void SAL_CALL
insertByName( const OUString
& aName
, const css::uno::Any
& aElement
) override
;
116 virtual void SAL_CALL
removeByName( const OUString
& Name
) override
;
118 // XEnumerationAccess
119 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
createEnumeration( ) override
;
122 virtual css::uno::Type SAL_CALL
getElementType( ) override
;
123 virtual sal_Bool SAL_CALL
hasElements( ) override
;
126 virtual css::uno::Any SAL_CALL
getByName( const OUString
& aName
) override
;
127 virtual css::uno::Sequence
< OUString
> SAL_CALL
getElementNames( ) override
;
128 virtual sal_Bool SAL_CALL
hasByName( const OUString
& aName
) override
;
131 virtual void SAL_CALL
replaceByName( const OUString
& aName
, const css::uno::Any
& aElement
) override
;
134 virtual void SAL_CALL
setPropertyValue( const OUString
& aPropertyName
, const css::uno::Any
& aValue
) override
;
135 virtual css::uno::Any SAL_CALL
getPropertyValue( const OUString
& PropertyName
) override
;
138 virtual OUString SAL_CALL
getImplementationName( ) override
;
139 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
140 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */