Filter extensions

From Apache OpenOffice Wiki
Revision as of 17:13, 27 October 2008 by Mba (Talk | contribs)

Jump to: navigation, search
OOo Extensions project

Please view the wiki usage guidelines
before contributing.

Categories:

Pages:

Extensions on the main site

Extensions in other languages:
ES - FR - IT - JA - NL - OC -

OOo Filter Extensions: Basic Principles

Any document filter (either import or export of both in one component) can be provided as an extension. This extension will contain the filter either as a UNO component (shared library, jar file, Python module) or an xslt file. A detailed description how filters are developed can be found in the Developer's Guide. What you can find here is: how can I deploy my filter as an extension? To make it simple, a sample extension is used and described here. The sample contains the built-in MediaWiki filter of OOo3.0, packaged as an extension.

A filter extension must contain the filter configuration and the type configuration in case the filter is made for a type that OOo does not know already. Here's the configuration of the sample extension:

<?xml version="1.0" encoding="UTF-8"?>
<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="Filter" oor:package="org.openoffice.TypeDetection">
 <node oor:name="Filters">
        <node oor:name="MediaWiki" oor:op="replace">
                <prop oor:name="FileFormatVersion"><value>0</value></prop>
                <prop oor:name="Type"><value>MediaWiki</value></prop>
                <prop oor:name="DocumentService"><value>com.sun.star.text.TextDocument</value></prop>
                <prop oor:name="UIComponent"/>
                <prop oor:name="UserData"><value oor:separator=",">com.sun.star.documentconversion.XSLTFilter,,,com.sun.star.comp.Writer.XMLOasisExporter,,%origin%/filter/odt2mediawiki.xsl</value></prop>
                <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.XmlFilterAdaptor</value></prop>
                <prop oor:name="UIName">
                        <value xml:lang="x-default">MediaWiki</value>
                </prop>
                <prop oor:name="Flags"><value>EXPORT ALIEN 3RDPARTYFILTER</value></prop>
        </node>
        <node oor:name="MediaWiki_Web" oor:op="replace">
                <prop oor:name="FileFormatVersion"><value>0</value></prop>
                <prop oor:name="Type"><value>MediaWiki</value></prop>
                <prop oor:name="DocumentService"><value>com.sun.star.text.WebDocument</value></prop>
                <prop oor:name="UIComponent"/>
                <prop oor:name="UserData"><value oor:separator=",">com.sun.star.documentconversion.XSLTFilter,,,com.sun.star.comp.Writer.XMLOasisExporter,,%origin%/filter/odt2mediawiki.xsl</value></prop>
                <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.XmlFilterAdaptor</value></prop>
                <prop oor:name="UIName">
                        <value xml:lang="x-default">MediaWiki</value>
                </prop>
                <prop oor:name="Flags"><value>EXPORT ALIEN 3RDPARTYFILTER</value></prop>
        </node>
 </node>
</oor:component-data>

The various parameters are described in the Developer's Guide. As you can read there, For filters based on code written in Java or C++ the only difference to this xslt filter is the content in the "UserData" parameter of the filter configuration.

In case of the xslt filter the filter configuration points to the place where the xsl file (or in case of a more complex transformation: the main xsl file) is found. It's coded as %origin%/filter/odt2mediawiki.xsl. "%origin%" points to the folder inside the zip package where the xcu file is located, here it's the root directory of the zip package. So the xsl is found in a folder "filter" inside the package. In case of a C++ or Java filter the configuration would point to the UNO service or implementation name of the filter component.

The "Type" parameter of the filter configuration points to the "MediaWiki" type that is configured in another configuration node:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE oor:component-data SYSTEM "../../../../component-update.dtd">
<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:package="org.openoffice.TypeDetection" oor:name="Types">
        <node oor:name="Types">
        <node oor:name="MediaWiki" oor:op="replace">
                <prop oor:name="DetectService"><value>com.sun.star.comp.filters.XMLFilterDetect</value></prop>
                <prop oor:name="URLPattern"/>
                <prop oor:name="Extensions"><value>txt</value></prop>
                <prop oor:name="MediaType"/>
                <prop oor:name="Preferred"><value>false</value></prop>
                <prop oor:name="PreferredFilter"/>
                <prop oor:name="UIName">
                        <value xml:lang="x-default">MediaWiki</value>
                </prop>
                <prop oor:name="ClipboardFormat"/>
        </node>
        </node>
</oor:component-data>

Again the parameters are described in the Developer's Guide.

As always in extensions, a manifest and a description.xml have to be added. That's it.

If you want to provide your own xsl filter, just adapt the Filter.xcu and Type.xcu files and the description.xml and of course add your xsl file(s).

Personal tools