*/
public abstract class FONode {
+ protected static String FO_URI = FOElementMapping.URI;
+
/** Parent FO node */
protected FONode parent;
*/
protected void invalidChildError(Locator loc, String nsURI, String lName)
throws SAXParseException {
- throw new SAXParseException (errorText(loc) + getNodeString(nsURI, lName) +
- " is not a valid child element of " + getName() + ".", loc);
+ invalidChildError(loc, nsURI, lName, null);
}
+ /**
+ * Helper function to return "invalid child" exceptions with more
+ * complex validation rules (i.e., needing more explanation of the problem)
+ * @param loc org.xml.sax.Locator object of the error (*not* parent node)
+ * @param nsURI namespace URI of incoming invalid node
+ * @param lName local name (i.e., no prefix) of incoming node
+ * @param ruleViolated text explanation of problem
+ */
+ protected void invalidChildError(Locator loc, String nsURI, String lName,
+ String ruleViolated)
+ throws SAXParseException {
+ throw new SAXParseException (errorText(loc) + getNodeString(nsURI, lName) +
+ " is not a valid child element of " + getName()
+ + ((ruleViolated != null) ? ": " + ruleViolated : "."), loc);
+ }
+
/**
* Helper function to return missing child element errors
* (e.g., fo:layout-master-set not having any page-master child element)
import org.xml.sax.SAXParseException;
// FOP
-import org.apache.fop.area.inline.InlineArea;
-import org.apache.fop.area.inline.InlineParent;
-import org.apache.fop.area.LinkResolver;
-import org.apache.fop.area.PageViewport;
-import org.apache.fop.area.Trait;
-import org.apache.fop.fo.FOElementMapping;
import org.apache.fop.fo.FONode;
-import org.apache.fop.layoutmgr.LayoutManager;
-import org.apache.fop.layoutmgr.LMiter;
-import org.apache.fop.layoutmgr.InlineStackingLayoutManager;
-import org.apache.fop.fo.properties.CommonAccessibility;
-import org.apache.fop.fo.properties.CommonAural;
-import org.apache.fop.fo.properties.CommonBorderAndPadding;
-import org.apache.fop.fo.properties.CommonBackground;
-import org.apache.fop.fo.properties.CommonMarginInline;
-import org.apache.fop.fo.properties.CommonRelativePosition;
+import org.apache.fop.layoutmgr.BasicLinkLayoutManager;
/**
- * The basic link.
- * This sets the basic link trait on the inline parent areas
- * that are created by the fo element.
+ * The fo:basic-link formatting object.
+ *
+ * This class contains the logic to determine the link represented by this FO,
+ * and whether that link is external (uses a URI) or internal (an id
+ * reference).
*/
public class BasicLink extends Inline {
+
+ // link represented by this FO
private String link = null;
- private boolean external = false;
+
+ // indicator of whether link is internal or external
+ private boolean isExternalLink = false;
- // used for FO validation
+ // used only for FO validation
private boolean blockOrInlineItemFound = false;
/**
*/
protected void addProperties(Attributes attlist) throws SAXParseException {
super.addProperties(attlist);
-
setupID();
+
+ // This logic is for determining the link represented by this FO.
String ext = propertyList.get(PR_EXTERNAL_DESTINATION).getString();
String internal = propertyList.get(PR_INTERNAL_DESTINATION).getString();
- // per spec, internal takes precedence if both specified
- if (internal.length() > 0) {
+ // per spec, internal takes precedence if both specified
+ if (internal.length() > 0) {
link = internal;
} else if (ext.length() > 0) {
link = ext;
- external = true;
+ isExternalLink = true;
} else {
// slightly stronger than spec "should be specified"
attributeError("Missing attribute: Either external-destination or " +
*/
protected void validateChildNode(Locator loc, String nsURI, String localName)
throws SAXParseException {
- if (nsURI == FOElementMapping.URI && localName.equals("marker")) {
+ if (nsURI == FO_URI && localName.equals("marker")) {
if (blockOrInlineItemFound) {
nodesOutOfOrderError(loc, "fo:marker", "(#PCDATA|%inline;|%block;)");
}
getFOInputHandler().endLink();
}
- /**
- * @return true (BasicLink can contain Markers)
- */
- protected boolean containsMarkers() {
- return true;
- }
-
/**
* @see org.apache.fop.fo.FObj#addLayoutManager(List)
- * @todo create a subclass for InlineStackingLayoutManager, moving the formatting
- * logic to the layoutmgr package
- */
+ */
public void addLayoutManager(List list) {
- InlineStackingLayoutManager lm;
- lm = new InlineStackingLayoutManager(this) {
- protected InlineParent createArea() {
- InlineParent area = super.createArea();
- setupBasicLinkArea(parentLM, area);
- return area;
- }
- };
- lm.setLMiter(new LMiter(lm, getChildNodes()));
+ BasicLinkLayoutManager lm = new BasicLinkLayoutManager(this);
list.add(lm);
}
-
- protected void setupBasicLinkArea(LayoutManager parentLM,
- InlineParent area) {
- if (link == null) {
- return;
- }
- if (external) {
- area.addTrait(Trait.EXTERNAL_LINK, link);
- } else {
- PageViewport page = parentLM.resolveRefID(link);
- if (page != null) {
- area.addTrait(Trait.INTERNAL_LINK, page.getKey());
- } else {
- LinkResolver res = new LinkResolver(link, area);
- parentLM.addUnresolvedArea(link, res);
- }
- }
- }
-
+
+ /**
+ * @return link represented by this fo:basic-link
+ */
+ public String getLink() {
+ return link;
+ }
+
+ /**
+ * @return true if link is external, false if internal
+ */
+ public boolean isExternalLink() {
+ return isExternalLink;
+ }
+
+ /**
+ * @see org.apache.fop.fo.FObj#getName()
+ */
public String getName() {
return "fo:basic-link";
}
+
+ /**
+ * @return true (BasicLink can contain Markers)
+ * @todo see if can remove in favor of a BitSet for all FO's
+ */
+ protected boolean containsMarkers() {
+ return true;
+ }
}
import org.xml.sax.SAXParseException;
// FOP
-import org.apache.fop.fo.FOElementMapping;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObjMixed;
import org.apache.fop.layoutmgr.BidiLayoutManager;
import org.apache.fop.layoutmgr.InlineStackingLayoutManager;
import org.apache.fop.layoutmgr.LayoutManager;
-import org.apache.fop.fo.properties.CommonAural;
-import org.apache.fop.fo.properties.CommonRelativePosition;
-
/**
* fo:bidi-override element.
/**
* @see org.apache.fop.fo.FObj#addProperties
+ * @todo see if can use a BitSet to determine if an FO should
+ * have its ID setup; then move setupID() instances to FObj.
*/
protected void addProperties(Attributes attlist) throws SAXParseException {
super.addProperties(attlist);
*/
protected void validateChildNode(Locator loc, String nsURI, String localName)
throws SAXParseException {
- if (nsURI == FOElementMapping.URI && localName.equals("marker")) {
+ if (nsURI == FO_URI && localName.equals("marker")) {
if (blockOrInlineItemFound) {
nodesOutOfOrderError(loc, "fo:marker",
"(#PCDATA|%inline;|%block;)");
} else if (!isBlockOrInlineItem(nsURI, localName)) {
invalidChildError(loc, nsURI, localName);
} else if (!canHaveBlockLevelChildren && isBlockItem(nsURI, localName)) {
- invalidChildError(loc, nsURI, localName);
+ String ruleViolated = "An fo:bidi-override" +
+ " that is a descendant of an fo:leader or of the fo:inline child" +
+ " of an fo:footnote may not have block-level children, unless it" +
+ " has a nearer ancestor that is an fo:inline-container.";
+ invalidChildError(loc, nsURI, localName, ruleViolated);
} else {
blockOrInlineItemFound = true;
}
}
- public String getName() {
- return "fo:bidi-override";
- }
-
- /**
- * @return true (BidiOverride can contain Markers)
- */
- protected boolean containsMarkers() {
- return true;
- }
-
/**
* @see org.apache.fop.fo.FObj#addLayoutManager(List)
+ * @todo see if can/should move the child iteration logic
+ * to BidiLayoutManager
*/
public void addLayoutManager(List list) {
if (false) {
for (int count = childList.size() - 1; count >= 0; count--) {
LayoutManager lm = (LayoutManager) childList.get(count);
if (lm.generatesInlineAreas()) {
- LayoutManager blm = new BidiLayoutManager((InlineStackingLayoutManager) lm);
- blm.setFObj(this);
+ LayoutManager blm = new BidiLayoutManager(this,
+ (InlineStackingLayoutManager) lm);
list.add(blm);
} else {
list.add(lm);
}
}
-
+ /**
+ * @see org.apache.fop.fo.FObj#getName()
+ */
+ public String getName() {
+ return "fo:bidi-override";
+ }
+
+ /**
+ * @return true (BidiOverride can contain Markers)
+ */
+ protected boolean containsMarkers() {
+ return true;
+ }
}
getFOInputHandler().startBlock(this);
}
- /**
- * @return true (Block can contain Markers)
- */
- protected boolean containsMarkers() {
- return true;
- }
-
/**
* @return span for this Block, in millipoints (??)
*/
list.add(blm);
}
- public String getName() {
+ public String getName() {
return "fo:block";
}
+ /**
+ * @return true (Block can contain Markers)
+ */
+ protected boolean containsMarkers() {
+ return true;
+ }
}
// FOP
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.LMVisited;
-import org.apache.fop.fo.FOElementMapping;
import org.apache.fop.layoutmgr.AddLMVisitor;
import org.apache.fop.fo.FObj;
*/
protected void validateChildNode(Locator loc, String nsURI, String localName)
throws SAXParseException {
- if (nsURI == FOElementMapping.URI) {
+ if (nsURI == FO_URI) {
invalidChildError(loc, nsURI, localName);
} else if (hasNonXSLNamespaceElement) {
tooManyNodesError(loc, "child element");
package org.apache.fop.fo.flow;
+// Java
+import java.util.List;
+
// XML
import org.xml.sax.Attributes;
import org.xml.sax.SAXParseException;
// FOP
-import org.apache.fop.apps.FOPException;
import org.apache.fop.fo.FONode;
-import org.apache.fop.layoutmgr.AddLMVisitor;
import org.apache.fop.fo.FObj;
-import org.apache.fop.fo.properties.CommonAccessibility;
-import org.apache.fop.fo.properties.CommonAural;
-import org.apache.fop.fo.properties.CommonBackground;
-import org.apache.fop.fo.properties.CommonBorderAndPadding;
-import org.apache.fop.fo.properties.CommonMarginBlock;
-import org.apache.fop.fo.properties.CommonRelativePosition;
-import org.apache.fop.fo.LMVisited;
+import org.apache.fop.layoutmgr.list.ListItemLayoutManager;
/**
* Class modelling the fo:list-item object. See Sec. 6.8.3 of the XSL-FO
* Standard.
*/
-public class ListItem extends FObj implements LMVisited {
+public class ListItem extends FObj {
private ListItemLabel label = null;
private ListItemBody body = null;
}
private void setup() {
-
- // Common Accessibility Properties
- CommonAccessibility mAccProps = propMgr.getAccessibilityProps();
-
- // Common Aural Properties
- CommonAural mAurProps = propMgr.getAuralProps();
-
- // Common Border, Padding, and Background Properties
- CommonBorderAndPadding bap = propMgr.getBorderAndPadding();
- CommonBackground bProps = propMgr.getBackgroundProps();
-
- // Common Margin Properties-Block
- CommonMarginBlock mProps = propMgr.getMarginProps();
-
- // Common Relative Position Properties
- CommonRelativePosition mRelProps = propMgr.getRelativePositionProps();
-
- // this.propertyList.get("break-after");
- // this.propertyList.get("break-before");
setupID();
- // this.propertyList.get("keep-together");
- // this.propertyList.get("keep-with-next");
- // this.propertyList.get("keep-with-previous");
- // this.propertyList.get("relative-align");
-
this.align = this.propertyList.get(PR_TEXT_ALIGN).getEnum();
this.alignLast = this.propertyList.get(PR_TEXT_ALIGN_LAST).getEnum();
this.lineHeight =
this.propertyList.get(PR_SPACE_BEFORE | CP_OPTIMUM).getLength().getValue();
this.spaceAfter =
this.propertyList.get(PR_SPACE_AFTER | CP_OPTIMUM).getLength().getValue();
-
}
/**
return true;
}
+ /**
+ * @see org.apache.fop.fo.FObj#addLayoutManager(List)
+ * @todo remove checks for non-nulls after validateChildNode() added
+ */
+ public void addLayoutManager(List list) {
+ if (label != null && body != null) {
+ ListItemLayoutManager blm = new ListItemLayoutManager(this);
+ list.add(blm);
+ } else {
+ getLogger().error("list-item requires list-item-label and list-item-body");
+ }
+ }
+
public ListItemLabel getLabel() {
return label;
}
return body;
}
- public void acceptVisitor(AddLMVisitor aLMV) {
- aLMV.serveListItem(this);
- }
-
protected void endOfNode() throws SAXParseException {
super.endOfNode();
getFOInputHandler().endListItem(this);
import org.xml.sax.SAXParseException;
// FOP
-import org.apache.fop.fo.FOElementMapping;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObj;
import org.apache.fop.fo.XMLObj;
*/
protected void validateChildNode(Locator loc, String nsURI, String localName)
throws SAXParseException {
- if (nsURI == FOElementMapping.URI) {
+ if (nsURI == FO_URI) {
if (!localName.equals("color-profile")) {
invalidChildError(loc, nsURI, localName);
}
// FOP
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObj;
-import org.apache.fop.fo.FOElementMapping;
import org.apache.fop.layoutmgr.FlowLayoutManager;
/**
*/
protected void validateChildNode(Locator loc, String nsURI, String localName)
throws SAXParseException {
- if (nsURI == FOElementMapping.URI && localName.equals("marker")) {
+ if (nsURI == FO_URI && localName.equals("marker")) {
if (blockItemFound) {
nodesOutOfOrderError(loc, "fo:marker", "(%block;)");
}
// FOP
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObj;
-import org.apache.fop.fo.FOElementMapping;
import org.apache.fop.apps.FOPException;
/**
*/
protected void validateChildNode(Locator loc, String nsURI, String localName)
throws SAXParseException {
- if (nsURI == FOElementMapping.URI) {
+ if (nsURI == FO_URI) {
if (!localName.equals("simple-page-master")
&& !localName.equals("page-sequence-master")) {
invalidChildError(loc, nsURI, localName);
import org.apache.fop.apps.FOPException;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObj;
-import org.apache.fop.fo.FOElementMapping;
-import org.apache.fop.apps.FOPException;
/**
* This provides pagination of flows onto pages. Much of the
*/
protected void validateChildNode(Locator loc, String nsURI, String localName)
throws SAXParseException {
- if (nsURI == FOElementMapping.URI) {
+ if (nsURI == FO_URI) {
if (localName.equals("title")) {
if (titleFO != null) {
tooManyNodesError(loc, "fo:title");
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.FObj;
import org.apache.fop.fo.FONode;
-import org.apache.fop.fo.FOElementMapping;
import org.apache.fop.apps.FOPException;
/**
*/
protected void validateChildNode(Locator loc, String nsURI, String localName)
throws SAXParseException {
- if (nsURI == FOElementMapping.URI) {
+ if (nsURI == FO_URI) {
if (!localName.equals("single-page-master-reference")
&& !localName.equals("repeatable-page-master-reference")
&& !localName.equals("repeatable-page-master-alternatives")) {
import org.xml.sax.SAXParseException;
// FOP
-import org.apache.fop.fo.FOElementMapping;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObj;
*/
protected void validateChildNode(Locator loc, String nsURI, String localName)
throws SAXParseException {
- if (!(nsURI == FOElementMapping.URI &&
+ if (!(nsURI == FO_URI &&
localName.equals("conditional-page-master-reference"))) {
invalidChildError(loc, nsURI, localName);
}
// FOP
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;
*/
protected void validateChildNode(Locator loc, String nsURI, String localName)
throws SAXParseException {
- if (nsURI == FOElementMapping.URI) {
+ if (nsURI == FO_URI) {
if (localName.equals("layout-master-set")) {
if (layoutMasterSet != null) {
tooManyNodesError(loc, "fo:layout-master-set");
import org.xml.sax.SAXParseException;
// FOP
-import org.apache.fop.fo.FOElementMapping;
import org.apache.fop.fo.FONode;
/**
import org.apache.fop.fo.flow.Inline;
import org.apache.fop.fo.flow.InstreamForeignObject;
import org.apache.fop.fo.flow.Leader;
-import org.apache.fop.fo.flow.ListItem;
-import org.apache.fop.fo.flow.ListItemBody;
-import org.apache.fop.fo.flow.ListItemLabel;
import org.apache.fop.fo.flow.PageNumber;
import org.apache.fop.fo.flow.RetrieveMarker;
import org.apache.fop.fo.flow.Table;
import org.apache.fop.fo.pagination.Title;
import org.apache.fop.fo.properties.CommonBackground;
import org.apache.fop.fo.properties.CommonBorderAndPadding;
-import org.apache.fop.layoutmgr.list.Item;
-import org.apache.fop.layoutmgr.list.ListItemLayoutManager;
import org.apache.fop.layoutmgr.table.Body;
import org.apache.fop.layoutmgr.table.Column;
import org.apache.fop.layoutmgr.table.TableLayoutManager;
return areaCurrent;
}
- public void serveListItem(ListItem node) {
- if (node.getLabel() != null && node.getBody() != null) {
- ListItemLayoutManager blm = new ListItemLayoutManager(node);
- blm.setLabel(getListItemLabelLayoutManager(node.getLabel()));
- blm.setBody(getListItemBodyLayoutManager(node.getBody()));
- currentLMList.add(blm);
- } else {
- node.getLogger().error("list-item requires list-item-label and list-item-body");
- }
- }
-
- /**
- * @return this object's Item layout manager
- */
- public Item getListItemLabelLayoutManager(ListItemLabel node) {
- Item itemLabel = new Item(node);
- return itemLabel;
- }
-
- /**
- * @return Item layout manager
- */
- public Item getListItemBodyLayoutManager(ListItemBody node) {
- Item item = new Item(node);
- return item;
- }
-
/**
* Overridden from FObj
* @param lms the list to which the layout manager(s) should be added
--- /dev/null
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.layoutmgr;
+
+import org.apache.fop.fo.flow.BasicLink;
+import org.apache.fop.area.inline.InlineParent;
+import org.apache.fop.area.Trait;
+import org.apache.fop.area.LinkResolver;
+import org.apache.fop.area.PageViewport;
+
+/**
+ * LayoutManager for the fo:basic-link formatting object
+ */
+public class BasicLinkLayoutManager extends InlineStackingLayoutManager {
+
+ private String link;
+ private boolean isExternalLink = false;
+
+ /**
+ * Create an fo:basic-link layout manager.
+ *
+ * @param node the formatting object that creates the area
+ */
+ public BasicLinkLayoutManager(BasicLink node) {
+ super(node);
+ setLMiter(new LMiter(this, node.getChildNodes()));
+ link = node.getLink();
+ isExternalLink = node.isExternalLink();
+ }
+
+ protected InlineParent createArea() {
+ InlineParent area = super.createArea();
+ setupBasicLinkArea(parentLM, area);
+ return area;
+ }
+
+ private void setupBasicLinkArea(LayoutManager parentLM,
+ InlineParent area) {
+ if (isExternalLink) {
+ area.addTrait(Trait.EXTERNAL_LINK, link);
+ } else {
+ PageViewport page = parentLM.resolveRefID(link);
+ if (page != null) {
+ area.addTrait(Trait.INTERNAL_LINK, page.getKey());
+ } else {
+ LinkResolver res = new LinkResolver(link, area);
+ parentLM.addUnresolvedArea(link, res);
+ }
+ }
+ }
+}
+
import java.util.List;
import org.apache.fop.area.inline.InlineArea;
+import org.apache.fop.fo.flow.BidiOverride;
/**
private List children;
- public BidiLayoutManager(InlineStackingLayoutManager cLM) {
+ public BidiLayoutManager(BidiOverride node, InlineStackingLayoutManager cLM) {
children = new ArrayList();
+ setFObj(node);
/*
for (int count = cLM.size() - 1; count >= 0; count--) {
InlineArea ia = cLM.get(count);
package org.apache.fop.layoutmgr.list;
import org.apache.fop.fo.FObj;
+import org.apache.fop.fo.flow.ListItem;
+import org.apache.fop.fo.flow.ListItemBody;
+import org.apache.fop.fo.flow.ListItemLabel;
import org.apache.fop.fo.PropertyManager;
import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
import org.apache.fop.layoutmgr.LayoutManager;
* Create a new list item layout manager.
*
*/
- public ListItemLayoutManager(FObj node) {
+ public ListItemLayoutManager(ListItem node) {
super(node);
+ setLabel(node.getLabel());
+ setBody(node.getBody());
}
/**
}
/**
- * Sets the label of the list item
- * @param item the label item
+ * Create a LM for the fo:list-item-label object
+ * @param node the fo:list-item-label FO
*/
- public void setLabel(Item item) {
- label = item;
+ public void setLabel(ListItemLabel node) {
+ label = new Item(node);
label.setParent(this);
}
/**
- * Sets the body of the list item
- * @param item the body item
+ * Create a LM for the fo:list-item-body object
+ * @param node the fo:list-item-body FO
*/
- public void setBody(Item item) {
- body = item;
+ public void setBody(ListItemBody node) {
+ body = new Item(node);
body.setParent(this);
}