1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef OOX_HELPER_STORAGEBASE_HXX 29 #define OOX_HELPER_STORAGEBASE_HXX 30 31 #include <vector> 32 #include <com/sun/star/uno/Reference.hxx> 33 #include "oox/helper/refmap.hxx" 34 #include "oox/dllapi.h" 35 36 namespace com { namespace sun { namespace star { 37 namespace embed { class XStorage; } 38 namespace io { class XInputStream; } 39 namespace io { class XOutputStream; } 40 namespace io { class XStream; } 41 } } } 42 43 namespace oox { 44 45 // ============================================================================ 46 47 class StorageBase; 48 typedef ::boost::shared_ptr< StorageBase > StorageRef; 49 50 /** Base class for storage access implementations. 51 52 Derived classes will be used to encapsulate storage access implementations 53 for ZIP storages containing XML streams, and OLE storages containing binary 54 data streams. 55 */ 56 class OOX_DLLPUBLIC StorageBase 57 { 58 public: 59 explicit StorageBase( 60 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxInStream, 61 bool bBaseStreamAccess ); 62 63 explicit StorageBase( 64 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& rxOutStream, 65 bool bBaseStreamAccess ); 66 67 virtual ~StorageBase(); 68 69 /** Returns true, if the object represents a valid storage. */ 70 bool isStorage() const; 71 72 /** Returns true, if the object represents the root storage. */ 73 bool isRootStorage() const; 74 75 /** Returns true, if the storage operates in read-only mode (based on an 76 input stream). */ 77 bool isReadOnly() const; 78 79 /** Returns the com.sun.star.embed.XStorage interface of the current storage. */ 80 ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > 81 getXStorage() const; 82 83 /** Returns the element name of this storage. */ 84 const ::rtl::OUString& getName() const; 85 86 /** Returns the full path of this storage. */ 87 ::rtl::OUString getPath() const; 88 89 /** Fills the passed vector with the names of all direct elements of this 90 storage. */ 91 void getElementNames( ::std::vector< ::rtl::OUString >& orElementNames ) const; 92 93 /** Opens and returns the specified sub storage from the storage. 94 95 @param rStorageName 96 The name of the embedded storage. The name may contain slashes to 97 open storages from embedded substorages. 98 @param bCreateMissing 99 True = create missing sub storages (for export filters). Must be 100 false for storages based on input streams. 101 */ 102 StorageRef openSubStorage( const ::rtl::OUString& rStorageName, bool bCreateMissing ); 103 104 /** Opens and returns the specified input stream from the storage. 105 106 @param rStreamName 107 The name of the embedded storage stream. The name may contain 108 slashes to open streams from embedded substorages. If base stream 109 access has been enabled in the constructor, the base stream can be 110 accessed by passing an empty string as stream name. 111 */ 112 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > 113 openInputStream( const ::rtl::OUString& rStreamName ); 114 115 /** Opens and returns the specified output stream from the storage. 116 117 @param rStreamName 118 The name of the embedded storage stream. The name may contain 119 slashes to create and open streams in embedded substorages. If base 120 stream access has been enabled in the constructor, the base stream 121 can be accessed by passing an empty string as stream name. 122 */ 123 ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > 124 openOutputStream( const ::rtl::OUString& rStreamName ); 125 126 /** Copies the specified element from this storage to the passed 127 destination storage. 128 129 @param rElementName 130 The name of the embedded storage or stream. The name may contain 131 slashes to specify an element in an embedded substorage. In this 132 case, the element will be copied to the same substorage in the 133 destination storage. 134 */ 135 void copyToStorage( StorageBase& rDestStrg, const ::rtl::OUString& rElementName ); 136 137 /** Copies all streams of this storage and of all substorages to the passed 138 destination. */ 139 void copyStorageToStorage( StorageBase& rDestStrg ); 140 141 /** Commits the changes to the storage and all substorages. */ 142 void commit(); 143 144 protected: 145 /** Special constructor for sub storage objects. */ 146 explicit StorageBase( const StorageBase& rParentStorage, const ::rtl::OUString& rStorageName, bool bReadOnly ); 147 148 private: 149 StorageBase( const StorageBase& ); 150 StorageBase& operator=( const StorageBase& ); 151 152 /** Returns true, if the object represents a valid storage. */ 153 virtual bool implIsStorage() const = 0; 154 155 /** Returns the com.sun.star.embed.XStorage interface of the current storage. */ 156 virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > 157 implGetXStorage() const = 0; 158 159 /** Returns the names of all elements of this storage. */ 160 virtual void implGetElementNames( ::std::vector< ::rtl::OUString >& orElementNames ) const = 0; 161 162 /** Implementation of opening a storage element. */ 163 virtual StorageRef implOpenSubStorage( const ::rtl::OUString& rElementName, bool bCreate ) = 0; 164 165 /** Implementation of opening an input stream element. */ 166 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > 167 implOpenInputStream( const ::rtl::OUString& rElementName ) = 0; 168 169 /** Implementation of opening an output stream element. */ 170 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > 171 implOpenOutputStream( const ::rtl::OUString& rElementName ) = 0; 172 173 /** Commits the current storage. */ 174 virtual void implCommit() const = 0; 175 176 /** Helper that opens and caches the specified direct substorage. */ 177 StorageRef getSubStorage( const ::rtl::OUString& rElementName, bool bCreateMissing ); 178 179 private: 180 typedef RefMap< ::rtl::OUString, StorageBase > SubStorageMap; 181 182 SubStorageMap maSubStorages; /// Map of direct sub storages. 183 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > 184 mxInStream; /// Cached base input stream (to keep it alive). 185 ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > 186 mxOutStream; /// Cached base output stream (to keep it alive). 187 ::rtl::OUString maParentPath; /// Full path of parent storage. 188 ::rtl::OUString maStorageName; /// Name of this storage, if it is a substorage. 189 bool mbBaseStreamAccess; /// True = access base streams with empty stream name. 190 bool mbReadOnly; /// True = storage opened read-only (based on input stream). 191 }; 192 193 // ============================================================================ 194 195 } // namespace oox 196 197 #endif 198