You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2014/08/16 17:21:10 UTC
svn commit: r1618374 [2/2] - in /pdfbox/trunk:
examples/src/main/java/org/apache/pdfbox/examples/fdf/
pdfbox/src/main/java/org/apache/pdfbox/pdmodel/
pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/digitalsignature/visible/
pdfbox/src/main/j...
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java?rev=1618374&r1=1618373&r2=1618374&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java Sat Aug 16 15:21:09 2014
@@ -17,14 +17,11 @@
package org.apache.pdfbox.pdmodel.interactive.form;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.List;
-import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSName;
-
-import org.apache.pdfbox.pdmodel.common.COSArrayList;
+import org.apache.pdfbox.pdmodel.common.COSObjectable;
/**
* Radio button fields contain a set of related buttons that can each be on or off.
@@ -33,20 +30,17 @@ import org.apache.pdfbox.pdmodel.common.
*/
public final class PDRadioButton extends PDButton
{
- /**
- * A Ff flag.
- */
- public static final int FLAG_RADIOS_IN_UNISON = 1 << 25;
/**
- * @param theAcroForm The acroForm for this field.
- * @param field The field that makes up the radio collection.
- *
- * {@inheritDoc}
+ * Constructor.
+ *
+ * @param theAcroForm 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
*/
- public PDRadioButton(PDAcroForm theAcroForm, COSDictionary field)
+ public PDRadioButton(PDAcroForm theAcroForm, COSDictionary field, PDFieldTreeNode parentNode)
{
- super(theAcroForm,field);
+ super(theAcroForm, field, parentNode);
}
/**
@@ -85,13 +79,12 @@ public final class PDRadioButton extends
public void setValue(String value) throws IOException
{
getDictionary().setString( COSName.V, value );
- List kids = getKids();
- for (Object kid : kids)
+ List<COSObjectable> kids = getKids();
+ for (COSObjectable kid : kids)
{
- PDField field = (PDField) kid;
- if ( field instanceof PDCheckbox )
+ if ( kid instanceof PDCheckbox )
{
- PDCheckbox btn = (PDCheckbox)field;
+ PDCheckbox btn = (PDCheckbox)kid;
if( btn.getOnValue().equals(value) )
{
btn.check();
@@ -115,13 +108,12 @@ public final class PDRadioButton extends
public String getValue() throws IOException
{
String retval = null;
- List kids = getKids();
- for (Object kid : kids)
+ List<COSObjectable> kids = getKids();
+ for (COSObjectable kid : kids)
{
- PDField field = (PDField) kid;
- if ( field instanceof PDCheckbox )
+ if ( kid instanceof PDCheckbox )
{
- PDCheckbox btn = (PDCheckbox)field;
+ PDCheckbox btn = (PDCheckbox)kid;
if( btn.isChecked() )
{
retval = btn.getOnValue();
@@ -135,34 +127,4 @@ public final class PDRadioButton extends
return retval;
}
-
- /**
- * This will return a list of PDField objects that are part of this radio collection.
- *
- * @see PDField#getWidget()
- * @return A list of PDWidget objects.
- * @throws IOException if there is an error while creating the children objects.
- */
- @SuppressWarnings("unchecked")
- public List getKids() throws IOException
- {
- COSArray kids = (COSArray)getDictionary().getDictionaryObject(COSName.KIDS);
- if( kids != null )
- {
- List kidsList = new ArrayList();
- for (int i = 0; i < kids.size(); i++)
- {
- PDField field = PDFieldFactory.createField( getAcroForm(), (COSDictionary)kids.getObject(i) );
- if (field != null)
- {
- kidsList.add( field );
- }
- }
- return new COSArrayList( kidsList, kids );
- }
- else
- {
- return new ArrayList();
- }
- }
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDSignatureField.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDSignatureField.java?rev=1618374&r1=1618373&r2=1618374&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDSignatureField.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDSignatureField.java Sat Aug 16 15:21:09 2014
@@ -37,15 +37,15 @@ import java.util.Set;
public class PDSignatureField extends PDField
{
/**
- * @see PDField#PDField(PDAcroForm,COSDictionary)
- *
- * @param theAcroForm The acroForm for this field.
- * @param field The dictionary for the signature.
- * @throws IOException If there is an error while resolving partital name for the signature field
+ * Constructor.
+ *
+ * @param theAcroForm 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
*/
- public PDSignatureField(PDAcroForm theAcroForm, COSDictionary field) throws IOException
+ public PDSignatureField(PDAcroForm theAcroForm, COSDictionary field, PDFieldTreeNode parentNode)
{
- super(theAcroForm,field);
+ super(theAcroForm, field, parentNode);
// dirty hack to avoid npe caused through getWidget() method
getDictionary().setItem( COSName.TYPE, COSName.ANNOT );
getDictionary().setName( COSName.SUBTYPE, PDAnnotationWidget.SUB_TYPE);
@@ -72,31 +72,26 @@ public class PDSignatureField extends PD
/**
* Generate a unique name for the signature.
* @return the signature's unique name
- * @throws IOException If there is an error while getting the list of fields.
*/
- private String generatePartialName() throws IOException
+ private String generatePartialName()
{
- PDAcroForm acroForm = getAcroForm();
- List fields = acroForm.getFields();
-
- String fieldName = "Signature";
- int i = 1;
-
- Set<String> sigNames = new HashSet<String>();
-
- for ( Object object : fields )
- {
- if(object instanceof PDSignatureField)
+ PDAcroForm acroForm = getAcroForm();
+ List<PDFieldTreeNode> fields = acroForm.getFields();
+ String fieldName = "Signature";
+ Set<String> sigNames = new HashSet<String>();
+ for ( PDFieldTreeNode field : fields )
{
- sigNames.add(((PDSignatureField) object).getPartialName());
+ if(field instanceof PDSignatureField)
+ {
+ sigNames.add(field.getPartialName());
+ }
}
- }
-
- while(sigNames.contains(fieldName+i))
- {
- ++i;
- }
- return fieldName+i;
+ int i = 1;
+ while(sigNames.contains(fieldName+i))
+ {
+ ++i;
+ }
+ return fieldName+i;
}
/**
@@ -147,7 +142,7 @@ public class PDSignatureField extends PD
*/
public void setSignature(PDSignature value)
{
- getDictionary().setItem(COSName.V, value);
+ getDictionary().setItem(COSName.V, value);
}
/**
@@ -158,12 +153,12 @@ public class PDSignatureField extends PD
*/
public PDSignature getSignature()
{
- COSBase dictionary = getDictionary().getDictionaryObject(COSName.V);
- if (dictionary == null)
- {
- return null;
- }
- return new PDSignature((COSDictionary)dictionary);
+ COSBase dictionary = getDictionary().getDictionaryObject(COSName.V);
+ if (dictionary == null)
+ {
+ return null;
+ }
+ return new PDSignature((COSDictionary)dictionary);
}
/**
@@ -175,13 +170,13 @@ public class PDSignatureField extends PD
*/
public PDSeedValue getSeedValue()
{
- COSDictionary dict = (COSDictionary)getDictionary().getDictionaryObject(COSName.SV);
- PDSeedValue sv = null;
- if (dict != null)
- {
- sv = new PDSeedValue(dict);
- }
- return sv;
+ COSDictionary dict = (COSDictionary)getDictionary().getDictionaryObject(COSName.SV);
+ PDSeedValue sv = null;
+ if (dict != null)
+ {
+ sv = new PDSeedValue(dict);
+ }
+ return sv;
}
/**
@@ -193,9 +188,9 @@ public class PDSignatureField extends PD
*/
public void setSeedValue(PDSeedValue sv)
{
- if (sv != null)
- {
- getDictionary().setItem(COSName.SV, sv.getCOSObject());
- }
+ if (sv != null)
+ {
+ getDictionary().setItem(COSName.SV, sv.getCOSObject());
+ }
}
}
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextField.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextField.java?rev=1618374&r1=1618373&r2=1618374&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextField.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextField.java Sat Aug 16 15:21:09 2014
@@ -27,8 +27,9 @@ import org.apache.pdfbox.cos.COSName;
*/
public final class PDTextField extends PDVariableText
{
+
/**
- * @see PDField#PDField(PDAcroForm,COSDictionary)
+ * @see PDFieldTreeNode#PDFieldTreeNode(PDAcroForm)(PDAcroForm,COSDictionary)
*
* @param theAcroForm The acroform.
*/
@@ -38,14 +39,15 @@ public final class PDTextField extends P
}
/**
- * @see org.apache.pdfbox.pdmodel.interactive.form.PDField#PDField(PDAcroForm,COSDictionary)
- *
- * @param theAcroForm The acroForm for this field.
- * @param field The field's dictionary.
+ * Constructor.
+ *
+ * @param theAcroForm 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
*/
- public PDTextField(PDAcroForm theAcroForm, COSDictionary field)
+ public PDTextField(PDAcroForm theAcroForm, COSDictionary field, PDFieldTreeNode parentNode)
{
- super( theAcroForm, field);
+ super( theAcroForm, field, parentNode);
}
/**
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDVariableText.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDVariableText.java?rev=1618374&r1=1618373&r2=1618374&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDVariableText.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDVariableText.java Sat Aug 16 15:21:09 2014
@@ -29,7 +29,7 @@ import java.io.IOException;
*
* @author Ben Litchfield
*/
-public abstract class PDVariableText extends PDField // TODO mixin, not really a field
+public abstract class PDVariableText extends PDField
{
/**
* A Ff flag.
@@ -95,14 +95,15 @@ public abstract class PDVariableText ext
}
/**
- * @see org.apache.pdfbox.pdmodel.interactive.form.PDField#PDField(PDAcroForm,COSDictionary)
- *
- * @param theAcroForm The acroForm for this field.
- * @param field The field's dictionary.
+ * Constructor.
+ *
+ * @param theAcroForm 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
*/
- PDVariableText(PDAcroForm theAcroForm, COSDictionary field)
+ protected PDVariableText(PDAcroForm theAcroForm, COSDictionary field, PDFieldTreeNode parentNode)
{
- super( theAcroForm, field);
+ super( theAcroForm, field, parentNode);
da = (COSString) field.getDictionaryObject(COSName.DA);
}
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=1618374&r1=1618373&r2=1618374&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 15:21:09 2014
@@ -50,8 +50,8 @@ 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.PDField;
import org.apache.pdfbox.pdmodel.interactive.form.PDFieldFactory;
+import org.apache.pdfbox.pdmodel.interactive.form.PDFieldTreeNode;
/**
* This class will take a list of pdf documents and merge them, saving the
@@ -544,28 +544,28 @@ public class PDFMergerUtility
private void mergeAcroForm(PDFCloneUtility cloner, PDAcroForm destAcroForm, PDAcroForm srcAcroForm)
throws IOException
{
- List destFields = destAcroForm.getFields();
- List srcFields = srcAcroForm.getFields();
+ List<PDFieldTreeNode> destFields = destAcroForm.getFields();
+ List<PDFieldTreeNode> srcFields = srcAcroForm.getFields();
if (srcFields != null)
{
if (destFields == null)
{
- destFields = new COSArrayList();
+ destFields = new COSArrayList<PDFieldTreeNode>();
destAcroForm.setFields(destFields);
}
- Iterator srcFieldsIterator = srcFields.iterator();
+ Iterator<PDFieldTreeNode> srcFieldsIterator = srcFields.iterator();
while (srcFieldsIterator.hasNext())
{
- PDField srcField = (PDField) srcFieldsIterator.next();
- PDField destField = PDFieldFactory.createField(destAcroForm,
- (COSDictionary) cloner.cloneForNewDocument(srcField.getDictionary()));
+ PDFieldTreeNode srcField = srcFieldsIterator.next();
+ PDFieldTreeNode destFieldNode = PDFieldFactory.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.
- if (destAcroForm.getField(destField.getFullyQualifiedName()) != null)
+ if (destAcroForm.getField(destFieldNode.getFullyQualifiedName()) != null)
{
- destField.setPartialName("dummyFieldName" + (nextFieldNum++));
+ destFieldNode.setPartialName("dummyFieldName" + (nextFieldNum++));
}
- destFields.add(destField);
+ destFields.add(destFieldNode);
}
}
}
Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java?rev=1618374&r1=1618373&r2=1618374&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java Sat Aug 16 15:21:09 2014
@@ -26,22 +26,24 @@ import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.cos.COSStream;
import org.apache.pdfbox.cos.COSString;
import org.apache.pdfbox.pdfparser.PDFStreamParser;
+import org.apache.pdfbox.pdmodel.common.COSObjectable;
import org.apache.pdfbox.pdmodel.fdf.FDFDocument;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
-import org.apache.pdfbox.pdmodel.interactive.form.PDField;
+import org.apache.pdfbox.pdmodel.interactive.form.PDFieldTreeNode;
import org.apache.pdfbox.pdmodel.interactive.form.PDRadioButton;
import org.apache.pdfbox.pdmodel.interactive.form.PDTextField;
/**
* This will test the FDF algorithms in PDFBox.
*
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
- * @version $Revision: 1.7 $
+ * @author Ben Litchfield
+ *
*/
public class TestFDF extends TestCase
{
@@ -182,8 +184,6 @@ public class TestFDF extends TestCase
PDRadioButton feld3 = (PDRadioButton)form.getField( "Feld.3" );
feld3.setValue("RB1");
assertEquals( "RB1", feld3.getValue() );
- //assertEquals( ((PDCheckbox)feld3.getKids().get( 0 )).getValue(), "RB1" );
-
}
finally
{
@@ -215,16 +215,16 @@ public class TestFDF extends TestCase
PDAcroForm form = freedom.getDocumentCatalog().getAcroForm();
form.importFDF( fdf );
PDTextField feld2 = (PDTextField)form.getField( "eeFirstName" );
- List kids = feld2.getKids();
- PDField firstKid = (PDField)kids.get( 0 );
- PDField secondKid = (PDField)kids.get( 1 );
+ List<COSObjectable> kids = feld2.getKids();
+ PDFieldTreeNode firstKid = (PDFieldTreeNode)kids.get( 0 );
+ PDFieldTreeNode secondKid = (PDFieldTreeNode)kids.get( 1 );
testContentStreamContains( freedom, firstKid, "Steve" );
testContentStreamContains( freedom, secondKid, "Steve" );
//the appearance stream is suppose to be null because there
//is an F action in the AA dictionary that populates that field.
- PDField totalAmt = form.getField( "eeSuppTotalAmt" );
- assertTrue( totalAmt.getDictionary().getDictionaryObject( "AP" ) == null );
+ PDFieldTreeNode totalAmt = form.getField( "eeSuppTotalAmt" );
+ assertTrue( totalAmt.getDictionary().getDictionaryObject( COSName.AP ) == null );
}
finally
@@ -241,26 +241,26 @@ public class TestFDF extends TestCase
}
}
- private void testContentStreamContains( PDDocument doc, PDField field, String expected ) throws Exception
+ private void testContentStreamContains( PDDocument doc, PDFieldTreeNode field, String expected ) throws Exception
{
PDAnnotationWidget widget = field.getWidget();
- Map normalAppearance = widget.getAppearance().getNormalAppearance();
- PDAppearanceStream appearanceStream = (PDAppearanceStream)normalAppearance.get( "default" );
+ Map<String,PDAppearanceStream> normalAppearance = widget.getAppearance().getNormalAppearance();
+ PDAppearanceStream appearanceStream = normalAppearance.get( "default" );
COSStream actual = appearanceStream.getStream();
- List actualTokens = getStreamTokens( doc, actual );
+ List<Object> actualTokens = getStreamTokens( doc, actual );
assertTrue( actualTokens.contains( new COSString( expected ) ) );
}
- private void testContentStreams( PDDocument doc, PDField field, String expected ) throws Exception
+ private void testContentStreams( PDDocument doc, PDFieldTreeNode field, String expected ) throws Exception
{
PDAnnotationWidget widget = field.getWidget();
- Map normalAppearance = widget.getAppearance().getNormalAppearance();
- PDAppearanceStream appearanceStream = (PDAppearanceStream)normalAppearance.get( "default" );
+ Map<String,PDAppearanceStream> normalAppearance = widget.getAppearance().getNormalAppearance();
+ PDAppearanceStream appearanceStream = normalAppearance.get( "default" );
COSStream actual = appearanceStream.getStream();
- List actualTokens = getStreamTokens( doc, actual );
- List expectedTokens = getStreamTokens( doc, expected );
+ List<Object> actualTokens = getStreamTokens( doc, actual );
+ List<Object> expectedTokens = getStreamTokens( doc, expected );
assertEquals( actualTokens.size(), expectedTokens.size() );
for( int i=0; i<actualTokens.size(); i++ )
{
@@ -270,11 +270,11 @@ public class TestFDF extends TestCase
}
}
- private List getStreamTokens( PDDocument doc, String string ) throws IOException
+ private List<Object> getStreamTokens( PDDocument doc, String string ) throws IOException
{
PDFStreamParser parser;
- List tokens = null;
+ List<Object> tokens = null;
if( string != null )
{
ByteArrayInputStream stream = new ByteArrayInputStream( string.getBytes() );
@@ -285,11 +285,11 @@ public class TestFDF extends TestCase
return tokens;
}
- private List getStreamTokens( PDDocument doc, COSStream stream ) throws IOException
+ private List<Object> getStreamTokens( PDDocument doc, COSStream stream ) throws IOException
{
PDFStreamParser parser;
- List tokens = null;
+ List<Object> tokens = null;
if( stream != null )
{
parser = new PDFStreamParser( stream );