aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org
diff options
context:
space:
mode:
authorAndreas L. Delmelle <adelmelle@apache.org>2007-07-07 01:07:10 +0000
committerAndreas L. Delmelle <adelmelle@apache.org>2007-07-07 01:07:10 +0000
commit69b7925f5cdbd813a4136705ee7a19e9af6f28fc (patch)
treeb51e50a5278f70c4e07f0c37650f0cada298badd /src/java/org
parent5abb46f263e647dee70d173e60d803928fc9e45c (diff)
downloadxmlgraphics-fop-69b7925f5cdbd813a4136705ee7a19e9af6f28fc.tar.gz
xmlgraphics-fop-69b7925f5cdbd813a4136705ee7a19e9af6f28fc.zip
Bugzilla 41656:
Refactoring in the fo package: -> removal of the childNodes instance member in fop.fo.FObj -> addition of a firstChild instance member in fop.fo.FObj -> addition of a siblings instance member in fop.fo.FONode -> addition of a FONodeIterator interface in FONode + corresponding implementation in FObj -> changed implementations of FObj.addChildNode(), .removeChild() and .getChildNodes() git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@554104 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org')
-rw-r--r--src/java/org/apache/fop/fo/ElementMappingRegistry.java4
-rw-r--r--src/java/org/apache/fop/fo/FONode.java70
-rw-r--r--src/java/org/apache/fop/fo/FObj.java271
-rw-r--r--src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java27
-rw-r--r--src/java/org/apache/fop/fo/flow/Character.java4
-rw-r--r--src/java/org/apache/fop/fo/flow/Float.java2
-rw-r--r--src/java/org/apache/fop/fo/flow/FootnoteBody.java2
-rw-r--r--src/java/org/apache/fop/fo/flow/InstreamForeignObject.java8
-rw-r--r--src/java/org/apache/fop/fo/flow/MultiSwitch.java2
-rw-r--r--src/java/org/apache/fop/fo/flow/RetrieveMarker.java4
-rw-r--r--src/java/org/apache/fop/fo/flow/Table.java8
-rw-r--r--src/java/org/apache/fop/fo/flow/TableBody.java56
-rw-r--r--src/java/org/apache/fop/fo/flow/TableCaption.java2
-rw-r--r--src/java/org/apache/fop/fo/flow/TableCell.java2
-rw-r--r--src/java/org/apache/fop/fo/flow/TableFObj.java101
-rw-r--r--src/java/org/apache/fop/fo/flow/TableRow.java16
-rw-r--r--src/java/org/apache/fop/fo/pagination/Declarations.java10
-rw-r--r--src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java2
-rw-r--r--src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java2
-rw-r--r--src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java2
-rw-r--r--src/java/org/apache/fop/fo/pagination/StaticContent.java2
21 files changed, 380 insertions, 217 deletions
diff --git a/src/java/org/apache/fop/fo/ElementMappingRegistry.java b/src/java/org/apache/fop/fo/ElementMappingRegistry.java
index 887fe8b55..2ba142203 100644
--- a/src/java/org/apache/fop/fo/ElementMappingRegistry.java
+++ b/src/java/org/apache/fop/fo/ElementMappingRegistry.java
@@ -131,10 +131,10 @@ public class ElementMappingRegistry {
Map table = (Map)fobjTable.get(namespaceURI);
Maker fobjMaker = null;
if (table != null) {
- fobjMaker = (ElementMapping.Maker)table.get(localName);
+ fobjMaker = (Maker)table.get(localName);
// try default
if (fobjMaker == null) {
- fobjMaker = (ElementMapping.Maker)table.get(ElementMapping.DEFAULT);
+ fobjMaker = (Maker)table.get(ElementMapping.DEFAULT);
}
}
diff --git a/src/java/org/apache/fop/fo/FONode.java b/src/java/org/apache/fop/fo/FONode.java
index baf964935..a90d564ec 100644
--- a/src/java/org/apache/fop/fo/FONode.java
+++ b/src/java/org/apache/fop/fo/FONode.java
@@ -50,6 +50,9 @@ public abstract class FONode implements Cloneable {
/** Parent FO node */
protected FONode parent;
+ /** pointer to the sibling nodes */
+ protected FONode[] siblings;
+
/**
* Marks location of this object from the input FO
* Call locator.getSystemId(), getLineNumber(),
@@ -60,7 +63,6 @@ public abstract class FONode implements Cloneable {
/** Logger for fo-tree related messages **/
protected static Log log = LogFactory.getLog(FONode.class);
- //TODO Remove getLogger() method!
/**
* Main constructor.
@@ -82,6 +84,7 @@ public abstract class FONode implements Cloneable {
throws FOPException {
FONode foNode = (FONode) clone();
foNode.parent = cloneparent;
+ foNode.siblings = null;
return foNode;
}
@@ -255,7 +258,7 @@ public abstract class FONode implements Cloneable {
* Return an iterator over all the child nodes of this FObj.
* @return A ListIterator.
*/
- public ListIterator getChildNodes() {
+ public FONodeIterator getChildNodes() {
return null;
}
@@ -266,7 +269,7 @@ public abstract class FONode implements Cloneable {
* @return A ListIterator or null if child node isn't a child of
* this FObj.
*/
- public ListIterator getChildNodes(FONode childNode) {
+ public FONodeIterator getChildNodes(FONode childNode) {
return null;
}
@@ -614,5 +617,64 @@ public abstract class FONode implements Cloneable {
return false;
}
}
-}
+
+ protected static void attachSiblings(FONode precedingSibling,
+ FONode followingSibling) {
+ if (precedingSibling.siblings == null) {
+ precedingSibling.siblings = new FONode[2];
+ }
+ if (followingSibling.siblings == null) {
+ followingSibling.siblings = new FONode[2];
+ }
+ precedingSibling.siblings[1] = followingSibling;
+ followingSibling.siblings[0] = precedingSibling;
+ }
+
+ /**
+ * Base iterator interface over a FO's children
+ *
+ */
+ public interface FONodeIterator extends ListIterator {
+
+ /**
+ * Returns the parent node for this iterator's list
+ * of child nodes
+ * @return the parent node
+ */
+ public FObj parentNode();
+
+ /**
+ * Convenience method with return type of FONode
+ * (should be semantically equivalent to
+ * <code>(FONode) next();</code>)
+ * @return the next node (if any), as a type FONode
+ */
+ public FONode nextNode();
+
+ /**
+ * Convenience method with return type of FONode
+ * (should be semantically equivalent to
+ * <code>(FONode) previous();</code>)
+ * @return the previous node (if any), as a type FONode
+ */
+ public FONode previousNode();
+
+ /**
+ * Returns the first node in the list, and decreases the index,
+ * so that a subsequent call to hasPrevious() will return false
+ * @return the first node in the list
+ * @throws NoSuchElementException if the list is empty
+ */
+ public FONode firstNode();
+
+ /**
+ * Returns the last node in the list, and advances the
+ * current position, so that a subsequent call to hasNext()
+ * will return false
+ * @return the last node in the list
+ * @throws NoSuchElementException if the list is empty
+ */
+ public FONode lastNode();
+ }
+}
diff --git a/src/java/org/apache/fop/fo/FObj.java b/src/java/org/apache/fop/fo/FObj.java
index 75c16ec45..00fdc3c8b 100644
--- a/src/java/org/apache/fop/fo/FObj.java
+++ b/src/java/org/apache/fop/fo/FObj.java
@@ -24,6 +24,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
+import java.util.NoSuchElementException;
import java.util.Set;
import org.apache.fop.apps.FOPException;
@@ -43,9 +44,11 @@ public abstract class FObj extends FONode implements Constants {
private static PropertyMaker[] propertyListTable
= FOPropertyMapping.getGenericMappings();
- /** The immediate child nodes of this node. */
- protected List childNodes = null;
-
+ /**
+ * pointer to the descendant subtree
+ */
+ protected FONode firstChild;
+
/** The list of extension attachments, null if none */
private List extensionAttachments = null;
@@ -94,7 +97,7 @@ public abstract class FObj extends FONode implements Constants {
throws FOPException {
FObj fobj = (FObj) super.clone(parent, removeChildren);
if (removeChildren) {
- fobj.childNodes = null;
+ fobj.firstChild = null;
}
return fobj;
}
@@ -214,10 +217,16 @@ public abstract class FObj extends FONode implements Constants {
*/
addExtensionAttachment(attachment);
} else {
- if (childNodes == null) {
- childNodes = new java.util.ArrayList();
+ if (firstChild == null) {
+ firstChild = child;
+ } else {
+ FONode prevChild = firstChild;
+ while (prevChild.siblings != null
+ && prevChild.siblings[1] != null) {
+ prevChild = prevChild.siblings[1];
+ }
+ FONode.attachSiblings(prevChild, child);
}
- childNodes.add(child);
}
}
}
@@ -235,8 +244,21 @@ public abstract class FObj extends FONode implements Constants {
/** @see org.apache.fop.fo.FONode#removeChild(org.apache.fop.fo.FONode) */
public void removeChild(FONode child) {
- if (childNodes != null) {
- childNodes.remove(child);
+ FONode nextChild = null;
+ if (child.siblings != null) {
+ nextChild = child.siblings[1];
+ }
+ if (child == firstChild) {
+ firstChild = nextChild;
+ if (firstChild != null) {
+ firstChild.siblings[0] = null;
+ }
+ } else {
+ FONode prevChild = child.siblings[0];
+ prevChild.siblings[1] = nextChild;
+ if (nextChild != null) {
+ nextChild.siblings[0] = prevChild;
+ }
}
}
@@ -264,39 +286,36 @@ public abstract class FObj extends FONode implements Constants {
/**
* @see org.apache.fop.fo.FONode#getChildNodes()
*/
- public ListIterator getChildNodes() {
- if (childNodes != null) {
- return childNodes.listIterator();
+ public FONodeIterator getChildNodes() {
+ if (firstChild != null) {
+ return new FObjIterator(this);
}
return null;
}
/**
* Return an iterator over the object's childNodes starting
- * at the passed-in node.
+ * at the passed-in node (= first call to iterator.next() will
+ * return childNode)
* @param childNode First node in the iterator
* @return A ListIterator or null if childNode isn't a child of
* this FObj.
*/
- public ListIterator getChildNodes(FONode childNode) {
- if (childNodes != null) {
- int i = childNodes.indexOf(childNode);
- if (i >= 0) {
- return childNodes.listIterator(i);
- }
- }
- return null;
- }
-
- /**
- * Return a FONode based on the index in the list of childNodes.
- * @param nodeIndex index of the node to return
- * @return the node or null if the index is invalid
- */
- public FONode getChildNodeAt(int nodeIndex) {
- if (childNodes != null) {
- if (nodeIndex >= 0 && nodeIndex < childNodes.size()) {
- return (FONode) childNodes.get(nodeIndex);
+ public FONodeIterator getChildNodes(FONode childNode) {
+ FONodeIterator it = getChildNodes();
+ if (it != null) {
+ if (firstChild == childNode) {
+ return it;
+ } else {
+ while (it.hasNext()
+ && it.nextNode().siblings[1] != childNode) {
+ //nop
+ }
+ if (it.hasNext()) {
+ return it;
+ } else {
+ return null;
+ }
}
}
return null;
@@ -322,9 +341,9 @@ public abstract class FObj extends FONode implements Constants {
*/
protected void addMarker(Marker marker) {
String mcname = marker.getMarkerClassName();
- if (childNodes != null) {
+ if (firstChild != null) {
// check for empty childNodes
- for (Iterator iter = childNodes.iterator(); iter.hasNext();) {
+ for (Iterator iter = getChildNodes(); iter.hasNext();) {
FONode node = (FONode) iter.next();
if (node instanceof FObj
|| (node instanceof FOText
@@ -561,4 +580,188 @@ public abstract class FObj extends FONode implements Constants {
return foreignAttributes;
}
}
+
+ public class FObjIterator implements FONodeIterator {
+
+ private static final int F_NONE_ALLOWED = 0;
+ private static final int F_SET_ALLOWED = 1;
+ private static final int F_REMOVE_ALLOWED = 2;
+
+ private FONode currentNode;
+ private FObj parentNode;
+ private int currentIndex;
+ private int flags = F_NONE_ALLOWED;
+
+ protected FObjIterator(FObj parent) {
+ this.parentNode = parent;
+ this.currentNode = parent.firstChild;
+ this.currentIndex = 0;
+ this.flags = F_NONE_ALLOWED;
+ }
+
+ /**
+ * @see FONodeIterator#parentNode()
+ */
+ public FObj parentNode() {
+ return parentNode;
+ }
+
+ /**
+ * @see java.util.ListIterator#next()
+ */
+ public Object next() {
+ if (currentNode != null) {
+ if (currentIndex != 0) {
+ if (currentNode.siblings != null
+ && currentNode.siblings[1] != null) {
+ currentNode = currentNode.siblings[1];
+ } else {
+ throw new NoSuchElementException();
+ }
+ }
+ currentIndex++;
+ flags |= (F_SET_ALLOWED | F_REMOVE_ALLOWED);
+ return currentNode;
+ } else {
+ throw new NoSuchElementException();
+ }
+ }
+
+ /**
+ * @see java.util.ListIterator#previous()
+ */
+ public Object previous() {
+ if (currentNode.siblings != null
+ && currentNode.siblings[0] != null) {
+ currentIndex--;
+ currentNode = currentNode.siblings[0];
+ flags |= (F_SET_ALLOWED | F_REMOVE_ALLOWED);
+ return currentNode;
+ } else {
+ throw new NoSuchElementException();
+ }
+ }
+
+ /**
+ * @see java.util.ListIterator#set(Object)
+ */
+ public void set(Object o) {
+ if ((flags & F_SET_ALLOWED) == F_SET_ALLOWED) {
+ FONode newNode = (FONode) o;
+ if (currentNode == parentNode.firstChild) {
+ parentNode.firstChild = newNode;
+ } else {
+ FONode.attachSiblings(currentNode.siblings[0], newNode);
+ }
+ if (currentNode.siblings != null
+ && currentNode.siblings[1] != null) {
+ FONode.attachSiblings(newNode, currentNode.siblings[1]);
+ }
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ /**
+ * @see java.util.ListIterator#add(Object)
+ */
+ public void add(Object o) {
+ FONode newNode = (FONode) o;
+ if (currentIndex == -1) {
+ if (currentNode != null) {
+ FONode.attachSiblings(newNode, currentNode);
+ }
+ parentNode.firstChild = newNode;
+ currentIndex = 0;
+ currentNode = newNode;
+ } else {
+ if (currentNode.siblings != null
+ && currentNode.siblings[1] != null) {
+ FONode.attachSiblings((FONode) o, currentNode.siblings[1]);
+ }
+ FONode.attachSiblings(currentNode, (FONode) o);
+ }
+ flags &= F_NONE_ALLOWED;
+ }
+
+ /**
+ * @see java.util.ListIterator#hasNext()
+ */
+ public boolean hasNext() {
+ return (currentNode != null)
+ && ((currentIndex == 0)
+ || (currentNode.siblings != null
+ && currentNode.siblings[1] != null));
+ }
+
+ /**
+ * @see java.util.ListIterator#hasPrevious()
+ */
+ public boolean hasPrevious() {
+ return (currentIndex != 0)
+ || (currentNode.siblings != null
+ && currentNode.siblings[0] != null);
+ }
+
+ /**
+ * @see java.util.ListIterator#nextIndex()
+ */
+ public int nextIndex() {
+ return currentIndex + 1;
+ }
+
+ /**
+ * @see java.util.ListIterator#previousIndex()
+ */
+ public int previousIndex() {
+ return currentIndex - 1;
+ }
+
+ /**
+ * @see java.util.ListIterator#remove()
+ */
+ public void remove() {
+ if ((flags & F_REMOVE_ALLOWED) == F_REMOVE_ALLOWED) {
+ parentNode.removeChild(currentNode);
+ if (currentIndex == 0) {
+ //first node removed
+ currentNode = parentNode.firstChild;
+ } else if (currentNode.siblings != null
+ && currentNode.siblings[0] != null) {
+ currentNode = currentNode.siblings[0];
+ currentIndex--;
+ } else {
+ currentNode = null;
+ }
+ flags &= F_NONE_ALLOWED;
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public FONode lastNode() {
+ while (currentNode != null
+ && currentNode.siblings != null
+ && currentNode.siblings[1] != null) {
+ currentNode = currentNode.siblings[1];
+ currentIndex++;
+ }
+ return currentNode;
+ }
+
+ public FONode firstNode() {
+ currentNode = parentNode.firstChild;
+ currentIndex = 0;
+ return currentNode;
+ }
+
+ public FONode nextNode() {
+ return (FONode) next();
+ }
+
+ public FONode previousNode() {
+ return (FONode) previous();
+ }
+ }
+
}
diff --git a/src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java b/src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java
index d7200dc24..e0e5898e3 100644
--- a/src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java
+++ b/src/java/org/apache/fop/fo/XMLWhiteSpaceHandler.java
@@ -82,25 +82,11 @@ public class XMLWhiteSpaceHandler {
private boolean nextChildIsBlockLevel;
private RecursiveCharIterator charIter;
- private List discardableFOCharacters;
private List pendingInlines;
private Stack nestedBlockStack = new java.util.Stack();
private CharIterator firstWhiteSpaceInSeq;
/**
- * Marks a Character object as discardable, so that it is effectively
- * removed from the FOTree at the end of handleWhitespace()
- * @param foChar the Character object to be removed from the list of
- * childNodes
- */
- public void addDiscardableFOChar(Character foChar) {
- if (discardableFOCharacters == null) {
- discardableFOCharacters = new java.util.ArrayList();
- }
- discardableFOCharacters.add(foChar);
- }
-
- /**
* Handle white-space for the fo that is passed in, starting at
* firstTextNode
* @param fo the FO for which to handle white-space
@@ -155,12 +141,10 @@ public class XMLWhiteSpaceHandler {
|| currentBlock == null
|| (foId == Constants.FO_RETRIEVE_MARKER
&& currentFO.getParent() == currentBlock)) {
- int textNodeIndex = fo.childNodes.indexOf(firstTextNode);
afterLinefeed = (
- (textNodeIndex == 0)
- || (textNodeIndex > 0
- && ((FONode) fo.childNodes.get(textNodeIndex - 1))
- .getNameId() == Constants.FO_BLOCK));
+ (firstTextNode == fo.firstChild)
+ || (firstTextNode.siblings[0].getNameId()
+ == Constants.FO_BLOCK));
}
endOfBlock = (nextChild == null && currentFO == currentBlock);
@@ -344,11 +328,6 @@ public class XMLWhiteSpaceHandler {
break;
}
}
- if (discardableFOCharacters != null
- && !discardableFOCharacters.isEmpty()) {
- currentFO.childNodes.removeAll(discardableFOCharacters);
- discardableFOCharacters.clear();
- }
}
private void addPendingInline(FObjMixed fo) {
diff --git a/src/java/org/apache/fop/fo/flow/Character.java b/src/java/org/apache/fop/fo/flow/Character.java
index b93ccbea7..78a1ea0ef 100644
--- a/src/java/org/apache/fop/fo/flow/Character.java
+++ b/src/java/org/apache/fop/fo/flow/Character.java
@@ -273,9 +273,7 @@ public class Character extends FObj {
}
public void remove() {
- foChar.character = CharUtilities.CODE_EOT;
- getFOEventHandler().getXMLWhiteSpaceHandler()
- .addDiscardableFOChar(foChar);
+ foChar.parent.removeChild(foChar);
}
public void replaceChar(char c) {
diff --git a/src/java/org/apache/fop/fo/flow/Float.java b/src/java/org/apache/fop/fo/flow/Float.java
index d68264b64..475ffee09 100644
--- a/src/java/org/apache/fop/fo/flow/Float.java
+++ b/src/java/org/apache/fop/fo/flow/Float.java
@@ -75,7 +75,7 @@ public class Float extends FObj {
* @see org.apache.fop.fo.FONode#endOfNode
*/
protected void endOfNode() throws FOPException {
- if (childNodes == null) {
+ if (firstChild == null) {
missingChildElementError("(%block;)+");
}
}
diff --git a/src/java/org/apache/fop/fo/flow/FootnoteBody.java b/src/java/org/apache/fop/fo/flow/FootnoteBody.java
index 35f44dff6..ef42012a8 100644
--- a/src/java/org/apache/fop/fo/flow/FootnoteBody.java
+++ b/src/java/org/apache/fop/fo/flow/FootnoteBody.java
@@ -63,7 +63,7 @@ public class FootnoteBody extends FObj {
* @see org.apache.fop.fo.FONode#endOfNode
*/
protected void endOfNode() throws FOPException {
- if (childNodes == null) {
+ if (firstChild == null) {
missingChildElementError("(%block;)+");
}
getFOEventHandler().endFootnoteBody(this);
diff --git a/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java b/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java
index fa10b2946..fc8dd4bc9 100644
--- a/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java
+++ b/src/java/org/apache/fop/fo/flow/InstreamForeignObject.java
@@ -55,7 +55,7 @@ public class InstreamForeignObject extends AbstractGraphics {
* @see org.apache.fop.fo.FONode#endOfNode
*/
protected void endOfNode() throws FOPException {
- if (childNodes == null || childNodes.size() != 1) {
+ if (firstChild == null) {
missingChildElementError("one (1) non-XSL namespace child");
}
getFOEventHandler().foreignObject(this);
@@ -69,7 +69,7 @@ public class InstreamForeignObject extends AbstractGraphics {
throws ValidationException {
if (FO_URI.equals(nsURI)) {
invalidChildError(loc, nsURI, localName);
- } else if (childNodes != null) {
+ } else if (firstChild != null) {
tooManyNodesError(loc, "child element");
}
}
@@ -91,7 +91,7 @@ public class InstreamForeignObject extends AbstractGraphics {
*/
private void prepareIntrinsicSize() {
if (intrinsicDimensions == null) {
- XMLObj child = (XMLObj)childNodes.get(0);
+ XMLObj child = (XMLObj) firstChild;
Point2D csize = new Point2D.Float(-1, -1);
intrinsicDimensions = child.getDimension(csize);
if (intrinsicDimensions == null) {
@@ -132,7 +132,7 @@ public class InstreamForeignObject extends AbstractGraphics {
/** @return the XMLObj child node of the instream-foreign-object. */
public XMLObj getChildXMLObj() {
- return (XMLObj) childNodes.get(0);
+ return (XMLObj) firstChild;
}
}
diff --git a/src/java/org/apache/fop/fo/flow/MultiSwitch.java b/src/java/org/apache/fop/fo/flow/MultiSwitch.java
index 2293459c7..097b09862 100644
--- a/src/java/org/apache/fop/fo/flow/MultiSwitch.java
+++ b/src/java/org/apache/fop/fo/flow/MultiSwitch.java
@@ -68,7 +68,7 @@ public class MultiSwitch extends FObj {
* @see org.apache.fop.fo.FONode#endOfNode
*/
protected void endOfNode() throws FOPException {
- if (childNodes == null) {
+ if (firstChild == null) {
missingChildElementError("(multi-case+)");
}
}
diff --git a/src/java/org/apache/fop/fo/flow/RetrieveMarker.java b/src/java/org/apache/fop/fo/flow/RetrieveMarker.java
index 6cdd359f9..016f84e47 100644
--- a/src/java/org/apache/fop/fo/flow/RetrieveMarker.java
+++ b/src/java/org/apache/fop/fo/flow/RetrieveMarker.java
@@ -174,9 +174,9 @@ public class RetrieveMarker extends FObjMixed {
private void cloneFromMarker(Marker marker)
throws FOPException {
// clean up remnants from a possible earlier layout
- if (childNodes != null) {
+ if (firstChild != null) {
currentTextNode = null;
- childNodes.removeAll(childNodes);
+ firstChild = null;
}
cloneSubtree(marker.getChildNodes(), this,
marker, propertyList);
diff --git a/src/java/org/apache/fop/fo/flow/Table.java b/src/java/org/apache/fop/fo/flow/Table.java
index 68fe126cf..0190c3cb4 100644
--- a/src/java/org/apache/fop/fo/flow/Table.java
+++ b/src/java/org/apache/fop/fo/flow/Table.java
@@ -349,14 +349,6 @@ public class Table extends TableFObj {
return columns;
}
- /**
- * @param index index of the table-body element.
- * @return the requested table-body element
- */
- public TableBody getBody(int index) {
- return (TableBody) childNodes.get(index);
- }
-
/** @return the body for the table-header. */
public TableBody getTableHeader() {
return tableHeader;
diff --git a/src/java/org/apache/fop/fo/flow/TableBody.java b/src/java/org/apache/fop/fo/flow/TableBody.java
index 891141c26..d38d96033 100644
--- a/src/java/org/apache/fop/fo/flow/TableBody.java
+++ b/src/java/org/apache/fop/fo/flow/TableBody.java
@@ -232,43 +232,6 @@ public class TableBody extends TableFObj {
}
/**
- * If table-cells are used as direct children of a table-body|header|footer
- * they are replaced in this method by proper table-rows.
- * @throws FOPException if there's a problem binding the TableRow's
- * properties.
- */
- // TODO: This is currently unused. Why is it here?
- private void convertCellsToRows() throws FOPException {
- //getLogger().debug("Converting cells to rows...");
- List cells = new java.util.ArrayList(childNodes);
- childNodes.clear();
- Iterator i = cells.iterator();
- TableRow row = null;
- while (i.hasNext()) {
- TableCell cell = (TableCell) i.next();
- if (cell.startsRow() && (row != null)) {
- childNodes.add(row);
- row = null;
- }
- if (row == null) {
- row = new TableRow(this);
- PropertyList pList = new StaticPropertyList(row,
- savedPropertyList);
- pList.setWritingMode();
- row.bind(pList);
- }
- row.addReplacedCell(cell);
- if (cell.endsRow()) {
- childNodes.add(row);
- row = null;
- }
- }
- if (row != null) {
- childNodes.add(row);
- }
- }
-
- /**
* @return the Common Border, Padding, and Background Properties.
*/
public CommonBorderPaddingBackground getCommonBorderPaddingBackground() {
@@ -292,22 +255,11 @@ public class TableBody extends TableFObj {
* @return true if the given table row is the first row of this body.
*/
public boolean isFirst(TableRow obj) {
- return (childNodes == null
- || (!childNodes.isEmpty()
- && childNodes.get(0) == obj));
+ return (firstChild == null
+ || firstChild == obj);
}
/**
- * @param obj table row in question
- * @return true if the given table row is the first row of this body.
- */
- public boolean isLast(TableRow obj) {
- return (childNodes == null
- || (childNodes.size() > 0
- && childNodes.get(childNodes.size() - 1) == obj));
- }
-
- /**
* Initializes list of pending row-spans; used for correctly
* assigning initial value for column-number for the
* cells of following rows
@@ -411,8 +363,8 @@ public class TableBody extends TableFObj {
* start of row)
*/
protected boolean previousCellEndedRow() {
- if (childNodes != null) {
- FONode prevNode = (FONode) childNodes.get(childNodes.size() - 1);
+ if (firstChild != null) {
+ FONode prevNode = getChildNodes().lastNode();
if (prevNode.getNameId() == FO_TABLE_CELL) {
return ((TableCell) prevNode).endsRow();
}
diff --git a/src/java/org/apache/fop/fo/flow/TableCaption.java b/src/java/org/apache/fop/fo/flow/TableCaption.java
index e0227b9a1..c1105a41f 100644
--- a/src/java/org/apache/fop/fo/flow/TableCaption.java
+++ b/src/java/org/apache/fop/fo/flow/TableCaption.java
@@ -94,7 +94,7 @@ public class TableCaption extends FObj {
* @see org.apache.fop.fo.FONode#endOfNode
*/
protected void endOfNode() throws FOPException {
- if (childNodes == null) {
+ if (firstChild == null) {
missingChildElementError("marker* (%block;)");
}
}
diff --git a/src/java/org/apache/fop/fo/flow/TableCell.java b/src/java/org/apache/fop/fo/flow/TableCell.java
index 8f1b48d54..3d6f5fb3c 100644
--- a/src/java/org/apache/fop/fo/flow/TableCell.java
+++ b/src/java/org/apache/fop/fo/flow/TableCell.java
@@ -106,7 +106,7 @@ public class TableCell extends TableFObj {
if (!blockItemFound) {
if (getUserAgent().validateStrictly()) {
missingChildElementError("marker* (%block;)+");
- } else if (childNodes != null && childNodes.size() > 0) {
+ } else if (firstChild != null) {
log.warn("fo:table-cell content that is not "
+ "enclosed by a fo:block will be dropped/ignored.");
}
diff --git a/src/java/org/apache/fop/fo/flow/TableFObj.java b/src/java/org/apache/fop/fo/flow/TableFObj.java
index 980eaeb7c..cf3eb3977 100644
--- a/src/java/org/apache/fop/fo/flow/TableFObj.java
+++ b/src/java/org/apache/fop/fo/flow/TableFObj.java
@@ -120,31 +120,13 @@ public abstract class TableFObj extends FObj {
super.addChildNode(child);
}
- private void updateColumnIndex(TableCell cell)
- throws ValidationException {
+ private void updateColumnIndex(TableCell cell) {
int rowSpan = cell.getNumberRowsSpanned();
int colSpan = cell.getNumberColumnsSpanned();
int columnIndex = getCurrentColumnIndex();
+ int i;
- int i = -1;
- while (++i < colSpan) {
- if (isColumnNumberUsed(columnIndex + i)) {
- /* if column-number is already in use by another cell
- * in the current row => error!
- */
- StringBuffer errorMessage = new StringBuffer();
- errorMessage.append("fo:table-cell overlaps in column ")
- .append(columnIndex + i);
- if (locator.getLineNumber() != -1) {
- errorMessage.append(" (line #")
- .append(locator.getLineNumber()).append(", column #")
- .append(locator.getColumnNumber()).append(")");
- }
- throw new ValidationException(errorMessage.toString());
- }
- }
-
if (getNameId() == FO_TABLE_ROW) {
TableRow row = (TableRow) this;
@@ -182,7 +164,8 @@ public abstract class TableFObj extends FObj {
/* pendingSpans not initialized for the first row...
*/
if (body.firstRow) {
- for (i = colSpan; --i >= 0;) {
+ for (i = colSpan;
+ --i >= 0|| body.pendingSpans.size() < cell.getColumnNumber();) {
body.pendingSpans.add(null);
}
}
@@ -343,60 +326,68 @@ public abstract class TableFObj extends FObj {
parent.resetColumnIndex();
}
}
- return new NumberProperty(((TableFObj) fo.getParent())
- .getCurrentColumnIndex());
- } else {
- throw new PropertyException(
- "column-number property is only allowed"
- + " on fo:table-cell or fo:table-column, not on "
- + fo.getName());
}
+ return new NumberProperty(
+ ((TableFObj) fo.getParent()).getCurrentColumnIndex());
}
+
/**
* Check the value of the column-number property.
* Return the parent's column index (initial value) in case
* of a negative or zero value
*
- * @see org.apache.fop.fo.properties.PropertyMaker#get(
- * int, PropertyList, boolean, boolean)
+ * @see org.apache.fop.fo.properties.PropertyMaker#make(
+ * org.apache.fop.fo.PropertyList,
+ * java.lang.String,
+ * org.apache.fop.fo.FObj)
*/
- public Property get(int subpropId, PropertyList propertyList,
- boolean tryInherit, boolean tryDefault)
- throws PropertyException {
+ public Property make(PropertyList propertyList, String value, FObj fo)
+ throws PropertyException {
+ Property p = super.make(propertyList, value, fo);
- Property p = super.get(0, propertyList, tryInherit, tryDefault);
- TableFObj fo = (TableFObj) propertyList.getFObj();
TableFObj parent = (TableFObj) propertyList.getParentFObj();
- if (p != null) {
- int columnIndex = p.getNumeric().getValue();
-
- if (columnIndex <= 0) {
- log.warn("Specified negative or zero value for "
- + "column-number on " + fo.getName() + ": "
- + columnIndex + " forced to "
- + parent.getCurrentColumnIndex());
- return new NumberProperty(parent.getCurrentColumnIndex());
- }
-
+ int columnIndex = p.getNumeric().getValue();
+ if (columnIndex <= 0) {
+ log.warn("Specified negative or zero value for "
+ + "column-number on " + fo.getName() + ": "
+ + columnIndex + " forced to "
+ + parent.getCurrentColumnIndex());
+ return new NumberProperty(parent.getCurrentColumnIndex());
+ } else {
double tmpIndex = p.getNumeric().getNumericValue();
if (tmpIndex - columnIndex > 0.0) {
columnIndex = (int) Math.round(tmpIndex);
log.warn("Rounding specified column-number of "
+ tmpIndex + " to " + columnIndex);
- return new NumberProperty(columnIndex);
+ p = new NumberProperty(columnIndex);
}
-
- /* if column-number was explicitly specified, force the
- * parent's current column index to the specified value,
- * so that the updated index will be the correct initial
- * value for the next cell/column (see Rec 7.26.8)
- */
- if (propertyList.getExplicit(Constants.PR_COLUMN_NUMBER) != null) {
- parent.setCurrentColumnIndex(p.getNumeric().getValue());
+ }
+
+ parent.setCurrentColumnIndex(columnIndex);
+
+ int colSpan = propertyList.get(Constants.PR_NUMBER_COLUMNS_SPANNED)
+ .getNumeric().getValue();
+ int i = -1;
+ while (++i < colSpan) {
+ if (parent.isColumnNumberUsed(columnIndex + i)) {
+ /* if column-number is already in use by another
+ * cell/column => error!
+ */
+ StringBuffer errorMessage = new StringBuffer();
+ errorMessage.append(fo.getName() + " overlaps in column ")
+ .append(columnIndex + i);
+ org.xml.sax.Locator loc = fo.getLocator();
+ if (loc != null && loc.getLineNumber() != -1) {
+ errorMessage.append(" (line #")
+ .append(loc.getLineNumber()).append(", column #")
+ .append(loc.getColumnNumber()).append(")");
+ }
+ throw new PropertyException(errorMessage.toString());
}
}
+
return p;
}
}
diff --git a/src/java/org/apache/fop/fo/flow/TableRow.java b/src/java/org/apache/fop/fo/flow/TableRow.java
index 1b5c05b05..74661e304 100644
--- a/src/java/org/apache/fop/fo/flow/TableRow.java
+++ b/src/java/org/apache/fop/fo/flow/TableRow.java
@@ -87,20 +87,6 @@ public class TableRow extends TableFObj {
}
/**
- * Adds a cell to this row (skips marker handling done by
- * FObj.addChildNode().
- * Used by TableBody during the row building process when only cells are
- * used as direct children of a table-body/header/footer.
- * @param cell cell to add.
- */
- protected void addReplacedCell(TableCell cell) {
- if (childNodes == null) {
- childNodes = new java.util.ArrayList();
- }
- childNodes.add(cell);
- }
-
- /**
* @see org.apache.fop.fo.FONode#processNode(String, Locator,
* Attributes, PropertyList)
*/
@@ -168,7 +154,7 @@ public class TableRow extends TableFObj {
* @see org.apache.fop.fo.FONode#endOfNode
*/
protected void endOfNode() throws FOPException {
- if (childNodes == null) {
+ if (firstChild == null) {
missingChildElementError("(table-cell+)");
}
if (!inMarker()) {
diff --git a/src/java/org/apache/fop/fo/pagination/Declarations.java b/src/java/org/apache/fop/fo/pagination/Declarations.java
index 86fa1b3f4..7232af1ae 100644
--- a/src/java/org/apache/fop/fo/pagination/Declarations.java
+++ b/src/java/org/apache/fop/fo/pagination/Declarations.java
@@ -20,13 +20,13 @@
package org.apache.fop.fo.pagination;
// Java
-import java.util.Iterator;
import java.util.Map;
import org.xml.sax.Locator;
import org.apache.fop.apps.FOPException;
import org.apache.fop.fo.FONode;
+import org.apache.fop.fo.FONode.FONodeIterator;
import org.apache.fop.fo.FObj;
import org.apache.fop.fo.PropertyList;
import org.apache.fop.fo.ValidationException;
@@ -77,9 +77,9 @@ public class Declarations extends FObj {
* @see org.apache.fop.fo.FONode#endOfNode()
*/
protected void endOfNode() throws FOPException {
- if (childNodes != null) {
- for (Iterator iter = childNodes.iterator(); iter.hasNext();) {
- FONode node = (FONode)iter.next();
+ if (firstChild != null) {
+ for (FONodeIterator iter = getChildNodes(); iter.hasNext();) {
+ FONode node = iter.nextNode();
if (node.getName().equals("fo:color-profile")) {
ColorProfile cp = (ColorProfile)node;
if (!"".equals(cp.getColorProfileName())) {
@@ -93,7 +93,7 @@ public class Declarations extends FObj {
}
}
}
- childNodes = null;
+ firstChild = null;
}
private void addColorProfile(ColorProfile cp) {
diff --git a/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java b/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java
index 69f621c65..e749044bb 100644
--- a/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java
+++ b/src/java/org/apache/fop/fo/pagination/LayoutMasterSet.java
@@ -72,7 +72,7 @@ public class LayoutMasterSet extends FObj {
* @see org.apache.fop.fo.FONode#endOfNode
*/
protected void endOfNode() throws FOPException {
- if (childNodes == null) {
+ if (firstChild == null) {
missingChildElementError("(simple-page-master|page-sequence-master)+");
}
checkRegionNames();
diff --git a/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java b/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java
index fc12205b7..efca3f740 100644
--- a/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java
+++ b/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java
@@ -83,7 +83,7 @@ public class PageSequenceMaster extends FObj {
* @see org.apache.fop.fo.FONode#endOfNode()
*/
protected void endOfNode() throws FOPException {
- if (childNodes == null) {
+ if (firstChild == null) {
missingChildElementError("(single-page-master-reference|"
+ "repeatable-page-master-reference|repeatable-page-master-alternatives)+");
}
diff --git a/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java b/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java
index f83bf005f..521a70787 100644
--- a/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java
+++ b/src/java/org/apache/fop/fo/pagination/RepeatablePageMasterAlternatives.java
@@ -84,7 +84,7 @@ public class RepeatablePageMasterAlternatives extends FObj
* @see org.apache.fop.fo.FONode#endOfNode
*/
protected void endOfNode() throws FOPException {
- if (childNodes == null) {
+ if (firstChild == null) {
missingChildElementError("(conditional-page-master-reference+)");
}
}
diff --git a/src/java/org/apache/fop/fo/pagination/StaticContent.java b/src/java/org/apache/fop/fo/pagination/StaticContent.java
index 43f6806ca..cd55609cd 100644
--- a/src/java/org/apache/fop/fo/pagination/StaticContent.java
+++ b/src/java/org/apache/fop/fo/pagination/StaticContent.java
@@ -55,7 +55,7 @@ public class StaticContent extends Flow {
* @see org.apache.fop.fo.FONode#endOfNode
*/
protected void endOfNode() throws FOPException {
- if (childNodes == null && getUserAgent().validateStrictly()) {
+ if (firstChild == null && getUserAgent().validateStrictly()) {
missingChildElementError("(%block;)+");
}
getFOEventHandler().endFlow(this);