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 .
21 #include <cppuhelper/implbase.hxx>
22 #include <com/sun/star/document/XFilter.hpp>
23 #include <com/sun/star/document/XImporter.hpp>
24 #include <com/sun/star/document/XExporter.hpp>
25 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/io/XActiveDataSource.hpp>
28 #include <osl/mutex.hxx>
29 #include <vcl/errcode.hxx>
31 namespace com::sun::star::beans
{ class XPropertySet
; }
32 namespace com::sun::star::uno
{ class XComponentContext
; }
33 namespace com::sun::star::xml::sax
{ class XWriter
; }
34 namespace com::sun::star::lang
{ class XMultiComponentFactory
; }
36 namespace com::sun::star
{
44 class XGraphicStorageHandler
;
51 class XMLFilter
: public
52 ::cppu::WeakImplHelper
<
53 css::document::XFilter
,
54 css::document::XExporter
,
55 css::document::XImporter
,
56 css::lang::XServiceInfo
>
59 explicit XMLFilter( css::uno::Reference
< css::uno::XComponentContext
> const & xContext
);
60 virtual ~XMLFilter() override
;
62 /// XServiceInfo declarations
63 virtual OUString SAL_CALL
getImplementationName() override
;
64 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
65 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
69 virtual sal_Bool SAL_CALL
filter(
70 const css::uno::Sequence
< css::beans::PropertyValue
>& aDescriptor
) override
;
71 virtual void SAL_CALL
cancel() override
;
73 // ____ XImporter ____
74 virtual void SAL_CALL
setTargetDocument(
75 const css::uno::Reference
< css::lang::XComponent
>& Document
) override
;
77 // ____ XExporter ____
78 virtual void SAL_CALL
setSourceDocument(
79 const css::uno::Reference
< css::lang::XComponent
>& Document
) override
;
81 void setDocumentHandler(const OUString
& _sDocumentHandler
) { m_sDocumentHandler
= _sDocumentHandler
; }
83 virtual OUString
getMediaType(bool _bOasis
);
85 /** fills the oasis flag only when a filtername was set
87 * \param _rMediaDescriptor
90 virtual void isOasisFormat(const css::uno::Sequence
< css::beans::PropertyValue
>& _rMediaDescriptor
, bool & _rOutOASIS
);
95 /// @return a warning code, or 0 for successful operation
96 ErrCode
impl_Import( const css::uno::Reference
< css::lang::XComponent
> & xDocumentComp
,
97 const css::uno::Sequence
< css::beans::PropertyValue
> & aMediaDescriptor
);
98 /// @return a warning code, or 0 for successful operation
99 ErrCode
impl_ImportStream(
100 const OUString
& rStreamName
,
101 const OUString
& rServiceName
,
102 const css::uno::Reference
< css::embed::XStorage
> & xStorage
,
103 const css::uno::Reference
< css::lang::XMultiComponentFactory
> & xFactory
,
104 const css::uno::Reference
<css::document::XGraphicStorageHandler
> & xGraphicStorageHandler
,
105 css::uno::Reference
< css::beans::XPropertySet
> const & xPropSet
);
107 /// @return a warning code, or 0 for successful operation
108 ErrCode
impl_Export( const css::uno::Reference
< css::lang::XComponent
> & xDocumentComp
,
109 const css::uno::Sequence
< css::beans::PropertyValue
> & aMediaDescriptor
);
110 /// @return a warning code, or 0 for successful operation
111 ErrCode
impl_ExportStream(
112 const OUString
& rStreamName
,
113 const OUString
& rServiceName
,
114 const css::uno::Reference
< css::embed::XStorage
> & xStorage
,
115 const css::uno::Reference
< css::xml::sax::XWriter
>& xActiveDataSource
,
116 const css::uno::Reference
< css::lang::XMultiServiceFactory
> & xFactory
,
117 const css::uno::Sequence
< css::uno::Any
> & rFilterProperties
);
120 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
121 css::uno::Reference
< css::lang::XComponent
> m_xTargetDoc
;
122 css::uno::Reference
< css::lang::XComponent
> m_xSourceDoc
;
124 css::uno::Sequence
<css::beans::PropertyValue
> m_aMediaDescriptor
;
126 OUString m_sDocumentHandler
; // when set it will be set as doc handler
128 volatile bool m_bCancelOperation
;
129 ::osl::Mutex m_aMutex
;
132 class XMLReportFilterHelper
: public XMLFilter
134 virtual void isOasisFormat(const css::uno::Sequence
< css::beans::PropertyValue
>& _rMediaDescriptor
,
135 bool & _rOutOASIS
) override
;
137 explicit XMLReportFilterHelper( css::uno::Reference
< css::uno::XComponentContext
> const & _xContext
)
138 :XMLFilter(_xContext
)
141 virtual OUString SAL_CALL
142 getImplementationName() override
144 return "com.sun.star.comp.chart2.report.XMLFilter";
146 // ____ XImporter ____
147 virtual void SAL_CALL
setTargetDocument(
148 const css::uno::Reference
< css::lang::XComponent
>& Document
) override
150 setDocumentHandler( "com.sun.star.comp.report.ImportDocumentHandler" );
151 XMLFilter::setTargetDocument(Document
);
154 // ____ XExporter ____
155 virtual void SAL_CALL
setSourceDocument(
156 const css::uno::Reference
< css::lang::XComponent
>& Document
) override
158 setDocumentHandler( "com.sun.star.comp.report.ExportDocumentHandler" );
159 XMLFilter::setSourceDocument(Document
);
162 virtual OUString
getMediaType(bool _bOasis
) override
;
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */