1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: stg.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
34 #include <com/sun/star/uno/Any.h>
35 #include <com/sun/star/uno/Reference.h>
37 #ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_H_
38 #include <com/sun/star/io/XInputStream.hpp>
41 #ifndef _COM_SUN_STAR_UCB_XCOMMANDENVIRONMENT_H_
42 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
45 #ifndef _COM_SUN_STAR_EMBED_XSTORAGE_H_
46 #include <com/sun/star/embed/XStorage.hpp>
50 #include <tools/rtti.hxx>
51 #ifndef _TOOLS_STREAM_HXX //autogen
52 #include <tools/stream.hxx>
54 #ifndef _TOOLS_GLOBNAME_HXX //autogen
55 #include <tools/globname.hxx>
57 #include "sot/sotdllapi.h"
60 class UNOStorageHolder
;
61 typedef ::std::list
< UNOStorageHolder
* > UNOStorageHolderList
;
73 UINT8 n4
, n5
, n6
, n7
, n8
, n9
, n10
, n11
;
76 class SOT_DLLPUBLIC StorageBase
: public SvRefBase
79 ULONG m_nError
; // error code
80 StreamMode m_nMode
; // open mode
83 virtual ~StorageBase();
86 virtual const SvStream
* GetSvStream() const = 0;
87 virtual BOOL
Validate( BOOL
=FALSE
) const = 0;
88 virtual BOOL
ValidateMode( StreamMode
) const = 0;
89 void ResetError() const;
90 void SetError( ULONG
) const;
91 ULONG
GetError() const;
92 BOOL
Good() const { return BOOL( m_nError
== SVSTREAM_OK
); }
93 StreamMode
GetMode() const { return m_nMode
; }
94 void SetAutoCommit( BOOL bSet
)
95 { m_bAutoCommit
= bSet
; }
98 class BaseStorageStream
: public StorageBase
102 virtual ULONG
Read( void * pData
, ULONG nSize
) = 0;
103 virtual ULONG
Write( const void* pData
, ULONG nSize
) = 0;
104 virtual ULONG
Seek( ULONG nPos
) = 0;
105 virtual ULONG
Tell() = 0;
106 virtual void Flush() = 0;
107 virtual BOOL
SetSize( ULONG nNewSize
) = 0;
108 virtual BOOL
CopyTo( BaseStorageStream
* pDestStm
) = 0;
109 virtual BOOL
Commit() = 0;
110 virtual BOOL
Revert() = 0;
111 virtual BOOL
Equals( const BaseStorageStream
& rStream
) const = 0;
114 class SvStorageInfoList
;
115 class BaseStorage
: public StorageBase
119 virtual const String
& GetName() const = 0;
120 virtual BOOL
IsRoot() const = 0;
121 virtual void SetClassId( const ClsId
& ) = 0;
122 virtual const ClsId
& GetClassId() const = 0;
123 virtual void SetDirty() = 0;
124 virtual void SetClass( const SvGlobalName
& rClass
,
125 ULONG nOriginalClipFormat
,
126 const String
& rUserTypeName
) = 0;
127 virtual void SetConvertClass( const SvGlobalName
& rConvertClass
,
128 ULONG nOriginalClipFormat
,
129 const String
& rUserTypeName
) = 0;
130 virtual SvGlobalName
GetClassName() = 0;
131 virtual ULONG
GetFormat() = 0;
132 virtual String
GetUserName() = 0;
133 virtual BOOL
ShouldConvert() = 0;
134 virtual void FillInfoList( SvStorageInfoList
* ) const = 0;
135 virtual BOOL
CopyTo( BaseStorage
* pDestStg
) const = 0;
136 virtual BOOL
Commit() = 0;
137 virtual BOOL
Revert() = 0;
138 virtual BaseStorageStream
* OpenStream( const String
& rEleName
,
139 StreamMode
= STREAM_STD_READWRITE
,
140 BOOL bDirect
= TRUE
, const ByteString
* pKey
=0 ) = 0;
141 virtual BaseStorage
* OpenStorage( const String
& rEleName
,
142 StreamMode
= STREAM_STD_READWRITE
,
143 BOOL bDirect
= FALSE
) = 0;
144 virtual BaseStorage
* OpenUCBStorage( const String
& rEleName
,
145 StreamMode
= STREAM_STD_READWRITE
,
146 BOOL bDirect
= FALSE
) = 0;
147 virtual BaseStorage
* OpenOLEStorage( const String
& rEleName
,
148 StreamMode
= STREAM_STD_READWRITE
,
149 BOOL bDirect
= FALSE
) = 0;
150 virtual BOOL
IsStream( const String
& rEleName
) const = 0;
151 virtual BOOL
IsStorage( const String
& rEleName
) const = 0;
152 virtual BOOL
IsContained( const String
& rEleName
) const = 0;
153 virtual BOOL
Remove( const String
& rEleName
) = 0;
154 virtual BOOL
Rename( const String
& rEleName
, const String
& rNewName
) = 0;
155 virtual BOOL
CopyTo( const String
& rEleName
, BaseStorage
* pDest
, const String
& rNewName
) = 0;
156 virtual BOOL
MoveTo( const String
& rEleName
, BaseStorage
* pDest
, const String
& rNewName
) = 0;
157 virtual BOOL
ValidateFAT() = 0;
158 virtual BOOL
Equals( const BaseStorage
& rStream
) const = 0;
164 StreamMode
& nStreamMode
; // open mode
165 StgIo
* pIo
; // I/O subsystem
166 StgDirEntry
* pEntry
; // the dir entry
167 OLEStorageBase( StgIo
*, StgDirEntry
*, StreamMode
& );
169 BOOL
Validate_Impl( BOOL
=FALSE
) const;
170 BOOL
ValidateMode_Impl( StreamMode
, StgDirEntry
* p
= NULL
) const ;
171 const SvStream
* GetSvStream_Impl() const;
175 class StorageStream
: public BaseStorageStream
, public OLEStorageBase
177 //friend class Storage;
178 ULONG nPos
; // current position
183 StorageStream( StgIo
*, StgDirEntry
*, StreamMode
);
184 virtual ULONG
Read( void * pData
, ULONG nSize
);
185 virtual ULONG
Write( const void* pData
, ULONG nSize
);
186 virtual ULONG
Seek( ULONG nPos
);
187 virtual ULONG
Tell() { return nPos
; }
188 virtual void Flush();
189 virtual BOOL
SetSize( ULONG nNewSize
);
190 virtual BOOL
CopyTo( BaseStorageStream
* pDestStm
);
191 virtual BOOL
Commit();
192 virtual BOOL
Revert();
193 virtual BOOL
Validate( BOOL
=FALSE
) const;
194 virtual BOOL
ValidateMode( StreamMode
) const;
195 BOOL
ValidateMode( StreamMode
, StgDirEntry
* p
) const;
196 const SvStream
* GetSvStream() const;
197 virtual BOOL
Equals( const BaseStorageStream
& rStream
) const;
200 class UCBStorageStream
;
202 class SOT_DLLPUBLIC Storage
: public BaseStorage
, public OLEStorageBase
206 void Init( BOOL bCreate
);
207 Storage( StgIo
*, StgDirEntry
*, StreamMode
);
212 Storage( const String
&, StreamMode
= STREAM_STD_READWRITE
, BOOL bDirect
= TRUE
);
213 Storage( SvStream
& rStrm
, BOOL bDirect
= TRUE
);
214 Storage( UCBStorageStream
& rStrm
, BOOL bDirect
= TRUE
);
216 static BOOL
IsStorageFile( const String
& rFileName
);
217 static BOOL
IsStorageFile( SvStream
* );
219 virtual const String
& GetName() const;
220 virtual BOOL
IsRoot() const { return bIsRoot
; }
221 virtual void SetClassId( const ClsId
& );
222 virtual const ClsId
& GetClassId() const;
223 virtual void SetDirty();
224 virtual void SetClass( const SvGlobalName
& rClass
,
225 ULONG nOriginalClipFormat
,
226 const String
& rUserTypeName
);
227 virtual void SetConvertClass( const SvGlobalName
& rConvertClass
,
228 ULONG nOriginalClipFormat
,
229 const String
& rUserTypeName
);
230 virtual SvGlobalName
GetClassName();
231 virtual ULONG
GetFormat();
232 virtual String
GetUserName();
233 virtual BOOL
ShouldConvert();
234 virtual void FillInfoList( SvStorageInfoList
* ) const;
235 virtual BOOL
CopyTo( BaseStorage
* pDestStg
) const;
236 virtual BOOL
Commit();
237 virtual BOOL
Revert();
238 virtual BaseStorageStream
* OpenStream( const String
& rEleName
,
239 StreamMode
= STREAM_STD_READWRITE
,
240 BOOL bDirect
= TRUE
, const ByteString
* pKey
=0 );
241 virtual BaseStorage
* OpenStorage( const String
& rEleName
,
242 StreamMode
= STREAM_STD_READWRITE
,
243 BOOL bDirect
= FALSE
);
244 virtual BaseStorage
* OpenUCBStorage( const String
& rEleName
,
245 StreamMode
= STREAM_STD_READWRITE
,
246 BOOL bDirect
= FALSE
);
247 virtual BaseStorage
* OpenOLEStorage( const String
& rEleName
,
248 StreamMode
= STREAM_STD_READWRITE
,
249 BOOL bDirect
= FALSE
);
250 virtual BOOL
IsStream( const String
& rEleName
) const;
251 virtual BOOL
IsStorage( const String
& rEleName
) const;
252 virtual BOOL
IsContained( const String
& rEleName
) const;
253 virtual BOOL
Remove( const String
& rEleName
);
254 virtual BOOL
Rename( const String
& rEleName
, const String
& rNewName
);
255 virtual BOOL
CopyTo( const String
& rEleName
, BaseStorage
* pDest
, const String
& rNewName
);
256 virtual BOOL
MoveTo( const String
& rEleName
, BaseStorage
* pDest
, const String
& rNewName
);
257 virtual BOOL
ValidateFAT();
258 virtual BOOL
Validate( BOOL
=FALSE
) const;
259 virtual BOOL
ValidateMode( StreamMode
) const;
260 BOOL
ValidateMode( StreamMode
, StgDirEntry
* p
) const;
261 virtual const SvStream
* GetSvStream() const;
262 virtual BOOL
Equals( const BaseStorage
& rStream
) const;
265 class UCBStorageStream_Impl
;
266 class UCBStorageStream
: public BaseStorageStream
268 friend class UCBStorage
;
270 UCBStorageStream_Impl
*
276 UCBStorageStream( const String
& rName
, StreamMode nMode
, BOOL bDirect
, const ByteString
* pKey
=0 );
277 UCBStorageStream( const String
& rName
, StreamMode nMode
, BOOL bDirect
, const ByteString
* pKey
, BOOL bRepair
, ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XProgressHandler
> xProgress
);
278 UCBStorageStream( UCBStorageStream_Impl
* );
280 virtual ULONG
Read( void * pData
, ULONG nSize
);
281 virtual ULONG
Write( const void* pData
, ULONG nSize
);
282 virtual ULONG
Seek( ULONG nPos
);
283 virtual ULONG
Tell();
284 virtual void Flush();
285 virtual BOOL
SetSize( ULONG nNewSize
);
286 virtual BOOL
CopyTo( BaseStorageStream
* pDestStm
);
287 virtual BOOL
Commit();
288 virtual BOOL
Revert();
289 virtual BOOL
Validate( BOOL
=FALSE
) const;
290 virtual BOOL
ValidateMode( StreamMode
) const;
291 const SvStream
* GetSvStream() const;
292 virtual BOOL
Equals( const BaseStorageStream
& rStream
) const;
293 BOOL
SetProperty( const String
& rName
, const ::com::sun::star::uno::Any
& rValue
);
294 BOOL
GetProperty( const String
& rName
, ::com::sun::star::uno::Any
& rValue
);
296 SvStream
* GetModifySvStream();
298 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
> GetXInputStream() const;
306 class UCBStorage_Impl
;
307 struct UCBStorageElement_Impl
;
308 class SOT_DLLPUBLIC UCBStorage
: public BaseStorage
310 UCBStorage_Impl
* pImp
;
315 static BOOL
IsStorageFile( SvStream
* );
316 static BOOL
IsStorageFile( const String
& rName
);
317 static BOOL
IsDiskSpannedFile( SvStream
* );
318 static String
GetLinkedFile( SvStream
& );
319 static String
CreateLinkFile( const String
& rName
);
321 UCBStorage( const ::ucbhelper::Content
& rContent
, const String
& rName
, StreamMode nMode
, BOOL bDirect
= TRUE
, BOOL bIsRoot
= TRUE
);
322 UCBStorage( const String
& rName
,
325 BOOL bIsRoot
= TRUE
);
327 UCBStorage( const String
& rName
,
332 ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XProgressHandler
>
335 UCBStorage( UCBStorage_Impl
* );
336 UCBStorage( SvStream
& rStrm
, BOOL bDirect
= TRUE
);
339 virtual const String
& GetName() const;
340 virtual BOOL
IsRoot() const;
341 virtual void SetClassId( const ClsId
& );
342 virtual const ClsId
& GetClassId() const;
343 virtual void SetDirty();
344 virtual void SetClass( const SvGlobalName
& rClass
,
345 ULONG nOriginalClipFormat
,
346 const String
& rUserTypeName
);
347 virtual void SetConvertClass( const SvGlobalName
& rConvertClass
,
348 ULONG nOriginalClipFormat
,
349 const String
& rUserTypeName
);
350 virtual SvGlobalName
GetClassName();
351 virtual ULONG
GetFormat();
352 virtual String
GetUserName();
353 virtual BOOL
ShouldConvert();
354 virtual void FillInfoList( SvStorageInfoList
* ) const;
355 virtual BOOL
CopyTo( BaseStorage
* pDestStg
) const;
356 virtual BOOL
Commit();
357 virtual BOOL
Revert();
358 virtual BaseStorageStream
* OpenStream( const String
& rEleName
,
359 StreamMode
= STREAM_STD_READWRITE
,
360 BOOL bDirect
= TRUE
, const ByteString
* pKey
=0 );
361 virtual BaseStorage
* OpenStorage( const String
& rEleName
,
362 StreamMode
= STREAM_STD_READWRITE
,
363 BOOL bDirect
= FALSE
);
364 virtual BaseStorage
* OpenUCBStorage( const String
& rEleName
,
365 StreamMode
= STREAM_STD_READWRITE
,
366 BOOL bDirect
= FALSE
);
367 virtual BaseStorage
* OpenOLEStorage( const String
& rEleName
,
368 StreamMode
= STREAM_STD_READWRITE
,
369 BOOL bDirect
= FALSE
);
370 virtual BOOL
IsStream( const String
& rEleName
) const;
371 virtual BOOL
IsStorage( const String
& rEleName
) const;
372 virtual BOOL
IsContained( const String
& rEleName
) const;
373 virtual BOOL
Remove( const String
& rEleName
);
374 virtual BOOL
Rename( const String
& rEleName
, const String
& rNewName
);
375 virtual BOOL
CopyTo( const String
& rEleName
, BaseStorage
* pDest
, const String
& rNewName
);
376 virtual BOOL
MoveTo( const String
& rEleName
, BaseStorage
* pDest
, const String
& rNewName
);
377 virtual BOOL
ValidateFAT();
378 virtual BOOL
Validate( BOOL
=FALSE
) const;
379 virtual BOOL
ValidateMode( StreamMode
) const;
380 virtual const SvStream
* GetSvStream() const;
381 virtual BOOL
Equals( const BaseStorage
& rStream
) const;
382 BOOL
SetProperty( const String
& rName
, const ::com::sun::star::uno::Any
& rValue
);
383 BOOL
GetProperty( const String
& rName
, ::com::sun::star::uno::Any
& rValue
);
384 BOOL
GetProperty( const String
& rEleName
, const String
& rName
, ::com::sun::star::uno::Any
& rValue
);
386 // HACK to avoid incompatible build, can be done since this feature is only for development
387 // should be removed before release
388 UNOStorageHolderList
* GetUNOStorageHolderList();
390 //#if _SOLAR__PRIVATE
391 UCBStorageElement_Impl
* FindElement_Impl( const String
& rName
) const;
392 BOOL
CopyStorageElement_Impl( UCBStorageElement_Impl
& rElement
,
393 BaseStorage
* pDest
, const String
& rNew
) const;
394 BaseStorage
* OpenStorage_Impl( const String
& rEleName
,
395 StreamMode
, BOOL bDirect
, BOOL bForceUCBStorage
);