1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_CHART2_SOURCE_MODEL_INC_XMLFILTER_HXX
20 #define INCLUDED_CHART2_SOURCE_MODEL_INC_XMLFILTER_HXX
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>
35 namespace com
{ namespace sun
{ namespace star
{
40 namespace xml
{ namespace sax
46 class XGraphicObjectResolver
;
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
>
61 explicit XMLFilter( ::com::sun::star::uno::Reference
<
62 ::com::sun::star::uno::XComponentContext
> const & xContext
);
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
)
69 return (::cppu::OWeakObject
*)new XMLFilter( xContext
);
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
;
79 static OUString
getImplementationName_Static();
80 static css::uno::Sequence
< OUString
> getSupportedServiceNames_Static();
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
;
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
;
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
;
105 inline OUString
getDocumentHandler() const { return m_sDocumentHandler
; }
106 inline void setDocumentHandler(const OUString
& _sDocumentHandler
) { m_sDocumentHandler
= _sDocumentHandler
; }
108 virtual OUString
getMediaType(bool _bOasis
);
110 /** fills the oasis flag only when a filtername was set
112 * \param _rMediaDescriptor
115 virtual void isOasisFormat(const ::com::sun::star::uno::Sequence
<
116 ::com::sun::star::beans::PropertyValue
>& _rMediaDescriptor
, bool & _rOutOASIS
);
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
);
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
);
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
;
167 css::uno::Sequence
<css::beans::PropertyValue
> m_aMediaDescriptor
;
169 OUString m_sDocumentHandler
; // when set it will be set as doc handler
171 volatile bool m_bCancelOperation
;
172 ::osl::Mutex m_aMutex
;
175 class XMLReportFilterHelper
: public XMLFilter
177 virtual void isOasisFormat(const ::com::sun::star::uno::Sequence
<
178 ::com::sun::star::beans::PropertyValue
>& _rMediaDescriptor
, bool & _rOutOASIS
) SAL_OVERRIDE
;
180 explicit XMLReportFilterHelper( ::com::sun::star::uno::Reference
<
181 ::com::sun::star::uno::XComponentContext
> const & _xContext
)
182 :XMLFilter(_xContext
)
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
)
188 return (::cppu::OWeakObject
*)new XMLReportFilterHelper( xContext
);
190 static OUString
getImplementationName_Static()
192 return OUString( "com.sun.star.comp.chart2.report.XMLFilter" );
195 virtual OUString SAL_CALL
196 getImplementationName()
197 throw( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
199 return getImplementationName_Static();
201 // ____ XImporter ____
202 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
208 setDocumentHandler( "com.sun.star.comp.report.ImportDocumentHandler" );
209 XMLFilter::setTargetDocument(Document
);
212 // ____ XExporter ____
213 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
219 setDocumentHandler( "com.sun.star.comp.report.ExportDocumentHandler" );
220 XMLFilter::setSourceDocument(Document
);
223 virtual OUString
getMediaType(bool _bOasis
) SAL_OVERRIDE
;
228 // INCLUDED_CHART2_SOURCE_MODEL_INC_XMLFILTER_HXX
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */