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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations