Line data Source code
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 :
20 : #ifndef INCLUDED_SOT_STG_HXX
21 : #define INCLUDED_SOT_STG_HXX
22 :
23 : #include <com/sun/star/uno/Any.h>
24 : #include <com/sun/star/uno/Reference.h>
25 :
26 : #include <com/sun/star/io/XInputStream.hpp>
27 :
28 : #include <com/sun/star/ucb/XCommandEnvironment.hpp>
29 :
30 : #include <com/sun/star/embed/XStorage.hpp>
31 :
32 :
33 : #include <tools/rtti.hxx>
34 : #include <tools/solar.h>
35 : #include <tools/stream.hxx>
36 : #include <tools/globname.hxx>
37 : #include <sot/storinfo.hxx>
38 : #include <sot/sotdllapi.h>
39 :
40 : class Storage;
41 : class StorageStream;
42 : class StgIo;
43 : class StgDirEntry;
44 : class StgStrm;
45 : class SvGlobalName;
46 : typedef struct SvGUID ClsId;
47 :
48 : class SOT_DLLPUBLIC StorageBase : public SvRefBase
49 : {
50 : protected:
51 : sal_uLong m_nError; // error code
52 : StreamMode m_nMode; // open mode
53 : bool m_bAutoCommit;
54 : StorageBase();
55 : virtual ~StorageBase();
56 : public:
57 : TYPEINFO();
58 : virtual const SvStream* GetSvStream() const = 0;
59 : virtual bool Validate( bool=false ) const = 0;
60 : virtual bool ValidateMode( StreamMode ) const = 0;
61 : void ResetError() const;
62 : void SetError( sal_uLong ) const;
63 : sal_uLong GetError() const;
64 17572 : bool Good() const { return bool( m_nError == SVSTREAM_OK ); }
65 2456 : StreamMode GetMode() const { return m_nMode; }
66 10950 : void SetAutoCommit( bool bSet )
67 10950 : { m_bAutoCommit = bSet; }
68 : };
69 :
70 22428 : class BaseStorageStream : public StorageBase
71 : {
72 : public:
73 : TYPEINFO_OVERRIDE();
74 : virtual sal_uLong Read( void * pData, sal_uLong nSize ) = 0;
75 : virtual sal_uLong Write( const void* pData, sal_uLong nSize ) = 0;
76 : virtual sal_uInt64 Seek( sal_uInt64 nPos ) = 0;
77 : virtual sal_uLong Tell() = 0;
78 : virtual void Flush() = 0;
79 : virtual bool SetSize( sal_uLong nNewSize ) = 0;
80 : virtual sal_uLong GetSize() const = 0;
81 : virtual bool CopyTo( BaseStorageStream * pDestStm ) = 0;
82 : virtual bool Commit() = 0;
83 : virtual bool Revert() = 0;
84 : virtual bool Equals( const BaseStorageStream& rStream ) const = 0;
85 : };
86 :
87 12636 : class BaseStorage : public StorageBase
88 : {
89 : public:
90 : TYPEINFO_OVERRIDE();
91 : virtual const OUString& GetName() const = 0;
92 : virtual bool IsRoot() const = 0;
93 : virtual void SetClassId( const ClsId& ) = 0;
94 : virtual const ClsId& GetClassId() const = 0;
95 : virtual void SetDirty() = 0;
96 : virtual void SetClass( const SvGlobalName & rClass,
97 : sal_uLong nOriginalClipFormat,
98 : const OUString & rUserTypeName ) = 0;
99 : virtual void SetConvertClass( const SvGlobalName & rConvertClass,
100 : sal_uLong nOriginalClipFormat,
101 : const OUString & rUserTypeName ) = 0;
102 : virtual SvGlobalName GetClassName() = 0;
103 : virtual sal_uLong GetFormat() = 0;
104 : virtual OUString GetUserName() = 0;
105 : virtual bool ShouldConvert() = 0;
106 : virtual void FillInfoList( SvStorageInfoList* ) const = 0;
107 : virtual bool CopyTo( BaseStorage* pDestStg ) const = 0;
108 : virtual bool Commit() = 0;
109 : virtual bool Revert() = 0;
110 : virtual BaseStorageStream* OpenStream( const OUString & rEleName,
111 : StreamMode = STREAM_STD_READWRITE,
112 : bool bDirect = true, const OString* pKey=0 ) = 0;
113 : virtual BaseStorage* OpenStorage( const OUString & rEleName,
114 : StreamMode = STREAM_STD_READWRITE,
115 : bool bDirect = false ) = 0;
116 : virtual BaseStorage* OpenUCBStorage( const OUString & rEleName,
117 : StreamMode = STREAM_STD_READWRITE,
118 : bool bDirect = false ) = 0;
119 : virtual BaseStorage* OpenOLEStorage( const OUString & rEleName,
120 : StreamMode = STREAM_STD_READWRITE,
121 : bool bDirect = false ) = 0;
122 : virtual bool IsStream( const OUString& rEleName ) const = 0;
123 : virtual bool IsStorage( const OUString& rEleName ) const = 0;
124 : virtual bool IsContained( const OUString& rEleName ) const = 0;
125 : virtual bool Remove( const OUString & rEleName ) = 0;
126 : virtual bool Rename( const OUString & rEleName, const OUString & rNewName ) = 0;
127 : virtual bool CopyTo( const OUString & rEleName, BaseStorage * pDest, const OUString & rNewName ) = 0;
128 : virtual bool MoveTo( const OUString & rEleName, BaseStorage * pDest, const OUString & rNewName ) = 0;
129 : virtual bool ValidateFAT() = 0;
130 : virtual bool Equals( const BaseStorage& rStream ) const = 0;
131 : };
132 :
133 : class OLEStorageBase
134 : {
135 : protected:
136 : StreamMode& nStreamMode; // open mode
137 : StgIo* pIo; // I/O subsystem
138 : StgDirEntry* pEntry; // the dir entry
139 : OLEStorageBase( StgIo*, StgDirEntry*, StreamMode& );
140 : ~OLEStorageBase();
141 : bool Validate_Impl( bool=false ) const;
142 : bool ValidateMode_Impl( StreamMode, StgDirEntry* p = NULL ) const ;
143 : const SvStream* GetSvStream_Impl() const;
144 : public:
145 : };
146 :
147 : class StorageStream : public BaseStorageStream, public OLEStorageBase
148 : {
149 : //friend class Storage;
150 : sal_uLong nPos; // current position
151 : protected:
152 : virtual ~StorageStream();
153 : public:
154 : TYPEINFO_OVERRIDE();
155 : StorageStream( StgIo*, StgDirEntry*, StreamMode );
156 : virtual sal_uLong Read( void * pData, sal_uLong nSize ) SAL_OVERRIDE;
157 : virtual sal_uLong Write( const void* pData, sal_uLong nSize ) SAL_OVERRIDE;
158 : virtual sal_uInt64 Seek( sal_uInt64 nPos ) SAL_OVERRIDE;
159 1854 : virtual sal_uLong Tell() SAL_OVERRIDE { return nPos; }
160 : virtual void Flush() SAL_OVERRIDE;
161 : virtual bool SetSize( sal_uLong nNewSize ) SAL_OVERRIDE;
162 : virtual sal_uLong GetSize() const SAL_OVERRIDE;
163 : virtual bool CopyTo( BaseStorageStream * pDestStm ) SAL_OVERRIDE;
164 : virtual bool Commit() SAL_OVERRIDE;
165 : virtual bool Revert() SAL_OVERRIDE;
166 : virtual bool Validate( bool=false ) const SAL_OVERRIDE;
167 : virtual bool ValidateMode( StreamMode ) const SAL_OVERRIDE;
168 : const SvStream* GetSvStream() const SAL_OVERRIDE;
169 : virtual bool Equals( const BaseStorageStream& rStream ) const SAL_OVERRIDE;
170 : };
171 :
172 : class UCBStorageStream;
173 :
174 : class SOT_DLLPUBLIC Storage : public BaseStorage, public OLEStorageBase
175 : {
176 : OUString aName;
177 : bool bIsRoot;
178 : void Init( bool bCreate );
179 : Storage( StgIo*, StgDirEntry*, StreamMode );
180 : protected:
181 : virtual ~Storage();
182 : public:
183 : TYPEINFO_OVERRIDE();
184 : Storage( const OUString &, StreamMode = STREAM_STD_READWRITE, bool bDirect = true );
185 : Storage( SvStream& rStrm, bool bDirect = true );
186 : Storage( UCBStorageStream& rStrm, bool bDirect = true );
187 :
188 : static bool IsStorageFile( const OUString & rFileName );
189 : static bool IsStorageFile( SvStream* );
190 :
191 : virtual const OUString& GetName() const SAL_OVERRIDE;
192 1730 : virtual bool IsRoot() const SAL_OVERRIDE { return bIsRoot; }
193 : virtual void SetClassId( const ClsId& ) SAL_OVERRIDE;
194 : virtual const ClsId& GetClassId() const SAL_OVERRIDE;
195 : virtual void SetDirty() SAL_OVERRIDE;
196 : virtual void SetClass( const SvGlobalName & rClass,
197 : sal_uLong nOriginalClipFormat,
198 : const OUString & rUserTypeName ) SAL_OVERRIDE;
199 : virtual void SetConvertClass( const SvGlobalName & rConvertClass,
200 : sal_uLong nOriginalClipFormat,
201 : const OUString & rUserTypeName ) SAL_OVERRIDE;
202 : virtual SvGlobalName GetClassName() SAL_OVERRIDE;
203 : virtual sal_uLong GetFormat() SAL_OVERRIDE;
204 : virtual OUString GetUserName() SAL_OVERRIDE;
205 : virtual bool ShouldConvert() SAL_OVERRIDE;
206 : virtual void FillInfoList( SvStorageInfoList* ) const SAL_OVERRIDE;
207 : virtual bool CopyTo( BaseStorage* pDestStg ) const SAL_OVERRIDE;
208 : virtual bool Commit() SAL_OVERRIDE;
209 : virtual bool Revert() SAL_OVERRIDE;
210 : virtual BaseStorageStream* OpenStream( const OUString & rEleName,
211 : StreamMode = STREAM_STD_READWRITE,
212 : bool bDirect = true, const OString* pKey=0 ) SAL_OVERRIDE;
213 : virtual BaseStorage* OpenStorage( const OUString & rEleName,
214 : StreamMode = STREAM_STD_READWRITE,
215 : bool bDirect = false ) SAL_OVERRIDE;
216 : virtual BaseStorage* OpenUCBStorage( const OUString & rEleName,
217 : StreamMode = STREAM_STD_READWRITE,
218 : bool bDirect = false ) SAL_OVERRIDE;
219 : virtual BaseStorage* OpenOLEStorage( const OUString & rEleName,
220 : StreamMode = STREAM_STD_READWRITE,
221 : bool bDirect = false ) SAL_OVERRIDE;
222 : virtual bool IsStream( const OUString& rEleName ) const SAL_OVERRIDE;
223 : virtual bool IsStorage( const OUString& rEleName ) const SAL_OVERRIDE;
224 : virtual bool IsContained( const OUString& rEleName ) const SAL_OVERRIDE;
225 : virtual bool Remove( const OUString & rEleName ) SAL_OVERRIDE;
226 : virtual bool Rename( const OUString & rEleName, const OUString & rNewName ) SAL_OVERRIDE;
227 : virtual bool CopyTo( const OUString & rEleName, BaseStorage * pDest, const OUString & rNewName ) SAL_OVERRIDE;
228 : virtual bool MoveTo( const OUString & rEleName, BaseStorage * pDest, const OUString & rNewName ) SAL_OVERRIDE;
229 : virtual bool ValidateFAT() SAL_OVERRIDE;
230 : virtual bool Validate( bool=false ) const SAL_OVERRIDE;
231 : virtual bool ValidateMode( StreamMode ) const SAL_OVERRIDE;
232 : bool ValidateMode( StreamMode, StgDirEntry* p ) const;
233 : virtual const SvStream* GetSvStream() const SAL_OVERRIDE;
234 : virtual bool Equals( const BaseStorage& rStream ) const SAL_OVERRIDE;
235 : };
236 :
237 : class UCBStorageStream_Impl;
238 : class UCBStorageStream : public BaseStorageStream
239 : {
240 : friend class UCBStorage;
241 :
242 : UCBStorageStream_Impl*
243 : pImp;
244 : protected:
245 : virtual ~UCBStorageStream();
246 : public:
247 : TYPEINFO_OVERRIDE();
248 : UCBStorageStream( const OUString& rName, StreamMode nMode, bool bDirect, const OString* pKey, bool bRepair, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XProgressHandler > xProgress );
249 : UCBStorageStream( UCBStorageStream_Impl* );
250 :
251 : virtual sal_uLong Read( void * pData, sal_uLong nSize ) SAL_OVERRIDE;
252 : virtual sal_uLong Write( const void* pData, sal_uLong nSize ) SAL_OVERRIDE;
253 : virtual sal_uInt64 Seek( sal_uInt64 nPos ) SAL_OVERRIDE;
254 : virtual sal_uLong Tell() SAL_OVERRIDE;
255 : virtual void Flush() SAL_OVERRIDE;
256 : virtual bool SetSize( sal_uLong nNewSize ) SAL_OVERRIDE;
257 : virtual sal_uLong GetSize() const SAL_OVERRIDE;
258 : virtual bool CopyTo( BaseStorageStream * pDestStm ) SAL_OVERRIDE;
259 : virtual bool Commit() SAL_OVERRIDE;
260 : virtual bool Revert() SAL_OVERRIDE;
261 : virtual bool Validate( bool=false ) const SAL_OVERRIDE;
262 : virtual bool ValidateMode( StreamMode ) const SAL_OVERRIDE;
263 : const SvStream* GetSvStream() const SAL_OVERRIDE;
264 : virtual bool Equals( const BaseStorageStream& rStream ) const SAL_OVERRIDE;
265 : bool SetProperty( const OUString& rName, const ::com::sun::star::uno::Any& rValue );
266 :
267 : SvStream* GetModifySvStream();
268 : };
269 :
270 : namespace ucbhelper
271 : {
272 : class Content;
273 : }
274 :
275 : class UCBStorage_Impl;
276 : struct UCBStorageElement_Impl;
277 : class SOT_DLLPUBLIC UCBStorage : public BaseStorage
278 : {
279 : UCBStorage_Impl* pImp;
280 :
281 : protected:
282 : virtual ~UCBStorage();
283 : public:
284 : static bool IsStorageFile( SvStream* );
285 : static bool IsDiskSpannedFile( SvStream* );
286 : static OUString GetLinkedFile( SvStream& );
287 : static OUString CreateLinkFile( const OUString& rName );
288 :
289 : UCBStorage( const ::ucbhelper::Content& rContent, const OUString& rName, StreamMode nMode, bool bDirect = true, bool bIsRoot = true );
290 : UCBStorage( const OUString& rName,
291 : StreamMode nMode,
292 : bool bDirect = true,
293 : bool bIsRoot = true );
294 :
295 : UCBStorage( const OUString& rName,
296 : StreamMode nMode,
297 : bool bDirect,
298 : bool bIsRoot,
299 : bool bIsRepair,
300 : ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XProgressHandler >
301 : xProgressHandler );
302 :
303 : UCBStorage( UCBStorage_Impl* );
304 : UCBStorage( SvStream& rStrm, bool bDirect = true );
305 :
306 : TYPEINFO_OVERRIDE();
307 : virtual const OUString& GetName() const SAL_OVERRIDE;
308 : virtual bool IsRoot() const SAL_OVERRIDE;
309 : virtual void SetClassId( const ClsId& ) SAL_OVERRIDE;
310 : virtual const ClsId& GetClassId() const SAL_OVERRIDE;
311 : virtual void SetDirty() SAL_OVERRIDE;
312 : virtual void SetClass( const SvGlobalName & rClass,
313 : sal_uLong nOriginalClipFormat,
314 : const OUString & rUserTypeName ) SAL_OVERRIDE;
315 : virtual void SetConvertClass( const SvGlobalName & rConvertClass,
316 : sal_uLong nOriginalClipFormat,
317 : const OUString & rUserTypeName ) SAL_OVERRIDE;
318 : virtual SvGlobalName GetClassName() SAL_OVERRIDE;
319 : virtual sal_uLong GetFormat() SAL_OVERRIDE;
320 : virtual OUString GetUserName() SAL_OVERRIDE;
321 : virtual bool ShouldConvert() SAL_OVERRIDE;
322 : virtual void FillInfoList( SvStorageInfoList* ) const SAL_OVERRIDE;
323 : virtual bool CopyTo( BaseStorage* pDestStg ) const SAL_OVERRIDE;
324 : virtual bool Commit() SAL_OVERRIDE;
325 : virtual bool Revert() SAL_OVERRIDE;
326 : virtual BaseStorageStream* OpenStream( const OUString & rEleName,
327 : StreamMode = STREAM_STD_READWRITE,
328 : bool bDirect = true, const OString* pKey=0 ) SAL_OVERRIDE;
329 : virtual BaseStorage* OpenStorage( const OUString & rEleName,
330 : StreamMode = STREAM_STD_READWRITE,
331 : bool bDirect = false ) SAL_OVERRIDE;
332 : virtual BaseStorage* OpenUCBStorage( const OUString & rEleName,
333 : StreamMode = STREAM_STD_READWRITE,
334 : bool bDirect = false ) SAL_OVERRIDE;
335 : virtual BaseStorage* OpenOLEStorage( const OUString & rEleName,
336 : StreamMode = STREAM_STD_READWRITE,
337 : bool bDirect = false ) SAL_OVERRIDE;
338 : virtual bool IsStream( const OUString& rEleName ) const SAL_OVERRIDE;
339 : virtual bool IsStorage( const OUString& rEleName ) const SAL_OVERRIDE;
340 : virtual bool IsContained( const OUString& rEleName ) const SAL_OVERRIDE;
341 : virtual bool Remove( const OUString & rEleName ) SAL_OVERRIDE;
342 : virtual bool Rename( const OUString & rEleName, const OUString & rNewName ) SAL_OVERRIDE;
343 : virtual bool CopyTo( const OUString & rEleName, BaseStorage * pDest, const OUString & rNewName ) SAL_OVERRIDE;
344 : virtual bool MoveTo( const OUString & rEleName, BaseStorage * pDest, const OUString & rNewName ) SAL_OVERRIDE;
345 : virtual bool ValidateFAT() SAL_OVERRIDE;
346 : virtual bool Validate( bool=false ) const SAL_OVERRIDE;
347 : virtual bool ValidateMode( StreamMode ) const SAL_OVERRIDE;
348 : virtual const SvStream* GetSvStream() const SAL_OVERRIDE;
349 : virtual bool Equals( const BaseStorage& rStream ) const SAL_OVERRIDE;
350 : bool GetProperty( const OUString& rEleName, const OUString& rName, ::com::sun::star::uno::Any& rValue );
351 :
352 : UCBStorageElement_Impl* FindElement_Impl( const OUString& rName ) const;
353 : bool CopyStorageElement_Impl( UCBStorageElement_Impl& rElement,
354 : BaseStorage* pDest, const OUString& rNew ) const;
355 : BaseStorage* OpenStorage_Impl( const OUString & rEleName,
356 : StreamMode, bool bDirect, bool bForceUCBStorage );
357 :
358 : };
359 :
360 : #endif
361 :
362 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|