You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ms...@apache.org on 2015/09/08 18:09:21 UTC
svn commit: r1701829 -
/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDField.java
Author: msahyoun
Date: Tue Sep 8 16:09:20 2015
New Revision: 1701829
URL: http://svn.apache.org/r1701829
Log:
PDFBOX-2964: implement getWidgets() to avoid IOException
Modified:
pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDField.java
Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDField.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDField.java?rev=1701829&r1=1701828&r2=1701829&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDField.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDField.java Tue Sep 8 16:09:20 2015
@@ -459,36 +459,31 @@ public abstract class PDField implements
* empty List is returned.
*
* @return The list of widget annotations.
- * @throws IOException
*/
- public List<PDAnnotationWidget> getWidgets() throws IOException
+ public List<PDAnnotationWidget> getWidgets()
{
List<PDAnnotationWidget> widgets = new ArrayList<PDAnnotationWidget>();
- List<COSObjectable> kids = getKids();
+
+ COSArray kids = (COSArray) getDictionary().getDictionaryObject(COSName.KIDS);
if (kids == null)
{
// the field itself is a widget
widgets.add(new PDAnnotationWidget(getDictionary()));
}
- else if (kids.size() > 0)
+ else
{
- Object firstKid = kids.get(0);
-
- /*
- * If this happens the current field is not a terminal field.
- * Return an empty list as there are no widgets associated to non
- * terminal fields.
- */
- if (firstKid instanceof PDField)
+ for (int i = 0; i < kids.size(); i++)
{
- return widgets;
- }
- else
- {
- // there are multiple widgets
- for (COSObjectable kid : kids)
+ COSDictionary kidDictionary = (COSDictionary) kids.getObject(i);
+
+ if (kidDictionary == null)
+ {
+ continue;
+ }
+
+ if ("Widget".equals(kidDictionary.getNameAsString(COSName.SUBTYPE)))
{
- widgets.add((PDAnnotationWidget) kid);
+ widgets.add(new PDAnnotationWidget(kidDictionary));
}
}
}