This commit is contained in:
os 2010-09-23 12:54:46 +02:00
commit a7326cb13e
5 changed files with 254 additions and 3 deletions

View file

@ -1,7 +1,7 @@
<node oor:name="Rich Text Format" oor:op="replace">
<prop oor:name="Flags"><value>IMPORT EXPORT ALIEN PREFERRED</value></prop>
<prop oor:name="Flags"><value>IMPORT EXPORT ALIEN 3RDPARTYFILTER PREFERRED</value></prop>
<prop oor:name="UIComponent"/>
<prop oor:name="FilterService"/>
<prop oor:name="FilterService"><value>com.sun.star.comp.Writer.RtfFilter</value></prop>
<prop oor:name="UserData"><value>RTF</value></prop>
<prop oor:name="UIName">
<value xml:lang="x-default">Rich Text Format</value>

View file

@ -0,0 +1,146 @@
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
* Copyright 2010 Miklos Vajna.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#ifndef _CPPUHELPER_IMPLEMENTATIONENTRY_
#include <cppuhelper/implementationentry.hxx>
#endif
#include <osl/module.hxx>
#include <tools/solar.h>
#include <RtfFilter.hxx>
using namespace ::rtl;
using namespace ::cppu;
using namespace ::com::sun::star;
RtfFilter::RtfFilter( const uno::Reference< uno::XComponentContext >& rxContext) :
m_xContext( rxContext )
{
}
RtfFilter::~RtfFilter()
{
}
sal_Bool RtfFilter::filter( const uno::Sequence< beans::PropertyValue >& aDescriptor )
throw (uno::RuntimeException)
{
OSL_TRACE("%s", OSL_THIS_FUNC);
if( m_xSrcDoc.is() )
{
uno::Reference< lang::XMultiServiceFactory > xMSF(m_xContext->getServiceManager(), uno::UNO_QUERY_THROW);
uno::Reference< uno::XInterface > xIfc( xMSF->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.Writer.RtfExport" ))), uno::UNO_QUERY_THROW);
if (!xIfc.is())
return sal_False;
uno::Reference< document::XExporter > xExprtr(xIfc, uno::UNO_QUERY_THROW);
uno::Reference< document::XFilter > xFltr(xIfc, uno::UNO_QUERY_THROW);
if (!xExprtr.is() || !xFltr.is())
return sal_False;
xExprtr->setSourceDocument(m_xSrcDoc);
return xFltr->filter(aDescriptor);
}
else if ( m_xDstDoc.is() )
{
uno::Reference< lang::XMultiServiceFactory > xMSF(m_xContext->getServiceManager(), uno::UNO_QUERY_THROW);
uno::Reference< uno::XInterface > xIfc( xMSF->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.Writer.RtfImport" ))), uno::UNO_QUERY_THROW);
if (!xIfc.is())
return sal_False;
uno::Reference< document::XImporter > xImprtr(xIfc, uno::UNO_QUERY_THROW);
uno::Reference< document::XFilter > xFltr(xIfc, uno::UNO_QUERY_THROW);
if (!xImprtr.is() || !xFltr.is())
return sal_False;
xImprtr->setTargetDocument(m_xDstDoc);
return xFltr->filter(aDescriptor);
}
return sal_False;
}
void RtfFilter::cancel( ) throw (uno::RuntimeException)
{
}
void RtfFilter::setSourceDocument( const uno::Reference< lang::XComponent >& xDoc )
throw (lang::IllegalArgumentException, uno::RuntimeException)
{
m_xSrcDoc = xDoc;
}
void RtfFilter::setTargetDocument( const uno::Reference< lang::XComponent >& xDoc )
throw (lang::IllegalArgumentException, uno::RuntimeException)
{
m_xDstDoc = xDoc;
}
void RtfFilter::initialize( const uno::Sequence< uno::Any >& /*aArguments*/ ) throw (uno::Exception, uno::RuntimeException)
{
// The DOCX exporter here extracts 'type' of the filter, ie 'Word' or
// 'Word Template' but we don't need it for RTF.
}
OUString RtfFilter::getImplementationName( ) throw (uno::RuntimeException)
{
return RtfFilter_getImplementationName();
}
#define SERVICE_NAME1 "com.sun.star.document.ImportFilter"
#define SERVICE_NAME2 "com.sun.star.document.ExportFilter"
sal_Bool RtfFilter::supportsService( const OUString& rServiceName ) throw (uno::RuntimeException)
{
return (rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME1 ) ) ||
rServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME2 ) ));
}
uno::Sequence< OUString > RtfFilter::getSupportedServiceNames( ) throw (uno::RuntimeException)
{
return RtfFilter_getSupportedServiceNames();
}
/* Helpers, used by shared lib exports. */
OUString RtfFilter_getImplementationName () throw (uno::RuntimeException)
{
return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.Writer.RtfFilter" ) );
}
uno::Sequence< OUString > RtfFilter_getSupportedServiceNames( ) throw (uno::RuntimeException)
{
uno::Sequence < OUString > aRet(2);
OUString* pArray = aRet.getArray();
pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME1 ) );
pArray[1] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME2 ) );
return aRet;
}
#undef SERVICE_NAME1
#undef SERVICE_NAME2
uno::Reference< uno::XInterface > RtfFilter_createInstance( const uno::Reference< uno::XComponentContext >& xContext)
throw( uno::Exception )
{
return (cppu::OWeakObject*) new RtfFilter( xContext );
}
/* vi:set shiftwidth=4 expandtab: */

View file

@ -0,0 +1,102 @@
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
* Copyright 2010 Miklos Vajna.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#ifndef _RTFFILTER_HXX
#define _RTFFILTER_HXX
#include <com/sun/star/document/XFilter.hpp>
#include <com/sun/star/document/XImporter.hpp>
#include <com/sun/star/document/XExporter.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
#include <cppuhelper/implbase5.hxx>
#include <WriterFilterDllApi.hxx>
class WRITERFILTER_DLLPUBLIC RtfFilter : public cppu::WeakImplHelper5
<
com::sun::star::document::XFilter,
com::sun::star::document::XImporter,
com::sun::star::document::XExporter,
com::sun::star::lang::XInitialization,
com::sun::star::lang::XServiceInfo
>
{
protected:
::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > m_xSrcDoc, m_xDstDoc;
::rtl::OUString m_sFilterName;
::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > m_xHandler;
public:
RtfFilter( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext);
virtual ~RtfFilter();
// XFilter
virtual sal_Bool SAL_CALL filter( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor )
throw (::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL cancel( )
throw (::com::sun::star::uno::RuntimeException);
// XImporter
virtual void SAL_CALL setTargetDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc )
throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
// XExporter
virtual void SAL_CALL setSourceDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc )
throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
// XInitialization
virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments )
throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
// XServiceInfo
virtual ::rtl::OUString SAL_CALL getImplementationName( )
throw (::com::sun::star::uno::RuntimeException);
virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
throw (::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
throw (::com::sun::star::uno::RuntimeException);
};
::rtl::OUString RtfFilter_getImplementationName()
throw ( ::com::sun::star::uno::RuntimeException );
::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL RtfFilter_getSupportedServiceNames( )
throw ( ::com::sun::star::uno::RuntimeException );
::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL RtfFilter_createInstance(
const ::com::sun::star::uno::Reference<
::com::sun::star::uno::XComponentContext > &xContext)
throw( ::com::sun::star::uno::Exception );
#endif

View file

@ -30,6 +30,7 @@
#endif
#include <WriterFilter.hxx>
#include <WriterFilterDetection.hxx>
#include <RtfFilter.hxx>
using namespace ::rtl;
using namespace ::cppu;
@ -56,6 +57,7 @@ static struct ::cppu::ImplementationEntry s_component_entries [] =
{
{ WriterFilter_createInstance, WriterFilter_getImplementationName, WriterFilter_getSupportedServiceNames, ::cppu::createSingleComponentFactory, 0, 0 },
{ WriterFilterDetection_createInstance, WriterFilterDetection_getImplementationName, WriterFilterDetection_getSupportedServiceNames, ::cppu::createSingleComponentFactory, 0, 0} ,
{ RtfFilter_createInstance, RtfFilter_getImplementationName, RtfFilter_getSupportedServiceNames, ::cppu::createSingleComponentFactory, 0, 0 },
{ 0, 0, 0, 0, 0, 0 } // terminate with NULL
};

View file

@ -40,7 +40,8 @@ ENABLE_EXCEPTIONS=TRUE
SLOFILES= $(SLO)$/WriterFilter.obj \
$(SLO)$/WriterFilterDetection.obj \
$(SLO)$/ImportFilter.obj
$(SLO)$/ImportFilter.obj \
$(SLO)$/RtfFilter.obj
# --- Targets ----------------------------------