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 2016/02/15 18:24:53 UTC

svn commit: r1730576 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDPropBuildDataDict.java

Author: tilman
Date: Mon Feb 15 17:24:52 2016
New Revision: 1730576

URL: http://svn.apache.org/viewvc?rev=1730576&view=rev
Log:
PDFBOX-3231: Update to latest signature specification, as suggested by Petras

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDPropBuildDataDict.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDPropBuildDataDict.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDPropBuildDataDict.java?rev=1730576&r1=1730575&r2=1730576&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDPropBuildDataDict.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDPropBuildDataDict.java Mon Feb 15 17:24:52 2016
@@ -16,6 +16,8 @@
  */
 package org.apache.pdfbox.pdmodel.interactive.digitalsignature;
 
+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;
@@ -28,7 +30,7 @@ import org.apache.pdfbox.pdmodel.common.
  */
 public class PDPropBuildDataDict implements COSObjectable
 {
-    private COSDictionary dictionary;
+    private final COSDictionary dictionary;
 
     /**
      * Default constructor.
@@ -36,7 +38,8 @@ public class PDPropBuildDataDict impleme
     public PDPropBuildDataDict()
     {
         dictionary = new COSDictionary();
-        dictionary.setDirect(true); // the specification claim to use direct objects
+        // the specification claim to use direct objects
+        dictionary.setDirect(true);
     }
 
     /**
@@ -47,7 +50,8 @@ public class PDPropBuildDataDict impleme
     public PDPropBuildDataDict(COSDictionary dict)
     {
         dictionary = dict;
-        dictionary.setDirect(true); // the specification claim to use direct objects
+        // the specification claim to use direct objects
+        dictionary.setDirect(true);
     }
 
     /**
@@ -55,6 +59,7 @@ public class PDPropBuildDataDict impleme
      *
      * @return The COS dictionary that matches this Java object.
      */
+    @Override
     public COSDictionary getCOSObject()
     {
         return dictionary;
@@ -66,7 +71,7 @@ public class PDPropBuildDataDict impleme
      */
     public String getName()
     {
-        return dictionary.getString(COSName.NAME);
+        return dictionary.getNameAsString(COSName.NAME);
     }
 
     /**
@@ -80,7 +85,9 @@ public class PDPropBuildDataDict impleme
     }
 
     /**
-     * The build date of the software module.
+     * The build date of the software module. This string is normally produced by the compiler that
+     * is used to compile the software, for example using the Date and Time preprocessor flags. As
+     * such, this not likely to be in PDF Date format.
      *
      * @return the build date of the software module
      */
@@ -90,8 +97,7 @@ public class PDPropBuildDataDict impleme
     }
 
     /**
-     * The build date of the software module. This string is normally produced by the
-     * compiler under C++.
+     * The build date of the software module. This string is normally produced by the compiler.
      *
      * @param date is the build date of the software module
      */
@@ -101,6 +107,34 @@ public class PDPropBuildDataDict impleme
     }
 
     /**
+     * A text string indicating the version of the application implementation, as described by the
+     * <code>Name</code> attribute in this dictionary. When set by Adobe Acrobat, this entry is in
+     * the format: major.minor.micro (for example 7.0.7).
+     * <p>
+     * NOTE: Version value is specific for build data dictionary when used as the <code>App</code>
+     * dictionary in a build properties dictionary.
+     * </p>
+     *
+     * @param applicationVersion the application implementation version
+     */
+    public void setVersion(String applicationVersion)
+    {
+        dictionary.setString("REx", applicationVersion);
+    }
+
+    /**
+     * A text string indicating the version of the application implementation, as described by the
+     * <code>/Name</code> attribute in this dictionary. When set by Adobe Acrobat, this entry is in
+     * the format: major.minor.micro (for example 7.0.7).
+     *
+     * @return the application implementation version
+     */
+    public String getVersion()
+    {
+        return dictionary.getString("REx");
+    }
+
+    /**
      * The software module revision number, corresponding to the Date attribute.
      *
      * @return the revision of the software module
@@ -121,8 +155,11 @@ public class PDPropBuildDataDict impleme
     }
 
     /**
-     * The software module revision number, used to determinate the minimum version
-     * of software that is required in order to process this signature.
+     * The software module revision number, used to determinate the minimum version of software that
+     * is required in order to process this signature.
+     * <p>
+     * NOTE: this entry is deprecated for PDF v1.7
+     * </p>
      *
      * @return the revision of the software module
      */
@@ -132,8 +169,11 @@ public class PDPropBuildDataDict impleme
     }
 
     /**
-     * The software module revision number, used to determinate the minimum version
-     * of software that is required in order to process this signature.
+     * The software module revision number, used to determinate the minimum version of software that
+     * is required in order to process this signature.
+     * <p>
+     * NOTE: this entry is deprecated for PDF v1.7
+     * </p>
      *
      * @param revision is the software module revision number
      */
@@ -166,23 +206,52 @@ public class PDPropBuildDataDict impleme
     }
 
     /**
-     * Indicates the operation system. The format isn't specified yet.
+     * Indicates the operating system. The string format isn't specified yet. In its PDF Signature
+     * Build Dictionary Specifications Adobe differently specifies the value type to store operating
+     * system string:<ul>
+     * <li>Specification for PDF v1.5 specifies type as string;</li>
+     * <li>Specification for PDF v1.7 specifies type as array and provided example for
+     * <code>/PropBuild</code> dictionary indicate it as array of names.</li>
+     * </ul>
+     * This method supports both types to retrieve the value.
      *
-     * @return a the operation system id or name.
+     * @return the operating system id or name.
      */
     public String getOS()
     {
+        final COSBase cosBase = dictionary.getItem(COSName.OS);
+        if (cosBase instanceof COSArray)
+        {
+            return ((COSArray) cosBase).getName(0);
+        }
+        // PDF v1.5 style
         return dictionary.getString(COSName.OS);
     }
 
     /**
-     * Indicates the operation system. The format isn't specified yet.
+     * Indicates the operating system. The string format isn't specified yet. Value will be stored
+     * as first item of the array, as specified in PDF Signature Build Dictionary Specification for
+     * PDF v1.7.
      *
      * @param os is a string with the system id or name.
      */
     public void setOS(String os)
     {
-        dictionary.setString(COSName.OS, os);
+        if (os == null)
+        {
+            dictionary.removeItem(COSName.OS);
+        }
+        else
+        {
+            COSBase osArray = dictionary.getItem(COSName.OS);
+            if (!(osArray instanceof COSArray))
+            {
+                osArray = new COSArray();
+                osArray.setDirect(true);
+                dictionary.setItem(COSName.OS, osArray);
+            }
+            ((COSArray) osArray).add(0, COSName.getPDFName(os));
+        }
     }
 
     /**