package org.apache.fop.apps;
-// Java
-import java.util.Map;
-import java.util.Set;
-import java.util.HashSet;
-
// FOP
import org.apache.fop.area.AreaTree;
import org.apache.fop.area.AreaTreeModel;
-
import org.apache.fop.fo.FOInputHandler;
import org.apache.fop.fonts.FontInfo;
-import org.apache.commons.logging.Log;
-
// SAX
import org.xml.sax.SAXException;
/** The AreaTreeModel for the PageSequence being rendered. */
public AreaTreeModel atModel;
- /**
- * The current set of id's in the FO tree.
- * This is used so we know if the FO tree contains duplicates.
- */
- private Set idReferences = new HashSet();
-
/**
* Structure handler used to notify structure
* events such as start end element.
return areaTree;
}
- /**
- * Retuns the set of ID references.
- * @return the ID references
- */
- public Set getIDReferences() {
- return idReferences;
- }
-
/**
* @return the FOInputHandler for parsing this FO Tree
*/
package org.apache.fop.fo;
+// Java
+import java.util.HashSet;
+import java.util.Set;
+
// FOP
import org.apache.fop.apps.Document;
import org.apache.fop.apps.Driver;
*/
protected Log logger = null;
+ /**
+ * The current set of id's in the FO tree.
+ * This is used so we know if the FO tree contains duplicates.
+ */
+ private Set idReferences = new HashSet();
+
/**
* Main constructor
* @param document the apps.Document implementation that is controlling
doc = document;
}
+ /**
+ * Retuns the set of ID references.
+ * @return the ID references
+ */
+ public Set getIDReferences() {
+ return idReferences;
+ }
+
/**
* Sets the Commons-Logging instance for this class
* @param logger The Commons-Logging instance
import org.apache.commons.logging.Log;
// FOP
-import org.apache.fop.apps.Document;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.util.CharUtilities;
* @return FOUserAgent
*/
public FOUserAgent getUserAgent() {
- return getDocument().getDriver().getUserAgent();
+ return getFOInputHandler().getDriver().getUserAgent();
}
/**
* @return the logger
*/
public Log getLogger() {
- return getDocument().getDriver().getLogger();
+ return getFOInputHandler().getDriver().getLogger();
}
/**
* @param localName (e.g. "table" for "fo:table")
* @throws IllegalArgumentException if incoming node not valid for parent
*/
- protected void validateChildNode(String namespaceURI, String localName) {}
+ protected void validateChildNode(Locator loc, String namespaceURI, String localName) {}
/**
* Adds characters (does nothing here)
}
/**
- * Recursively goes up the FOTree hierarchy until the FONode is found,
- * which returns the parent Document.
- * @return the Document object that is the parent of this node.
+ * Recursively goes up the FOTree hierarchy until the fo:root is found,
+ * which returns the parent FOInputHandler.
+ * @return the FOInputHandler object that is the parent of the FO Tree
*/
- public Document getDocument() {
- return parent.getDocument();
+ public FOInputHandler getFOInputHandler() {
+ return parent.getFOInputHandler();
}
/**
* (e.g., two fo:declarations within fo:root)
* @param offendingNode incoming node that would cause a duplication.
*/
- protected void tooManyNodesError(String offendingNode) {
+ protected void tooManyNodesError(Locator loc, String offendingNode) {
throw new IllegalArgumentException(
- "Error: for " + getName() + ", only one "
+ errorText(loc) + getName() + ", only one "
+ offendingNode + " may be declared.");
}
* @param tooLateNode string name of node that should be earlier in document
* @param tooEarlyNode string name of node that should be later in document
*/
- protected void nodesOutOfOrderError(String tooLateNode, String tooEarlyNode) {
+ protected void nodesOutOfOrderError(Locator loc, String tooLateNode,
+ String tooEarlyNode) {
throw new IllegalArgumentException(
- "Error: for " + getName() + ", " + tooLateNode
+ errorText(loc) + getName() + ", " + tooLateNode
+ " must be declared before " + tooEarlyNode + ".");
}
* @param nsURI namespace URI of incoming invalid node
* @param lName local name (i.e., no prefix) of incoming node
*/
- protected void invalidChildError(String nsURI, String lName) {
+ protected void invalidChildError(Locator loc, String nsURI, String lName) {
throw new IllegalArgumentException(
- "Error: " + getNodeString(nsURI, lName) +
+ errorText(loc) + getNodeString(nsURI, lName) +
" is not valid child element of " + getName() + ".");
}
+ /**
+ * Helper function to return "Error (line#/column#)" string for
+ * above exception messages
+ * @param loc org.xml.sax.Locator object
+ */
+ protected static String errorText(Locator loc) {
+ return "Error(" + loc.getLineNumber() + "/" + loc.getColumnNumber() + "): ";
+ }
}
}
} else { // check that incoming node is valid for currentFObj
try {
- currentFObj.validateChildNode(namespaceURI, localName);
+ currentFObj.validateChildNode(locator, namespaceURI, localName);
} catch (IllegalArgumentException e) {
throw new SAXException(e);
}
if (rootFObj == null) {
rootFObj = (Root) foNode;
- rootFObj.setDocument(document);
+ rootFObj.setFOInputHandler(document.getFOInputHandler());
} else {
currentFObj.addChild(foNode);
}
if (prop != null) {
String str = prop.getString();
if (str != null && !str.equals("")) {
- Set idrefs = getDocument().getIDReferences();
+ Set idrefs = getFOInputHandler().getIDReferences();
if (!idrefs.contains(str)) {
id = str;
idrefs.add(id);
if (textInfo == null) {
// Really only need one of these, but need to get fontInfo
// stored in propMgr for later use.
- propMgr.setFontInfo(getDocument());
- textInfo = propMgr.getTextLayoutProps(getDocument());
+ propMgr.setFontInfo(getFOInputHandler().getDocument());
+ textInfo = propMgr.getTextLayoutProps(getFOInputHandler().getDocument());
}
FOText ft = new FOText(data, start, length, textInfo, this);
ft.setName("text");
/* characters() processing empty for FOTreeHandler, not empty for RTF & MIFHandlers */
- getDocument().getFOInputHandler().characters(ft.ca, ft.startIndex, ft.endIndex);
+ getFOInputHandler().characters(ft.ca, ft.startIndex, ft.endIndex);
addChild(ft);
}
*/
protected void addProperties(Attributes attlist) throws FOPException {
super.addProperties(attlist);
- getDocument().getFOInputHandler().startLink(this);
+ getFOInputHandler().startLink(this);
}
public void setup() {
*/
public void end() {
super.end();
-
- getDocument().getFOInputHandler().endLink();
+ getFOInputHandler().endLink();
}
public String getName() {
setupID();
- getDocument().getFOInputHandler().startBlock(this);
+ getFOInputHandler().startBlock(this);
}
private void setup() {
*/
public void end() {
handleWhiteSpace();
- getDocument().getFOInputHandler().endBlock(this);
+ getFOInputHandler().endBlock(this);
}
private void handleWhiteSpace() {
*/
protected void addProperties(Attributes attlist) throws FOPException {
super.addProperties(attlist);
- getDocument().getFOInputHandler().image(this);
+ getFOInputHandler().image(this);
}
/**
*/
protected void addProperties(Attributes attlist) throws FOPException {
super.addProperties(attlist);
- getDocument().getFOInputHandler().startFootnote(this);
+ getFOInputHandler().startFootnote(this);
}
/**
protected void end() {
super.end();
- getDocument().getFOInputHandler().endFootnote(this);
+ getFOInputHandler().endFootnote(this);
}
public String getName() {
*/
protected void addProperties(Attributes attlist) throws FOPException {
super.addProperties(attlist);
- getDocument().getFOInputHandler().startFootnoteBody(this);
+ getFOInputHandler().startFootnoteBody(this);
}
public void acceptVisitor(FOTreeVisitor fotv) {
protected void end() {
super.end();
-
- getDocument().getFOInputHandler().endFootnoteBody(this);
+ getFOInputHandler().endFootnoteBody(this);
}
public String getName() {
this.lineThrough = true;
}
- getDocument().getFOInputHandler().startInline(this);
+ getFOInputHandler().startInline(this);
}
/**
* @see org.apache.fop.fo.FONode#end
*/
public void end() {
- getDocument().getFOInputHandler().endInline(this);
+ getFOInputHandler().endInline(this);
}
public String getName() {
CommonBackground bProps = propMgr.getBackgroundProps();
// Common Font Properties
- this.fontState = propMgr.getFontState(getDocument());
+ this.fontState = propMgr.getFontState(getFOInputHandler().getDocument());
// Common Margin Properties-Inline
CommonMarginInline mProps = propMgr.getMarginInlineProps();
*/
protected void addProperties(Attributes attlist) throws FOPException {
super.addProperties(attlist);
- getDocument().getFOInputHandler().startList(this);
+ getFOInputHandler().startList(this);
}
private void setup() throws FOPException {
protected void end() {
super.end();
-
- getDocument().getFOInputHandler().endList(this);
+ getFOInputHandler().endList(this);
}
public String getName() {
*/
protected void addProperties(Attributes attlist) throws FOPException {
super.addProperties(attlist);
- getDocument().getFOInputHandler().startListItem(this);
+ getFOInputHandler().startListItem(this);
}
private void setup() {
protected void end() {
super.end();
- getDocument().getFOInputHandler().endListItem(this);
+ getFOInputHandler().endListItem(this);
}
public String getName() {
*/
protected void addProperties(Attributes attlist) throws FOPException {
super.addProperties(attlist);
- getDocument().getFOInputHandler().startListLabel();
+ getFOInputHandler().startListLabel();
}
private void setup() {
protected void end() {
super.end();
-
- getDocument().getFOInputHandler().endListLabel();
+ getFOInputHandler().endListLabel();
}
public String getName() {
protected void addProperties(Attributes attlist) throws FOPException {
super.addProperties(attlist);
setup();
- getDocument().getFOInputHandler().startPageNumber(this);
+ getFOInputHandler().startPageNumber(this);
}
public void setup() {
CommonBackground bProps = propMgr.getBackgroundProps();
// Common Font Properties
- this.fontState = propMgr.getFontState(getDocument());
+ this.fontState = propMgr.getFontState(getFOInputHandler().getDocument());
// Common Margin Properties-Inline
CommonMarginInline mProps = propMgr.getMarginInlineProps();
}
protected void end() {
- getDocument().getFOInputHandler().endPageNumber(this);
+ getFOInputHandler().endPageNumber(this);
}
public String getName() {
CommonBackground bProps = propMgr.getBackgroundProps();
// Common Font Properties
- this.fontState = propMgr.getFontState(getDocument());
+ this.fontState = propMgr.getFontState(getFOInputHandler().getDocument());
// Common Margin Properties-Inline
CommonMarginInline mProps = propMgr.getMarginInlineProps();
protected void addProperties(Attributes attlist) throws FOPException {
super.addProperties(attlist);
setupID();
- getDocument().getFOInputHandler().startTable(this);
+ getFOInputHandler().startTable(this);
}
/**
}
protected void end() {
- getDocument().getFOInputHandler().endTable(this);
+ getFOInputHandler().endTable(this);
}
public String getName() {
protected void addProperties(Attributes attlist) throws FOPException {
super.addProperties(attlist);
setupID();
- getDocument().getFOInputHandler().startBody(this);
+ getFOInputHandler().startBody(this);
}
private void setup() throws FOPException {
}
protected void end() {
- getDocument().getFOInputHandler().endBody(this);
+ getFOInputHandler().endBody(this);
}
public String getName() {
protected void addProperties(Attributes attlist) throws FOPException {
super.addProperties(attlist);
doSetup(); // init some basic property values
- getDocument().getFOInputHandler().startCell(this);
+ getFOInputHandler().startCell(this);
}
/**
}
protected void end() {
- getDocument().getFOInputHandler().endCell(this);
+ getFOInputHandler().endCell(this);
}
public String getName() {
protected void addProperties(Attributes attlist) throws FOPException {
super.addProperties(attlist);
initialize(); // init some basic property values
- getDocument().getFOInputHandler().startColumn(this);
+ getFOInputHandler().startColumn(this);
}
/**
}
protected void end() {
- getDocument().getFOInputHandler().endColumn(this);
+ getFOInputHandler().endColumn(this);
}
public String getName() {
protected void addProperties(Attributes attlist) throws FOPException {
super.addProperties(attlist);
setupID();
- getDocument().getFOInputHandler().startRow(this);
+ getFOInputHandler().startRow(this);
}
/**
}
protected void end() {
- getDocument().getFOInputHandler().endRow(this);
+ getFOInputHandler().endRow(this);
}
public String getName() {
import java.net.URL;
import java.io.IOException;
import java.io.InputStream;
+import org.xml.sax.Locator;
// FOP
import org.apache.fop.datatypes.ColorType;
super(parent);
}
+ /**
+ * @see org.apache.fop.fo.FONode#validateChildNode(String, String)
+ XSL 1.0/FOP: EMPTY (no child nodes permitted)
+ */
+ protected void validateChildNode(Locator loc, String nsURI, String localName) {
+ invalidChildError(loc, nsURI, localName);
+ }
+
/**
* Special processing for the end of parsing an ColorProfile object.
* Extract instance variables from the collection of properties for this
import org.apache.fop.fo.FObj;
import org.apache.fop.fo.FOTreeVisitor;
import org.apache.fop.fo.XMLObj;
+import org.xml.sax.Locator;
/**
/**
* @see org.apache.fop.fo.FONode#validateChildNode(String, String)
XSL 1.0: (color-profile)+ (and non-XSL NS nodes)
- FOP (currently): (color-profile)* (and non-XSL NS nodes)
+ FOP/XSL 1.1: (color-profile)* (and non-XSL NS nodes)
*/
- protected void validateChildNode(String nsURI, String localName) {
+ protected void validateChildNode(Locator loc, String nsURI, String localName) {
if (nsURI == FOElementMapping.URI) {
if (!localName.equals("color-profile")) {
- invalidChildError(nsURI, localName);
+ invalidChildError(loc, nsURI, localName);
}
} // anything outside of XSL namespace is OK.
}
// Now done in addChild of page-sequence
//pageSequence.addFlow(this);
- getDocument().getFOInputHandler().startFlow(this);
+ getFOInputHandler().startFlow(this);
}
/**
* Tell the StructureRenderer that we are at the end of the flow.
*/
public void end() {
- getDocument().getFOInputHandler().endFlow(this);
+ getFOInputHandler().endFlow(this);
}
/**
*/
private void startStructuredPageSequence() {
if (!sequenceStarted) {
- getDocument().getFOInputHandler().startPageSequence(this);
+ getFOInputHandler().startPageSequence(this);
sequenceStarted = true;
}
}
*/
public void end() {
try {
- this.getDocument().getFOInputHandler().endPageSequence(this);
+ getFOInputHandler().endPageSequence(this);
} catch (FOPException fopex) {
getLogger().error("Error in PageSequence.end(): "
+ fopex.getMessage(), fopex);
import java.util.List;
// FOP
-import org.apache.fop.apps.Document;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObj;
import org.apache.fop.fo.FOElementMapping;
import org.apache.fop.fo.extensions.ExtensionElementMapping;
import org.apache.fop.fo.extensions.Bookmarks;
+import org.apache.fop.fo.FOInputHandler;
import org.apache.fop.fo.FOTreeVisitor;
+import org.xml.sax.Locator;
/**
* The fo:root formatting object. Contains page masters, page-sequences.
*/
private int runningPageNumberCounter = 0;
- private Document document = null;
+ /**
+ * Controlling FOTreeHandler object for this FO Tree
+ */
+ private FOInputHandler foInputHandler = null;
/**
* @see org.apache.fop.fo.FONode#FONode(FONode)
XSL 1.0 Spec: (layout-master-set,declarations?,page-sequence+)
FOP: (layout-master-set, declarations?, fox:bookmarks?, page-sequence+)
*/
- protected void validateChildNode(String nsURI, String localName) {
+ protected void validateChildNode(Locator loc, String nsURI, String localName) {
if (nsURI == FOElementMapping.URI) {
if (localName.equals("layout-master-set")) {
if (layoutMasterSet != null) {
- tooManyNodesError("fo:layout-master-set");
+ tooManyNodesError(loc, "fo:layout-master-set");
}
} else if (localName.equals("declarations")) {
if (layoutMasterSet == null) {
- nodesOutOfOrderError("fo:layout-master-set", "fo:declarations");
+ nodesOutOfOrderError(loc, "fo:layout-master-set", "fo:declarations");
} else if (declarations != null) {
- tooManyNodesError("fo:declarations");
+ tooManyNodesError(loc, "fo:declarations");
} else if (bookmarks != null) {
- nodesOutOfOrderError("fo:declarations", "fox:bookmarks");
+ nodesOutOfOrderError(loc, "fo:declarations", "fox:bookmarks");
} else if (pageSequenceFound) {
- nodesOutOfOrderError("fo:declarations", "fo:page-sequence");
+ nodesOutOfOrderError(loc, "fo:declarations", "fo:page-sequence");
}
} else if (localName.equals("page-sequence")) {
if (layoutMasterSet == null) {
- nodesOutOfOrderError("fo:layout-master-set", "fo:page-sequence");
+ nodesOutOfOrderError(loc, "fo:layout-master-set", "fo:page-sequence");
} else {
pageSequenceFound = true;
}
} else {
- invalidChildError(nsURI, localName);
+ invalidChildError(loc, nsURI, localName);
}
} else if (nsURI.equals(ExtensionElementMapping.URI)) {
if (!localName.equals("bookmarks")) {
- invalidChildError(nsURI, localName);
+ invalidChildError(loc, nsURI, localName);
} else if (layoutMasterSet == null) {
- nodesOutOfOrderError("fo:layout-master-set", "fox:bookmarks");
+ nodesOutOfOrderError(loc, "fo:layout-master-set", "fox:bookmarks");
} else if (bookmarks != null) {
- tooManyNodesError("fox:bookmarks");
+ tooManyNodesError(loc, "fox:bookmarks");
} else if (pageSequenceFound) {
- nodesOutOfOrderError("fox:bookmarks", "fo:page-sequence");
+ nodesOutOfOrderError(loc, "fox:bookmarks", "fo:page-sequence");
}
} else {
- invalidChildError(nsURI, localName);
+ invalidChildError(loc, nsURI, localName);
}
}
* @param document the apps.Document implementation to which this Root
* is attached
*/
- public void setDocument(Document document) {
- this.document = document;
+ public void setFOInputHandler(FOInputHandler foInputHandler) {
+ this.foInputHandler = foInputHandler;
}
/**
* This method overrides the FONode version. The FONode version calls the
* method by the same name for the parent object. Since Root is at the top
- * of the tree, it returns the actual apps.Document object. Thus, any FONode
- * can use this chain to find which apps.Document it is being built for.
- * @return the Document implementation that this Root is attached to
+ * of the tree, it returns the actual FOInputHandler object. Thus, any FONode
+ * can use this chain to find which FOInputHandler it is being built for.
+ * @return the FOInputHandler implementation that this Root is attached to
*/
- public Document getDocument() {
- return document;
+ public FOInputHandler getFOInputHandler() {
+ return foInputHandler;
}
/**
CommonBackground bProps = propMgr.getBackgroundProps();
// Common Font Properties
- Font fontState = propMgr.getFontState(getDocument());
+ Font fontState = propMgr.getFontState(getFOInputHandler().getDocument());
// Common Margin Properties-Inline
CommonMarginInline mProps = propMgr.getMarginInlineProps();
childLMiter = new BlockLMiter(this, childLMiter);
userAgent = inBlock.getUserAgent();
setBlockTextInfo(inBlock.getPropertyManager().getTextLayoutProps(
- inBlock.getDocument()));
+ inBlock.getFOInputHandler().getDocument()));
}
private void setBlockTextInfo(TextInfo ti) {