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 
29 #define PACKAGE_STORAGE_FORMAT_STRING "PackageFormat"
30 #define ZIP_STORAGE_FORMAT_STRING "ZipFormat"
31 #define OFOPXML_STORAGE_FORMAT_STRING "OFOPXMLFormat"
32 
33 #define PACKAGE_ENCRYPTIONDATA_SHA256UTF8 "PackageSHA256UTF8EncryptionKey"
34 #define PACKAGE_ENCRYPTIONDATA_SHA1UTF8 "PackageSHA1UTF8EncryptionKey"
35 #define PACKAGE_ENCRYPTIONDATA_SHA1MS1252 "PackageSHA1MS1252EncryptionKey"
36 #define PACKAGE_ENCRYPTIONDATA_SHA1CORRECT "PackageSHA1CorrectEncryptionKey"
37 
38 namespace 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 
50 namespace 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 {
58 private:
59  class Impl;
60 public:
61  std::unique_ptr<Impl> m_xBadness;
63  ~LifecycleProxy();
64  // commit the storages: necessary for writes to streams to take effect!
65  void commitStorages();
66 };
67 
69 {
70 public:
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( const OUString& aName, bool bSlashAllowed );
181  static bool IsValidZipEntryFileName( const sal_Unicode *pChar, sal_Int32 nLength, bool bSlashAllowed );
182 
183  static bool PathHasSegment( const OUString& aPath, const OUString& aSegment );
184 
185  // Methods to allow easy use of hierarchical names inside storages
186 
187  static css::uno::Reference< css::embed::XStorage > GetStorageAtPath(
188  const css::uno::Reference< css::embed::XStorage > &xStorage,
189  const OUString& aPath, sal_uInt32 nOpenMode, LifecycleProxy const &rNastiness );
190  static css::uno::Reference< css::io::XStream > GetStreamAtPath(
191  const css::uno::Reference< css::embed::XStorage > &xStorage,
192  const OUString& aPath, sal_uInt32 nOpenMode, LifecycleProxy const &rNastiness );
193  static css::uno::Reference< css::io::XStream > GetStreamAtPackageURL(
194  const css::uno::Reference< css::embed::XStorage > &xStorage,
195  const OUString& rURL, sal_uInt32 const nOpenMode,
196  LifecycleProxy const & rNastiness );
197 
198  static OUString
199  GetODFVersionFromStorage(const css::uno::Reference<css::embed::XStorage>& xStorage);
200 };
201 
202 }
203 
204 #endif
205 
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
URL aURL
exports com.sun.star. io
exports com.sun.star. embed
sal_uInt16 sal_Unicode
Reference< XInputStream > xStream
std::unique_ptr< Impl > m_xBadness
exports com.sun.star. beans
exports com.sun.star. lang
OUString aName
const char * pChar
#define COMPHELPER_DLLPUBLIC
sal_Int32 nLength