]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Bugzilla #39607:
authorJeremias Maerki <jeremias@apache.org>
Thu, 18 May 2006 14:00:11 +0000 (14:00 +0000)
committerJeremias Maerki <jeremias@apache.org>
Thu, 18 May 2006 14:00:11 +0000 (14:00 +0000)
Bugfix for NPE in RTF library.
Submitted by: Julien AymĂ© <julien.ayme.at.gmail.com>

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@407553 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableRow.java
test/java/org/apache/fop/StandardTestSuite.java
test/java/org/apache/fop/render/rtf/Bug39607TestCase.java [new file with mode: 0644]
test/java/org/apache/fop/render/rtf/RichTextFormatTestSuite.java [new file with mode: 0644]

index 681ab9a8210080aff92e64f39f1d4554f21474f5..25e14d3e9c22902c1736bddecd028ce457b13f00 100644 (file)
@@ -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));
+                        }
                     }
                 }
                 
index ee3c5add8b07f66f724c7c59a6f0f66ce224735f..28d960446d4a5dd79e901662e2b842a306af15c5 100644 (file)
@@ -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 (file)
index 0000000..9c85373
--- /dev/null
@@ -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 (file)
index 0000000..5f90a40
--- /dev/null
@@ -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;
+    }
+}