Slide 1

Slide 1 text

Writing Import filters for “beginners” Ha, ha, ha, I got you!!! Fridrich Štrba Software Engineer & TrainedMonkey™ LibreOffice Team Novell, Inc.

Slide 2

Slide 2 text

© 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)

Slide 3

Slide 3 text

Why import filters ?

Slide 4

Slide 4 text

© 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

Slide 5

Slide 5 text

© 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.

Slide 6

Slide 6 text

XSLT filters

Slide 7

Slide 7 text

© 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++

Slide 8

Slide 8 text

© Novell, Inc. All rights reserved. 8 New XSLT filter programming 1

Slide 9

Slide 9 text

© Novell, Inc. All rights reserved. 9 New XSLT filter programming 2

Slide 10

Slide 10 text

© Novell, Inc. All rights reserved. 10 New XSLT filter programming 3

Slide 11

Slide 11 text

© Novell, Inc. All rights reserved. 11 Filter description 0 writer_ODT_FlatXML com.sun.star.text.TextDocument 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 com.sun.star.comp.Writer.XmlFilterAdaptor OpenDocument Text (Flat XML) IMPORT EXPORT OWN 3RDPARTYFILTER

Slide 12

Slide 12 text

© Novell, Inc. All rights reserved. 12 Type description com.sun.star.comp.filters.XMLFilterDetect fodt odt xml false OpenDocument Text Flat XML OpenDocument Text (Flat XML) doctype:office:mimetype="application/vnd.oasis.opendocument.text"

Slide 13

Slide 13 text

XFilter framework

Slide 14

Slide 14 text

© Novell, Inc. All rights reserved. 14 XFilter framework (XImporter, XExporter)

Slide 15

Slide 15 text

© 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

Slide 16

Slide 16 text

© Novell, Inc. All rights reserved. 16 Document representation • com::sun::star::xml::sax::XDocumentHandler – startDocument – endDocument – startElement – endElement – characters – ignorableWhitespace – processingInstruction – setDocumentLocator

Slide 17

Slide 17 text

© 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

Slide 18

Slide 18 text

© 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

Slide 19

Slide 19 text

Q&A and Stoning session

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

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.