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