1b4a4f18cSAndrew Rist /**************************************************************
2*68128652Smseidel  *
3b4a4f18cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b4a4f18cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b4a4f18cSAndrew Rist  * distributed with this work for additional information
6b4a4f18cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b4a4f18cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b4a4f18cSAndrew Rist  * "License"); you may not use this file except in compliance
9b4a4f18cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*68128652Smseidel  *
11b4a4f18cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*68128652Smseidel  *
13b4a4f18cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b4a4f18cSAndrew Rist  * software distributed under the License is distributed on an
15b4a4f18cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b4a4f18cSAndrew Rist  * KIND, either express or implied.  See the License for the
17b4a4f18cSAndrew Rist  * specific language governing permissions and limitations
18b4a4f18cSAndrew Rist  * under the License.
19*68128652Smseidel  *
20b4a4f18cSAndrew Rist  *************************************************************/
21b4a4f18cSAndrew Rist 
22b4a4f18cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_
25cdf0e10cSrcweir #include <cppuhelper/implementationentry.hxx>
26cdf0e10cSrcweir #endif
27cdf0e10cSrcweir #include <osl/module.hxx>
28cdf0e10cSrcweir #include <tools/solar.h>
29cdf0e10cSrcweir #include <RtfFilter.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir using namespace ::rtl;
32cdf0e10cSrcweir using namespace ::cppu;
33cdf0e10cSrcweir using namespace ::com::sun::star;
34cdf0e10cSrcweir 
RtfFilter(const uno::Reference<uno::XComponentContext> & rxContext)35*68128652Smseidel RtfFilter::RtfFilter( const uno::Reference< uno::XComponentContext >& rxContext) :
36*68128652Smseidel 	m_xContext( rxContext )
37cdf0e10cSrcweir {
38cdf0e10cSrcweir }
39cdf0e10cSrcweir 
~RtfFilter()40cdf0e10cSrcweir RtfFilter::~RtfFilter()
41cdf0e10cSrcweir {
42cdf0e10cSrcweir }
43cdf0e10cSrcweir 
filter(const uno::Sequence<beans::PropertyValue> & aDescriptor)44cdf0e10cSrcweir sal_Bool RtfFilter::filter( const uno::Sequence< beans::PropertyValue >& aDescriptor )
45*68128652Smseidel 	throw (uno::RuntimeException)
46cdf0e10cSrcweir {
47*68128652Smseidel 	OSL_TRACE("%s", OSL_THIS_FUNC);
48*68128652Smseidel 	if( m_xSrcDoc.is() )
49*68128652Smseidel 	{
50*68128652Smseidel 		uno::Reference< lang::XMultiServiceFactory > xMSF(m_xContext->getServiceManager(), uno::UNO_QUERY_THROW);
51*68128652Smseidel 		uno::Reference< uno::XInterface > xIfc( xMSF->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.Writer.RtfExport" ))), uno::UNO_QUERY_THROW);
52*68128652Smseidel 		if (!xIfc.is())
53*68128652Smseidel 			return sal_False;
54*68128652Smseidel 		uno::Reference< document::XExporter > xExprtr(xIfc, uno::UNO_QUERY_THROW);
55*68128652Smseidel 		uno::Reference< document::XFilter > xFltr(xIfc, uno::UNO_QUERY_THROW);
56*68128652Smseidel 		if (!xExprtr.is() || !xFltr.is())
57*68128652Smseidel 			return sal_False;
58*68128652Smseidel 		xExprtr->setSourceDocument(m_xSrcDoc);
59*68128652Smseidel 		return xFltr->filter(aDescriptor);
60*68128652Smseidel 	}
61*68128652Smseidel 	else if ( m_xDstDoc.is() )
62*68128652Smseidel 	{
63*68128652Smseidel 		uno::Reference< lang::XMultiServiceFactory > xMSF(m_xContext->getServiceManager(), uno::UNO_QUERY_THROW);
64*68128652Smseidel 		uno::Reference< uno::XInterface > xIfc( xMSF->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.Writer.RtfImport" ))), uno::UNO_QUERY_THROW);
65*68128652Smseidel 		if (!xIfc.is())
66*68128652Smseidel 			return sal_False;
67*68128652Smseidel 		uno::Reference< document::XImporter > xImprtr(xIfc, uno::UNO_QUERY_THROW);
68*68128652Smseidel 		uno::Reference< document::XFilter > xFltr(xIfc, uno::UNO_QUERY_THROW);
69*68128652Smseidel 		if (!xImprtr.is() || !xFltr.is())
70*68128652Smseidel 			return sal_False;
71*68128652Smseidel 		xImprtr->setTargetDocument(m_xDstDoc);
72*68128652Smseidel 		return xFltr->filter(aDescriptor);
73*68128652Smseidel 	}
74*68128652Smseidel 	return sal_False;
75cdf0e10cSrcweir }
76cdf0e10cSrcweir 
cancel()77cdf0e10cSrcweir void RtfFilter::cancel(  ) throw (uno::RuntimeException)
78cdf0e10cSrcweir {
79cdf0e10cSrcweir }
80cdf0e10cSrcweir 
setSourceDocument(const uno::Reference<lang::XComponent> & xDoc)81cdf0e10cSrcweir void RtfFilter::setSourceDocument( const uno::Reference< lang::XComponent >& xDoc )
82*68128652Smseidel 	throw (lang::IllegalArgumentException, uno::RuntimeException)
83cdf0e10cSrcweir {
84*68128652Smseidel 	m_xSrcDoc = xDoc;
85cdf0e10cSrcweir }
86cdf0e10cSrcweir 
setTargetDocument(const uno::Reference<lang::XComponent> & xDoc)87cdf0e10cSrcweir void RtfFilter::setTargetDocument( const uno::Reference< lang::XComponent >& xDoc )
88*68128652Smseidel 	throw (lang::IllegalArgumentException, uno::RuntimeException)
89cdf0e10cSrcweir {
90*68128652Smseidel 	m_xDstDoc = xDoc;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
initialize(const uno::Sequence<uno::Any> &)93cdf0e10cSrcweir void RtfFilter::initialize( const uno::Sequence< uno::Any >& /*aArguments*/ ) throw (uno::Exception, uno::RuntimeException)
94cdf0e10cSrcweir {
95*68128652Smseidel 	// The DOCX exporter here extracts 'type' of the filter, i.e. 'Word' or
96*68128652Smseidel 	// 'Word Template' but we don't need it for RTF.
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
getImplementationName()99cdf0e10cSrcweir OUString RtfFilter::getImplementationName(  ) throw (uno::RuntimeException)
100cdf0e10cSrcweir {
101*68128652Smseidel 	return RtfFilter_getImplementationName();
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir #define SERVICE_NAME1 "com.sun.star.document.ImportFilter"
105cdf0e10cSrcweir #define SERVICE_NAME2 "com.sun.star.document.ExportFilter"
supportsService(const OUString & rServiceName)106cdf0e10cSrcweir sal_Bool RtfFilter::supportsService( const OUString& rServiceName ) throw (uno::RuntimeException)
107cdf0e10cSrcweir {
108*68128652Smseidel 	return (rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME1 ) ) ||
109*68128652Smseidel 			rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME2 ) ));
110cdf0e10cSrcweir }
111cdf0e10cSrcweir 
getSupportedServiceNames()112cdf0e10cSrcweir uno::Sequence< OUString > RtfFilter::getSupportedServiceNames(  ) throw (uno::RuntimeException)
113cdf0e10cSrcweir {
114*68128652Smseidel 	return RtfFilter_getSupportedServiceNames();
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir /* Helpers, used by shared lib exports. */
118cdf0e10cSrcweir 
RtfFilter_getImplementationName()119cdf0e10cSrcweir OUString RtfFilter_getImplementationName () throw (uno::RuntimeException)
120cdf0e10cSrcweir {
121*68128652Smseidel 	return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.Writer.RtfFilter" ) );
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
RtfFilter_getSupportedServiceNames()124cdf0e10cSrcweir uno::Sequence< OUString > RtfFilter_getSupportedServiceNames(  ) throw (uno::RuntimeException)
125cdf0e10cSrcweir {
126*68128652Smseidel 	uno::Sequence < OUString > aRet(2);
127*68128652Smseidel 	OUString* pArray = aRet.getArray();
128*68128652Smseidel 	pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME1 ) );
129*68128652Smseidel 	pArray[1] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME2 ) );
130*68128652Smseidel 	return aRet;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir #undef SERVICE_NAME1
133cdf0e10cSrcweir #undef SERVICE_NAME2
134cdf0e10cSrcweir 
RtfFilter_createInstance(const uno::Reference<uno::XComponentContext> & xContext)135cdf0e10cSrcweir uno::Reference< uno::XInterface > RtfFilter_createInstance( const uno::Reference< uno::XComponentContext >& xContext)
136*68128652Smseidel 				throw( uno::Exception )
137cdf0e10cSrcweir {
138*68128652Smseidel 	return (cppu::OWeakObject*) new RtfFilter( xContext );
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
141*68128652Smseidel /* vim: set noet sw=4 ts=4: */
142