1*9877b273SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9877b273SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9877b273SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9877b273SAndrew Rist  * distributed with this work for additional information
6*9877b273SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9877b273SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9877b273SAndrew Rist  * "License"); you may not use this file except in compliance
9*9877b273SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9877b273SAndrew Rist  *
11*9877b273SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9877b273SAndrew Rist  *
13*9877b273SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9877b273SAndrew Rist  * software distributed under the License is distributed on an
15*9877b273SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9877b273SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9877b273SAndrew Rist  * specific language governing permissions and limitations
18*9877b273SAndrew Rist  * under the License.
19*9877b273SAndrew Rist  *
20*9877b273SAndrew Rist  *************************************************************/
21*9877b273SAndrew Rist 
22*9877b273SAndrew Rist 
23cdf0e10cSrcweir #ifndef _COMPHELPER_STORAGEHELPER_HXX
24cdf0e10cSrcweir #define _COMPHELPER_STORAGEHELPER_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
27cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx>
28cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
30cdf0e10cSrcweir #include <com/sun/star/embed/XStorage.hpp>
31cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp>
32cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
33cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp>
34cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp>
35cdf0e10cSrcweir #include <com/sun/star/io/XStream.hpp>
36cdf0e10cSrcweir #include "comphelper/comphelperdllapi.h"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #define PACKAGE_STORAGE_FORMAT_STRING	::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageFormat" ) )
40cdf0e10cSrcweir #define ZIP_STORAGE_FORMAT_STRING		::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ZipFormat" ) )
41cdf0e10cSrcweir #define OFOPXML_STORAGE_FORMAT_STRING	::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OFOPXMLFormat" ) )
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #define PACKAGE_ENCRYPTIONDATA_SHA256UTF8 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSHA256UTF8EncryptionKey" ) )
44cdf0e10cSrcweir #define PACKAGE_ENCRYPTIONDATA_SHA1UTF8   ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSHA1UTF8EncryptionKey" ) )
45cdf0e10cSrcweir #define PACKAGE_ENCRYPTIONDATA_SHA1MS1252 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PackageSHA1MS1252EncryptionKey" ) )
46cdf0e10cSrcweir 
47cdf0e10cSrcweir namespace comphelper {
48cdf0e10cSrcweir 
49cdf0e10cSrcweir class COMPHELPER_DLLPUBLIC OStorageHelper
50cdf0e10cSrcweir {
51cdf0e10cSrcweir public:
52cdf0e10cSrcweir 	static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory >
53cdf0e10cSrcweir 		GetStorageFactory(
54cdf0e10cSrcweir 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xSF
55cdf0e10cSrcweir 							= ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() )
56cdf0e10cSrcweir 		throw ( ::com::sun::star::uno::Exception );
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 	static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory >
59cdf0e10cSrcweir 		GetFileSystemStorageFactory(
60cdf0e10cSrcweir 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xSF
61cdf0e10cSrcweir 							= ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() )
62cdf0e10cSrcweir 		throw ( ::com::sun::star::uno::Exception );
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 	static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
65cdf0e10cSrcweir 		GetTemporaryStorage(
66cdf0e10cSrcweir 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory
67cdf0e10cSrcweir 							= ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() )
68cdf0e10cSrcweir 		throw ( ::com::sun::star::uno::Exception );
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     /// this one will only return Storage
71cdf0e10cSrcweir 	static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
72cdf0e10cSrcweir 		GetStorageFromURL(
73cdf0e10cSrcweir 			const ::rtl::OUString& aURL,
74cdf0e10cSrcweir 			sal_Int32 nStorageMode,
75cdf0e10cSrcweir 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory
76cdf0e10cSrcweir 							= ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() )
77cdf0e10cSrcweir 		throw ( ::com::sun::star::uno::Exception );
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     /// this one will return either Storage or FileSystemStorage
80cdf0e10cSrcweir 	static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
81cdf0e10cSrcweir 		GetStorageFromURL2(
82cdf0e10cSrcweir 			const ::rtl::OUString& aURL,
83cdf0e10cSrcweir 			sal_Int32 nStorageMode,
84cdf0e10cSrcweir 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory
85cdf0e10cSrcweir 							= ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() )
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 		throw ( ::com::sun::star::uno::Exception );
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
90cdf0e10cSrcweir         GetStorageFromInputStream(
91cdf0e10cSrcweir             const ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream >& xStream,
92cdf0e10cSrcweir 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory
93cdf0e10cSrcweir 							= ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() )
94cdf0e10cSrcweir 		throw ( ::com::sun::star::uno::Exception );
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 	static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
97cdf0e10cSrcweir         GetStorageFromStream(
98cdf0e10cSrcweir             const ::com::sun::star::uno::Reference < ::com::sun::star::io::XStream >& xStream,
99cdf0e10cSrcweir 			sal_Int32 nStorageMode = ::com::sun::star::embed::ElementModes::READWRITE,
100cdf0e10cSrcweir 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory
101cdf0e10cSrcweir 							= ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() )
102cdf0e10cSrcweir 		throw ( ::com::sun::star::uno::Exception );
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 	static void CopyInputToOutput(
105cdf0e10cSrcweir 			const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& xInput,
106cdf0e10cSrcweir 			const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutput )
107cdf0e10cSrcweir 		throw ( ::com::sun::star::uno::Exception );
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	static ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
110cdf0e10cSrcweir 		GetInputStreamFromURL(
111cdf0e10cSrcweir 			const ::rtl::OUString& aURL,
112cdf0e10cSrcweir 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory
113cdf0e10cSrcweir 							= ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() )
114cdf0e10cSrcweir 		throw ( ::com::sun::star::uno::Exception );
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 	static void SetCommonStorageEncryptionData(
117cdf0e10cSrcweir 			const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage,
118cdf0e10cSrcweir 			const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& aEncryptionData )
119cdf0e10cSrcweir 		throw ( ::com::sun::star::uno::Exception );
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 	// the following method supports only storages of OOo formats
122cdf0e10cSrcweir 	static sal_Int32 GetXStorageFormat(
123cdf0e10cSrcweir 			const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage )
124cdf0e10cSrcweir 		throw ( ::com::sun::star::uno::Exception );
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 	// The followin methods are related to creation of a storage of specified format
127cdf0e10cSrcweir 	static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
128cdf0e10cSrcweir 		GetTemporaryStorageOfFormat(
129cdf0e10cSrcweir 			const ::rtl::OUString& aFormat,
130cdf0e10cSrcweir 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory
131cdf0e10cSrcweir 							= ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() )
132cdf0e10cSrcweir 		throw ( ::com::sun::star::uno::Exception );
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 	static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
135cdf0e10cSrcweir 		GetStorageOfFormatFromURL(
136cdf0e10cSrcweir 			const ::rtl::OUString& aFormat,
137cdf0e10cSrcweir 			const ::rtl::OUString& aURL,
138cdf0e10cSrcweir 			sal_Int32 nStorageMode,
139cdf0e10cSrcweir 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory
140cdf0e10cSrcweir 							= ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >(),
141cdf0e10cSrcweir             sal_Bool bRepairStorage = sal_False )
142cdf0e10cSrcweir 		throw ( ::com::sun::star::uno::Exception );
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 	static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
145cdf0e10cSrcweir         GetStorageOfFormatFromInputStream(
146cdf0e10cSrcweir 			const ::rtl::OUString& aFormat,
147cdf0e10cSrcweir             const ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream >& xStream,
148cdf0e10cSrcweir 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory
149cdf0e10cSrcweir 							= ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >(),
150cdf0e10cSrcweir             sal_Bool bRepairStorage = sal_False )
151cdf0e10cSrcweir 		throw ( ::com::sun::star::uno::Exception );
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 	static ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
154cdf0e10cSrcweir         GetStorageOfFormatFromStream(
155cdf0e10cSrcweir 			const ::rtl::OUString& aFormat,
156cdf0e10cSrcweir             const ::com::sun::star::uno::Reference < ::com::sun::star::io::XStream >& xStream,
157cdf0e10cSrcweir 			sal_Int32 nStorageMode = ::com::sun::star::embed::ElementModes::READWRITE,
158cdf0e10cSrcweir 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory
159cdf0e10cSrcweir 							= ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >(),
160cdf0e10cSrcweir             sal_Bool bRepairStorage = sal_False )
161cdf0e10cSrcweir 		throw ( ::com::sun::star::uno::Exception );
162cdf0e10cSrcweir 
163cdf0e10cSrcweir     static ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >
164cdf0e10cSrcweir         CreatePackageEncryptionData(
165cdf0e10cSrcweir             const ::rtl::OUString& aPassword,
166cdf0e10cSrcweir             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xSF
167cdf0e10cSrcweir                 = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >() );
168cdf0e10cSrcweir 
169cdf0e10cSrcweir     static sal_Bool IsValidZipEntryFileName( const ::rtl::OUString& aName, sal_Bool bSlashAllowed );
170cdf0e10cSrcweir     static sal_Bool IsValidZipEntryFileName( const sal_Unicode *pChar, sal_Int32 nLength, sal_Bool bSlashAllowed );
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     static sal_Bool PathHasSegment( const ::rtl::OUString& aPath, const ::rtl::OUString& aSegment );
173cdf0e10cSrcweir };
174cdf0e10cSrcweir 
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir #endif
178cdf0e10cSrcweir 
179