Difference between revisions of "Documentation/DevGuide/OfficeDev/Writing the Filtering Component"

From Apache OpenOffice Wiki
Jump to: navigation, search
 
(3 intermediate revisions by 3 users not shown)
Line 7: Line 7:
 
|NextPage=Documentation/DevGuide/OfficeDev/The Importer
 
|NextPage=Documentation/DevGuide/OfficeDev/The Importer
 
}}
 
}}
{{DISPLAYTITLE:Writing the Filtering Component}}
+
{{Documentation/DevGuideLanguages|Documentation/DevGuide/OfficeDev/{{SUBPAGENAME}}}}
 +
{{DISPLAYTITLE:Writing the Filtering Component}}
 
<!--<idltopic>com.sun.star.xml.ImportFilter;com.sun.star.xml.ExportFilter;com.sun.star.xml.XMLImportFilter;com.sun.star.xml.XMLImportFilter;com.sun.star.xml.sax.XDocumentHandler</idltopic>-->
 
<!--<idltopic>com.sun.star.xml.ImportFilter;com.sun.star.xml.ExportFilter;com.sun.star.xml.XMLImportFilter;com.sun.star.xml.XMLImportFilter;com.sun.star.xml.sax.XDocumentHandler</idltopic>-->
 
The filtering component must implement the following interfaces as described by the <idl>com.sun.star.xml.ImportFilter</idl> service and the <idl>com.sun.star.xml.ExportFilter</idl> service:
 
The filtering component must implement the following interfaces as described by the <idl>com.sun.star.xml.ImportFilter</idl> service and the <idl>com.sun.star.xml.ExportFilter</idl> service:
Line 22: Line 23:
  
 
The service <idl>com.sun.star.xml.XMLImportFilter</idl> defines an interface with the following method:
 
The service <idl>com.sun.star.xml.XMLImportFilter</idl> defines an interface with the following method:
<source lang="idl">
+
<syntaxhighlight lang="idl">
 
   boolean importer(
 
   boolean importer(
 
   [in] sequence< com::sun::star::beans::PropertyValue > aSourceData,
 
   [in] sequence< com::sun::star::beans::PropertyValue > aSourceData,
 
   [in] com::sun::star::xml::sax::XDocumentHandler xDocHandler,
 
   [in] com::sun::star::xml::sax::XDocumentHandler xDocHandler,
 
   [in] sequence< string > msUserData )
 
   [in] sequence< string > msUserData )
</source>
+
</syntaxhighlight>
 
<code>aSourceData</code> is a <code>MediaDescriptor</code>, which can be used to obtain the following information:
 
<code>aSourceData</code> is a <code>MediaDescriptor</code>, which can be used to obtain the following information:
  
Line 35: Line 36:
 
:This is the name of the file on the disk, that the input stream comes from.
 
:This is the name of the file on the disk, that the input stream comes from.
 
* <code>Url</code>
 
* <code>Url</code>
:This is a url describing the location being read.
+
:This is an URL describing the location being read.
  
<code>xDocHandler</code> is a SAX event handler that can be used when parsing an <code>XInputStream</code>, which may or may not contain {{PRODUCTNAME}} XML. Before this stream can be read by {{PRODUCTNAME}}, it will need to be transformed into {{PRODUCTNAME}} XML.  
+
<code>xDocHandler</code> is a SAX event handler that can be used when parsing an <code>XInputStream</code>, which may or may not contain {{AOo}} XML. Before this stream can be read by {{AOo}}, it will need to be transformed into {{AOo}} XML.  
  
 
<code>msUserData</code> is an array of <code>Strings</code>, that contains the information supplied in the <code>UserData</code> section of the <code>Filter</code> definition in the ''TypeDetection.xcu'' file.  
 
<code>msUserData</code> is an array of <code>Strings</code>, that contains the information supplied in the <code>UserData</code> section of the <code>Filter</code> definition in the ''TypeDetection.xcu'' file.  
Line 44: Line 45:
  
 
The <idl>com.sun.star.xml.XExportFilter</idl> defines an interface with the following method:
 
The <idl>com.sun.star.xml.XExportFilter</idl> defines an interface with the following method:
<source lang="idl">
+
<syntaxhighlight lang="idl">
 
   boolean exporter(  
 
   boolean exporter(  
 
   [in] sequence< com::sun::star::beans::PropertyValue > aSourceData,
 
   [in] sequence< com::sun::star::beans::PropertyValue > aSourceData,
 
   [in] sequence< string > msUserData )
 
   [in] sequence< string > msUserData )
</source>
+
</syntaxhighlight>
 
<code>aSourceData</code> and <code>msUserData</code> contain the same type of information as in the importer, except that the <code>MediaDescriptor</code> contains an <code>XOutputStream</code>, which can be used to write to.  
 
<code>aSourceData</code> and <code>msUserData</code> contain the same type of information as in the importer, except that the <code>MediaDescriptor</code> contains an <code>XOutputStream</code>, which can be used to write to.  
  
Line 56: Line 57:
 
When the export takes place, the new Filtering component must also be an <code>XDocumentHandler</code>, to allow the output based on SAX events to be filtered, if required. For this reason, an <code>XDocumentHandler</code> is not passed to the exporter, and any exporter that is used by the XML filter adaptor must implement the <idl>com.sun.star.xml.sax.XDocumentHandler</idl> interface.
 
When the export takes place, the new Filtering component must also be an <code>XDocumentHandler</code>, to allow the output based on SAX events to be filtered, if required. For this reason, an <code>XDocumentHandler</code> is not passed to the exporter, and any exporter that is used by the XML filter adaptor must implement the <idl>com.sun.star.xml.sax.XDocumentHandler</idl> interface.
  
{{Documentation/Note| In order for Java based components to operate effectively, a set of wrapper classes have been added to the ''javaunohelper'' package. These files allow for an XInputStream or an XOutputStream to be accessed using the same methods as a normal Java InputStream or OutputStream. These classes are located in the ''javaunohelper'' package at  
+
{{Note| In order for Java based components to operate effectively, a set of wrapper classes have been added to the ''javaunohelper'' package. These files allow for an XInputStream or an XOutputStream to be accessed using the same methods as a normal Java InputStream or OutputStream. These classes are located in the ''javaunohelper'' package at  
  
 
* com.sun.star.lib.uno.adapter.XInputStreamToInputStreamAdapter  
 
* com.sun.star.lib.uno.adapter.XInputStreamToInputStreamAdapter  
* com.sun.star.lib.uno.adapter.XInputStreamToInputStreamAdapter
+
* com.sun.star.lib.uno.adapter.XOutputStreamToOutputStreamAdapter
  
 
For more information on the use of these helper classes, see the flatxmljava example.}}
 
For more information on the use of these helper classes, see the flatxmljava example.}}

Latest revision as of 12:25, 3 January 2021



The filtering component must implement the following interfaces as described by the com.sun.star.xml.ImportFilter service and the com.sun.star.xml.ExportFilter service:

Importer:

com.sun.star.xml.XMLImportFilter

Exporter:

com.sun.star.xml.XMLExportFilter and com.sun.star.xml.sax.XDocumentHandler

XImportFilter

The service com.sun.star.xml.XMLImportFilter defines an interface with the following method:

  boolean importer(
  [in] sequence< com::sun::star::beans::PropertyValue > aSourceData,
  [in] com::sun::star::xml::sax::XDocumentHandler xDocHandler,
  [in] sequence< string > msUserData )

aSourceData is a MediaDescriptor, which can be used to obtain the following information:

  • An XInputStream
This is a stream that is attached to the source to be read. This can be a file, or some other data source.
  • Filename
This is the name of the file on the disk, that the input stream comes from.
  • Url
This is an URL describing the location being read.

xDocHandler is a SAX event handler that can be used when parsing an XInputStream, which may or may not contain Apache OpenOffice XML. Before this stream can be read by Apache OpenOffice, it will need to be transformed into Apache OpenOffice XML.

msUserData is an array of Strings, that contains the information supplied in the UserData section of the Filter definition in the TypeDetection.xcu file.

XExportFilter

The com.sun.star.xml.XExportFilter defines an interface with the following method:

  boolean exporter( 
  [in] sequence< com::sun::star::beans::PropertyValue > aSourceData,
  [in] sequence< string > msUserData )

aSourceData and msUserData contain the same type of information as in the importer, except that the MediaDescriptor contains an XOutputStream, which can be used to write to.

XDocumentHandler

When the export takes place, the new Filtering component must also be an XDocumentHandler, to allow the output based on SAX events to be filtered, if required. For this reason, an XDocumentHandler is not passed to the exporter, and any exporter that is used by the XML filter adaptor must implement the com.sun.star.xml.sax.XDocumentHandler interface.

Documentation note.png In order for Java based components to operate effectively, a set of wrapper classes have been added to the javaunohelper package. These files allow for an XInputStream or an XOutputStream to be accessed using the same methods as a normal Java InputStream or OutputStream. These classes are located in the javaunohelper package at
  • com.sun.star.lib.uno.adapter.XInputStreamToInputStreamAdapter
  • com.sun.star.lib.uno.adapter.XOutputStreamToOutputStreamAdapter

For more information on the use of these helper classes, see the flatxmljava example.

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