Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #ifndef INCLUDED_CHART2_SOURCE_MODEL_INC_XMLFILTER_HXX
20 : #define INCLUDED_CHART2_SOURCE_MODEL_INC_XMLFILTER_HXX
21 :
22 : #include <cppuhelper/implbase4.hxx>
23 : #include <com/sun/star/beans/XPropertySet.hpp>
24 : #include <com/sun/star/document/XFilter.hpp>
25 : #include <com/sun/star/document/XImporter.hpp>
26 : #include <com/sun/star/document/XExporter.hpp>
27 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 : #include <com/sun/star/lang/XServiceInfo.hpp>
29 : #include <com/sun/star/uno/XComponentContext.hpp>
30 : #include <com/sun/star/io/XActiveDataSource.hpp>
31 : #include <com/sun/star/xml/sax/XWriter.hpp>
32 : #include <osl/mutex.hxx>
33 :
34 :
35 : namespace com { namespace sun { namespace star {
36 : namespace embed
37 : {
38 : class XStorage;
39 : }
40 : namespace xml { namespace sax
41 : {
42 : class XParser;
43 : }}
44 : namespace document
45 : {
46 : class XGraphicObjectResolver;
47 : }
48 : }}}
49 :
50 : namespace chart
51 : {
52 :
53 : class XMLFilter : public
54 : ::cppu::WeakImplHelper4<
55 : ::com::sun::star::document::XFilter,
56 : ::com::sun::star::document::XExporter,
57 : ::com::sun::star::document::XImporter,
58 : ::com::sun::star::lang::XServiceInfo >
59 : {
60 : public:
61 : explicit XMLFilter( ::com::sun::star::uno::Reference<
62 : ::com::sun::star::uno::XComponentContext > const & xContext );
63 : virtual ~XMLFilter();
64 :
65 : /// establish methods for factory instatiation
66 : static css::uno::Reference< css::uno::XInterface > SAL_CALL create( css::uno::Reference< css::uno::XComponentContext > const & xContext)
67 : throw(css::uno::Exception)
68 : {
69 : return static_cast<cppu::OWeakObject *>(new XMLFilter( xContext ));
70 : }
71 : /// XServiceInfo declarations
72 : virtual OUString SAL_CALL getImplementationName()
73 : throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
74 : virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
75 : throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
76 : virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
77 : throw( css::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
78 :
79 : static OUString getImplementationName_Static();
80 : static css::uno::Sequence< OUString > getSupportedServiceNames_Static();
81 :
82 : protected:
83 : // ____ XFilter ____
84 : virtual sal_Bool SAL_CALL filter(
85 : const ::com::sun::star::uno::Sequence<
86 : ::com::sun::star::beans::PropertyValue >& aDescriptor )
87 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
88 : virtual void SAL_CALL cancel()
89 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
90 :
91 : // ____ XImporter ____
92 : virtual void SAL_CALL setTargetDocument(
93 : const ::com::sun::star::uno::Reference<
94 : ::com::sun::star::lang::XComponent >& Document )
95 : throw (::com::sun::star::lang::IllegalArgumentException,
96 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
97 :
98 : // ____ XExporter ____
99 : virtual void SAL_CALL setSourceDocument(
100 : const ::com::sun::star::uno::Reference<
101 : ::com::sun::star::lang::XComponent >& Document )
102 : throw (::com::sun::star::lang::IllegalArgumentException,
103 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
104 :
105 : inline OUString getDocumentHandler() const { return m_sDocumentHandler; }
106 0 : inline void setDocumentHandler(const OUString& _sDocumentHandler) { m_sDocumentHandler = _sDocumentHandler; }
107 :
108 : virtual OUString getMediaType(bool _bOasis);
109 :
110 : /** fills the oasis flag only when a filtername was set
111 : *
112 : * \param _rMediaDescriptor
113 : * \param _rOutOASIS
114 : */
115 : virtual void isOasisFormat(const ::com::sun::star::uno::Sequence<
116 : ::com::sun::star::beans::PropertyValue >& _rMediaDescriptor, bool & _rOutOASIS );
117 :
118 : private:
119 : // methods
120 :
121 : /// @return a warning code, or 0 for successful operation
122 : sal_Int32 impl_Import( const ::com::sun::star::uno::Reference<
123 : ::com::sun::star::lang::XComponent > & xDocumentComp,
124 : const ::com::sun::star::uno::Sequence<
125 : ::com::sun::star::beans::PropertyValue > & aMediaDescriptor );
126 : /// @return a warning code, or 0 for successful operation
127 : sal_Int32 impl_ImportStream(
128 : const OUString & rStreamName,
129 : const OUString & rServiceName,
130 : const ::com::sun::star::uno::Reference<
131 : ::com::sun::star::embed::XStorage > & xStorage,
132 : const ::com::sun::star::uno::Reference<
133 : ::com::sun::star::xml::sax::XParser > & xParser,
134 : const ::com::sun::star::uno::Reference<
135 : ::com::sun::star::lang::XMultiComponentFactory > & xFactory,
136 : const ::com::sun::star::uno::Reference<
137 : ::com::sun::star::document::XGraphicObjectResolver > & xGraphicObjectResolver,
138 : ::com::sun::star::uno::Reference<
139 : ::com::sun::star::beans::XPropertySet >& xPropSet );
140 :
141 : /// @return a warning code, or 0 for successful operation
142 : sal_Int32 impl_Export( const ::com::sun::star::uno::Reference<
143 : ::com::sun::star::lang::XComponent > & xDocumentComp,
144 : const ::com::sun::star::uno::Sequence<
145 : ::com::sun::star::beans::PropertyValue > & aMediaDescriptor );
146 : /// @return a warning code, or 0 for successful operation
147 : sal_Int32 impl_ExportStream(
148 : const OUString & rStreamName,
149 : const OUString & rServiceName,
150 : const ::com::sun::star::uno::Reference<
151 : ::com::sun::star::embed::XStorage > & xStorage,
152 : const ::com::sun::star::uno::Reference<
153 : ::com::sun::star::xml::sax::XWriter >& xActiveDataSource,
154 : const ::com::sun::star::uno::Reference<
155 : ::com::sun::star::lang::XMultiServiceFactory > & xFactory,
156 : const ::com::sun::star::uno::Sequence<
157 : ::com::sun::star::uno::Any > & rFilterProperties );
158 :
159 : // members
160 : ::com::sun::star::uno::Reference<
161 : ::com::sun::star::uno::XComponentContext > m_xContext;
162 : ::com::sun::star::uno::Reference<
163 : ::com::sun::star::lang::XComponent > m_xTargetDoc;
164 : ::com::sun::star::uno::Reference<
165 : ::com::sun::star::lang::XComponent > m_xSourceDoc;
166 :
167 : css::uno::Sequence<css::beans::PropertyValue> m_aMediaDescriptor;
168 :
169 : OUString m_sDocumentHandler; // when set it will be set as doc handler
170 :
171 : volatile bool m_bCancelOperation;
172 : ::osl::Mutex m_aMutex;
173 : };
174 :
175 2 : class XMLReportFilterHelper : public XMLFilter
176 : {
177 : virtual void isOasisFormat(const ::com::sun::star::uno::Sequence<
178 : ::com::sun::star::beans::PropertyValue >& _rMediaDescriptor, bool & _rOutOASIS ) SAL_OVERRIDE;
179 : public:
180 1 : explicit XMLReportFilterHelper( ::com::sun::star::uno::Reference<
181 : ::com::sun::star::uno::XComponentContext > const & _xContext )
182 1 : :XMLFilter(_xContext)
183 1 : {}
184 : /// establish methods for factory instatiation
185 : static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL create(
186 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext) throw(::com::sun::star::uno::Exception)
187 : {
188 : return static_cast<cppu::OWeakObject *>(new XMLReportFilterHelper( xContext ));
189 : }
190 1 : static OUString getImplementationName_Static()
191 : {
192 1 : return OUString( "com.sun.star.comp.chart2.report.XMLFilter" );
193 : }
194 : protected:
195 : virtual OUString SAL_CALL
196 1 : getImplementationName()
197 : throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE
198 : {
199 1 : return getImplementationName_Static();
200 : }
201 : // ____ XImporter ____
202 0 : virtual void SAL_CALL setTargetDocument(
203 : const ::com::sun::star::uno::Reference<
204 : ::com::sun::star::lang::XComponent >& Document )
205 : throw (::com::sun::star::lang::IllegalArgumentException,
206 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
207 : {
208 0 : setDocumentHandler( "com.sun.star.comp.report.ImportDocumentHandler" );
209 0 : XMLFilter::setTargetDocument(Document);
210 0 : }
211 :
212 : // ____ XExporter ____
213 0 : virtual void SAL_CALL setSourceDocument(
214 : const ::com::sun::star::uno::Reference<
215 : ::com::sun::star::lang::XComponent >& Document )
216 : throw (::com::sun::star::lang::IllegalArgumentException,
217 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
218 : {
219 0 : setDocumentHandler( "com.sun.star.comp.report.ExportDocumentHandler" );
220 0 : XMLFilter::setSourceDocument(Document);
221 0 : }
222 :
223 : virtual OUString getMediaType(bool _bOasis) SAL_OVERRIDE;
224 : };
225 :
226 : } // namespace chart
227 :
228 : // INCLUDED_CHART2_SOURCE_MODEL_INC_XMLFILTER_HXX
229 : #endif
230 :
231 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|