Difference between revisions of "ODFDOM"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (The ODF Document / Convenient Functionality Layer)
m (OpenDocument API - ODFDOM)
Line 5: Line 5:
 
It is the succesor of [[AODL]] and [[Odf4j]], designed together with their architects to provide the ODF developer community an easy lightwork programming API, meant to be portable to any object-oriented language.
 
It is the succesor of [[AODL]] and [[Odf4j]], designed together with their architects to provide the ODF developer community an easy lightwork programming API, meant to be portable to any object-oriented language.
 
    
 
    
The first pre-version of the Java 5 reference implementation of ODFDOM is planned to be made public under LGPL3 in May 2008.
+
The first pre-version of the Java 5 reference implementation of ODFDOM is planned to become available under LGPL3 in May 2008.
  
 
=Overview=
 
=Overview=

Revision as of 21:11, 23 April 2008

OpenDocument API - ODFDOM

ODFDOM is the name of the upcoming free OpenDocument framework sponsered by Sun Microsystems Inc.

It is the succesor of AODL and Odf4j, designed together with their architects to provide the ODF developer community an easy lightwork programming API, meant to be portable to any object-oriented language.

The first pre-version of the Java 5 reference implementation of ODFDOM is planned to become available under LGPL3 in May 2008.

Overview

The ODFDOM project's objective is to provide an API for easily reading, writing and manipulating ODF documents. ODFDOM implements a layered approach through which documents are accessed.

  • The ODF Package / Physical Layer - provides direct access to the resources that are stored in the ODF package, such as XML streams, images or embedded objects.
  • The ODF Typed DOM / XML Layer - provides classes for all XML elements. XML attributes are mapped to class attributes. It is a typed DOM as every ODF XML element is represented by a different class, generated from the ODF RelaxNG schema. This level is concerned with the representation of the content of the standardized XML streams of the underlying package using the language independent W3C DOM API. This layer easily provides the ODF developer with all informations about the ODF XML structure.
  • The ODF Document / Convenient Layer - represents components consisting of multiple underlying XML elements. This level is concerned with usability aids, which are not specified by the ODF standard.
  • The Customized ODF Document / Extendable Layer - not part of the delivered API, but part of the design. This level is concerned with user defined customizations.

File:ODFDOM-Layered-Model.png

ODFDOM is part of the odftoolkit project. Development is discussed on the dev@odftoolkit.openoffice.org mailing list.

The ODFDOM Layers

The Package / Physical Layer

At this level, a document is represented as a package of named resources. All resources can be accessed as streams. Resources that are XML can additionally be accessed as DOM documents. For standardized file streams explicit methods are being provided.

File:ODF Package.jpg Note: All file streams aside of the /Pictures directory are specified by the ODF standard.

The main requirements for this layer are

  • Zip/unzip the file streams of the package
  • Enlist all file streams in the /META-INF/manifest.xml (otherwise OOo won't save the file streams)
  • Begin the package with an unzipped 'mimetype' file stream

All sources of the Package/Physical layer are organized beyond org.openoffice.odf.pkg.*

The following example illustrates how to add a graphic to the package level (not shown by OOo, as not referenced by content.xml):

import org.openoffice.odf.pkg.OdfPackage;
[...]

// loads the ODF document package from the path
OdfPackage pkg = OdfPackage.load("/home/myDocuments/myVacation.odt");


// loads the image from the URL and inserts the image in the package, adapting the manifest
pkg.insert("http://myweb.org/images/myHoliday.png", "/Pictures/myHoliday.png");

The ODF Typed DOM / XML Layer

At this level, only the by ODF standardized XML file streams of the document are accessible via the W3C DOM API.

For instance the XML of an ODF table

File:FruitTable code.jpg

Note: In the OpenDocument ISO standard the ODF elements are reused among all document types. The above XML for a table is equally usable in Text and Spreadsheet documents.


Would be mapped to a W3C derived ODF DOM class structure:

File:Table fruits diagramm.jpg

All sources of the typed DOM/XML layer are organized beyond org.openoffice.odf.dom.*

Its sources are all generated from the RelaxNG schema using the following naming conventions:

  • The Class name is equal to the element name using 'Odf' as an Prefix and 'Element' as Suffix.
  • Elements are stored beyond a sub-package equal to their Namespace used by the OOo.

For instance, the frame element 'draw:frame' would be generated as class org.openoffice.odf.dom.draw.OdfFrameElement

Note: Java dependent helper classes, which are not part of the official API, but for convenient part of the module are delivered beyond org.openoffice.odf.java.*

The following example illustrates how to add a graphic to the ODF document, that it is viewable:

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import org.openoffice.odf.doc.OdfDocument;
import org.openoffice.odf.dom.text.OdfParagraphElement;
import org.openoffice.odf.java.OdfNamespaceContext;
import org.w3c.dom.Document;
[...]

// loads the ODF document from the path
OdfDocument odfDoc = OdfDocument.load("/home/myDocuments/myVacation.odt");

// get the ODF content as DOM tree representation
Document odfContent = odfDocument.getContent();

// XPath initialization ''(JDK5 functionality)''
XPath xpath = XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(new OdfNamespaceContext());

// receiving the first Paragraph "//text:p[1]" ''(JDK5 functionality)''
OdfParagraphElement para = (OdfParagraphElement) xpath.evaluate("//text:p[1]", odfContent, XPathConstants.NODE);

// adding an image - expecting the user to know that 
// an image consists always of a 'draw:image' and a 'draw:frame' parent
para.createDrawFrame().createDrawImage("http://myweb.org/images/myHoliday.png", "/Pictures/myHoliday.png");

The ODF Document / Convenient Functionality Layer

The purpose of a class from the convenient layer is a higher usability for the API user. Usually a class is derived from covered XML layered class.

All sources of the ODF document / convenient functionality layer are organized beyond org.openoffice.odf.doc.* The name of a convenient class is similar as it's XML parent, only the suffix 'Element' has been neglected.

For instance, a convenient class for a frame, derived from the class representing 'draw:frame' would be named org.openoffice.odf.doc.draw.OdfFrame

In contrary to the classes of the XML layer, an object of the convenient layer controls multiple XML elements. For instance, a default table consisting of the similar amount of the earlier mentioned table can be created by a single method call, instead creating every single element using directly the XML layer.

Personal tools