Return-Path: X-Original-To: apmail-pdfbox-commits-archive@www.apache.org Delivered-To: apmail-pdfbox-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 392739A5C for ; Fri, 1 Mar 2013 16:34:27 +0000 (UTC) Received: (qmail 33038 invoked by uid 500); 1 Mar 2013 16:34:27 -0000 Delivered-To: apmail-pdfbox-commits-archive@pdfbox.apache.org Received: (qmail 33003 invoked by uid 500); 1 Mar 2013 16:34:27 -0000 Mailing-List: contact commits-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pdfbox.apache.org Delivered-To: mailing list commits@pdfbox.apache.org Received: (qmail 32992 invoked by uid 99); 1 Mar 2013 16:34:27 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Mar 2013 16:34:27 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_FILL_THIS_FORM_SHORT,T_FRT_STOCK2 X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 01 Mar 2013 16:34:19 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 031CC23889DE; Fri, 1 Mar 2013 16:33:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1451638 [2/2] - in /pdfbox/trunk: examples/ examples/src/main/java/org/apache/pdfbox/examples/signature/ pdfbox/src/main/java/org/apache/pdfbox/cos/ pdfbox/src/main/java/org/apache/pdfbox/pdfparser/ pdfbox/src/main/java/org/apache/pdfbox/p... Date: Fri, 01 Mar 2013 16:33:56 -0000 To: commits@pdfbox.apache.org From: lehmi@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130301163358.031CC23889DE@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/filespecification/PDComplexFileSpecification.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/filespecification/PDComplexFileSpecification.java?rev=1451638&r1=1451637&r2=1451638&view=diff ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/filespecification/PDComplexFileSpecification.java (original) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/filespecification/PDComplexFileSpecification.java Fri Mar 1 16:33:56 2013 @@ -18,6 +18,7 @@ package org.apache.pdfbox.pdmodel.common import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSDictionary; +import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.cos.COSStream; /** @@ -36,7 +37,7 @@ public class PDComplexFileSpecification public PDComplexFileSpecification() { fs = new COSDictionary(); - fs.setName( "Type", "Filespec" ); + fs.setItem( COSName.TYPE, COSName.FILESPEC ); } /** @@ -70,13 +71,56 @@ public class PDComplexFileSpecification } /** + *

Preferred method for getting the filename. + * It will determinate the recommended file name.

+ *

First of all we try to get the unicode filename if it exist. + * If it doesn't exist we take a look at the DOS, MAC UNIX filenames. + * If no one exist the required F entry will be returned.

+ * + * @return The preferred file name. + */ + public String getFilename() + { + if (getUnicodeFile() != null) + { + return getUnicodeFile(); + } + else if (getFileDos() != null) + { + return getFileDos(); + } + else if (getFileMac() != null) + { + return getFileMac(); + } + else if (getFileUnix() != null) + { + return getFileUnix(); + } + else + { + return getFile(); + } + } + + /** + * This will get the unicode file name. + * + * @return The file name. + */ + public String getUnicodeFile() + { + return fs.getString(COSName.UF); + } + + /** * This will get the file name. * * @return The file name. */ public String getFile() { - return fs.getString( "F" ); + return fs.getString( COSName.F ); } /** @@ -86,7 +130,7 @@ public class PDComplexFileSpecification */ public void setFile( String file ) { - fs.setString( "F", file ); + fs.setString( COSName.F, file ); } /** @@ -96,7 +140,7 @@ public class PDComplexFileSpecification */ public String getFileDos() { - return fs.getString( "DOS" ); + return fs.getString( COSName.DOS ); } /** @@ -106,7 +150,7 @@ public class PDComplexFileSpecification */ public void setFileDos( String file ) { - fs.setString( "DOS", file ); + fs.setString( COSName.DOS, file ); } /** @@ -116,7 +160,7 @@ public class PDComplexFileSpecification */ public String getFileMac() { - return fs.getString( "Mac" ); + return fs.getString( COSName.MAC ); } /** @@ -126,7 +170,7 @@ public class PDComplexFileSpecification */ public void setFileMac( String file ) { - fs.setString( "Mac", file ); + fs.setString( COSName.MAC, file ); } /** @@ -136,7 +180,7 @@ public class PDComplexFileSpecification */ public String getFileUnix() { - return fs.getString( "Unix" ); + return fs.getString( COSName.UNIX ); } /** @@ -146,7 +190,7 @@ public class PDComplexFileSpecification */ public void setFileUnix( String file ) { - fs.setString( "Unix", file ); + fs.setString( COSName.UNIX, file ); } /** @@ -157,7 +201,7 @@ public class PDComplexFileSpecification */ public void setVolatile( boolean fileIsVolatile ) { - fs.setBoolean( "V", fileIsVolatile ); + fs.setBoolean( COSName.V, fileIsVolatile ); } /** @@ -167,7 +211,7 @@ public class PDComplexFileSpecification */ public boolean isVolatile() { - return fs.getBoolean( "V", false ); + return fs.getBoolean( COSName.V, false ); } /** @@ -193,15 +237,15 @@ public class PDComplexFileSpecification */ public void setEmbeddedFile( PDEmbeddedFile file ) { - COSDictionary ef = (COSDictionary)fs.getDictionaryObject( "EF" ); + COSDictionary ef = (COSDictionary)fs.getDictionaryObject( COSName.EF ); if( ef == null && file != null ) { ef = new COSDictionary(); - fs.setItem( "EF", ef ); + fs.setItem( COSName.EF, ef ); } if( ef != null ) { - ef.setItem( "F", file ); + ef.setItem( COSName.F, file ); } } @@ -228,15 +272,15 @@ public class PDComplexFileSpecification */ public void setEmbeddedFileDos( PDEmbeddedFile file ) { - COSDictionary ef = (COSDictionary)fs.getDictionaryObject( "DOS" ); + COSDictionary ef = (COSDictionary)fs.getDictionaryObject( COSName.DOS ); if( ef == null && file != null ) { ef = new COSDictionary(); - fs.setItem( "EF", ef ); + fs.setItem( COSName.EF, ef ); } if( ef != null ) { - ef.setItem( "DOS", file ); + ef.setItem( COSName.DOS, file ); } } @@ -263,15 +307,15 @@ public class PDComplexFileSpecification */ public void setEmbeddedFileMac( PDEmbeddedFile file ) { - COSDictionary ef = (COSDictionary)fs.getDictionaryObject( "Mac" ); + COSDictionary ef = (COSDictionary)fs.getDictionaryObject( COSName.MAC ); if( ef == null && file != null ) { ef = new COSDictionary(); - fs.setItem( "EF", ef ); + fs.setItem( COSName.EF, ef ); } if( ef != null ) { - ef.setItem( "Mac", file ); + ef.setItem( COSName.MAC, file ); } } @@ -298,15 +342,16 @@ public class PDComplexFileSpecification */ public void setEmbeddedFileUnix( PDEmbeddedFile file ) { - COSDictionary ef = (COSDictionary)fs.getDictionaryObject( "Unix" ); + COSDictionary ef = (COSDictionary)fs.getDictionaryObject( COSName.UNIX ); if( ef == null && file != null ) { ef = new COSDictionary(); - fs.setItem( "EF", ef ); + fs.setItem( COSName.EF, ef ); } if( ef != null ) { - ef.setItem( "Unix", file ); + ef.setItem( COSName.UNIX, file ); } } } + Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDPropBuild.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDPropBuild.java?rev=1451638&view=auto ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDPropBuild.java (added) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDPropBuild.java Fri Mar 1 16:33:56 2013 @@ -0,0 +1,162 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pdfbox.pdmodel.interactive.digitalsignature; + +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; + +/** + *

This represents a pdf signature build dictionary as specified in + * + * http://partners.adobe.com/public/developer/en/acrobat/Acrobat_Signature_BuildDict.pdf

+ * + *

The signature build properties dictionary provides signature properties for the software + * application that was used to create the signature.

+ * + * @author Thomas Chojecki + * @version $Revision: 1.1 $ + */ +public class PDPropBuild implements COSObjectable +{ + + private COSDictionary dictionary; + + /** + * Default constructor. + */ + public PDPropBuild() + { + dictionary = new COSDictionary(); + dictionary.setDirect(true); // the specification claim to use direct objects + } + + /** + * Constructor. + * + * @param dict The signature dictionary. + */ + public PDPropBuild(COSDictionary dict) + { + dictionary = dict; + dictionary.setDirect(true); // the specification claim to use direct objects + } + + /** + * Convert this standard java object to a COS object. + * + * @return The cos object that matches this Java object. + */ + public COSBase getCOSObject() + { + return getDictionary(); + } + + /** + * Convert this standard java object to a COS dictionary. + * + * @return The COS dictionary that matches this Java object. + */ + public COSDictionary getDictionary() + { + return dictionary; + } + + /** + * A build data dictionary for the signature handler that was + * used to create the parent signature. + * + * @return the Filter as PDPropBuildFilter object + */ + public PDPropBuildDataDict getFilter() + { + PDPropBuildDataDict filter = null; + COSDictionary filterDic = (COSDictionary)dictionary.getDictionaryObject(COSName.FILTER); + if (filterDic != null) + { + filter = new PDPropBuildDataDict(filterDic); + } + return filter; + } + + /** + * Set the build data dictionary for the signature handler. + * This entry is optional but is highly recommended for the signatures. + * + * @param filter is the PDPropBuildFilter + */ + public void setPDPropBuildFilter(PDPropBuildDataDict filter) + { + dictionary.setItem(COSName.FILTER, filter); + } + + /** + * A build data dictionary for the PubSec software module + * that was used to create the parent signature. + * + * @return the PubSec as PDPropBuildPubSec object + */ + public PDPropBuildDataDict getPubSec() + { + PDPropBuildDataDict pubSec = null; + COSDictionary pubSecDic = (COSDictionary)dictionary.getDictionaryObject(COSName.PUB_SEC); + if (pubSecDic != null) + { + pubSec = new PDPropBuildDataDict(pubSecDic); + } + return pubSec; + } + + /** + * Set the build data dictionary for the PubSec Software module. + * + * @param pubSec is the PDPropBuildPubSec + */ + public void setPDPropBuildPubSec(PDPropBuildDataDict pubSec) + { + dictionary.setItem(COSName.PUB_SEC, pubSec); + } + + /** + * A build data dictionary for the viewing application software + * module that was used to create the parent signature. + * + * @return the App as PDPropBuildApp object + */ + public PDPropBuildDataDict getApp() + { + PDPropBuildDataDict app = null; + COSDictionary appDic = (COSDictionary)dictionary.getDictionaryObject(COSName.APP); + if (appDic != null) + { + app = new PDPropBuildDataDict(appDic); + } + return app; + } + + /** + * Set the build data dictionary for the viewing application + * software module. + * + * @param app is the PDPropBuildApp + */ + public void setPDPropBuildApp(PDPropBuildDataDict app) + { + dictionary.setItem(COSName.APP, app); + } +} Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDPropBuild.java ------------------------------------------------------------------------------ svn:eol-style = native Added: 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=1451638&view=auto ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDPropBuildDataDict.java (added) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDPropBuildDataDict.java Fri Mar 1 16:33:56 2013 @@ -0,0 +1,248 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pdfbox.pdmodel.interactive.digitalsignature; + +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; + +/** + *

This represents the general property dictionaries from the build property dictionary.

+ * + * @see PDPropBuild + * @author Thomas Chojecki + * @version $Revision: 1.1 $ + */ +public class PDPropBuildDataDict implements COSObjectable +{ + + private COSDictionary dictionary; + + /** + * Default constructor. + */ + public PDPropBuildDataDict() + { + dictionary = new COSDictionary(); + dictionary.setDirect(true); // the specification claim to use direct objects + } + + /** + * Constructor. + * + * @param dict The signature dictionary. + */ + public PDPropBuildDataDict(COSDictionary dict) + { + dictionary = dict; + dictionary.setDirect(true); // the specification claim to use direct objects + } + + + /** + * Convert this standard java object to a COS object. + * + * @return The cos object that matches this Java object. + */ + public COSBase getCOSObject() + { + return getDictionary(); + } + + /** + * Convert this standard java object to a COS dictionary. + * + * @return The COS dictionary that matches this Java object. + */ + public COSDictionary getDictionary() + { + return dictionary; + } + + /** + * The name of the software module that was used to create the signature. + * @return the name of the software module + */ + public String getName() + { + return dictionary.getString(COSName.NAME); + } + + /** + * The name of the software module that was used to create the signature. + * + * @param name is the name of the software module + */ + public void setName(String name) + { + dictionary.setString(COSName.NAME, name); + } + + /** + * The build date of the software module. + * + * @return the build date of the software module + */ + public String getDate() + { + return dictionary.getString(COSName.DATE); + } + + /** + * The build date of the software module. This string is normally produced by the + * compiler under C++. + * + * @param date is the build date of the software module + */ + public void setDate(String date) + { + dictionary.setString(COSName.DATE, date); + } + + /** + * The software module revision number, corresponding to the Date attribute. + * + * @return the revision of the software module + */ + public long getRevision() + { + return dictionary.getLong(COSName.R); + } + + /** + * The software module revision number, corresponding to the Date attribute. + * + * @param revision is the software module revision number + */ + public void setRevision(long revision) + { + dictionary.setLong(COSName.R, revision); + } + + /** + * The software module revision number, used to determinate the minimum version + * of software that is required in order to process this signature. + * + * @return the revision of the software module + */ + public long getMinimumRevision() + { + return dictionary.getLong(COSName.V); + } + + /** + * The software module revision number, used to determinate the minimum version + * of software that is required in order to process this signature. + * + * @param revision is the software module revision number + */ + public void setMinimumRevision(long revision) + { + dictionary.setLong(COSName.V, revision); + } + + /** + * A flag that can be used by the signature handler or software module to + * indicate that this signature was created with unrelease software. + * + * @return true if the software module or signature handler was a pre release. + */ + public boolean getPreRelease() + { + return dictionary.getBoolean(COSName.PRE_RELEASE, false); + } + + /** + * A flag that can be used by the signature handler or software module to + * indicate that this signature was created with unrelease software. + * + * @param preRelease is true if the signature was created with a unrelease + * software, otherwise false. + */ + public void setPreRelease(boolean preRelease) + { + dictionary.setBoolean(COSName.PRE_RELEASE, preRelease); + } + + /** + * Indicates the operation system. The format isn't specified yet. + * + * @return a the operation system id or name. + */ + public String getOS() + { + return dictionary.getString(COSName.OS); + } + + /** + * Indicates the operation system. The format isn't specified yet. + * + * @param os is a string with the system id or name. + */ + public void setOS(String os) + { + dictionary.setString(COSName.OS, os); + } + + /** + * If there is a LegalPDF dictionary in the catalog + * of the PDF file and the NonEmbeddedFonts attribute in this dictionary + * has a non zero value, and the viewing application has a preference + * set to suppress the display of this warning then the value of this + * attribute will be set to true. + * + * @return true if NonEFontNoWarn is set to true + */ + public boolean getNonEFontNoWarn() + { + return dictionary.getBoolean(COSName.NON_EFONT_NO_WARN, true); + } + + /* + * setNonEFontNoWarn missing. Maybe not needed or should be self + * implemented. + * + * Documentation says: + * (Optional; PDF 1.5) If there is a LegalPDF dictionary in the catalog + * of the PDF file and the NonEmbeddedFonts attribute in this dictionary + * has a non zero value, and the viewing application has a preference + * set to suppress the display of this warning then the value of this + * attribute will be set to true. + */ + + /** + * If true, the application was in trusted mode when signing took place. + * + * @return true if the application was in trusted mode while signing. + * default: false + */ + public boolean getTrustedMode() + { + return dictionary.getBoolean(COSName.TRUSTED_MODE, false); + } + + /** + * If true, the application was in trusted mode when signing took place. + * + * @param trustedMode true if the application is in trusted mode. + */ + public void setTrustedMode(boolean trustedMode) + { + dictionary.setBoolean(COSName.TRUSTED_MODE, trustedMode); + } +} Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDPropBuildDataDict.java ------------------------------------------------------------------------------ svn:eol-style = native Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDSeedValue.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDSeedValue.java?rev=1451638&view=auto ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDSeedValue.java (added) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDSeedValue.java Fri Mar 1 16:33:56 2013 @@ -0,0 +1,575 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pdfbox.pdmodel.interactive.digitalsignature; + +import java.util.ArrayList; +import java.util.List; + +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.COSArrayList; +import org.apache.pdfbox.pdmodel.common.COSObjectable; +import org.apache.pdfbox.util.BitFlagHelper; + +/** + * This represents a pdf signature seed value dictionary. + * + * @author Thomas Chojecki + * @version $Revision: 1.1 $ + */ +public class PDSeedValue implements COSObjectable +{ + + /** + * A Ff flag. + */ + public static final int FLAG_FILTER = 1; + + /** + * A Ff flag. + */ + public static final int FLAG_SUBFILTER = 1 << 1; + + /** + * A Ff flag. + */ + public static final int FLAG_V = 1 << 2; + + /** + * A Ff flag. + */ + public static final int FLAG_REASON = 1 << 3; + + /** + * A Ff flag. + */ + public static final int FLAG_LEGAL_ATTESTATION = 1 << 4; + + /** + * A Ff flag. + */ + public static final int FLAG_ADD_REV_INFO = 1 << 5; + + /** + * A Ff flag. + */ + public static final int FLAG_DIGEST_METHOD = 1 << 6; + + private COSDictionary dictionary; + + /** + * Default constructor. + */ + public PDSeedValue() + { + dictionary = new COSDictionary(); + dictionary.setItem(COSName.TYPE, COSName.SV); + dictionary.setDirect(true); // the specification claim to use direct objects + } + + /** + * Constructor. + * + * @param dict The signature dictionary. + */ + public PDSeedValue(COSDictionary dict) + { + dictionary = dict; + dictionary.setDirect(true); // the specification claim to use direct objects + } + + + /** + * Convert this standard java object to a COS object. + * + * @return The cos object that matches this Java object. + */ + public COSBase getCOSObject() + { + return getDictionary(); + } + + /** + * Convert this standard java object to a COS dictionary. + * + * @return The COS dictionary that matches this Java object. + */ + public COSDictionary getDictionary() + { + return dictionary; + } + + /** + * + * @return true if the Filter is required + */ + public boolean isFilterRequired() + { + return BitFlagHelper.getFlag(getDictionary(), COSName.FF, FLAG_FILTER); + } + + /** + * set true if the filter shall be required. + * + * @param flag if true, the specified Filter shall be used when signing. + */ + public void setFilterRequired(boolean flag) + { + BitFlagHelper.setFlag(getDictionary(), COSName.FF, FLAG_FILTER, flag); + } + + /** + * + * @return true if the SubFilter is required + */ + public boolean isSubFilterRequired() + { + return BitFlagHelper.getFlag(getDictionary(), COSName.FF, FLAG_SUBFILTER); + } + + /** + * set true if the subfilter shall be required. + * + * @param flag if true, the first supported SubFilter in the array shall be used when signing. + */ + public void setSubFilterRequired(boolean flag) + { + BitFlagHelper.setFlag(getDictionary(), COSName.FF, FLAG_SUBFILTER, flag); + } + + /** + * + * @return true if the DigestMethod is required + */ + public boolean isDigestMethodRequired() + { + return BitFlagHelper.getFlag(getDictionary(), COSName.FF, FLAG_DIGEST_METHOD); + } + + /** + * set true if the DigestMethod shall be required. + * + * @param flag if true, one digest from the array shall be used. + */ + public void setDigestMethodRequired(boolean flag) + { + BitFlagHelper.setFlag(getDictionary(), COSName.FF, FLAG_DIGEST_METHOD, flag); + } + + /** + * + * @return true if the V entry is required + */ + public boolean isVRequired() + { + return BitFlagHelper.getFlag(getDictionary(), COSName.FF, FLAG_V); + } + + /** + * set true if the V entry shall be required. + * + * @param flag if true, the V entry shall be used. + */ + public void setVRequired(boolean flag) + { + BitFlagHelper.setFlag(getDictionary(), COSName.FF, FLAG_V, flag); + } + + /** + * + * @return true if the Reason is required + */ + public boolean isReasonRequired() + { + return BitFlagHelper.getFlag(getDictionary(), COSName.FF, FLAG_REASON); + } + + /** + * set true if the Reason shall be required. + * + * @param flag if true, the Reason entry shall be used. + */ + public void setReasonRequired(boolean flag) + { + BitFlagHelper.setFlag(getDictionary(), COSName.FF, FLAG_REASON, flag); + } + + /** + * + * @return true if the LegalAttestation is required + */ + public boolean isLegalAttestationRequired() + { + return BitFlagHelper.getFlag(getDictionary(), COSName.FF, FLAG_LEGAL_ATTESTATION); + } + + /** + * set true if the LegalAttestation shall be required. + * + * @param flag if true, the LegalAttestation entry shall be used. + */ + public void setLegalAttestationRequired(boolean flag) + { + BitFlagHelper.setFlag(getDictionary(), COSName.FF, FLAG_LEGAL_ATTESTATION, flag); + } + + /** + * + * @return true if the AddRevInfo is required + */ + public boolean isAddRevInfoRequired() + { + return BitFlagHelper.getFlag(getDictionary(), COSName.FF, FLAG_ADD_REV_INFO); + } + + /** + * set true if the AddRevInfo shall be required. + * + * @param flag if true, the AddRevInfo shall be used. + */ + public void setAddRevInfoRequired(boolean flag) + { + BitFlagHelper.setFlag(getDictionary(), COSName.FF, FLAG_ADD_REV_INFO, flag); + } + + /** + * If Filter is not null and the {@link #isFilterRequired()} indicates this entry is a + * required constraint, then the signature handler specified by this entry shall be used when + * signing; otherwise, signing shall not take place. If {@link #isFilterRequired()} indicates + * that this is an optional constraint, this handler may be used if it is available. If it is + * not available, a different handler may be used instead. + * + * @return the filter that shall be used by the signature handler + */ + public String getFilter() + { + return dictionary.getNameAsString(COSName.FILTER); + } + + /** + * (Optional) The signature handler that shall be used to sign the signature field. + * + * @param filter is the filter that shall be used by the signature handler + */ + public void setFilter(COSName filter) + { + dictionary.setItem(COSName.FILTER, filter); + } + + /** + * If SubFilter is not null and the {@link #isSubFilterRequired()} indicates this + * entry is a required constraint, then the first matching encodings shall be used when + * signing; otherwise, signing shall not take place. If {@link #isSubFilterRequired()} + * indicates that this is an optional constraint, then the first matching encoding shall + * be used if it is available. If it is not available, a different encoding may be used + * instead. + * + * @return the subfilter that shall be used by the signature handler + */ + public List getSubFilter() + { + List retval = null; + COSArray fields = (COSArray)dictionary.getDictionaryObject(COSName.SUBFILTER); + + if (fields != null) + { + List actuals = new ArrayList(); + for ( int i = 0; i < fields.size(); i++ ) + { + String element = fields.getName(i); + if (element != null) + { + if (element != null) + { + actuals.add(element); + } + } + } + retval = new COSArrayList(actuals, fields); + } + return retval; + } + + /** + * (Optional) An array of names indicating encodings to use when signing. The first name + * in the array that matches an encoding supported by the signature handler shall be the + * encoding that is actually used for signing. + * + * @param subfilter is the name that shall be used for encoding + */ + public void setSubFilter(List subfilter) + { + dictionary.setItem(COSName.SUBFILTER, COSArrayList.converterToCOSArray(subfilter)); + } + + /** + * An array of names indicating acceptable digest algorithms to use when + * signing. The value shall be one of SHA1, SHA256, SHA384, + * SHA512, RIPEMD160. The default value is implementation-specific. + * + * @return the digest method that shall be used by the signature handler + */ + public List getDigestMethod() + { + List retval = null; + COSArray fields = (COSArray)dictionary.getDictionaryObject(COSName.DIGEST_METHOD); + + if (fields != null) + { + List actuals = new ArrayList(); + for ( int i = 0; i < fields.size(); i++ ) + { + String element = fields.getName(i); + if (element != null) + { + if (element != null) + { + actuals.add(element); + } + } + } + retval = new COSArrayList(actuals, fields); + } + return retval; + } + + /** + *

(Optional, PDF 1.7) An array of names indicating acceptable digest + * algorithms to use when signing. The value shall be one of SHA1, + * SHA256, SHA384, SHA512, RIPEMD160. The default + * value is implementation-specific.

+ * + *

This property is only applicable if the digital credential signing contains RSA + * public/privat keys

+ * + * @param digestMethod is a list of possible names of the digests, that should be + * used for signing. + */ + public void setDigestMethod(List digestMethod) + { + // integrity check + for ( COSName cosName : digestMethod ) + { + if (!(cosName.equals(COSName.DIGEST_SHA1) + || cosName.equals(COSName.DIGEST_SHA256) + || cosName.equals(COSName.DIGEST_SHA384) + || cosName.equals(COSName.DIGEST_SHA512) + || cosName.equals(COSName.DIGEST_RIPEMD160))) + { + throw new IllegalArgumentException("Specified digest " + cosName.getName() + " isn't allowed."); + } + } + dictionary.setItem(COSName.DIGEST_METHOD, COSArrayList.converterToCOSArray(digestMethod)); + } + + /** + * The minimum required capability of the signature field seed value + * dictionary parser. A value of 1 specifies that the parser shall be able to + * recognize all seed value dictionary entries in a PDF 1.5 file. A value of 2 + * specifies that it shall be able to recognize all seed value dictionary entries + * specified. + * + * @return the minimum required capability of the signature field seed value + * dictionary parser + */ + public float getV() + { + return dictionary.getFloat(COSName.V); + } + + /** + * (Optional) The minimum required capability of the signature field seed value + * dictionary parser. A value of 1 specifies that the parser shall be able to + * recognize all seed value dictionary entries in a PDF 1.5 file. A value of 2 + * specifies that it shall be able to recognize all seed value dictionary entries + * specified. + * + * @param minimumRequiredCapability is the minimum required capability of the + * signature field seed value dictionary parser + */ + public void setV(float minimumRequiredCapability) + { + dictionary.setFloat(COSName.V, minimumRequiredCapability); + } + + /** + * If the Reasons array is provided and {@link #isReasonRequired()} indicates that + * Reasons is a required constraint, one of the reasons in the array shall be used + * for the signature dictionary; otherwise signing shall not take place. If the + * {@link #isReasonRequired()} indicates Reasons is an optional constraint, one of + * the reasons in the array may be chose or a custom reason can be provided. + * + * @return the reasons that should be used by the signature handler + */ + public List getReasons() + { + List retval = null; + COSArray fields = (COSArray)dictionary.getDictionaryObject(COSName.REASONS); + + if (fields != null) + { + List actuals = new ArrayList(); + for ( int i = 0; i < fields.size(); i++ ) + { + String element = fields.getString(i); + if (element != null) + { + if (element != null) + { + actuals.add(element); + } + } + } + retval = new COSArrayList(actuals, fields); + } + return retval; + } + + /** + * (Optional) An array of text strings that specifying possible reasons for signing + * a document. If specified, the reasons supplied in this entry replace those used + * by conforming products. + * + * @param reasons is a list of possible text string that specifying possible reasons + */ + public void setReasonsd(List reasons) + { + dictionary.setItem(COSName.REASONS, COSArrayList.converterToCOSArray(reasons)); + } + + /** + *

(Optional; PDF 1.6) A dictionary containing a single entry whose key is P + * and whose value is an integer between 0 and 3. A value of 0 defines the + * signatures as an author signature. The value 1 through 3 shall be used for + * certification signatures and correspond to the value of P in a DocMDP transform + * parameters dictionary.

+ * + *

If this MDP key is not present or the MDP dictionary does not contain a P + * entry, no rules shall be defined regarding the type of signature or its + * permissions.

+ * + * @return the mdp dictionary as PDSeedValueMDP + */ + public PDSeedValueMDP getMDP() + { + COSDictionary dict = (COSDictionary)dictionary.getDictionaryObject(COSName.MDP); + PDSeedValueMDP mdp = null; + if (dict != null) + { + mdp = new PDSeedValueMDP(dict); + } + return mdp; + } + + /** + *

(Optional; PDF 1.6) A dictionary containing a single entry whose key is P + * and whose value is an integer between 0 and 3. A value of 0 defines the + * signatures as an author signature. The value 1 through 3 shall be used for + * certification signatures and correspond to the value of P in a DocMDP transform + * parameters dictionary.

+ * + *

If this MDP key is not present or the MDP dictionary does not contain a P + * entry, no rules shall be defined regarding the type of signature or its + * permissions.

+ * + * @param mdp dictionary + */ + public void setMPD(PDSeedValueMDP mdp) + { + if (mdp != null) + { + dictionary.setItem(COSName.MDP, mdp.getCOSObject()); + } + } + + /** + *

(Optional; PDF 1.6) A time stamp dictionary containing two entries. URL which + * is a ASCII string specifying the URL to a rfc3161 conform timestamp server and Ff + * to indicate if a timestamp is required or optional.

+ * + * @return the timestamp dictionary as PDSeedValueTimeStamp + */ + public PDSeedValueTimeStamp getTimeStamp() + { + COSDictionary dict = (COSDictionary)dictionary.getDictionaryObject(COSName.TIME_STAMP); + PDSeedValueTimeStamp timestamp = null; + if (dict != null) + { + timestamp = new PDSeedValueTimeStamp(dict); + } + return timestamp; + } + + /** + *

(Optional; PDF 1.6) A time stamp dictionary containing two entries. URL which + * is a ASCII string specifying the URL to a rfc3161 conform timestamp server and Ff + * to indicate if a timestamp is required or optional.

+ * + * @param timestamp dictionary + */ + public void setTimeStamp(PDSeedValueTimeStamp timestamp) + { + if (timestamp != null) + { + dictionary.setItem(COSName.TIME_STAMP, timestamp.getCOSObject()); + } + } + + /** + * (Optional, PDF 1.6) An array of text strings that specifying possible legal + * attestations. + * + * @return the reasons that should be used by the signature handler + */ + public List getLegalAttestation() + { + List retval = null; + COSArray fields = (COSArray)dictionary.getDictionaryObject(COSName.LEGAL_ATTESTATION); + + if (fields != null) + { + List actuals = new ArrayList(); + for ( int i = 0; i < fields.size(); i++ ) + { + String element = fields.getString(i); + if (element != null) + { + if (element != null) + { + actuals.add(element); + } + } + } + retval = new COSArrayList(actuals, fields); + } + return retval; + } + + /** + * (Optional, PDF 1.6) An array of text strings that specifying possible legal + * attestations. + * + * @param legalAttestation is a list of possible text string that specifying possible + * legal attestations. + */ + public void setLegalAttestation(List legalAttestation) + { + dictionary.setItem(COSName.LEGAL_ATTESTATION, COSArrayList.converterToCOSArray(legalAttestation)); + } +} Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDSeedValue.java ------------------------------------------------------------------------------ svn:eol-style = native Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDSeedValueMDP.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDSeedValueMDP.java?rev=1451638&view=auto ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDSeedValueMDP.java (added) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDSeedValueMDP.java Fri Mar 1 16:33:56 2013 @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pdfbox.pdmodel.interactive.digitalsignature; + +import org.apache.pdfbox.cos.COSBase; +import org.apache.pdfbox.cos.COSDictionary; +import org.apache.pdfbox.cos.COSName; + +/** + *

This MDP dictionary is a part of the seed value dictionary and define + * if a author signature or a certification signature should be use.

+ * + *

For more informations, consider the spare documented chapter in the seed + * value dictionary in the ISO 32000 specification.

+ * + * @author Thomas Chojecki + * @version $Revision: 1.1 $ + */ +public class PDSeedValueMDP +{ + + private COSDictionary dictionary; + + /** + * Default constructor. + */ + public PDSeedValueMDP() + { + dictionary = new COSDictionary(); + dictionary.setDirect(true); + } + + /** + * Constructor. + * + * @param dict The signature dictionary. + */ + public PDSeedValueMDP(COSDictionary dict) + { + dictionary = dict; + dictionary.setDirect(true); + } + + + /** + * Convert this standard java object to a COS object. + * + * @return The cos object that matches this Java object. + */ + public COSBase getCOSObject() + { + return getDictionary(); + } + + /** + * Convert this standard java object to a COS dictionary. + * + * @return The COS dictionary that matches this Java object. + */ + public COSDictionary getDictionary() + { + return dictionary; + } + + /** + * Return the P value. + * + * @return the P value + */ + public int getP() + { + return dictionary.getInt(COSName.P); + } + + /** + * Set the P value. + * + * @param p the value to be set as P + */ + public void setP(int p) + { + if (p < 0 || p > 3) + { + throw new IllegalArgumentException("Only values between 0 and 3 nare allowed."); + } + dictionary.setInt(COSName.P, p); + } +} Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDSeedValueMDP.java ------------------------------------------------------------------------------ svn:eol-style = native Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDSeedValueTimeStamp.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDSeedValueTimeStamp.java?rev=1451638&view=auto ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDSeedValueTimeStamp.java (added) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDSeedValueTimeStamp.java Fri Mar 1 16:33:56 2013 @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.pdfbox.pdmodel.interactive.digitalsignature; + +import org.apache.pdfbox.cos.COSBase; +import org.apache.pdfbox.cos.COSDictionary; +import org.apache.pdfbox.cos.COSName; + +/** + * If exist, it describe where the signature handler can request a rfc3161 + * timestamp and if it is a must have for the signature. + * + * @author Thomas Chojecki + * @version $Revision: 1.1 $ + */ +public class PDSeedValueTimeStamp +{ + + private COSDictionary dictionary; + + /** + * Default constructor. + */ + public PDSeedValueTimeStamp() + { + dictionary = new COSDictionary(); + dictionary.setDirect(true); + } + + /** + * Constructor. + * + * @param dict The signature dictionary. + */ + public PDSeedValueTimeStamp(COSDictionary dict) + { + dictionary = dict; + dictionary.setDirect(true); + } + + + /** + * Convert this standard java object to a COS object. + * + * @return The cos object that matches this Java object. + */ + public COSBase getCOSObject() + { + return getDictionary(); + } + + /** + * Convert this standard java object to a COS dictionary. + * + * @return The COS dictionary that matches this Java object. + */ + public COSDictionary getDictionary() + { + return dictionary; + } + + /** + * Returns the URL. + * + * @return the URL + */ + public String getURL() + { + return dictionary.getString(COSName.URL); + } + + /** + * Sets the URL. + * @param url the URL to be set as URL + */ + public void setURL(String url) + { + dictionary.setString(COSName.URL, url); + } + + /** + * Indicates if a timestamp is required. + * + * @return true if a timestamp is required + */ + public boolean isTimestampRequired() + { + return dictionary.getInt(COSName.FT, 0) != 0; + } + + /** + * Sets if a timestamp is reuqired or not. + * + * @param flag true if a timestamp is required + */ + public void setTimestampRequired(boolean flag) + { + dictionary.setInt(COSName.FT, flag ? 1 : 0); + } +} Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDSeedValueTimeStamp.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDSignature.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDSignature.java?rev=1451638&r1=1451637&r2=1451638&view=diff ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDSignature.java (original) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/PDSignature.java Fri Mar 1 16:33:56 2013 @@ -121,6 +121,21 @@ public class PDSignature implements COSO return dictionary; } + /** + * Set the dictionary type. + * + * @param type is the dictionary type. + */ + public void setType(COSName type) + { + dictionary.setItem(COSName.TYPE, type); + } + + /** + * Set the filter. + * + * @param filter the filter to be used + */ public void setFilter(COSName filter) { dictionary.setItem(COSName.FILTER, filter); @@ -136,56 +151,123 @@ public class PDSignature implements COSO dictionary.setItem(COSName.SUBFILTER, subfilter); } + /** + * Sets the name. + * @param name the name to be used + */ public void setName(String name) { dictionary.setString(COSName.NAME, name); } + /** + * Sets the location. + * @param location the location to be used + */ public void setLocation(String location) { dictionary.setString(COSName.LOCATION, location); } + /** + * Sets the reason. + * + * @param reason the reason to be used + */ public void setReason(String reason) { dictionary.setString(COSName.REASON, reason); } + /** + * Sets the contact info. + * + * @param contactInfo the contact info to be used + */ + public void setContactInfo(String contactInfo) + { + dictionary.setString(COSName.CONTACT_INFO, contactInfo); + } + + /** + * Set the sign date. + * + * @param cal the date to be used as sign date + */ public void setSignDate(Calendar cal) { - dictionary.setDate("M", cal); + dictionary.setDate(COSName.M, cal); } + /** + * Returns the filter. + * @return the filter + */ public String getFilter() { - return ((COSName)dictionary.getItem(COSName.FILTER)).getName(); + return dictionary.getNameAsString(COSName.FILTER); } + /** + * Returns the subfilter. + * + * @return the subfilter + */ public String getSubFilter() { - return ((COSName)dictionary.getItem(COSName.SUBFILTER)).getName(); + return dictionary.getNameAsString(COSName.SUBFILTER); } + /** + * Returns the name. + * + * @return the name + */ public String getName() { return dictionary.getString(COSName.NAME); } + /** + * Returns the location. + * + * @return the location + */ public String getLocation() { return dictionary.getString(COSName.LOCATION); } + /** + * Returns the reason. + * + * @return the reason + */ public String getReason() { return dictionary.getString(COSName.REASON); } + /** + * Returns the contact info. + * + * @return teh contact info + */ + public String getContactInfo() + { + return dictionary.getString(COSName.CONTACT_INFO); + } + + /** + * Returns the sign date. + * + * @return the sign date + */ public Calendar getSignDate() { try { - return dictionary.getDate("M"); + return dictionary.getDate(COSName.M); } catch (IOException e) { @@ -193,32 +275,39 @@ public class PDSignature implements COSO } } + /** + * Sets the byte range. + * + * @param range the byte range to be used + */ public void setByteRange(int[] range) { if (range.length!=4) + { return; - + } COSArray ary = new COSArray(); for ( int i : range ) { ary.add(COSInteger.get(i)); } - dictionary.setItem("ByteRange", ary); + dictionary.setItem(COSName.BYTERANGE, ary); } /** - * Read out the byterange from the file + * Read out the byterange from the file. * * @return a integer array with the byterange */ public int[] getByteRange() { - COSArray byteRange = (COSArray)dictionary.getDictionaryObject("ByteRange"); + COSArray byteRange = (COSArray)dictionary.getDictionaryObject(COSName.BYTERANGE); int[] ary = new int[byteRange.size()]; for (int i = 0; i and ) else if(buffer[c-1]==0x3E || buffer[c-1]==0x29) + { byteOS.write(buffer, 0, c-1); - else + } + else + { byteOS.write(buffer, 0, c); + } } fis.close(); return COSString.createFromHexString(byteOS.toString()).getBytes(); } + /** + * Sets the contents. + * + * @param bytes contents to be used + */ public void setContents(byte[] bytes) { COSString string = new COSString(bytes); string.setForceHexForm(true); - dictionary.setItem("Contents", string); + dictionary.setItem(COSName.CONTENTS, string); } /** @@ -291,18 +391,20 @@ public class PDSignature implements COSO */ public byte[] getSignedContent(InputStream pdfFile) throws IOException { - COSFilterInputStream fis=null; - - try - { - fis = new COSFilterInputStream(pdfFile,getByteRange()); - return fis.toByteArray(); - } - finally - { - if (fis != null) - fis.close(); - } + COSFilterInputStream fis=null; + + try + { + fis = new COSFilterInputStream(pdfFile,getByteRange()); + return fis.toByteArray(); + } + finally + { + if (fis != null) + { + fis.close(); + } + } } /** @@ -314,17 +416,45 @@ public class PDSignature implements COSO */ public byte[] getSignedContent(byte[] pdfFile) throws IOException { - COSFilterInputStream fis=null; - - try - { - fis = new COSFilterInputStream(pdfFile,getByteRange()); - return fis.toByteArray(); - } - finally - { - if (fis != null) - fis.close(); - } + COSFilterInputStream fis=null; + try + { + fis = new COSFilterInputStream(pdfFile,getByteRange()); + return fis.toByteArray(); + } + finally + { + if (fis != null) + { + fis.close(); + } + } + } + + /** + * PDF signature build dictionary. Provides informations about the signature handler. + * + * @return the pdf signature build dictionary. + */ + public PDPropBuild getPropBuild() + { + PDPropBuild propBuild = null; + COSDictionary propBuildDic = (COSDictionary)dictionary.getDictionaryObject(COSName.PROP_BUILD); + if (propBuildDic != null) + { + propBuild = new PDPropBuild(propBuildDic); + } + return propBuild; + } + + /** + * PDF signature build dictionary. Provides informations about the signature handler. + * + * @param propBuild the prop build + */ + public void setPropBuild(PDPropBuild propBuild) + { + dictionary.setItem(COSName.PROP_BUILD, propBuild); } } + Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDSignatureField.java URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDSignatureField.java?rev=1451638&r1=1451637&r2=1451638&view=diff ============================================================================== --- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDSignatureField.java (original) +++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDSignatureField.java Fri Mar 1 16:33:56 2013 @@ -20,6 +20,7 @@ import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget; +import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSeedValue; import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature; import java.io.IOException; @@ -48,7 +49,7 @@ public class PDSignatureField extends PD { super(theAcroForm,field); // dirty hack to avoid npe caused through getWidget() method - getDictionary().setName( COSName.TYPE, "Annot" ); + getDictionary().setItem( COSName.TYPE, COSName.ANNOT ); getDictionary().setName( COSName.SUBTYPE, PDAnnotationWidget.SUB_TYPE); } @@ -57,22 +58,23 @@ public class PDSignatureField extends PD * * @param theAcroForm The acroForm for this field. * @throws IOException If there is an error while resolving partial name for the signature field + * or getting the widget object. */ public PDSignatureField( PDAcroForm theAcroForm) throws IOException { super( theAcroForm ); - getDictionary().setName("FT", "Sig"); + getDictionary().setItem(COSName.FT, COSName.SIG); getWidget().setLocked(true); getWidget().setPrinted(true); setPartialName(generatePartialName()); - getDictionary().setName( COSName.TYPE, "Annot" ); + getDictionary().setItem( COSName.TYPE, COSName.ANNOT ); getDictionary().setName( COSName.SUBTYPE, PDAnnotationWidget.SUB_TYPE); } /** - * Generate a unique name for the signature + * Generate a unique name for the signature. * @return - * @throws IOException + * @throws IOException If there is an error while getting the list of fields. */ private String generatePartialName() throws IOException { @@ -93,8 +95,9 @@ public class PDSignatureField extends PD } while(sigNames.contains(fieldName+i)) + { ++i; - + } return fieldName+i; } @@ -140,17 +143,17 @@ public class PDSignatureField extends PD } /** - * Add a signature dictionary to the signature field + * Add a signature dictionary to the signature field. * * @param value is the PDSignature */ public void setSignature(PDSignature value) { - getDictionary().setItem("V", value); + getDictionary().setItem(COSName.V, value); } /** - * Get the signature dictionary + * Get the signature dictionary. * * @return the signature dictionary * @@ -159,7 +162,42 @@ public class PDSignatureField extends PD { COSBase dictionary = getDictionary().getDictionaryObject(COSName.V); if (dictionary == null) - return null; + { + return null; + } return new PDSignature((COSDictionary)dictionary); } + + /** + *

(Optional; PDF 1.5) A seed value dictionary containing information + * that constrains the properties of a signature that is applied to the + * field.

+ * + * @return the seed value dictionary as PDSeedValue + */ + public PDSeedValue getSeedValue() + { + COSDictionary dict = (COSDictionary)getDictionary().getDictionaryObject(COSName.SV); + PDSeedValue sv = null; + if (dict != null) + { + sv = new PDSeedValue(dict); + } + return sv; + } + + /** + *

(Optional; PDF 1.) A seed value dictionary containing information + * that constrains the properties of a signature that is applied to the + * field.

+ * + * @param sv is the seed value dictionary as PDSeedValue + */ + public void setSeedValue(PDSeedValue sv) + { + if (sv != null) + { + getDictionary().setItem(COSName.SV, sv.getCOSObject()); + } + } }