You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ms...@apache.org on 2015/02/15 22:25:19 UTC

svn commit: r1659998 - in /pdfbox/trunk/pdfbox/src: main/java/org/apache/pdfbox/cos/ main/java/org/apache/pdfbox/pdfparser/ main/java/org/apache/pdfbox/pdfwriter/ main/java/org/apache/pdfbox/pdmodel/ main/java/org/apache/pdfbox/pdmodel/interactive/digi...

Author: msahyoun
Date: Sun Feb 15 21:25:19 2015
New Revision: 1659998

URL: http://svn.apache.org/r1659998
Log:
PDFBOX-2685 move setNeedToBeUpdate to COSDictionary

Added:
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSDictionary.java   (with props)
Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSBase.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/VisualSignatureParser.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDVisibleSigBuilder.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSBase.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSBase.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSBase.java?rev=1659998&r1=1659997&r2=1659998&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSBase.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSBase.java Sun Feb 15 21:25:19 2015
@@ -27,7 +27,6 @@ import java.io.IOException;
  */
 public abstract class COSBase implements COSObjectable
 {
-    private boolean needToBeUpdate;
     private boolean direct;
 
     /**
@@ -35,7 +34,6 @@ public abstract class COSBase implements
      */
     public COSBase()
     {
-      needToBeUpdate = false;
     }
 
     /**
@@ -58,11 +56,6 @@ public abstract class COSBase implements
      */
     public abstract Object accept(ICOSVisitor visitor) throws IOException;
     
-    public void setNeedToBeUpdate(boolean flag) 
-    {
-      needToBeUpdate = flag;
-    }
-    
     /**
      * If the state is set true, the dictionary will be written direct into the called object. 
      * This means, no indirect object will be created.
@@ -83,10 +76,4 @@ public abstract class COSBase implements
     {
       this.direct = direct;
     }
-    
-    public boolean isNeedToBeUpdate() 
-    {
-      return needToBeUpdate;
-    }
-
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java?rev=1659998&r1=1659997&r2=1659998&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java Sun Feb 15 21:25:19 2015
@@ -35,6 +35,7 @@ import org.apache.pdfbox.util.DateConver
 public class COSDictionary extends COSBase
 {
     private static final String PATH_SEPARATOR = "/";
+    private boolean needToBeUpdated;
 
     /**
      * The name-value pairs of this dictionary. The pairs are kept in the order they were added to the dictionary.
@@ -1318,6 +1319,27 @@ public class COSDictionary extends COSBa
     {
         return visitor.visitFromDictionary(this);
     }
+    
+    /**
+     * Get the update state for the COSWriter.
+     * 
+     * @return the update state.
+     */
+    public boolean isNeedToBeUpdated() 
+    {
+      return needToBeUpdated;
+    }
+    
+    /**
+     * Set the update state of the dictionary for the COSWriter.
+     * 
+     * @param flag the update state.
+     */
+    public void setNeedToBeUpdated(boolean flag) 
+    {
+      needToBeUpdated = flag;
+    }
+    
 
     /**
      * This will add all of the dictionarys keys/values to this dictionary. Only called when adding keys to a trailer

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/VisualSignatureParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/VisualSignatureParser.java?rev=1659998&r1=1659997&r2=1659998&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/VisualSignatureParser.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/VisualSignatureParser.java Sun Feb 15 21:25:19 2015
@@ -209,7 +209,10 @@ public class VisualSignatureParser exten
                 endObjectKey = readString();
             }
             COSObject pdfObject = document.getObjectFromPool(key);
-            pb.setNeedToBeUpdate(true);
+            if (pb instanceof COSDictionary)
+            {
+                ((COSDictionary) pb).setNeedToBeUpdated(true);
+            }
             pdfObject.setObject(pb);
 
             if (!endObjectKey.equals(ENDOBJ_STRING))

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java?rev=1659998&r1=1659997&r2=1659998&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java Sun Feb 15 21:25:19 2015
@@ -480,11 +480,18 @@ public class COSWriter implements ICOSVi
             {
                 cosBase = keyObject.get(cosObjectKey);
             }
+
             if(actual != null && objectKeys.containsKey(actual) &&
-                    !object.isNeedToBeUpdate() && (cosBase!= null &&
-                    !cosBase.isNeedToBeUpdate()))
+                    cosBase!= null)
             {
-                return;
+                if (object instanceof COSDictionary &&
+                        cosBase instanceof COSDictionary &&
+                        !((COSDictionary) object).isNeedToBeUpdated() &&
+                        !((COSDictionary) cosBase).isNeedToBeUpdated()
+                        )
+                {
+                    return;
+                }
             }
           
             objectsToWrite.add( object );

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java?rev=1659998&r1=1659997&r2=1659998&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDDocument.java Sun Feb 15 21:25:19 2015
@@ -202,7 +202,7 @@ public class PDDocument implements Close
 
         // Get the AcroForm from the Root-Dictionary and append the annotation
         PDAcroForm acroForm = catalog.getAcroForm();
-        catalog.getCOSObject().setNeedToBeUpdate(true);
+        catalog.getCOSObject().setNeedToBeUpdated(true);
 
         if (acroForm == null)
         {
@@ -211,7 +211,7 @@ public class PDDocument implements Close
         }
         else
         {
-            acroForm.getCOSObject().setNeedToBeUpdate(true);
+            acroForm.getDictionary().setNeedToBeUpdated(true);
         }
 
         // For invisible signatures, the annotation has a rectangle array with values [ 0 0 0 0 ]. This annotation is
@@ -264,7 +264,7 @@ public class PDDocument implements Close
                     && ((PDSignatureField) field).getCOSObject().equals(signatureField.getCOSObject()))
             {
                 checkFields = true;
-                signatureField.getCOSObject().setNeedToBeUpdate(true);
+                ((COSDictionary) signatureField.getCOSObject()).setNeedToBeUpdated(true);
                 break;
             }
         }
@@ -344,11 +344,11 @@ public class PDDocument implements Close
                         signatureField.getWidget().setAppearance(ap);
 
                         // read and set AcroForm DefaultResource
-                        COSBase dr = cosBaseDict.getItem(COSName.DR);
+                        COSDictionary dr = (COSDictionary) cosBaseDict.getItem(COSName.DR);
                         if (dr != null)
                         {
                             dr.setDirect(true);
-                            dr.setNeedToBeUpdate(true);
+                            dr.setNeedToBeUpdated(true);
                             acroFormDict.setItem(COSName.DR, dr);
                         }
                         sigFieldNotFound = false;
@@ -371,7 +371,7 @@ public class PDDocument implements Close
         {
             annotations.add(signatureField.getWidget());
         }
-        page.getCOSObject().setNeedToBeUpdate(true);
+        ((COSDictionary) page.getCOSObject()).setNeedToBeUpdated(true);
     }
 
     /**
@@ -386,7 +386,7 @@ public class PDDocument implements Close
             SignatureOptions options) throws IOException
     {
         PDDocumentCatalog catalog = getDocumentCatalog();
-        catalog.getCOSObject().setNeedToBeUpdate(true);
+        ((COSDictionary) catalog.getCOSObject()).setNeedToBeUpdated(true);
 
         PDAcroForm acroForm = catalog.getAcroForm();
         if (acroForm == null)
@@ -396,12 +396,12 @@ public class PDDocument implements Close
         }
         else
         {
-            acroForm.getCOSObject().setNeedToBeUpdate(true);
+            ((COSDictionary) acroForm.getCOSObject()).setNeedToBeUpdated(true);
         }
 
         COSDictionary acroFormDict = acroForm.getDictionary();
         acroFormDict.setDirect(true);
-        acroFormDict.setNeedToBeUpdate(true);
+        acroFormDict.setNeedToBeUpdated(true);
         if (!acroForm.isSignaturesExist())
         {
             // 1 if at least one signature field is available
@@ -413,7 +413,7 @@ public class PDDocument implements Close
         for (PDSignatureField sigField : sigFields)
         {
             PDSignature sigObject = sigField.getSignature();
-            sigField.getCOSObject().setNeedToBeUpdate(true);
+            ((COSDictionary) sigField.getCOSObject()).setNeedToBeUpdated(true);
 
             // Check if the field already exists
             boolean checkFields = false;
@@ -423,7 +423,7 @@ public class PDDocument implements Close
                         && fieldNode.getCOSObject().equals(sigField.getCOSObject()))
                 {
                     checkFields = true;
-                    sigField.getCOSObject().setNeedToBeUpdate(true);
+                    ((COSDictionary) sigField.getCOSObject()).setNeedToBeUpdated(true);
                     break;
                 }
             }
@@ -436,7 +436,7 @@ public class PDDocument implements Close
             // Check if we need to add a signature
             if (sigField.getSignature() != null)
             {
-                sigField.getCOSObject().setNeedToBeUpdate(true);
+                ((COSDictionary) sigField.getCOSObject()).setNeedToBeUpdated(true);
                 if (options == null)
                 {
 

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDVisibleSigBuilder.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDVisibleSigBuilder.java?rev=1659998&r1=1659997&r2=1659998&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDVisibleSigBuilder.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDVisibleSigBuilder.java Sun Feb 15 21:25:19 2015
@@ -374,7 +374,7 @@ public class PDVisibleSigBuilder impleme
                                        PDResources holderFormResources) throws IOException
     {
         COSDictionary widgetDict = signatureField.getWidget().getDictionary();
-        widgetDict.setNeedToBeUpdate(true);
+        widgetDict.setNeedToBeUpdated(true);
         widgetDict.setItem(COSName.DR, holderFormResources.getCOSObject());
 
         pdfStructure.setWidgetDictionary(widgetDict);

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSBase.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSBase.java?rev=1659998&r1=1659997&r2=1659998&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSBase.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSBase.java Sun Feb 15 21:25:19 2015
@@ -43,17 +43,6 @@ public abstract class TestCOSBase extend
     public abstract void testAccept() throws IOException;
 
     /**
-     * Tests isNeedToBeUpdate() and setNeedToBeUpdate() - tests the getter/setter methods.
-     */
-    public void testIsSetNeedToBeUpdate()
-    {
-        testCOSBase.setNeedToBeUpdate(true);
-        assertTrue(testCOSBase.isNeedToBeUpdate());
-        testCOSBase.setNeedToBeUpdate(false);
-        assertFalse(testCOSBase.isNeedToBeUpdate());
-    }
-
-    /**
      * Tests isDirect() and setDirect() - tests the getter/setter methods.
      */
     public void testIsSetDirect()

Added: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSDictionary.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSDictionary.java?rev=1659998&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSDictionary.java (added)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSDictionary.java Sun Feb 15 21:25:19 2015
@@ -0,0 +1,46 @@
+/*
+ * 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.cos;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+import org.junit.Test;
+
+/**
+ * Test class for {@link COSDictionary}.
+ */
+public class TestCOSDictionary
+{
+    
+    /** The COSDictionary abstraction of the object being tested. */
+    protected COSDictionary testCOSDictionary = new COSDictionary();;
+    
+    /**
+     * Tests isNeedToBeUpdate() and setNeedToBeUpdate() - tests the getter/setter methods.
+     */
+    @Test
+    public void testIsSetNeedToBeUpdate()
+    {
+        testCOSDictionary.setNeedToBeUpdated(true);
+        assertTrue(testCOSDictionary.isNeedToBeUpdated());
+        testCOSDictionary.setNeedToBeUpdated(false);
+        assertFalse(testCOSDictionary.isNeedToBeUpdated());
+    }
+
+}

Propchange: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSDictionary.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/cos/TestCOSDictionary.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain