[ooo-build-commit] .: filter/source writerfilter/source

Cédric Bosdonnat cbosdo at kemper.freedesktop.org
Fri Sep 17 04:17:04 PDT 2010


 filter/source/config/fragments/filters/Rich_Text_Format.xcu |    4 
 writerfilter/source/filter/RtfFilter.cxx                    |  145 ++++++++++++
 writerfilter/source/filter/RtfFilter.hxx                    |  100 ++++++++
 writerfilter/source/filter/WriterFilter.cxx                 |    2 
 writerfilter/source/filter/makefile.mk                      |    3 
 5 files changed, 251 insertions(+), 3 deletions(-)

New commits:
commit 3a22f10e8203aa10439026940a3cef4963017d59
Author: Miklos Vajna <vmiklos at frugalware.org>
Date:   Fri Sep 17 12:12:53 2010 +0200

    cws-vmiklos01.diff: Better RTF export filter

diff --git a/filter/source/config/fragments/filters/Rich_Text_Format.xcu b/filter/source/config/fragments/filters/Rich_Text_Format.xcu
index dc8b07e..d8fb18c 100644
--- a/filter/source/config/fragments/filters/Rich_Text_Format.xcu
+++ b/filter/source/config/fragments/filters/Rich_Text_Format.xcu
@@ -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>
diff --git a/writerfilter/source/filter/RtfFilter.cxx b/writerfilter/source/filter/RtfFilter.cxx
new file mode 100644
index 0000000..b9445bb
--- /dev/null
+++ b/writerfilter/source/filter/RtfFilter.cxx
@@ -0,0 +1,145 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * 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: */
diff --git a/writerfilter/source/filter/RtfFilter.hxx b/writerfilter/source/filter/RtfFilter.hxx
new file mode 100644
index 0000000..7a00b3b
--- /dev/null
+++ b/writerfilter/source/filter/RtfFilter.hxx
@@ -0,0 +1,100 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * 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
diff --git a/writerfilter/source/filter/WriterFilter.cxx b/writerfilter/source/filter/WriterFilter.cxx
index 922cfc2..3c8cb75 100644
--- a/writerfilter/source/filter/WriterFilter.cxx
+++ b/writerfilter/source/filter/WriterFilter.cxx
@@ -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
 };
 
diff --git a/writerfilter/source/filter/makefile.mk b/writerfilter/source/filter/makefile.mk
index f578e28..6b11fd4 100644
--- a/writerfilter/source/filter/makefile.mk
+++ b/writerfilter/source/filter/makefile.mk
@@ -40,7 +40,8 @@ ENABLE_EXCEPTIONS=TRUE
 
 SLOFILES=           $(SLO)$/WriterFilter.obj \
                     $(SLO)$/WriterFilterDetection.obj \
-                    $(SLO)$/ImportFilter.obj
+                    $(SLO)$/ImportFilter.obj \
+                    $(SLO)$/RtfFilter.obj
 
 
 # --- Targets ----------------------------------


More information about the ooo-build-commit mailing list