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