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/06/26 13:14:55 UTC
svn commit: r1687753 - in
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form:
PDButton.java PDPushButton.java
Author: msahyoun
Date: Fri Jun 26 11:14:54 2015
New Revision: 1687753
URL: http://svn.apache.org/r1687753
Log:
PDFBOX-2841: new method to get/set the fields export values
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDPushButton.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java?rev=1687753&r1=1687752&r2=1687753&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java Fri Jun 26 11:14:54 2015
@@ -163,6 +163,61 @@ public abstract class PDButton extends P
dictionary.setItem(COSName.OPT, cosValues);
}
+
+ /**
+ * This will get the export values.
+ *
+ * <p>The export values are defined in the field dictionaries /Opt key.</p>
+ *
+ * <p>The option values are used to define the export values
+ * for the field to
+ * <ul>
+ * <li>hold values in non-Latin writing systems as name objects, which represent the field value, are limited
+ * to PDFDocEncoding
+ * </li>
+ * <li>allow radio buttons having the same export value to be handled independently
+ * </li>
+ * </ul>
+ * </p>
+ *
+ * @return List containing all possible export values. If there is no Opt entry an empty list will be returned.
+ */
+ public List<String> getExportValues()
+ {
+ COSBase value = getInheritableAttribute(COSName.OPT);
+ if (value instanceof COSString)
+ {
+ List<String> array = new ArrayList<String>();
+ array.add(((COSString) value).getString());
+ return array;
+ }
+ else if (value instanceof COSArray)
+ {
+ return COSArrayList.convertCOSStringCOSArrayToList((COSArray)value);
+ }
+ return Collections.emptyList();
+ }
+
+ /**
+ * This will set the export values.
+ *
+ * @see #getExportValues()
+ * @param values List containing all possible export values. Supplying null or an empty list will remove the Opt entry.
+ */
+ public void setExportValues(List<String> values)
+ {
+ COSArray cosValues = null;
+ if (values != null && !values.isEmpty())
+ {
+ cosValues = COSArrayList.convertStringListToCOSStringCOSArray(values);
+ dictionary.setItem(COSName.OPT, cosValues);
+ }
+ else
+ {
+ dictionary.removeItem(COSName.OPT);
+ }
+ }
+
@Override
void constructAppearances() throws IOException
{
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDPushButton.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDPushButton.java?rev=1687753&r1=1687752&r2=1687753&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDPushButton.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDPushButton.java Fri Jun 26 11:14:54 2015
@@ -68,6 +68,21 @@ public class PDPushButton extends PDButt
}
@Override
+ public List<String> getExportValues()
+ {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public void setExportValues(List<String> values)
+ {
+ if (values != null && !values.isEmpty())
+ {
+ throw new IllegalArgumentException("A PDPushButton shall not use the Opt entry in the field dictionary");
+ }
+ }
+
+ @Override
public String getValueAsString()
{
return "";