pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1679413 [1/2] - in /pdfbox/trunk: examples/src/main/java/org/apache/pdfbox/examples/fdf/ pdfbox/src/main/java/org/apache/pdfbox/cos/ pdfbox/src/main/java/org/apache/pdfbox/multipdf/ pdfbox/src/main/java/org/apache/pdfbox/pdmodel/ pdfbox/sr...
Date Thu, 14 May 2015 17:45:44 GMT
Author: jahewson
Date: Thu May 14 17:45:43 2015
New Revision: 1679413

URL: http://svn.apache.org/r1679413
Log:
PDFBOX-2333: Clean up PDFieldTreeNode constructors and increase type safety

Added:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDField.java
      - copied, changed from r1679304, 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/PDFieldFactory.java   (with props)
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTerminalField.java
      - copied, changed from r1679304, pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDField.java
Removed:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeNode.java
Modified:
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/fdf/PrintFields.java
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/fdf/SetField.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.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/PDFTemplateStructure.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDVisibleSigBuilder.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGenerator.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java
    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/PDChoice.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/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/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextField.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDVariableText.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextFieldTest.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/AcroFormValidationProcess.java

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/fdf/PrintFields.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/fdf/PrintFields.java?rev=1679413&r1=1679412&r2=1679413&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/fdf/PrintFields.java (original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/fdf/PrintFields.java Thu May 14 17:45:43 2015
@@ -25,7 +25,7 @@ import org.apache.pdfbox.pdmodel.PDDocum
 import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
 import org.apache.pdfbox.pdmodel.common.COSObjectable;
 import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
-import org.apache.pdfbox.pdmodel.interactive.form.PDFieldTreeNode;
+import org.apache.pdfbox.pdmodel.interactive.form.PDField;
 import org.apache.pdfbox.pdmodel.interactive.form.PDNonTerminalField;
 import org.apache.pdfbox.pdmodel.interactive.form.PDSignatureField;
 
@@ -49,19 +49,19 @@ public class PrintFields
     {
         PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
         PDAcroForm acroForm = docCatalog.getAcroForm();
-        List<PDFieldTreeNode> fields = acroForm.getFields();
-        Iterator<PDFieldTreeNode> fieldsIter = fields.iterator();
+        List<PDField> fields = acroForm.getFields();
+        Iterator<PDField> fieldsIter = fields.iterator();
 
         System.out.println(fields.size() + " top-level fields were found on the form");
 
         while (fieldsIter.hasNext())
         {
-            PDFieldTreeNode field = fieldsIter.next();
+            PDField field = fieldsIter.next();
             processField(field, "|--", field.getPartialName());
         }
     }
 
-    private void processField(PDFieldTreeNode field, String sLevel, String sParent) throws IOException
+    private void processField(PDField field, String sLevel, String sParent) throws IOException
     {
         String partialName = field != null ? field.getPartialName() : "";
         List<COSObjectable> kids = field.getKids();
@@ -79,9 +79,9 @@ public class PrintFields
             while (kidsIter.hasNext())
             {
                 Object pdfObj = kidsIter.next();
-                if (pdfObj instanceof PDFieldTreeNode)
+                if (pdfObj instanceof PDField)
                 {
-                    PDFieldTreeNode kid = (PDFieldTreeNode) pdfObj;
+                    PDField kid = (PDField) pdfObj;
                     processField(kid, "|  " + sLevel, sParent);
                 }
             }

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/fdf/SetField.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/fdf/SetField.java?rev=1679413&r1=1679412&r2=1679413&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/fdf/SetField.java (original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/fdf/SetField.java Thu May 14 17:45:43 2015
@@ -25,7 +25,7 @@ import org.apache.pdfbox.pdmodel.interac
 import org.apache.pdfbox.pdmodel.interactive.form.PDCheckbox;
 import org.apache.pdfbox.pdmodel.interactive.form.PDChoice;
 import org.apache.pdfbox.pdmodel.interactive.form.PDComboBox;
-import org.apache.pdfbox.pdmodel.interactive.form.PDFieldTreeNode;
+import org.apache.pdfbox.pdmodel.interactive.form.PDField;
 import org.apache.pdfbox.pdmodel.interactive.form.PDListBox;
 import org.apache.pdfbox.pdmodel.interactive.form.PDRadioButton;
 import org.apache.pdfbox.pdmodel.interactive.form.PDTextField;
@@ -51,7 +51,7 @@ public class SetField
     {
         PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
         PDAcroForm acroForm = docCatalog.getAcroForm();
-        PDFieldTreeNode field = acroForm.getField(name);
+        PDField field = acroForm.getField(name);
         if (field != null)
         {
             if (field instanceof PDCheckbox)

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java?rev=1679413&r1=1679412&r2=1679413&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDocument.java Thu May 14 17:45:43 2015
@@ -20,12 +20,9 @@ import java.io.Closeable;
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.pdfparser.PDFObjectStreamParser;
@@ -320,66 +317,6 @@ public class COSDocument extends COSBase
     {
         trailer.setItem( COSName.ENCRYPT, encDictionary );
     }
-
-    /**
-     * This will return a list of signature dictionaries as COSDictionary.
-     *
-     * @return list of signature dictionaries as COSDictionary
-     * @throws IOException if no document catalog can be found
-     */
-    public List<COSDictionary> getSignatureDictionaries() throws IOException
-    {
-        List<COSDictionary> signatureFields = getSignatureFields(false);
-        List<COSDictionary> signatures = new LinkedList<COSDictionary>();
-        for ( COSDictionary dict : signatureFields )
-        {
-            COSBase dictionaryObject = dict.getDictionaryObject(COSName.V);
-            if (dictionaryObject != null)
-            {
-                signatures.add((COSDictionary)dictionaryObject);
-            }
-        }
-        return signatures;
-    }
-
-    /**
-     * This will return a list of signature fields.
-     *
-     * @return list of signature dictionaries as COSDictionary
-     * @throws IOException if no document catalog can be found
-     */
-    public List<COSDictionary> getSignatureFields(boolean onlyEmptyFields) throws IOException
-    {
-        COSObject documentCatalog = getCatalog();
-        if (documentCatalog != null)
-        {
-            COSDictionary acroForm = (COSDictionary)documentCatalog.getDictionaryObject(COSName.ACRO_FORM);
-            if (acroForm != null)
-            {
-                COSArray fields = (COSArray)acroForm.getDictionaryObject(COSName.FIELDS);
-                if (fields != null)
-                {
-                    // Some fields may contain twice references to a single field. 
-                    // This will prevent such double entries.
-                    Map<COSObjectKey, COSDictionary> signatures = new HashMap<COSObjectKey, COSDictionary>();
-                    for ( Object object : fields )
-                    {
-                        COSObject dict = (COSObject)object;
-                        if (COSName.SIG.equals(dict.getItem(COSName.FT)))
-                        {
-                            COSBase dictionaryObject = dict.getDictionaryObject(COSName.V);
-                            if (dictionaryObject == null || !onlyEmptyFields)
-                            {
-                                signatures.put(new COSObjectKey(dict), (COSDictionary)dict.getObject());
-                            }
-                        }
-                    }
-                    return new LinkedList<COSDictionary>(signatures.values());
-                }
-            }
-        }
-        return Collections.emptyList();
-    }
     
     /**
      * This will get the document ID.

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java?rev=1679413&r1=1679412&r2=1679413&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/multipdf/PDFMergerUtility.java Thu May 14 17:45:43 2015
@@ -53,7 +53,7 @@ import org.apache.pdfbox.pdmodel.interac
 import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDDocumentOutline;
 import org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineItem;
 import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
-import org.apache.pdfbox.pdmodel.interactive.form.PDFieldTreeNode;
+import org.apache.pdfbox.pdmodel.interactive.form.PDField;
 
 /**
  * This class will take a list of pdf documents and merge them, saving the
@@ -531,29 +531,24 @@ public class PDFMergerUtility
     private void mergeAcroForm(PDFCloneUtility cloner, PDAcroForm destAcroForm, PDAcroForm srcAcroForm)
             throws IOException
     {
-        List<PDFieldTreeNode> destFields = destAcroForm.getFields();
-        List<PDFieldTreeNode> srcFields = srcAcroForm.getFields();
+        List<PDField> srcFields = srcAcroForm.getFields();
         if (srcFields != null)
         {
-            if (destFields == null)
+            List<COSDictionary> destFields = new ArrayList<COSDictionary>();
+            // fixme: we're only iterating over the root fields, names of kids aren't being checked
+            for (PDField srcField : srcFields)
             {
-                destFields = new COSArrayList<PDFieldTreeNode>();
-                destAcroForm.setFields(destFields);
-            }
-            Iterator<PDFieldTreeNode> srcFieldsIterator = srcFields.iterator();
-            while (srcFieldsIterator.hasNext())
-            {
-                PDFieldTreeNode srcField = srcFieldsIterator.next();
-                PDFieldTreeNode destFieldNode = PDFieldTreeNode.createField(destAcroForm,
-                        (COSDictionary) cloner.cloneForNewDocument(srcField.getCOSObject()), null);
+                COSDictionary dstField = (COSDictionary) cloner.cloneForNewDocument(srcField.getCOSObject());
                 // if the form already has a field with this name then we need to rename this field
                 // to prevent merge conflicts.
-                if (destAcroForm.getField(destFieldNode.getFullyQualifiedName()) != null)
+                if (destAcroForm.getField(srcField.getFullyQualifiedName()) != null)
                 {
-                    destFieldNode.setPartialName("dummyFieldName" + (nextFieldNum++));
+                    dstField.setString(COSName.T, "dummyFieldName" + nextFieldNum++);
                 }
-                destFields.add(destFieldNode);
+                destFields.add(dstField);
             }
+            destAcroForm.getCOSObject().setItem(COSName.FIELDS,
+                                                COSArrayList.converterToCOSArray(destFields));
         }
     }
 

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=1679413&r1=1679412&r2=1679413&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 Thu May 14 17:45:43 2015
@@ -24,10 +24,8 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.HashSet;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.Set;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.cos.COSArray;
@@ -59,7 +57,7 @@ import org.apache.pdfbox.pdmodel.interac
 import org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureInterface;
 import org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureOptions;
 import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
-import org.apache.pdfbox.pdmodel.interactive.form.PDFieldTreeNode;
+import org.apache.pdfbox.pdmodel.interactive.form.PDField;
 import org.apache.pdfbox.pdmodel.interactive.form.PDSignatureField;
 
 /**
@@ -222,10 +220,10 @@ public class PDDocument implements Close
         // Create Annotation / Field for signature
         List<PDAnnotation> annotations = page.getAnnotations();
 
-        List<PDFieldTreeNode> fields = acroForm.getFields();
+        List<PDField> fields = acroForm.getFields();
         if (fields == null)
         {
-            fields = new ArrayList<PDFieldTreeNode>();
+            fields = new ArrayList<PDField>();
             acroForm.setFields(fields);
         }
         PDSignatureField signatureField = findSignatureField(fields, sigObject);
@@ -235,7 +233,7 @@ public class PDDocument implements Close
         }
 
         // Set the AcroForm Fields
-        List<PDFieldTreeNode> acroFormFields = acroForm.getFields();
+        List<PDField> acroFormFields = acroForm.getFields();
         acroForm.getCOSObject().setDirect(true);
         acroForm.setSignaturesExist(true);
         acroForm.setAppendOnly(true);
@@ -279,10 +277,10 @@ public class PDDocument implements Close
     }
 
     // search acroform field list for signature field with specific signature dictionary
-    private PDSignatureField findSignatureField(List<PDFieldTreeNode> fields, PDSignature sigObject)
+    private PDSignatureField findSignatureField(List<PDField> fields, PDSignature sigObject)
     {
         PDSignatureField signatureField = null;
-        for (PDFieldTreeNode pdField : fields)
+        for (PDField pdField : fields)
         {
             if (pdField instanceof PDSignatureField)
             {
@@ -297,10 +295,10 @@ public class PDDocument implements Close
     }
 
     // return true if the field already existed in the field list, in that case, it is marked for update
-    private boolean checkSignatureField(List<PDFieldTreeNode> acroFormFields, PDSignatureField signatureField)
+    private boolean checkSignatureField(List<PDField> acroFormFields, PDSignatureField signatureField)
     {
         boolean checkFields = false;
-        for (PDFieldTreeNode field : acroFormFields)
+        for (PDField field : acroFormFields)
         {
             if (field instanceof PDSignatureField
                     && field.getCOSObject().equals(signatureField.getCOSObject()))
@@ -309,6 +307,7 @@ public class PDDocument implements Close
                 signatureField.getCOSObject().setNeedToBeUpdated(true);
                 break;
             }
+            // fixme: this code does not check non-terminal fields, there could be a descendant signature
         }
         if (!checkFields)
         {
@@ -443,7 +442,7 @@ public class PDDocument implements Close
             acroForm.setSignaturesExist(true); 
         }
 
-        List<PDFieldTreeNode> acroformFields = acroForm.getFields();
+        List<PDField> acroformFields = acroForm.getFields();
 
         for (PDSignatureField sigField : sigFields)
         {
@@ -694,14 +693,17 @@ public class PDDocument implements Close
      */
     public List<PDSignatureField> getSignatureFields() throws IOException
     {
-        List<PDSignatureField> fields = new LinkedList<PDSignatureField>();
+        List<PDSignatureField> fields = new ArrayList<PDSignatureField>();
         PDAcroForm acroForm = getDocumentCatalog().getAcroForm();
         if (acroForm != null)
         {
-            List<COSDictionary> signatureDictionary = document.getSignatureFields(false);
-            for (COSDictionary dict : signatureDictionary)
+            // fixme: non-terminal fields are ignored, could have descendant signatures
+            for (PDField field : acroForm.getFields())
             {
-                fields.add(new PDSignatureField(acroForm, dict, null));
+                if (field instanceof PDSignatureField)
+                {
+                    fields.add((PDSignatureField)field);
+                }
             }
         }
         return fields;
@@ -715,11 +717,14 @@ public class PDDocument implements Close
      */
     public List<PDSignature> getSignatureDictionaries() throws IOException
     {
-        List<COSDictionary> signatureDictionary = document.getSignatureDictionaries();
-        List<PDSignature> signatures = new LinkedList<PDSignature>();
-        for (COSDictionary dict : signatureDictionary)
+        List<PDSignature> signatures = new ArrayList<PDSignature>();
+        for (PDSignatureField field : getSignatureFields())
         {
-            signatures.add(new PDSignature(dict));
+            COSBase value = field.getCOSObject().getDictionaryObject(COSName.V);
+            if (value != null)
+            {
+                signatures.add(new PDSignature((COSDictionary)value));
+            }
         }
         return signatures;
     }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateStructure.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateStructure.java?rev=1679413&r1=1679412&r2=1679413&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateStructure.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/PDFTemplateStructure.java Thu May 14 17:45:43 2015
@@ -37,8 +37,9 @@ import org.apache.pdfbox.pdmodel.graphic
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary;
 import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature;
 import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
-import org.apache.pdfbox.pdmodel.interactive.form.PDFieldTreeNode;
+import org.apache.pdfbox.pdmodel.interactive.form.PDField;
 import org.apache.pdfbox.pdmodel.interactive.form.PDSignatureField;
+import org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField;
 
 /**
  * Structure of PDF document with visible signature.
@@ -67,7 +68,7 @@ public class PDFTemplateStructure
     private PDFormXObject innerForm;
     private PDStream imageFormStream;
     private PDResources imageFormResources;
-    private List<PDFieldTreeNode> acroFormFields;
+    private List<PDField> acroFormFields;
     private COSName innerFormName;
     private COSName imageFormName;
     private COSName imageName;
@@ -555,7 +556,7 @@ public class PDFTemplateStructure
      * Gets acroFormFields
      * @return the AcroForm fields
      */
-    public List<PDFieldTreeNode> getAcroFormFields()
+    public List<PDField> getAcroFormFields()
     {
         return acroFormFields;
     }
@@ -564,7 +565,7 @@ public class PDFTemplateStructure
      * Sets acroFormFields
      * @param acroFormFields
      */
-    public void setAcroFormFields(List<PDFieldTreeNode> acroFormFields)
+    public void setAcroFormFields(List<PDField> acroFormFields)
     {
         this.acroFormFields = acroFormFields;
     }
@@ -590,8 +591,8 @@ public class PDFTemplateStructure
 
     /**
      * Gets Widget Dictionary.
-     * {@link org.apache.pdfbox.pdmodel.interactive.form.PDField}
-     * @see org.apache.pdfbox.pdmodel.interactive.form.PDField#getWidget()
+     * {@link PDTerminalField}
+     * @see PDTerminalField#getWidget()
      * @return the widget dictionary
      */
     public COSDictionary getWidgetDictionary()
@@ -601,8 +602,8 @@ public class PDFTemplateStructure
 
     /**
      * Sets Widget Dictionary.
-     * {@link org.apache.pdfbox.pdmodel.interactive.form.PDField}
-     * @see org.apache.pdfbox.pdmodel.interactive.form.PDField#getWidget()
+     * {@link PDTerminalField}
+     * @see PDTerminalField#getWidget()
      * @param widgetDictionary
      */
     public void setWidgetDictionary(COSDictionary widgetDictionary)

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=1679413&r1=1679412&r2=1679413&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 Thu May 14 17:45:43 2015
@@ -39,7 +39,7 @@ import org.apache.pdfbox.pdmodel.interac
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream;
 import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature;
 import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
-import org.apache.pdfbox.pdmodel.interactive.form.PDFieldTreeNode;
+import org.apache.pdfbox.pdmodel.interactive.form.PDField;
 import org.apache.pdfbox.pdmodel.interactive.form.PDSignatureField;
 
 /**
@@ -118,7 +118,7 @@ public class PDVisibleSigBuilder impleme
             throws IOException
     {
         @SuppressWarnings("unchecked")
-        List<PDFieldTreeNode> acroFormFields = acroForm.getFields();
+        List<PDField> acroFormFields = acroForm.getFields();
         COSDictionary acroFormDict = acroForm.getCOSObject();
         acroForm.setSignaturesExist(true);
         acroForm.setAppendOnly(true);

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGenerator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGenerator.java?rev=1679413&r1=1679412&r2=1679413&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGenerator.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGenerator.java Thu May 14 17:45:43 2015
@@ -39,18 +39,14 @@ public final class AppearanceGenerator
      * @param field The field which appearances need to be generated.
      * @throws IOException 
      */
-    public static void generateFieldAppearances(PDField field) throws IOException
+    public static void generateFieldAppearances(PDTerminalField field) throws IOException
     {
         if (field instanceof PDVariableText)
         {
-            AppearanceGeneratorHelper apHelper = null;
-            Object fieldValue = null;
-
-            apHelper = new AppearanceGeneratorHelper(field.getAcroForm(),
-                        (PDVariableText) field);
-    
-                
-            fieldValue = field.getValue();
+            AppearanceGeneratorHelper apHelper = new AppearanceGeneratorHelper(
+                    field.getAcroForm(), (PDVariableText) field);
+            
+            Object fieldValue = field.getValue();
             
             // TODO: implement the handling for additional values.
             if (fieldValue instanceof String)

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java?rev=1679413&r1=1679412&r2=1679413&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGeneratorHelper.java Thu May 14 17:45:43 2015
@@ -151,11 +151,11 @@ class AppearanceGeneratorHelper
         while (widgetIter.hasNext())
         {
             COSObjectable next = widgetIter.next();
-            PDField field = null;
+            PDTerminalField field = null;
             PDAnnotationWidget widget;
-            if (next instanceof PDField)
+            if (next instanceof PDTerminalField)
             {
-                field = (PDField) next;
+                field = (PDTerminalField) next;
                 widget = field.getWidget();
             }
             else

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java?rev=1679413&r1=1679412&r2=1679413&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java Thu May 14 17:45:43 2015
@@ -52,7 +52,7 @@ public final class PDAcroForm implements
     private final COSDictionary acroForm;
     private final PDDocument document;
 
-    private Map<String,PDFieldTreeNode> fieldCache;
+    private Map<String,PDField> fieldCache;
 
     /**
      * Constructor.
@@ -116,7 +116,7 @@ public final class PDAcroForm implements
             for (Object field : fields)
             {
                 FDFField fdfField = (FDFField) field;
-                PDFieldTreeNode docField = getField( fdfField.getPartialFieldName() );
+                PDField docField = getField( fdfField.getPartialFieldName() );
                 if( docField != null )
                 {
                     docField.importFDF( fdfField );
@@ -139,11 +139,11 @@ public final class PDAcroForm implements
         catalog.setFDF( fdfDict );
 
         List<FDFField> fdfFields = new ArrayList<FDFField>();
-        List<PDFieldTreeNode> fields = getFields();
-        Iterator<PDFieldTreeNode> fieldIter = fields.iterator();
+        List<PDField> fields = getFields();
+        Iterator<PDField> fieldIter = fields.iterator();
         while( fieldIter.hasNext() )
         {
-            PDFieldTreeNode docField = fieldIter.next();
+            PDField docField = fieldIter.next();
             addFieldAndChildren( docField, fdfFields );
         }
         fdfDict.setID( document.getDocument().getDocumentID() );
@@ -154,7 +154,7 @@ public final class PDAcroForm implements
         return fdf;
     }
 
-    private void addFieldAndChildren( PDFieldTreeNode docField, List<FDFField> fdfFields ) throws IOException
+    private void addFieldAndChildren( PDField docField, List<FDFField> fdfFields ) throws IOException
     {
         Object fieldValue = docField.getValue();
         FDFField fdfField = new FDFField();
@@ -166,7 +166,7 @@ public final class PDAcroForm implements
         {
             for (COSObjectable kid : kids)
             {
-                addFieldAndChildren((PDFieldTreeNode) kid, childFDFFields);
+                addFieldAndChildren((PDField) kid, childFDFFields);
             }
             if( !childFDFFields.isEmpty() )
             {
@@ -187,32 +187,29 @@ public final class PDAcroForm implements
      * 
      * The fields within an AcroForm are organized in a tree structure. The documents root fields 
      * might either be terminal fields, non-terminal fields or a mixture of both. Non-terminal fields
-     * mark branches which contents can be retrieved using {@link PDFieldTreeNode#getKids()}.
+     * mark branches which contents can be retrieved using {@link PDField#getKids()}.
      * 
      * @return A list of the documents root fields.
      * 
      */
-    public List<PDFieldTreeNode> getFields()
+    public List<PDField> getFields()
     {
         COSArray cosFields = (COSArray) acroForm.getDictionaryObject(COSName.FIELDS);
         if( cosFields == null )
         {
-            return Collections.<PDFieldTreeNode>emptyList();
+            return Collections.<PDField>emptyList();
         }
-        List<PDFieldTreeNode> pdFields = new ArrayList<PDFieldTreeNode>();
+        List<PDField> pdFields = new ArrayList<PDField>();
         for (int i = 0; i < cosFields.size(); i++)
         {
             COSDictionary element = (COSDictionary) cosFields.getObject(i);
             if (element != null)
             {
-                PDFieldTreeNode field = PDFieldTreeNode.createField( this, element, null );
-                if( field != null )
-                {
-                    pdFields.add(field);
-                }
+                PDField field = PDField.fromDictionary(this, element, null);
+                pdFields.add(field);
             }
         }
-        return new COSArrayList<PDFieldTreeNode>( pdFields, cosFields );
+        return new COSArrayList<PDField>( pdFields, cosFields );
     }
 
     /**
@@ -220,7 +217,7 @@ public final class PDAcroForm implements
      *
      * @param fields The fields that are part of the documents root fields.
      */
-    public void setFields( List<PDFieldTreeNode> fields )
+    public void setFields( List<PDField> fields )
     {
         acroForm.setItem( COSName.FIELDS, COSArrayList.converterToCOSArray( fields ));
     }
@@ -238,12 +235,13 @@ public final class PDAcroForm implements
     {
         if( cache )
         {
-            fieldCache = new HashMap<String,PDFieldTreeNode>();
-            List<PDFieldTreeNode> fields = getFields();
-            Iterator<PDFieldTreeNode> fieldIter = fields.iterator();
+            fieldCache = new HashMap<String,PDField>();
+            // fixme: this code does not cache non-terminal fields or their kids
+            List<PDField> fields = getFields();
+            Iterator<PDField> fieldIter = fields.iterator();
             while( fieldIter.hasNext() )
             {
-                PDFieldTreeNode next = fieldIter.next();
+                PDField next = fieldIter.next();
                 fieldCache.put( next.getFullyQualifiedName(), next );
             }
         }
@@ -266,22 +264,20 @@ public final class PDAcroForm implements
     /**
      * This will get a field by name, possibly using the cache if setCache is true.
      *
-     * @param name The name of the field to get.
-     *
+     * @param fullyQualifiedName The name of the field to get.
      * @return The field with that name of null if one was not found.
-     *
      * @throws IOException If there is an error getting the field type.
      */
-    public PDFieldTreeNode getField( String name ) throws IOException
+    public PDField getField( String fullyQualifiedName ) throws IOException
     {
-        PDFieldTreeNode retval = null;
+        PDField retval = null;
         if( fieldCache != null )
         {
-            retval = fieldCache.get( name );
+            retval = fieldCache.get( fullyQualifiedName );
         }
         else
         {
-            String[] nameSubSection = name.split( "\\." );
+            String[] nameSubSection = fullyQualifiedName.split( "\\." );
             COSArray fields = (COSArray) acroForm.getDictionaryObject(COSName.FIELDS);
 
             for (int i = 0; i < fields.size() && retval == null; i++)
@@ -291,14 +287,14 @@ public final class PDAcroForm implements
                 {
                     COSString fieldName =
                         (COSString)element.getDictionaryObject( COSName.T );
-                    if( fieldName.getString().equals( name ) ||
+                    if( fieldName.getString().equals( fullyQualifiedName ) ||
                         fieldName.getString().equals( nameSubSection[0] ) )
                     {
-                        PDFieldTreeNode root = PDFieldTreeNode.createField( this, element, null );
+                        PDField root = PDField.fromDictionary(this, element, null);
 
                         if( nameSubSection.length > 1 )
                         {
-                            PDFieldTreeNode kid = root.findKid( nameSubSection, 1 );
+                            PDField kid = root.findKid( nameSubSection, 1 );
                             if( kid != null )
                             {
                                 retval = kid;

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=1679413&r1=1679412&r2=1679413&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 Thu May 14 17:45:43 2015
@@ -34,42 +34,33 @@ import java.util.List;
  *
  * @author sug
  */
-public abstract class PDButton extends PDField
+public abstract class PDButton extends PDTerminalField
 {
-
-    /**
-     * The value for the Off state for PDCheckbox and PDRadioButton.
-     * 
-     * This shall not be confused with the OFF state as it is used within
-     * other parts of a PDF. 
-     * 
-     */
-    static final COSName OFF = COSName.getPDFName("Off");
-    
     /**
      * A Ff flag. If set, the field is a set of radio buttons
      */
-    public static final int FLAG_RADIO = 1 << 15;
+    static final int FLAG_RADIO = 1 << 15;
+    
     /**
      * A Ff flag. If set, the field is a pushbutton.
      */
-    public static final int FLAG_PUSHBUTTON = 1 << 16;
+    static final int FLAG_PUSHBUTTON = 1 << 16;
+    
     /**
      * A Ff flag. If set, radio buttons individual fields, using the same
      * value for the on state will turn on and off in unison.
      */
-    public static final int FLAG_RADIOS_IN_UNISON = 1 << 25;
-
+    static final int FLAG_RADIOS_IN_UNISON = 1 << 25;
     
     /**
-     * @see PDFieldTreeNode#PDFieldTreeNode(PDAcroForm)
+     * @see PDField#PDField(PDAcroForm)
      *
-     * @param theAcroForm The acroform.
+     * @param acroForm The acroform.
      */
-    public PDButton(PDAcroForm theAcroForm)
+    public PDButton(PDAcroForm acroForm)
     {
-        super( theAcroForm );
-        getCOSObject().setItem(COSName.FT, COSName.BTN);
+        super( acroForm );
+        dictionary.setItem(COSName.FT, COSName.BTN);
     }
     
     /**
@@ -77,11 +68,11 @@ public abstract class PDButton extends P
      * 
      * @param acroForm The form that this field is part of.
      * @param field the PDF object to represent as a field.
-     * @param parentNode the parent node of the node to be created
+     * @param parent the parent node of the node
      */
-    public PDButton(PDAcroForm acroForm, COSDictionary field, PDFieldTreeNode parentNode)
+    PDButton(PDAcroForm acroForm, COSDictionary field, PDNonTerminalField parent)
     {
-        super(acroForm, field, parentNode);
+        super(acroForm, field, parent);
     }
     
     /**
@@ -91,7 +82,7 @@ public abstract class PDButton extends P
      */
     public boolean isPushButton()
     {
-        return getCOSObject().getFlag( COSName.FF, FLAG_PUSHBUTTON );
+        return dictionary.getFlag(COSName.FF, FLAG_PUSHBUTTON);
     }
 
     /**
@@ -101,7 +92,7 @@ public abstract class PDButton extends P
      */
     public void setPushButton( boolean pushbutton )
     {
-        getCOSObject().setFlag( COSName.FF, FLAG_PUSHBUTTON, pushbutton );
+        dictionary.setFlag(COSName.FF, FLAG_PUSHBUTTON, pushbutton);
     }
 
     /**
@@ -111,7 +102,7 @@ public abstract class PDButton extends P
      */
     public boolean isRadioButton()
     {
-        return getCOSObject().getFlag( COSName.FF, FLAG_RADIO );
+        return dictionary.getFlag(COSName.FF, FLAG_RADIO);
     }
 
     /**
@@ -121,7 +112,7 @@ public abstract class PDButton extends P
      */
     public void setRadioButton( boolean radiobutton )
     {
-        getCOSObject().setFlag( COSName.FF, FLAG_RADIO, radiobutton );
+        dictionary.setFlag(COSName.FF, FLAG_RADIO, radiobutton);
     }   
     
     
@@ -144,28 +135,16 @@ public abstract class PDButton extends P
         }
     }
     
-    /**
-     * 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
-     * field or to revert when resetting the form.
-     * 
-     * @param defaultValue the new field value.
-     */
     @Override
     public void setDefaultValue(String defaultValue)
     {
         if (defaultValue == null)
         {
-            getCOSObject().removeItem(COSName.DV);
+            dictionary.removeItem(COSName.DV);
         }
         else
         {
-            getCOSObject().setItem(COSName.DV, COSName.getPDFName(defaultValue));
+            dictionary.setItem(COSName.DV, COSName.getPDFName(defaultValue));
         }
     }
     

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=1679413&r1=1679412&r2=1679413&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 Thu May 14 17:45:43 2015
@@ -30,27 +30,26 @@ import org.apache.pdfbox.cos.COSName;
  */
 public final class PDCheckbox extends PDButton
 {
-    
     /**
-     * @see PDFieldTreeNode#PDFieldTreeNode(PDAcroForm)
+     * @see PDField#PDField(PDAcroForm)
      *
-     * @param theAcroForm The acroform.
+     * @param acroForm The acroform.
      */
-    public PDCheckbox(PDAcroForm theAcroForm)
+    public PDCheckbox(PDAcroForm acroForm)
     {
-        super( theAcroForm );
+        super( acroForm );
     }
     
     /**
      * Constructor.
      * 
-     * @param theAcroForm The form that this field is part of.
+     * @param acroForm The form that this field is part of.
      * @param field the PDF object to represent as a field.
-     * @param parentNode the parent node of the node to be created
+     * @param parent the parent node of the node
      */
-    public PDCheckbox( PDAcroForm theAcroForm, COSDictionary field, PDFieldTreeNode parentNode)
+    PDCheckbox( PDAcroForm acroForm, COSDictionary field, PDNonTerminalField parent)
     {
-        super( theAcroForm, field, parentNode);
+        super( acroForm, field, parent);
     }
 
     /**
@@ -76,7 +75,7 @@ public final class PDCheckbox extends PD
             // empty catch blocks.
             return false;
         }
-        COSName radioValue = (COSName)getCOSObject().getDictionaryObject( COSName.AS );
+        COSName radioValue = (COSName)dictionary.getDictionaryObject(COSName.AS);
         if( radioValue != null && fieldValue != null && radioValue.getName().equals( onValue ) )
         {
             return true;
@@ -92,7 +91,7 @@ public final class PDCheckbox extends PD
     {
         String onValue = getOnValue();
         setValue(onValue);
-        getCOSObject().setItem(COSName.AS, COSName.getPDFName(onValue));
+        dictionary.setItem(COSName.AS, COSName.getPDFName(onValue));
     }
 
     /**
@@ -100,7 +99,7 @@ public final class PDCheckbox extends PD
      */
     public void unCheck()
     {
-        getCOSObject().setItem(COSName.AS, PDButton.OFF);
+        dictionary.setItem(COSName.AS, COSName.OFF);
     }
 
     /**
@@ -110,7 +109,7 @@ public final class PDCheckbox extends PD
      */
     public String getOffValue()
     {
-        return PDButton.OFF.getName();
+        return COSName.OFF.getName();
     }
 
     /**
@@ -120,7 +119,7 @@ public final class PDCheckbox extends PD
      */
     public String getOnValue()
     {
-        COSDictionary ap = (COSDictionary) getCOSObject().getDictionaryObject(COSName.AP);
+        COSDictionary ap = (COSDictionary) dictionary.getDictionaryObject(COSName.AP);
         COSBase n = ap.getDictionaryObject(COSName.N);
 
         //N can be a COSDictionary or a COSStream
@@ -128,7 +127,7 @@ public final class PDCheckbox extends PD
         {
             for( COSName key :((COSDictionary)n).keySet() )
             {
-                if( !key.equals( PDButton.OFF) )
+                if( !key.equals( COSName.OFF) )
                 {
                     return key.getName();
                 }
@@ -156,29 +155,19 @@ public final class PDCheckbox extends PD
         }
     }
 
-    /**
-     * Set the field 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 Off.
-     * 
-     * @param value the new field value value.
-     */
+    @Override
     public void setValue(String value)
     {
         if (value == null)
         {
-            getCOSObject().removeItem(COSName.V);
-            getCOSObject().setItem( COSName.AS, PDButton.OFF );
+            dictionary.removeItem(COSName.V);
+            dictionary.setItem(COSName.AS, COSName.OFF);
         }
         else
         {
             COSName nameValue = COSName.getPDFName(value);
-            getCOSObject().setItem(COSName.V, nameValue);
-            getCOSObject().setItem( COSName.AS, nameValue);
+            dictionary.setItem(COSName.V, nameValue);
+            dictionary.setItem(COSName.AS, nameValue);
         }
     }
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java?rev=1679413&r1=1679412&r2=1679413&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java Thu May 14 17:45:43 2015
@@ -29,31 +29,30 @@ import org.apache.pdfbox.pdmodel.common.
 import org.apache.pdfbox.pdmodel.interactive.form.FieldUtils.KeyValue;
 
 /**
- * A choice field contains several text items, one or more of which shall be selected as the field value.
+ * A choice field contains several text items, one or more of which shall be selected as the field
+ * value.
  * 
  * @author sug
  * @author John Hewson
  */
 public abstract class PDChoice extends PDVariableText
 {
-    /**
-     *  Ff-flags.
-     */
-    public  static final int FLAG_COMBO = 1 << 17;
+    static final int FLAG_COMBO = 1 << 17;
+    
     private static final int FLAG_SORT = 1 << 19;
     private static final int FLAG_MULTI_SELECT = 1 << 21;
     private static final int FLAG_DO_NOT_SPELL_CHECK = 1 << 22;
     private static final int FLAG_COMMIT_ON_SEL_CHANGE = 1 << 26;
     
     /**
-     * @see PDFieldTreeNode#PDFieldTreeNode(PDAcroForm)
+     * @see PDField#PDField(PDAcroForm)
      *
-     * @param theAcroForm The acroform.
+     * @param acroForm The acroform.
      */
-    public PDChoice(PDAcroForm theAcroForm)
+    public PDChoice(PDAcroForm acroForm)
     {
-        super( theAcroForm );
-        getCOSObject().setItem(COSName.FT, COSName.CH);
+        super( acroForm );
+        dictionary.setItem(COSName.FT, COSName.CH);
     }
 
     /**
@@ -61,11 +60,11 @@ public abstract class PDChoice extends P
      * 
      * @param acroForm The form that this field is part of.
      * @param field the PDF object to represent as a field.
-     * @param parentNode the parent node of the node to be created
+     * @param parent the parent node of the node
      */
-    public PDChoice(PDAcroForm acroForm, COSDictionary field, PDFieldTreeNode parentNode)
+    PDChoice(PDAcroForm acroForm, COSDictionary field, PDNonTerminalField parent)
     {
-        super(acroForm, field, parentNode);
+        super(acroForm, field, parent);
     }
 
     /**
@@ -89,23 +88,21 @@ public abstract class PDChoice extends P
     {
         if (value != null)
         {
-            if (getOptions().indexOf((String) value) == -1)
+            if (getOptions().indexOf(value) == -1)
             {
                 throw new IllegalArgumentException("The list box does not contain the given value.");
             }
             else
             {
-                getCOSObject().setString(COSName.DV, (String)value);
+                dictionary.setString(COSName.DV, value);
             }
         }
         else
         {
-            getCOSObject().removeItem(COSName.DV);
+            dictionary.removeItem(COSName.DV);
         }
     }
     
-    
-    
     /**
      * This will get the option values "Opt".
      * 
@@ -125,7 +122,7 @@ public abstract class PDChoice extends P
      */
     public List<String> getOptions()
     {
-        COSBase values = getCOSObject().getDictionaryObject(COSName.OPT);
+        COSBase values = dictionary.getDictionaryObject(COSName.OPT);
         return FieldUtils.getPairableItems(values, 0);
     }
 
@@ -152,11 +149,11 @@ public abstract class PDChoice extends P
             {
                 Collections.sort(displayValues);
             }
-            getCOSObject().setItem(COSName.OPT, COSArrayList.convertStringListToCOSStringCOSArray(displayValues));
+            dictionary.setItem(COSName.OPT, COSArrayList.convertStringListToCOSStringCOSArray(displayValues));
         }
         else
         {
-            getCOSObject().removeItem(COSName.OPT);
+            dictionary.removeItem(COSName.OPT);
         }
     }
 
@@ -204,12 +201,12 @@ public abstract class PDChoice extends P
                     entry.add(new COSString(keyValuePairs.get(i).getValue()));
                     options.add(entry);
                 }
-                getCOSObject().setItem(COSName.OPT, options);
+                dictionary.setItem(COSName.OPT, options);
             }
         }
         else
         {
-            getCOSObject().removeItem(COSName.OPT);
+            dictionary.removeItem(COSName.OPT);
         }      
     }
 
@@ -227,7 +224,7 @@ public abstract class PDChoice extends P
      */
     public List<String> getOptionsDisplayValues()
     {
-        COSBase values = getCOSObject().getDictionaryObject(COSName.OPT);
+        COSBase values = dictionary.getDictionaryObject(COSName.OPT);
         return FieldUtils.getPairableItems(values, 1);
     }
 
@@ -261,7 +258,7 @@ public abstract class PDChoice extends P
      */
     public List<Integer> getSelectedOptionsIndex()
     {
-        COSBase value = getCOSObject().getDictionaryObject(COSName.I);
+        COSBase value = dictionary.getDictionaryObject(COSName.I);
         if (value != null)
         {
             return COSArrayList.convertIntegerCOSArrayToList((COSArray) value);
@@ -293,11 +290,11 @@ public abstract class PDChoice extends P
                 throw new IllegalArgumentException(
                         "Setting the indices is not allowed for choice fields not allowing multiple selections.");
             }
-            getCOSObject().setItem(COSName.I, COSArrayList.converterToCOSArray(values));
+            dictionary.setItem(COSName.I, COSArrayList.converterToCOSArray(values));
         }
         else
         {
-            getCOSObject().removeItem(COSName.I);
+            dictionary.removeItem(COSName.I);
         }
     }
 
@@ -314,7 +311,7 @@ public abstract class PDChoice extends P
      */
     public boolean isSort()
     {
-        return getCOSObject().getFlag( COSName.FF, FLAG_SORT );
+        return dictionary.getFlag(COSName.FF, FLAG_SORT);
     }
 
     /**
@@ -325,7 +322,7 @@ public abstract class PDChoice extends P
      */
     public void setSort( boolean sort )
     {
-        getCOSObject().setFlag( COSName.FF, FLAG_SORT, sort );
+        dictionary.setFlag(COSName.FF, FLAG_SORT, sort);
     }
 
     /**
@@ -335,7 +332,7 @@ public abstract class PDChoice extends P
      */
     public boolean isMultiSelect()
     {
-        return getCOSObject().getFlag( COSName.FF, FLAG_MULTI_SELECT );
+        return dictionary.getFlag(COSName.FF, FLAG_MULTI_SELECT);
     }
 
     /**
@@ -345,7 +342,7 @@ public abstract class PDChoice extends P
      */
     public void setMultiSelect( boolean multiSelect )
     {
-        getCOSObject().setFlag( COSName.FF, FLAG_MULTI_SELECT, multiSelect );
+        dictionary.setFlag(COSName.FF, FLAG_MULTI_SELECT, multiSelect);
     }
 
     /**
@@ -355,7 +352,7 @@ public abstract class PDChoice extends P
      */
     public boolean isDoNotSpellCheck()
     {
-        return getCOSObject().getFlag( COSName.FF, FLAG_DO_NOT_SPELL_CHECK );
+        return dictionary.getFlag(COSName.FF, FLAG_DO_NOT_SPELL_CHECK);
     }
 
     /**
@@ -365,7 +362,7 @@ public abstract class PDChoice extends P
      */
     public void setDoNotSpellCheck( boolean doNotSpellCheck )
     {
-        getCOSObject().setFlag( COSName.FF, FLAG_DO_NOT_SPELL_CHECK, doNotSpellCheck );
+        dictionary.setFlag(COSName.FF, FLAG_DO_NOT_SPELL_CHECK, doNotSpellCheck);
     }
 
     /**
@@ -375,7 +372,7 @@ public abstract class PDChoice extends P
      */
     public boolean isCommitOnSelChange()
     {
-        return getCOSObject().getFlag( COSName.FF, FLAG_COMMIT_ON_SEL_CHANGE );
+        return dictionary.getFlag(COSName.FF, FLAG_COMMIT_ON_SEL_CHANGE);
     }
 
     /**
@@ -385,7 +382,7 @@ public abstract class PDChoice extends P
      */
     public void setCommitOnSelChange( boolean commitOnSelChange )
     {
-        getCOSObject().setFlag( COSName.FF, FLAG_COMMIT_ON_SEL_CHANGE, commitOnSelChange );
+        dictionary.setFlag(COSName.FF, FLAG_COMMIT_ON_SEL_CHANGE, commitOnSelChange);
     }
 
     /**
@@ -395,7 +392,7 @@ public abstract class PDChoice extends P
      */
     public boolean isCombo()
     {
-        return getCOSObject().getFlag( COSName.FF, FLAG_COMBO );
+        return dictionary.getFlag(COSName.FF, FLAG_COMBO);
     }
 
     /**
@@ -405,33 +402,32 @@ public abstract class PDChoice extends P
      */
     public void setCombo( boolean combo )
     {
-        getCOSObject().setFlag( COSName.FF, FLAG_COMBO, combo );
+        dictionary.setFlag(COSName.FF, FLAG_COMBO, combo);
     }
 
     /**
      * setValue sets the entry "V" to the given value.
      * 
      * @param value the value
-     * 
      */
     public void setValue(String value)
     {
         if (value != null)
         {
-            if (getOptions().indexOf((String) value) == -1)
+            if (getOptions().indexOf(value) == -1)
             {
                 throw new IllegalArgumentException("The list box does not contain the given value.");
             }
             else
             {
-                getCOSObject().setString(COSName.V, (String)value);
+                dictionary.setString(COSName.V, value);
                 // remove I key for single valued choice field
                 setSelectedOptionsIndex(null);
             }
         }
         else
         {
-            getCOSObject().removeItem(COSName.V);
+            dictionary.removeItem(COSName.V);
         }
         // TODO create/update appearance
     }
@@ -453,25 +449,20 @@ public abstract class PDChoice extends P
             {
                 throw new IllegalArgumentException("The values are not contained in the selectable options.");
             }
-            getCOSObject().setItem(COSName.V, COSArrayList.convertStringListToCOSStringCOSArray(values));
+            dictionary.setItem(COSName.V, COSArrayList.convertStringListToCOSStringCOSArray(values));
             updateSelectedOptionsIndex(values);
         }
         else
         {
-            getCOSObject().removeItem(COSName.V);
+            dictionary.removeItem(COSName.V);
         }
         // TODO create/update appearance
     }    
-
-    /**
-     * getValue gets the value of the "V" entry.
-     * 
-     * @return The value of this entry.
-     */
+    
     @Override
     public List<String> getValue()
     {
-        COSBase value = getCOSObject().getDictionaryObject( COSName.V);
+        COSBase value = dictionary.getDictionaryObject(COSName.V);
         if (value instanceof COSString)
         {
             List<String> array = new ArrayList<String>();

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=1679413&r1=1679412&r2=1679413&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 Thu May 14 17:45:43 2015
@@ -22,23 +22,21 @@ import org.apache.pdfbox.cos.COSName;
 /**
  * A combo box consisting of a drop-down list.
  * May be accompanied by an editable text box in which non-predefined values may be entered.
+ * 
  * @author John Hewson
  */
 public final class PDComboBox extends PDChoice
 {
-    /**
-     *  Ff-flag.
-     */
     private static final int FLAG_EDIT = 1 << 18;
     
     /**
-     * @see PDFieldTreeNode#PDFieldTreeNode(PDAcroForm)
+     * @see PDField#PDField(PDAcroForm)
      *
-     * @param theAcroForm The acroform.
+     * @param acroForm The acroform.
      */
-    public PDComboBox(PDAcroForm theAcroForm)
+    public PDComboBox(PDAcroForm acroForm)
     {
-        super( theAcroForm );
+        super( acroForm );
         setCombo(true);
     }    
 
@@ -47,11 +45,11 @@ public final class PDComboBox extends PD
      * 
      * @param acroForm The form that this field is part of.
      * @param field the PDF object to represent as a field.
-     * @param parentNode the parent node of the node to be created
+     * @param parent the parent node of the node
      */
-    public PDComboBox(PDAcroForm acroForm, COSDictionary field, PDFieldTreeNode parentNode)
+    PDComboBox(PDAcroForm acroForm, COSDictionary field, PDNonTerminalField parent)
     {
-        super(acroForm, field, parentNode);
+        super(acroForm, field, parent);
     }
 
     /**
@@ -61,7 +59,7 @@ public final class PDComboBox extends PD
      */
     public boolean isEdit()
     {
-        return getCOSObject().getFlag( COSName.FF, FLAG_EDIT );
+        return dictionary.getFlag(COSName.FF, FLAG_EDIT);
     }
 
     /**
@@ -71,14 +69,9 @@ public final class PDComboBox extends PD
      */
     public void setEdit( boolean edit )
     {
-        getCOSObject().setFlag( COSName.FF, FLAG_EDIT, edit );
+        dictionary.setFlag(COSName.FF, FLAG_EDIT, edit);
     }
-
-    /**
-     * Sets the field value - the 'V' key.
-     * 
-     * @param value the value
-     */
+    
     @Override
     public void setValue(String value)
     {
@@ -87,20 +80,20 @@ public final class PDComboBox extends PD
             // check if the options contain the value to be set is
             // only necessary if the edit flag has not been set.
             // If the edit flag has been set the field allows a custom value.
-            if (!isEdit() && getOptions().indexOf((String) value) == -1)
+            if (!isEdit() && getOptions().indexOf(value) == -1)
             {
                 throw new IllegalArgumentException("The list box does not contain the given value.");
             }
             else
             {
-                getCOSObject().setString(COSName.V, (String)value);
+                dictionary.setString(COSName.V, value);
                 // remove I key for single valued choice field
                 setSelectedOptionsIndex(null);
             }
         }
         else
         {
-            getCOSObject().removeItem(COSName.V);
+            dictionary.removeItem(COSName.V);
         }
         // TODO create/update appearance
     }

Copied: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDField.java (from r1679304, 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/PDField.java?p2=pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDField.java&p1=pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeNode.java&r1=1679304&r2=1679413&rev=1679413&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/PDField.java Thu May 14 17:45:43 2015
@@ -33,62 +33,51 @@ import org.apache.pdfbox.pdmodel.interac
 
 /**
  * A field in an interactive form.
- *
  */
-public abstract class PDFieldTreeNode implements COSObjectable
+public abstract class PDField implements COSObjectable
 {
-    /**
-     * Ff flags.
-     */
     private static final int FLAG_READ_ONLY = 1;
     private static final int FLAG_REQUIRED = 1 << 1;
     private static final int FLAG_NO_EXPORT = 1 << 2;
-
-    /**
-     * Field type Text.
-     */
-    private static final String FIELD_TYPE_TEXT = "Tx";
-    /**
-     * Field type Button.
-     */
-    private static final String FIELD_TYPE_BUTTON = "Btn";
-    /**
-     * Field type Button.
-     */
-    private static final String FIELD_TYPE_CHOICE = "Ch";
+    
     /**
-     * Field type Button.
+     * Creates a COSField subclass from the given COS field. This is for reading fields from PDFs.
+     *
+     * @param form the form that the field is part of
+     * @param field the dictionary representing a field element
+     * @param parent the parent node of the node to be created, or null if root.
+     * @return a new PDField instance
      */
-    private static final String FIELD_TYPE_SIGNATURE = "Sig";
-
-    private PDAcroForm acroForm;
-
-    private COSDictionary dictionary;
+    static PDField fromDictionary(PDAcroForm form, COSDictionary field, PDNonTerminalField parent)
+    {
+        return PDFieldFactory.createField(form, field, parent);
+    }
 
-    private PDFieldTreeNode parent = null;
+    protected final PDAcroForm acroForm;
+    protected final PDNonTerminalField parent;
+    protected final COSDictionary dictionary;
 
     /**
      * Constructor.
      * 
-     * @param theAcroForm The form that this field is part of.
+     * @param acroForm The form that this field is part of.
      */
-    protected PDFieldTreeNode(PDAcroForm theAcroForm)
+    PDField(PDAcroForm acroForm)
     {
-        this(theAcroForm, new COSDictionary(), null);
+        this(acroForm, new COSDictionary(), null);
     }
 
     /**
      * Constructor.
-     * 
-     * @param theAcroForm The form that this field is part of.
+     *  @param acroForm The form that this field is part of.
      * @param field the PDF object to represent as a field.
-     * @param parentNode the parent node of the node to be created
+     * @param parent the parent node of the node
      */
-    protected PDFieldTreeNode(PDAcroForm theAcroForm, COSDictionary field, PDFieldTreeNode parentNode)
+    PDField(PDAcroForm acroForm, COSDictionary field, PDNonTerminalField parent)
     {
-        acroForm = theAcroForm;
-        dictionary = field;
-        parent = parentNode;
+        this.acroForm = acroForm;
+        this.dictionary = field;
+        this.parent = parent;
     }
 
     /**
@@ -98,22 +87,21 @@ public abstract class PDFieldTreeNode im
      * @param key the key to look for
      * @return PDFieldTreeNode the node from which the attribute will be inherited or null
      */    
-    public PDFieldTreeNode getInheritableAttributesNode(PDFieldTreeNode field, COSName key)
+    public PDField getInheritableAttributesNode(PDField field, COSName key)
     {
-        if (field.getDictionary().containsKey(key))
+        if (field.dictionary.containsKey(key))
         {
             return field;
         }
         else
         {
-            PDFieldTreeNode parentField = field.getParent();
-            if (parentField != null)
+            if (field.parent != null)
             {
-                getInheritableAttributesNode(parentField, key);
+                getInheritableAttributesNode(field.parent, key);
             }
         }
         return null;
-    }    
+    }
     
     /**
      * Returns the given attribute, inheriting from parent nodes if necessary.
@@ -123,14 +111,14 @@ public abstract class PDFieldTreeNode im
      */
     protected COSBase getInheritableAttribute(COSName key)
     {
-        PDFieldTreeNode attributesNode = getInheritableAttributesNode(this,key);
+        PDField attributesNode = getInheritableAttributesNode(this, key);
         if (attributesNode != null)
         {
-            return attributesNode.getCOSObject().getDictionaryObject(key);
+            return attributesNode.dictionary.getDictionaryObject(key);
         }
         else
         {
-            return getAcroForm().getCOSObject().getDictionaryObject(key);
+            return acroForm.getCOSObject().getDictionaryObject(key);
         }
     }    
     
@@ -148,14 +136,14 @@ public abstract class PDFieldTreeNode im
         } 
         else 
         {
-            PDFieldTreeNode attributesNode = getInheritableAttributesNode(this,key);
+            PDField attributesNode = getInheritableAttributesNode(this, key);
             if (attributesNode != null)
             {
-                attributesNode.getDictionary().setItem(key, value);
+                attributesNode.dictionary.setItem(key, value);
             } 
             else
             {
-                getDictionary().setItem(key, value);
+                dictionary.setItem(key, value);
             }
         }
     }  
@@ -167,10 +155,10 @@ public abstract class PDFieldTreeNode im
      */
     protected void removeInheritableAttribute(COSName key)
     {
-        PDFieldTreeNode attributesNode = getInheritableAttributesNode(this,key);
+        PDField attributesNode = getInheritableAttributesNode(this, key);
         if (attributesNode != null)
         {
-            attributesNode.getDictionary().removeItem(key);
+            attributesNode.dictionary.removeItem(key);
         }
     }      
     
@@ -231,7 +219,6 @@ 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.
      * 
@@ -250,7 +237,6 @@ public abstract class PDFieldTreeNode im
      */    
     public abstract void setDefaultValue(String defaultValue);
     
-
     /**
      * Get the value of the "V" entry. The "V" entry is an inheritable attribute.
      * 
@@ -292,7 +278,6 @@ public abstract class PDFieldTreeNode im
      */    
     public abstract void setValue(String fieldValue) throws IOException;
     
-
     /**
      * sets the field to be read-only.
      * 
@@ -300,7 +285,7 @@ public abstract class PDFieldTreeNode im
      */
     public void setReadonly(boolean readonly)
     {
-        getDictionary().setFlag(COSName.FF, FLAG_READ_ONLY, readonly);
+        dictionary.setFlag(COSName.FF, FLAG_READ_ONLY, readonly);
     }
 
     /**
@@ -309,7 +294,7 @@ public abstract class PDFieldTreeNode im
      */
     public boolean isReadonly()
     {
-        return getDictionary().getFlag(COSName.FF, FLAG_READ_ONLY);
+        return dictionary.getFlag(COSName.FF, FLAG_READ_ONLY);
     }
 
     /**
@@ -319,7 +304,7 @@ public abstract class PDFieldTreeNode im
      */
     public void setRequired(boolean required)
     {
-        getDictionary().setFlag(COSName.FF, FLAG_REQUIRED, required);
+        dictionary.setFlag(COSName.FF, FLAG_REQUIRED, required);
     }
 
     /**
@@ -328,7 +313,7 @@ public abstract class PDFieldTreeNode im
      */
     public boolean isRequired()
     {
-        return getDictionary().getFlag(COSName.FF, FLAG_REQUIRED);
+        return dictionary.getFlag(COSName.FF, FLAG_REQUIRED);
     }
 
     /**
@@ -338,7 +323,7 @@ public abstract class PDFieldTreeNode im
      */
     public void setNoExport(boolean noExport)
     {
-        getDictionary().setFlag(COSName.FF, FLAG_NO_EXPORT, noExport);
+        dictionary.setFlag(COSName.FF, FLAG_NO_EXPORT, noExport);
     }
 
     /**
@@ -347,7 +332,7 @@ public abstract class PDFieldTreeNode im
      */
     public boolean isNoExport()
     {
-        return getDictionary().getFlag(COSName.FF, FLAG_NO_EXPORT);
+        return dictionary.getFlag(COSName.FF, FLAG_NO_EXPORT);
     }
 
     /**
@@ -364,7 +349,7 @@ public abstract class PDFieldTreeNode im
      */
     public void setFieldFlags(int flags)
     {
-        getDictionary().setInt(COSName.FF, flags);
+        dictionary.setInt(COSName.FF, flags);
     }
 
     /**
@@ -375,7 +360,7 @@ public abstract class PDFieldTreeNode im
      */
     public PDFormFieldAdditionalActions getActions()
     {
-        COSDictionary aa = (COSDictionary) getDictionary().getDictionaryObject(COSName.AA);
+        COSDictionary aa = (COSDictionary) dictionary.getDictionaryObject(COSName.AA);
         PDFormFieldAdditionalActions retval = null;
         if (aa != null)
         {
@@ -388,7 +373,6 @@ public abstract class PDFieldTreeNode im
      * This will import a fdf field from a fdf document.
      * 
      * @param fdfField The fdf field to import.
-     * 
      * @throws IOException If there is an error importing the data for this field.
      */
     public void importFDF(FDFField fdfField) throws IOException
@@ -491,9 +475,9 @@ public abstract class PDFieldTreeNode im
             String fdfName = fdfChild.getPartialFieldName();
             for (COSObjectable pdKid : pdKids)
             {
-                if (pdKid instanceof PDFieldTreeNode)
+                if (pdKid instanceof PDField)
                 {
-                    PDFieldTreeNode pdChild = (PDFieldTreeNode) pdKid;
+                    PDField pdChild = (PDField) pdKid;
                     if (fdfName != null && fdfName.equals(pdChild.getPartialName()))
                     {
                         pdChild.importFDF(fdfChild);
@@ -516,7 +500,7 @@ public abstract class PDFieldTreeNode im
         List<COSObjectable> kids = getKids();
         if (kids == null)
         {
-            retval = new PDAnnotationWidget(getDictionary());
+            retval = new PDAnnotationWidget(dictionary);
         }
         else if (!kids.isEmpty())
         {
@@ -527,7 +511,7 @@ public abstract class PDFieldTreeNode im
             }
             else
             {
-                retval = ((PDFieldTreeNode) firstKid).getWidget();
+                retval = ((PDField) firstKid).getWidget();
             }
         }
         return retval;
@@ -537,32 +521,13 @@ public abstract class PDFieldTreeNode im
      * Get the parent field to this field, or null if none exists.
      * 
      * @return The parent field.
-     * 
      */
-    public PDFieldTreeNode getParent()
+    public PDNonTerminalField getParent()
     {
         return parent;
     }
 
     /**
-     * Set the parent of this field.
-     * 
-     * @param parentNode The parent to this field.
-     */
-    public void setParent(PDFieldTreeNode parentNode)
-    {
-        parent = parentNode;
-        if (parentNode != null)
-        {
-            getDictionary().setItem(COSName.PARENT, parent.getDictionary());
-        }
-        else
-        {
-            getDictionary().removeItem(COSName.PARENT);
-        }
-    }
-
-    /**
      * This will find one of the child elements. The name array are the components of the name to search down the tree
      * of names. The nameIndex is where to start in that array. This method is called recursively until it finds the end
      * point based on the name array.
@@ -571,10 +536,10 @@ public abstract class PDFieldTreeNode im
      * @param nameIndex The index into the array.
      * @return The field at the endpoint or null if none is found.
      */
-    public PDFieldTreeNode findKid(String[] name, int nameIndex)
+    PDField findKid(String[] name, int nameIndex)
     {
-        PDFieldTreeNode retval = null;
-        COSArray kids = (COSArray) getDictionary().getDictionaryObject(COSName.KIDS);
+        PDField retval = null;
+        COSArray kids = (COSArray) dictionary.getDictionaryObject(COSName.KIDS);
         if (kids != null)
         {
             for (int i = 0; retval == null && i < kids.size(); i++)
@@ -582,7 +547,8 @@ public abstract class PDFieldTreeNode im
                 COSDictionary kidDictionary = (COSDictionary) kids.getObject(i);
                 if (name[nameIndex].equals(kidDictionary.getString(COSName.T)))
                 {
-                    retval = PDFieldTreeNode.createField(acroForm, kidDictionary, this);
+                    retval = PDField.fromDictionary(acroForm, kidDictionary,
+                                                    (PDNonTerminalField)this);
                     if (name.length > nameIndex + 1)
                     {
                         retval = retval.findKid(name, nameIndex + 1);
@@ -620,11 +586,9 @@ public abstract class PDFieldTreeNode im
                 // of its own shall not be considered a field but simply a Widget annotation. 
                 if (kidDictionary.getDictionaryObject(COSName.T) != null)
                 {
-                    PDFieldTreeNode field = PDFieldTreeNode.createField(acroForm, kidDictionary, this);
-                    if (field != null)
-                    {
-                        kidsList.add(field);
-                    }
+                    PDField field = PDField.fromDictionary(acroForm, kidDictionary,
+                                                           (PDNonTerminalField)this);
+                    kidsList.add(field);
                 }
                 else
                 {
@@ -644,18 +608,7 @@ public abstract class PDFieldTreeNode im
     public void setKids(List<COSObjectable> kids)
     {
         COSArray kidsArray = COSArrayList.converterToCOSArray(kids);
-        getDictionary().setItem(COSName.KIDS, kidsArray);
-    }
-
-    /**
-     * This will return a string representation of this field.
-     * 
-     * @return A string representation of this field.
-     */
-    @Override
-    public String toString()
-    {
-        return getFullyQualifiedName() + "{type: " + getClass().getSimpleName() + " value: "+ getInheritableAttribute(COSName.V) + "}";
+        dictionary.setItem(COSName.KIDS, kidsArray);
     }
 
     /**
@@ -669,16 +622,6 @@ public abstract class PDFieldTreeNode im
     }
 
     /**
-     * This will set the form this field is on.
-     * 
-     * @param value The new form to use.
-     */
-    public void setAcroForm(PDAcroForm value)
-    {
-        acroForm = value;
-    }
-
-    /**
      * This will get the dictionary associated with this field.
      * 
      * @deprecated  use {@link #getCOSObject()} instead.
@@ -689,12 +632,7 @@ public abstract class PDFieldTreeNode im
     {
         return dictionary;
     }
-
-    /**
-     * Convert this standard java object to a COS object.
-     * 
-     * @return the COS object that matches this Java object.
-     */
+    
     @Override
     public COSDictionary getCOSObject()
     {
@@ -708,9 +646,8 @@ public abstract class PDFieldTreeNode im
      */
     public String getPartialName()
     {
-        return getDictionary().getString(COSName.T);
+        return dictionary.getString(COSName.T);
     }
-
     /**
      * This will set the partial name of the field.
      * 
@@ -718,7 +655,7 @@ public abstract class PDFieldTreeNode im
      */
     public void setPartialName(String name)
     {
-        getDictionary().setString(COSName.T, name);
+        dictionary.setString(COSName.T, name);
     }
 
     /**
@@ -729,7 +666,7 @@ public abstract class PDFieldTreeNode im
     public String getFullyQualifiedName()
     {
         String finalName = getPartialName();
-        String parentName = getParent() != null ? getParent().getFullyQualifiedName() : null;
+        String parentName = parent != null ? parent.getFullyQualifiedName() : null;
         if (parentName != null)
         {
             if (finalName != null)
@@ -751,7 +688,7 @@ public abstract class PDFieldTreeNode im
      */
     public String getAlternateFieldName()
     {
-        return this.getDictionary().getString(COSName.TU);
+        return dictionary.getString(COSName.TU);
     }
 
     /**
@@ -761,7 +698,7 @@ public abstract class PDFieldTreeNode im
      */
     public void setAlternateFieldName(String alternateFieldName)
     {
-        this.getDictionary().setString(COSName.TU, alternateFieldName);
+        dictionary.setString(COSName.TU, alternateFieldName);
     }
     
     /**
@@ -774,7 +711,7 @@ public abstract class PDFieldTreeNode im
      */
     public String getMappingName()
     {
-        return this.getDictionary().getString(COSName.TM);
+        return dictionary.getString(COSName.TM);
     }
 
     /**
@@ -784,86 +721,13 @@ public abstract class PDFieldTreeNode im
      */
     public void setMappingName(String mappingName)
     {
-        this.getDictionary().setString(COSName.TM, mappingName);
-    }    
-
-    /**
-     * Creates a COSField subclass from the given field.
-     * @param form the form that the field is part of
-     * @param field the dictionary representing a field element
-     * @param parentNode the parent node of the node to be created 
-     * @return the corresponding PDField instance
-     */
-    public static PDFieldTreeNode createField(PDAcroForm form, COSDictionary field, PDFieldTreeNode parentNode)
-    {
-        String fieldType = findFieldType(field);
-        if (FIELD_TYPE_CHOICE.equals(fieldType))
-        {
-            return createChoiceSubType(form, field, parentNode);
-        }
-        else if (FIELD_TYPE_TEXT.equals(fieldType))
-        {
-            return new PDTextField(form, field, parentNode);
-        }
-        else if (FIELD_TYPE_SIGNATURE.equals(fieldType))
-        {
-            return new PDSignatureField(form, field, parentNode);
-        }
-        else if (FIELD_TYPE_BUTTON.equals(fieldType))
-        {
-            return createButtonSubType(form, field, parentNode);
-        }
-        else
-        {
-            return new PDNonTerminalField(form, field, parentNode); 
-        }
+        dictionary.setString(COSName.TM, mappingName);
     }
 
-    private static PDFieldTreeNode createChoiceSubType(PDAcroForm form, COSDictionary field, PDFieldTreeNode parentNode)
-    {
-        int flags = field.getInt(COSName.FF, 0);
-        if ((flags & PDChoice.FLAG_COMBO) != 0)
-        {
-            return new PDComboBox(form, field, parentNode);
-        }
-        else
-        {
-            return new PDListBox(form, field, parentNode);
-        }
-    }
-    
-    private static PDFieldTreeNode createButtonSubType(PDAcroForm form, COSDictionary field, PDFieldTreeNode parentNode)
-    {
-        int flags = field.getInt(COSName.FF, 0);
-        // BJL: I have found that the radio flag bit is not always set
-        // and that sometimes there is just a kids dictionary.
-        // so, if there is a kids dictionary then it must be a radio button group.
-        if ((flags & PDButton.FLAG_RADIO) != 0)
-        {
-            return new PDRadioButton(form, field, parentNode);
-        }
-        else if ((flags & PDButton.FLAG_PUSHBUTTON) != 0)
-        {
-            return new PDPushButton(form, field, parentNode);
-        }
-        else
-        {
-            return new PDCheckbox(form, field, parentNode);
-        }
-    }
-    
-    private static String findFieldType(COSDictionary dic)
+    @Override
+    public String toString()
     {
-        String retval = dic.getNameAsString(COSName.FT);
-        if (retval == null)
-        {
-            COSDictionary parent = (COSDictionary) dic.getDictionaryObject(COSName.PARENT,
-                    COSName.P);
-            if (parent != null)
-            {
-                retval = findFieldType(parent);
-            }
-        }
-        return retval;
+        return getFullyQualifiedName() + "{type: " + getClass().getSimpleName() + " value: " +
+                getInheritableAttribute(COSName.V) + "}";
     }
 }

Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldFactory.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldFactory.java?rev=1679413&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldFactory.java (added)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldFactory.java Thu May 14 17:45:43 2015
@@ -0,0 +1,119 @@
+/*
+ * 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.form;
+
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+
+/**
+ * A PDField factory.
+ */
+final class PDFieldFactory
+{
+    private PDFieldFactory()
+    {
+    }
+    
+    private static final String FIELD_TYPE_TEXT = "Tx";
+    private static final String FIELD_TYPE_BUTTON = "Btn";
+    private static final String FIELD_TYPE_CHOICE = "Ch";
+    private static final String FIELD_TYPE_SIGNATURE = "Sig";
+
+    /**
+     * Creates a COSField subclass from the given field.
+     *
+     * @param form the form that the field is part of
+     * @param field the dictionary representing a field element
+     * @param parent the parent node of the node to be created 
+     * @return the corresponding PDField instance
+     */
+    static PDField createField(PDAcroForm form, COSDictionary field, PDNonTerminalField parent)
+    {
+        String fieldType = findFieldType(field);
+        if (FIELD_TYPE_CHOICE.equals(fieldType))
+        {
+            return createChoiceSubType(form, field, parent);
+        }
+        else if (FIELD_TYPE_TEXT.equals(fieldType))
+        {
+            return new PDTextField(form, field, parent);
+        }
+        else if (FIELD_TYPE_SIGNATURE.equals(fieldType))
+        {
+            return new PDSignatureField(form, field, parent);
+        }
+        else if (FIELD_TYPE_BUTTON.equals(fieldType))
+        {
+            return createButtonSubType(form, field, parent);
+        }
+        else
+        {
+            return new PDNonTerminalField(form, field, parent);
+        }
+    }
+
+    private static PDField createChoiceSubType(PDAcroForm form, COSDictionary field,
+                                               PDNonTerminalField parent)
+    {
+        int flags = field.getInt(COSName.FF, 0);
+        if ((flags & PDChoice.FLAG_COMBO) != 0)
+        {
+            return new PDComboBox(form, field, parent);
+        }
+        else
+        {
+            return new PDListBox(form, field, parent);
+        }
+    }
+
+    private static PDField createButtonSubType(PDAcroForm form, COSDictionary field,
+                                               PDNonTerminalField parent)
+    {
+        int flags = field.getInt(COSName.FF, 0);
+        // BJL: I have found that the radio flag bit is not always set
+        // and that sometimes there is just a kids dictionary.
+        // so, if there is a kids dictionary then it must be a radio button group.
+        if ((flags & PDButton.FLAG_RADIO) != 0)
+        {
+            return new PDRadioButton(form, field, parent);
+        }
+        else if ((flags & PDButton.FLAG_PUSHBUTTON) != 0)
+        {
+            return new PDPushButton(form, field, parent);
+        }
+        else
+        {
+            return new PDCheckbox(form, field, parent);
+        }
+    }
+
+    private static String findFieldType(COSDictionary dic)
+    {
+        String retval = dic.getNameAsString(COSName.FT);
+        if (retval == null)
+        {
+            COSDictionary parent = (COSDictionary) dic.getDictionaryObject(COSName.PARENT,
+                    COSName.P);
+            if (parent != null)
+            {
+                retval = findFieldType(parent);
+            }
+        }
+        return retval;
+    }
+}

Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=1679413&r1=1679412&r2=1679413&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 Thu May 14 17:45:43 2015
@@ -20,34 +20,33 @@ import org.apache.pdfbox.cos.COSDictiona
 import org.apache.pdfbox.cos.COSName;
 
 /**
- * A scrollable list box. Contains several text items, one or more of which shall be selected as the field value.
+ * A scrollable list box. Contains several text items, one or more of which shall be selected as the
+ * field value.
  * 
  * @author John Hewson
  */
 public final class PDListBox extends PDChoice
 {
-    
     /**
-     * @see PDFieldTreeNode#PDFieldTreeNode(PDAcroForm)
+     * @see PDField#PDField(PDAcroForm)
      *
-     * @param theAcroForm The acroform.
+     * @param acroForm The acroform.
      */
-    public PDListBox(PDAcroForm theAcroForm)
+    public PDListBox(PDAcroForm acroForm)
     {
-        super( theAcroForm );
+        super( acroForm );
     }
     
-    
     /**
      * Constructor.
      * 
      * @param acroForm The form that this field is part of.
      * @param field the PDF object to represent as a field.
-     * @param parentNode the parent node of the node to be created
+     * @param parent the parent node of the node
      */
-    public PDListBox(PDAcroForm acroForm, COSDictionary field, PDFieldTreeNode parentNode)
+    PDListBox(PDAcroForm acroForm, COSDictionary field, PDNonTerminalField parent)
     {
-        super(acroForm, field, parentNode);
+        super(acroForm, field, parent);
     }
 
     /**
@@ -57,7 +56,7 @@ public final class PDListBox extends PDC
      */
     public int getTopIndex()
     {
-        return getCOSObject().getInt(COSName.TI, 0);
+        return dictionary.getInt(COSName.TI, 0);
     }
 
     /**
@@ -69,11 +68,11 @@ public final class PDListBox extends PDC
     {
         if (topIndex != null)
         {
-            getCOSObject().setInt(COSName.TI, topIndex);
+            dictionary.setInt(COSName.TI, topIndex);
         }
         else
         {
-            getCOSObject().removeItem(COSName.TI);
+            dictionary.removeItem(COSName.TI);
         }
     }
 }



Mime
View raw message