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 _SOT_STORAGE_HXX
21 #define _SOT_STORAGE_HXX
23 #include <com/sun/star/uno/Any.hxx>
24 #include <com/sun/star/uno/Reference.h>
26 #include <com/sun/star/io/XInputStream.hpp>
27 #include <com/sun/star/embed/XStorage.hpp>
28 #include <sot/object.hxx>
29 #include <sot/factory.hxx>
30 #include <tools/stream.hxx>
31 #include <tools/errcode.hxx>
32 #include "sot/storinfo.hxx"
33 #include "sot/sotdllapi.h"
35 #define STORAGE_FAILIFTHERE 0x02
36 #define STORAGE_TRANSACTED 0x04
37 #define STORAGE_PRIORITY 0x08
38 #define STORAGE_DELETEONRELEASE 0x10
39 #define STORAGE_CONVERT 0x20
40 #define STORAGE_UNPACKED_MODE 0x40
41 #define STORAGE_DISKSPANNED_MODE 0x80
42 #define STORAGE_CREATE_UNPACKED 0x44
43 typedef short StorageMode
;
48 /*************************************************************************
49 *************************************************************************/
51 class BaseStorageStream
;
52 class SOT_DLLPUBLIC SotStorageStream
: virtual public SotObject
, public SvStream
54 friend class SotStorage
;
55 BaseStorageStream
* pOwnStm
;// Zeiger auf den eigenen Stream
57 virtual sal_uLong
GetData( void* pData
, sal_uLong nSize
);
58 virtual sal_uLong
PutData( const void* pData
, sal_uLong nSize
);
59 virtual sal_uLong
SeekPos( sal_uLong nPos
);
60 virtual void FlushData();
63 SotStorageStream( const String
&,
64 StreamMode
= STREAM_STD_READWRITE
,
66 SotStorageStream( BaseStorageStream
*pStm
);
68 SO2_DECL_BASIC_CLASS_DLL(SotStorageStream
,SOTDATA())
70 virtual void ResetError();
72 virtual void SetSize( sal_uLong nNewSize
);
73 sal_uInt32
GetSize() const;
74 sal_Bool
CopyTo( SotStorageStream
* pDestStm
);
75 virtual sal_Bool
Commit();
76 virtual sal_Bool
Revert();
77 sal_Bool
SetProperty( const String
& rName
, const ::com::sun::star::uno::Any
& rValue
);
78 virtual sal_Size
remainingSize();
81 #ifndef SOT_DECL_SOTSTORAGESTREAM_DEFINED
82 #define SOT_DECL_SOTSTORAGESTREAM_DEFINED
83 SV_DECL_REF(SotStorageStream
)
85 SV_IMPL_REF(SotStorageStream
)
93 class UNOStorageHolder
;
94 class SOT_DLLPUBLIC SotStorage
: virtual public SotObject
96 friend class SotStorageStream
;
97 friend class SvStorage
;
99 BaseStorage
* m_pTmpStg
; // Temp-Storage fuer Transacted, nur auf diesem schreiben! ??? Useless ???
100 BaseStorage
* m_pOwnStg
; // Zielstorage
101 SvStream
* m_pStorStm
; // nur fuer SDSTORAGES
103 String m_aName
; // Name des Storage
104 sal_Bool m_bIsRoot
:1, // z.B.: File-Storage
106 OString m_aKey
; // aKey.Len != 0 -> Verschluesselung
111 void CreateStorage( sal_Bool bUCBStorage
, StreamMode
, StorageMode
);
113 SotStorage( const String
&,
114 StreamMode
= STREAM_STD_READWRITE
,
116 SotStorage( sal_Bool bUCBStorage
, const String
&,
117 StreamMode
= STREAM_STD_READWRITE
,
119 SotStorage( BaseStorage
* );
120 SotStorage( SvStream
& rStm
);
121 SotStorage( sal_Bool bUCBStorage
, SvStream
& rStm
);
122 SotStorage( SvStream
* pStm
, sal_Bool bDelete
);
124 SO2_DECL_BASIC_CLASS_DLL(SotStorage
,SOTDATA())
126 SvMemoryStream
* CreateMemoryStream();
128 static sal_Bool
IsStorageFile( const String
& rFileName
);
129 static sal_Bool
IsStorageFile( SvStream
* pStream
);
131 virtual const String
& GetName() const;
133 virtual sal_Bool
Validate();
135 const OString
& GetKey() const;
137 void SetVersion( long nVers
)
141 long GetVersion() const
146 sal_uLong
GetErrorCode() const { return m_nError
; }
147 sal_uLong
GetError() const { return ERRCODE_TOERROR(m_nError
); }
148 void SetError( sal_uLong nErrorCode
)
150 if( m_nError
== SVSTREAM_OK
)
151 m_nError
= nErrorCode
;
153 virtual void ResetError();
155 sal_Bool
IsRoot() const { return m_bIsRoot
; }
156 void SignAsRoot( sal_Bool b
= sal_True
) { m_bIsRoot
= b
; }
157 void SetDeleteStream( sal_Bool bDelete
) { m_bDelStm
= bDelete
; }
159 // eigener Datenbereich
160 virtual void SetClass( const SvGlobalName
& rClass
,
161 sal_uLong bOriginalClipFormat
,
162 const String
& rUserTypeName
);
163 virtual void SetConvertClass( const SvGlobalName
& rConvertClass
,
164 sal_uLong bOriginalClipFormat
,
165 const String
& rUserTypeName
);
166 virtual SvGlobalName
GetClassName();// Typ der Daten im Storage
167 virtual sal_uLong
GetFormat();
168 virtual String
GetUserName();
169 virtual sal_Bool
ShouldConvert();
171 // Liste aller Elemente
172 virtual void FillInfoList( SvStorageInfoList
* ) const;
173 virtual sal_Bool
CopyTo( SotStorage
* pDestStg
);
174 virtual sal_Bool
Commit();
175 virtual sal_Bool
Revert();
177 /* Element Methoden */
178 // Stream mit Verbindung zu Storage erzeugen,
179 // in etwa eine Parent-Child Beziehung
180 SotStorageStream
* OpenSotStream( const String
& rEleName
,
181 StreamMode
= STREAM_STD_READWRITE
,
183 SotStorage
* OpenSotStorage( const String
& rEleName
,
184 StreamMode
= STREAM_STD_READWRITE
,
185 StorageMode
= STORAGE_TRANSACTED
);
186 // Abfrage auf Storage oder Stream
187 virtual sal_Bool
IsStream( const String
& rEleName
) const;
188 virtual sal_Bool
IsStorage( const String
& rEleName
) const;
189 virtual sal_Bool
IsContained( const String
& rEleName
) const;
191 virtual sal_Bool
Remove( const String
& rEleName
);
192 // Elementnamen aendern
193 virtual sal_Bool
Rename( const String
& rEleName
,
194 const String
& rNewName
);
195 virtual sal_Bool
CopyTo( const String
& rEleName
, SotStorage
* pDest
,
196 const String
& rNewName
);
197 virtual sal_Bool
MoveTo( const String
& rEleName
, SotStorage
* pDest
,
198 const String
& rNewName
);
200 sal_Bool
IsOLEStorage() const;
201 static sal_Bool
IsOLEStorage( const String
& rFileName
);
202 static sal_Bool
IsOLEStorage( SvStream
* pStream
);
204 static SotStorage
* OpenOLEStorage( const com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
>& xStorage
,
205 const String
& rEleName
, StreamMode
= STREAM_STD_READWRITE
);
206 static sal_Int32
GetFormatID( const com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
>& xStorage
);
207 static sal_Int32
GetVersion( const com::sun::star::uno::Reference
< com::sun::star::embed::XStorage
>& xStorage
);
210 #ifndef SOT_DECL_SOTSTORAGE_DEFINED
211 #define SOT_DECL_SOTSTORAGE_DEFINED
212 SV_DECL_REF(SotStorage
)
214 SV_IMPL_REF(SotStorage
)
216 #define SvStorage SotStorage
217 #define SvStorageRef SotStorageRef
218 #define SvStorageStream SotStorageStream
219 #define SvStorageStreamRef SotStorageStreamRef
221 #endif // _SVSTOR_HXX
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */