Search in sources :

Example 1 with XmpParsingException

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));
    }
}
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 XmpParsingException

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

Example 3 with XmpParsingException

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());
    }
}
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 XmpParsingException

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

Example 5 with XmpParsingException

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());
    }
}
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)13 XmpParsingException (org.apache.xmpbox.xml.XmpParsingException)13 InputStream (java.io.InputStream)11 Test (org.junit.Test)9 XMPMetadata (org.apache.xmpbox.XMPMetadata)4 PDDocument (org.apache.pdfbox.pdmodel.PDDocument)3 PDMetadata (org.apache.pdfbox.pdmodel.common.PDMetadata)3 ValidationError (org.apache.pdfbox.preflight.ValidationResult.ValidationError)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 PDDocumentCatalog (org.apache.pdfbox.pdmodel.PDDocumentCatalog)1 PDDocumentInformation (org.apache.pdfbox.pdmodel.PDDocumentInformation)1 ValidationException (org.apache.pdfbox.preflight.exception.ValidationException)1 FontMetaDataValidation (org.apache.pdfbox.preflight.font.util.FontMetaDataValidation)1 PDFAIdentificationValidation (org.apache.pdfbox.preflight.metadata.PDFAIdentificationValidation)1 RDFAboutAttributeConcordanceValidation (org.apache.pdfbox.preflight.metadata.RDFAboutAttributeConcordanceValidation)1 DifferentRDFAboutException (org.apache.pdfbox.preflight.metadata.RDFAboutAttributeConcordanceValidation.DifferentRDFAboutException)1 SynchronizedMetaDataValidation (org.apache.pdfbox.preflight.metadata.SynchronizedMetaDataValidation)1