From: Jeremias Maerki Date: Thu, 18 May 2006 14:00:11 +0000 (+0000) Subject: Bugzilla #39607: X-Git-Tag: fop-0_93~228 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f16ef429a49fa9ab4520e28d470d76c58967792b;p=xmlgraphics-fop.git Bugzilla #39607: Bugfix for NPE in RTF library. Submitted by: Julien Aymé git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@407553 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java index 681ab9a82..25e14d3e9 100644 --- a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java +++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java @@ -198,36 +198,38 @@ public class RtfTableRow extends RtfContainer implements ITableAttributes { // Adjust the cell's display attributes so the table's/row's borders // are drawn properly. - // get border attributes from table - if (index == 0) { - if (!rtfcell.getRtfAttributes().isSet(ITableAttributes.CELL_BORDER_LEFT)) { - rtfcell.getRtfAttributes().set(ITableAttributes.CELL_BORDER_LEFT, - (RtfAttributes) tableBorderAttributes.getValue( - ITableAttributes.CELL_BORDER_LEFT)); + if (tableBorderAttributes != null) { + // get border attributes from table + if (index == 0) { + String border = ITableAttributes.CELL_BORDER_LEFT; + if (!rtfcell.getRtfAttributes().isSet(border)) { + rtfcell.getRtfAttributes().set(border, + (RtfAttributes) tableBorderAttributes.getValue(border)); + } } - } - if (index == this.getChildCount() - 1) { - if (!rtfcell.getRtfAttributes().isSet(ITableAttributes.CELL_BORDER_RIGHT)) { - rtfcell.getRtfAttributes().set(ITableAttributes.CELL_BORDER_RIGHT, - (RtfAttributes) tableBorderAttributes.getValue( - ITableAttributes.CELL_BORDER_RIGHT)); + if (index == this.getChildCount() - 1) { + String border = ITableAttributes.CELL_BORDER_RIGHT; + if (!rtfcell.getRtfAttributes().isSet(border)) { + rtfcell.getRtfAttributes().set(border, + (RtfAttributes) tableBorderAttributes.getValue(border)); + } } - } - if (isFirstRow()) { - if (!rtfcell.getRtfAttributes().isSet(ITableAttributes.CELL_BORDER_TOP)) { - rtfcell.getRtfAttributes().set(ITableAttributes.CELL_BORDER_TOP, - (RtfAttributes) (RtfAttributes) tableBorderAttributes.getValue( - ITableAttributes.CELL_BORDER_TOP)); + if (isFirstRow()) { + String border = ITableAttributes.CELL_BORDER_TOP; + if (!rtfcell.getRtfAttributes().isSet(border)) { + rtfcell.getRtfAttributes().set(border, + (RtfAttributes) tableBorderAttributes.getValue(border)); + } } - } - if ((parentTable != null) && (parentTable.isHighestRow(id))) { - if (!rtfcell.getRtfAttributes().isSet(ITableAttributes.CELL_BORDER_BOTTOM)) { - rtfcell.getRtfAttributes().set(ITableAttributes.CELL_BORDER_BOTTOM, - (RtfAttributes) tableBorderAttributes.getValue( - ITableAttributes.CELL_BORDER_BOTTOM)); + if ((parentTable != null) && (parentTable.isHighestRow(id))) { + String border = ITableAttributes.CELL_BORDER_BOTTOM; + if (!rtfcell.getRtfAttributes().isSet(border)) { + rtfcell.getRtfAttributes().set(border, + (RtfAttributes) tableBorderAttributes.getValue(border)); + } } } diff --git a/test/java/org/apache/fop/StandardTestSuite.java b/test/java/org/apache/fop/StandardTestSuite.java index ee3c5add8..28d960446 100644 --- a/test/java/org/apache/fop/StandardTestSuite.java +++ b/test/java/org/apache/fop/StandardTestSuite.java @@ -19,6 +19,7 @@ package org.apache.fop; import org.apache.fop.render.pdf.PDFAConformanceTestCase; +import org.apache.fop.render.rtf.RichTextFormatTestSuite; import junit.framework.Test; import junit.framework.TestSuite; @@ -39,6 +40,7 @@ public class StandardTestSuite { suite.addTest(BasicDriverTestSuite.suite()); suite.addTest(UtilityCodeTestSuite.suite()); suite.addTest(new TestSuite(PDFAConformanceTestCase.class)); + suite.addTest(RichTextFormatTestSuite.suite()); //$JUnit-END$ return suite; } diff --git a/test/java/org/apache/fop/render/rtf/Bug39607TestCase.java b/test/java/org/apache/fop/render/rtf/Bug39607TestCase.java new file mode 100644 index 000000000..9c853735a --- /dev/null +++ b/test/java/org/apache/fop/render/rtf/Bug39607TestCase.java @@ -0,0 +1,64 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed 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.render.rtf; + +import java.io.StringWriter; + +import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfDocumentArea; +import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfFile; +import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfParagraph; +import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfSection; +import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTable; +import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableRow; + +import junit.framework.TestCase; + +/** + * Test for http://issues.apache.org/bugzilla/show_bug.cgi?id=39607 + */ +public class Bug39607TestCase extends TestCase { + + /** + * Test for the NPE describes in bug 39607 + * @throws Exception If an error occurs + */ + public void testForNPE() throws Exception { + StringWriter writer = new StringWriter(); + RtfFile f = new RtfFile(writer); + + RtfDocumentArea doc = f.startDocumentArea(); + + RtfSection section = doc.newSection(); + + RtfParagraph paragraph = section.newParagraph(); + paragraph.newText("Testing fop - rtf module - class RtfTableRow"); + paragraph.close(); + + RtfTable table = section.newTable(null); + RtfTableRow row = table.newTableRow(); + row.newTableCell(2000).newParagraph().newText("blah"); + row.newTableCell(5000).newParagraph().newText("doubleBlah"); + row.close(); + table.close(); + section.close(); + doc.close(); + f.flush(); + } + +} diff --git a/test/java/org/apache/fop/render/rtf/RichTextFormatTestSuite.java b/test/java/org/apache/fop/render/rtf/RichTextFormatTestSuite.java new file mode 100644 index 000000000..5f90a403c --- /dev/null +++ b/test/java/org/apache/fop/render/rtf/RichTextFormatTestSuite.java @@ -0,0 +1,41 @@ +/* + * Copyright 2006 The Apache Software Foundation. + * + * Licensed 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.render.rtf; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * Test suite for FOP's RTF library. + */ +public class RichTextFormatTestSuite { + + /** + * Builds the test suite + * @return the test suite + */ + public static Test suite() { + TestSuite suite = new TestSuite( + "Test suite for RTF library"); + //$JUnit-BEGIN$ + suite.addTest(new TestSuite(Bug39607TestCase.class)); + //$JUnit-END$ + return suite; + } +}