Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Writing Import filters for “beginners”

Writing Import filters for “beginners”

Fridrich Strba

February 11, 2011
Tweet

More Decks by Fridrich Strba

Other Decks in Technology

Transcript

  1. Writing Import filters for “beginners” Ha, ha, ha, I got

    you!!! Fridrich Štrba Software Engineer & TrainedMonkey™ LibreOffice Team Novell, Inc.
  2. © Novell, Inc. All rights reserved. 2 Agenda • Why

    would anybody care about writing import filters? • What interfaces are available for filter developers • Technicalities that will make you feel cool if I manage to explain them (after I actually understand them myself)
  3. © Novell, Inc. All rights reserved. 4 Legacy formats out

    there • ODF is the future of the humanity – Nevertheless, humanity does not know about it as of now • Other de facto standards – Some people use other Office Suites :( • Hard-disks full of teenage poetry in funny formats – LibreOffice offers the freedom to read that crap
  4. © Novell, Inc. All rights reserved. 5 Pure intellectual exercise

    • Allows to program for LibreOffice without having to understand the internals thereof – Pretty stand-alone functionality communicating with LibreOffice over well defined interfaces … – … almost • Happy users will reward you – You will be the hero of the people who can now read their documents... – … and they will get on your nerves listing features that are not converted.
  5. © Novell, Inc. All rights reserved. 7 XSLT filters •

    The easiest way to write an import filter from other xml format – Possibility to add using user interface … – … and export as an extension • Used services – com.sun.star.comp.Writer.XMLOasisImporter > XSLT filter that pushes to LibreOffice flat ODT – com.sun.star.comp.Calc.XMLOasisExporter > XSLT filter that receives from LibreOffice flat ODS • Now it is even fast – Someone rewrote it from Java to C++
  6. © Novell, Inc. All rights reserved. 11 Filter description <node

    oor:name="OpenDocument Text Flat XML" oor:op="replace"> <prop oor:name="FileFormatVersion"> <value>0</value> </prop> <prop oor:name="Type"> <value>writer_ODT_FlatXML</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.XMLOasisImporter,com.sun.star.comp.Writer.XMLOasisExporter, ../share/xslt/odfflatxml/odfflatxmlimport.xsl, ../share/xslt/odfflatxml/odfflatxmlexport.xsl </value> </prop> <prop oor:name="FilterService"> <value>com.sun.star.comp.Writer.XmlFilterAdaptor</value> </prop> <prop oor:name="TemplateName" /> <prop oor:name="UIName"> <value>OpenDocument Text (Flat XML)</value> </prop> <prop oor:name="Flags"> <value>IMPORT EXPORT OWN 3RDPARTYFILTER</value> </prop> </node>
  7. © Novell, Inc. All rights reserved. 12 Type description <node

    oor:name="writer_ODT_FlatXML" 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>fodt odt xml</value> </prop> <prop oor:name="MediaType" /> <prop oor:name="Preferred"> <value>false</value> </prop> <prop oor:name="PreferredFilter"> <value>OpenDocument Text Flat XML</value> </prop> <prop oor:name="UIName"> <value>OpenDocument Text (Flat XML)</value> </prop> <prop oor:name="ClipboardFormat"> <value> doctype:office:mimetype="application/vnd.oasis.opendocument.text"</value> </prop> </node>
  8. © Novell, Inc. All rights reserved. 15 Interfaces • com.sun.star.document.ImportFilter

    – XImporter > setTargetDocument – XFilter > filter > cancel – Win32 API and C runtime headers and import libraries • com.sun.star.document.ExportFilter – XExporter > SetSourceDocument – XFilter
  9. © Novell, Inc. All rights reserved. 16 Document representation •

    com::sun::star::xml::sax::XDocumentHandler – startDocument – endDocument – startElement – endElement – characters – ignorableWhitespace – processingInstruction – setDocumentLocator
  10. © Novell, Inc. All rights reserved. 17 File information •

    com::sun::star::document::MediaDescriptor – Represented by ::com::sun::star::beans::PropertyValue > Basically XML-ish structure with property names and their values – com::sun::star::io::XOutputStream OutputStream > A stream to receive the document data (for export filters) – com::sun::star::io::XInputStream InputStream > Content of document – string URL > URL of the document » Create the stream if it does not exist » Not necessary now because the XOutputStream or XinputStream are guaranteed
  11. © Novell, Inc. All rights reserved. 18 Type detection •

    com::sun::star::document::XExtendedFilterDetection – string detect( sequence< ::com::sun::star::beans::PropertyValue > Descriptor) – Returns > any valid type name (which specifies the detected format) or an empty value for unknown formats. > Adds the information into the Descriptor
  12. Unpublished Work of Novell, Inc. All Rights Reserved. This work

    is an unpublished work and contains confidential, proprietary, and trade secret information of Novell, Inc. Access to this work is restricted to Novell employees who have a need to know to perform tasks within the scope of their assignments. No part of this work may be practiced, performed, copied, distributed, revised, modified, translated, abridged, condensed, expanded, collected, or adapted without the prior written consent of Novell, Inc. Any use or exploitation of this work without authorization could subject the perpetrator to criminal and civil liability. General Disclaimer This document is not to be construed as a promise by any participating company to develop, deliver, or market a product. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. Novell, Inc. makes no representations or warranties with respect to the contents of this document, and specifically disclaims any express or implied warranties of merchantability or fitness for any particular purpose. The development, release, and timing of features or functionality described for Novell products remains at the sole discretion of Novell. Further, Novell, Inc. reserves the right to revise this document and to make changes to its content, at any time, without obligation to notify any person or entity of such revisions or changes. All Novell marks referenced in this presentation are trademarks or registered trademarks of Novell, Inc. in the United States and other countries. All third-party trademarks are the property of their respective owners.