XML Based Filter Development

From Apache OpenOffice Wiki
< Documentation‎ | DevGuide
Revision as of 09:20, 30 September 2008 by Mba (Talk | contribs)

Jump to: navigation, search



Introduction

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.

The course of action during export and import can be described as follows: when a user clicks File - Open, or some UNO code calls loadComponentFromURL(), the office looks in the type detection configuration to identify an import filter and optionally checks the file format by doing some deep detection. It instantiates the import filter it finds 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 has to 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.

Similarly, the office instantiates an export filter after clicking File - Save (As) or a call to storeXXX(), and uses 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().

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools