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/XServiceInfo.hpp>
28 : #include <com/sun/star/uno/XComponentContext.hpp>
29 : #include <com/sun/star/io/XActiveDataSource.hpp>
30 : #include <com/sun/star/xml/sax/XWriter.hpp>
31 : #include <osl/mutex.hxx>
32 :
33 : // for APPHELPER_... macros
34 : #include "ServiceMacros.hxx"
35 :
36 : namespace com { namespace sun { namespace star {
37 : namespace embed
38 : {
39 : class XStorage;
40 : }
41 : namespace xml { namespace sax
42 : {
43 : class XParser;
44 : }}
45 : namespace document
46 : {
47 : class XGraphicObjectResolver;
48 : }
49 : }}}
50 :
51 : namespace chart
52 : {
53 :
54 : class XMLFilter : public
55 : ::cppu::WeakImplHelper4<
56 : ::com::sun::star::document::XFilter,
57 : ::com::sun::star::document::XExporter,
58 : ::com::sun::star::document::XImporter,
59 : ::com::sun::star::lang::XServiceInfo >
60 : {
61 : public:
62 : explicit XMLFilter( ::com::sun::star::uno::Reference<
63 : ::com::sun::star::uno::XComponentContext > const & xContext );
64 : virtual ~XMLFilter();
65 :
66 : /// establish methods for factory instatiation
67 0 : APPHELPER_SERVICE_FACTORY_HELPER( XMLFilter )
68 : /// XServiceInfo declarations
69 : APPHELPER_XSERVICEINFO_DECL()
70 :
71 : protected:
72 : // ____ XFilter ____
73 : virtual sal_Bool SAL_CALL filter(
74 : const ::com::sun::star::uno::Sequence<
75 : ::com::sun::star::beans::PropertyValue >& aDescriptor )
76 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
77 : virtual void SAL_CALL cancel()
78 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
79 :
80 : // ____ XImporter ____
81 : virtual void SAL_CALL setTargetDocument(
82 : const ::com::sun::star::uno::Reference<
83 : ::com::sun::star::lang::XComponent >& Document )
84 : throw (::com::sun::star::lang::IllegalArgumentException,
85 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
86 :
87 : // ____ XExporter ____
88 : virtual void SAL_CALL setSourceDocument(
89 : const ::com::sun::star::uno::Reference<
90 : ::com::sun::star::lang::XComponent >& Document )
91 : throw (::com::sun::star::lang::IllegalArgumentException,
92 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
93 :
94 : inline OUString getDocumentHandler() const { return m_sDocumentHandler; }
95 0 : inline void setDocumentHandler(const OUString& _sDocumentHandler) { m_sDocumentHandler = _sDocumentHandler; }
96 :
97 : virtual OUString getMediaType(bool _bOasis);
98 :
99 : /** fills the oasis flag only when a filtername was set
100 : *
101 : * \param _rMediaDescriptor
102 : * \param _rOutOASIS
103 : */
104 : virtual void isOasisFormat(const ::com::sun::star::uno::Sequence<
105 : ::com::sun::star::beans::PropertyValue >& _rMediaDescriptor, bool & _rOutOASIS );
106 :
107 : private:
108 : // methods
109 :
110 : /// @return a warning code, or 0 for successful operation
111 : sal_Int32 impl_Import( const ::com::sun::star::uno::Reference<
112 : ::com::sun::star::lang::XComponent > & xDocumentComp,
113 : const ::com::sun::star::uno::Sequence<
114 : ::com::sun::star::beans::PropertyValue > & aMediaDescriptor );
115 : /// @return a warning code, or 0 for successful operation
116 : sal_Int32 impl_ImportStream(
117 : const OUString & rStreamName,
118 : const OUString & rServiceName,
119 : const ::com::sun::star::uno::Reference<
120 : ::com::sun::star::embed::XStorage > & xStorage,
121 : const ::com::sun::star::uno::Reference<
122 : ::com::sun::star::xml::sax::XParser > & xParser,
123 : const ::com::sun::star::uno::Reference<
124 : ::com::sun::star::lang::XMultiComponentFactory > & xFactory,
125 : const ::com::sun::star::uno::Reference<
126 : ::com::sun::star::document::XGraphicObjectResolver > & xGraphicObjectResolver,
127 : ::com::sun::star::uno::Reference<
128 : ::com::sun::star::beans::XPropertySet >& xPropSet );
129 :
130 : /// @return a warning code, or 0 for successful operation
131 : sal_Int32 impl_Export( const ::com::sun::star::uno::Reference<
132 : ::com::sun::star::lang::XComponent > & xDocumentComp,
133 : const ::com::sun::star::uno::Sequence<
134 : ::com::sun::star::beans::PropertyValue > & aMediaDescriptor );
135 : /// @return a warning code, or 0 for successful operation
136 : sal_Int32 impl_ExportStream(
137 : const OUString & rStreamName,
138 : const OUString & rServiceName,
139 : const ::com::sun::star::uno::Reference<
140 : ::com::sun::star::embed::XStorage > & xStorage,
141 : const ::com::sun::star::uno::Reference<
142 : ::com::sun::star::xml::sax::XWriter >& xActiveDataSource,
143 : const ::com::sun::star::uno::Reference<
144 : ::com::sun::star::lang::XMultiServiceFactory > & xFactory,
145 : const ::com::sun::star::uno::Sequence<
146 : ::com::sun::star::uno::Any > & rFilterProperties );
147 :
148 : // members
149 : ::com::sun::star::uno::Reference<
150 : ::com::sun::star::uno::XComponentContext > m_xContext;
151 : ::com::sun::star::uno::Reference<
152 : ::com::sun::star::lang::XComponent > m_xTargetDoc;
153 : ::com::sun::star::uno::Reference<
154 : ::com::sun::star::lang::XComponent > m_xSourceDoc;
155 : OUString m_sDocumentHandler; // when set it will be set as doc handler
156 :
157 : volatile bool m_bCancelOperation;
158 : ::osl::Mutex m_aMutex;
159 : };
160 :
161 0 : class XMLReportFilterHelper : public XMLFilter
162 : {
163 : virtual void isOasisFormat(const ::com::sun::star::uno::Sequence<
164 : ::com::sun::star::beans::PropertyValue >& _rMediaDescriptor, bool & _rOutOASIS ) SAL_OVERRIDE;
165 : public:
166 0 : explicit XMLReportFilterHelper( ::com::sun::star::uno::Reference<
167 : ::com::sun::star::uno::XComponentContext > const & _xContext )
168 0 : :XMLFilter(_xContext)
169 0 : {}
170 : /// establish methods for factory instatiation
171 0 : static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL create(
172 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext) throw(::com::sun::star::uno::Exception)
173 : {
174 0 : return (::cppu::OWeakObject *)new XMLReportFilterHelper( xContext );
175 : }
176 0 : static OUString getImplementationName_Static()
177 : {
178 0 : return OUString( "com.sun.star.comp.chart2.report.XMLFilter" );
179 : }
180 : protected:
181 : virtual OUString SAL_CALL
182 0 : getImplementationName()
183 : throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE
184 : {
185 0 : return getImplementationName_Static();
186 : }
187 : // ____ XImporter ____
188 0 : virtual void SAL_CALL setTargetDocument(
189 : const ::com::sun::star::uno::Reference<
190 : ::com::sun::star::lang::XComponent >& Document )
191 : throw (::com::sun::star::lang::IllegalArgumentException,
192 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
193 : {
194 0 : setDocumentHandler( "com.sun.star.comp.report.ImportDocumentHandler" );
195 0 : XMLFilter::setTargetDocument(Document);
196 0 : }
197 :
198 : // ____ XExporter ____
199 0 : virtual void SAL_CALL setSourceDocument(
200 : const ::com::sun::star::uno::Reference<
201 : ::com::sun::star::lang::XComponent >& Document )
202 : throw (::com::sun::star::lang::IllegalArgumentException,
203 : ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
204 : {
205 0 : setDocumentHandler( "com.sun.star.comp.report.ExportDocumentHandler" );
206 0 : XMLFilter::setSourceDocument(Document);
207 0 : }
208 :
209 : virtual OUString getMediaType(bool _bOasis) SAL_OVERRIDE;
210 : };
211 :
212 : } // namespace chart
213 :
214 : // INCLUDED_CHART2_SOURCE_MODEL_INC_XMLFILTER_HXX
215 : #endif
216 :
217 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|