LibreOffice Module comphelper (master) 1
storagehelper.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#ifndef INCLUDED_COMPHELPER_STORAGEHELPER_HXX
20#define INCLUDED_COMPHELPER_STORAGEHELPER_HXX
21
22#include <com/sun/star/uno/Sequence.h>
23#include <com/sun/star/uno/Reference.hxx>
24#include <com/sun/star/embed/ElementModes.hpp>
26#include <memory>
27#include <string_view>
28
29inline constexpr OUStringLiteral PACKAGE_STORAGE_FORMAT_STRING = u"PackageFormat";
30inline constexpr OUStringLiteral ZIP_STORAGE_FORMAT_STRING = u"ZipFormat";
31inline constexpr OUStringLiteral OFOPXML_STORAGE_FORMAT_STRING = u"OFOPXMLFormat";
32
33inline constexpr OUStringLiteral PACKAGE_ENCRYPTIONDATA_SHA256UTF8 = u"PackageSHA256UTF8EncryptionKey";
34inline constexpr OUStringLiteral PACKAGE_ENCRYPTIONDATA_SHA1UTF8 = u"PackageSHA1UTF8EncryptionKey";
35inline constexpr OUStringLiteral PACKAGE_ENCRYPTIONDATA_SHA1MS1252 = u"PackageSHA1MS1252EncryptionKey";
36inline constexpr OUStringLiteral PACKAGE_ENCRYPTIONDATA_SHA1CORRECT = u"PackageSHA1CorrectEncryptionKey";
37
38namespace com::sun::star {
39 namespace beans { struct NamedValue; }
40 namespace embed { class XStorage; }
41 namespace io {
42 class XInputStream;
43 class XOutputStream;
44 class XStream;
45 }
46 namespace lang { class XSingleServiceFactory; }
47 namespace uno { class XComponentContext; }
48}
49
50namespace comphelper {
51
52// Unfortunately - the impl.s of XStorage like to invalidate all
53// their sub streams and storages when you release references, so
54// it is necessary to keep references to all storages down the
55// path - this is 'beautiful' (TM). So we need this ugly hack:
57{
58private:
59 class Impl;
60public:
61 std::unique_ptr<Impl> m_xBadness;
64 // commit the storages: necessary for writes to streams to take effect!
65 void commitStorages();
66};
67
69{
70public:
72 static css::uno::Reference< css::lang::XSingleServiceFactory >
73 GetStorageFactory(
74 const css::uno::Reference< css::uno::XComponentContext >& rxContext
75 = css::uno::Reference< css::uno::XComponentContext >() );
76
78 static css::uno::Reference< css::lang::XSingleServiceFactory >
79 GetFileSystemStorageFactory(
80 const css::uno::Reference< css::uno::XComponentContext >& rxContext
81 = css::uno::Reference< css::uno::XComponentContext >() );
82
84 static css::uno::Reference< css::embed::XStorage >
85 GetTemporaryStorage(
86 const css::uno::Reference< css::uno::XComponentContext >& rxContext
87 = css::uno::Reference< css::uno::XComponentContext >() );
88
92 static css::uno::Reference< css::embed::XStorage >
93 GetStorageFromURL(
94 const OUString& aURL,
95 sal_Int32 nStorageMode,
96 const css::uno::Reference< css::uno::XComponentContext >& rxContext
97 = css::uno::Reference< css::uno::XComponentContext >() );
98
102 static css::uno::Reference< css::embed::XStorage >
103 GetStorageFromURL2(
104 const OUString& aURL,
105 sal_Int32 nStorageMode,
106 const css::uno::Reference< css::uno::XComponentContext >& rxContext
107 = css::uno::Reference< css::uno::XComponentContext >() );
108
110 static css::uno::Reference< css::embed::XStorage >
111 GetStorageFromInputStream(
112 const css::uno::Reference < css::io::XInputStream >& xStream,
113 const css::uno::Reference< css::uno::XComponentContext >& rxContext
114 = css::uno::Reference< css::uno::XComponentContext >() );
115
117 static css::uno::Reference< css::embed::XStorage >
118 GetStorageFromStream(
119 const css::uno::Reference < css::io::XStream >& xStream,
120 sal_Int32 nStorageMode = css::embed::ElementModes::READWRITE,
121 const css::uno::Reference< css::uno::XComponentContext >& rxContext
122 = css::uno::Reference< css::uno::XComponentContext >() );
123
125 static void CopyInputToOutput(
126 const css::uno::Reference< css::io::XInputStream >& xInput,
127 const css::uno::Reference< css::io::XOutputStream >& xOutput );
128
130 static css::uno::Reference< css::io::XInputStream >
131 GetInputStreamFromURL(
132 const OUString& aURL,
133 const css::uno::Reference< css::uno::XComponentContext >& context );
134
136 static void SetCommonStorageEncryptionData(
137 const css::uno::Reference< css::embed::XStorage >& xStorage,
138 const css::uno::Sequence< css::beans::NamedValue >& aEncryptionData );
139
140 // the following method supports only storages of OOo formats
142 static sal_Int32 GetXStorageFormat(
143 const css::uno::Reference< css::embed::XStorage >& xStorage );
144
146 static css::uno::Reference< css::embed::XStorage >
147 GetStorageOfFormatFromURL(
148 const OUString& aFormat,
149 const OUString& aURL,
150 sal_Int32 nStorageMode,
151 const css::uno::Reference< css::uno::XComponentContext >& rxContext
152 = css::uno::Reference< css::uno::XComponentContext >() );
153
155 static css::uno::Reference< css::embed::XStorage >
156 GetStorageOfFormatFromInputStream(
157 const OUString& aFormat,
158 const css::uno::Reference < css::io::XInputStream >& xStream,
159 const css::uno::Reference< css::uno::XComponentContext >& rxContext
160 = css::uno::Reference< css::uno::XComponentContext >(),
161 bool bRepairStorage = false );
162
164 static css::uno::Reference< css::embed::XStorage >
165 GetStorageOfFormatFromStream(
166 const OUString& aFormat,
167 const css::uno::Reference < css::io::XStream >& xStream,
168 sal_Int32 nStorageMode = css::embed::ElementModes::READWRITE,
169 const css::uno::Reference< css::uno::XComponentContext >& rxContext
170 = css::uno::Reference< css::uno::XComponentContext >(),
171 bool bRepairStorage = false );
172
173 static css::uno::Sequence< css::beans::NamedValue >
174 CreatePackageEncryptionData(
175 std::u16string_view aPassword );
176
177 static css::uno::Sequence< css::beans::NamedValue >
178 CreateGpgPackageEncryptionData();
179
180 static bool IsValidZipEntryFileName( std::u16string_view aName, bool bSlashAllowed );
181
182 static bool PathHasSegment( std::u16string_view aPath, std::u16string_view aSegment );
183
184 // Methods to allow easy use of hierarchical names inside storages
185
186 static css::uno::Reference< css::embed::XStorage > GetStorageAtPath(
187 const css::uno::Reference< css::embed::XStorage > &xStorage,
188 std::u16string_view 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 std::u16string_view 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 );
196
197 static OUString
198 GetODFVersionFromStorage(const css::uno::Reference<css::embed::XStorage>& xStorage);
199};
200
201}
202
203#endif
204
205/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XInputStream > xStream
std::unique_ptr< Impl > m_xBadness
#define COMPHELPER_DLLPUBLIC
URL aURL
float u
OUString aName
constexpr OUStringLiteral ZIP_STORAGE_FORMAT_STRING
constexpr OUStringLiteral PACKAGE_ENCRYPTIONDATA_SHA1UTF8
constexpr OUStringLiteral PACKAGE_ENCRYPTIONDATA_SHA1CORRECT
constexpr OUStringLiteral PACKAGE_ENCRYPTIONDATA_SHA1MS1252
constexpr OUStringLiteral OFOPXML_STORAGE_FORMAT_STRING
constexpr OUStringLiteral PACKAGE_ENCRYPTIONDATA_SHA256UTF8
constexpr OUStringLiteral PACKAGE_STORAGE_FORMAT_STRING