Search in sources :

Example 81 with ValidationError

use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.

the class PDFAIdentificationValidation method validatePDFAIdentifer.

/**
 * Check if PDFAIdentification is valid
 *
 * @param metadata the XMP MetaData.
 * @return the list of validation errors.
 * @throws ValidationException
 */
public List<ValidationError> validatePDFAIdentifer(XMPMetadata metadata) throws ValidationException {
    List<ValidationError> ve = new ArrayList<>();
    PDFAIdentificationSchema id = metadata.getPDFIdentificationSchema();
    if (id == null) {
        ve.add(new ValidationError(ERROR_METADATA_PDFA_ID_MISSING, "PDF/A identification schema " + PDFAIdentificationSchema.class.getAnnotation(StructuredType.class).namespace() + " is missing"));
        return ve;
    }
    // According to the PDF/A specification, the prefix must be pdfaid for this schema.
    StructuredType stBasic = XMPBasicSchema.class.getAnnotation(StructuredType.class);
    StructuredType stPdfaIdent = PDFAIdentificationSchema.class.getAnnotation(StructuredType.class);
    if (!id.getPrefix().equals(stPdfaIdent.preferedPrefix())) {
        if (metadata.getSchema(stPdfaIdent.preferedPrefix(), stBasic.namespace()) == null) {
            ve.add(unexpectedPrefixFoundError(id.getPrefix(), stPdfaIdent.preferedPrefix(), PDFAIdentificationSchema.class.getName()));
        } else {
            id = (PDFAIdentificationSchema) metadata.getSchema(stPdfaIdent.preferedPrefix(), stPdfaIdent.namespace());
        }
    }
    checkConformanceLevel(ve, id.getConformance());
    checkPartNumber(ve, id.getPart() == null ? -1 : id.getPart());
    return ve;
}
Also used : PDFAIdentificationSchema(org.apache.xmpbox.schema.PDFAIdentificationSchema) ArrayList(java.util.ArrayList) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError) StructuredType(org.apache.xmpbox.type.StructuredType)

Example 82 with ValidationError

use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.

the class GoToAction method innerValid.

/*
     * (non-Javadoc)
     * 
     * @see AbstractActionManager#valid(java.util.List)
     */
@Override
protected boolean innerValid() throws ValidationException {
    COSBase dest = this.actionDictionnary.getItem(COSName.D);
    // ---- D entry is mandatory
    if (dest == null) {
        context.addValidationError(new ValidationError(ERROR_ACTION_MISING_KEY, "D entry is mandatory for the GoToActions"));
        return false;
    }
    ContextHelper.validateElement(context, dest, DESTINATION_PROCESS);
    return true;
}
Also used : COSBase(org.apache.pdfbox.cos.COSBase) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError)

Example 83 with ValidationError

use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.

the class HideAction method innerValid.

/*
     * (non-Javadoc)
     * 
     * @see net.awl.edoc.pdfa.validation.actions.AbstractActionManager#valid(java.util .List)
     */
@Override
protected boolean innerValid() {
    COSBase t = this.actionDictionnary.getItem(COSName.T);
    // ---- T entry is mandatory
    if (t == null) {
        context.addValidationError(new ValidationError(ERROR_ACTION_MISING_KEY, "T entry is mandatory for the NamedActions"));
        return false;
    }
    COSDocument cosDocument = this.context.getDocument().getDocument();
    if (!(COSUtils.isDictionary(t, cosDocument) || COSUtils.isArray(t, cosDocument) || COSUtils.isString(t, cosDocument))) {
        context.addValidationError(new ValidationError(ERROR_ACTION_INVALID_TYPE, "T entry type is invalid"));
        return false;
    }
    /*
         * ---- H entry is optional but the default value is True (annotations of the T entry will be hidden) according
         * to the aim of a PDF/A it should be false (annotations of the T entry will be shown).
         * 
         * We check the H value and we throw an error if it is true because of the PDF/A Application Notes sentence :
         * 
         * The PDF Reference supports a concept whereby something will happen when the user performs an explicit or
         * implicit action in a PDF viewer - these "things" are called Actions. PDF/A-1 permits a limited set of these
         * Actions, which are detailed in section 6.6.1. Specifically, any action that could change the visual
         * representation of the document or is not documented in the PDF Reference is not permitted. This includes the
         * /Hide action which isn't specifically prohibited by PDF/A-1, but should have been.
         */
    boolean h = this.actionDictionnary.getBoolean(COSName.H, true);
    if (h) {
        context.addValidationError(new ValidationError(ERROR_ACTION_HIDE_H_INVALID, "H entry is \"true\""));
        return false;
    }
    return true;
}
Also used : COSBase(org.apache.pdfbox.cos.COSBase) COSDocument(org.apache.pdfbox.cos.COSDocument) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError)

Example 84 with ValidationError

use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.

the class UriAction method innerValid.

/*
     * (non-Javadoc)
     * 
     * @see net.awl.edoc.pdfa.validation.actions.AbstractActionManager#valid(java.util .List)
     */
@Override
protected boolean innerValid() {
    COSBase uri = this.actionDictionnary.getItem(COSName.URI);
    if (uri == null) {
        context.addValidationError(new ValidationError(ERROR_ACTION_MISING_KEY, "URI entry is mandatory for the UriAction"));
        return false;
    }
    COSDocument cosDocument = this.context.getDocument().getDocument();
    if (!COSUtils.isString(uri, cosDocument)) {
        context.addValidationError(new ValidationError(ERROR_ACTION_INVALID_TYPE, "URI entry should be a string"));
        return false;
    }
    return true;
}
Also used : COSBase(org.apache.pdfbox.cos.COSBase) COSDocument(org.apache.pdfbox.cos.COSDocument) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError)

Example 85 with ValidationError

use of org.apache.pdfbox.preflight.ValidationResult.ValidationError in project pdfbox by apache.

the class AnnotationValidator method checkMandatoryFields.

/**
 * Checks if all mandatory fields of an annotation are present. If some fields are missing, the method returns false
 * and the errors list is updated.
 *
 * @return true if validation succeed, false otherwise.
 */
protected boolean checkMandatoryFields() {
    boolean subtype = this.annotDictionary.containsKey(COSName.SUBTYPE);
    boolean rect = this.annotDictionary.containsKey(COSName.RECT);
    boolean result = (subtype && rect && checkSpecificMandatoryFields());
    if (!result) {
        ctx.addValidationError(new ValidationError(ERROR_ANNOT_MISSING_FIELDS, "A mandatory field for the " + this.pdAnnot.getSubtype() + " annotation is missing"));
    }
    return result;
}
Also used : ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError)

Aggregations

ValidationError (org.apache.pdfbox.preflight.ValidationResult.ValidationError)108 COSBase (org.apache.pdfbox.cos.COSBase)36 COSDictionary (org.apache.pdfbox.cos.COSDictionary)28 IOException (java.io.IOException)27 COSDocument (org.apache.pdfbox.cos.COSDocument)13 COSObject (org.apache.pdfbox.cos.COSObject)13 COSArray (org.apache.pdfbox.cos.COSArray)10 COSStream (org.apache.pdfbox.cos.COSStream)10 COSString (org.apache.pdfbox.cos.COSString)8 PDColorSpace (org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace)8 ValidationException (org.apache.pdfbox.preflight.exception.ValidationException)8 COSName (org.apache.pdfbox.cos.COSName)7 COSObjectKey (org.apache.pdfbox.cos.COSObjectKey)7 PreflightPath (org.apache.pdfbox.preflight.PreflightPath)6 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)5 PDStream (org.apache.pdfbox.pdmodel.common.PDStream)5 PreflightParser (org.apache.pdfbox.preflight.parser.PreflightParser)5 DublinCoreSchema (org.apache.xmpbox.schema.DublinCoreSchema)5 PDDocument (org.apache.pdfbox.pdmodel.PDDocument)4