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 9743 : bool Good() const { return bool( m_nError == SVSTREAM_OK ); }
65 1574 : StreamMode GetMode() const { return m_nMode; }
66 6133 : void SetAutoCommit( bool bSet )
67 6133 : { m_bAutoCommit = bSet; }
68 : };
69 :
70 12606 : 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 : enum class SotClipboardFormatId : sal_uLong;
88 :
89 11742 : class BaseStorage : public StorageBase
90 : {
91 : public:
92 : TYPEINFO_OVERRIDE();
93 : virtual const OUString& GetName() const = 0;
94 : virtual bool IsRoot() const = 0;
95 : virtual void SetClassId( const ClsId& ) = 0;
96 : virtual const ClsId& GetClassId() const = 0;
97 : virtual void SetDirty() = 0;
98 : virtual void SetClass( const SvGlobalName & rClass,
99 : SotClipboardFormatId nOriginalClipFormat,
100 : const OUString & rUserTypeName ) = 0;
101 : virtual void SetConvertClass( const SvGlobalName & rConvertClass,
102 : SotClipboardFormatId nOriginalClipFormat,
103 : const OUString & rUserTypeName ) = 0;
104 : virtual SvGlobalName GetClassName() = 0;
105 : virtual SotClipboardFormatId GetFormat() = 0;
106 : virtual OUString GetUserName() = 0;
107 : virtual bool ShouldConvert() = 0;
108 : virtual void FillInfoList( SvStorageInfoList* ) const = 0;
109 : virtual bool CopyTo( BaseStorage* pDestStg ) const = 0;
110 : virtual bool Commit() = 0;
111 : virtual bool Revert() = 0;
112 : virtual BaseStorageStream* OpenStream( const OUString & rEleName,
113 893 : StreamMode = STREAM_STD_READWRITE,
114 : bool bDirect = true, const OString* pKey=0 ) = 0;
115 : virtual BaseStorage* OpenStorage( const OUString & rEleName,
116 98 : StreamMode = STREAM_STD_READWRITE,
117 : bool bDirect = false ) = 0;
118 : virtual BaseStorage* OpenUCBStorage( const OUString & rEleName,
119 : StreamMode = STREAM_STD_READWRITE,
120 : bool bDirect = false ) = 0;
121 : virtual BaseStorage* OpenOLEStorage( const OUString & rEleName,
122 : StreamMode = STREAM_STD_READWRITE,
123 : bool bDirect = false ) = 0;
124 : virtual bool IsStream( const OUString& rEleName ) const = 0;
125 : virtual bool IsStorage( const OUString& rEleName ) const = 0;
126 : virtual bool IsContained( const OUString& rEleName ) const = 0;
127 : virtual bool Remove( const OUString & rEleName ) = 0;
128 : virtual bool Rename( const OUString & rEleName, const OUString & rNewName ) = 0;
129 : virtual bool CopyTo( const OUString & rEleName, BaseStorage * pDest, const OUString & rNewName ) = 0;
130 : virtual bool MoveTo( const OUString & rEleName, BaseStorage * pDest, const OUString & rNewName ) = 0;
131 : virtual bool ValidateFAT() = 0;
132 : virtual bool Equals( const BaseStorage& rStream ) const = 0;
133 : };
134 :
135 : class OLEStorageBase
136 : {
137 : protected:
138 : StreamMode& nStreamMode; // open mode
139 : StgIo* pIo; // I/O subsystem
140 : StgDirEntry* pEntry; // the dir entry
141 : OLEStorageBase( StgIo*, StgDirEntry*, StreamMode& );
142 : ~OLEStorageBase();
143 : bool Validate_Impl( bool=false ) const;
144 : static bool ValidateMode_Impl( StreamMode, StgDirEntry* p = NULL );
145 : const SvStream* GetSvStream_Impl() const;
146 : public:
147 : };
148 :
149 : class StorageStream : public BaseStorageStream, public OLEStorageBase
150 : {
151 : //friend class Storage;
152 : sal_uLong nPos; // current position
153 : protected:
154 : virtual ~StorageStream();
155 : public:
156 : TYPEINFO_OVERRIDE();
157 : StorageStream( StgIo*, StgDirEntry*, StreamMode );
158 : virtual sal_uLong Read( void * pData, sal_uLong nSize ) SAL_OVERRIDE;
159 : virtual sal_uLong Write( const void* pData, sal_uLong nSize ) SAL_OVERRIDE;
160 : virtual sal_uInt64 Seek( sal_uInt64 nPos ) SAL_OVERRIDE;
161 991 : virtual sal_uLong Tell() SAL_OVERRIDE { return nPos; }
162 : virtual void Flush() SAL_OVERRIDE;
163 : virtual bool SetSize( sal_uLong nNewSize ) SAL_OVERRIDE;
164 : virtual sal_uLong GetSize() const SAL_OVERRIDE;
165 : virtual bool CopyTo( BaseStorageStream * pDestStm ) SAL_OVERRIDE;
166 : virtual bool Commit() SAL_OVERRIDE;
167 : virtual bool Revert() SAL_OVERRIDE;
168 : virtual bool Validate( bool=false ) const SAL_OVERRIDE;
169 : virtual bool ValidateMode( StreamMode ) const SAL_OVERRIDE;
170 : const SvStream* GetSvStream() const SAL_OVERRIDE;
171 : virtual bool Equals( const BaseStorageStream& rStream ) const SAL_OVERRIDE;
172 : };
173 :
174 : class UCBStorageStream;
175 :
176 : class SOT_DLLPUBLIC Storage : public BaseStorage, public OLEStorageBase
177 : {
178 : OUString aName;
179 : bool bIsRoot;
180 : void Init( bool bCreate );
181 : Storage( StgIo*, StgDirEntry*, StreamMode );
182 : protected:
183 : virtual ~Storage();
184 : public:
185 : TYPEINFO_OVERRIDE();
186 : Storage( const OUString &, StreamMode = STREAM_STD_READWRITE, bool bDirect = true );
187 : Storage( SvStream& rStrm, bool bDirect = true );
188 : Storage( UCBStorageStream& rStrm, bool bDirect = true );
189 :
190 : static bool IsStorageFile( const OUString & rFileName );
191 : static bool IsStorageFile( SvStream* );
192 :
193 : virtual const OUString& GetName() const SAL_OVERRIDE;
194 2013 : virtual bool IsRoot() const SAL_OVERRIDE { return bIsRoot; }
195 : virtual void SetClassId( const ClsId& ) SAL_OVERRIDE;
196 : virtual const ClsId& GetClassId() const SAL_OVERRIDE;
197 : virtual void SetDirty() SAL_OVERRIDE;
198 : virtual void SetClass( const SvGlobalName & rClass,
199 : SotClipboardFormatId nOriginalClipFormat,
200 : const OUString & rUserTypeName ) SAL_OVERRIDE;
201 : virtual void SetConvertClass( const SvGlobalName & rConvertClass,
202 : SotClipboardFormatId nOriginalClipFormat,
203 : const OUString & rUserTypeName ) SAL_OVERRIDE;
204 : virtual SvGlobalName GetClassName() SAL_OVERRIDE;
205 : virtual SotClipboardFormatId GetFormat() SAL_OVERRIDE;
206 : virtual OUString GetUserName() SAL_OVERRIDE;
207 : virtual bool ShouldConvert() SAL_OVERRIDE;
208 : virtual void FillInfoList( SvStorageInfoList* ) const SAL_OVERRIDE;
209 : virtual bool CopyTo( BaseStorage* pDestStg ) const SAL_OVERRIDE;
210 : virtual bool Commit() SAL_OVERRIDE;
211 : virtual bool Revert() SAL_OVERRIDE;
212 : virtual BaseStorageStream* OpenStream( const OUString & rEleName,
213 : StreamMode = STREAM_STD_READWRITE,
214 : bool bDirect = true, const OString* pKey=0 ) SAL_OVERRIDE;
215 : virtual BaseStorage* OpenStorage( const OUString & rEleName,
216 : StreamMode = STREAM_STD_READWRITE,
217 : bool bDirect = false ) SAL_OVERRIDE;
218 : virtual BaseStorage* OpenUCBStorage( const OUString & rEleName,
219 : StreamMode = STREAM_STD_READWRITE,
220 : bool bDirect = false ) SAL_OVERRIDE;
221 : virtual BaseStorage* OpenOLEStorage( const OUString & rEleName,
222 : StreamMode = STREAM_STD_READWRITE,
223 : bool bDirect = false ) SAL_OVERRIDE;
224 : virtual bool IsStream( const OUString& rEleName ) const SAL_OVERRIDE;
225 : virtual bool IsStorage( const OUString& rEleName ) const SAL_OVERRIDE;
226 : virtual bool IsContained( const OUString& rEleName ) const SAL_OVERRIDE;
227 : virtual bool Remove( const OUString & rEleName ) SAL_OVERRIDE;
228 : virtual bool Rename( const OUString & rEleName, const OUString & rNewName ) SAL_OVERRIDE;
229 : virtual bool CopyTo( const OUString & rEleName, BaseStorage * pDest, const OUString & rNewName ) SAL_OVERRIDE;
230 : virtual bool MoveTo( const OUString & rEleName, BaseStorage * pDest, const OUString & rNewName ) SAL_OVERRIDE;
231 : virtual bool ValidateFAT() SAL_OVERRIDE;
232 : virtual bool Validate( bool=false ) const SAL_OVERRIDE;
233 : virtual bool ValidateMode( StreamMode ) const SAL_OVERRIDE;
234 : bool ValidateMode( StreamMode, StgDirEntry* p ) const;
235 : virtual const SvStream* GetSvStream() const SAL_OVERRIDE;
236 : virtual bool Equals( const BaseStorage& rStream ) const SAL_OVERRIDE;
237 : };
238 :
239 : class UCBStorageStream_Impl;
240 : class UCBStorageStream : public BaseStorageStream
241 : {
242 : friend class UCBStorage;
243 :
244 : UCBStorageStream_Impl*
245 : pImp;
246 : protected:
247 : virtual ~UCBStorageStream();
248 : public:
249 : TYPEINFO_OVERRIDE();
250 : UCBStorageStream( const OUString& rName, StreamMode nMode, bool bDirect, const OString* pKey, bool bRepair, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XProgressHandler > xProgress );
251 : UCBStorageStream( UCBStorageStream_Impl* );
252 :
253 : virtual sal_uLong Read( void * pData, sal_uLong nSize ) SAL_OVERRIDE;
254 : virtual sal_uLong Write( const void* pData, sal_uLong nSize ) SAL_OVERRIDE;
255 : virtual sal_uInt64 Seek( sal_uInt64 nPos ) SAL_OVERRIDE;
256 : virtual sal_uLong Tell() SAL_OVERRIDE;
257 : virtual void Flush() SAL_OVERRIDE;
258 : virtual bool SetSize( sal_uLong nNewSize ) SAL_OVERRIDE;
259 : virtual sal_uLong GetSize() const SAL_OVERRIDE;
260 : virtual bool CopyTo( BaseStorageStream * pDestStm ) SAL_OVERRIDE;
261 : virtual bool Commit() SAL_OVERRIDE;
262 : virtual bool Revert() SAL_OVERRIDE;
263 : virtual bool Validate( bool=false ) const SAL_OVERRIDE;
264 : virtual bool ValidateMode( StreamMode ) const SAL_OVERRIDE;
265 : const SvStream* GetSvStream() const SAL_OVERRIDE;
266 : virtual bool Equals( const BaseStorageStream& rStream ) const SAL_OVERRIDE;
267 : bool SetProperty( const OUString& rName, const ::com::sun::star::uno::Any& rValue );
268 :
269 : SvStream* GetModifySvStream();
270 : };
271 :
272 : namespace ucbhelper
273 : {
274 : class Content;
275 : }
276 :
277 : class UCBStorage_Impl;
278 : struct UCBStorageElement_Impl;
279 : class SOT_DLLPUBLIC UCBStorage : public BaseStorage
280 : {
281 : UCBStorage_Impl* pImp;
282 :
283 : protected:
284 : virtual ~UCBStorage();
285 : public:
286 : static bool IsStorageFile( SvStream* );
287 : static OUString GetLinkedFile( SvStream& );
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 : SotClipboardFormatId nOriginalClipFormat,
314 : const OUString & rUserTypeName ) SAL_OVERRIDE;
315 : virtual void SetConvertClass( const SvGlobalName & rConvertClass,
316 : SotClipboardFormatId nOriginalClipFormat,
317 : const OUString & rUserTypeName ) SAL_OVERRIDE;
318 : virtual SvGlobalName GetClassName() SAL_OVERRIDE;
319 : virtual SotClipboardFormatId 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: */
|