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 
28 #define PACKAGE_STORAGE_FORMAT_STRING "PackageFormat"
29 #define ZIP_STORAGE_FORMAT_STRING "ZipFormat"
30 #define OFOPXML_STORAGE_FORMAT_STRING "OFOPXMLFormat"
31 
32 #define PACKAGE_ENCRYPTIONDATA_SHA256UTF8 "PackageSHA256UTF8EncryptionKey"
33 #define PACKAGE_ENCRYPTIONDATA_SHA1UTF8 "PackageSHA1UTF8EncryptionKey"
34 #define PACKAGE_ENCRYPTIONDATA_SHA1MS1252 "PackageSHA1MS1252EncryptionKey"
35 #define PACKAGE_ENCRYPTIONDATA_SHA1CORRECT "PackageSHA1CorrectEncryptionKey"
36 
37 namespace com { namespace sun { namespace star {
38  namespace beans { struct NamedValue; }
39  namespace embed { class XStorage; }
40  namespace io {
41  class XInputStream;
42  class XOutputStream;
43  class XStream;
44  }
45  namespace lang { class XSingleServiceFactory; }
46  namespace uno { class XComponentContext; }
47 } } }
48 
49 namespace comphelper {
50 
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:
56 {
57 private:
58  class Impl;
59 public:
60  std::unique_ptr<Impl> m_xBadness;
62  ~LifecycleProxy();
63  // commit the storages: necessary for writes to streams to take effect!
64  void commitStorages();
65 };
66 
68 {
69 public:
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 >() );
75 
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 >() );
81 
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 >() );
87 
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 >() );
97 
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 >() );
107 
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 >() );
114 
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 >() );
122 
124  static void CopyInputToOutput(
125  const css::uno::Reference< css::io::XInputStream >& xInput,
126  const css::uno::Reference< css::io::XOutputStream >& xOutput );
127 
129  static css::uno::Reference< css::io::XInputStream >
130  GetInputStreamFromURL(
131  const OUString& aURL,
132  const css::uno::Reference< css::uno::XComponentContext >& context );
133 
135  static void SetCommonStorageEncryptionData(
136  const css::uno::Reference< css::embed::XStorage >& xStorage,
137  const css::uno::Sequence< css::beans::NamedValue >& aEncryptionData );
138 
139  // the following method supports only storages of OOo formats
141  static sal_Int32 GetXStorageFormat(
142  const css::uno::Reference< css::embed::XStorage >& xStorage );
143 
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 >() );
152 
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 );
161 
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 );
171 
172  static css::uno::Sequence< css::beans::NamedValue >
173  CreatePackageEncryptionData(
174  const OUString& aPassword );
175 
176  static css::uno::Sequence< css::beans::NamedValue >
177  CreateGpgPackageEncryptionData();
178 
179  static bool IsValidZipEntryFileName( const OUString& aName, bool bSlashAllowed );
180  static bool IsValidZipEntryFileName( const sal_Unicode *pChar, sal_Int32 nLength, bool bSlashAllowed );
181 
182  static bool PathHasSegment( const OUString& aPath, const OUString& 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  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 );
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: */
const sal_Char * pChar
sal_uInt16 sal_Unicode
Reference< XInputStream > xStream
std::unique_ptr< Impl > m_xBadness
OString const aName
#define COMPHELPER_DLLPUBLIC
sal_Int32 const nLength