Browse Source

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
tags/Root_Temp_KnuthStylePageBreaking
Glen Mazza 19 years ago
parent
commit
b667d1a700

+ 7
- 0
src/java/org/apache/fop/area/MainReference.java View File

@@ -31,6 +31,13 @@ public class MainReference extends Area {
private int width;
private boolean isEmpty = true;

/**
* Constructor
*/
public MainReference() {
addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE);
}
/**
* Add a span area to this area.
*

+ 5
- 4
src/java/org/apache/fop/fo/FONode.java View File

@@ -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);
}

/**

+ 59
- 1
src/java/org/apache/fop/fo/flow/Table.java View File

@@ -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

+ 26
- 32
src/java/org/apache/fop/fo/flow/TableBody.java View File

@@ -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);
}
}

+ 1
- 3
src/java/org/apache/fop/fo/flow/TableFooter.java View File

@@ -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.

+ 20
- 0
src/java/org/apache/fop/fo/flow/TableHeader.java View File

@@ -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()
@@ -34,6 +36,24 @@ public class TableHeader extends TableBody {
super(parent);
}

/**
* @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()
*/

+ 1
- 3
src/java/org/apache/fop/layoutmgr/PageSequenceLayoutManager.java View File

@@ -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() {

Loading…
Cancel
Save