You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2013/03/10 13:28:18 UTC

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

Author: lehmi
Date: Sun Mar 10 12:28:18 2013
New Revision: 1454844

URL: http://svn.apache.org/r1454844
Log:
PDFBOX-1382 fixed getReferencedObject as proposed by Dominic Tubach

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

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDObjectReference.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDObjectReference.java?rev=1454844&r1=1454843&r2=1454844&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDObjectReference.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDObjectReference.java Sun Mar 10 12:28:18 2013
@@ -24,6 +24,7 @@ import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.common.COSObjectable;
 import org.apache.pdfbox.pdmodel.graphics.xobject.PDXObject;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationUnknown;
 
 /**
  * An object reference.
@@ -34,10 +35,18 @@ import org.apache.pdfbox.pdmodel.interac
 public class PDObjectReference implements COSObjectable
 {
 
+    /**
+     * TYPE of this object.
+     */
     public static final String TYPE = "OBJR";
 
     private COSDictionary dictionary;
 
+    /**
+     * Returns the underlying dictionary.
+     * 
+     * @return the dictionary
+     */
     protected COSDictionary getCOSDictionary()
     {
         return this.dictionary;
@@ -56,11 +65,11 @@ public class PDObjectReference implement
     /**
      * Constructor for an existing object reference.
      *
-     * @param dictionary The existing dictionary.
+     * @param theDictionary The existing dictionary.
      */
-    public PDObjectReference(COSDictionary dictionary)
+    public PDObjectReference(COSDictionary theDictionary)
     {
-        this.dictionary = dictionary;
+        dictionary = theDictionary;
     }
 
     /**
@@ -81,23 +90,35 @@ public class PDObjectReference implement
     public COSObjectable getReferencedObject()
     {
         COSBase obj = this.getCOSDictionary().getDictionaryObject(COSName.OBJ);
-        try
+        if (!(obj instanceof COSDictionary))
         {
-            return PDAnnotation.createAnnotation(obj);
+            return null;
         }
-        catch (IOException e)
+        try
         {
-            // No Annotation
-            try
+            PDXObject xobject = PDXObject.createXObject(obj);
+            if (xobject != null)
             {
-                return PDXObject.createXObject(obj);
+                return xobject;
             }
-            catch (IOException e1)
+            COSDictionary objDictionary  = (COSDictionary)obj;
+            PDAnnotation annotation = PDAnnotation.createAnnotation(obj);
+            /*
+             * COSName.TYPE is optional, so if annotation is of type unknown and
+             * COSName.TYPE is not COSName.ANNOT it still may be an annotation.
+             * TODO shall we return the annotation object instead of null?
+             * what else can be the target of the object reference?
+             */
+            if (!(annotation instanceof PDAnnotationUnknown) 
+                    || COSName.ANNOT.equals(objDictionary.getDictionaryObject(COSName.TYPE))) 
             {
-                // No XObject
-                // TODO what else can be the target of the object reference?
+                return annotation;
             }
         }
+        catch (IOException exception)
+        {
+            // this can only happen if the target is an XObject.
+        }
         return null;
     }