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