Search in sources :

Example 1 with PDTerminalField

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());
    }
}
Also used : PDFormFieldAdditionalActions(org.apache.pdfbox.pdmodel.interactive.action.PDFormFieldAdditionalActions) PDTerminalField(org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField) PDAnnotationWidget(org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget) COSBase(org.apache.pdfbox.cos.COSBase) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError) PDNonTerminalField(org.apache.pdfbox.pdmodel.interactive.form.PDNonTerminalField)

Aggregations

COSBase (org.apache.pdfbox.cos.COSBase)1 PDFormFieldAdditionalActions (org.apache.pdfbox.pdmodel.interactive.action.PDFormFieldAdditionalActions)1 PDAnnotationWidget (org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget)1 PDNonTerminalField (org.apache.pdfbox.pdmodel.interactive.form.PDNonTerminalField)1 PDTerminalField (org.apache.pdfbox.pdmodel.interactive.form.PDTerminalField)1 ValidationError (org.apache.pdfbox.preflight.ValidationResult.ValidationError)1