Author: lehmi
Date: Sat Aug 16 16:39:52 2014
New Revision: 1618381

URL: http://svn.apache.org/r1618381
Log:
PDFBOX-2261: removed PDFieldFactory

Removed:
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldFactory.java
Modified:
    
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/PDFieldTreeNode.java
    
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java

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=1618381&r1=1618380&r2=1618381&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
 Sat Aug 16 16:39:52 2014
@@ -196,7 +196,7 @@ public final class PDAcroForm implements
             COSDictionary element = (COSDictionary) cosFields.getObject(i);
             if (element != null)
             {
-                PDFieldTreeNode field = PDFieldFactory.createField( this, 
element, null );
+                PDFieldTreeNode field = PDFieldTreeNode.createField( this, 
element, null );
                 if( field != null )
                 {
                     pdFields.add(field);
@@ -285,7 +285,7 @@ public final class PDAcroForm implements
                     if( fieldName.getString().equals( name ) ||
                         fieldName.getString().equals( nameSubSection[0] ) )
                     {
-                        PDFieldTreeNode root = PDFieldFactory.createField( 
this, element, null );
+                        PDFieldTreeNode root = PDFieldTreeNode.createField( 
this, element, null );
 
                         if( nameSubSection.length > 1 )
                         {

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=1618381&r1=1618380&r2=1618381&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
 Sat Aug 16 16:39:52 2014
@@ -107,21 +107,6 @@ public abstract class PDFieldTreeNode im
      */
     public abstract String getFieldType();
 
-    // used by factory class
-    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;
-    }
 
     /**
      * setValue sets the fields value to a given string.
@@ -417,7 +402,7 @@ public abstract class PDFieldTreeNode im
                 COSDictionary kidDictionary = (COSDictionary) 
kids.getObject(i);
                 if (name[nameIndex].equals(kidDictionary.getString(COSName.T)))
                 {
-                    retval = (PDFieldTreeNode) 
PDFieldFactory.createField(acroForm, kidDictionary, this);
+                    retval = (PDFieldTreeNode) 
PDFieldTreeNode.createField(acroForm, kidDictionary, this);
                     if (name.length > nameIndex + 1)
                     {
                         retval = retval.findKid(name, nameIndex + 1);
@@ -453,7 +438,7 @@ public abstract class PDFieldTreeNode im
                 if (kidDictionary.getDictionaryObject(COSName.FT) != null
                         || (parent != null && 
parent.getDictionaryObject(COSName.FT) != null))
                 {
-                    PDFieldTreeNode field = 
PDFieldFactory.createField(acroForm, kidDictionary, this);
+                    PDFieldTreeNode field = 
PDFieldTreeNode.createField(acroForm, kidDictionary, this);
                     if (field != null)
                     {
                         kidsList.add(field);
@@ -465,7 +450,7 @@ public abstract class PDFieldTreeNode im
                 }
                 else
                 {
-                    PDFieldTreeNode field = 
PDFieldFactory.createField(acroForm, kidDictionary, this);
+                    PDFieldTreeNode field = 
PDFieldTreeNode.createField(acroForm, kidDictionary, this);
                     if (field != null)
                     {
                         kidsList.add(field);
@@ -597,4 +582,73 @@ public abstract class PDFieldTreeNode im
         this.getDictionary().setString(COSName.TU, alternateFieldName);
     }
 
+    /**
+     * 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
+     * @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))
+        {
+            int flags = field.getInt(COSName.FF, 0);
+            if ((flags & PDVariableText.FLAG_COMB) != 0)
+            {
+                return new PDComboBox(form, field, parentNode);
+            }
+            else
+            {
+                return new PDListBox(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))
+        {
+            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 || 
field.getDictionaryObject(COSName.KIDS) != null)
+            {
+                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);
+            }
+        }
+        else
+        {
+            return new PDNonTerminalField(form, field, parentNode); 
+        }
+    }
+
+    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;
+    }
+
 }

Modified: 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java
URL: 
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java?rev=1618381&r1=1618380&r2=1618381&view=diff
==============================================================================
--- 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java 
(original)
+++ 
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFMergerUtility.java 
Sat Aug 16 16:39:52 2014
@@ -50,7 +50,6 @@ 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.PDFieldFactory;
 import org.apache.pdfbox.pdmodel.interactive.form.PDFieldTreeNode;
 
 /**
@@ -557,7 +556,7 @@ public class PDFMergerUtility
             while (srcFieldsIterator.hasNext())
             {
                 PDFieldTreeNode srcField = srcFieldsIterator.next();
-                PDFieldTreeNode destFieldNode = 
PDFieldFactory.createField(destAcroForm,
+                PDFieldTreeNode destFieldNode = 
PDFieldTreeNode.createField(destAcroForm,
                         (COSDictionary) 
cloner.cloneForNewDocument(srcField.getDictionary()), null);
                 // if the form already has a field with this name then we need 
to rename this field
                 // to prevent merge conflicts.


Reply via email to