Package org.apache.padaf.preflight

Examples of org.apache.padaf.preflight.ValidationResult


    this.target = file;
  }
 
  @Test
  public void validate () throws Exception {
    ValidationResult result = null;
    try {
      result = validator.validate(new FileDataSource(target));
      Assert.assertFalse(result.isValid());
    } finally {
      if (result != null) {
        result.closePdf();
      }
    }
  }
View Full Code Here


    this.target = file;
  }
 
  @Test
  public void validate () throws Exception {
    ValidationResult result = null;
    try {
      System.out.println(target);
      result = validator.validate(new FileDataSource(target));
      Assert.assertTrue("Validation of " + target ,result.isValid());
    } finally {
      if (result != null) {
        result.closePdf();
      }
    }
  }
View Full Code Here

   
    int size = lfd.size();
    for (int i = 0 ; i < loop ; i++) {
      File file = lfd.get(i%size);
      long startLTime = System.currentTimeMillis();
      ValidationResult result = validator.validate(new FileDataSource(file));
      if (!result.isValid()) {
        resFile.write(file.getAbsolutePath() + " isn't PDF/A\n");
        for (ValidationError error : result.getErrorsList()) {
          resFile.write(error.getErrorCode() + " : " + error.getDetails() +"\n");
        }
      }
      result.closePdf();
      long endLTime = System.currentTimeMillis();
      resFile.write(file.getName() + " (ms) : " + (endLTime - startLTime) + "\n");
      resFile.flush();
    }
View Full Code Here

         }
     }

     @Test()
     public void validate() throws Exception {
         ValidationResult result = null;
         try {
             InputStream input = this.getClass().getResourceAsStream(path);
             ByteArrayDataSource bds = new ByteArrayDataSource(input);
             result = validator.validate(bds);
             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;
             for (ValidationError error : result.getErrorsList()) {
                 if (error.getErrorCode().equals(this.expectedError)) {
                     found = true;
                 }
                 if (isartorResultFile != null) {
                     String log = path.replace(".pdf", "") + "#"
+error.getErrorCode()+"#"+error.getDetails()+"\n";
                     isartorResultFile.write(log.getBytes());
                 }
             }

             if (result.getErrorsList().size() > 1) {
                 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) {
             throw new Exception(path + " :" + e.getMessage(), e);
         } finally {
             if (result!=null) {
                 result.closePdf();
             }
         }
     }
View Full Code Here

    public final void validate() throws Exception {
        if (path==null) {
            logger.warn("This is an empty test");
            return;
        }
        ValidationResult result = null;
        try {
            FileDataSource bds = new FileDataSource(path);
            result = validator.validate(bds);
            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) {
                        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) {
            throw new Exception(path + " :" + e.getMessage(), e);
        } finally {
            if (result!=null) {
                result.closePdf();
            }
        }
    }
View Full Code Here

    public void validate() throws Exception {
        if (path==null) {
            logger.warn("This is an empty test");
            return;
        }
        ValidationResult result = null;
        try {
            FileDataSource bds = new FileDataSource(path);
            result = validator.validate(bds);
            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) {
            throw new Exception(path + " :" + e.getMessage(), e);
        } finally {
            if (result!=null) {
                result.closePdf();
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.padaf.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.