Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / oox / helper / storagebase.hxx
blob7f88c5ff21230201398a2cb2ef7472059b3da2f0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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_OOX_HELPER_STORAGEBASE_HXX
21 #define INCLUDED_OOX_HELPER_STORAGEBASE_HXX
23 #include <functional>
24 #include <memory>
25 #include <vector>
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <oox/dllapi.h>
29 #include <oox/helper/refmap.hxx>
30 #include <rtl/ustring.hxx>
32 namespace com { namespace sun { namespace star {
33 namespace embed { class XStorage; }
34 namespace io { class XInputStream; }
35 namespace io { class XOutputStream; }
36 namespace io { class XStream; }
37 } } }
39 namespace oox {
42 class StorageBase;
43 typedef std::shared_ptr< StorageBase > StorageRef;
45 /** Base class for storage access implementations.
47 Derived classes will be used to encapsulate storage access implementations
48 for ZIP storages containing XML streams, and OLE storages containing binary
49 data streams.
51 class OOX_DLLPUBLIC StorageBase
53 public:
54 explicit StorageBase(
55 const css::uno::Reference< css::io::XInputStream >& rxInStream,
56 bool bBaseStreamAccess );
58 explicit StorageBase(
59 const css::uno::Reference< css::io::XStream >& rxOutStream,
60 bool bBaseStreamAccess );
62 virtual ~StorageBase();
64 /** Returns true, if the object represents a valid storage. */
65 bool isStorage() const;
67 /** Returns true, if the object represents the root storage. */
68 bool isRootStorage() const;
70 /** Returns true, if the storage operates in read-only mode (based on an
71 input stream). */
72 bool isReadOnly() const { return mbReadOnly;}
74 /** Returns the com.sun.star.embed.XStorage interface of the current storage. */
75 css::uno::Reference< css::embed::XStorage >
76 getXStorage() const;
78 /** Returns the element name of this storage. */
79 const OUString& getName() const { return maStorageName;}
81 /** Returns the full path of this storage. */
82 OUString getPath() const;
84 /** Fills the passed vector with the names of all direct elements of this
85 storage. */
86 void getElementNames( ::std::vector< OUString >& orElementNames ) const;
88 /** Opens and returns the specified sub storage from the storage.
90 @param rStorageName
91 The name of the embedded storage. The name may contain slashes to
92 open storages from embedded substorages.
93 @param bCreateMissing
94 True = create missing sub storages (for export filters). Must be
95 false for storages based on input streams.
97 StorageRef openSubStorage( const OUString& rStorageName, bool bCreateMissing );
99 /** Opens and returns the specified input stream from the storage.
101 @param rStreamName
102 The name of the embedded storage stream. The name may contain
103 slashes to open streams from embedded substorages. If base stream
104 access has been enabled in the constructor, the base stream can be
105 accessed by passing an empty string as stream name.
107 css::uno::Reference< css::io::XInputStream >
108 openInputStream( const OUString& rStreamName );
110 /** Opens and returns the specified output stream from the storage.
112 @param rStreamName
113 The name of the embedded storage stream. The name may contain
114 slashes to create and open streams in embedded substorages. If base
115 stream access has been enabled in the constructor, the base stream
116 can be accessed by passing an empty string as stream name.
118 css::uno::Reference< css::io::XOutputStream >
119 openOutputStream( const OUString& rStreamName );
121 /** Copies the specified element from this storage to the passed
122 destination storage.
124 @param rElementName
125 The name of the embedded storage or stream. The name may contain
126 slashes to specify an element in an embedded substorage. In this
127 case, the element will be copied to the same substorage in the
128 destination storage.
130 void copyToStorage( StorageBase& rDestStrg, const OUString& rElementName );
132 /** Copies all streams of this storage and of all substorages to the passed
133 destination. */
134 void copyStorageToStorage( StorageBase& rDestStrg );
136 /** Commits the changes to the storage and all substorages. */
137 void commit();
139 protected:
140 /** Special constructor for sub storage objects. */
141 explicit StorageBase( const StorageBase& rParentStorage, const OUString& rStorageName, bool bReadOnly );
143 private:
144 StorageBase( const StorageBase& ) = delete;
145 StorageBase& operator=( const StorageBase& ) = delete;
147 /** Returns true, if the object represents a valid storage. */
148 virtual bool implIsStorage() const = 0;
150 /** Returns the com.sun.star.embed.XStorage interface of the current storage. */
151 virtual css::uno::Reference< css::embed::XStorage >
152 implGetXStorage() const = 0;
154 /** Returns the names of all elements of this storage. */
155 virtual void implGetElementNames( ::std::vector< OUString >& orElementNames ) const = 0;
157 /** Implementation of opening a storage element. */
158 virtual StorageRef implOpenSubStorage( const OUString& rElementName, bool bCreate ) = 0;
160 /** Implementation of opening an input stream element. */
161 virtual css::uno::Reference< css::io::XInputStream >
162 implOpenInputStream( const OUString& rElementName ) = 0;
164 /** Implementation of opening an output stream element. */
165 virtual css::uno::Reference< css::io::XOutputStream >
166 implOpenOutputStream( const OUString& rElementName ) = 0;
168 /** Commits the current storage. */
169 virtual void implCommit() const = 0;
171 /** Helper that opens and caches the specified direct substorage. */
172 StorageRef getSubStorage( const OUString& rElementName, bool bCreateMissing );
174 private:
175 typedef RefMap< OUString, StorageBase > SubStorageMap;
177 SubStorageMap maSubStorages; ///< Map of direct sub storages.
178 css::uno::Reference< css::io::XInputStream >
179 mxInStream; ///< Cached base input stream (to keep it alive).
180 css::uno::Reference< css::io::XStream >
181 mxOutStream; ///< Cached base output stream (to keep it alive).
182 OUString maParentPath; ///< Full path of parent storage.
183 OUString maStorageName; ///< Name of this storage, if it is a substorage.
184 bool mbBaseStreamAccess; ///< True = access base streams with empty stream name.
185 bool mbReadOnly; ///< True = storage opened read-only (based on input stream).
189 } // namespace oox
191 #endif
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */