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
24 #include <com/sun/star/uno/Reference.hxx>
25 #include <oox/helper/refmap.hxx>
26 #include <oox/dllapi.h>
28 namespace com
{ namespace sun
{ namespace star
{
29 namespace embed
{ class XStorage
; }
30 namespace io
{ class XInputStream
; }
31 namespace io
{ class XOutputStream
; }
32 namespace io
{ class XStream
; }
40 typedef std::shared_ptr
< StorageBase
> StorageRef
;
42 /** Base class for storage access implementations.
44 Derived classes will be used to encapsulate storage access implementations
45 for ZIP storages containing XML streams, and OLE storages containing binary
48 class OOX_DLLPUBLIC StorageBase
52 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& rxInStream
,
53 bool bBaseStreamAccess
);
56 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XStream
>& rxOutStream
,
57 bool bBaseStreamAccess
);
59 virtual ~StorageBase();
61 /** Returns true, if the object represents a valid storage. */
62 bool isStorage() const;
64 /** Returns true, if the object represents the root storage. */
65 bool isRootStorage() const;
67 /** Returns true, if the storage operates in read-only mode (based on an
69 bool isReadOnly() const { return mbReadOnly
;}
71 /** Returns the com.sun.star.embed.XStorage interface of the current storage. */
72 ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>
75 /** Returns the element name of this storage. */
76 const OUString
& getName() const { return maStorageName
;}
78 /** Returns the full path of this storage. */
79 OUString
getPath() const;
81 /** Fills the passed vector with the names of all direct elements of this
83 void getElementNames( ::std::vector
< OUString
>& orElementNames
) const;
85 /** Opens and returns the specified sub storage from the storage.
88 The name of the embedded storage. The name may contain slashes to
89 open storages from embedded substorages.
91 True = create missing sub storages (for export filters). Must be
92 false for storages based on input streams.
94 StorageRef
openSubStorage( const OUString
& rStorageName
, bool bCreateMissing
);
96 /** Opens and returns the specified input stream from the storage.
99 The name of the embedded storage stream. The name may contain
100 slashes to open streams from embedded substorages. If base stream
101 access has been enabled in the constructor, the base stream can be
102 accessed by passing an empty string as stream name.
104 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>
105 openInputStream( const OUString
& rStreamName
);
107 /** Opens and returns the specified output stream from the storage.
110 The name of the embedded storage stream. The name may contain
111 slashes to create and open streams in embedded substorages. If base
112 stream access has been enabled in the constructor, the base stream
113 can be accessed by passing an empty string as stream name.
115 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XOutputStream
>
116 openOutputStream( const OUString
& rStreamName
);
118 /** Copies the specified element from this storage to the passed
122 The name of the embedded storage or stream. The name may contain
123 slashes to specify an element in an embedded substorage. In this
124 case, the element will be copied to the same substorage in the
127 void copyToStorage( StorageBase
& rDestStrg
, const OUString
& rElementName
);
129 /** Copies all streams of this storage and of all substorages to the passed
131 void copyStorageToStorage( StorageBase
& rDestStrg
);
133 /** Commits the changes to the storage and all substorages. */
137 /** Special constructor for sub storage objects. */
138 explicit StorageBase( const StorageBase
& rParentStorage
, const OUString
& rStorageName
, bool bReadOnly
);
141 StorageBase( const StorageBase
& ) SAL_DELETED_FUNCTION
;
142 StorageBase
& operator=( const StorageBase
& ) SAL_DELETED_FUNCTION
;
144 /** Returns true, if the object represents a valid storage. */
145 virtual bool implIsStorage() const = 0;
147 /** Returns the com.sun.star.embed.XStorage interface of the current storage. */
148 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::embed::XStorage
>
149 implGetXStorage() const = 0;
151 /** Returns the names of all elements of this storage. */
152 virtual void implGetElementNames( ::std::vector
< OUString
>& orElementNames
) const = 0;
154 /** Implementation of opening a storage element. */
155 virtual StorageRef
implOpenSubStorage( const OUString
& rElementName
, bool bCreate
) = 0;
157 /** Implementation of opening an input stream element. */
158 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>
159 implOpenInputStream( const OUString
& rElementName
) = 0;
161 /** Implementation of opening an output stream element. */
162 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::io::XOutputStream
>
163 implOpenOutputStream( const OUString
& rElementName
) = 0;
165 /** Commits the current storage. */
166 virtual void implCommit() const = 0;
168 /** Helper that opens and caches the specified direct substorage. */
169 StorageRef
getSubStorage( const OUString
& rElementName
, bool bCreateMissing
);
172 typedef RefMap
< OUString
, StorageBase
> SubStorageMap
;
174 SubStorageMap maSubStorages
; ///< Map of direct sub storages.
175 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>
176 mxInStream
; ///< Cached base input stream (to keep it alive).
177 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XStream
>
178 mxOutStream
; ///< Cached base output stream (to keep it alive).
179 OUString maParentPath
; ///< Full path of parent storage.
180 OUString maStorageName
; ///< Name of this storage, if it is a substorage.
181 bool mbBaseStreamAccess
; ///< True = access base streams with empty stream name.
182 bool mbReadOnly
; ///< True = storage opened read-only (based on input stream).
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */