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