pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msahy...@apache.org
Subject svn commit: r1647218 - in /pdfbox/trunk/pdfbox/src: main/java/org/apache/pdfbox/pdmodel/interactive/form/ test/java/org/apache/pdfbox/pdmodel/interactive/form/
Date Sun, 21 Dec 2014 22:02:40 GMT
Author: msahyoun
Date: Sun Dec 21 22:02:39 2014
New Revision: 1647218

URL: http://svn.apache.org/r1647218
Log:
PDFBOX-2516 use Java types instead of COS model types

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDCheckbox.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDComboBox.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeNode.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDListBox.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDNonTerminalField.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDPushButton.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDSignatureField.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java?rev=1647218&r1=1647217&r2=1647218&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java
Sun Dec 21 22:02:39 2014
@@ -112,30 +112,4 @@ public abstract class PDButton extends P
             getDictionary().setItem(COSName.OPT, COSArrayList.converterToCOSArray( options
) );
         }
     }
-    
-    @Override
-    public COSBase getDefaultValue() throws IOException
-    {
-        // Button fields don't support the "DV" entry.
-        return null;
-    }
-
-    /**
-     * Set the fields default value.
-     * 
-     * The field value holds a name object which is corresponding to the 
-     * appearance state representing the corresponding appearance 
-     * from the appearance directory.
-     *
-     * The default value is used to represent the initial state of the
-     * checkbox or to revert when resetting the form.
-     * 
-     * @param defaultValue the COSName object to set the field value.
-     */
-    public void setDefaultValue(COSName defaultValue)
-    {
-        // Button fields don't support the "DV" entry.
-        throw new IllegalArgumentException( "Button fields don't support the \"DV\" entry."
);
-    }
-
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDCheckbox.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDCheckbox.java?rev=1647218&r1=1647217&r2=1647218&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDCheckbox.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDCheckbox.java
Sun Dec 21 22:02:39 2014
@@ -130,13 +130,13 @@ public final class PDCheckbox extends PD
     }
 
     @Override
-    public COSName getDefaultValue() throws IOException
+    public String getDefaultValue() throws IOException
     {
         COSBase attribute = getInheritableAttribute(COSName.V);
 
         if (attribute instanceof COSName)
         {
-            return (COSName) attribute;
+            return ((COSName) attribute).getName();
         }
         else
         {
@@ -156,7 +156,8 @@ public final class PDCheckbox extends PD
      * 
      * @param defaultValue the COSName object to set the field value.
      */
-    public void setDefaultValue(COSName defaultValue)
+    @Override
+    public void setDefaultValue(String defaultValue)
     {
         if (defaultValue == null)
         {
@@ -164,7 +165,7 @@ public final class PDCheckbox extends PD
         }
         else
         {
-            getDictionary().setItem(COSName.DV, defaultValue);
+            getDictionary().setItem(COSName.DV, COSName.getPDFName(defaultValue));
         }
     }
     

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDComboBox.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDComboBox.java?rev=1647218&r1=1647217&r2=1647218&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDComboBox.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDComboBox.java
Sun Dec 21 22:02:39 2014
@@ -77,6 +77,21 @@ public final class PDComboBox extends PD
         // TODO add handling specific to combo box
         return getInheritableAttribute(getDictionary(), COSName.DV);
     }     
+
+    @Override
+    public void setDefaultValue(String defaultValue)
+    {
+        if (defaultValue == null)
+        {
+            getDictionary().removeItem(COSName.DV);
+        }
+        else
+        {
+            getDictionary().setString(COSName.DV, defaultValue);
+        }
+    }    
+    
+    
     
     
     /**

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeNode.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeNode.java?rev=1647218&r1=1647217&r2=1647218&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeNode.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeNode.java
Sun Dec 21 22:02:39 2014
@@ -254,6 +254,26 @@ public abstract class PDFieldTreeNode im
      * 
      */
     public abstract Object getDefaultValue() throws IOException;
+    
+
+    /**
+     * Set the value of the "DV" entry. The "DV" entry is an inheritable attribute.
+     * 
+     * The different field types do require specific object types for their value
+     * e.g. for RadioButtons the DV entry needs to be a name object. This needs to be handled
by the
+     * individual classes.
+     * 
+     * Trying to set the default value for a {@link PDPushButton} field will lead to an 
+     * {@link IllegalArgumentException} as PDPushButton fields do not support setting the

+     * entry although, common to all field types, the DV entry shall not be set.
+     * 
+     * As a result it might be necessary to check the type of the value before
+     * reusing it.
+     * 
+     * @param defaultValue The new default field value.
+     */    
+    public abstract void setDefaultValue(String defaultValue);
+    
 
     /**
      * Get the value of the "V" entry. The "V" entry is an inheritable attribute.
@@ -276,6 +296,25 @@ public abstract class PDFieldTreeNode im
      * 
      */
     public abstract Object getValue() throws IOException;
+    
+    /**
+     * Set the value of the "V" entry. The "V" entry is an inheritable attribute.
+     * 
+     * The different field types do require specific object types for their value
+     * e.g. for RadioButtons the V entry needs to be a name object. This needs to be handled
by the
+     * individual classes.
+     * 
+     * Trying to set the value for a {@link PDPushButton} field will lead to an
+     * {@link IllegalArgumentException} as PDPushButton fields do not support setting the
+     * entry although, common to all field types, the DV entry shall not be set.
+     * 
+     * As a result it might be necessary to check the type of the value before
+     * reusing it.
+     * 
+     * @param fieldValue The new field value.
+     */    
+    public abstract void setValue(String fieldValue);
+    
 
     /**
      * sets the field to be read-only.

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDListBox.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDListBox.java?rev=1647218&r1=1647217&r2=1647218&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDListBox.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDListBox.java
Sun Dec 21 22:02:39 2014
@@ -78,4 +78,20 @@ public final class PDListBox extends PDC
         // TODO add handling specific to list box
         return getInheritableAttribute(getDictionary(), COSName.DV);
     }
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setDefaultValue(String defaultValue)
+    {
+        if (defaultValue == null)
+        {
+            getDictionary().removeItem(COSName.DV);
+        }
+        else
+        {
+            getDictionary().setString(COSName.DV, defaultValue);
+        }
+    }
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDNonTerminalField.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDNonTerminalField.java?rev=1647218&r1=1647217&r2=1647218&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDNonTerminalField.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDNonTerminalField.java
Sun Dec 21 22:02:39 2014
@@ -22,7 +22,14 @@ import org.apache.pdfbox.cos.COSName;
 
 /**
  * A non terminal field in an interactive form.
- *
+ * 
+ * A non terminal field is a node in the fields tree node whose descendants
+ * are fields. 
+ * 
+ * The attributes such as FT (field type) or V (field value) do not logically
+ * belong to the non terminal field but are inheritable attributes
+ * for descendant terminal fields. 
+ * 
  * @author Andreas Lehmkühler
  */
 public class PDNonTerminalField extends PDFieldTreeNode
@@ -75,30 +82,44 @@ public class PDNonTerminalField extends
         return getDictionary().getNameAsString(COSName.FT);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public Object getValue()
     {
-        // Nonterminal fields don't support the "V" entry.
-        return null;
+        // There is no need to look up the parent hierarchy within a non terminal field
+        return getDictionary().getNameAsString(COSName.V);
     }
     
-    public void setValue(Object value)
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void setValue(String fieldValue)
     {
-        // Nonterminal fields don't support the "V" entry.
-        throw new IllegalArgumentException( "Nonterminal fields don't support the \"V\" entry."
);
+        // There is no need to look up the parent hierarchy within a non terminal field
+        getDictionary().setString(COSName.V, fieldValue);
     }
-    
+
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public Object getDefaultValue()
     {
-        // Nonterminal fields don't support the "DV" entry.
-        return null;
+        // There is no need to look up the parent hierarchy within a non terminal field
+        return getDictionary().getNameAsString(COSName.V);
     }
-    
-    public void setDefaultValue(Object value)
+
+    /**
+     * {@inheritDoc}
+     */    
+    @Override
+    public void setDefaultValue(String defaultValue)
     {
-        // Nonterminal fields don't support the "DV" entry.
-        throw new IllegalArgumentException( "Nonterminal fields don't support the \"DV\"
entry." );
+        // There is no need to look up the parent hierarchy within a non terminal field
+        getDictionary().setString(COSName.V, defaultValue);
     }
     
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDPushButton.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDPushButton.java?rev=1647218&r1=1647217&r2=1647218&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDPushButton.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDPushButton.java
Sun Dec 21 22:02:39 2014
@@ -38,11 +38,30 @@ public class PDPushButton extends PDButt
     {
         super(theAcroForm, field, parentNode);
     }
-
+    
+    @Override
+    public Object getDefaultValue()
+    {
+        // PushButton fields don't support the "V" entry.
+        return null;
+    }    
+    
+    @Override
+    public void setDefaultValue(String defaultValue)
+    {
+        throw new IllegalArgumentException("A PDPushButton shall not use the DV entry in
the field dictionary");
+        
+    }
     @Override
     public Object getValue()
     {
         // PushButton fields don't support the "V" entry.
         return null;
     }
+    
+    @Override
+    public void setValue(String fieldValue)
+    {
+        throw new IllegalArgumentException("A PDPushButton shall not use the V entry in the
field dictionary");
+    }
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java?rev=1647218&r1=1647217&r2=1647218&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
Sun Dec 21 22:02:39 2014
@@ -22,6 +22,7 @@ import java.util.List;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.cos.COSString;
 import org.apache.pdfbox.pdmodel.common.COSObjectable;
 
 /**
@@ -92,9 +93,9 @@ public final class PDRadioButton extends
      * The default value is used to represent the initial state of the
      * checkbox or to revert when resetting the form.
      * 
-     * @param defaultValue the COSName object to set the field value.
+     * @param defaultValue the string to set the field value.
      */
-    public void setDefaultValue(COSName defaultValue)
+    public void setDefaultValue(String defaultValue)
     {
         if (defaultValue == null)
         {
@@ -102,7 +103,7 @@ public final class PDRadioButton extends
         }
         else
         {
-            setInheritableAttribute(COSName.DV, defaultValue);
+            setInheritableAttribute(COSName.DV, new COSString(defaultValue));
         }
     }
     
@@ -129,24 +130,25 @@ public final class PDRadioButton extends
      * 
      * The default value is Off.
      * 
-     * @param value the COSName object to set the field value.
+     * @param fieldValue the COSName object to set the field value.
      */
-    public void setValue(String value)
+    @Override
+    public void setValue(String fieldValue)
     {
-        if (value == null)
+        if (fieldValue == null)
         {
             removeInheritableAttribute(COSName.V);
         }
         else
         {
-            setInheritableAttribute(COSName.V, COSName.getPDFName(value));
+            setInheritableAttribute(COSName.V, COSName.getPDFName(fieldValue));
             List<COSObjectable> kids = getKids();
             for (COSObjectable kid : kids)
             {
                 if (kid instanceof PDCheckbox)
                 {
                     PDCheckbox btn = (PDCheckbox) kid;
-                    if (btn.getOnValue().equals(value))
+                    if (btn.getOnValue().equals(fieldValue))
                     {
                         btn.check();
                     }

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=1647218&r1=1647217&r2=1647218&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
Sun Dec 21 22:02:39 2014
@@ -131,18 +131,25 @@ public class PDSignatureField extends PD
      * 
      * @param value is the PDSignatureField
      */
-    public void setValue(Object value)
+    public void setValue(PDSignature value)
     {
         if (value == null)
         {
             getDictionary().removeItem(COSName.V);
         }
-        else if (value instanceof PDSignature)
+        else
         {
             getDictionary().setItem(COSName.V, (PDSignature)value);
         }
     }
     
+    @Override
+    public void setValue(String fieldValue)
+    {
+        // Signature fields don't support the strings for value
+        throw new IllegalArgumentException( "Signature fields don't support a string for
the value entry." );     
+    }    
+    
     /**
      * Get the signature dictionary.
      * 
@@ -199,10 +206,10 @@ public class PDSignatureField extends PD
         return null;
     }
 
-    public void setDefaultValue(Object value)
+    @Override
+    public void setDefaultValue(String defaultValue)
     {
         // Signature fields don't support the "DV" entry.
-        throw new IllegalArgumentException( "Signature fields don't support the \"DV\" entry."
);
+        throw new IllegalArgumentException( "Signature fields don't support the \"DV\" entry."
);     
     }
-
 }

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java?rev=1647218&r1=1647217&r2=1647218&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java
(original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java
Sun Dec 21 22:02:39 2014
@@ -153,8 +153,9 @@ public class TestFields extends TestCase
             // get the Checkbox with a DV entry
             field = form.getField("Checkbox-DefaultValue");
             assertNotNull(field);
-            assertEquals(field.getDefaultValue(),COSName.getPDFName("Yes"));
-            assertEquals(field.getDefaultValue(),field.getDictionary().getDictionaryObject(COSName.DV));
+            assertEquals(field.getDefaultValue(),"Yes");
+            assertEquals(field.getDefaultValue(),
+                    ((COSName) field.getDictionary().getDictionaryObject(COSName.DV)).getName());
             
             // get the TextField with a DV entry
             field = form.getField("TextField-DefaultValue");



Mime
View raw message