Chapter 3. Phase 1: Building the FO tree

Table of Contents

1. Creating the FO nodes
2. Creating the property values

FOP's first task is building a suitable data structure from the XML input, which is an XML file with formatting objects or a result tree with formatting objects from an XSLT transformation. One could call this FOP's data binding. The data structure is an FO tree, i.e., a tree of FONode objects. The structure of the FO tree exactly parallels the structure of the XML file or the corresponding DOM tree, but instead of XML nodes its nodes are objects of type The FO tree is built on the basis of SAX parser events. The parser is responsible for parsing the XML document; it calls FOP's callbacks when SAX events occur.

FOP's callbacks are implemented by the FOTreeBuilder treebuilder object, which is a SAX content handler. It was constructed in the preparation phase, and registered with the parser as the content handler. It has meaningful implementations of the methods startDocument, endDocument, startElement, endElement, and characters.

treebuilder delegates its startDocument and endDocument methods to its FOTreeHandler object foInputHandler. FOTreeHandler is a subclas of FOInputHandler.

 treebuilder.foInputHandler = {
    runtime: instance of java.lang.Runtime(id=635)
    pageCount: 0
    initialMemory: 0
    startTime: 0
    foTreeListeners: instance of java.util.HashSet(id=636) instance of org.apache.fop.apps.Document(id=634)
    org.apache.avalon.framework.logger.AbstractLogEnabled.m_logger: instance of org.apache.avalon.framework.logger.ConsoleLogger(id=342)

The first important task of treebuilder is creating a suitable FO node for each element in the XML document. This is done in its startElement method. Its most important tool in this process is its fobjTable object. fobjTable is a map of maps. For each namespace supported by FOP it contains a map of local XML element name to a Node maker object fobjMaker, of type ElementMapping.Maker. In addition to the FO namespace it contains makers for FOP's extensions namespace, the SVG namespace and Batik's extensions namespace.

 treebuilder.fobjTable = "{{$SC@39e5b5,$Ta@117f31e,$EG@15a6029,$TC@5f6303,$TAC@5d9084,$TB@bad8a8,$Dec@e61fd1,$W@331059,$PS@766a24,$SPMR@32784a,$Foot@1774b9b,$MS@104c575,$BO@3fa5ac,$LMS@95cfbe,$F@179dce4,$LI@1950198,$BL@19bb25a,$MPS@da6bf4,$TR@1e58cb8,$RE@179935d,$B@b9e45a,$L@3ef810,$TB@100363,$LIB@14e8cee,$MP@67064,$RA@bcda2d,$MC@97d01f,$BC@e0a386,$T@feb48,$RM@11ff436,$CP@da3a1e,$Ch@11dba45,$SPM@b03be0,$PSM@2af081,$FB@113a53d,$M@c5495e,$TB@53fb57,$In@19a32e0,$TCell@8238f4,$LB@16925b0,$RS@297ffb,$TCaption@914f6a,$CPMR@1f4cbee,$LIL@787d6a,$MT@71dc3d,$IPS@1326484,$RPMA@16546ef,$RPMR@1428ea,$Fl@18a49e0,$PN@1f82982,$IFO@16d2633,$IC@e70e30,$R@154864a,$RBefore@3c9217,$RB@9b42e6,$PNC@14520eb

The values in this map are objects of subclasses of ElementMapping.Maker. ElementMapping.Maker is a static nested class of ElementMapping. It has no members and a single object method FONode make(FONode parent). The subclasses are static nested classes of FOElementMapping. Each subclass has its own implementation of the make method, and returns its own subclass of FONode. For example, FOElementMapping$R returns a object.

treebuilder delegates its endElement method to the node's end method, which allows FOP to take appropriate action at the end of each FO element. The only node type whose end method takes special action, is It hands control to FOP's next phase, building of the area tree.