xref: /aoo41x/main/sot/inc/sot/storage.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _SOT_STORAGE_HXX
29 #define _SOT_STORAGE_HXX
30 
31 #include <com/sun/star/uno/Any.hxx>
32 #include <com/sun/star/uno/Reference.h>
33 
34 #ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_H_
35 #include <com/sun/star/io/XInputStream.hpp>
36 #endif
37 #include <com/sun/star/embed/XStorage.hpp>
38 #include <sot/object.hxx>
39 #include <sot/factory.hxx>
40 #ifndef _TOOLS_STREAM_HXX
41 #include <tools/stream.hxx>
42 #endif
43 #ifndef _TOOLS_ERRCODE_HXX
44 #include <tools/errcode.hxx>
45 #endif
46 #include "sot/sotdllapi.h"
47 
48 #define STORAGE_FAILIFTHERE		0x02
49 #define STORAGE_TRANSACTED		0x04
50 #define STORAGE_PRIORITY		0x08
51 #define STORAGE_DELETEONRELEASE	0x10
52 #define STORAGE_CONVERT			0x20
53 #define STORAGE_UNPACKED_MODE   0x40
54 #define STORAGE_DISKSPANNED_MODE   0x80
55 #define STORAGE_CREATE_UNPACKED 0x44
56 typedef short StorageMode;
57 
58 class SvStorage;
59 namespace binfilter
60 {
61 	class SvStorage;
62 }
63 
64 /*************************************************************************
65 *************************************************************************/
66 class SotStorage;
67 class BaseStorageStream;
68 class SOT_DLLPUBLIC SotStorageStream : virtual public SotObject, public SvStream
69 {
70 friend class SotStorage;
71 friend class ImpStream;
72     BaseStorageStream * pOwnStm;// Zeiger auf den eigenen Stream
73 protected:
74     virtual sal_uLong       GetData( void* pData, sal_uLong nSize );
75     virtual sal_uLong       PutData( const void* pData, sal_uLong nSize );
76     virtual sal_uLong       SeekPos( sal_uLong nPos );
77     virtual void        FlushData();
78                         ~SotStorageStream();
79 public:
80                         SotStorageStream( const String &,
81                                      StreamMode = STREAM_STD_READWRITE,
82                                      StorageMode = 0 );
83                         SotStorageStream( BaseStorageStream *pStm );
84                         SotStorageStream();
85                         SO2_DECL_BASIC_CLASS_DLL(SotStorageStream,SOTDATA())
86 						SO2_DECL_INVARIANT()
87 
88     using SvStream::SyncSvStream;
89 	virtual void 		SyncSvStream();
90 	void 				SyncSysStream() { SvStream::SyncSysStream(); }
91 
92     virtual void        ResetError();
93 
94     virtual void        SetSize( sal_uLong nNewSize );
95     sal_uInt32				GetSize() const;
96     sal_Bool				CopyTo( SotStorageStream * pDestStm );
97     virtual sal_Bool        Commit();
98     virtual sal_Bool        Revert();
99     sal_Bool                SetProperty( const String& rName, const ::com::sun::star::uno::Any& rValue );
100     sal_Bool                GetProperty( const String& rName, ::com::sun::star::uno::Any& rValue );
101 	::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >
102 						GetXInputStream() const;
103 };
104 
105 #ifndef SOT_DECL_SOTSTORAGESTREAM_DEFINED
106 #define SOT_DECL_SOTSTORAGESTREAM_DEFINED
107 SO2_DECL_REF(SotStorageStream)
108 #endif
109 SO2_IMPL_REF(SotStorageStream)
110 
111 namespace ucbhelper
112 {
113 	class Content;
114 }
115 
116 class  SvStorageInfoList;
117 class  BaseStorage;
118 class  UNOStorageHolder;
119 class SOT_DLLPUBLIC SotStorage : virtual public SotObject
120 {
121 friend class SotStorageStream;
122 friend class SvStorage;
123 friend class ::binfilter::SvStorage;
124 
125     BaseStorage *   m_pTmpStg;   // Temp-Storage fuer Transacted, nur auf diesem schreiben!        ??? Useless ???
126     BaseStorage *   m_pOwnStg;   // Zielstorage
127     SvStream *  m_pStorStm;  // nur fuer SDSTORAGES
128     sal_uLong       m_nError;
129     String      m_aName;      // Name des Storage
130     sal_Bool        m_bIsRoot:1,  // z.B.: File-Storage
131                 m_bDelStm:1;
132     ByteString  m_aKey;           // aKey.Len != 0  -> Verschluesselung
133 	long 		m_nVersion;
134 
135 protected:
136                         ~SotStorage();
137    void 				CreateStorage( sal_Bool bUCBStorage, StreamMode, StorageMode );
138 public:
139                         SotStorage( const String &,
140                                    StreamMode = STREAM_STD_READWRITE,
141                                    StorageMode = 0 );
142                         SotStorage( sal_Bool bUCBStorage, const String &,
143                                    StreamMode = STREAM_STD_READWRITE,
144                                    StorageMode = 0 );
145                         SotStorage( const ::ucbhelper::Content& rContent, const String &,
146                                    StreamMode = STREAM_STD_READWRITE,
147                                    StorageMode = 0 );
148                         SotStorage( BaseStorage * );
149                         SotStorage( SvStream & rStm );
150                         SotStorage( sal_Bool bUCBStorage, SvStream & rStm );
151                         SotStorage( SvStream * pStm, sal_Bool bDelete );
152                         SotStorage();
153                         SO2_DECL_BASIC_CLASS_DLL(SotStorage,SOTDATA())
154 						SO2_DECL_INVARIANT()
155 
156     SvMemoryStream *    CreateMemoryStream();
157 	const SvStream *	GetSvStream();
158 
159     static sal_Bool         IsStorageFile( const String & rFileName );
160     static sal_Bool         IsStorageFile( SvStream* pStream );
161 
162     virtual const String & GetName() const;
163 
164 	virtual sal_Bool        Validate();
165 
166     void                SetKey( const ByteString& rKey );
167     const ByteString &  GetKey() const { return m_aKey; }
168 
169 	void				SetVersion( long nVers )
170 						{
171 							m_nVersion = nVers;
172 						}
173 	long				GetVersion() const
174 						{
175 							return m_nVersion;
176 						}
177 
178     sal_uLong               GetErrorCode() const { return m_nError; }
179     sal_uLong               GetError() const { return ERRCODE_TOERROR(m_nError); }
180     void                SetError( sal_uLong nErrorCode )
181                         {
182                             if( m_nError == SVSTREAM_OK )
183                                 m_nError = nErrorCode;
184                         }
185     virtual void        ResetError();
186 
187     sal_Bool                IsRoot() const              { return m_bIsRoot; }
188     void                SignAsRoot( sal_Bool b = sal_True ) { m_bIsRoot = b; }
189 	void				SetDeleteStream( sal_Bool bDelete ) { m_bDelStm = bDelete; }
190 
191                         // eigener Datenbereich
192     virtual void        SetClass( const SvGlobalName & rClass,
193                                   sal_uLong bOriginalClipFormat,
194                                   const String & rUserTypeName );
195     virtual void        SetConvertClass( const SvGlobalName & rConvertClass,
196                                          sal_uLong bOriginalClipFormat,
197                                          const String & rUserTypeName );
198     virtual SvGlobalName GetClassName();// Typ der Daten im Storage
199     virtual sal_uLong       GetFormat();
200     virtual String      GetUserName();
201     virtual sal_Bool        ShouldConvert();
202     void                SetName( const String& rName );
203 
204                         // Liste aller Elemente
205     virtual void        FillInfoList( SvStorageInfoList * ) const;
206     virtual sal_Bool        CopyTo( SotStorage * pDestStg );
207     virtual sal_Bool        Commit();
208     virtual sal_Bool        Revert();
209 
210                         /* Element Methoden     */
211                         // Stream mit Verbindung zu Storage erzeugen,
212                         // in etwa eine Parent-Child Beziehung
213     SotStorageStream *  OpenSotStream( const String & rEleName,
214                                     StreamMode = STREAM_STD_READWRITE,
215                                     StorageMode = 0 );
216     SotStorageStream *  OpenEncryptedSotStream( const String & rEleName, const ByteString& rKey,
217                                     StreamMode = STREAM_STD_READWRITE,
218                                     StorageMode = 0 );
219     SotStorage *		OpenSotStorage( const String & rEleName,
220                                     StreamMode = STREAM_STD_READWRITE,
221                                     StorageMode = STORAGE_TRANSACTED );
222     SotStorage *		OpenUCBStorage( const String & rEleName,
223                                     StreamMode = STREAM_STD_READWRITE,
224                                     StorageMode = STORAGE_TRANSACTED );
225     SotStorage *        OpenOLEStorage( const String & rEleName,
226                                     StreamMode = STREAM_STD_READWRITE,
227                                     StorageMode = STORAGE_TRANSACTED );
228                         // Abfrage auf Storage oder Stream
229     virtual sal_Bool        IsStream( const String & rEleName ) const;
230     virtual sal_Bool        IsStorage( const String & rEleName ) const;
231     virtual sal_Bool        IsContained( const String & rEleName ) const;
232                         // Element loeschen
233     virtual sal_Bool        Remove( const String & rEleName );
234                         // Elementnamen aendern
235     virtual sal_Bool        Rename( const String & rEleName,
236                                 const String & rNewName );
237     virtual sal_Bool        CopyTo( const String & rEleName, SotStorage * pDest,
238                                 const String & rNewName );
239     virtual sal_Bool        MoveTo( const String & rEleName, SotStorage * pDest,
240                                 const String & rNewName );
241 
242 	SvStream*			GetTargetSvStream() const;
243     sal_Bool                SetProperty( const String& rName, const ::com::sun::star::uno::Any& rValue );
244     sal_Bool                GetProperty( const String& rName, ::com::sun::star::uno::Any& rValue );
245     sal_Bool                GetProperty( const String& rEleName, const String& rName, ::com::sun::star::uno::Any& rValue );
246 	sal_Bool				IsOLEStorage() const;
247     static sal_Bool         IsOLEStorage( const String & rFileName );
248     static sal_Bool         IsOLEStorage( SvStream* pStream );
249 
250 	// this is temporary HACK, _MUST_ be removed before release
251 	::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
252 						GetUNOAPIDuplicate( const String& rEleName, sal_Int32 nUNOStorageMode );
253 	void				RemoveUNOStorageHolder( UNOStorageHolder* pHolder );
254 
255     static SotStorage*  OpenOLEStorage( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& xStorage,
256                                     const String& rEleName, StreamMode = STREAM_STD_READWRITE );
257     static sal_Int32    GetFormatID( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& xStorage );
258 	static sal_Int32	GetVersion( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& xStorage );
259 };
260 
261 #ifndef SOT_DECL_SOTSTORAGE_DEFINED
262 #define SOT_DECL_SOTSTORAGE_DEFINED
263 SO2_DECL_REF(SotStorage)
264 #endif
265 SO2_IMPL_REF(SotStorage)
266 
267 #define SvStorage SotStorage
268 #define SvStorageRef SotStorageRef
269 #define SvStorageStream SotStorageStream
270 #define SvStorageStreamRef SotStorageStreamRef
271 
272 #endif // _SVSTOR_HXX
273