use of org.apache.xmpbox.xml.XmpParsingException in project pdfbox by apache.
the class FontDescriptorHelper method checkFontFileMetaData.
/**
* Type0, Type1 and TrueType FontValidator call this method to check the FontFile meta data.
*
* @param fontDescriptor
* The FontDescriptor which contains the FontFile stream
* @param fontFile
* The font file stream to check
*/
protected void checkFontFileMetaData(PDFontDescriptor fontDescriptor, PDStream fontFile) {
try {
PDMetadata metadata = fontFile.getMetadata();
if (metadata != null) {
// Filters are forbidden in a XMP stream
if (metadata.getFilters() != null && !metadata.getFilters().isEmpty()) {
this.fContainer.push(new ValidationError(ERROR_SYNTAX_STREAM_INVALID_FILTER, this.font.getName() + ": Filter specified in font file metadata dictionnary"));
return;
}
byte[] mdAsBytes = getMetaDataStreamAsBytes(metadata);
try {
DomXmpParser xmpBuilder = new DomXmpParser();
XMPMetadata xmpMeta = xmpBuilder.parse(mdAsBytes);
FontMetaDataValidation fontMDval = new FontMetaDataValidation();
List<ValidationError> ve = new ArrayList<>();
fontMDval.analyseFontName(xmpMeta, fontDescriptor, ve);
fontMDval.analyseRights(xmpMeta, fontDescriptor, ve);
this.fContainer.push(ve);
} catch (XmpParsingException e) {
if (e.getErrorType() == ErrorType.NoValueType) {
this.fContainer.push(new ValidationError(ERROR_METADATA_UNKNOWN_VALUETYPE, e.getMessage(), e));
} else if (e.getErrorType() == ErrorType.XpacketBadEnd) {
this.fContainer.push(new ValidationError(ERROR_METADATA_FORMAT_XPACKET, this.font.getName() + ": Unable to parse font metadata due to : " + e.getMessage(), e));
} else {
this.fContainer.push(new ValidationError(ERROR_METADATA_FORMAT, e.getMessage(), e));
}
}
}
} catch (IllegalStateException e) {
this.fContainer.push(new ValidationError(ERROR_METADATA_FORMAT_UNKOWN, this.font.getName() + ": The Metadata entry doesn't reference a stream object", e));
}
}
use of org.apache.xmpbox.xml.XmpParsingException in project pdfbox by apache.
the class DeserializationTest method testWithInvalidRDFElementPrefix.
@Test
public void testWithInvalidRDFElementPrefix() throws Exception {
InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/invalidroot2.xml");
DomXmpParser xdb = new DomXmpParser();
try {
xdb.parse(fis);
Assert.fail("Should fail during parse");
} catch (XmpParsingException e) {
Assert.assertEquals(ErrorType.Format, e.getErrorType());
}
}
use of org.apache.xmpbox.xml.XmpParsingException in project pdfbox by apache.
the class DeserializationTest method testUndefinedPropertyWithDefinedSchema.
@Test
public void testUndefinedPropertyWithDefinedSchema() throws Exception {
InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/undefinedpropertyindefinedschema.xml");
DomXmpParser xdb = new DomXmpParser();
try {
xdb.parse(fis);
Assert.fail("Should fail during parse");
} catch (XmpParsingException e) {
Assert.assertEquals(ErrorType.NoType, e.getErrorType());
}
}
use of org.apache.xmpbox.xml.XmpParsingException in project pdfbox by apache.
the class DeserializationTest method testWithRDFRootAsText.
@Test
public void testWithRDFRootAsText() throws Exception {
InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/invalidroot.xml");
DomXmpParser xdb = new DomXmpParser();
try {
xdb.parse(fis);
Assert.fail("Should fail during parse");
} catch (XmpParsingException e) {
Assert.assertEquals(ErrorType.Format, e.getErrorType());
}
}
use of org.apache.xmpbox.xml.XmpParsingException in project pdfbox by apache.
the class DeserializationTest method testWithNoRDFElement.
@Test
public void testWithNoRDFElement() throws Exception {
InputStream fis = DomXmpParser.class.getResourceAsStream("/invalidxmp/noroot.xml");
DomXmpParser xdb = new DomXmpParser();
try {
xdb.parse(fis);
Assert.fail("Should fail during parse");
} catch (XmpParsingException e) {
Assert.assertEquals(ErrorType.Format, e.getErrorType());
}
}
Aggregations