use of org.apache.xmpbox.xml.DomXmpParser 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.DomXmpParser in project pdfbox by apache.
the class DeserializationTest method testEmptyLi.
@Test
public void testEmptyLi() throws Exception {
InputStream fis = DomXmpParser.class.getResourceAsStream("/org/apache/xmpbox/parser/empty_list.xml");
DomXmpParser xdb = new DomXmpParser();
xdb.parse(fis);
}
use of org.apache.xmpbox.xml.DomXmpParser 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.DomXmpParser in project pdfbox by apache.
the class DeserializationTest method testIsartorStyleWithThumbs.
@Test
public void testIsartorStyleWithThumbs() throws Exception {
InputStream fis = DomXmpParser.class.getResourceAsStream("/org/apache/xmpbox/parser/ThumbisartorStyle.xml");
DomXmpParser xdb = new DomXmpParser();
XMPMetadata metadata = xdb.parse(fis);
// <xmpMM:DocumentID>
Assert.assertEquals("uuid:09C78666-2F91-3A9C-92AF-3691A6D594F7", metadata.getXMPMediaManagementSchema().getDocumentID());
// <xmp:CreateDate>
// <xmp:ModifyDate>
// <xmp:MetadataDate>
Assert.assertEquals(DateConverter.toCalendar("2008-01-18T16:59:54+01:00"), metadata.getXMPBasicSchema().getCreateDate());
Assert.assertEquals(DateConverter.toCalendar("2008-01-18T16:59:54+01:00"), metadata.getXMPBasicSchema().getModifyDate());
Assert.assertEquals(DateConverter.toCalendar("2008-01-18T16:59:54+01:00"), metadata.getXMPBasicSchema().getMetadataDate());
// THUMBNAILS TEST
List<ThumbnailType> thumbs = metadata.getXMPBasicSchema().getThumbnailsProperty();
Assert.assertNotNull(thumbs);
Assert.assertEquals(2, thumbs.size());
ThumbnailType thumb = thumbs.get(0);
Assert.assertEquals(Integer.valueOf(162), thumb.getHeight());
Assert.assertEquals(Integer.valueOf(216), thumb.getWidth());
Assert.assertEquals("JPEG", thumb.getFormat());
Assert.assertEquals("/9j/4AAQSkZJRgABAgEASABIAAD", thumb.getImage());
thumb = thumbs.get(1);
Assert.assertEquals(Integer.valueOf(162), thumb.getHeight());
Assert.assertEquals(Integer.valueOf(216), thumb.getWidth());
Assert.assertEquals("JPEG", thumb.getFormat());
Assert.assertEquals("/9j/4AAQSkZJRgABAgEASABIAAD", thumb.getImage());
}
use of org.apache.xmpbox.xml.DomXmpParser 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());
}
}
Aggregations