1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _ZIP_PACKAGE_FOLDER_HXX
24 #define _ZIP_PACKAGE_FOLDER_HXX
25 
26 #include <com/sun/star/container/XNameContainer.hpp>
27 #include <com/sun/star/container/XEnumerationAccess.hpp>
28 #include <com/sun/star/beans/StringPair.hpp>
29 #include <HashMaps.hxx>
30 #include <vector>
31 #include <ZipPackageEntry.hxx>
32 #include <cppuhelper/implbase2.hxx>
33 
34 namespace com { namespace sun { namespace star {
35 namespace beans
36 {
37 	struct PropertyValue;
38 }
39 namespace packages
40 {
41     class ContentInfo;
42 }
43 } } }
44 
45 class ZipFile;
46 class ZipPackage;
47 class ZipOutputStream;
48 struct ZipEntry;
49 typedef void* rtlRandomPool;
50 
51 class ZipPackageFolder : public cppu::ImplInheritanceHelper2
52 <
53 	ZipPackageEntry,
54 	::com::sun::star::container::XNameContainer,
55 	::com::sun::star::container::XEnumerationAccess
56 >
57 {
58 protected:
59 	ContentHash maContents;
60 	const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > m_xFactory;
61 	sal_Int32 m_nFormat;
62 	::rtl::OUString m_sVersion;
63 
64 public:
65 
66 	ZipPackageFolder( const ::com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory >& xFactory,
67 					  sal_Int32 nFormat,
68 					  sal_Bool bAllowRemoveOnInsert );
69 	virtual ~ZipPackageFolder();
70 
GetVersion()71     ::rtl::OUString& GetVersion() { return m_sVersion; }
SetVersion(const::rtl::OUString & aVersion)72     void SetVersion( const ::rtl::OUString& aVersion ) { m_sVersion = aVersion; }
73 
74     sal_Bool LookForUnexpectedODF12Streams( const ::rtl::OUString& aPath );
75 
76 	void setChildStreamsTypeByExtension( const ::com::sun::star::beans::StringPair& aPair );
77 
78 	void doInsertByName ( ZipPackageEntry *pEntry, sal_Bool bSetParent )
79 		throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
80 
81 	com::sun::star::packages::ContentInfo & doGetByName( const ::rtl::OUString& aName )
82 		throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
83 
84 	static void copyZipEntry( ZipEntry &rDest, const ZipEntry &rSource);
85 	static const ::com::sun::star::uno::Sequence < sal_Int8 >& static_getImplementationId();
86 
setPackageFormat_Impl(sal_Int32 nFormat)87 	void setPackageFormat_Impl( sal_Int32 nFormat ) { m_nFormat = nFormat; }
setRemoveOnInsertMode_Impl(sal_Bool bRemove)88 	void setRemoveOnInsertMode_Impl( sal_Bool bRemove ) { this->mbAllowRemoveOnInsert = bRemove; }
89 
90 	bool saveChild(const rtl::OUString &rShortName, const com::sun::star::packages::ContentInfo &rInfo, rtl::OUString &rPath, std::vector < com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > > &rManList, ZipOutputStream & rZipOut, const com::sun::star::uno::Sequence < sal_Int8 >& rEncryptionKey, rtlRandomPool & rRandomPool);
91 
92 	// Recursive functions
93 	void  saveContents(rtl::OUString &rPath, std::vector < com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > > &rManList, ZipOutputStream & rZipOut, const com::sun::star::uno::Sequence< sal_Int8 > &rEncryptionKey, rtlRandomPool & rRandomPool)
94 		throw(::com::sun::star::uno::RuntimeException);
95 	void  releaseUpwardRef();
96 
97 	// XNameContainer
98     virtual void SAL_CALL insertByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement )
99 		throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::ElementExistException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
100     virtual void SAL_CALL removeByName( const ::rtl::OUString& Name )
101 		throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
102 
103 	// XEnumerationAccess
104     virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL createEnumeration(  )
105 		throw(::com::sun::star::uno::RuntimeException);
106 
107 	// XElementAccess
108     virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  )
109 		throw(::com::sun::star::uno::RuntimeException);
110     virtual sal_Bool SAL_CALL hasElements(  )
111 		throw(::com::sun::star::uno::RuntimeException);
112 
113 	// XNameAccess
114     virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName )
115 		throw(::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
116     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(  )
117 		throw(::com::sun::star::uno::RuntimeException);
118     virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName )
119 		throw(::com::sun::star::uno::RuntimeException);
120 
121 	// XNameReplace
122     virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement )
123 		throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
124 
125 	// XPropertySet
126     virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue )
127 		throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
128     virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName )
129 		throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
130 
131 	// XUnoTunnel
132     virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier )
133 		throw(::com::sun::star::uno::RuntimeException);
134 
135 	// XServiceInfo
136     virtual ::rtl::OUString SAL_CALL getImplementationName(  )
137 		throw (::com::sun::star::uno::RuntimeException);
138     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
139 		throw (::com::sun::star::uno::RuntimeException);
140     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  )
141 		throw (::com::sun::star::uno::RuntimeException);
142 };
143 #endif
144