Package org.apache.pdfbox.preflight

Examples of org.apache.pdfbox.preflight.ValidationResult


        PreflightParser parser = new PreflightParser(documentFileName);
        parser.parse();
        PreflightDocument document = parser.getPreflightDocument();

        // Validate the document.
        ValidationResult result = null;
        try {
            document.validate();
            result = document.getResult();
        } catch (SyntaxValidationException exception) {
            result = exception.getResult();
View Full Code Here


            "UsagePDFAValidator"), jar), arguments);
        String inputDocument = command.getOptionValue("in");

        try {
            // Check compliance of a document with the PDF/A standard.
            ValidationResult result = PDFAValidator.validate(inputDocument);

            // Print validation errors if the document is not compliant.
            if (!result.isValid()) {
                for (ValidationError error : result.getErrorsList()) {
                    System.err.println(error.getDetails());
                }
                System.exit(1);
            }
        } catch (Exception exception) {
View Full Code Here

     * @return the ValidationError instance.
     */
    protected static ValidationResult createUnknownErrorResult()
    {
        ValidationError error = new ValidationError(PreflightConstants.ERROR_UNKOWN_ERROR);
        ValidationResult result = new ValidationResult(error);
        return result;
    }
View Full Code Here

     */
    protected void addValidationError(ValidationError error)
    {
        if (this.validationResult == null)
        {
            this.validationResult = new ValidationResult(error.isWarning());
        }
        this.validationResult.addError(error);
    }
View Full Code Here

            PreflightParser parser = new PreflightParser(bds);
            parser.parse();
            document = parser.getPreflightDocument();
            document.validate();

            ValidationResult result = document.getResult();
            Assert.assertFalse(path + " : Isartor file should be invalid (" + path + ")", result.isValid());
            Assert.assertTrue(path + " : Should find at least one error", result.getErrorsList().size() > 0);
            // could contain more than one error
            boolean found = false;
            if (this.expectedError != null)
            {
                for (ValidationError error : result.getErrorsList())
                {
                    if (error.getErrorCode().equals(this.expectedError))
                    {
                        found = true;
                        if (outputResult == null)
                        {
                            break;
                        }
                    }
                    if (outputResult != null)
                    {
                        String log = path.getName().replace(".pdf", "") + "#" + error.getErrorCode() + "#"
                                + error.getDetails() + "\n";
                        outputResult.write(log.getBytes());
                    }
                }
            }

            if (result.getErrorsList().size() > 0)
            {
                if (this.expectedError == null)
                {
                    logger.info("File invalid as expected (no expected code) :" + this.path.getAbsolutePath());
                }
                else if (!found)
                {
                    StringBuilder message = new StringBuilder(100);
                    message.append(path).append(" : Invalid error code returned. Expected ");
                    message.append(this.expectedError).append(", found ");
                    for (ValidationError error : result.getErrorsList())
                    {
                        message.append(error.getErrorCode()).append(" ");
                    }
                    Assert.fail(message.toString());
                }
            }
            else
            {
                Assert.assertEquals(path + " : Invalid error code returned.", this.expectedError, result
                        .getErrorsList().get(0).getErrorCode());
            }
        }
        catch (ValidationException e)
        {
View Full Code Here

        xpath = XPathFactory.newInstance().newXPath();
    }

    @Test
    public void testOneError () throws Exception {
        ValidationResult result = new ValidationResult(false);
        result.addError(new ValidationResult.ValidationError("7"));
        parser.createResponseWithError(document, "pdftype", result, preflight);
        Assert.assertNotNull(xpath.evaluate("errors[@count='1']", preflight, XPathConstants.NODE));
        NodeList nl = (NodeList)xpath.evaluate("errors/error[@count='1']", preflight, XPathConstants.NODESET);
        Assert.assertEquals(1,nl.getLength());
    }
View Full Code Here

        Assert.assertEquals(1,nl.getLength());
    }

    @Test
    public void testTwoError () throws Exception {
        ValidationResult result = new ValidationResult(false);
        result.addError(new ValidationResult.ValidationError("7"));
        result.addError(new ValidationResult.ValidationError(ERROR_CODE));
        parser.createResponseWithError(document, "pdftype", result, preflight);
        Assert.assertNotNull(xpath.evaluate("errors[@count='2']", preflight, XPathConstants.NODE));
        NodeList nl = (NodeList)xpath.evaluate("errors/error[@count='1']", preflight, XPathConstants.NODESET);
        Assert.assertEquals(2,nl.getLength());
    }
View Full Code Here

        Assert.assertEquals(2,nl.getLength());
    }

    @Test
    public void testSameErrorTwice () throws Exception {
        ValidationResult result = new ValidationResult(false);
        result.addError(new ValidationResult.ValidationError(ERROR_CODE));
        result.addError(new ValidationResult.ValidationError(ERROR_CODE));
        parser.createResponseWithError(document,"pdftype",result,preflight);
        Assert.assertNotNull(xpath.evaluate("errors[@count='2']", preflight, XPathConstants.NODE));
        Assert.assertNotNull(xpath.evaluate("errors/error[@count='2']", preflight, XPathConstants.NODE));
        Element code = (Element)xpath.evaluate("errors/error[@count='2']/code", preflight, XPathConstants.NODE);
        Assert.assertNotNull(code);
View Full Code Here

        Assert.assertEquals(ERROR_CODE,code.getTextContent());
    }

    @Test
    public void testSameCodeWithDifferentMessages () throws Exception {
        ValidationResult result = new ValidationResult(false);
        result.addError(new ValidationResult.ValidationError(ERROR_CODE,"message 1"));
        result.addError(new ValidationResult.ValidationError(ERROR_CODE,"message 2"));
        parser.createResponseWithError(document, "pdftype", result, preflight);
        Assert.assertNotNull(xpath.evaluate("errors[@count='2']", preflight, XPathConstants.NODE));
        NodeList nl = (NodeList)xpath.evaluate("errors/error[@count='1']", preflight, XPathConstants.NODESET);
        Assert.assertEquals(2,nl.getLength());
    }
View Full Code Here

            PreflightParser parser = new PreflightParser(bds);
            parser.parse();
            document = parser.getPreflightDocument();
            document.validate();

            ValidationResult result = document.getResult();
            Assert.assertFalse(path + " : Isartor file should be invalid (" + path + ")", result.isValid());
            Assert.assertTrue(path + " : Should find at least one error", result.getErrorsList().size() > 0);
            // could contain more than one error
            if (result.getErrorsList().size() > 0)
            {
                Assert.fail("File expected valid : " + path.getAbsolutePath());
            }
        }
        catch (ValidationException e)
View Full Code Here

TOP

Related Classes of org.apache.pdfbox.preflight.ValidationResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.