use of org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField in project pdfbox by apache.
the class AcroFormValidationProcess method validateField.
/**
* A and AA field are forbidden, this method checks if they are present and checks all children of this field. If the
* an Additional Action is present the error code ERROR_ACTION_FORBIDDEN_ADDITIONAL_ACTIONS_FIELD (6.2.3) is added
* to the error list If the an Action is present (in the Widget Annotation) the error
* ERROR_ACTION_FORBIDDEN_WIDGET_ACTION_FIELD (6.2.4) is added to the error list. (Remark : The widget validation
* will be done by the AnnotationValidationHelper, but some actions are authorized in a standard Widget)
*
* @param ctx the preflight context.
* @param field an acro forms field.
* @return the result of the check for A or AA entries.
* @throws IOException
*/
protected boolean validateField(PreflightContext ctx, PDField field) throws IOException {
boolean res = true;
PDFormFieldAdditionalActions aa = field.getActions();
if (aa != null) {
addValidationError(ctx, new ValidationError(ERROR_ACTION_FORBIDDEN_ADDITIONAL_ACTIONS_FIELD, "\"AA\" must not be used in a Field dictionary"));
res = false;
}
if (field instanceof PDTerminalField) {
// The widget validation will be done by the widget annotation, a widget contained in a Field can't have action.
List<PDAnnotationWidget> widgets = field.getWidgets();
if (res && widgets != null) {
for (PDAnnotationWidget widget : widgets) {
ContextHelper.validateElement(ctx, widget.getCOSObject(), ANNOTATIONS_PROCESS);
COSBase act = widget.getCOSObject().getDictionaryObject(COSName.A);
if (act != null) {
addValidationError(ctx, new ValidationError(ERROR_ACTION_FORBIDDEN_WIDGET_ACTION_FIELD, "\"A\" must not be used in a widget annotation"));
return false;
}
}
}
return exploreWidgets(ctx, field.getWidgets());
} else {
return res && exploreFields(ctx, ((PDNonTerminalField) field).getChildren());
}
}
Aggregations