pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1818177 - in /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox: cos/COSName.java pdmodel/interactive/measurement/PDViewportDictionary.java
Date Thu, 14 Dec 2017 18:23:37 GMT
Author: tilman
Date: Thu Dec 14 18:23:37 2017
New Revision: 1818177

URL: http://svn.apache.org/viewvc?rev=1818177&view=rev
Log:
PDFBOX-2852: avoid potential classcastexception, use constants, make field final

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/measurement/PDViewportDictionary.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java?rev=1818177&r1=1818176&r2=1818177&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java Thu Dec 14
18:23:37 2017
@@ -343,6 +343,7 @@ public final class COSName extends COSBa
     public static final COSName MCID = new COSName("MCID");
     public static final COSName MDP = new COSName("MDP");
     public static final COSName MEDIA_BOX = new COSName("MediaBox");
+    public static final COSName MEASURE = new COSName("Measure");
     public static final COSName METADATA = new COSName("Metadata");
     public static final COSName MISSING_WIDTH = new COSName("MissingWidth");
     public static final COSName MIX = new COSName("Mix");

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/measurement/PDViewportDictionary.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/measurement/PDViewportDictionary.java?rev=1818177&r1=1818176&r2=1818177&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/measurement/PDViewportDictionary.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/measurement/PDViewportDictionary.java
Thu Dec 14 18:23:37 2017
@@ -17,6 +17,7 @@
 package org.apache.pdfbox.pdmodel.interactive.measurement;
 
 import org.apache.pdfbox.cos.COSArray;
+import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.common.COSObjectable;
@@ -30,11 +31,11 @@ public class PDViewportDictionary implem
 {
 
     /**
-     * The type of this annotation.
+     * The type of this object.
      */
     public static final String TYPE = "Viewport";
     
-    private COSDictionary viewportDictionary;
+    private final COSDictionary viewportDictionary;
 
     /**
      * Constructor.
@@ -83,10 +84,10 @@ public class PDViewportDictionary implem
      */
     public PDRectangle getBBox()
     {
-        COSArray bbox = (COSArray)this.getCOSObject().getDictionaryObject("BBox");
-        if (bbox != null)
+        COSBase bbox = this.getCOSObject().getDictionaryObject(COSName.BBOX);
+        if (bbox instanceof COSArray)
         {
-            return new PDRectangle(bbox);
+            return new PDRectangle((COSArray) bbox);
         }
         return null;
     }
@@ -98,7 +99,7 @@ public class PDViewportDictionary implem
      */
     public void setBBox(PDRectangle rectangle)
     {
-        this.getCOSObject().setItem("BBox", rectangle);
+        this.getCOSObject().setItem(COSName.BBOX, rectangle);
     }
 
     /**
@@ -128,10 +129,10 @@ public class PDViewportDictionary implem
      */
     public PDMeasureDictionary getMeasure()
     {
-        COSDictionary measure = (COSDictionary)this.getCOSObject().getDictionaryObject("Measure");
-        if (measure != null)
+        COSBase base = this.getCOSObject().getDictionaryObject(COSName.MEASURE);
+        if (base instanceof COSDictionary)
         {
-            return new PDMeasureDictionary(measure);
+            return new PDMeasureDictionary((COSDictionary) base);
         }
         return null;
     }
@@ -143,7 +144,7 @@ public class PDViewportDictionary implem
      */
     public void setMeasure(PDMeasureDictionary measure)
     {
-        this.getCOSObject().setItem("Measure", measure);
+        this.getCOSObject().setItem(COSName.MEASURE, measure);
     }
 
 }



Mime
View raw message