XMPDocumentBuilder builder;
try {
builder = new XMPDocumentBuilder();
builder.addPreprocessor(new PDFAExtentionSchemaPreprocessor());
} catch (XmpSchemaException e1) {
throw new ValidationException(e1.getMessage(), e1);
}
XMPMetadata metadata;
try {
metadata = builder.parse(tmp);
handler.setMetadata(metadata);
} catch (XmpSchemaException e) {
throw new ValidationException(
"Parser: Internal Problem (failed to instanciate Schema object)", e);
} catch (XmpXpacketEndException e) {
throw new ValidationException("Unable to parse font metadata due to : "
+ e.getMessage(), e);
}
List<ValidationError> lve = new ArrayList<ValidationError>();
// 6.7.5 no deprecated attribute in xpacket processing instruction
if (metadata.getXpacketBytes() != null) {
lve.add(new ValidationError(
ValidationConstants.ERROR_METADATA_XPACKET_DEPRECATED,
"bytes attribute is forbidden"));
}
if (metadata.getXpacketEncoding() != null) {
lve.add(new ValidationError(
ValidationConstants.ERROR_METADATA_XPACKET_DEPRECATED,
"encoding attribute is forbidden"));
}
// Call metadata synchronization checking
lve.addAll(new SynchronizedMetaDataValidation()
.validateMetadataSynchronization(document, metadata));
// Call PDF/A Identifier checking
lve.addAll(new PDFAIdentificationValidation()
.validatePDFAIdentifer(metadata));
// Call rdf:about checking
try {
new RDFAboutAttributeConcordanceValidation()
.validateRDFAboutAttributes(metadata);
} catch (DifferentRDFAboutException e) {
lve.add(new ValidationError(
ValidationConstants.ERROR_METADATA_RDF_ABOUT_ATTRIBUTE_INEQUAL_VALUE, e
.getMessage()));
}
return lve;
} catch (XpacketParsingException e) {
List<ValidationError> lve = new ArrayList<ValidationError>();
if (e.getError() != null) {
lve.add(e.getError());
} else {
lve.add(new ValidationError(ValidationConstants.ERROR_METADATA_MAIN,
"Unexpected error"));
}
return lve;
} catch (XmpPropertyFormatException e) {
List<ValidationError> lve = new ArrayList<ValidationError>();
lve.add(new ValidationError(
ValidationConstants.ERROR_METADATA_PROPERTY_FORMAT, e.getMessage()));
return lve;
} catch (BadFieldValueException e) {
List<ValidationError> lve = new ArrayList<ValidationError>();
lve.add(new ValidationError(ValidationConstants.ERROR_METADATA_CATEGORY_PROPERTY_INVALID ,e.getMessage()));
return lve;
}
catch (XmpExpectedRdfAboutAttribute e) {
List<ValidationError> lve = new ArrayList<ValidationError>();
lve.add(new ValidationError(ValidationConstants.ERROR_METADATA_RDF_ABOUT_ATTRIBUTE_MISSING ,e.getMessage()));
return lve;
} catch (XmpUnknownPropertyException e) {
List<ValidationError> lve = new ArrayList<ValidationError>();
lve.add(new ValidationError(
ValidationConstants.ERROR_METADATA_PROPERTY_UNKNOWN, e.getMessage()));
return lve;
} catch (XmpUnknownSchemaException e) {
List<ValidationError> lve = new ArrayList<ValidationError>();
lve.add(new ValidationError(
ValidationConstants.ERROR_METADATA_ABSENT_DESCRIPTION_SCHEMA, e
.getMessage()));
return lve;
} catch (XmpUnexpectedNamespaceURIException e) {
List<ValidationError> lve = new ArrayList<ValidationError>();
lve.add(new ValidationError(
ValidationConstants.ERROR_METADATA_WRONG_NS_URI, e.getMessage()));
return lve;
} catch (XmpUnexpectedNamespacePrefixException e) {
List<ValidationError> lve = new ArrayList<ValidationError>();
lve.add(new ValidationError(
ValidationConstants.ERROR_METADATA_ABSENT_DESCRIPTION_SCHEMA, e
.getMessage()));
return lve;
} catch (XmpRequiredPropertyException e) {
List<ValidationError> lve = new ArrayList<ValidationError>();
lve.add(new ValidationError(
ValidationConstants.ERROR_METADATA_PROPERTY_MISSING, e.getMessage()));
return lve;
} catch (XmpUnknownValueTypeException e) {
List<ValidationError> lve = new ArrayList<ValidationError>();
lve
.add(new ValidationError(
ValidationConstants.ERROR_METADATA_UNKNOWN_VALUETYPE, e
.getMessage()));
return lve;
} catch (XmpParsingException e) {
List<ValidationError> lve = new ArrayList<ValidationError>();
lve.add(new ValidationError(ValidationConstants.ERROR_METADATA_FORMAT, e
.getMessage()));
return lve;
}
catch (IOException e) {
throw new ValidationException("Failed while validating", e);
}
}