Package org.apache.pdfbox.preflight

Examples of org.apache.pdfbox.preflight.ValidationResult


     * @return
     */
    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

    }


    public Element validate (Document rdocument, DataSource source) throws IOException {
        String pdfType = null;
        ValidationResult result = null;
        long before = System.currentTimeMillis();
        try {
            PreflightParser parser = new PreflightParser(source);
            try
            {
                parser.parse();
                PreflightDocument document = parser.getPreflightDocument();
                document.validate();
                pdfType = document.getSpecification().getFname();
                result = document.getResult();
                document.close();
            }
            catch (SyntaxValidationException e)
            {
                result = e.getResult();
            }
        }
        catch(Exception e)
        {
            long after = System.currentTimeMillis();
            return generateFailureResponse(rdocument, source.getName(), after-before, pdfType, e);
        }

        long after = System.currentTimeMillis();
        if (result.isValid()) {
            Element preflight = generateResponseSkeleton(rdocument, source.getName(), after-before);
            // valid ?
            Element valid = rdocument.createElement("isValid");
            valid.setAttribute("type", pdfType);
            valid.setTextContent("true");
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

            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

     * @return
     */
    protected static ValidationResult createUnknownErrorResult()
    {
        ValidationError error = new ValidationError(PreflightConstants.ERROR_UNKOWN_ERROR);
        ValidationResult result = new ValidationResult(error);
        return result;
    }
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.