From 335f9a3502c0a8d39a95a599119e6053bc005d3d Mon Sep 17 00:00:00 2001 From: Vincent Hennebert Date: Tue, 6 Nov 2007 11:53:38 +0000 Subject: [PATCH] Added check for table-cells which span more rows than available in their parent element git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@592392 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/fo/flow/table/RowGroupBuilder.java | 18 ++--- .../apache/fop/fo/flow/table/TableBody.java | 23 +++++- .../apache/fop/fo/flow/table/TableFooter.java | 2 +- .../apache/fop/fo/flow/table/TableHeader.java | 2 +- status.xml | 4 + .../table/illegal-row-span_body_1.fo | 42 ++++++++++ .../table/illegal-row-span_body_2.fo | 66 +++++++++++++++ .../table/illegal-row-span_footer.fo | 75 +++++++++++++++++ .../table/illegal-row-span_header.fo | 81 +++++++++++++++++++ .../fop/fo/flow/table/ErrorCheckTestCase.java | 42 ++++++++++ .../fo/flow/table/IllegalRowSpanTestCase.java | 48 +++++++++++ .../fo/flow/table/TooManyColumnsTestCase.java | 16 ++-- 12 files changed, 393 insertions(+), 26 deletions(-) create mode 100644 test/fotree/unittests/table/illegal-row-span_body_1.fo create mode 100644 test/fotree/unittests/table/illegal-row-span_body_2.fo create mode 100644 test/fotree/unittests/table/illegal-row-span_footer.fo create mode 100644 test/fotree/unittests/table/illegal-row-span_header.fo create mode 100644 test/java/org/apache/fop/fo/flow/table/ErrorCheckTestCase.java create mode 100644 test/java/org/apache/fop/fo/flow/table/IllegalRowSpanTestCase.java 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 e321547a8..2f9a009c2 100644 --- a/src/java/org/apache/fop/fo/flow/table/RowGroupBuilder.java +++ b/src/java/org/apache/fop/fo/flow/table/RowGroupBuilder.java @@ -22,6 +22,7 @@ package org.apache.fop.fo.flow.table; import java.util.ArrayList; import java.util.List; +import org.apache.fop.fo.ValidationException; import org.apache.fop.layoutmgr.table.GridUnit; import org.apache.fop.layoutmgr.table.PrimaryGridUnit; @@ -113,19 +114,18 @@ abstract class RowGroupBuilder { } /** - * Finishes and records the last row-group of the given table-body, if any. If there - * is no fo:table-row and the last cell of the table-body didn't have ends-row="true", - * then the {@link signalNewRow} method has not been called and the last row group has - * yet to be recorded. + * Signals that the end of a table-header/footer/body has been reached. The current + * row-group is checked for emptiness. This row group builder is reset for handling + * further possible table parts. * - * @param tableBody + * @param tableBody the table part being finished + * @throws ValidationException if a cell is spanning further than the given table part */ - void finishLastRowGroup(TableBody tableBody) { + void signalEndOfPart(TableBody tableBody) throws ValidationException { if (rows.size() > 0) { - tableBody.addRowGroup(rows); + throw new ValidationException( + "A table-cell is spanning more rows than available in its parent element."); } - // Reset, in case this rowGroupBuilder is re-used for other - // table-header/footer/body initialize(); } 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 7671a9c4f..7e4ee2fb0 100644 --- a/src/java/org/apache/fop/fo/flow/table/TableBody.java +++ b/src/java/org/apache/fop/fo/flow/table/TableBody.java @@ -57,6 +57,8 @@ public class TableBody extends TableCellContainer { private boolean rowsStarted = false; + private boolean lastCellEndsRow = true; + private List rowGroups = new LinkedList(); /** @@ -124,7 +126,20 @@ public class TableBody extends TableCellContainer { getParent().removeChild(this); } } else { - getTable().getRowGroupBuilder().finishLastRowGroup(this); + finishLastRowGroup(); + } + } + + protected void finishLastRowGroup() throws ValidationException { + RowGroupBuilder rowGroupBuilder = getTable().getRowGroupBuilder(); + if (tableRowsFound || !lastCellEndsRow) { + rowGroupBuilder.signalRowEnd(this); + } + try { + rowGroupBuilder.signalEndOfPart(this); + } catch (ValidationException e) { + e.setLocator(locator); + throw e; } } @@ -179,7 +194,8 @@ public class TableBody extends TableCellContainer { rowsStarted = true; TableCell cell = (TableCell) child; addTableCellChild(cell, firstRow); - if (cell.endsRow()) { + lastCellEndsRow = cell.endsRow(); + if (lastCellEndsRow) { firstRow = false; columnNumberManager.prepareForNextRow(pendingSpans); getTable().getRowGroupBuilder().signalRowEnd(this); @@ -231,8 +247,7 @@ public class TableBody extends TableCellContainer { void signalNewRow() { if (rowsStarted) { firstRow = false; - TableCell previousCell = (TableCell) getChildNodes().lastNode(); - if (!previousCell.endsRow()) { + if (!lastCellEndsRow) { columnNumberManager.prepareForNextRow(pendingSpans); getTable().getRowGroupBuilder().signalRowEnd(this); } 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 fe3521318..a7ee21406 100644 --- a/src/java/org/apache/fop/fo/flow/table/TableFooter.java +++ b/src/java/org/apache/fop/fo/flow/table/TableFooter.java @@ -51,7 +51,7 @@ public class TableFooter extends TableBody { if (!(tableRowsFound || tableCellsFound)) { missingChildElementError("marker* (table-row+|table-cell+)"); } else { - getTable().getRowGroupBuilder().finishLastRowGroup(this); + finishLastRowGroup(); } // convertCellsToRows(); } 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 3cfb782c0..bc9d88952 100644 --- a/src/java/org/apache/fop/fo/flow/table/TableHeader.java +++ b/src/java/org/apache/fop/fo/flow/table/TableHeader.java @@ -51,7 +51,7 @@ public class TableHeader extends TableBody { if (!(tableRowsFound || tableCellsFound)) { missingChildElementError("marker* (table-row+|table-cell+)"); } else { - getTable().getRowGroupBuilder().finishLastRowGroup(this); + finishLastRowGroup(); } // convertCellsToRows(); } diff --git a/status.xml b/status.xml index e25c48f5e..5975d8725 100644 --- a/status.xml +++ b/status.xml @@ -28,6 +28,10 @@ + + Added check for table-cells which span more rows than available in their parent element + (table-header/footer/body). + Added support for fo:markers in fo:inline and fo:basic-link. diff --git a/test/fotree/unittests/table/illegal-row-span_body_1.fo b/test/fotree/unittests/table/illegal-row-span_body_1.fo new file mode 100644 index 000000000..edf5bbb36 --- /dev/null +++ b/test/fotree/unittests/table/illegal-row-span_body_1.fo @@ -0,0 +1,42 @@ + + + + + + + + + + + + The following table has a cell which spans further than its + containing table-body. + + + + + Cell 1.1 + + + Cell 1.2 + + + + + + diff --git a/test/fotree/unittests/table/illegal-row-span_body_2.fo b/test/fotree/unittests/table/illegal-row-span_body_2.fo new file mode 100644 index 000000000..14ec32dda --- /dev/null +++ b/test/fotree/unittests/table/illegal-row-span_body_2.fo @@ -0,0 +1,66 @@ + + + + + + + + + + + + The following table has a cell which spans further than its + containing table-body. + + + + + Cell 1.1 + + + Cell 1.2 + + + Cell 2.1 + + + Cell 2.2 + + + + + + Cell 3.1 + + + Cell 3.2 + + + + + Cell 4.1 + + + Cell 4.2 + + + + + + + diff --git a/test/fotree/unittests/table/illegal-row-span_footer.fo b/test/fotree/unittests/table/illegal-row-span_footer.fo new file mode 100644 index 000000000..ba88b6ddc --- /dev/null +++ b/test/fotree/unittests/table/illegal-row-span_footer.fo @@ -0,0 +1,75 @@ + + + + + + + + + + + + The following table has a cell which spans further than its + containing table-footer. + + + + + + Header 1.1 + + + Header 1.2 + + + + + + Footer 1.1 + + + Footer 1.2 + + + Footer 2.1 + + + Footer 2.2 + + + Footer 3.1 + + + + + Cell 1.1 + + + Cell 1.2 + + + Cell 2.1 + + + Cell 2.2 + + + + + + diff --git a/test/fotree/unittests/table/illegal-row-span_header.fo b/test/fotree/unittests/table/illegal-row-span_header.fo new file mode 100644 index 000000000..2fb9127c0 --- /dev/null +++ b/test/fotree/unittests/table/illegal-row-span_header.fo @@ -0,0 +1,81 @@ + + + + + + + + + + + + The following table has a cell which spans further than its + containing table-header. + + + + + + Header 1.1 + + + Header 1.2 + + + + + Header 2.2 + + + + + + Cell 1.1 + + + Cell 1.2 + + + Cell 2.1 + + + Cell 2.2 + + + + + + Cell 3.1 + + + Cell 3.2 + + + + + Cell 4.1 + + + Cell 4.2 + + + + + + + diff --git a/test/java/org/apache/fop/fo/flow/table/ErrorCheckTestCase.java b/test/java/org/apache/fop/fo/flow/table/ErrorCheckTestCase.java new file mode 100644 index 000000000..7327c3324 --- /dev/null +++ b/test/java/org/apache/fop/fo/flow/table/ErrorCheckTestCase.java @@ -0,0 +1,42 @@ +/* + * 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$ */ + +package org.apache.fop.fo.flow.table; + +import org.apache.fop.fo.ValidationException; + +/** + * Abstract class for testing erroneous files, checking that a ValidationException is thrown. + */ +abstract class ErrorCheckTestCase extends AbstractTableTestCase { + + public ErrorCheckTestCase() throws Exception { + super(); + } + + protected void launchTest(String filename) throws Exception { + try { + setUp(filename); + fail(); + } catch (ValidationException e) { + // TODO check location + } + } + +} diff --git a/test/java/org/apache/fop/fo/flow/table/IllegalRowSpanTestCase.java b/test/java/org/apache/fop/fo/flow/table/IllegalRowSpanTestCase.java new file mode 100644 index 000000000..447b14946 --- /dev/null +++ b/test/java/org/apache/fop/fo/flow/table/IllegalRowSpanTestCase.java @@ -0,0 +1,48 @@ +/* + * 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$ */ + +package org.apache.fop.fo.flow.table; + +/** + * Testcase checking that cells spanning further than their parent element aren't + * accepted. + */ +public class IllegalRowSpanTestCase extends ErrorCheckTestCase { + + public IllegalRowSpanTestCase() throws Exception { + super(); + } + + public void testBody1() throws Exception { + launchTest("table/illegal-row-span_body_1.fo"); + } + + public void testBody2() throws Exception { + launchTest("table/illegal-row-span_body_2.fo"); + } + + public void testHeader() throws Exception { + launchTest("table/illegal-row-span_header.fo"); + } + + public void testFooter() throws Exception { + launchTest("table/illegal-row-span_footer.fo"); + } + +} diff --git a/test/java/org/apache/fop/fo/flow/table/TooManyColumnsTestCase.java b/test/java/org/apache/fop/fo/flow/table/TooManyColumnsTestCase.java index c28f44ff7..c02f634cd 100644 --- a/test/java/org/apache/fop/fo/flow/table/TooManyColumnsTestCase.java +++ b/test/java/org/apache/fop/fo/flow/table/TooManyColumnsTestCase.java @@ -19,23 +19,13 @@ package org.apache.fop.fo.flow.table; -import org.apache.fop.fo.ValidationException; -public class TooManyColumnsTestCase extends AbstractTableTestCase { +public class TooManyColumnsTestCase extends ErrorCheckTestCase { public TooManyColumnsTestCase() throws Exception { super(); } - private void launchTest(String filename) throws Exception { - try { - setUp(filename); - fail(); - } catch (ValidationException e) { - // TODO check location - } - } - public void testBody1() throws Exception { launchTest("table/too-many-columns_body_1.fo"); } @@ -48,6 +38,10 @@ public class TooManyColumnsTestCase extends AbstractTableTestCase { launchTest("table/too-many-columns_body_3.fo"); } + public void testBody4() throws Exception { + launchTest("table/too-many-columns_body_4.fo"); + } + public void testHeader() throws Exception { launchTest("table/too-many-columns_header.fo"); } -- 2.39.5