From 8ada5c8257ff520a5869e2f6fccce3d5349a9305 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Wed, 23 Feb 2005 22:04:01 +0000 Subject: [PATCH] An empty table-body is illegal but we'll allow it to make things easier for stylesheet writers. Empty table-body elements are removed from their parent so they can't cause any nasty effects in the LMs. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198457 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/fo/FONode.java | 10 ++++++++++ src/java/org/apache/fop/fo/FObj.java | 7 +++++++ src/java/org/apache/fop/fo/flow/TableBody.java | 9 ++++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/java/org/apache/fop/fo/FONode.java b/src/java/org/apache/fop/fo/FONode.java index 4f9707c2d..ba7832858 100644 --- a/src/java/org/apache/fop/fo/FONode.java +++ b/src/java/org/apache/fop/fo/FONode.java @@ -197,6 +197,15 @@ public abstract class FONode implements Cloneable { protected void addChildNode(FONode child) throws FOPException { } + /** + * Removes a child node. Used by the child nodes to remove themselves, for + * example table-body if it has no children. + * @param child child node to be removed + */ + public void removeChild(FONode child) { + //nop + } + /** * @return the parent node of this node */ @@ -410,5 +419,6 @@ public abstract class FONode implements Cloneable { public int getNameId() { return Constants.FO_UNKNOWN_NODE; } + } diff --git a/src/java/org/apache/fop/fo/FObj.java b/src/java/org/apache/fop/fo/FObj.java index 87dc3bb1e..b3982bfa5 100644 --- a/src/java/org/apache/fop/fo/FObj.java +++ b/src/java/org/apache/fop/fo/FObj.java @@ -170,6 +170,13 @@ 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); + } + } + /** * Find the nearest parent, grandparent, etc. FONode that is also an FObj * @return FObj the nearest ancestor FONode that is an FObj diff --git a/src/java/org/apache/fop/fo/flow/TableBody.java b/src/java/org/apache/fop/fo/flow/TableBody.java index 28c182424..fd3b42341 100644 --- a/src/java/org/apache/fop/fo/flow/TableBody.java +++ b/src/java/org/apache/fop/fo/flow/TableBody.java @@ -88,6 +88,11 @@ public class TableBody extends FObj { */ protected void endOfNode() throws FOPException { getFOEventHandler().endBody(this); + if (childNodes == null || childNodes.size() == 0) { + getLogger().error("fo:table-body must not be empty. " + + "Expected: (table-row+|table-cell+)"); + getParent().removeChild(this); + } convertCellsToRows(); } @@ -98,7 +103,9 @@ public class TableBody extends FObj { */ private void convertCellsToRows() throws FOPException { try { - if (childNodes.size() == 0 || childNodes.get(0) instanceof TableRow) { + if (childNodes == null + || childNodes.size() == 0 + || childNodes.get(0) instanceof TableRow) { return; } //getLogger().debug("Converting cells to rows..."); -- 2.39.5