XML Based Filter Development
This chapter outlines the development of XML based filtering components that use the XML filter adaptor framework. Further information is also available at http://xml.openoffice.org/filter/. The XML filter adaptor is a generic com.sun.star.document.XFilter implementation. It has been designed to be reusable, and to supply a standard method of designing and referencing XML based import and export filters. The XML filter adaptor does not perform any of the filtering functionality itself, but instead is used to instantiate a filtering component.
The advantage of the XML filter adapter framework is that you do not have to work with document models to create a document from an import file, nor do you have to iterate over a document model to export it to a different file format. Rather, you can use the OpenOffice.org XML file format to import and export. When importing, you parse your import file and send OpenOffice.org XML to the filter adaptor, which creates a document for you in the GUI. When exporting, the office sends a description of the current document as OpenOffice.org XML, so that you can export without having to iterate over a document model.
As described in the chapter about filters a filter works through its method
filter(). In case of XML based filters this method is implemented by the XML filter adaptor. Based on its "UserData" property it instantiates an XML import filter and uses its method importer() to pass a MediaDescriptor for the source, a specialized XML document handler for OpenOffice.org XML, and user data. The import filter must read the import source and deliver OpenOffice.org XML to the document handler received in the call to
importer(), emulating a SAX parser that calls the parser callback functions.
In case of export filters the same
filter() call will use the "UserData" property to instaniate an XML export filter and use its method exporter() to pass a target location and user data. In this case, the office expects the export filter to be a com.sun.star.xml.sax.XDocumentHandler, which is able to handle OpenOffice.org XML. The office creates an export stream with OpenOffice.org XML, and parses this XML so that the export filter receives the SAX callbacks and can translate them to whatever is necessary, writing the result to the target received in the call to com.sun.star.xml.XExportFilter:exporter().
There are currently three filtering components which use the XML filter adapter.
The first one is the
XMergeBridge. This has been created as a means of linking the
XMerge Small Device filter framework with OpenOffice.org. This means that any available
XMerge plugin, can also be used as a OpenOffice.org filter. This is currently hosted within the
XMerge project in OpenOffice HG at
The final two are a Java and a C++ implementation of a Flat OpenOffice.org XML reader and writer. These are intended to be sample filter component implementations, and offer a skeleton filter component that can be expanded upon by developers wishing to create their own filtering components. These are temporarily hosted in HG at
|Content on this page is licensed under the Public Documentation License (PDL).|