1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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.hxx>
23 #include <com/sun/star/uno/Reference.hxx>
24 #include <com/sun/star/embed/ElementModes.hpp>
25 #include <comphelper/comphelperdllapi.h>
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"
36 namespace com
{ namespace sun
{ namespace star
{
37 namespace beans
{ struct NamedValue
; }
38 namespace embed
{ class XStorage
; }
44 namespace lang
{ class XSingleServiceFactory
; }
45 namespace uno
{ class XComponentContext
; }
48 namespace comphelper
{
50 // Unfortunately - the impl.s of XStorage like to invalidate all
51 // their sub streams and storages when you release references, so
52 // it is necessary to keep references to all storages down the
53 // path - this is 'beautiful' (TM). So we need this ugly hack:
54 class COMPHELPER_DLLPUBLIC LifecycleProxy
59 std::unique_ptr
<Impl
> m_xBadness
;
62 // commit the storages: necessary for writes to streams to take effect!
63 void commitStorages();
66 class COMPHELPER_DLLPUBLIC OStorageHelper
69 static ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XSingleServiceFactory
>
71 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
72 = ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>() )
73 throw ( ::com::sun::star::uno::Exception
);
75 static ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XSingleServiceFactory
>
76 GetFileSystemStorageFactory(
77 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
78 = ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>() )
79 throw ( ::com::sun::star::uno::Exception
);
81 static ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>
83 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
84 = ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>() )
85 throw ( ::com::sun::star::uno::Exception
);
87 /// this one will only return Storage
88 static ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>
91 sal_Int32 nStorageMode
,
92 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
93 = ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>() )
94 throw ( ::com::sun::star::uno::Exception
);
96 /// this one will return either Storage or FileSystemStorage
97 static ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>
100 sal_Int32 nStorageMode
,
101 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
102 = ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>() )
104 throw ( ::com::sun::star::uno::Exception
);
106 static ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>
107 GetStorageFromInputStream(
108 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& xStream
,
109 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
110 = ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>() )
111 throw ( ::com::sun::star::uno::Exception
);
113 static ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>
114 GetStorageFromStream(
115 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XStream
>& xStream
,
116 sal_Int32 nStorageMode
= ::com::sun::star::embed::ElementModes::READWRITE
,
117 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
118 = ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>() )
119 throw ( ::com::sun::star::uno::Exception
);
121 static void CopyInputToOutput(
122 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& xInput
,
123 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XOutputStream
>& xOutput
)
124 throw ( ::com::sun::star::uno::Exception
);
126 static ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>
127 GetInputStreamFromURL(
128 const OUString
& aURL
,
129 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& context
)
130 throw ( ::com::sun::star::uno::Exception
);
132 static void SetCommonStorageEncryptionData(
133 const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>& xStorage
,
134 const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::NamedValue
>& aEncryptionData
)
135 throw ( ::com::sun::star::uno::Exception
);
137 // the following method supports only storages of OOo formats
138 static sal_Int32
GetXStorageFormat(
139 const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>& xStorage
)
140 throw ( ::com::sun::star::uno::Exception
);
142 static ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>
143 GetStorageOfFormatFromURL(
144 const OUString
& aFormat
,
145 const OUString
& aURL
,
146 sal_Int32 nStorageMode
,
147 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
148 = ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>(),
149 bool bRepairStorage
= false )
150 throw ( ::com::sun::star::uno::Exception
);
152 static ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>
153 GetStorageOfFormatFromInputStream(
154 const OUString
& aFormat
,
155 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& xStream
,
156 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
157 = ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>(),
158 bool bRepairStorage
= false )
159 throw ( ::com::sun::star::uno::Exception
);
161 static ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>
162 GetStorageOfFormatFromStream(
163 const OUString
& aFormat
,
164 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XStream
>& xStream
,
165 sal_Int32 nStorageMode
= ::com::sun::star::embed::ElementModes::READWRITE
,
166 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
167 = ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>(),
168 bool bRepairStorage
= false )
169 throw ( ::com::sun::star::uno::Exception
);
171 static ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::NamedValue
>
172 CreatePackageEncryptionData(
173 const OUString
& aPassword
);
175 static bool IsValidZipEntryFileName( const OUString
& aName
, bool bSlashAllowed
);
176 static bool IsValidZipEntryFileName( const sal_Unicode
*pChar
, sal_Int32 nLength
, bool bSlashAllowed
);
178 static bool PathHasSegment( const OUString
& aPath
, const OUString
& aSegment
);
180 // Methods to allow easy use of hierarchical names inside storages
182 static ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
> GetStorageAtPath(
183 const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
> &xStorage
,
184 const OUString
& aPath
, sal_uInt32 nOpenMode
, LifecycleProxy
&rNastiness
);
185 static ::com::sun::star::uno::Reference
< ::com::sun::star::io::XStream
> GetStreamAtPath(
186 const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
> &xStorage
,
187 const OUString
& aPath
, sal_uInt32 nOpenMode
, LifecycleProxy
&rNastiness
);
188 static ::com::sun::star::uno::Reference
< ::com::sun::star::io::XStream
> GetStreamAtPackageURL(
189 const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
> &xStorage
,
190 const OUString
& rURL
, sal_uInt32
const nOpenMode
,
191 LifecycleProxy
& rNastiness
);
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */