You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2017/11/11 10:15:23 UTC

svn commit: r1814933 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureElement.java

Author: tilman
Date: Sat Nov 11 10:15:23 2017
New Revision: 1814933

URL: http://svn.apache.org/viewvc?rev=1814933&view=rev
Log:
PDFBOX-2852: avoid ClassCastException, simplify code

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureElement.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureElement.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureElement.java?rev=1814933&r1=1814932&r2=1814933&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureElement.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureElement.java Sat Nov 11 10:15:23 2017
@@ -24,6 +24,7 @@ import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSInteger;
 import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.cos.COSNumber;
 import org.apache.pdfbox.cos.COSObject;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.documentinterchange.markedcontent.PDMarkedContent;
@@ -90,12 +91,12 @@ public class PDStructureElement extends
      */
     public PDStructureNode getParent()
     {
-        COSDictionary p = (COSDictionary) this.getCOSObject().getDictionaryObject(COSName.P);
-        if (p == null)
+        COSBase base = this.getCOSObject().getDictionaryObject(COSName.P);
+        if (base instanceof COSDictionary)
         {
-            return null;
+            return PDStructureNode.create((COSDictionary) base);
         }
-        return PDStructureNode.create(p);
+        return null;
     }
 
     /**
@@ -137,12 +138,12 @@ public class PDStructureElement extends
      */
     public PDPage getPage()
     {
-        COSDictionary pageDic = (COSDictionary) this.getCOSObject().getDictionaryObject(COSName.PG);
-        if (pageDic == null)
+        COSBase base = this.getCOSObject().getDictionaryObject(COSName.PG);
+        if (base instanceof COSDictionary)
         {
-            return null;
+            return new PDPage((COSDictionary) base);
         }
-        return new PDPage(pageDic);
+        return null;
     }
 
     /**
@@ -163,8 +164,7 @@ public class PDStructureElement extends
      */
     public Revisions<PDAttributeObject> getAttributes()
     {
-        Revisions<PDAttributeObject> attributes =
-            new Revisions<>();
+        Revisions<PDAttributeObject> attributes = new Revisions<>();
         COSBase a = this.getCOSObject().getDictionaryObject(COSName.A);
         if (a instanceof COSArray)
         {
@@ -182,8 +182,7 @@ public class PDStructureElement extends
                 }
                 else if (item instanceof COSInteger)
                 {
-                    attributes.setRevisionNumber(ao,
-                        ((COSInteger) item).intValue());
+                    attributes.setRevisionNumber(ao, ((COSNumber) item).intValue());
                 }
             }
         }
@@ -352,8 +351,7 @@ public class PDStructureElement extends
                 }
                 else if (item instanceof COSInteger)
                 {
-                    classNames.setRevisionNumber(className,
-                        ((COSInteger) item).intValue());
+                    classNames.setRevisionNumber(className, ((COSNumber) item).intValue());
                 }
             }
         }