Author: lehmi
Date: Sun Oct 27 18:15:22 2013
New Revision: 1536173
URL: http://svn.apache.org/r1536173
Log:
PDFBOX-1412: avoid NPE when iterating through the kids of a field
Modified:
pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/fdf/PrintFields.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDField.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=1536173&r1=1536172&r2=1536173&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
Sun Oct 27 18:15:22 2013
@@ -17,36 +17,35 @@
package org.apache.pdfbox.examples.fdf;
import java.io.IOException;
-
import java.util.Iterator;
import java.util.List;
-import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
-import org.apache.pdfbox.pdmodel.interactive.form.PDField;
-
import org.apache.pdfbox.exceptions.CryptographyException;
import org.apache.pdfbox.exceptions.InvalidPasswordException;
-
import org.apache.pdfbox.pdmodel.PDDocument;
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.PDField;
+import org.apache.pdfbox.pdmodel.interactive.form.PDSignatureField;
/**
* This example will take a PDF document and print all the fields from the
file.
- *
+ *
* @author <a href="mailto:[email protected]">Ben Litchfield</a>
- * @version $Revision: 1.16 $
+ *
*/
public class PrintFields
{
/**
* This will print all the fields from the document.
- *
+ *
* @param pdfDocument The PDF to get the fields from.
- *
+ *
* @throws IOException If there is an error getting the fields.
*/
- public void printFields( PDDocument pdfDocument ) throws IOException
+ public void printFields(PDDocument pdfDocument) throws IOException
{
PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
PDAcroForm acroForm = docCatalog.getAcroForm();
@@ -55,51 +54,59 @@ public class PrintFields
System.out.println(new Integer(fields.size()).toString() + " top-level
fields were found on the form");
- while( fieldsIter.hasNext())
+ while (fieldsIter.hasNext())
{
- PDField field = (PDField)fieldsIter.next();
- processField(field, "|--", field.getPartialName());
+ PDField field = (PDField) fieldsIter.next();
+ processField(field, "|--", field.getPartialName());
}
}
private void processField(PDField field, String sLevel, String sParent)
throws IOException
{
- List kids = field.getKids();
- if(kids != null)
+ List<COSObjectable> kids = field.getKids();
+ if (kids != null)
{
- Iterator kidsIter = kids.iterator();
- if(!sParent.equals(field.getPartialName()))
+ Iterator<COSObjectable> kidsIter = kids.iterator();
+ if (!sParent.equals(field.getPartialName()))
{
- sParent = sParent + "." + field.getPartialName();
+ sParent = sParent + "." + field.getPartialName();
}
System.out.println(sLevel + sParent);
- //System.out.println(sParent + " is of type " +
field.getClass().getName());
- while(kidsIter.hasNext())
+ // System.out.println(sParent + " is of type " +
field.getClass().getName());
+ while (kidsIter.hasNext())
{
- Object pdfObj = kidsIter.next();
- if(pdfObj instanceof PDField)
- {
- PDField kid = (PDField)pdfObj;
- processField(kid, "| " + sLevel, sParent);
- }
- }
- }
- else
- {
- String outputString = sLevel + sParent + "." +
field.getPartialName() + " = " + field.getValue() +
- ", type=" + field.getClass().getName();
-
- System.out.println(outputString);
- }
+ Object pdfObj = kidsIter.next();
+ if (pdfObj instanceof PDField)
+ {
+ PDField kid = (PDField) pdfObj;
+ processField(kid, "| " + sLevel, sParent);
+ }
+ }
+ }
+ else
+ {
+ String fieldValue = null;
+ if (field instanceof PDSignatureField)
+ {
+ // PDSignature doesn't have a value
+ fieldValue = "PDSignatureField";
+ }
+ else
+ {
+ fieldValue = field.getValue();
+ }
+ String outputString = sLevel + sParent + "." +
field.getPartialName() + " = " + fieldValue + ", type="
+ + field.getClass().getName();
+ System.out.println(outputString);
+ }
}
/**
- * This will read a PDF file and print out the form elements.
- * <br />
+ * This will read a PDF file and print out the form elements. <br />
* see usage() for commandline
- *
+ *
* @param args command line arguments
- *
+ *
* @throws IOException If there is an error importing the FDF document.
* @throws CryptographyException If there is an error decrypting the
document.
*/
@@ -108,42 +115,43 @@ public class PrintFields
PDDocument pdf = null;
try
{
- if( args.length != 1 )
+ if (args.length != 1)
{
usage();
}
else
{
- pdf = PDDocument.load( args[0] );
+ pdf = PDDocument.load(args[0]);
PrintFields exporter = new PrintFields();
- if( pdf.isEncrypted() )
+ if (pdf.isEncrypted())
{
try
{
- pdf.decrypt( "" );
+ pdf.decrypt("");
}
- catch( InvalidPasswordException e )
+ catch (InvalidPasswordException e)
{
- System.err.println( "Error: The document is
encrypted." );
+ System.err.println("Error: The document is
encrypted.");
usage();
}
}
- exporter.printFields( pdf );
+ exporter.printFields(pdf);
}
}
finally
{
- if( pdf != null )
+ if (pdf != null)
{
pdf.close();
}
}
}
+
/**
* This will print out a message telling how to use this example.
*/
private static void usage()
{
- System.err.println( "usage: org.apache.pdfbox.examples.fdf.PrintFields
<pdf-file>" );
+ System.err.println("usage: org.apache.pdfbox.examples.fdf.PrintFields
<pdf-file>");
}
}
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDField.java
URL:
http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDField.java?rev=1536173&r1=1536172&r2=1536173&view=diff
==============================================================================
---
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDField.java
(original)
+++
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDField.java
Sun Oct 27 18:15:22 2013
@@ -16,34 +16,28 @@
*/
package org.apache.pdfbox.pdmodel.interactive.form;
-import
org.apache.pdfbox.pdmodel.interactive.action.PDFormFieldAdditionalActions;
-import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
-
-import org.apache.pdfbox.pdmodel.common.COSArrayList;
-import org.apache.pdfbox.pdmodel.common.COSObjectable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSInteger;
import org.apache.pdfbox.cos.COSName;
-
+import org.apache.pdfbox.pdmodel.common.COSArrayList;
+import org.apache.pdfbox.pdmodel.common.COSObjectable;
import org.apache.pdfbox.pdmodel.common.PDTextStream;
-
import org.apache.pdfbox.pdmodel.fdf.FDFField;
+import
org.apache.pdfbox.pdmodel.interactive.action.PDFormFieldAdditionalActions;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
import org.apache.pdfbox.util.BitFlagHelper;
-import java.io.IOException;
-
-import java.util.ArrayList;
-import java.util.List;
-
/**
- * This is the superclass for a Field element in a PDF.
- * Based on the COS object model from PDFBox.
- *
+ * This is the superclass for a Field element in a PDF. Based on the COS
object model from PDFBox.
+ *
* @author sug
- * @version $Revision: 1.23 $
+ *
*/
public abstract class PDField implements COSObjectable
{
@@ -60,28 +54,25 @@ public abstract class PDField implements
*/
public static final int FLAG_NO_EXPORT = 1 << 2;
-
private PDAcroForm acroForm;
private COSDictionary dictionary;
/**
* Constructor.
- *
+ *
* @param theAcroForm The form that this field is part of.
*/
- public PDField( PDAcroForm theAcroForm )
+ public PDField(PDAcroForm theAcroForm)
{
acroForm = theAcroForm;
dictionary = new COSDictionary();
- //no required fields in base field class
+ // no required fields in base field class
}
-
/**
- * Creates a COSField from a COSDictionary, expected to be
- * a correct object definition for a field in PDF.
- *
+ * Creates a COSField from a COSDictionary, expected to be a correct
object definition for a field in PDF.
+ *
* @param theAcroForm The form that this field is part of.
* @param field the PDF objet to represent as a field.
*/
@@ -93,42 +84,41 @@ public abstract class PDField implements
/**
* Returns the partial name of the field.
- *
+ *
* @return the name of the field
*/
public String getPartialName()
{
- return getDictionary().getString( COSName.T );
+ return getDictionary().getString(COSName.T);
}
/**
* This will set the partial name of the field.
- *
+ *
* @param name The new name for the field.
*/
- public void setPartialName( String name )
+ public void setPartialName(String name)
{
- getDictionary().setString( COSName.T, name );
+ getDictionary().setString(COSName.T, name);
}
/**
- * Returns the fully qualified name of the field, which is a concatenation
of
- * the names of all the parents fields.
- *
+ * Returns the fully qualified name of the field, which is a concatenation
of the names of all the parents fields.
+ *
* @return the name of the field
- *
+ *
* @throws IOException If there is an error generating the fully qualified
name.
*/
public String getFullyQualifiedName() throws IOException
{
PDField parent = getParent();
String parentName = null;
- if( parent != null )
+ if (parent != null)
{
parentName = parent.getFullyQualifiedName();
}
String finalName = getPartialName();
- if( parentName != null )
+ if (parentName != null)
{
finalName = parentName + "." + finalName;
}
@@ -156,135 +146,132 @@ public abstract class PDField implements
}
/**
- * Get the FT entry of the field. This is a read only field and is set
depending
- * on the actual type. The field type is an inheritable attribute. This
method will
- * return only the direct value on this object. Use the findFieldType for
an upward
- * recursive search.
- *
+ * Get the FT entry of the field. This is a read only field and is set
depending on the actual type. The field type
+ * is an inheritable attribute. This method will return only the direct
value on this object. Use the findFieldType
+ * for an upward recursive search.
+ *
* @return The Field type.
- *
+ *
* @see PDField#findFieldType()
*/
public String getFieldType()
{
- return getDictionary().getNameAsString( COSName.FT );
+ return getDictionary().getNameAsString(COSName.FT);
}
/**
- * Find the field type and optionally do a recursive upward search.
Sometimes the fieldtype
- * will be specified on the parent instead of the direct object. This
will look at this
- * object for the field type, if none is specified then it will look to
the parent if there
- * is a parent. If there is no parent and no field type has been found
then this
+ * Find the field type and optionally do a recursive upward search.
Sometimes the fieldtype will be specified on the
+ * parent instead of the direct object. This will look at this object for
the field type, if none is specified then
+ * it will look to the parent if there is a parent. If there is no parent
and no field type has been found then this
* will return null.
- *
+ *
* @return The field type or null if none was found.
*/
public String findFieldType()
{
- return findFieldType( getDictionary() );
+ return findFieldType(getDictionary());
}
- private String findFieldType( COSDictionary dic )
+ private String findFieldType(COSDictionary dic)
{
- String retval = dic.getNameAsString( COSName.FT );
- if( retval == null )
+ String retval = dic.getNameAsString(COSName.FT);
+ if (retval == null)
{
- COSDictionary parent = (COSDictionary)dic.getDictionaryObject(
COSName.PARENT, COSName.P );
- if( parent != null )
+ COSDictionary parent = (COSDictionary)
dic.getDictionaryObject(COSName.PARENT, COSName.P);
+ if (parent != null)
{
- retval = findFieldType( parent );
+ retval = findFieldType(parent);
}
}
return retval;
}
-
/**
* setValue sets the fields value to a given string.
- *
+ *
* @param value the string value
- *
+ *
* @throws IOException If there is an error creating the appearance stream.
*/
public abstract void setValue(String value) throws IOException;
/**
* getValue gets the fields value to as a string.
- *
+ *
* @return The string value of this field.
- *
+ *
* @throws IOException If there is an error getting the value.
*/
public abstract String getValue() throws IOException;
/**
* sets the field to be read-only.
- *
+ *
* @param readonly The new flag for readonly.
*/
public void setReadonly(boolean readonly)
{
- BitFlagHelper.setFlag( getDictionary(), COSName.FF, FLAG_READ_ONLY,
readonly );
+ BitFlagHelper.setFlag(getDictionary(), COSName.FF, FLAG_READ_ONLY,
readonly);
}
/**
- *
+ *
* @return true if the field is readonly
*/
public boolean isReadonly()
{
- return BitFlagHelper.getFlag( getDictionary(), COSName.FF,
FLAG_READ_ONLY );
+ return BitFlagHelper.getFlag(getDictionary(), COSName.FF,
FLAG_READ_ONLY);
}
/**
* sets the field to be required.
- *
+ *
* @param required The new flag for required.
*/
public void setRequired(boolean required)
{
- BitFlagHelper.setFlag( getDictionary(), COSName.FF, FLAG_REQUIRED,
required );
+ BitFlagHelper.setFlag(getDictionary(), COSName.FF, FLAG_REQUIRED,
required);
}
/**
- *
+ *
* @return true if the field is required
*/
public boolean isRequired()
{
- return BitFlagHelper.getFlag( getDictionary(), COSName.FF,
FLAG_REQUIRED );
+ return BitFlagHelper.getFlag(getDictionary(), COSName.FF,
FLAG_REQUIRED);
}
/**
* sets the field to be not exported..
- *
+ *
* @param noExport The new flag for noExport.
*/
public void setNoExport(boolean noExport)
{
- BitFlagHelper.setFlag( getDictionary(), COSName.FF, FLAG_NO_EXPORT,
noExport );
+ BitFlagHelper.setFlag(getDictionary(), COSName.FF, FLAG_NO_EXPORT,
noExport);
}
/**
- *
+ *
* @return true if the field is not to be exported.
*/
public boolean isNoExport()
{
- return BitFlagHelper.getFlag( getDictionary(), COSName.FF,
FLAG_NO_EXPORT );
+ return BitFlagHelper.getFlag(getDictionary(), COSName.FF,
FLAG_NO_EXPORT);
}
/**
* This will get the flags for this field.
- *
+ *
* @return flags The set of flags.
*/
public int getFieldFlags()
{
int retval = 0;
- COSInteger ff = (COSInteger)getDictionary().getDictionaryObject(
COSName.FF );
- if( ff != null )
+ COSInteger ff = (COSInteger)
getDictionary().getDictionaryObject(COSName.FF);
+ if (ff != null)
{
retval = ff.intValue();
}
@@ -293,128 +280,128 @@ public abstract class PDField implements
/**
* This will set the flags for this field.
- *
+ *
* @param flags The new flags.
*/
- public void setFieldFlags( int flags )
+ public void setFieldFlags(int flags)
{
- getDictionary().setInt( COSName.FF, flags );
+ getDictionary().setInt(COSName.FF, flags);
}
/**
* 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
+ public void importFDF(FDFField fdfField) throws IOException
{
Object fieldValue = fdfField.getValue();
int fieldFlags = getFieldFlags();
- if( fieldValue != null )
+ if (fieldValue != null)
{
- if( fieldValue instanceof String )
+ if (fieldValue instanceof String)
{
- setValue( (String)fieldValue );
+ setValue((String) fieldValue);
}
- else if( fieldValue instanceof PDTextStream )
+ else if (fieldValue instanceof PDTextStream)
{
- setValue( ((PDTextStream)fieldValue).getAsString() );
+ setValue(((PDTextStream) fieldValue).getAsString());
}
else
{
- throw new IOException( "Unknown field type:" +
fieldValue.getClass().getName() );
+ throw new IOException("Unknown field type:" +
fieldValue.getClass().getName());
}
}
Integer ff = fdfField.getFieldFlags();
- if( ff != null )
+ if (ff != null)
{
- setFieldFlags( ff.intValue() );
+ setFieldFlags(ff.intValue());
}
else
{
- //these are suppose to be ignored if the Ff is set.
+ // these are suppose to be ignored if the Ff is set.
Integer setFf = fdfField.getSetFieldFlags();
- if( setFf != null )
+ if (setFf != null)
{
int setFfInt = setFf.intValue();
fieldFlags = fieldFlags | setFfInt;
- setFieldFlags( fieldFlags );
+ setFieldFlags(fieldFlags);
}
Integer clrFf = fdfField.getClearFieldFlags();
- if( clrFf != null )
+ if (clrFf != null)
{
- //we have to clear the bits of the document fields for every
bit that is
- //set in this field.
+ // we have to clear the bits of the document fields for every
bit that is
+ // set in this field.
//
- //Example:
- //docFf = 1011
- //clrFf = 1101
- //clrFfValue = 0010;
- //newValue = 1011 & 0010 which is 0010
+ // Example:
+ // docFf = 1011
+ // clrFf = 1101
+ // clrFfValue = 0010;
+ // newValue = 1011 & 0010 which is 0010
int clrFfValue = clrFf.intValue();
clrFfValue ^= 0xFFFFFFFF;
fieldFlags = fieldFlags & clrFfValue;
- setFieldFlags( fieldFlags );
+ setFieldFlags(fieldFlags);
}
}
PDAnnotationWidget widget = getWidget();
- if( widget != null )
+ if (widget != null)
{
int annotFlags = widget.getAnnotationFlags();
Integer f = fdfField.getWidgetFieldFlags();
- if( f != null && widget != null )
+ if (f != null && widget != null)
{
- widget.setAnnotationFlags( f.intValue() );
+ widget.setAnnotationFlags(f.intValue());
}
else
{
- //these are suppose to be ignored if the F is set.
+ // these are suppose to be ignored if the F is set.
Integer setF = fdfField.getSetWidgetFieldFlags();
- if( setF != null )
+ if (setF != null)
{
annotFlags = annotFlags | setF.intValue();
- widget.setAnnotationFlags( annotFlags );
+ widget.setAnnotationFlags(annotFlags);
}
Integer clrF = fdfField.getClearWidgetFieldFlags();
- if( clrF != null )
+ if (clrF != null)
{
- //we have to clear the bits of the document fields for
every bit that is
- //set in this field.
+ // we have to clear the bits of the document fields for
every bit that is
+ // set in this field.
//
- //Example:
- //docF = 1011
- //clrF = 1101
- //clrFValue = 0010;
- //newValue = 1011 & 0010 which is 0010
+ // Example:
+ // docF = 1011
+ // clrF = 1101
+ // clrFValue = 0010;
+ // newValue = 1011 & 0010 which is 0010
int clrFValue = clrF.intValue();
clrFValue ^= 0xFFFFFFFFL;
annotFlags = annotFlags & clrFValue;
- widget.setAnnotationFlags( annotFlags );
+ widget.setAnnotationFlags(annotFlags);
}
}
}
List<FDFField> fdfKids = fdfField.getKids();
List<COSObjectable> pdKids = getKids();
- for( int i=0; fdfKids != null && i<fdfKids.size(); i++ )
+ for (int i = 0; fdfKids != null && i < fdfKids.size(); i++)
{
- FDFField fdfChild = fdfKids.get( i );
+ FDFField fdfChild = fdfKids.get(i);
String fdfName = fdfChild.getPartialFieldName();
- for( int j=0; j<pdKids.size(); j++ )
+ for (int j = 0; j < pdKids.size(); j++)
{
- Object pdChildObj = pdKids.get( j );
- if( pdChildObj instanceof PDField )
+ Object pdChildObj = pdKids.get(j);
+ if (pdChildObj instanceof PDField)
{
- PDField pdChild = (PDField)pdChildObj;
- if( fdfName != null && fdfName.equals(
pdChild.getPartialName() ) )
+ PDField pdChild = (PDField) pdChildObj;
+ if (fdfName != null &&
fdfName.equals(pdChild.getPartialName()))
{
- pdChild.importFDF( fdfChild );
+ pdChild.importFDF(fdfChild);
}
}
}
@@ -422,12 +409,10 @@ public abstract class PDField implements
}
/**
- * This will get the single associated widget that is part of this field.
This
- * occurs when the Widget is embedded in the fields dictionary. Sometimes
there
- * are multiple sub widgets associated with this field, in which case you
want to
- * use getKids(). If the kids entry is specified, then the first entry in
that
- * list will be returned.
- *
+ * This will get the single associated widget that is part of this field.
This occurs when the Widget is embedded in
+ * the fields dictionary. Sometimes there are multiple sub widgets
associated with this field, in which case you
+ * want to use getKids(). If the kids entry is specified, then the first
entry in that list will be returned.
+ *
* @return The widget that is associated with this field.
* @throws IOException If there is an error getting the widget object.
*/
@@ -435,20 +420,20 @@ public abstract class PDField implements
{
PDAnnotationWidget retval = null;
List<COSObjectable> kids = getKids();
- if( kids == null )
+ if (kids == null)
{
- retval = new PDAnnotationWidget( getDictionary() );
+ retval = new PDAnnotationWidget(getDictionary());
}
- else if( kids.size() > 0 )
+ else if (kids.size() > 0)
{
- Object firstKid = kids.get( 0 );
- if( firstKid instanceof PDAnnotationWidget )
+ Object firstKid = kids.get(0);
+ if (firstKid instanceof PDAnnotationWidget)
{
- retval = (PDAnnotationWidget)firstKid;
+ retval = (PDAnnotationWidget) firstKid;
}
else
{
- retval = ((PDField)firstKid).getWidget();
+ retval = ((PDField) firstKid).getWidget();
}
}
else
@@ -460,58 +445,57 @@ public abstract class PDField implements
/**
* Get the parent field to this field, or null if none exists.
- *
+ *
* @return The parent field.
- *
+ *
* @throws IOException If there is an error creating the parent field.
*/
public PDField getParent() throws IOException
{
PDField parent = null;
- COSDictionary parentDic =
(COSDictionary)getDictionary().getDictionaryObject( COSName.PARENT, COSName.P );
- if( parentDic != null )
+ COSDictionary parentDic = (COSDictionary)
getDictionary().getDictionaryObject(COSName.PARENT, COSName.P);
+ if (parentDic != null)
{
- parent = PDFieldFactory.createField( getAcroForm(), parentDic );
+ parent = PDFieldFactory.createField(getAcroForm(), parentDic);
}
return parent;
}
/**
* Set the parent of this field.
- *
+ *
* @param parent The parent to this field.
*/
- public void setParent( PDField parent )
+ public void setParent(PDField parent)
{
- getDictionary().setItem( "Parent", parent );
+ getDictionary().setItem("Parent", 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.
- *
+ * 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.
+ *
* @param name An array that picks the path to the field.
* @param nameIndex The index into the array.
* @return The field at the endpoint or null if none is found.
* @throws IOException If there is an error creating the field.
*/
- public PDField findKid( String[] name, int nameIndex ) throws IOException
+ public PDField findKid(String[] name, int nameIndex) throws IOException
{
PDField retval = null;
- COSArray kids = (COSArray)getDictionary().getDictionaryObject(
COSName.KIDS );
- if( kids != null )
+ COSArray kids = (COSArray)
getDictionary().getDictionaryObject(COSName.KIDS);
+ if (kids != null)
{
for (int i = 0; retval == null && i < kids.size(); i++)
{
- COSDictionary kidDictionary = (COSDictionary)kids.getObject(i);
- if( name[nameIndex].equals( kidDictionary.getString( "T" ) ) )
+ COSDictionary kidDictionary = (COSDictionary)
kids.getObject(i);
+ if (name[nameIndex].equals(kidDictionary.getString("T")))
{
- retval = PDFieldFactory.createField( acroForm,
kidDictionary );
- if( name.length > nameIndex+1 )
+ retval = PDFieldFactory.createField(acroForm,
kidDictionary);
+ if (name.length > nameIndex + 1)
{
- retval = retval.findKid( name, nameIndex+1 );
+ retval = retval.findKid(name, nameIndex + 1);
}
}
}
@@ -520,69 +504,72 @@ public abstract class PDField implements
}
/**
- * This will get all the kids of this field. The values in the list
- * will either be PDWidget or PDField. Normally they will be PDWidget
objects
- * unless this is a non-terminal field and they will be child PDField
objects.
- *
+ * This will get all the kids of this field. The values in the list will
either be PDWidget or PDField. Normally
+ * they will be PDWidget objects unless this is a non-terminal field and
they will be child PDField objects.
+ *
* @return A list of either PDWidget or PDField objects.
* @throws IOException If there is an error retrieving the kids.
*/
public List<COSObjectable> getKids() throws IOException
{
List<COSObjectable> retval = null;
- COSArray kids =
(COSArray)getDictionary().getDictionaryObject(COSName.KIDS);
- if( kids != null )
+ COSArray kids = (COSArray)
getDictionary().getDictionaryObject(COSName.KIDS);
+ if (kids != null)
{
List<COSObjectable> kidsList = new ArrayList<COSObjectable>();
for (int i = 0; i < kids.size(); i++)
{
- COSDictionary kidDictionary = (COSDictionary)kids.getObject(i);
- COSDictionary parent =
(COSDictionary)kidDictionary.getDictionaryObject( COSName.PARENT, COSName.P );
- if( kidDictionary.getDictionaryObject( COSName.FT ) != null ||
- (parent != null && parent.getDictionaryObject( COSName.FT
) != null ) )
+ COSDictionary kidDictionary = (COSDictionary)
kids.getObject(i);
+ if (kidDictionary == null)
+ {
+ continue;
+ }
+ COSDictionary parent = (COSDictionary)
kidDictionary.getDictionaryObject(COSName.PARENT, COSName.P);
+ if (kidDictionary.getDictionaryObject(COSName.FT) != null
+ || (parent != null &&
parent.getDictionaryObject(COSName.FT) != null))
{
- kidsList.add( PDFieldFactory.createField( acroForm,
kidDictionary ));
+ kidsList.add(PDFieldFactory.createField(acroForm,
kidDictionary));
}
- else if( "Widget".equals( kidDictionary.getNameAsString(
COSName.SUBTYPE ) ) )
+ else if
("Widget".equals(kidDictionary.getNameAsString(COSName.SUBTYPE)))
{
- kidsList.add( new PDAnnotationWidget( kidDictionary ) );
+ kidsList.add(new PDAnnotationWidget(kidDictionary));
}
else
{
//
- kidsList.add( PDFieldFactory.createField( acroForm,
kidDictionary ));
+ kidsList.add(PDFieldFactory.createField(acroForm,
kidDictionary));
}
}
- retval = new COSArrayList( kidsList, kids );
+ retval = new COSArrayList<COSObjectable>(kidsList, kids);
}
return retval;
}
/**
* This will set the list of kids.
- *
+ *
* @param kids The list of child widgets.
*/
- public void setKids( List<COSObjectable> kids )
+ public void setKids(List<COSObjectable> kids)
{
- COSArray kidsArray = COSArrayList.converterToCOSArray( kids );
- getDictionary().setItem( COSName.KIDS, kidsArray );
+ 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 "" + getDictionary().getDictionaryObject( COSName.V );
+ return "" + getDictionary().getDictionaryObject(COSName.V);
}
/**
* This will get the acroform that this field is part of.
- *
+ *
* @return The form this field is on.
*/
public PDAcroForm getAcroForm()
@@ -592,7 +579,7 @@ public abstract class PDField implements
/**
* This will set the form this field is on.
- *
+ *
* @param value The new form to use.
*/
public void setAcroForm(PDAcroForm value)
@@ -602,7 +589,7 @@ public abstract class PDField implements
/**
* This will get the dictionary associated with this field.
- *
+ *
* @return The dictionary that this class wraps.
*/
public COSDictionary getDictionary()
@@ -612,7 +599,7 @@ public abstract class PDField implements
/**
* Convert this standard java object to a COS object.
- *
+ *
* @return The cos object that matches this Java object.
*/
public COSBase getCOSObject()
@@ -621,29 +608,29 @@ public abstract class PDField implements
}
/**
- * Get the additional actions for this field. This will return null
- * if there are no additional actions for this field.
- *
+ * Get the additional actions for this field. This will return null if
there are no additional actions for this
+ * field.
+ *
* @return The actions of the field.
*/
public PDFormFieldAdditionalActions getActions()
{
- COSDictionary aa = (COSDictionary)dictionary.getDictionaryObject(
COSName.AA );
+ COSDictionary aa = (COSDictionary)
dictionary.getDictionaryObject(COSName.AA);
PDFormFieldAdditionalActions retval = null;
- if( aa != null )
+ if (aa != null)
{
- retval = new PDFormFieldAdditionalActions( aa );
+ retval = new PDFormFieldAdditionalActions(aa);
}
return retval;
}
/**
* Set the actions of the field.
- *
+ *
* @param actions The field actions.
*/
- public void setActions( PDFormFieldAdditionalActions actions )
+ public void setActions(PDFormFieldAdditionalActions actions)
{
- dictionary.setItem( COSName.AA, actions );
+ dictionary.setItem(COSName.AA, actions);
}
}