use of org.apache.xmpbox.xml.XmpParsingException in project pdfbox by apache.
the class DeserializationTest method testUndefinedStructuredWithDefinedSchema.
@Test
public void testUndefinedStructuredWithDefinedSchema() throws Exception {
InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/undefinedstructuredindefinedschema.xml");
DomXmpParser xdb = new DomXmpParser();
try {
xdb.parse(fis);
Assert.fail("Should fail during parse");
} catch (XmpParsingException e) {
Assert.assertEquals(ErrorType.NoValueType, e.getErrorType());
}
}
use of org.apache.xmpbox.xml.XmpParsingException in project pdfbox by apache.
the class DeserializationTest method testWithNoXPacketEnd.
@Test
public void testWithNoXPacketEnd() throws Exception {
InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/noxpacketend.xml");
DomXmpParser xdb = new DomXmpParser();
try {
xdb.parse(fis);
Assert.fail("Should fail during parse");
} catch (XmpParsingException e) {
Assert.assertEquals(ErrorType.XpacketBadEnd, e.getErrorType());
}
}
use of org.apache.xmpbox.xml.XmpParsingException in project pdfbox by apache.
the class MetadataValidationProcess method validate.
@Override
public void validate(PreflightContext ctx) throws ValidationException {
try {
PDDocument document = ctx.getDocument();
InputStream is = getXpacket(document.getDocument());
DomXmpParser builder = new DomXmpParser();
XMPMetadata metadata = builder.parse(is);
is.close();
ctx.setMetadata(metadata);
// 6.7.5 no deprecated attribute in xpacket processing instruction
if (metadata.getXpacketBytes() != null) {
addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_METADATA_XPACKET_DEPRECATED, "bytes attribute is forbidden"));
}
if (metadata.getXpacketEncoding() != null) {
addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_METADATA_XPACKET_DEPRECATED, "encoding attribute is forbidden"));
}
checkThumbnails(ctx, metadata);
// Call metadata synchronization checking
addValidationErrors(ctx, new SynchronizedMetaDataValidation().validateMetadataSynchronization(document, metadata));
// Call PDF/A Identifier checking
addValidationErrors(ctx, new PDFAIdentificationValidation().validatePDFAIdentifer(metadata));
// Call rdf:about checking
try {
new RDFAboutAttributeConcordanceValidation().validateRDFAboutAttributes(metadata);
} catch (DifferentRDFAboutException e) {
addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_METADATA_RDF_ABOUT_ATTRIBUTE_INEQUAL_VALUE, e.getMessage(), e));
}
} catch (XpacketParsingException e) {
if (e.getError() != null) {
addValidationError(ctx, e.getError());
} else {
addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_METADATA_MAIN, "Unexpected error", e));
}
} catch (XmpParsingException e) {
if (e.getErrorType() == ErrorType.NoValueType) {
addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_METADATA_UNKNOWN_VALUETYPE, e.getMessage(), e));
} else if (e.getErrorType() == ErrorType.RequiredProperty) {
addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_METADATA_PROPERTY_MISSING, e.getMessage(), e));
} else if (e.getErrorType() == ErrorType.InvalidPrefix) {
addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_METADATA_ABSENT_DESCRIPTION_SCHEMA, e.getMessage(), e));
} else if (e.getErrorType() == ErrorType.InvalidType) {
addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_METADATA_PROPERTY_UNKNOWN, e.getMessage(), e));
} else if (e.getErrorType() == ErrorType.XpacketBadEnd) {
throw new ValidationException("Unable to parse font metadata due to : " + e.getMessage(), e);
} else if (e.getErrorType() == ErrorType.NoSchema) {
addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_METADATA_ABSENT_DESCRIPTION_SCHEMA, e.getMessage(), e));
} else if (e.getErrorType() == ErrorType.InvalidPdfaSchema) {
addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_METADATA_WRONG_NS_URI, e.getMessage(), e));
} else {
addValidationError(ctx, new ValidationError(PreflightConstants.ERROR_METADATA_FORMAT, e.getMessage(), e));
}
} catch (IOException e) {
throw new ValidationException("Failed while validating", e);
}
}
Aggregations