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 INCLUDED_OOX_HELPER_STORAGEBASE_HXX
21 #define INCLUDED_OOX_HELPER_STORAGEBASE_HXX
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::sun::star
{
33 namespace embed
{ class XStorage
; }
34 namespace io
{ class XInputStream
; }
35 namespace io
{ class XOutputStream
; }
36 namespace io
{ class XStream
; }
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
51 class OOX_DLLPUBLIC StorageBase
55 const css::uno::Reference
< css::io::XInputStream
>& rxInStream
,
56 bool bBaseStreamAccess
);
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
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
>
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
86 void getElementNames( ::std::vector
< OUString
>& orElementNames
) const;
88 /** Opens and returns the specified sub storage from the storage.
91 The name of the embedded storage. The name may contain slashes to
92 open storages from embedded substorages.
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.
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.
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
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
130 void copyToStorage( StorageBase
& rDestStrg
, const OUString
& rElementName
);
132 /** Copies all streams of this storage and of all substorages to the passed
134 void copyStorageToStorage( StorageBase
& rDestStrg
);
136 /** Commits the changes to the storage and all substorages. */
140 /** Special constructor for sub storage objects. */
141 explicit StorageBase( const StorageBase
& rParentStorage
, OUString aStorageName
, bool bReadOnly
);
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
);
175 RefMap
< OUString
, StorageBase
>
176 maSubStorages
; ///< Map of direct sub storages.
177 css::uno::Reference
< css::io::XInputStream
>
178 mxInStream
; ///< Cached base input stream (to keep it alive).
179 css::uno::Reference
< css::io::XStream
>
180 mxOutStream
; ///< Cached base output stream (to keep it alive).
181 OUString maParentPath
; ///< Full path of parent storage.
182 OUString maStorageName
; ///< Name of this storage, if it is a substorage.
183 bool mbBaseStreamAccess
; ///< True = access base streams with empty stream name.
184 bool mbReadOnly
; ///< True = storage opened read-only (based on input stream).
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */