Author: ssteiner Date: Wed Jun 10 12:03:54 2020 New Revision: 1878710 URL: http://svn.apache.org/viewvc?rev=1878710&view=rev Log: FOP-2942: COSNull not supported error
Modified: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PageParentTreeFinder.java xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/StructureTreeMergerUtil.java xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PageParentTreeFinderTestCase.java xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/StructureTreeMergerUtilTestCase.java Modified: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PageParentTreeFinder.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PageParentTreeFinder.java?rev=1878710&r1=1878709&r2=1878710&view=diff ============================================================================== --- xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PageParentTreeFinder.java (original) +++ xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PageParentTreeFinder.java Wed Jun 10 12:03:54 2020 @@ -121,7 +121,9 @@ public class PageParentTreeFinder { if (keyFlag) { if (kid instanceof COSObject) { tempObject = ((COSObject)kid).getObject(); - return (COSArray)tempObject; + if (tempObject instanceof COSArray) { + return (COSArray) tempObject; + } } else if (kid instanceof COSArray) { return (COSArray)kid; } Modified: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/StructureTreeMergerUtil.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/StructureTreeMergerUtil.java?rev=1878710&r1=1878709&r2=1878710&view=diff ============================================================================== --- xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/StructureTreeMergerUtil.java (original) +++ xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/StructureTreeMergerUtil.java Wed Jun 10 12:03:54 2020 @@ -45,10 +45,12 @@ public final class StructureTreeMergerUt List<String> keys = new ArrayList<String>(); if (roleMap != null) { for (Entry<COSName, COSBase> entry : roleMap.entrySet()) { - String value = ((COSName)entry.getValue()).getName(); - String key = entry.getKey().getName(); - if (type.equals(value)) { - keys.add(key); + if (entry.getValue() instanceof COSName) { + String value = ((COSName) entry.getValue()).getName(); + String key = entry.getKey().getName(); + if (type.equals(value)) { + keys.add(key); + } } } } Modified: xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PageParentTreeFinderTestCase.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PageParentTreeFinderTestCase.java?rev=1878710&r1=1878709&r2=1878710&view=diff ============================================================================== --- xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PageParentTreeFinderTestCase.java (original) +++ xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PageParentTreeFinderTestCase.java Wed Jun 10 12:03:54 2020 @@ -27,6 +27,7 @@ import org.apache.pdfbox.cos.COSArray; import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSInteger; import org.apache.pdfbox.cos.COSName; +import org.apache.pdfbox.cos.COSNull; import org.apache.pdfbox.cos.COSObject; import org.apache.pdfbox.pdmodel.PDDocument; @@ -36,8 +37,6 @@ import org.apache.pdfbox.pdmodel.common. import org.apache.fop.render.pdf.pdfbox.PageParentTreeFinder; - - public class PageParentTreeFinderTestCase { private static final String LINK = "test/resources/linkTagged.pdf"; @@ -91,5 +90,19 @@ public class PageParentTreeFinderTestCas COSArray numList = new PageParentTreeFinder(doc.getPage(0)).getPageParentTreeArray(doc); Assert.assertEquals(numList.size(), 3); doc.close(); + } + + @Test + public void testCOSNull() throws IOException { + PDDocument doc = PDDocument.load(new File(LINK)); + PDNumberTreeNode srcNumberTreeNode = doc.getDocumentCatalog().getStructureTreeRoot().getParentTree(); + COSArray parentTree = (COSArray) srcNumberTreeNode.getCOSObject().getDictionaryObject(COSName.KIDS); + COSObject kidCOSObj = (COSObject) parentTree.get(0); + COSArray nums = (COSArray) kidCOSObj.getDictionaryObject(COSName.NUMS); + nums.add(0, COSInteger.ZERO); + nums.add(1, new COSObject(COSNull.NULL)); + COSArray numList = new PageParentTreeFinder(doc.getPage(0)).getPageParentTreeArray(doc); + Assert.assertEquals(numList.size(), 3); + doc.close(); } } Modified: xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/StructureTreeMergerUtilTestCase.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/StructureTreeMergerUtilTestCase.java?rev=1878710&r1=1878709&r2=1878710&view=diff ============================================================================== --- xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/StructureTreeMergerUtilTestCase.java (original) +++ xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/StructureTreeMergerUtilTestCase.java Wed Jun 10 12:03:54 2020 @@ -24,11 +24,10 @@ import org.junit.Test; import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSName; +import org.apache.pdfbox.cos.COSNull; import org.apache.fop.render.pdf.pdfbox.StructureTreeMergerUtil; - - public class StructureTreeMergerUtilTestCase { @Test @@ -47,4 +46,12 @@ public class StructureTreeMergerUtilTest String expected = "Icon"; Assert.assertEquals(test, expected); } + + @Test + public void testCOSNull() { + COSDictionary rolemap = new COSDictionary(); + rolemap.setItem(COSName.A, COSNull.NULL); + List<String> result = StructureTreeMergerUtil.findRoleMapKeyByValue(null, rolemap); + Assert.assertTrue(result.isEmpty()); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: fop-commits-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-commits-h...@xmlgraphics.apache.org