// FOP
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.StructureHandler;
-import org.apache.fop.fo.pagination.Root;
-import org.apache.fop.fo.pagination.PageSequence;
-import org.apache.fop.extensions.ExtensionObj;
// Avalon
import org.apache.avalon.framework.logger.Logger;
// SAX
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.SAXException;
-import org.xml.sax.InputSource;
import org.xml.sax.Attributes;
// Java
-import java.util.HashMap;
-import java.util.ArrayList;
-import java.io.IOException;
+import java.util.*;
/**
* SAX Handler that builds the formatting object tree.
public class FOTreeBuilder extends DefaultHandler {
/**
- * table mapping element names to the makers of objects
- * representing formatting objects
+ * Table mapping element names to the makers of objects
+ * representing formatting objects.
*/
- protected HashMap fobjTable = new HashMap();
-
- protected ArrayList namespaces = new ArrayList();
+ protected Map fobjTable = new HashMap();
/**
- * current formatting object being handled
+ * Set of mapped namespaces.
*/
- protected FONode currentFObj = null;
+ protected Set namespaces = new HashSet();
/**
- * the root of the formatting object tree
+ * Current formatting object being handled
*/
- protected FObj rootFObj = null;
+ protected FONode currentFObj = null;
/**
- * set of names of formatting objects encountered but unknown
+ * The root of the formatting object tree
*/
- protected HashMap unknownFOs = new HashMap();
+ protected FONode rootFObj = null;
/**
- *
* The class that handles formatting and rendering to a stream
* (mark-fop@inomial.com)
*/
private StructureHandler structHandler;
+
private FOUserAgent userAgent;
public FOTreeBuilder() {}
return userAgent;
}
-
public void setStructHandler(StructureHandler sh) {
this.structHandler = sh;
}
/**
- * add a mapping from element name to maker.
+ * Adds a mapping from a namespace to a table of makers.
*
- * @param namespaceURI namespace URI of formatting object element
- * @param localName local name of formatting object element
- * @param maker Maker for class representing formatting object
+ * @param namespaceURI namespace URI of formatting object elements
+ * @param table table of makers
*/
public void addMapping(String namespaceURI, HashMap table) {
this.fobjTable.put(namespaceURI, table);
public void endElement(String uri, String localName, String rawName)
throws SAXException {
currentFObj.end();
-
currentFObj = currentFObj.getParent();
}
public void startDocument()
throws SAXException {
rootFObj = null; // allows FOTreeBuilder to be reused
- getLogger().debug("building formatting object tree");
+ if (getLogger().isDebugEnabled())
+ getLogger().debug("Building formatting object tree");
structHandler.startDocument();
}
+ /**
+ * SAX Handler for the end of the document
+ */
public void endDocument()
throws SAXException {
- getLogger().debug("Parsing of document complete");
+ if (getLogger().isDebugEnabled())
+ getLogger().debug("Parsing of document complete");
structHandler.endDocument();
}
/* the maker for the formatting object started */
ElementMapping.Maker fobjMaker = null;
- HashMap table = (HashMap)fobjTable.get(uri);
+ Map table = (Map)fobjTable.get(uri);
if(table != null) {
fobjMaker = (ElementMapping.Maker)table.get(localName);
// try default
}
}
- boolean foreignXML = false;
if (fobjMaker == null) {
- String fullName = uri + "^" + localName;
- if (!this.unknownFOs.containsKey(fullName)) {
- this.unknownFOs.put(fullName, "");
- getLogger().warn("Unknown formatting object "
- + fullName);
- }
+ if (getLogger().isWarnEnabled())
+ getLogger().warn("Unknown formatting object " + uri + "^" + localName);
if(namespaces.contains(uri.intern())) {
// fall back
fobjMaker = new Unknown.Maker();
} else {
fobjMaker = new UnknownXMLObj.Maker(uri);
- foreignXML = true;
}
}
+ " be fo:root, not "
+ fobj.getName()));
}
- rootFObj = (FObj)fobj;
+ rootFObj = fobj;
} else {
currentFObj.addChild(fobj);
}
public boolean hasData() {
return (rootFObj != null);
}
-
}