nss: upgrade to release 3.73
[LibreOffice.git] / include / comphelper / storagehelper.hxx
bloba4bd3605c2962976f8f51e613c2ee22bcb1e5e44
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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_COMPHELPER_STORAGEHELPER_HXX
20 #define INCLUDED_COMPHELPER_STORAGEHELPER_HXX
22 #include <com/sun/star/uno/Sequence.h>
23 #include <com/sun/star/uno/Reference.hxx>
24 #include <com/sun/star/embed/ElementModes.hpp>
25 #include <comphelper/comphelperdllapi.h>
26 #include <memory>
28 #define PACKAGE_STORAGE_FORMAT_STRING "PackageFormat"
29 #define ZIP_STORAGE_FORMAT_STRING "ZipFormat"
30 #define OFOPXML_STORAGE_FORMAT_STRING "OFOPXMLFormat"
32 #define PACKAGE_ENCRYPTIONDATA_SHA256UTF8 "PackageSHA256UTF8EncryptionKey"
33 #define PACKAGE_ENCRYPTIONDATA_SHA1UTF8 "PackageSHA1UTF8EncryptionKey"
34 #define PACKAGE_ENCRYPTIONDATA_SHA1MS1252 "PackageSHA1MS1252EncryptionKey"
35 #define PACKAGE_ENCRYPTIONDATA_SHA1CORRECT "PackageSHA1CorrectEncryptionKey"
37 namespace com::sun::star {
38 namespace beans { struct NamedValue; }
39 namespace embed { class XStorage; }
40 namespace io {
41 class XInputStream;
42 class XOutputStream;
43 class XStream;
45 namespace lang { class XSingleServiceFactory; }
46 namespace uno { class XComponentContext; }
49 namespace comphelper {
51 // Unfortunately - the impl.s of XStorage like to invalidate all
52 // their sub streams and storages when you release references, so
53 // it is necessary to keep references to all storages down the
54 // path - this is 'beautiful' (TM). So we need this ugly hack:
55 class COMPHELPER_DLLPUBLIC LifecycleProxy
57 private:
58 class Impl;
59 public:
60 std::unique_ptr<Impl> m_xBadness;
61 LifecycleProxy();
62 ~LifecycleProxy();
63 // commit the storages: necessary for writes to streams to take effect!
64 void commitStorages();
67 class COMPHELPER_DLLPUBLIC OStorageHelper
69 public:
70 /// @throws css::uno::Exception
71 static css::uno::Reference< css::lang::XSingleServiceFactory >
72 GetStorageFactory(
73 const css::uno::Reference< css::uno::XComponentContext >& rxContext
74 = css::uno::Reference< css::uno::XComponentContext >() );
76 /// @throws css::uno::Exception
77 static css::uno::Reference< css::lang::XSingleServiceFactory >
78 GetFileSystemStorageFactory(
79 const css::uno::Reference< css::uno::XComponentContext >& rxContext
80 = css::uno::Reference< css::uno::XComponentContext >() );
82 /// @throws css::uno::Exception
83 static css::uno::Reference< css::embed::XStorage >
84 GetTemporaryStorage(
85 const css::uno::Reference< css::uno::XComponentContext >& rxContext
86 = css::uno::Reference< css::uno::XComponentContext >() );
88 /// this one will only return Storage
89 ///
90 /// @throws css::uno::Exception
91 static css::uno::Reference< css::embed::XStorage >
92 GetStorageFromURL(
93 const OUString& aURL,
94 sal_Int32 nStorageMode,
95 const css::uno::Reference< css::uno::XComponentContext >& rxContext
96 = css::uno::Reference< css::uno::XComponentContext >() );
98 /// this one will return either Storage or FileSystemStorage
99 ///
100 /// @throws css::uno::Exception
101 static css::uno::Reference< css::embed::XStorage >
102 GetStorageFromURL2(
103 const OUString& aURL,
104 sal_Int32 nStorageMode,
105 const css::uno::Reference< css::uno::XComponentContext >& rxContext
106 = css::uno::Reference< css::uno::XComponentContext >() );
108 /// @throws css::uno::Exception
109 static css::uno::Reference< css::embed::XStorage >
110 GetStorageFromInputStream(
111 const css::uno::Reference < css::io::XInputStream >& xStream,
112 const css::uno::Reference< css::uno::XComponentContext >& rxContext
113 = css::uno::Reference< css::uno::XComponentContext >() );
115 /// @throws css::uno::Exception
116 static css::uno::Reference< css::embed::XStorage >
117 GetStorageFromStream(
118 const css::uno::Reference < css::io::XStream >& xStream,
119 sal_Int32 nStorageMode = css::embed::ElementModes::READWRITE,
120 const css::uno::Reference< css::uno::XComponentContext >& rxContext
121 = css::uno::Reference< css::uno::XComponentContext >() );
123 /// @throws css::uno::Exception
124 static void CopyInputToOutput(
125 const css::uno::Reference< css::io::XInputStream >& xInput,
126 const css::uno::Reference< css::io::XOutputStream >& xOutput );
128 /// @throws css::uno::Exception
129 static css::uno::Reference< css::io::XInputStream >
130 GetInputStreamFromURL(
131 const OUString& aURL,
132 const css::uno::Reference< css::uno::XComponentContext >& context );
134 /// @throws css::uno::Exception
135 static void SetCommonStorageEncryptionData(
136 const css::uno::Reference< css::embed::XStorage >& xStorage,
137 const css::uno::Sequence< css::beans::NamedValue >& aEncryptionData );
139 // the following method supports only storages of OOo formats
140 /// @throws css::uno::Exception
141 static sal_Int32 GetXStorageFormat(
142 const css::uno::Reference< css::embed::XStorage >& xStorage );
144 /// @throws css::uno::Exception
145 static css::uno::Reference< css::embed::XStorage >
146 GetStorageOfFormatFromURL(
147 const OUString& aFormat,
148 const OUString& aURL,
149 sal_Int32 nStorageMode,
150 const css::uno::Reference< css::uno::XComponentContext >& rxContext
151 = css::uno::Reference< css::uno::XComponentContext >() );
153 /// @throws css::uno::Exception
154 static css::uno::Reference< css::embed::XStorage >
155 GetStorageOfFormatFromInputStream(
156 const OUString& aFormat,
157 const css::uno::Reference < css::io::XInputStream >& xStream,
158 const css::uno::Reference< css::uno::XComponentContext >& rxContext
159 = css::uno::Reference< css::uno::XComponentContext >(),
160 bool bRepairStorage = false );
162 /// @throws css::uno::Exception
163 static css::uno::Reference< css::embed::XStorage >
164 GetStorageOfFormatFromStream(
165 const OUString& aFormat,
166 const css::uno::Reference < css::io::XStream >& xStream,
167 sal_Int32 nStorageMode = css::embed::ElementModes::READWRITE,
168 const css::uno::Reference< css::uno::XComponentContext >& rxContext
169 = css::uno::Reference< css::uno::XComponentContext >(),
170 bool bRepairStorage = false );
172 static css::uno::Sequence< css::beans::NamedValue >
173 CreatePackageEncryptionData(
174 const OUString& aPassword );
176 static css::uno::Sequence< css::beans::NamedValue >
177 CreateGpgPackageEncryptionData();
179 static bool IsValidZipEntryFileName( const OUString& aName, bool bSlashAllowed );
180 static bool IsValidZipEntryFileName( const sal_Unicode *pChar, sal_Int32 nLength, bool bSlashAllowed );
182 static bool PathHasSegment( const OUString& aPath, const OUString& aSegment );
184 // Methods to allow easy use of hierarchical names inside storages
186 static css::uno::Reference< css::embed::XStorage > GetStorageAtPath(
187 const css::uno::Reference< css::embed::XStorage > &xStorage,
188 const OUString& aPath, sal_uInt32 nOpenMode, LifecycleProxy const &rNastiness );
189 static css::uno::Reference< css::io::XStream > GetStreamAtPath(
190 const css::uno::Reference< css::embed::XStorage > &xStorage,
191 const OUString& aPath, sal_uInt32 nOpenMode, LifecycleProxy const &rNastiness );
192 static css::uno::Reference< css::io::XStream > GetStreamAtPackageURL(
193 const css::uno::Reference< css::embed::XStorage > &xStorage,
194 const OUString& rURL, sal_uInt32 const nOpenMode,
195 LifecycleProxy const & rNastiness );
197 static OUString
198 GetODFVersionFromStorage(const css::uno::Reference<css::embed::XStorage>& xStorage);
203 #endif
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */