Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 89ACE200B97 for ; Sun, 9 Oct 2016 19:40:08 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 8839A160ADA; Sun, 9 Oct 2016 17:40:08 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C7DE2160AD6 for ; Sun, 9 Oct 2016 19:40:07 +0200 (CEST) Received: (qmail 95458 invoked by uid 500); 9 Oct 2016 17:40:06 -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 95449 invoked by uid 99); 9 Oct 2016 17:40:06 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 09 Oct 2016 17:40:06 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 6D5A5C0B72 for ; Sun, 9 Oct 2016 17:40:06 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -1.999 X-Spam-Level: X-Spam-Status: No, score=-1.999 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-2.999] autolearn=disabled Received: from mx2-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id fxMvEZ0r03lT for ; Sun, 9 Oct 2016 17:40:02 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx2-lw-eu.apache.org (ASF Mail Server at mx2-lw-eu.apache.org) with ESMTP id 65C3F5F233 for ; Sun, 9 Oct 2016 17:40:01 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 6DE21E00A5 for ; Sun, 9 Oct 2016 17:40:00 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 1C32A3A0233 for ; Sun, 9 Oct 2016 17:40:00 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1763995 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Date: Sun, 09 Oct 2016 17:39:59 -0000 To: commits@pdfbox.apache.org From: tilman@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20161009174000.1C32A3A0233@svn01-us-west.apache.org> archived-at: Sun, 09 Oct 2016 17:40:08 -0000 Author: tilman Date: Sun Oct 9 17:39:59 2016 New Revision: 1763995 URL: http://svn.apache.org/viewvc?rev=1763995&view=rev Log: PDFBOX-2852, PDFBOX-3017: "do one thing" refactoring of checkSignatureField() Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1763995&r1=1763994&r2=1763995&view=diff ============================================================================== --- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (original) +++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Sun Oct 9 17:39:59 2016 @@ -313,6 +313,14 @@ public class PDDocument implements Close acroForm.setAppendOnly(true); boolean checkFields = checkSignatureField(acroFormFields, signatureField); + if (checkFields) + { + signatureField.getCOSObject().setNeedToBeUpdated(true); + } + else + { + acroFormFields.add(signatureField); + } // Get the object from the visual signature COSDocument visualSignature = options.getVisualSignature(); @@ -364,26 +372,25 @@ public class PDDocument implements Close return signatureField; } - // return true if the field already existed in the field list, in that case, it is marked for update + /** + * Check if the field already exists in the field list. + * + * @param acroFormFields the list of AcroForm fields. + * @param signatureField the signature field. + * @return true if the field already existed in the field list, false if not. + */ private boolean checkSignatureField(List acroFormFields, PDSignatureField signatureField) { - boolean checkFields = false; for (PDField field : acroFormFields) { if (field instanceof PDSignatureField && field.getCOSObject().equals(signatureField.getCOSObject())) { - checkFields = true; - signatureField.getCOSObject().setNeedToBeUpdated(true); - break; + return true; } // fixme: this code does not check non-terminal fields, there could be a descendant signature } - if (!checkFields) - { - acroFormFields.add(signatureField); - } - return checkFields; + return false; } private void prepareVisibleSignature(PDSignatureField signatureField, PDAcroForm acroForm, @@ -469,7 +476,7 @@ public class PDDocument implements Close } /** - * This will add a signature field to the document. + * This will add a list of signature fields to the document. * * @param sigFields are the PDSignatureFields that should be added to the document * @param signatureInterface is a interface which provides signing capabilities @@ -504,7 +511,15 @@ public class PDDocument implements Close sigField.getCOSObject().setNeedToBeUpdated(true); // Check if the field already exists - checkSignatureField(acroformFields, sigField); + boolean checkSignatureField = checkSignatureField(acroformFields, sigField); + if (checkSignatureField) + { + sigField.getCOSObject().setNeedToBeUpdated(true); + } + else + { + acroformFields.add(sigField); + } // Check if we need to add a signature if (sigField.getSignature() != null) @@ -1161,7 +1176,7 @@ public class PDDocument implements Close } } - /** + /** * Save the PDF as an incremental update. This is only possible if the PDF was loaded from a * file or a stream, not if the document was created in PDFBox itself. *