diff options
author | Adrian Cumiskey <acumiskey@apache.org> | 2008-06-21 16:10:03 +0000 |
---|---|---|
committer | Adrian Cumiskey <acumiskey@apache.org> | 2008-06-21 16:10:03 +0000 |
commit | 30d0f7a3e83bf0e2d7866ea623f64d6f8204a13e (patch) | |
tree | 092254d9437bd86b20ae305ace405fc7712b557e /src/java/org | |
parent | 4ae76120cfae1310834b6a7a4e50fac833eb81d8 (diff) | |
download | xmlgraphics-fop-30d0f7a3e83bf0e2d7866ea623f64d6f8204a13e.tar.gz xmlgraphics-fop-30d0f7a3e83bf0e2d7866ea623f64d6f8204a13e.zip |
Moved the contents of TableBody into a new abstract base class TablePart, which is now subclassed by TableBody, TableHeader and TableFooter.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@670217 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org')
23 files changed, 397 insertions, 330 deletions
diff --git a/src/java/org/apache/fop/fo/FOEventHandler.java b/src/java/org/apache/fop/fo/FOEventHandler.java index 880dd7868..90856d57a 100644 --- a/src/java/org/apache/fop/fo/FOEventHandler.java +++ b/src/java/org/apache/fop/fo/FOEventHandler.java @@ -40,6 +40,9 @@ import org.apache.fop.fo.flow.PageNumberCitation; import org.apache.fop.fo.flow.PageNumberCitationLast; import org.apache.fop.fo.flow.table.Table; import org.apache.fop.fo.flow.table.TableBody; +import org.apache.fop.fo.flow.table.TableFooter; +import org.apache.fop.fo.flow.table.TableHeader; +import org.apache.fop.fo.flow.table.TablePart; import org.apache.fop.fo.flow.table.TableCell; import org.apache.fop.fo.flow.table.TableColumn; import org.apache.fop.fo.flow.table.TableRow; @@ -257,44 +260,44 @@ public abstract class FOEventHandler { /** * - * @param th TableBody that is starting; + * @param header TableHeader that is starting; */ - public void startHeader(TableBody th) { + public void startHeader(TableHeader header) { } /** * - * @param th TableBody that is ending. + * @param header TableHeader that is ending. */ - public void endHeader(TableBody th) { + public void endHeader(TableHeader header) { } /** * - * @param tf TableFooter that is starting. + * @param footer TableFooter that is starting. */ - public void startFooter(TableBody tf) { + public void startFooter(TableFooter footer) { } /** * - * @param tf TableFooter that is ending. + * @param footer TableFooter that is ending. */ - public void endFooter(TableBody tf) { + public void endFooter(TableFooter footer) { } /** * - * @param tb TableBody that is starting. + * @param body TableBody that is starting. */ - public void startBody(TableBody tb) { + public void startBody(TableBody body) { } /** * - * @param tb TableBody that is ending. + * @param body TableBody that is ending. */ - public void endBody(TableBody tb) { + public void endBody(TableBody body) { } /** 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 5f998b956..771ec0c64 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; @@ -279,10 +279,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); @@ -404,12 +404,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; } 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..ee5024240 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,17 @@ * 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; /** * 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} @@ -72,200 +36,4 @@ public class TableBody extends TableCellContainer { 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 { - 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 { - super.startOfNode(); - getFOEventHandler().startBody(this); - } - - /** {@inheritDoc} */ - public void endOfNode() throws FOPException { - - if (!inMarker()) { - pendingSpans = null; - columnNumberManager = null; - } - - 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} */ - public String getLocalName() { - return "table-body"; - } - - /** - * {@inheritDoc} - * @return {@link org.apache.fop.fo.Constants#FO_TABLE_BODY} - */ - 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..2603ba8b4 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(); 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/TableFooter.java b/src/java/org/apache/fop/fo/flow/table/TableFooter.java index d05824e95..8f166b321 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} @@ -67,8 +67,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..5939fba73 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} @@ -66,8 +66,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..677a7a17c --- /dev/null +++ b/src/java/org/apache/fop/fo/flow/table/TablePart.java @@ -0,0 +1,274 @@ +/* + * 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; + + /** The last encountered table-row. */ + private TableRow lastRow; + + 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 { + 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 { + super.startOfNode(); + if (this instanceof TableHeader) { + getFOEventHandler().startHeader((TableHeader)this); + } else if (this instanceof TableFooter) { + getFOEventHandler().startFooter((TableFooter)this); + } else { + getFOEventHandler().startBody((TableBody)this); + } + } + + /** {@inheritDoc} */ + public void endOfNode() throws FOPException { + if (!inMarker()) { + pendingSpans = null; + columnNumberManager = null; + } + + if (this instanceof TableHeader) { + getFOEventHandler().endHeader((TableHeader)this); + } else if (this instanceof TableFooter) { + getFOEventHandler().endFooter((TableFooter)this); + } else { + getFOEventHandler().endBody((TableBody)this); + } + + 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; + 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} */ + public String getLocalName() { + return "table-body"; + } + + /** + * {@inheritDoc} + * @return {@link org.apache.fop.fo.Constants#FO_TABLE_BODY} + */ + public int getNameId() { + return FO_TABLE_BODY; + } + + /** + * @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..8b5fc6bd4 100644 --- a/src/java/org/apache/fop/fo/flow/table/TableRow.java +++ b/src/java/org/apache/fop/fo/flow/table/TableRow.java @@ -79,9 +79,9 @@ public class TableRow extends TableCellContainer { public void processNode(String elementName, Locator locator, Attributes attlist, PropertyList pList) throws FOPException { 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); } @@ -90,8 +90,8 @@ public class TableRow extends TableCellContainer { 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); } @@ -129,8 +129,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); diff --git a/src/java/org/apache/fop/layoutmgr/table/RowPainter.java b/src/java/org/apache/fop/layoutmgr/table/RowPainter.java index d432c7657..38f1a7b30 100644 --- a/src/java/org/apache/fop/layoutmgr/table/RowPainter.java +++ b/src/java/org/apache/fop/layoutmgr/table/RowPainter.java @@ -32,7 +32,7 @@ import org.apache.fop.fo.flow.table.ConditionalBorder; import org.apache.fop.fo.flow.table.EffRow; import org.apache.fop.fo.flow.table.GridUnit; import org.apache.fop.fo.flow.table.PrimaryGridUnit; -import org.apache.fop.fo.flow.table.TableBody; +import org.apache.fop.fo.flow.table.TablePart; import org.apache.fop.fo.properties.CommonBorderPaddingBackground; import org.apache.fop.layoutmgr.ElementListUtils; import org.apache.fop.layoutmgr.KnuthElement; @@ -94,7 +94,7 @@ class RowPainter { this.firstRowOnPageIndex = -1; } - void startTablePart(TableBody tablePart) { + void startTablePart(TablePart tablePart) { CommonBorderPaddingBackground background = tablePart.getCommonBorderPaddingBackground(); if (background.hasBackground()) { tablePartBackground = background; diff --git a/src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java b/src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java index 43b34e4b7..52915c008 100644 --- a/src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/table/TableCellLayoutManager.java @@ -31,7 +31,7 @@ import org.apache.fop.fo.flow.table.ConditionalBorder; import org.apache.fop.fo.flow.table.GridUnit; import org.apache.fop.fo.flow.table.PrimaryGridUnit; import org.apache.fop.fo.flow.table.Table; -import org.apache.fop.fo.flow.table.TableBody; +import org.apache.fop.fo.flow.table.TablePart; import org.apache.fop.fo.flow.table.TableCell; import org.apache.fop.fo.flow.table.TableColumn; import org.apache.fop.fo.flow.table.TableRow; @@ -439,7 +439,7 @@ public class TableCellLayoutManager extends BlockStackingLayoutManager -startIndent); } - TableBody body = primaryGridUnit.getTableBody(); + TablePart body = primaryGridUnit.getTablePart(); if (body.getCommonBorderPaddingBackground().hasBackground()) { painter.registerPartBackgroundArea( getBackgroundArea(paddingRectBPD, borderBeforeWidth)); diff --git a/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java b/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java index 9b4a03a67..80e904f8f 100644 --- a/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/table/TableContentLayoutManager.java @@ -19,7 +19,6 @@ package org.apache.fop.layoutmgr.table; -import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -35,7 +34,7 @@ import org.apache.fop.fo.FObj; import org.apache.fop.fo.flow.table.EffRow; import org.apache.fop.fo.flow.table.PrimaryGridUnit; import org.apache.fop.fo.flow.table.Table; -import org.apache.fop.fo.flow.table.TableBody; +import org.apache.fop.fo.flow.table.TablePart; import org.apache.fop.layoutmgr.BlockLevelLayoutManager; import org.apache.fop.layoutmgr.BreakElement; import org.apache.fop.layoutmgr.ElementListUtils; @@ -324,7 +323,7 @@ public class TableContentLayoutManager implements PercentBaseContext { this.usedBPD = 0; RowPainter painter = new RowPainter(this, layoutContext); - List tablePositions = new ArrayList(); + List tablePositions = new java.util.ArrayList(); List headerElements = null; List footerElements = null; Position firstPos = null; @@ -417,9 +416,9 @@ public class TableContentLayoutManager implements PercentBaseContext { } } - private void addHeaderFooterAreas(List elements, TableBody part, RowPainter painter, + private void addHeaderFooterAreas(List elements, TablePart part, RowPainter painter, boolean lastOnPage) { - List lst = new ArrayList(elements.size()); + List lst = new java.util.ArrayList(elements.size()); for (Iterator iter = new KnuthPossPosIter(elements); iter.hasNext();) { Position pos = (Position) iter.next(); /* @@ -446,32 +445,32 @@ public class TableContentLayoutManager implements PercentBaseContext { private void addBodyAreas(Iterator iterator, RowPainter painter, boolean lastOnPage) { painter.startBody(); - List lst = new ArrayList(); + List lst = new java.util.ArrayList(); TableContentPosition pos = (TableContentPosition) iterator.next(); boolean isFirstPos = pos.getFlag(TableContentPosition.FIRST_IN_ROWGROUP) && pos.getRow().getFlag(EffRow.FIRST_IN_PART); - TableBody body = pos.getTableBody(); + TablePart part = pos.getTablePart(); lst.add(pos); while (iterator.hasNext()) { pos = (TableContentPosition) iterator.next(); - if (pos.getTableBody() != body) { - addTablePartAreas(lst, painter, body, isFirstPos, true, false, false); + if (pos.getTablePart() != part) { + addTablePartAreas(lst, painter, part, isFirstPos, true, false, false); isFirstPos = true; lst.clear(); - body = pos.getTableBody(); + part = pos.getTablePart(); } lst.add(pos); } boolean isLastPos = pos.getFlag(TableContentPosition.LAST_IN_ROWGROUP) && pos.getRow().getFlag(EffRow.LAST_IN_PART); - addTablePartAreas(lst, painter, body, isFirstPos, isLastPos, true, lastOnPage); + addTablePartAreas(lst, painter, part, isFirstPos, isLastPos, true, lastOnPage); painter.endBody(); } /** * Adds the areas corresponding to a single fo:table-header/footer/body element. */ - private void addTablePartAreas(List positions, RowPainter painter, TableBody body, + private void addTablePartAreas(List positions, RowPainter painter, TablePart body, boolean isFirstPos, boolean isLastPos, boolean lastInBody, boolean lastOnPage) { getTableLM().getCurrentPV().addMarkers(body.getMarkers(), true, isFirstPos, isLastPos); diff --git a/src/java/org/apache/fop/layoutmgr/table/TableContentPosition.java b/src/java/org/apache/fop/layoutmgr/table/TableContentPosition.java index 260b8cfdf..62d25fcb1 100644 --- a/src/java/org/apache/fop/layoutmgr/table/TableContentPosition.java +++ b/src/java/org/apache/fop/layoutmgr/table/TableContentPosition.java @@ -22,7 +22,7 @@ package org.apache.fop.layoutmgr.table; import java.util.List; import org.apache.fop.fo.flow.table.EffRow; -import org.apache.fop.fo.flow.table.TableBody; +import org.apache.fop.fo.flow.table.TablePart; import org.apache.fop.layoutmgr.LayoutManager; import org.apache.fop.layoutmgr.Position; @@ -80,8 +80,8 @@ class TableContentPosition extends Position { return row; } - TableBody getTableBody() { - return ((CellPart) cellParts.get(0)).pgu.getTableBody(); + TablePart getTablePart() { + return ((CellPart) cellParts.get(0)).pgu.getTablePart(); } /** diff --git a/src/java/org/apache/fop/layoutmgr/table/TableRowIterator.java b/src/java/org/apache/fop/layoutmgr/table/TableRowIterator.java index 62e308c13..282cd0fd5 100644 --- a/src/java/org/apache/fop/layoutmgr/table/TableRowIterator.java +++ b/src/java/org/apache/fop/layoutmgr/table/TableRowIterator.java @@ -28,6 +28,7 @@ import org.apache.fop.fo.FONode.FONodeIterator; import org.apache.fop.fo.flow.table.EffRow; import org.apache.fop.fo.flow.table.Table; import org.apache.fop.fo.flow.table.TableBody; +import org.apache.fop.fo.flow.table.TablePart; /** @@ -69,7 +70,7 @@ public class TableRowIterator { case FOOTER: rowGroupsIter = table.getTableFooter().getRowGroups().iterator(); break; - default: + case BODY: List rowGroupsList = new LinkedList(); // TODO this is ugly for (FONodeIterator iter = table.getChildNodes(); iter.hasNext();) { @@ -79,6 +80,9 @@ public class TableRowIterator { } } rowGroupsIter = rowGroupsList.iterator(); + break; + default: + throw new IllegalArgumentException("Unrecognised TablePart: " + tablePart); } } diff --git a/src/java/org/apache/fop/render/rtf/RTFHandler.java b/src/java/org/apache/fop/render/rtf/RTFHandler.java index 05aade551..75f524f72 100644 --- a/src/java/org/apache/fop/render/rtf/RTFHandler.java +++ b/src/java/org/apache/fop/render/rtf/RTFHandler.java @@ -76,6 +76,8 @@ import org.apache.fop.fo.flow.ListItemLabel; import org.apache.fop.fo.flow.PageNumber; import org.apache.fop.fo.flow.table.Table; import org.apache.fop.fo.flow.table.TableBody; +import org.apache.fop.fo.flow.table.TableFooter; +import org.apache.fop.fo.flow.table.TablePart; import org.apache.fop.fo.flow.table.TableCell; import org.apache.fop.fo.flow.table.TableColumn; import org.apache.fop.fo.flow.table.TableHeader; @@ -611,25 +613,29 @@ public class RTFHandler extends FOEventHandler { /** * {@inheritDoc} */ - public void startHeader(TableBody th) { + public void startHeader(TableHeader header) { + startPart(header); } /** * {@inheritDoc} */ - public void endHeader(TableBody th) { + public void endHeader(TableHeader header) { + endPart(header); } /** * {@inheritDoc} */ - public void startFooter(TableBody tf) { + public void startFooter(TableFooter footer) { + startPart(footer); } /** * {@inheritDoc} */ - public void endFooter(TableBody tf) { + public void endFooter(TableFooter footer) { + endPart(footer); } /** @@ -687,31 +693,25 @@ public class RTFHandler extends FOEventHandler { } } - /** - * {@inheritDoc} - */ - public void startBody(TableBody tb) { + private void startPart(TablePart part) { if (bDefer) { return; } try { - RtfAttributes atts = TableAttributesConverter.convertTableBodyAttributes(tb); + RtfAttributes atts = TableAttributesConverter.convertTablePartAttributes(part); RtfTable tbl = (RtfTable)builderContext.getContainer(RtfTable.class, true, this); tbl.setHeaderAttribs(atts); } catch (IOException ioe) { handleIOTrouble(ioe); } catch (Exception e) { - log.error("startBody: " + e.getMessage()); + log.error("startPart: " + e.getMessage()); throw new RuntimeException(e.getMessage()); - } + } } - /** - * {@inheritDoc} - */ - public void endBody(TableBody tb) { + private void endPart(TablePart tb) { if (bDefer) { return; } @@ -722,9 +722,25 @@ public class RTFHandler extends FOEventHandler { } catch (IOException ioe) { handleIOTrouble(ioe); } catch (Exception e) { - log.error("endBody: " + e.getMessage()); + log.error("endPart: " + e.getMessage()); throw new RuntimeException(e.getMessage()); - } + } + } + + + /** + * {@inheritDoc} + */ + public void startBody(TableBody body) { + startPart(body); + } + + + /** + * {@inheritDoc} + */ + public void endBody(TableBody body) { + endPart(body); } /** @@ -1607,6 +1623,18 @@ public class RTFHandler extends FOEventHandler { } else { endTable( (Table) foNode); } + } else if (foNode instanceof TableHeader) { + if (bStart) { + startHeader( (TableHeader) foNode); + } else { + endHeader( (TableHeader) foNode); + } + } else if (foNode instanceof TableFooter) { + if (bStart) { + startFooter( (TableFooter) foNode); + } else { + endFooter( (TableFooter) foNode); + } } else if (foNode instanceof TableBody) { if (bStart) { startBody( (TableBody) foNode); diff --git a/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java b/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java index 677832418..a28d91d36 100644 --- a/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java +++ b/src/java/org/apache/fop/render/rtf/TableAttributesConverter.java @@ -24,12 +24,11 @@ import java.awt.Color; import org.apache.fop.apps.FOPException; import org.apache.fop.fo.Constants; import org.apache.fop.fo.flow.table.Table; -import org.apache.fop.fo.flow.table.TableBody; +import org.apache.fop.fo.flow.table.TablePart; import org.apache.fop.fo.flow.table.TableCell; import org.apache.fop.fo.flow.table.TableHeader; import org.apache.fop.fo.flow.table.TableRow; import org.apache.fop.fo.properties.CommonBorderPaddingBackground; -import org.apache.fop.fo.properties.FixedLength; import org.apache.fop.render.rtf.rtflib.rtfdoc.ITableAttributes; import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes; @@ -91,7 +90,7 @@ public final class TableAttributesConverter { * * @throws ConverterException On convertion error */ - static RtfAttributes convertTableBodyAttributes(TableBody fobj) + static RtfAttributes convertTablePartAttributes(TablePart part) throws FOPException { FOPRtfAttributes attrib = new FOPRtfAttributes(); return attrib; |