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 #ifndef OOX_CORE_FILTERBASE_HXX 23 #define OOX_CORE_FILTERBASE_HXX 24 25 #include <memory> 26 #include <com/sun/star/beans/NamedValue.hpp> 27 #include <com/sun/star/document/XExporter.hpp> 28 #include <com/sun/star/document/XFilter.hpp> 29 #include <com/sun/star/document/XImporter.hpp> 30 #include <com/sun/star/io/XInputStream.hpp> 31 #include <com/sun/star/io/XOutputStream.hpp> 32 #include <com/sun/star/io/XStream.hpp> 33 #include <com/sun/star/lang/XInitialization.hpp> 34 #include <com/sun/star/lang/XServiceInfo.hpp> 35 #include <cppuhelper/basemutex.hxx> 36 #include <cppuhelper/implbase5.hxx> 37 #include "oox/helper/binarystreambase.hxx" 38 #include "oox/helper/storagebase.hxx" 39 #include "oox/dllapi.h" 40 41 namespace com { namespace sun { namespace star { 42 namespace awt { struct DeviceInfo; } 43 namespace frame { class XFrame; } 44 namespace frame { class XModel; } 45 namespace graphic { class XGraphic; } 46 namespace io { class XInputStream; } 47 namespace io { class XOutputStream; } 48 namespace io { class XStream; } 49 namespace lang { class XMultiComponentFactory; } 50 namespace lang { class XMultiServiceFactory; } 51 namespace task { class XInteractionHandler; } 52 namespace task { class XStatusIndicator; } 53 namespace uno { class XComponentContext; } 54 } } } 55 56 namespace comphelper { 57 class IDocPasswordVerifier; 58 class MediaDescriptor; 59 } 60 61 namespace oox { 62 class GraphicHelper; 63 class ModelObjectHelper; 64 } 65 66 namespace oox { namespace ole { 67 class OleObjectHelper; 68 class VbaProject; 69 } } 70 71 namespace oox { 72 namespace core { 73 74 // ============================================================================ 75 76 struct FilterBaseImpl; 77 78 typedef ::cppu::WeakImplHelper5< 79 ::com::sun::star::lang::XServiceInfo, 80 ::com::sun::star::lang::XInitialization, 81 ::com::sun::star::document::XImporter, 82 ::com::sun::star::document::XExporter, 83 ::com::sun::star::document::XFilter > 84 FilterBase_BASE; 85 86 class OOX_DLLPUBLIC FilterBase : public FilterBase_BASE, public ::cppu::BaseMutex 87 { 88 public: 89 explicit FilterBase( 90 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext ) 91 throw( ::com::sun::star::uno::RuntimeException ); 92 93 virtual ~FilterBase(); 94 95 /** Returns true, if filter is an import filter. */ 96 bool isImportFilter() const; 97 /** Returns true, if filter is an export filter. */ 98 bool isExportFilter() const; 99 100 /** Derived classes implement import of the entire document. */ 101 virtual bool importDocument() = 0; 102 103 /** Derived classes implement export of the entire document. */ 104 virtual bool exportDocument() = 0; 105 106 // ------------------------------------------------------------------------ 107 108 /** Returns the specified argument passed through the XInitialization interface. */ 109 ::com::sun::star::uno::Any getArgument( const ::rtl::OUString& rArgName ) const; 110 111 /** Returns the component context passed in the filter constructor (always existing). */ 112 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& 113 getComponentContext() const; 114 115 /** Returns the component service factory (always existing). */ 116 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiComponentFactory >& 117 getComponentFactory() const; 118 119 /** Returns the multi service factory of the component (always existing). */ 120 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& 121 getServiceFactory() const; 122 123 /** Returns the document model (always existing). */ 124 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& 125 getModel() const; 126 127 /** Returns the service factory provided by the document model (always existing). */ 128 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& 129 getModelFactory() const; 130 131 /** Returns the frame that will contain the document model (may be null). */ 132 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& 133 getTargetFrame() const; 134 135 /** Returns the status indicator (may be null). */ 136 const ::com::sun::star::uno::Reference< ::com::sun::star::task::XStatusIndicator >& 137 getStatusIndicator() const; 138 139 /** Returns the status interaction handler (may be null). */ 140 const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& 141 getInteractionHandler() const; 142 143 /** Returns the media descriptor. */ 144 ::comphelper::MediaDescriptor& getMediaDescriptor() const; 145 146 /** Returns the URL of the imported or exported file. */ 147 const ::rtl::OUString& getFileUrl() const; 148 149 /** Returns an absolute URL for the passed relative or absolute URL. */ 150 ::rtl::OUString getAbsoluteUrl( const ::rtl::OUString& rUrl ) const; 151 152 /** Returns the base storage of the imported/exported file. */ 153 StorageRef getStorage() const; 154 155 /** Opens and returns the specified sub storage from the base storage. 156 157 @param rStorageName 158 The name of the embedded storage. The name may contain slashes to 159 open storages from embedded substorages. 160 @param bCreateMissing 161 True = create missing sub storages (for export filters). 162 */ 163 StorageRef openSubStorage( 164 const ::rtl::OUString& rStorageName, 165 bool bCreateMissing ) const; 166 167 /** Opens and returns the specified input stream from the base storage. 168 169 @param rStreamName 170 The name of the embedded storage stream. The name may contain 171 slashes to open streams from embedded substorages. If base stream 172 access has been enabled in the storage, the base stream can be 173 accessed by passing an empty string as stream name. 174 */ 175 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > 176 openInputStream( const ::rtl::OUString& rStreamName ) const; 177 178 /** Opens and returns the specified output stream from the base storage. 179 180 @param rStreamName 181 The name of the embedded storage stream. The name may contain 182 slashes to open streams from embedded substorages. If base stream 183 access has been enabled in the storage, the base stream can be 184 accessed by passing an empty string as stream name. 185 */ 186 ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > 187 openOutputStream( const ::rtl::OUString& rStreamName ) const; 188 189 /** Commits changes to base storage (and substorages) */ 190 void commitStorage() const; 191 192 // helpers ---------------------------------------------------------------- 193 194 /** Returns a helper for the handling of graphics and graphic objects. */ 195 GraphicHelper& getGraphicHelper() const; 196 197 /** Returns a helper with containers for various named drawing objects for 198 the imported document. */ 199 ModelObjectHelper& getModelObjectHelper() const; 200 201 /** Returns a helper for the handling of OLE objects. */ 202 ::oox::ole::OleObjectHelper& getOleObjectHelper() const; 203 204 /** Returns the VBA project manager. */ 205 ::oox::ole::VbaProject& getVbaProject() const; 206 207 /** Requests the encryption data from the media descriptor or from the user. On 208 success, the encryption data will be inserted into the media descriptor. */ 209 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue > 210 requestEncryptionData( ::comphelper::IDocPasswordVerifier& rVerifier ) const; 211 212 /** Imports the raw binary data from the specified stream. 213 @return True, if the data could be imported from the stream. */ 214 bool importBinaryData( StreamDataSequence& orDataSeq, const ::rtl::OUString& rStreamName ); 215 216 // com.sun.star.lang.XServiceInfo interface ------------------------------- 217 218 virtual ::rtl::OUString SAL_CALL 219 getImplementationName() 220 throw( ::com::sun::star::uno::RuntimeException ); 221 222 virtual sal_Bool SAL_CALL 223 supportsService( const ::rtl::OUString& rServiceName ) 224 throw( ::com::sun::star::uno::RuntimeException ); 225 226 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL 227 getSupportedServiceNames() 228 throw( ::com::sun::star::uno::RuntimeException ); 229 230 // com.sun.star.lang.XInitialization interface ---------------------------- 231 232 /** Receives user defined arguments. 233 234 @param rArgs 235 the sequence of arguments passed to the filter. The implementation 236 expects one or two arguments. The first argument shall be the 237 com.sun.star.lang.XMultiServiceFactory interface of the global 238 service factory. The optional second argument may contain a 239 sequence of com.sun.star.beans.NamedValue objects. The different 240 filter implementations may support different arguments. 241 */ 242 virtual void SAL_CALL initialize( 243 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rArgs ) 244 throw( ::com::sun::star::uno::Exception, 245 ::com::sun::star::uno::RuntimeException ); 246 247 // com.sun.star.document.XImporter interface ------------------------------ 248 249 virtual void SAL_CALL setTargetDocument( 250 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& rxDocument ) 251 throw( ::com::sun::star::lang::IllegalArgumentException, 252 ::com::sun::star::uno::RuntimeException ); 253 254 // com.sun.star.document.XExporter interface ------------------------------ 255 256 virtual void SAL_CALL setSourceDocument( 257 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& rxDocument ) 258 throw( ::com::sun::star::lang::IllegalArgumentException, 259 ::com::sun::star::uno::RuntimeException ); 260 261 // com.sun.star.document.XFilter interface -------------------------------- 262 263 virtual sal_Bool SAL_CALL filter( 264 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rMediaDescSeq ) 265 throw( ::com::sun::star::uno::RuntimeException ); 266 267 virtual void SAL_CALL cancel() 268 throw( ::com::sun::star::uno::RuntimeException ); 269 270 // ------------------------------------------------------------------------ 271 protected: 272 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > 273 implGetInputStream( ::comphelper::MediaDescriptor& rMediaDesc ) const; 274 virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > 275 implGetOutputStream( ::comphelper::MediaDescriptor& rMediaDesc ) const; 276 277 private: 278 void setMediaDescriptor( 279 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rMediaDescSeq ); 280 281 /** Derived classes may create a specialized graphic helper, e.g. for 282 resolving palette colors. */ 283 virtual GraphicHelper* implCreateGraphicHelper() const; 284 285 /** Derived classes create a VBA project manager object. */ 286 virtual ::oox::ole::VbaProject* implCreateVbaProject() const = 0; 287 288 virtual ::rtl::OUString implGetImplementationName() const = 0; 289 290 virtual StorageRef implCreateStorage( 291 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rxInStream ) const = 0; 292 virtual StorageRef implCreateStorage( 293 const ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream >& rxOutStream ) const = 0; 294 295 private: 296 ::std::auto_ptr< FilterBaseImpl > mxImpl; 297 }; 298 299 // ============================================================================ 300 301 } // namespace core 302 } // namespace oox 303 304 #endif 305 306 /* vim: set noet sw=4 ts=4: */ 307