diff options
Diffstat (limited to 'src/java/org/apache/fop/fo/flow/table')
17 files changed, 339 insertions, 312 deletions
diff --git a/src/java/org/apache/fop/fo/flow/table/BorderResolver.java b/src/java/org/apache/fop/fo/flow/table/BorderResolver.java index 5322b08d3..82bdac845 100644 --- a/src/java/org/apache/fop/fo/flow/table/BorderResolver.java +++ b/src/java/org/apache/fop/fo/flow/table/BorderResolver.java @@ -40,7 +40,7 @@ interface BorderResolver { * * @param part the part that has started */ - void startPart(TableBody part); + void startPart(TablePart part); /** * Receives notification of the end of a table-header/footer/body. diff --git a/src/java/org/apache/fop/fo/flow/table/CollapsingBorderResolver.java b/src/java/org/apache/fop/fo/flow/table/CollapsingBorderResolver.java index 2d48380ee..3a887166a 100644 --- a/src/java/org/apache/fop/fo/flow/table/CollapsingBorderResolver.java +++ b/src/java/org/apache/fop/fo/flow/table/CollapsingBorderResolver.java @@ -73,7 +73,7 @@ class CollapsingBorderResolver implements BorderResolver { */ private abstract class Resolver { - protected TableBody tablePart; + protected TablePart tablePart; protected boolean firstInPart; @@ -177,7 +177,7 @@ class CollapsingBorderResolver implements BorderResolver { } } - void startPart(TableBody part) { + void startPart(TablePart part) { tablePart = part; firstInPart = true; borderStartTableAndBody = collapsingBorderModel.determineWinner(table.borderStart, @@ -415,8 +415,8 @@ class CollapsingBorderResolver implements BorderResolver { } /** {@inheritDoc} */ - public void startPart(TableBody part) { - if (part.isTableHeader()) { + public void startPart(TablePart part) { + if (part instanceof TableHeader) { delegate = new ResolverInHeader(); } else { if (leadingBorders == null || table.omitHeaderAtBreak()) { @@ -427,7 +427,7 @@ class CollapsingBorderResolver implements BorderResolver { leadingBorders.add(border); } } - if (part.isTableFooter()) { + if (part instanceof TableFooter) { resolverInFooter = new ResolverInFooter(); delegate = resolverInFooter; } else { diff --git a/src/java/org/apache/fop/fo/flow/table/FixedColRowGroupBuilder.java b/src/java/org/apache/fop/fo/flow/table/FixedColRowGroupBuilder.java index 0d24491d9..a7719528a 100644 --- a/src/java/org/apache/fop/fo/flow/table/FixedColRowGroupBuilder.java +++ b/src/java/org/apache/fop/fo/flow/table/FixedColRowGroupBuilder.java @@ -143,8 +143,8 @@ class FixedColRowGroupBuilder extends RowGroupBuilder { } /** {@inheritDoc} */ - void endRow(TableBody body) { - handleRowEnd(body); + void endRow(TablePart part) { + handleRowEnd(part); } private void handleRowEnd(TableCellContainer container) { @@ -172,7 +172,7 @@ class FixedColRowGroupBuilder extends RowGroupBuilder { } /** {@inheritDoc} */ - void startTablePart(TableBody part) { + void startTablePart(TablePart part) { firstInPart = true; borderResolver.startPart(part); } diff --git a/src/java/org/apache/fop/fo/flow/table/PrimaryGridUnit.java b/src/java/org/apache/fop/fo/flow/table/PrimaryGridUnit.java index 915208e2d..a4b064a53 100644 --- a/src/java/org/apache/fop/fo/flow/table/PrimaryGridUnit.java +++ b/src/java/org/apache/fop/fo/flow/table/PrimaryGridUnit.java @@ -78,12 +78,12 @@ public class PrimaryGridUnit extends GridUnit { * * @return the enclosing table part */ - public TableBody getTableBody() { + public TablePart getTablePart() { FONode node = cell.getParent(); if (node instanceof TableRow) { node = node.getParent(); } - return (TableBody) node; + return (TablePart) node; } public TableCellLayoutManager getCellLM() { diff --git a/src/java/org/apache/fop/fo/flow/table/RowGroupBuilder.java b/src/java/org/apache/fop/fo/flow/table/RowGroupBuilder.java index c954be711..9748a77aa 100644 --- a/src/java/org/apache/fop/fo/flow/table/RowGroupBuilder.java +++ b/src/java/org/apache/fop/fo/flow/table/RowGroupBuilder.java @@ -57,7 +57,7 @@ abstract class RowGroupBuilder { /** * Receives notification of the end of the current row. If the current row finishes - * the row group, the {@link TableBody#addRowGroup(List)} method of the parent table + * the row group, the {@link TablePart#addRowGroup(List)} method of the parent table * part will be called. */ abstract void endTableRow(); @@ -65,21 +65,21 @@ abstract class RowGroupBuilder { /** * Receives notification of the end of the current row, when the source contains no * fo:table-row element. If the current row finishes the row group, the - * {@link TableBody#addRowGroup(List)} method of the given table part will be called. + * {@link TablePart#addRowGroup(List)} method of the given table part will be called. * * <p>If the source does contain explicit fo:table-row elements, then the * {@link #endTableRow()} method will be called instead.</p> * * @param part the part containing the current row */ - abstract void endRow(TableBody part); + abstract void endRow(TablePart part); /** * Receives notification of the start of a table-header/footer/body. * * @param part the part being started */ - abstract void startTablePart(TableBody part); + abstract void startTablePart(TablePart part); /** * Receives notification of the end of a table-header/footer/body. The current diff --git a/src/java/org/apache/fop/fo/flow/table/SeparateBorderResolver.java b/src/java/org/apache/fop/fo/flow/table/SeparateBorderResolver.java index c6d46ecf5..afd05823b 100644 --- a/src/java/org/apache/fop/fo/flow/table/SeparateBorderResolver.java +++ b/src/java/org/apache/fop/fo/flow/table/SeparateBorderResolver.java @@ -31,7 +31,7 @@ class SeparateBorderResolver implements BorderResolver { } /** {@inheritDoc} */ - public void startPart(TableBody part) { + public void startPart(TablePart part) { } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/fo/flow/table/Table.java b/src/java/org/apache/fop/fo/flow/table/Table.java index 5b96a668e..9feb77c9c 100644 --- a/src/java/org/apache/fop/fo/flow/table/Table.java +++ b/src/java/org/apache/fop/fo/flow/table/Table.java @@ -76,8 +76,8 @@ public class Table extends TableFObj implements ColumnNumberManagerHolder { private ColumnNumberManager columnNumberManager = new ColumnNumberManager(); /** the table-header and -footer */ - private TableBody tableHeader = null; - private TableBody tableFooter = null; + private TableHeader tableHeader = null; + private TableFooter tableFooter = null; /** used for validation */ private boolean tableColumnFound = false; @@ -157,10 +157,8 @@ public class Table extends TableFObj implements ColumnNumberManagerHolder { this.propList = pList; } - /** - * {@inheritDoc} - */ - public void startOfNode() throws FOPException { + /** {@inheritDoc} */ + protected void startOfNode() throws FOPException { super.startOfNode(); getFOEventHandler().startTable(this); } @@ -200,7 +198,9 @@ public class Table extends TableFObj implements ColumnNumberManagerHolder { } else { tableFooterFound = true; if (tableBodyFound) { - nodesOutOfOrderError(loc, "fo:table-footer", "(table-body+)", true); + if (getUserAgent().validateStrictly()) { + nodesOutOfOrderError(loc, "fo:table-footer", "(table-body+)", true); + } if (!isSeparateBorderModel()) { TableEventProducer eventProducer = TableEventProducer.Provider.get( getUserAgent().getEventBroadcaster()); @@ -216,11 +216,15 @@ public class Table extends TableFObj implements ColumnNumberManagerHolder { } } - /** - * {@inheritDoc} - */ - public void endOfNode() throws FOPException { + /** {@inheritDoc} */ + protected void endOfNode() throws FOPException { + super.endOfNode(); + getFOEventHandler().endTable(this); + } + /** {@inheritDoc} */ + public void finalizeNode() throws FOPException { + if (!tableBodyFound) { missingChildElementError( "(marker*,table-column*,table-header?,table-footer?" @@ -242,13 +246,10 @@ public class Table extends TableFObj implements ColumnNumberManagerHolder { this.propList = null; rowGroupBuilder = null; } - getFOEventHandler().endTable(this); - + } - - /** - * {@inheritDoc} - */ + + /** {@inheritDoc} */ protected void addChildNode(FONode child) throws FOPException { int childId = child.getNameId(); @@ -277,10 +278,10 @@ public class Table extends TableFObj implements ColumnNumberManagerHolder { } switch (childId) { case FO_TABLE_FOOTER: - tableFooter = (TableBody) child; + tableFooter = (TableFooter) child; break; case FO_TABLE_HEADER: - tableHeader = (TableBody) child; + tableHeader = (TableHeader) child; break; default: super.addChildNode(child); @@ -402,12 +403,12 @@ public class Table extends TableFObj implements ColumnNumberManagerHolder { } /** @return the body for the table-header. */ - public TableBody getTableHeader() { + public TableHeader getTableHeader() { return tableHeader; } /** @return the body for the table-footer. */ - public TableBody getTableFooter() { + public TableFooter getTableFooter() { return tableFooter; } @@ -521,17 +522,17 @@ public class Table extends TableFObj implements ColumnNumberManagerHolder { return FO_TABLE; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public FONode clone(FONode parent, boolean removeChildren) throws FOPException { Table clone = (Table) super.clone(parent, removeChildren); - clone.columnsFinalized = false; if (removeChildren) { clone.columns = new ArrayList(); + clone.columnsFinalized = false; + clone.columnNumberManager = new ColumnNumberManager(); clone.tableHeader = null; clone.tableFooter = null; + clone.rowGroupBuilder = null; } return clone; } diff --git a/src/java/org/apache/fop/fo/flow/table/TableBody.java b/src/java/org/apache/fop/fo/flow/table/TableBody.java index b4e48d2e6..b4071e255 100644 --- a/src/java/org/apache/fop/fo/flow/table/TableBody.java +++ b/src/java/org/apache/fop/fo/flow/table/TableBody.java @@ -15,53 +15,18 @@ * limitations under the License. */ -/* $Id$ */ +/* $Id: $ */ package org.apache.fop.fo.flow.table; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -import org.xml.sax.Attributes; -import org.xml.sax.Locator; - -import org.apache.fop.apps.FOPException; import org.apache.fop.fo.FONode; -import org.apache.fop.fo.PropertyList; -import org.apache.fop.fo.ValidationException; -import org.apache.fop.fo.properties.CommonBorderPaddingBackground; +import org.apache.fop.apps.FOPException; /** * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_table-body"> * <code>fo:table-body</code></a> object. */ -public class TableBody extends TableCellContainer { - // The value of properties relevant for fo:table-body. - private CommonBorderPaddingBackground commonBorderPaddingBackground; - // Unused but valid items, commented out for performance: - // private CommonAccessibility commonAccessibility; - // private CommonAural commonAural; - // private CommonRelativePosition commonRelativePosition; - // private int visibility; - // End of property values - - /** - * used for validation - */ - protected boolean tableRowsFound = false; - protected boolean tableCellsFound = false; - - private boolean firstRow = true; - - private boolean rowsStarted = false; - - private boolean lastCellEndsRow = true; - - /** The last encountered table-row. */ - private TableRow lastRow; - - private List rowGroups = new LinkedList(); +public class TableBody extends TablePart { /** * Create a TableBody instance with the given {@link FONode} @@ -73,159 +38,15 @@ public class TableBody extends TableCellContainer { } /** {@inheritDoc} */ - public void bind(PropertyList pList) throws FOPException { - commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps(); - super.bind(pList); - } - - /** {@inheritDoc} */ - public void processNode(String elementName, Locator locator, - Attributes attlist, PropertyList pList) - throws FOPException { - if (!inMarker()) { - Table t = getTable(); - if (t.hasExplicitColumns()) { - int size = t.getNumberOfColumns(); - pendingSpans = new ArrayList(size); - for (int i = 0; i < size; i++) { - pendingSpans.add(null); - } - } else { - pendingSpans = new ArrayList(); - } - columnNumberManager = new ColumnNumberManager(); - } - super.processNode(elementName, locator, attlist, pList); - } - - /** {@inheritDoc} */ - public void startOfNode() throws FOPException { + protected void startOfNode() throws FOPException { super.startOfNode(); getFOEventHandler().startBody(this); } /** {@inheritDoc} */ - public void endOfNode() throws FOPException { - - if (!inMarker()) { - pendingSpans = null; - columnNumberManager = null; - } - + protected void endOfNode() throws FOPException { + super.endOfNode(); getFOEventHandler().endBody(this); - - if (!(tableRowsFound || tableCellsFound)) { - missingChildElementError("marker* (table-row+|table-cell+)", true); - getParent().removeChild(this); - } else { - finishLastRowGroup(); - } - } - - /** {@inheritDoc} */ - TableBody getTablePart() { - return this; - } - - protected void finishLastRowGroup() throws ValidationException { - if (!inMarker()) { - RowGroupBuilder rowGroupBuilder = getTable().getRowGroupBuilder(); - if (tableRowsFound) { - rowGroupBuilder.endTableRow(); - } else if (!lastCellEndsRow) { - rowGroupBuilder.endRow(this); - } - try { - rowGroupBuilder.endTablePart(); - } catch (ValidationException e) { - e.setLocator(locator); - throw e; - } - } - } - - /** - * {@inheritDoc} - * <br>XSL Content Model: marker* (table-row+|table-cell+) - */ - protected void validateChildNode(Locator loc, String nsURI, String localName) - throws ValidationException { - if (FO_URI.equals(nsURI)) { - if (localName.equals("marker")) { - if (tableRowsFound || tableCellsFound) { - nodesOutOfOrderError(loc, "fo:marker", "(table-row+|table-cell+)"); - } - } else if (localName.equals("table-row")) { - tableRowsFound = true; - if (tableCellsFound) { - TableEventProducer eventProducer = TableEventProducer.Provider.get( - getUserAgent().getEventBroadcaster()); - eventProducer.noMixRowsAndCells(this, getName(), getLocator()); - } - } else if (localName.equals("table-cell")) { - tableCellsFound = true; - if (tableRowsFound) { - TableEventProducer eventProducer = TableEventProducer.Provider.get( - getUserAgent().getEventBroadcaster()); - eventProducer.noMixRowsAndCells(this, getName(), getLocator()); - } - } else { - invalidChildError(loc, nsURI, localName); - } - } - } - - /** {@inheritDoc} */ - protected void addChildNode(FONode child) throws FOPException { - if (!inMarker()) { - switch (child.getNameId()) { - case FO_TABLE_ROW: - if (!rowsStarted) { - getTable().getRowGroupBuilder().startTablePart(this); - } else { - columnNumberManager.prepareForNextRow(pendingSpans); - getTable().getRowGroupBuilder().endTableRow(); - } - rowsStarted = true; - lastRow = (TableRow) child; - getTable().getRowGroupBuilder().startTableRow(lastRow); - break; - case FO_TABLE_CELL: - if (!rowsStarted) { - getTable().getRowGroupBuilder().startTablePart(this); - } - rowsStarted = true; - TableCell cell = (TableCell) child; - addTableCellChild(cell, firstRow); - lastCellEndsRow = cell.endsRow(); - if (lastCellEndsRow) { - firstRow = false; - columnNumberManager.prepareForNextRow(pendingSpans); - getTable().getRowGroupBuilder().endRow(this); - } - break; - default: - //nop - } - } - super.addChildNode(child); - } - - void addRowGroup(List rowGroup) { - rowGroups.add(rowGroup); - } - - public List getRowGroups() { - return rowGroups; - } - - /** - * Get the {@link CommonBorderPaddingBackground} instance attached - * to this TableBody. - * @return the {@link CommonBorderPaddingBackground} instance. - */ - public CommonBorderPaddingBackground getCommonBorderPaddingBackground() { - return commonBorderPaddingBackground; } /** {@inheritDoc} */ @@ -240,32 +61,4 @@ public class TableBody extends TableCellContainer { public int getNameId() { return FO_TABLE_BODY; } - - protected boolean isTableHeader() { - return false; - } - - protected boolean isTableFooter() { - return false; - } - - /** - * @param obj table row in question - * @return true if the given table row is the first row of this body. - */ - public boolean isFirst(TableRow obj) { - return (firstChild == null - || firstChild == obj); - } - - void signalNewRow() { - if (rowsStarted) { - firstRow = false; - if (!lastCellEndsRow) { - columnNumberManager.prepareForNextRow(pendingSpans); - getTable().getRowGroupBuilder().endRow(this); - } - } - } - } diff --git a/src/java/org/apache/fop/fo/flow/table/TableCell.java b/src/java/org/apache/fop/fo/flow/table/TableCell.java index 2781bf082..21da54128 100644 --- a/src/java/org/apache/fop/fo/flow/table/TableCell.java +++ b/src/java/org/apache/fop/fo/flow/table/TableCell.java @@ -81,7 +81,7 @@ public class TableCell extends TableFObj { startsRow = pList.get(PR_STARTS_ROW).getEnum(); // For properly computing columnNumber if (startsRow() && getParent().getNameId() != FO_TABLE_ROW) { - ((TableBody) getParent()).signalNewRow(); + ((TablePart) getParent()).signalNewRow(); } endsRow = pList.get(PR_ENDS_ROW).getEnum(); columnNumber = pList.get(PR_COLUMN_NUMBER).getNumeric().getValue(); @@ -91,17 +91,24 @@ public class TableCell extends TableFObj { } /** {@inheritDoc} */ - public void startOfNode() throws FOPException { + protected void startOfNode() throws FOPException { super.startOfNode(); getFOEventHandler().startCell(this); } /** * Make sure content model satisfied, if so then tell the - * FOEventHandler that we are at the end of the flow. + * FOEventHandler that we are at the end of the table-cell. * {@inheritDoc} */ - public void endOfNode() throws FOPException { + protected void endOfNode() throws FOPException { + super.endOfNode(); + getFOEventHandler().endCell(this); + } + + /** {@inheritDoc} */ + public void finalizeNode() throws FOPException { + if (!blockItemFound) { missingChildElementError("marker* (%block;)+", true); } @@ -111,9 +118,9 @@ public class TableCell extends TableFObj { getUserAgent().getEventBroadcaster()); eventProducer.startEndRowUnderTableRowWarning(this, getLocator()); } - getFOEventHandler().endCell(this); + } - + /** * {@inheritDoc} * <br>XSL Content Model: marker* (%block;)+ diff --git a/src/java/org/apache/fop/fo/flow/table/TableCellContainer.java b/src/java/org/apache/fop/fo/flow/table/TableCellContainer.java index de9f271b5..1d1a29b35 100644 --- a/src/java/org/apache/fop/fo/flow/table/TableCellContainer.java +++ b/src/java/org/apache/fop/fo/flow/table/TableCellContainer.java @@ -95,9 +95,9 @@ public abstract class TableCellContainer extends TableFObj implements ColumnNumb /** * Returns the enclosing table-header/footer/body of this container. * - * @return <code>this</code> for TableBody, or the parent element for TableRow + * @return <code>this</code> for TablePart, or the parent element for TableRow */ - abstract TableBody getTablePart(); + abstract TablePart getTablePart(); /** {@inheritDoc} */ public ColumnNumberManager getColumnNumberManager() { diff --git a/src/java/org/apache/fop/fo/flow/table/TableColumn.java b/src/java/org/apache/fop/fo/flow/table/TableColumn.java index 6916e090b..025f5a74f 100644 --- a/src/java/org/apache/fop/fo/flow/table/TableColumn.java +++ b/src/java/org/apache/fop/fo/flow/table/TableColumn.java @@ -239,7 +239,7 @@ public class TableColumn extends TableFObj { sb.append(" number-columns-spanned=") .append(getNumberColumnsSpanned()); } - sb.append(" column-width=").append(getColumnWidth()); + sb.append(" column-width=").append(((Property)getColumnWidth()).getString()); return sb.toString(); } diff --git a/src/java/org/apache/fop/fo/flow/table/TableFObj.java b/src/java/org/apache/fop/fo/flow/table/TableFObj.java index 016046ae2..370bb9de4 100644 --- a/src/java/org/apache/fop/fo/flow/table/TableFObj.java +++ b/src/java/org/apache/fop/fo/flow/table/TableFObj.java @@ -34,6 +34,8 @@ import org.apache.fop.fo.properties.NumberProperty; import org.apache.fop.fo.properties.Property; import org.apache.fop.fo.properties.PropertyMaker; import org.apache.fop.layoutmgr.table.CollapsingBorderModel; +import org.xml.sax.Locator; +import org.xml.sax.Attributes; /** * Common base class for table-related FOs @@ -207,8 +209,8 @@ public abstract class TableFObj extends FObj { } /** {@inheritDoc} */ - public void startOfNode() throws FOPException { - super.startOfNode(); + public void processNode(String elementName, Locator locator, Attributes attlist, PropertyList pList) throws FOPException { + super.processNode(elementName, locator, attlist, pList); Table table = getTable(); if (!inMarker() && !table.isSeparateBorderModel()) { collapsingBorderModel = CollapsingBorderModel.getBorderModelFor(table @@ -216,15 +218,7 @@ public abstract class TableFObj extends FObj { setCollapsedBorders(); } } - - /* - * TODO made public so that RetrieveMarker can access it. - */ - /** {@inheritDoc} */ - public void endOfNode() throws FOPException { - super.endOfNode(); - } - + /** * Prepares the borders of this element if the collapsing-border model is in use. * Conflict resolution with parent elements is done where applicable. diff --git a/src/java/org/apache/fop/fo/flow/table/TableFooter.java b/src/java/org/apache/fop/fo/flow/table/TableFooter.java index d05824e95..a89a2e431 100644 --- a/src/java/org/apache/fop/fo/flow/table/TableFooter.java +++ b/src/java/org/apache/fop/fo/flow/table/TableFooter.java @@ -28,7 +28,7 @@ import org.apache.fop.fo.FONode; * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_table-footer"> * <code>fo:table-footer</code></a> object. */ -public class TableFooter extends TableBody { +public class TableFooter extends TablePart { /** * Create a TableFooter instance with the given {@link FONode} @@ -41,17 +41,15 @@ public class TableFooter extends TableBody { } /** {@inheritDoc} */ - public void startOfNode() throws FOPException { + protected void startOfNode() throws FOPException { super.startOfNode(); + getFOEventHandler().startFooter(this); } /** {@inheritDoc} */ - public void endOfNode() throws FOPException { - if (!(tableRowsFound || tableCellsFound)) { - missingChildElementError("marker* (table-row+|table-cell+)"); - } else { - finishLastRowGroup(); - } + protected void endOfNode() throws FOPException { + super.endOfNode(); + getFOEventHandler().endFooter(this); } /** {@inheritDoc} */ @@ -67,8 +65,4 @@ public class TableFooter extends TableBody { return FO_TABLE_FOOTER; } - /** {@inheritDoc} */ - protected boolean isTableFooter() { - return true; - } } diff --git a/src/java/org/apache/fop/fo/flow/table/TableHeader.java b/src/java/org/apache/fop/fo/flow/table/TableHeader.java index 252ba1b8b..7f4173754 100644 --- a/src/java/org/apache/fop/fo/flow/table/TableHeader.java +++ b/src/java/org/apache/fop/fo/flow/table/TableHeader.java @@ -28,7 +28,7 @@ import org.apache.fop.fo.FONode; * Class modelling the <a href="http://www.w3.org/TR/xsl/#fo_table-header"> * <code>fo:table-header</code></a> object. */ -public class TableHeader extends TableBody { +public class TableHeader extends TablePart { /** * Create a TableHeader instance with the given {@link FONode} @@ -40,17 +40,15 @@ public class TableHeader extends TableBody { } /** {@inheritDoc} */ - public void startOfNode() throws FOPException { + protected void startOfNode() throws FOPException { super.startOfNode(); + getFOEventHandler().startHeader(this); } /** {@inheritDoc} */ - public void endOfNode() throws FOPException { - if (!(tableRowsFound || tableCellsFound)) { - missingChildElementError("marker* (table-row+|table-cell+)"); - } else { - finishLastRowGroup(); - } + protected void endOfNode() throws FOPException { + super.endOfNode(); + getFOEventHandler().endHeader(this); } /** {@inheritDoc} */ @@ -66,8 +64,4 @@ public class TableHeader extends TableBody { return FO_TABLE_HEADER; } - /** {@inheritDoc} */ - protected boolean isTableHeader() { - return true; - } } diff --git a/src/java/org/apache/fop/fo/flow/table/TablePart.java b/src/java/org/apache/fop/fo/flow/table/TablePart.java new file mode 100644 index 000000000..4d20db8c4 --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/table/TablePart.java @@ -0,0 +1,239 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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: TableBody.java 655614 2008-05-12 19:37:39Z vhennebert $ */ + +package org.apache.fop.fo.flow.table; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +import org.xml.sax.Attributes; +import org.xml.sax.Locator; + +import org.apache.fop.apps.FOPException; +import org.apache.fop.fo.FONode; +import org.apache.fop.fo.PropertyList; +import org.apache.fop.fo.ValidationException; +import org.apache.fop.fo.properties.CommonBorderPaddingBackground; + +/** + * An abstract base class modelling a TablePart + * (i.e. fo:table-header, fo:table-footer and fo:table-body). + */ +public abstract class TablePart extends TableCellContainer { + // The value of properties relevant for fo:table-body. + private CommonBorderPaddingBackground commonBorderPaddingBackground; + // Unused but valid items, commented out for performance: + // private CommonAccessibility commonAccessibility; + // private CommonAural commonAural; + // private CommonRelativePosition commonRelativePosition; + // private int visibility; + // End of property values + + /** + * used for validation + */ + protected boolean tableRowsFound = false; + protected boolean tableCellsFound = false; + + private boolean firstRow = true; + + private boolean rowsStarted = false; + + private boolean lastCellEndsRow = true; + + private List rowGroups = new LinkedList(); + + /** + * Create a TablePart instance with the given {@link FONode} + * as parent. + * @param parent FONode that is the parent of the object + */ + public TablePart(FONode parent) { + super(parent); + } + + /** {@inheritDoc} */ + public void bind(PropertyList pList) throws FOPException { + commonBorderPaddingBackground = pList.getBorderPaddingBackgroundProps(); + super.bind(pList); + } + + /** {@inheritDoc} */ + public void processNode(String elementName, Locator locator, + Attributes attlist, PropertyList pList) + throws FOPException { + + super.processNode(elementName, locator, attlist, pList); + if (!inMarker()) { + Table t = getTable(); + if (t.hasExplicitColumns()) { + int size = t.getNumberOfColumns(); + pendingSpans = new ArrayList(size); + for (int i = 0; i < size; i++) { + pendingSpans.add(null); + } + } else { + pendingSpans = new ArrayList(); + } + columnNumberManager = new ColumnNumberManager(); + } + + } + + /** {@inheritDoc} */ + public void finalizeNode() throws FOPException { + if (!inMarker()) { + pendingSpans = null; + columnNumberManager = null; + } + + if (!(tableRowsFound || tableCellsFound)) { + missingChildElementError("marker* (table-row+|table-cell+)", true); + getParent().removeChild(this); + } else { + finishLastRowGroup(); + } + } + + /** {@inheritDoc} */ + TablePart getTablePart() { + return this; + } + + protected void finishLastRowGroup() throws ValidationException { + if (!inMarker()) { + RowGroupBuilder rowGroupBuilder = getTable().getRowGroupBuilder(); + if (tableRowsFound) { + rowGroupBuilder.endTableRow(); + } else if (!lastCellEndsRow) { + rowGroupBuilder.endRow(this); + } + try { + rowGroupBuilder.endTablePart(); + } catch (ValidationException e) { + e.setLocator(locator); + throw e; + } + } + } + + /** + * {@inheritDoc} + * <br>XSL Content Model: marker* (table-row+|table-cell+) + */ + protected void validateChildNode(Locator loc, String nsURI, String localName) + throws ValidationException { + if (FO_URI.equals(nsURI)) { + if (localName.equals("marker")) { + if (tableRowsFound || tableCellsFound) { + nodesOutOfOrderError(loc, "fo:marker", "(table-row+|table-cell+)"); + } + } else if (localName.equals("table-row")) { + tableRowsFound = true; + if (tableCellsFound) { + TableEventProducer eventProducer = TableEventProducer.Provider.get( + getUserAgent().getEventBroadcaster()); + eventProducer.noMixRowsAndCells(this, getName(), getLocator()); + } + } else if (localName.equals("table-cell")) { + tableCellsFound = true; + if (tableRowsFound) { + TableEventProducer eventProducer = TableEventProducer.Provider.get( + getUserAgent().getEventBroadcaster()); + eventProducer.noMixRowsAndCells(this, getName(), getLocator()); + } + } else { + invalidChildError(loc, nsURI, localName); + } + } + } + + /** {@inheritDoc} */ + protected void addChildNode(FONode child) throws FOPException { + if (!inMarker()) { + switch (child.getNameId()) { + case FO_TABLE_ROW: + if (!rowsStarted) { + getTable().getRowGroupBuilder().startTablePart(this); + } else { + columnNumberManager.prepareForNextRow(pendingSpans); + getTable().getRowGroupBuilder().endTableRow(); + } + rowsStarted = true; + getTable().getRowGroupBuilder().startTableRow((TableRow)child); + break; + case FO_TABLE_CELL: + if (!rowsStarted) { + getTable().getRowGroupBuilder().startTablePart(this); + } + rowsStarted = true; + TableCell cell = (TableCell) child; + addTableCellChild(cell, firstRow); + lastCellEndsRow = cell.endsRow(); + if (lastCellEndsRow) { + firstRow = false; + columnNumberManager.prepareForNextRow(pendingSpans); + getTable().getRowGroupBuilder().endRow(this); + } + break; + default: + //nop + } + } + super.addChildNode(child); + } + + void addRowGroup(List rowGroup) { + rowGroups.add(rowGroup); + } + + public List getRowGroups() { + return rowGroups; + } + + /** + * Get the {@link CommonBorderPaddingBackground} instance attached + * to this TableBody. + * @return the {@link CommonBorderPaddingBackground} instance. + */ + public CommonBorderPaddingBackground getCommonBorderPaddingBackground() { + return commonBorderPaddingBackground; + } + + /** + * @param obj table row in question + * @return true if the given table row is the first row of this body. + */ + public boolean isFirst(TableRow obj) { + return (firstChild == null + || firstChild == obj); + } + + void signalNewRow() { + if (rowsStarted) { + firstRow = false; + if (!lastCellEndsRow) { + columnNumberManager.prepareForNextRow(pendingSpans); + getTable().getRowGroupBuilder().endRow(this); + } + } + } + +} diff --git a/src/java/org/apache/fop/fo/flow/table/TableRow.java b/src/java/org/apache/fop/fo/flow/table/TableRow.java index 3be794fbd..ac6eafc2f 100644 --- a/src/java/org/apache/fop/fo/flow/table/TableRow.java +++ b/src/java/org/apache/fop/fo/flow/table/TableRow.java @@ -78,32 +78,38 @@ public class TableRow extends TableCellContainer { /** {@inheritDoc} */ public void processNode(String elementName, Locator locator, Attributes attlist, PropertyList pList) throws FOPException { + super.processNode(elementName, locator, attlist, pList); if (!inMarker()) { - TableBody body = (TableBody) parent; - pendingSpans = body.pendingSpans; - columnNumberManager = body.columnNumberManager; + TablePart part = (TablePart) parent; + pendingSpans = part.pendingSpans; + columnNumberManager = part.columnNumberManager; } - super.processNode(elementName, locator, attlist, pList); } /** {@inheritDoc} */ protected void addChildNode(FONode child) throws FOPException { if (!inMarker()) { TableCell cell = (TableCell) child; - TableBody body = (TableBody) getParent(); - addTableCellChild(cell, body.isFirst(this)); + TablePart part = (TablePart) getParent(); + addTableCellChild(cell, part.isFirst(this)); } super.addChildNode(child); } /** {@inheritDoc} */ - public void startOfNode() throws FOPException { + protected void startOfNode() throws FOPException { super.startOfNode(); getFOEventHandler().startRow(this); } /** {@inheritDoc} */ - public void endOfNode() throws FOPException { + protected void endOfNode() throws FOPException { + super.endOfNode(); + getFOEventHandler().endRow(this); + } + + /** {@inheritDoc} */ + public void finalizeNode() throws FOPException { if (firstChild == null) { missingChildElementError("(table-cell+)"); } @@ -111,9 +117,8 @@ public class TableRow extends TableCellContainer { pendingSpans = null; columnNumberManager = null; } - getFOEventHandler().endRow(this); } - + /** * {@inheritDoc} String, String) * <br>XSL Content Model: (table-cell+) @@ -129,8 +134,8 @@ public class TableRow extends TableCellContainer { } /** {@inheritDoc} */ - TableBody getTablePart() { - return (TableBody) parent; + TablePart getTablePart() { + return (TablePart) parent; } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/fo/flow/table/VariableColRowGroupBuilder.java b/src/java/org/apache/fop/fo/flow/table/VariableColRowGroupBuilder.java index d59870f0a..23c16d1f2 100644 --- a/src/java/org/apache/fop/fo/flow/table/VariableColRowGroupBuilder.java +++ b/src/java/org/apache/fop/fo/flow/table/VariableColRowGroupBuilder.java @@ -82,7 +82,7 @@ class VariableColRowGroupBuilder extends RowGroupBuilder { } /** {@inheritDoc} */ - void endRow(final TableBody part) { + void endRow(final TablePart part) { events.add(new Event() { public void play(RowGroupBuilder rowGroupBuilder) { rowGroupBuilder.endRow(part); @@ -91,7 +91,7 @@ class VariableColRowGroupBuilder extends RowGroupBuilder { } /** {@inheritDoc} */ - void startTablePart(final TableBody part) { + void startTablePart(final TablePart part) { events.add(new Event() { public void play(RowGroupBuilder rowGroupBuilder) { rowGroupBuilder.startTablePart(part); |