pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1678052 - /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/type/PDActionGoTo.java
Date Wed, 06 May 2015 18:10:12 GMT
Author: tilman
Date: Wed May  6 18:10:12 2015
New Revision: 1678052

URL: http://svn.apache.org/r1678052
Log:
PDFBOX-2786: check GoTo action destination parameter

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/type/PDActionGoTo.java

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/type/PDActionGoTo.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/type/PDActionGoTo.java?rev=1678052&r1=1678051&r2=1678052&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/type/PDActionGoTo.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/type/PDActionGoTo.java
Wed May  6 18:10:12 2015
@@ -17,9 +17,13 @@
 package org.apache.pdfbox.pdmodel.interactive.action.type;
 
 import java.io.IOException;
+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.interactive.documentnavigation.destination.PDDestination;
+import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination;
 
 /**
  * This represents a go-to action that can be executed in a PDF document.
@@ -63,16 +67,32 @@ public class PDActionGoTo extends PDActi
      */
     public PDDestination getDestination() throws IOException
     {
-        return PDDestination.create( getCOSDictionary().getDictionaryObject( "D" ) );
+        return PDDestination.create(getCOSDictionary().getDictionaryObject(COSName.D));
     }
 
     /**
      * This will set the destination to jump to.
      *
      * @param d The destination.
+     * 
+     * @IllegalArgumentException if the destination is not a page dictionary object.
      */
     public void setDestination( PDDestination d )
     {
-        getCOSDictionary().setItem( "D", d );
+        if (d instanceof PDPageDestination)
+        {
+            PDPageDestination pageDest = (PDPageDestination) d;
+            COSArray destArray = pageDest.getCOSArray();
+            if (destArray.size() >= 1)
+            {
+                COSBase page = destArray.getObject(0);
+                if (!(page instanceof COSDictionary))
+                {
+                    throw new IllegalArgumentException("Destination of a GoTo action must
be "
+                            + "a page dictionary object");
+                }
+            }
+        }
+        getCOSDictionary().setItem(COSName.D, d);
     }
 }



Mime
View raw message