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 <boost/scoped_ptr.hpp>
24 #include <com/sun/star/uno/Sequence.hxx>
25 #include <com/sun/star/uno/Reference.hxx>
26 #include <com/sun/star/embed/ElementModes.hpp>
27 #include <comphelper/comphelperdllapi.h>
30 #define PACKAGE_STORAGE_FORMAT_STRING OUString( "PackageFormat" )
31 #define ZIP_STORAGE_FORMAT_STRING OUString( "ZipFormat" )
32 #define OFOPXML_STORAGE_FORMAT_STRING OUString( "OFOPXMLFormat" )
34 #define PACKAGE_ENCRYPTIONDATA_SHA256UTF8 OUString( "PackageSHA256UTF8EncryptionKey" )
35 #define PACKAGE_ENCRYPTIONDATA_SHA1UTF8 OUString( "PackageSHA1UTF8EncryptionKey" )
36 #define PACKAGE_ENCRYPTIONDATA_SHA1MS1252 OUString( "PackageSHA1MS1252EncryptionKey" )
38 namespace com
{ namespace sun
{ namespace star
{
39 namespace beans
{ struct NamedValue
; }
40 namespace embed
{ class XStorage
; }
46 namespace lang
{ class XSingleServiceFactory
; }
47 namespace uno
{ class XComponentContext
; }
50 namespace comphelper
{
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:
56 class COMPHELPER_DLLPUBLIC LifecycleProxy
61 ::boost::scoped_ptr
<Impl
> m_pBadness
;
64 // commit the storages: necessary for writes to streams to take effect!
65 void commitStorages();
68 class COMPHELPER_DLLPUBLIC OStorageHelper
71 static ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XSingleServiceFactory
>
73 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
74 = ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>() )
75 throw ( ::com::sun::star::uno::Exception
);
77 static ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XSingleServiceFactory
>
78 GetFileSystemStorageFactory(
79 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
80 = ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>() )
81 throw ( ::com::sun::star::uno::Exception
);
83 static ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>
85 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
86 = ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>() )
87 throw ( ::com::sun::star::uno::Exception
);
89 /// this one will only return Storage
90 static ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>
93 sal_Int32 nStorageMode
,
94 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
95 = ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>() )
96 throw ( ::com::sun::star::uno::Exception
);
98 /// this one will return either Storage or FileSystemStorage
99 static ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>
101 const OUString
& aURL
,
102 sal_Int32 nStorageMode
,
103 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
104 = ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>() )
106 throw ( ::com::sun::star::uno::Exception
);
108 static ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>
109 GetStorageFromInputStream(
110 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& xStream
,
111 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
112 = ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>() )
113 throw ( ::com::sun::star::uno::Exception
);
115 static ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>
116 GetStorageFromStream(
117 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XStream
>& xStream
,
118 sal_Int32 nStorageMode
= ::com::sun::star::embed::ElementModes::READWRITE
,
119 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
120 = ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>() )
121 throw ( ::com::sun::star::uno::Exception
);
123 static void CopyInputToOutput(
124 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& xInput
,
125 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XOutputStream
>& xOutput
)
126 throw ( ::com::sun::star::uno::Exception
);
128 static ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>
129 GetInputStreamFromURL(
130 const OUString
& aURL
,
131 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& context
)
132 throw ( ::com::sun::star::uno::Exception
);
134 static void SetCommonStorageEncryptionData(
135 const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>& xStorage
,
136 const ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::NamedValue
>& aEncryptionData
)
137 throw ( ::com::sun::star::uno::Exception
);
139 // the following method supports only storages of OOo formats
140 static sal_Int32
GetXStorageFormat(
141 const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>& xStorage
)
142 throw ( ::com::sun::star::uno::Exception
);
144 static ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>
145 GetStorageOfFormatFromURL(
146 const OUString
& aFormat
,
147 const OUString
& aURL
,
148 sal_Int32 nStorageMode
,
149 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
150 = ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>(),
151 sal_Bool bRepairStorage
= sal_False
)
152 throw ( ::com::sun::star::uno::Exception
);
154 static ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>
155 GetStorageOfFormatFromInputStream(
156 const OUString
& aFormat
,
157 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& xStream
,
158 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
159 = ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>(),
160 sal_Bool bRepairStorage
= sal_False
)
161 throw ( ::com::sun::star::uno::Exception
);
163 static ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>
164 GetStorageOfFormatFromStream(
165 const OUString
& aFormat
,
166 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XStream
>& xStream
,
167 sal_Int32 nStorageMode
= ::com::sun::star::embed::ElementModes::READWRITE
,
168 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
169 = ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>(),
170 sal_Bool bRepairStorage
= sal_False
)
171 throw ( ::com::sun::star::uno::Exception
);
173 static ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::NamedValue
>
174 CreatePackageEncryptionData(
175 const OUString
& aPassword
);
177 static sal_Bool
IsValidZipEntryFileName( const OUString
& aName
, sal_Bool bSlashAllowed
);
178 static sal_Bool
IsValidZipEntryFileName( const sal_Unicode
*pChar
, sal_Int32 nLength
, sal_Bool bSlashAllowed
);
180 static sal_Bool
PathHasSegment( const OUString
& aPath
, const OUString
& aSegment
);
182 // Methods to allow easy use of hierachical names inside storages
184 static ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
> GetStorageAtPath(
185 const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
> &xStorage
,
186 const OUString
& aPath
, sal_uInt32 nOpenMode
, LifecycleProxy
&rNastiness
);
187 static ::com::sun::star::uno::Reference
< ::com::sun::star::io::XStream
> GetStreamAtPath(
188 const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
> &xStorage
,
189 const OUString
& aPath
, sal_uInt32 nOpenMode
, LifecycleProxy
&rNastiness
);
190 static ::com::sun::star::uno::Reference
< ::com::sun::star::io::XStream
> GetStreamAtPackageURL(
191 const ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
> &xStorage
,
192 const OUString
& rURL
, sal_uInt32
const nOpenMode
,
193 LifecycleProxy
& rNastiness
);
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */