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 .
20 #ifndef INCLUDED_SOT_STG_HXX
21 #define INCLUDED_SOT_STG_HXX
23 #include <com/sun/star/uno/Any.h>
24 #include <com/sun/star/uno/Reference.h>
26 #include <com/sun/star/io/XInputStream.hpp>
28 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
30 #include <com/sun/star/embed/XStorage.hpp>
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>
46 typedef struct SvGUID ClsId
;
48 class SOT_DLLPUBLIC StorageBase
: public SvRefBase
51 sal_uLong m_nError
; // error code
52 StreamMode m_nMode
; // open mode
55 virtual ~StorageBase();
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 bool Good() const { return bool( m_nError
== SVSTREAM_OK
); }
65 StreamMode
GetMode() const { return m_nMode
; }
66 void SetAutoCommit( bool bSet
)
67 { m_bAutoCommit
= bSet
; }
70 class BaseStorageStream
: public StorageBase
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;
87 enum class SotClipboardFormatId
: sal_uLong
;
89 class BaseStorage
: public StorageBase
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 StreamMode
= STREAM_STD_READWRITE
,
114 bool bDirect
= true, const OString
* pKey
=0 ) = 0;
115 virtual BaseStorage
* OpenStorage( const OUString
& rEleName
,
116 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;
138 StreamMode
& nStreamMode
; // open mode
139 StgIo
* pIo
; // I/O subsystem
140 StgDirEntry
* pEntry
; // the dir entry
141 OLEStorageBase( StgIo
*, StgDirEntry
*, StreamMode
& );
143 bool Validate_Impl( bool=false ) const;
144 static bool ValidateMode_Impl( StreamMode
, StgDirEntry
* p
= NULL
);
145 const SvStream
* GetSvStream_Impl() const;
149 class StorageStream
: public BaseStorageStream
, public OLEStorageBase
151 //friend class Storage;
152 sal_uLong nPos
; // current position
154 virtual ~StorageStream();
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 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
;
174 class UCBStorageStream
;
176 class SOT_DLLPUBLIC Storage
: public BaseStorage
, public OLEStorageBase
180 void Init( bool bCreate
);
181 Storage( StgIo
*, StgDirEntry
*, StreamMode
);
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 );
190 static bool IsStorageFile( const OUString
& rFileName
);
191 static bool IsStorageFile( SvStream
* );
193 virtual const OUString
& GetName() const SAL_OVERRIDE
;
194 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
;
239 class UCBStorageStream_Impl
;
240 class UCBStorageStream
: public BaseStorageStream
242 friend class UCBStorage
;
244 UCBStorageStream_Impl
*
247 virtual ~UCBStorageStream();
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
* );
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
);
269 SvStream
* GetModifySvStream();
277 class UCBStorage_Impl
;
278 struct UCBStorageElement_Impl
;
279 class SOT_DLLPUBLIC UCBStorage
: public BaseStorage
281 UCBStorage_Impl
* pImp
;
284 virtual ~UCBStorage();
286 static bool IsStorageFile( SvStream
* );
287 static OUString
GetLinkedFile( SvStream
& );
289 UCBStorage( const ::ucbhelper::Content
& rContent
, const OUString
& rName
, StreamMode nMode
, bool bDirect
= true, bool bIsRoot
= true );
290 UCBStorage( const OUString
& rName
,
293 bool bIsRoot
= true );
295 UCBStorage( const OUString
& rName
,
300 ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XProgressHandler
>
303 UCBStorage( UCBStorage_Impl
* );
304 UCBStorage( SvStream
& rStrm
, bool bDirect
= true );
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
);
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
);
362 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */