xref: /trunk/main/chart2/source/model/inc/XMLFilter.hxx (revision de7b3f82)
1*de7b3f82SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*de7b3f82SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*de7b3f82SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*de7b3f82SAndrew Rist  * distributed with this work for additional information
6*de7b3f82SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*de7b3f82SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*de7b3f82SAndrew Rist  * "License"); you may not use this file except in compliance
9*de7b3f82SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*de7b3f82SAndrew Rist  *
11*de7b3f82SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*de7b3f82SAndrew Rist  *
13*de7b3f82SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*de7b3f82SAndrew Rist  * software distributed under the License is distributed on an
15*de7b3f82SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*de7b3f82SAndrew Rist  * KIND, either express or implied.  See the License for the
17*de7b3f82SAndrew Rist  * specific language governing permissions and limitations
18*de7b3f82SAndrew Rist  * under the License.
19*de7b3f82SAndrew Rist  *
20*de7b3f82SAndrew Rist  *************************************************************/
21*de7b3f82SAndrew Rist 
22*de7b3f82SAndrew Rist 
23cdf0e10cSrcweir #ifndef CHART2_XMLFILTER_HXX
24cdf0e10cSrcweir #define CHART2_XMLFILTER_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <cppuhelper/implbase4.hxx>
27cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
28cdf0e10cSrcweir #include <com/sun/star/document/XFilter.hpp>
29cdf0e10cSrcweir #include <com/sun/star/document/XImporter.hpp>
30cdf0e10cSrcweir #include <com/sun/star/document/XExporter.hpp>
31cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
32cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp>
33cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSource.hpp>
34cdf0e10cSrcweir #include <osl/mutex.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir // for APPHELPER_... macros
37cdf0e10cSrcweir #include "ServiceMacros.hxx"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir namespace com { namespace sun { namespace star {
40cdf0e10cSrcweir namespace embed
41cdf0e10cSrcweir {
42cdf0e10cSrcweir     class XStorage;
43cdf0e10cSrcweir }
44cdf0e10cSrcweir namespace xml { namespace sax
45cdf0e10cSrcweir {
46cdf0e10cSrcweir     class XParser;
47cdf0e10cSrcweir }}
48cdf0e10cSrcweir namespace document
49cdf0e10cSrcweir {
50cdf0e10cSrcweir     class XGraphicObjectResolver;
51cdf0e10cSrcweir }
52cdf0e10cSrcweir }}}
53cdf0e10cSrcweir 
54cdf0e10cSrcweir namespace chart
55cdf0e10cSrcweir {
56cdf0e10cSrcweir 
57cdf0e10cSrcweir class XMLFilter : public
58cdf0e10cSrcweir     ::cppu::WeakImplHelper4<
59cdf0e10cSrcweir         ::com::sun::star::document::XFilter,
60cdf0e10cSrcweir         ::com::sun::star::document::XExporter,
61cdf0e10cSrcweir         ::com::sun::star::document::XImporter,
62cdf0e10cSrcweir         ::com::sun::star::lang::XServiceInfo >
63cdf0e10cSrcweir {
64cdf0e10cSrcweir public:
65cdf0e10cSrcweir 	explicit XMLFilter( ::com::sun::star::uno::Reference<
66cdf0e10cSrcweir                             ::com::sun::star::uno::XComponentContext > const & xContext );
67cdf0e10cSrcweir 	virtual ~XMLFilter();
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     /// establish methods for factory instatiation
70cdf0e10cSrcweir     APPHELPER_SERVICE_FACTORY_HELPER( XMLFilter )
71cdf0e10cSrcweir     /// XServiceInfo declarations
72cdf0e10cSrcweir     APPHELPER_XSERVICEINFO_DECL()
73cdf0e10cSrcweir 
74cdf0e10cSrcweir protected:
75cdf0e10cSrcweir     // ____ XFilter ____
76cdf0e10cSrcweir     virtual sal_Bool SAL_CALL filter(
77cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence<
78cdf0e10cSrcweir             ::com::sun::star::beans::PropertyValue >& aDescriptor )
79cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
80cdf0e10cSrcweir     virtual void SAL_CALL cancel()
81cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     // ____ XImporter ____
84cdf0e10cSrcweir     virtual void SAL_CALL setTargetDocument(
85cdf0e10cSrcweir         const ::com::sun::star::uno::Reference<
86cdf0e10cSrcweir             ::com::sun::star::lang::XComponent >& Document )
87cdf0e10cSrcweir         throw (::com::sun::star::lang::IllegalArgumentException,
88cdf0e10cSrcweir                ::com::sun::star::uno::RuntimeException);
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     // ____ XExporter ____
91cdf0e10cSrcweir     virtual void SAL_CALL setSourceDocument(
92cdf0e10cSrcweir         const ::com::sun::star::uno::Reference<
93cdf0e10cSrcweir             ::com::sun::star::lang::XComponent >& Document )
94cdf0e10cSrcweir         throw (::com::sun::star::lang::IllegalArgumentException,
95cdf0e10cSrcweir                ::com::sun::star::uno::RuntimeException);
96cdf0e10cSrcweir 
getDocumentHandler() const97cdf0e10cSrcweir     inline ::rtl::OUString getDocumentHandler() const { return m_sDocumentHandler; }
setDocumentHandler(const::rtl::OUString & _sDocumentHandler)98cdf0e10cSrcweir     inline void setDocumentHandler(const ::rtl::OUString& _sDocumentHandler) { m_sDocumentHandler = _sDocumentHandler; }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     virtual ::rtl::OUString getMediaType(bool _bOasis);
101cdf0e10cSrcweir 
102cdf0e10cSrcweir     /** fills the oasis flag only when a filtername was set
103cdf0e10cSrcweir     *
104cdf0e10cSrcweir     * \param _rMediaDescriptor
105cdf0e10cSrcweir     * \param _rOutOASIS
106cdf0e10cSrcweir     */
107cdf0e10cSrcweir     virtual void isOasisFormat(const ::com::sun::star::uno::Sequence<
108cdf0e10cSrcweir             ::com::sun::star::beans::PropertyValue >& _rMediaDescriptor, bool & _rOutOASIS );
109cdf0e10cSrcweir 
110cdf0e10cSrcweir private:
111cdf0e10cSrcweir     // methods
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     /// @return a warning code, or 0 for successful operation
114cdf0e10cSrcweir     sal_Int32 impl_Import( const ::com::sun::star::uno::Reference<
115cdf0e10cSrcweir                                ::com::sun::star::lang::XComponent > & xDocumentComp,
116cdf0e10cSrcweir                            const ::com::sun::star::uno::Sequence<
117cdf0e10cSrcweir                                ::com::sun::star::beans::PropertyValue > & aMediaDescriptor );
118cdf0e10cSrcweir     /// @return a warning code, or 0 for successful operation
119cdf0e10cSrcweir     sal_Int32 impl_ImportStream(
120cdf0e10cSrcweir         const ::rtl::OUString & rStreamName,
121cdf0e10cSrcweir         const ::rtl::OUString & rServiceName,
122cdf0e10cSrcweir         const ::com::sun::star::uno::Reference<
123cdf0e10cSrcweir             ::com::sun::star::embed::XStorage > & xStorage,
124cdf0e10cSrcweir         const ::com::sun::star::uno::Reference<
125cdf0e10cSrcweir             ::com::sun::star::xml::sax::XParser > & xParser,
126cdf0e10cSrcweir         const ::com::sun::star::uno::Reference<
127cdf0e10cSrcweir             ::com::sun::star::lang::XMultiComponentFactory > & xFactory,
128cdf0e10cSrcweir         const ::com::sun::star::uno::Reference<
129cdf0e10cSrcweir             ::com::sun::star::document::XGraphicObjectResolver > & xGraphicObjectResolver,
130cdf0e10cSrcweir         ::com::sun::star::uno::Reference<
131cdf0e10cSrcweir             ::com::sun::star::beans::XPropertySet >& xPropSet );
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     /// @return a warning code, or 0 for successful operation
134cdf0e10cSrcweir     sal_Int32 impl_Export( const ::com::sun::star::uno::Reference<
135cdf0e10cSrcweir                                ::com::sun::star::lang::XComponent > & xDocumentComp,
136cdf0e10cSrcweir                            const ::com::sun::star::uno::Sequence<
137cdf0e10cSrcweir                                ::com::sun::star::beans::PropertyValue > & aMediaDescriptor );
138cdf0e10cSrcweir     /// @return a warning code, or 0 for successful operation
139cdf0e10cSrcweir     sal_Int32 impl_ExportStream(
140cdf0e10cSrcweir         const ::rtl::OUString & rStreamName,
141cdf0e10cSrcweir         const ::rtl::OUString & rServiceName,
142cdf0e10cSrcweir         const ::com::sun::star::uno::Reference<
143cdf0e10cSrcweir             ::com::sun::star::embed::XStorage > & xStorage,
144cdf0e10cSrcweir         const ::com::sun::star::uno::Reference<
145cdf0e10cSrcweir             ::com::sun::star::io::XActiveDataSource >& xActiveDataSource,
146cdf0e10cSrcweir         const ::com::sun::star::uno::Reference<
147cdf0e10cSrcweir             ::com::sun::star::lang::XMultiServiceFactory > & xFactory,
148cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence<
149cdf0e10cSrcweir             ::com::sun::star::uno::Any > & rFilterProperties );
150cdf0e10cSrcweir 
151cdf0e10cSrcweir     // members
152cdf0e10cSrcweir     ::com::sun::star::uno::Reference<
153cdf0e10cSrcweir         ::com::sun::star::uno::XComponentContext > m_xContext;
154cdf0e10cSrcweir     ::com::sun::star::uno::Reference<
155cdf0e10cSrcweir         ::com::sun::star::lang::XComponent >       m_xTargetDoc;
156cdf0e10cSrcweir     ::com::sun::star::uno::Reference<
157cdf0e10cSrcweir         ::com::sun::star::lang::XComponent >       m_xSourceDoc;
158cdf0e10cSrcweir     ::rtl::OUString                                m_sDocumentHandler; // when set it will be set as doc handler
159cdf0e10cSrcweir 
160cdf0e10cSrcweir     volatile bool                                  m_bCancelOperation;
161cdf0e10cSrcweir     ::osl::Mutex                                   m_aMutex;
162cdf0e10cSrcweir };
163cdf0e10cSrcweir 
164cdf0e10cSrcweir // =============================================================================
165cdf0e10cSrcweir class XMLReportFilterHelper : public XMLFilter
166cdf0e10cSrcweir {
167cdf0e10cSrcweir     virtual void isOasisFormat(const ::com::sun::star::uno::Sequence<
168cdf0e10cSrcweir                                     ::com::sun::star::beans::PropertyValue >& _rMediaDescriptor, bool & _rOutOASIS );
169cdf0e10cSrcweir public:
XMLReportFilterHelper(::com::sun::star::uno::Reference<::com::sun::star::uno::XComponentContext> const & _xContext)170cdf0e10cSrcweir     explicit XMLReportFilterHelper( ::com::sun::star::uno::Reference<
171cdf0e10cSrcweir                             ::com::sun::star::uno::XComponentContext > const & _xContext )
172cdf0e10cSrcweir                             :XMLFilter(_xContext)
173cdf0e10cSrcweir     {}
174cdf0e10cSrcweir     /// establish methods for factory instatiation
create(::com::sun::star::uno::Reference<::com::sun::star::uno::XComponentContext> const & xContext)175cdf0e10cSrcweir     static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL	create(
176cdf0e10cSrcweir         ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext) throw(::com::sun::star::uno::Exception)
177cdf0e10cSrcweir     {
178cdf0e10cSrcweir 	    return (::cppu::OWeakObject *)new XMLReportFilterHelper( xContext );
179cdf0e10cSrcweir     }
getImplementationName_Static()180cdf0e10cSrcweir     static ::rtl::OUString getImplementationName_Static()
181cdf0e10cSrcweir     {
182cdf0e10cSrcweir         return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.chart2.report.XMLFilter" ));
183cdf0e10cSrcweir     }
184cdf0e10cSrcweir protected:
185cdf0e10cSrcweir     virtual ::rtl::OUString SAL_CALL
getImplementationName()186cdf0e10cSrcweir 		getImplementationName()
187cdf0e10cSrcweir 			throw( ::com::sun::star::uno::RuntimeException )
188cdf0e10cSrcweir     {
189cdf0e10cSrcweir         return getImplementationName_Static();
190cdf0e10cSrcweir     }
191cdf0e10cSrcweir     // ____ XImporter ____
setTargetDocument(const::com::sun::star::uno::Reference<::com::sun::star::lang::XComponent> & Document)192cdf0e10cSrcweir     virtual void SAL_CALL setTargetDocument(
193cdf0e10cSrcweir         const ::com::sun::star::uno::Reference<
194cdf0e10cSrcweir             ::com::sun::star::lang::XComponent >& Document )
195cdf0e10cSrcweir         throw (::com::sun::star::lang::IllegalArgumentException,
196cdf0e10cSrcweir                ::com::sun::star::uno::RuntimeException)
197cdf0e10cSrcweir     {
198cdf0e10cSrcweir         setDocumentHandler(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.report.ImportDocumentHandler")));
199cdf0e10cSrcweir         XMLFilter::setTargetDocument(Document);
200cdf0e10cSrcweir     }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir     // ____ XExporter ____
setSourceDocument(const::com::sun::star::uno::Reference<::com::sun::star::lang::XComponent> & Document)203cdf0e10cSrcweir     virtual void SAL_CALL setSourceDocument(
204cdf0e10cSrcweir         const ::com::sun::star::uno::Reference<
205cdf0e10cSrcweir             ::com::sun::star::lang::XComponent >& Document )
206cdf0e10cSrcweir         throw (::com::sun::star::lang::IllegalArgumentException,
207cdf0e10cSrcweir                ::com::sun::star::uno::RuntimeException)
208cdf0e10cSrcweir     {
209cdf0e10cSrcweir         setDocumentHandler(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.report.ExportDocumentHandler")));
210cdf0e10cSrcweir         XMLFilter::setSourceDocument(Document);
211cdf0e10cSrcweir     }
212cdf0e10cSrcweir 
213cdf0e10cSrcweir     virtual ::rtl::OUString getMediaType(bool _bOasis);
214cdf0e10cSrcweir };
215cdf0e10cSrcweir 
216cdf0e10cSrcweir } //  namespace chart
217cdf0e10cSrcweir 
218cdf0e10cSrcweir // CHART2_XMLFILTER_HXX
219cdf0e10cSrcweir #endif
220