aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGlen Mazza <gmazza@apache.org>2005-03-05 00:32:25 +0000
committerGlen Mazza <gmazza@apache.org>2005-03-05 00:32:25 +0000
commitb667d1a7003cb132595aa260e56ee95eb7edccd3 (patch)
tree4d2a970321f539ab595ddf459bd060ff1aa2d189 /src
parent07493978a3bd4e9903484f79c6db33a9bcc77f54 (diff)
downloadxmlgraphics-fop-b667d1a7003cb132595aa260e56ee95eb7edccd3.tar.gz
xmlgraphics-fop-b667d1a7003cb132595aa260e56ee95eb7edccd3.zip
Validation for fo:table and fo:table-header added, some minor simplifications in other places.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@198466 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/java/org/apache/fop/area/MainReference.java7
-rw-r--r--src/java/org/apache/fop/fo/FONode.java9
-rw-r--r--src/java/org/apache/fop/fo/flow/Table.java60
-rw-r--r--src/java/org/apache/fop/fo/flow/TableBody.java58
-rw-r--r--src/java/org/apache/fop/fo/flow/TableFooter.java4
-rw-r--r--src/java/org/apache/fop/fo/flow/TableHeader.java20
-rw-r--r--src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java4
7 files changed, 119 insertions, 43 deletions
diff --git a/src/java/org/apache/fop/area/MainReference.java b/src/java/org/apache/fop/area/MainReference.java
index c9b50fd68..8dac9777f 100644
--- a/src/java/org/apache/fop/area/MainReference.java
+++ b/src/java/org/apache/fop/area/MainReference.java
@@ -32,6 +32,13 @@ public class MainReference extends Area {
private boolean isEmpty = true;
/**
+ * Constructor
+ */
+ public MainReference() {
+ addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE);
+ }
+
+ /**
* Add a span area to this area.
*
* @param span the span area to add
diff --git a/src/java/org/apache/fop/fo/FONode.java b/src/java/org/apache/fop/fo/FONode.java
index ba7832858..c0f3a2c92 100644
--- a/src/java/org/apache/fop/fo/FONode.java
+++ b/src/java/org/apache/fop/fo/FONode.java
@@ -292,8 +292,9 @@ public abstract class FONode implements Cloneable {
*/
protected void tooManyNodesError(Locator loc, String nsURI, String lName)
throws ValidationException {
- throw new ValidationException(errorText(loc) + getName() + ", only one "
- + getNodeString(nsURI, lName) + " may be declared.", loc);
+ throw new ValidationException(errorText(loc) + "For " + getName() +
+ ", only one " + getNodeString(nsURI, lName) + " may be declared.",
+ loc);
}
/**
@@ -305,8 +306,8 @@ public abstract class FONode implements Cloneable {
*/
protected void tooManyNodesError(Locator loc, String offendingNode)
throws ValidationException {
- throw new ValidationException(errorText(loc) + getName() + ", only one "
- + offendingNode + " may be declared.", loc);
+ throw new ValidationException(errorText(loc) + "For " + getName() +
+ ", only one " + offendingNode + " may be declared.", loc);
}
/**
diff --git a/src/java/org/apache/fop/fo/flow/Table.java b/src/java/org/apache/fop/fo/flow/Table.java
index 78272973e..df5249648 100644
--- a/src/java/org/apache/fop/fo/flow/Table.java
+++ b/src/java/org/apache/fop/fo/flow/Table.java
@@ -18,6 +18,8 @@
package org.apache.fop.fo.flow;
+import org.xml.sax.Locator;
+
import java.util.List;
import org.apache.fop.apps.FOPException;
@@ -25,6 +27,7 @@ import org.apache.fop.fo.FONode;
import org.apache.fop.fo.FObj;
import org.apache.fop.fo.PropertyList;
import org.apache.fop.fo.StaticPropertyList;
+import org.apache.fop.fo.ValidationException;
import org.apache.fop.fo.properties.CommonAccessibility;
import org.apache.fop.fo.properties.CommonAural;
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
@@ -73,7 +76,13 @@ public class Table extends FObj {
protected List columns = null;
private TableBody tableHeader = null;
private TableBody tableFooter = null;
-
+
+ /** used for validation */
+ private boolean tableColumnFound = false;
+ private boolean tableHeaderFound = false;
+ private boolean tableFooterFound = false;
+ private boolean tableBodyFound = false;
+
/**
* Default table-column used when no columns are specified. It is used
* to handle inheritance (especially visibility) and defaults properly. */
@@ -136,6 +145,55 @@ public class Table extends FObj {
checkId(id);
getFOEventHandler().startTable(this);
}
+
+ /**
+ * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
+ * XSL Content Model: (marker*,table-column*,table-header?,table-footer?,table-body+)
+ */
+ protected void validateChildNode(Locator loc, String nsURI, String localName)
+ throws ValidationException {
+ if (nsURI == FO_URI) {
+ if (localName.equals("marker")) {
+ if (tableColumnFound || tableHeaderFound || tableFooterFound
+ || tableBodyFound) {
+ nodesOutOfOrderError(loc, "fo:marker",
+ "(table-column*,table-header?,table-footer?,table-body+)");
+ }
+ } else if (localName.equals("table-column")) {
+ tableColumnFound = true;
+ if (tableHeaderFound || tableFooterFound || tableBodyFound) {
+ nodesOutOfOrderError(loc, "fo:table-column",
+ "(table-header?,table-footer?,table-body+)");
+ }
+ } else if (localName.equals("table-header")) {
+ if (tableHeaderFound) {
+ tooManyNodesError(loc, "table-header");
+ } else {
+ tableHeaderFound = true;
+ if (tableFooterFound || tableBodyFound) {
+ nodesOutOfOrderError(loc, "fo:table-header",
+ "(table-footer?,table-body+)");
+ }
+ }
+ } else if (localName.equals("table-footer")) {
+ if (tableFooterFound) {
+ tooManyNodesError(loc, "table-footer");
+ } else {
+ tableFooterFound = true;
+ if (tableBodyFound) {
+ nodesOutOfOrderError(loc, "fo:table-footer",
+ "(table-body+)");
+ }
+ }
+ } else if (localName.equals("table-body")) {
+ tableBodyFound = true;
+ } else {
+ invalidChildError(loc, nsURI, localName);
+ }
+ } else {
+ invalidChildError(loc, nsURI, localName);
+ }
+ }
/**
* @see org.apache.fop.fo.FONode#endOfNode
diff --git a/src/java/org/apache/fop/fo/flow/TableBody.java b/src/java/org/apache/fop/fo/flow/TableBody.java
index bf9aac835..da1dc92f9 100644
--- a/src/java/org/apache/fop/fo/flow/TableBody.java
+++ b/src/java/org/apache/fop/fo/flow/TableBody.java
@@ -102,7 +102,10 @@ public class TableBody extends FObj {
getParent().removeChild(this);
}
}
- convertCellsToRows();
+ if (tableCellsFound) {
+ convertCellsToRows();
+ }
+ savedPropertyList = null; //Release reference
}
/**
@@ -140,44 +143,35 @@ public class TableBody extends FObj {
/**
* If table-cells are used as direct children of a table-body|header|footer
- * they are replace in this method by proper table-rows.
+ * they are replaced in this method by proper table-rows.
* @throws FOPException if there's a problem binding the TableRows properties.
*/
private void convertCellsToRows() throws FOPException {
- try {
- if (childNodes == null
- || childNodes.size() == 0
- || childNodes.get(0) instanceof TableRow) {
- return;
+ //getLogger().debug("Converting cells to rows...");
+ List cells = (List)childNodes.clone();
+ 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;
}
- //getLogger().debug("Converting cells to rows...");
- List cells = (List)childNodes.clone();
- 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) {
+ row = new TableRow(this);
+ PropertyList pList = new StaticPropertyList(row, savedPropertyList);
+ pList.setWritingMode();
+ row.bind(pList);
}
- if (row != null) {
+ row.addReplacedCell(cell);
+ if (cell.endsRow()) {
childNodes.add(row);
+ row = null;
}
- } finally {
- savedPropertyList = null; //Release reference
+ }
+ if (row != null) {
+ childNodes.add(row);
}
}
diff --git a/src/java/org/apache/fop/fo/flow/TableFooter.java b/src/java/org/apache/fop/fo/flow/TableFooter.java
index 6db9242e8..09cba1cc3 100644
--- a/src/java/org/apache/fop/fo/flow/TableFooter.java
+++ b/src/java/org/apache/fop/fo/flow/TableFooter.java
@@ -19,11 +19,9 @@
package org.apache.fop.fo.flow;
// FOP
+import org.apache.fop.apps.FOPException;
import org.apache.fop.fo.FONode;
-import org.xml.sax.Locator;
-import org.apache.fop.apps.FOPException;
-import org.apache.fop.fo.ValidationException;
/**
* Class modelling the fo:table-footer object.
diff --git a/src/java/org/apache/fop/fo/flow/TableHeader.java b/src/java/org/apache/fop/fo/flow/TableHeader.java
index 0b61b524d..8aa222ec6 100644
--- a/src/java/org/apache/fop/fo/flow/TableHeader.java
+++ b/src/java/org/apache/fop/fo/flow/TableHeader.java
@@ -19,8 +19,10 @@
package org.apache.fop.fo.flow;
// FOP
+import org.apache.fop.apps.FOPException;
import org.apache.fop.fo.FONode;
+
/**
* Class modelling the fo:table-header object.
* @todo implement validateChildNode()
@@ -35,6 +37,24 @@ public class TableHeader extends TableBody {
}
/**
+ * @see org.apache.fop.fo.FONode#startOfNode
+ */
+ protected void startOfNode() throws FOPException {
+// getFOEventHandler().startHeader(this);
+ }
+
+ /**
+ * @see org.apache.fop.fo.FONode#endOfNode
+ */
+ protected void endOfNode() throws FOPException {
+// getFOEventHandler().endHeader(this);
+ if (!(tableRowsFound || tableCellsFound)) {
+ missingChildElementError("marker* (table-row+|table-cell+)");
+ }
+// convertCellsToRows();
+ }
+
+ /**
* @see org.apache.fop.fo.FObj#getName()
*/
public String getName() {
diff --git a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
index d7cb07fa3..890f09aff 100644
--- a/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
+++ b/src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java
@@ -704,9 +704,7 @@ public class PageSequenceLayoutManager extends AbstractLayoutManager {
}
private void createBodyMainReferenceArea() {
- MainReference mainRef = new MainReference();
- mainRef.addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE);
- curBody.setMainReference(mainRef);
+ curBody.setMainReference(new MainReference());
}
private Flow createFlow() {