1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef OOX_HELPER_STORAGEBASE_HXX 25 #define OOX_HELPER_STORAGEBASE_HXX 26 27 #include <vector> 28 #include <com/sun/star/uno/Reference.hxx> 29 #include "oox/helper/refmap.hxx" 30 #include "oox/dllapi.h" 31 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 } } } 38 39 namespace oox { 40 41 // ============================================================================ 42 43 class StorageBase; 44 typedef ::boost::shared_ptr< StorageBase > StorageRef; 45 46 /** Base class for storage access implementations. 47 48 Derived classes will be used to encapsulate storage access implementations 49 for ZIP storages containing XML streams, and OLE storages containing binary 50 data streams. 51 */ 52 class OOX_DLLPUBLIC StorageBase 53 { 54 public: 55 explicit StorageBase( 56 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxInStream, 57 bool bBaseStreamAccess ); 58 59 explicit StorageBase( 60 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& rxOutStream, 61 bool bBaseStreamAccess ); 62 63 virtual ~StorageBase(); 64 65 /** Returns true, if the object represents a valid storage. */ 66 bool isStorage() const; 67 68 /** Returns true, if the object represents the root storage. */ 69 bool isRootStorage() const; 70 71 /** Returns true, if the storage operates in read-only mode (based on an 72 input stream). */ 73 bool isReadOnly() const; 74 75 /** Returns the com.sun.star.embed.XStorage interface of the current storage. */ 76 ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > 77 getXStorage() const; 78 79 /** Returns the element name of this storage. */ 80 const ::rtl::OUString& getName() const; 81 82 /** Returns the full path of this storage. */ 83 ::rtl::OUString getPath() const; 84 85 /** Fills the passed vector with the names of all direct elements of this 86 storage. */ 87 void getElementNames( ::std::vector< ::rtl::OUString >& orElementNames ) const; 88 89 /** Opens and returns the specified sub storage from the storage. 90 91 @param rStorageName 92 The name of the embedded storage. The name may contain slashes to 93 open storages from embedded substorages. 94 @param bCreateMissing 95 True = create missing sub storages (for export filters). Must be 96 false for storages based on input streams. 97 */ 98 StorageRef openSubStorage( const ::rtl::OUString& rStorageName, bool bCreateMissing ); 99 100 /** Opens and returns the specified input stream from the storage. 101 102 @param rStreamName 103 The name of the embedded storage stream. The name may contain 104 slashes to open streams from embedded substorages. If base stream 105 access has been enabled in the constructor, the base stream can be 106 accessed by passing an empty string as stream name. 107 */ 108 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > 109 openInputStream( const ::rtl::OUString& rStreamName ); 110 111 /** Opens and returns the specified output stream from the storage. 112 113 @param rStreamName 114 The name of the embedded storage stream. The name may contain 115 slashes to create and open streams in embedded substorages. If base 116 stream access has been enabled in the constructor, the base stream 117 can be accessed by passing an empty string as stream name. 118 */ 119 ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > 120 openOutputStream( const ::rtl::OUString& rStreamName ); 121 122 /** Copies the specified element from this storage to the passed 123 destination storage. 124 125 @param rElementName 126 The name of the embedded storage or stream. The name may contain 127 slashes to specify an element in an embedded substorage. In this 128 case, the element will be copied to the same substorage in the 129 destination storage. 130 */ 131 void copyToStorage( StorageBase& rDestStrg, const ::rtl::OUString& rElementName ); 132 133 /** Copies all streams of this storage and of all substorages to the passed 134 destination. */ 135 void copyStorageToStorage( StorageBase& rDestStrg ); 136 137 /** Commits the changes to the storage and all substorages. */ 138 void commit(); 139 140 protected: 141 /** Special constructor for sub storage objects. */ 142 explicit StorageBase( const StorageBase& rParentStorage, const ::rtl::OUString& rStorageName, bool bReadOnly ); 143 144 private: 145 StorageBase( const StorageBase& ); 146 StorageBase& operator=( const StorageBase& ); 147 148 /** Returns true, if the object represents a valid storage. */ 149 virtual bool implIsStorage() const = 0; 150 151 /** Returns the com.sun.star.embed.XStorage interface of the current storage. */ 152 virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > 153 implGetXStorage() const = 0; 154 155 /** Returns the names of all elements of this storage. */ 156 virtual void implGetElementNames( ::std::vector< ::rtl::OUString >& orElementNames ) const = 0; 157 158 /** Implementation of opening a storage element. */ 159 virtual StorageRef implOpenSubStorage( const ::rtl::OUString& rElementName, bool bCreate ) = 0; 160 161 /** Implementation of opening an input stream element. */ 162 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > 163 implOpenInputStream( const ::rtl::OUString& rElementName ) = 0; 164 165 /** Implementation of opening an output stream element. */ 166 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > 167 implOpenOutputStream( const ::rtl::OUString& rElementName ) = 0; 168 169 /** Commits the current storage. */ 170 virtual void implCommit() const = 0; 171 172 /** Helper that opens and caches the specified direct substorage. */ 173 StorageRef getSubStorage( const ::rtl::OUString& rElementName, bool bCreateMissing ); 174 175 private: 176 typedef RefMap< ::rtl::OUString, StorageBase > SubStorageMap; 177 178 SubStorageMap maSubStorages; /// Map of direct sub storages. 179 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > 180 mxInStream; /// Cached base input stream (to keep it alive). 181 ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > 182 mxOutStream; /// Cached base output stream (to keep it alive). 183 ::rtl::OUString maParentPath; /// Full path of parent storage. 184 ::rtl::OUString maStorageName; /// Name of this storage, if it is a substorage. 185 bool mbBaseStreamAccess; /// True = access base streams with empty stream name. 186 bool mbReadOnly; /// True = storage opened read-only (based on input stream). 187 }; 188 189 // ============================================================================ 190 191 } // namespace oox 192 193 #endif 194