org.apache.fop.fo

## Class FOTreeBuilder

- java.lang.Object
- - org.xml.sax.helpers.DefaultHandler
  - - org.apache.fop.fo.FOTreeBuilder

- All Implemented Interfaces:
    ContentHandler, DTDHandler, EntityResolver, ErrorHandler

      public class FOTreeBuilder
      extends DefaultHandler

  SAX Handler that passes parsed data to the various FO objects, where they can be used either to build an FO Tree, or used by Structure Renderers to build other data structures.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected ContentHandler` | `delegate` Current delegate ContentHandler to receive the SAX events
    `protected ElementMappingRegistry` | `elementMappingRegistry` The registry for ElementMapping instances
    `protected org.apache.fop.fo.FOTreeBuilder.MainFOHandler` | `mainFOHandler` Main DefaultHandler that handles the FO namespace.
    `protected Root` | `rootFObj` The root of the formatting object tree

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FOTreeBuilder(String outputFormat, FOUserAgent foUserAgent, OutputStream stream)` `FOTreeBuilder` constructor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `characters(char[] data, int start, int length)`
    `void` | `endDocument()`
    `void` | `endElement(String uri, String localName, String rawName)`
    `void` | `error(SAXParseException e)`
    `void` | `fatalError(SAXParseException e)`
    `protected Locator` | `getEffectiveLocator()`
    `FOEventHandler` | `getEventHandler()` Provides access to the underlying `FOEventHandler` object.
    `FormattingResults` | `getResults()` Returns the results of the rendering process.
    `void` | `setDocumentLocator(Locator locator)`
    `void` | `startDocument()`
    `void` | `startElement(String namespaceURI, String localName, String rawName, Attributes attlist)`
    `void` | `warning(SAXParseException e)`

    - ### Methods inherited from class org.xml.sax.helpers.DefaultHandler

      `endPrefixMapping, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, skippedEntity, startPrefixMapping, unparsedEntityDecl`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### elementMappingRegistry

          protected ElementMappingRegistry elementMappingRegistry

      The registry for ElementMapping instances

    - #### rootFObj

          protected Root rootFObj

      The root of the formatting object tree

    - #### mainFOHandler

          protected org.apache.fop.fo.FOTreeBuilder.MainFOHandler mainFOHandler

      Main DefaultHandler that handles the FO namespace.

    - #### delegate

          protected ContentHandler delegate

      Current delegate ContentHandler to receive the SAX events

  - ### Constructor Detail

    - #### FOTreeBuilder

          public FOTreeBuilder(String outputFormat,
                               FOUserAgent foUserAgent,
                               OutputStream stream)
                        throws FOPException

      `FOTreeBuilder` constructor
      Parameters:
        `outputFormat` - the MIME type of the output format to use (ex. "application/pdf").
        `foUserAgent` - the `FOUserAgent` in effect for this process
        `stream` - the `OutputStream` to direct the results to
      Throws:
        `FOPException` - if the `FOTreeBuilder` cannot be properly created

  - ### Method Detail

    - #### setDocumentLocator

          public void setDocumentLocator(Locator locator)

      Specified by:
        `setDocumentLocator` in interface `ContentHandler`
      Overrides:
        `setDocumentLocator` in class `DefaultHandler`

    - #### getEffectiveLocator

          protected Locator getEffectiveLocator()

      Returns:
        a `Locator` instance if it is available and not disabled

    - #### characters

          public void characters(char[] data,
                                 int start,
                                 int length)
                          throws SAXException

      Specified by:
        `characters` in interface `ContentHandler`
      Overrides:
        `characters` in class `DefaultHandler`
      Throws:
        `SAXException`

    - #### startDocument

          public void startDocument()
                             throws SAXException

      Specified by:
        `startDocument` in interface `ContentHandler`
      Overrides:
        `startDocument` in class `DefaultHandler`
      Throws:
        `SAXException`

    - #### endDocument

          public void endDocument()
                           throws SAXException

      Specified by:
        `endDocument` in interface `ContentHandler`
      Overrides:
        `endDocument` in class `DefaultHandler`
      Throws:
        `SAXException`

    - #### startElement

          public void startElement(String namespaceURI,
                                   String localName,
                                   String rawName,
                                   Attributes attlist)
                            throws SAXException

      Specified by:
        `startElement` in interface `ContentHandler`
      Overrides:
        `startElement` in class `DefaultHandler`
      Throws:
        `SAXException`

    - #### endElement

          public void endElement(String uri,
                                 String localName,
                                 String rawName)
                          throws SAXException

      Specified by:
        `endElement` in interface `ContentHandler`
      Overrides:
        `endElement` in class `DefaultHandler`
      Throws:
        `SAXException`

    - #### warning

          public void warning(SAXParseException e)

      Specified by:
        `warning` in interface `ErrorHandler`
      Overrides:
        `warning` in class `DefaultHandler`

    - #### error

          public void error(SAXParseException e)

      Specified by:
        `error` in interface `ErrorHandler`
      Overrides:
        `error` in class `DefaultHandler`

    - #### fatalError

          public void fatalError(SAXParseException e)
                          throws SAXException

      Specified by:
        `fatalError` in interface `ErrorHandler`
      Overrides:
        `fatalError` in class `DefaultHandler`
      Throws:
        `SAXException`

    - #### getEventHandler

          public FOEventHandler getEventHandler()

      Provides access to the underlying `FOEventHandler` object.
      Returns:
        the FOEventHandler object

    - #### getResults

          public FormattingResults getResults()

      Returns the results of the rendering process. Information includes the total number of pages generated and the number of pages per page-sequence.
      Returns:
        the results of the rendering process.

Copyright © 2025 Apache Software Foundation. All rights reserved.