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/07/01 18:57:28 UTC
svn commit: r1688690 -
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
Author: msahyoun
Date: Wed Jul 1 16:57:27 2015
New Revision: 1688690
URL: http://svn.apache.org/r1688690
Log:
PDFBOX-2849, PDFBOX-2841: check if value to be set is within the defined values
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
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=1688690&r1=1688689&r2=1688690&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 Wed Jul 1 16:57:27 2015
@@ -185,21 +185,29 @@ public final class PDRadioButton extends
*/
public void setValue(String value) throws IOException
{
- dictionary.setName(COSName.V, value);
- // update the appearance state (AS)
- for (PDAnnotationWidget widget : getWidgets())
+ List<String> onValues = getOnValues();
+ if (COSName.Off.getName().compareTo(value) != 0 && !onValues.contains(value))
{
- PDAppearanceEntry appearanceEntry = widget.getAppearance().getNormalAppearance();
- if (((COSDictionary)appearanceEntry.getCOSObject()).containsKey(value))
- {
- widget.getCOSObject().setName(COSName.AS, value);
- }
- else
+ throw new IllegalArgumentException(value + " is not a valid option for the radio button " + getFullyQualifiedName());
+ }
+ else
+ {
+ dictionary.setName(COSName.V, value);
+ // update the appearance state (AS)
+ for (PDAnnotationWidget widget : getWidgets())
{
- widget.getCOSObject().setItem(COSName.AS, COSName.Off);
+ PDAppearanceEntry appearanceEntry = widget.getAppearance().getNormalAppearance();
+ if (((COSDictionary)appearanceEntry.getCOSObject()).containsKey(value))
+ {
+ widget.getCOSObject().setName(COSName.AS, value);
+ }
+ else
+ {
+ widget.getCOSObject().setItem(COSName.AS, COSName.Off);
+ }
}
+ applyChange();
}
- applyChange();
}
/**
@@ -210,7 +218,15 @@ public final class PDRadioButton extends
*/
public void setDefaultValue(String value) throws IOException
{
- dictionary.setName(COSName.DV, value);
+ List<String> onValues = getOnValues();
+ if (COSName.Off.getName().compareTo(value) != 0 && !onValues.contains(value))
+ {
+ throw new IllegalArgumentException(value + " is not a valid option for the radio button " + getFullyQualifiedName());
+ }
+ else
+ {
+ dictionary.setName(COSName.DV, value);
+ }
}