Search in sources :

Example 1 with DomXmpParser

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));
    }
}
Also used : XmpParsingException(org.apache.xmpbox.xml.XmpParsingException) XMPMetadata(org.apache.xmpbox.XMPMetadata) FontMetaDataValidation(org.apache.pdfbox.preflight.font.util.FontMetaDataValidation) DomXmpParser(org.apache.xmpbox.xml.DomXmpParser) ArrayList(java.util.ArrayList) PDMetadata(org.apache.pdfbox.pdmodel.common.PDMetadata) ValidationError(org.apache.pdfbox.preflight.ValidationResult.ValidationError)

Example 2 with DomXmpParser

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);
}
Also used : InputStream(java.io.InputStream) DomXmpParser(org.apache.xmpbox.xml.DomXmpParser) Test(org.junit.Test)

Example 3 with DomXmpParser

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());
    }
}
Also used : XmpParsingException(org.apache.xmpbox.xml.XmpParsingException) InputStream(java.io.InputStream) DomXmpParser(org.apache.xmpbox.xml.DomXmpParser) Test(org.junit.Test)

Example 4 with DomXmpParser

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());
}
Also used : XMPMetadata(org.apache.xmpbox.XMPMetadata) InputStream(java.io.InputStream) DomXmpParser(org.apache.xmpbox.xml.DomXmpParser) ThumbnailType(org.apache.xmpbox.type.ThumbnailType) Test(org.junit.Test)

Example 5 with DomXmpParser

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());
    }
}
Also used : XmpParsingException(org.apache.xmpbox.xml.XmpParsingException) InputStream(java.io.InputStream) DomXmpParser(org.apache.xmpbox.xml.DomXmpParser) Test(org.junit.Test)

Aggregations

DomXmpParser (org.apache.xmpbox.xml.DomXmpParser)30 InputStream (java.io.InputStream)22 Test (org.junit.Test)21 XMPMetadata (org.apache.xmpbox.XMPMetadata)13 XmpParsingException (org.apache.xmpbox.xml.XmpParsingException)13 DublinCoreSchema (org.apache.xmpbox.schema.DublinCoreSchema)6 PDDocument (org.apache.pdfbox.pdmodel.PDDocument)5 PDMetadata (org.apache.pdfbox.pdmodel.common.PDMetadata)5 File (java.io.File)3 ValidationError (org.apache.pdfbox.preflight.ValidationResult.ValidationError)3 XMPBasicSchema (org.apache.xmpbox.schema.XMPBasicSchema)3 PDDocumentCatalog (org.apache.pdfbox.pdmodel.PDDocumentCatalog)2 AdobePDFSchema (org.apache.xmpbox.schema.AdobePDFSchema)2 PDFAIdentificationSchema (org.apache.xmpbox.schema.PDFAIdentificationSchema)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 PDDocumentInformation (org.apache.pdfbox.pdmodel.PDDocumentInformation)1