Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SOT_STORAGE_HXX
21 : #define INCLUDED_SOT_STORAGE_HXX
22 :
23 : #include <com/sun/star/uno/Any.hxx>
24 : #include <com/sun/star/uno/Reference.h>
25 :
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>
34 :
35 : class SotStorage;
36 :
37 : enum class SotClipboardFormatId : sal_uLong;
38 :
39 : /*************************************************************************
40 : *************************************************************************/
41 : class SotStorage;
42 : class BaseStorageStream;
43 : class SOT_DLLPUBLIC SotStorageStream : virtual public SotObject, public SvStream
44 : {
45 : friend class SotStorage;
46 : BaseStorageStream * pOwnStm; // pointer to the own stream
47 : protected:
48 : virtual sal_uLong GetData( void* pData, sal_uLong nSize ) SAL_OVERRIDE;
49 : virtual sal_uLong PutData( const void* pData, sal_uLong nSize ) SAL_OVERRIDE;
50 : virtual sal_uInt64 SeekPos(sal_uInt64 nPos) SAL_OVERRIDE;
51 : virtual void FlushData() SAL_OVERRIDE;
52 : virtual ~SotStorageStream();
53 : public:
54 : SotStorageStream( const OUString &,
55 0 : StreamMode = STREAM_STD_READWRITE );
56 : SotStorageStream( BaseStorageStream *pStm );
57 : SotStorageStream();
58 :
59 : private:
60 0 : static SotFactory ** GetFactoryAdress()
61 0 : { return &(SOTDATA()->pSotStorageStreamFactory); }
62 : public:
63 : static void * CreateInstance( SotObject ** = NULL );
64 : static SotFactory * ClassFactory();
65 : virtual const SotFactory * GetSvFactory() const SAL_OVERRIDE;
66 : virtual void * Cast( const SotFactory * ) SAL_OVERRIDE;
67 :
68 : virtual void ResetError() SAL_OVERRIDE;
69 :
70 : virtual void SetSize( sal_uInt64 nNewSize ) SAL_OVERRIDE;
71 : sal_uInt32 GetSize() const;
72 : bool CopyTo( SotStorageStream * pDestStm );
73 : bool Commit();
74 : bool SetProperty( const OUString& rName, const ::com::sun::star::uno::Any& rValue );
75 : virtual sal_uInt64 remainingSize() SAL_OVERRIDE;
76 : };
77 :
78 : namespace ucbhelper
79 : {
80 : class Content;
81 : }
82 :
83 : class BaseStorage;
84 : class UNOStorageHolder;
85 : class SOT_DLLPUBLIC SotStorage : virtual public SotObject
86 : {
87 : friend class SotStorageStream;
88 :
89 : BaseStorage * m_pOwnStg; // target storage
90 : SvStream * m_pStorStm; // only for SDSTORAGES
91 : sal_uLong m_nError;
92 : OUString m_aName; // name of the storage
93 : bool m_bIsRoot; // e.g.: File Storage
94 : bool m_bDelStm;
95 : OString m_aKey; // aKey.Len != 0 -> encryption
96 : long m_nVersion;
97 :
98 : protected:
99 : virtual ~SotStorage();
100 : void CreateStorage( bool bUCBStorage, StreamMode, bool transacted );
101 : public:
102 : SotStorage( const OUString &,
103 2006 : StreamMode = STREAM_STD_READWRITE,
104 : bool transacted = false );
105 : SotStorage( bool bUCBStorage, const OUString &,
106 0 : StreamMode = STREAM_STD_READWRITE );
107 : SotStorage( BaseStorage * );
108 : SotStorage( SvStream & rStm );
109 : SotStorage( bool bUCBStorage, SvStream & rStm );
110 : SotStorage( SvStream * pStm, bool bDelete );
111 : SotStorage();
112 :
113 : private:
114 0 : static SotFactory ** GetFactoryAdress()
115 0 : { return &(SOTDATA()->pSotStorageFactory); }
116 : public:
117 : static void * CreateInstance( SotObject ** = NULL );
118 : static SotFactory * ClassFactory();
119 : virtual const SotFactory * GetSvFactory() const SAL_OVERRIDE;
120 : virtual void * Cast( const SotFactory * ) SAL_OVERRIDE;
121 :
122 : SvMemoryStream * CreateMemoryStream();
123 :
124 : static bool IsStorageFile( const OUString & rFileName );
125 : static bool IsStorageFile( SvStream* pStream );
126 :
127 : const OUString& GetName() const;
128 :
129 : bool Validate();
130 :
131 13 : const OString& GetKey() const { return m_aKey;}
132 :
133 0 : void SetVersion( long nVers )
134 : {
135 0 : m_nVersion = nVers;
136 0 : }
137 13 : long GetVersion() const
138 : {
139 13 : return m_nVersion;
140 : }
141 :
142 : sal_uLong GetErrorCode() const { return m_nError; }
143 1817 : sal_uLong GetError() const { return ERRCODE_TOERROR(m_nError); }
144 6117 : void SetError( sal_uLong nErrorCode )
145 : {
146 6117 : if( m_nError == SVSTREAM_OK )
147 6096 : m_nError = nErrorCode;
148 6117 : }
149 :
150 : bool IsRoot() const { return m_bIsRoot; }
151 4049 : void SignAsRoot( bool b = true ) { m_bIsRoot = b; }
152 : void SetDeleteStream( bool bDelete ) { m_bDelStm = bDelete; }
153 :
154 : // own data sector
155 : void SetClass( const SvGlobalName & rClass,
156 : SotClipboardFormatId bOriginalClipFormat,
157 : const OUString & rUserTypeName );
158 : SvGlobalName GetClassName(); // type of data in the storage
159 : SotClipboardFormatId GetFormat();
160 : OUString GetUserName();
161 :
162 : // list of all elements
163 : void FillInfoList( SvStorageInfoList * ) const;
164 : bool CopyTo( SotStorage * pDestStg );
165 : bool Commit();
166 :
167 : // create stream with connection to Storage,
168 : // more or less a Parent-Child relationship
169 : SotStorageStream * OpenSotStream( const OUString & rEleName,
170 291 : StreamMode = STREAM_STD_READWRITE );
171 : SotStorage * OpenSotStorage( const OUString & rEleName,
172 37 : StreamMode = STREAM_STD_READWRITE,
173 : bool transacted = true );
174 : // query whether Storage or Stream
175 : bool IsStream( const OUString & rEleName ) const;
176 : bool IsStorage( const OUString & rEleName ) const;
177 : bool IsContained( const OUString & rEleName ) const;
178 : // remove element
179 : bool Remove( const OUString & rEleName );
180 : bool CopyTo( const OUString & rEleName, SotStorage * pDest,
181 : const OUString & rNewName );
182 :
183 : bool IsOLEStorage() const;
184 : static bool IsOLEStorage( const OUString & rFileName );
185 : static bool IsOLEStorage( SvStream* pStream );
186 :
187 : static SotStorage* OpenOLEStorage( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& xStorage,
188 0 : const OUString& rEleName, StreamMode = STREAM_STD_READWRITE );
189 : static SotClipboardFormatId GetFormatID( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& xStorage );
190 : static sal_Int32 GetVersion( const com::sun::star::uno::Reference < com::sun::star::embed::XStorage >& xStorage );
191 : };
192 :
193 : #endif // _SVSTOR_HXX
194 :
195 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|