Package org.apache.padaf.preflight

Examples of org.apache.padaf.preflight.ValidationException


   */
  protected ValidationException SchemaAccessException(String target,
      Throwable cause) {
    StringBuilder sb = new StringBuilder(80);
    sb.append("Cannot access to the ").append(target).append(" schema");
    return new ValidationException(sb.toString(), cause);
  }
View Full Code Here


  public void validateRDFAboutAttributes(XMPMetadata metadata)
      throws ValidationException, DifferentRDFAboutException {

    List<XMPSchema> schemas = metadata.getAllSchemas();
    if (schemas.size() == 0) {
      throw new ValidationException(
          "Schemas not found in the given metadata representation");
    }
    String about = schemas.get(0).getAboutValue();
    // rdf:description must have an about attribute, it has been checked during
    // parsing
View Full Code Here

      long skipped = 0;
      if (offset != null) {
        while (skipped != offset) {
          long curSkip = ra.skip(offset - skipped);
          if (curSkip < 0) {
            throw new ValidationException(
                "Unable to skip bytes in the PDFFile to check stream length");
          }
          skipped += curSkip;
        }

        // ---- go to the stream key word
        if (readUntilStream(ra)) {
          int c = ra.read();
          if (c == '\r') {
            ra.read();
          } // else c is '\n' no more character to read


          // ---- Here is the true beginning of the Stream Content.
          // ---- Read the given length of bytes and check the 10 next bytes
          // ---- to see if there are endstream.
          byte[] buffer = new byte[1024];
          int nbBytesToRead = length;

          do {
            int cr = 0;
            if (nbBytesToRead > 1024) {
              cr = ra.read(buffer, 0, 1024);
            } else {
              cr = ra.read(buffer, 0, nbBytesToRead);
            }
            if (cr == -1) {
              result.add(new ValidationResult.ValidationError(
                  ValidationConstants.ERROR_SYNTAX_STREAM_LENGTH_INVALID,
                  "Stream length is invalide"));
              return;
            } else {
              nbBytesToRead = nbBytesToRead - cr;
            }
          } while (nbBytesToRead > 0);

          int len = "endstream".length() + 2;
          byte[] buffer2 = new byte[len];
          for (int i = 0; i < len; ++i) {
            buffer2[i] = (byte) ra.read();
          }

          // ---- check the content of 10 last characters
          String endStream = new String(buffer2);
          if (buffer2[0] == '\r' && buffer2[1] == '\n') {
            if (!endStream.contains("endstream")) {
              result.add(new ValidationResult.ValidationError(
                  ValidationConstants.ERROR_SYNTAX_STREAM_LENGTH_INVALID,
                  "Stream length is invalide"));
            }
          } else if (buffer2[0] == '\r' && buffer2[1] == 'e') {
            if (!endStream.contains("endstream")) {
              result.add(new ValidationResult.ValidationError(
                  ValidationConstants.ERROR_SYNTAX_STREAM_LENGTH_INVALID,
                  "Stream length is invalide"));
            }
          } else if (buffer2[0] == '\n' && buffer2[1] == 'e') {
            if (!endStream.contains("endstream")) {
              result.add(new ValidationResult.ValidationError(
                  ValidationConstants.ERROR_SYNTAX_STREAM_LENGTH_INVALID,
                  "Stream length is invalide"));
            }
          } else {
            result.add(new ValidationResult.ValidationError(
                ValidationConstants.ERROR_SYNTAX_STREAM_LENGTH_INVALID,
                "Stream length is invalide"));
          }

        } else {
          result.add(new ValidationResult.ValidationError(
              ValidationConstants.ERROR_SYNTAX_STREAM_LENGTH_INVALID,
              "Stream length is invalide"));
        }
      } else {
        /*
         *
         * Offset is null. The stream isn't used, check is useless.
         *
         * TODO : Is it the truth?
         */
      }
    } catch (IOException e) {
      throw new ValidationException(
          "Unable to read a stream to validate it due to : " + e.getMessage(),
          e);
    } finally {
      if ( ra != null) {
        IOUtils.closeQuietly(ra);
View Full Code Here

      XMPDocumentBuilder builder;
    try {
    builder = new XMPDocumentBuilder();
    builder.addPreprocessor(new PDFAExtentionSchemaPreprocessor());
    } catch (XmpSchemaException e1) {
      throw new ValidationException(e1.getMessage(), e1);
    }
      XMPMetadata metadata;
      try {
        metadata = builder.parse(tmp);
        handler.setMetadata(metadata);
      } catch (XmpSchemaException e) {
        throw new ValidationException(
            "Parser: Internal Problem (failed to instanciate Schema object)", e);
      } catch (XmpXpacketEndException e) {
        throw new ValidationException("Unable to parse font metadata due to : "
            + e.getMessage(), e);
      }
      List<ValidationError> lve = new ArrayList<ValidationError>();

      // 6.7.5 no deprecated attribute in xpacket processing instruction
      if (metadata.getXpacketBytes() != null) {
        lve.add(new ValidationError(
            ValidationConstants.ERROR_METADATA_XPACKET_DEPRECATED,
            "bytes attribute is forbidden"));
      }
      if (metadata.getXpacketEncoding() != null) {
        lve.add(new ValidationError(
            ValidationConstants.ERROR_METADATA_XPACKET_DEPRECATED,
            "encoding attribute is forbidden"));
      }

      // Call metadata synchronization checking
      lve.addAll(new SynchronizedMetaDataValidation()
          .validateMetadataSynchronization(document, metadata));

      // Call PDF/A Identifier checking
      lve.addAll(new PDFAIdentificationValidation()
          .validatePDFAIdentifer(metadata));

      // Call rdf:about checking
      try {
        new RDFAboutAttributeConcordanceValidation()
            .validateRDFAboutAttributes(metadata);
      } catch (DifferentRDFAboutException e) {
        lve.add(new ValidationError(
            ValidationConstants.ERROR_METADATA_RDF_ABOUT_ATTRIBUTE_INEQUAL_VALUE, e
                .getMessage()));
      }

      return lve;
    } catch (XpacketParsingException e) {
      List<ValidationError> lve = new ArrayList<ValidationError>();
      if (e.getError() != null) {
        lve.add(e.getError());
      } else {
        lve.add(new ValidationError(ValidationConstants.ERROR_METADATA_MAIN,
            "Unexpected error"));
      }
      return lve;
    } catch (XmpPropertyFormatException e) {
      List<ValidationError> lve = new ArrayList<ValidationError>();
      lve.add(new ValidationError(
          ValidationConstants.ERROR_METADATA_PROPERTY_FORMAT, e.getMessage()));
      return lve;
    } catch (BadFieldValueException e) {
    List<ValidationError> lve = new ArrayList<ValidationError>();
    lve.add(new ValidationError(ValidationConstants.ERROR_METADATA_CATEGORY_PROPERTY_INVALID ,e.getMessage()));
    return lve;
  }
  catch (XmpExpectedRdfAboutAttribute e) {
    List<ValidationError> lve = new ArrayList<ValidationError>();
    lve.add(new ValidationError(ValidationConstants.ERROR_METADATA_RDF_ABOUT_ATTRIBUTE_MISSING ,e.getMessage()));
    return lve;
    } catch (XmpUnknownPropertyException e) {
      List<ValidationError> lve = new ArrayList<ValidationError>();
      lve.add(new ValidationError(
          ValidationConstants.ERROR_METADATA_PROPERTY_UNKNOWN, e.getMessage()));
      return lve;
    } catch (XmpUnknownSchemaException e) {
      List<ValidationError> lve = new ArrayList<ValidationError>();
      lve.add(new ValidationError(
          ValidationConstants.ERROR_METADATA_ABSENT_DESCRIPTION_SCHEMA, e
              .getMessage()));
      return lve;
    } catch (XmpUnexpectedNamespaceURIException e) {
      List<ValidationError> lve = new ArrayList<ValidationError>();
      lve.add(new ValidationError(
          ValidationConstants.ERROR_METADATA_WRONG_NS_URI, e.getMessage()));
      return lve;
    } catch (XmpUnexpectedNamespacePrefixException e) {
      List<ValidationError> lve = new ArrayList<ValidationError>();
      lve.add(new ValidationError(
          ValidationConstants.ERROR_METADATA_ABSENT_DESCRIPTION_SCHEMA, e
              .getMessage()));
      return lve;
    } catch (XmpRequiredPropertyException e) {
      List<ValidationError> lve = new ArrayList<ValidationError>();
      lve.add(new ValidationError(
          ValidationConstants.ERROR_METADATA_PROPERTY_MISSING, e.getMessage()));
      return lve;
    } catch (XmpUnknownValueTypeException e) {
      List<ValidationError> lve = new ArrayList<ValidationError>();
      lve
          .add(new ValidationError(
              ValidationConstants.ERROR_METADATA_UNKNOWN_VALUETYPE, e
                  .getMessage()));
      return lve;
    } catch (XmpParsingException e) {
      List<ValidationError> lve = new ArrayList<ValidationError>();
      lve.add(new ValidationError(ValidationConstants.ERROR_METADATA_FORMAT, e
          .getMessage()));
      return lve;
    }

    catch (IOException e) {
      throw new ValidationException("Failed while validating", e);
    }
  }
View Full Code Here

        if (!validatePage((PDPage) pages.get(i), handler, result)) {
          return result;
        }
      }
    } else {
      throw new ValidationException(
          "There are no Catalog entry in the Document.");
    }

    return result;
  }
View Full Code Here

        }
      }

    } catch (IOException e) {
      throw new ValidationException("Unable to access Annotation", e);
    }
    // --- No annotations, validation OK
    return true;
  }
View Full Code Here

      this.pFont = PDFontFactory.createFont(fDictionary);

      this.fontContainer = instanciateContainer(this.pFont);
      this.handler.addFont(this.pFont.getCOSObject(), this.fontContainer);
    } catch (IOException e) {
      throw new ValidationException(
          "Unable to instantiate a FontValidator object : " + e.getMessage());
    }
  }
View Full Code Here

        IOUtils.copyLarge(metaDataContent, bos);
        IOUtils.closeQuietly(metaDataContent);
        IOUtils.closeQuietly(bos);
        mdAsBytes = bos.toByteArray();
      } catch (IOException e) {
        throw new ValidationException("Unable to read font metadata due to : "
            + e.getMessage(), e);
      }

      try {

        XMPDocumentBuilder xmpBuilder = new XMPDocumentBuilder();
        XMPMetadata xmpMeta = xmpBuilder.parse(mdAsBytes);

        FontMetaDataValidation fontMDval = new FontMetaDataValidation();
        List<ValidationError> ve = new ArrayList<ValidationError>();
        boolean isVal = fontMDval.analyseFontName(xmpMeta, fontDesc, ve);
        isVal = isVal & fontMDval.analyseRights(xmpMeta, fontDesc, ve);
        for (ValidationError validationError : ve) {
          fontContainer.addError(validationError);
        }
        return isVal;

      } catch (XmpUnknownValueTypeException e) {
        fontContainer.addError(new ValidationError(
            ValidationConstants.ERROR_METADATA_UNKNOWN_VALUETYPE, e
            .getMessage()));
        return false;
      } catch (XmpParsingException e) {
        fontContainer.addError(new ValidationError(
            ValidationConstants.ERROR_METADATA_FORMAT, e.getMessage()));
        return false;
      } catch (XmpSchemaException e) {
        fontContainer.addError(new ValidationError(
            ValidationConstants.ERROR_METADATA_FORMAT, e.getMessage()));
        return false;
      } catch (XmpExpectedRdfAboutAttribute e) {
        fontContainer.addError(new ValidationError(ValidationConstants.ERROR_METADATA_RDF_ABOUT_ATTRIBUTE_MISSING,e.getMessage()));
        return false;
      } catch (BadFieldValueException e) {
        fontContainer.addError(new ValidationError(ValidationConstants.ERROR_METADATA_CATEGORY_PROPERTY_INVALID,e.getMessage()));
        return false;
      } catch (XmpXpacketEndException e) {
        throw new ValidationException("Unable to parse font metadata due to : "
            + e.getMessage(), e);
      }
    }

    // --- No MetaData, valid
View Full Code Here

    String subtype = dic.getNameAsString(COSName
        .getPDFName(DICTIONARY_KEY_SUBTYPE));

    if ((type == null || "".equals(type))
        || (subtype == null || "".equals(subtype))) {
      throw new ValidationException("Type and/or Subtype keys are missing : "
          + ERROR_FONTS_DICTIONARY_INVALID);
    } else {
      if (FONT_DICTIONARY_VALUE_TRUETYPE.equals(subtype)) {
        return new TrueTypeFontValidator(handler, cObj);
      } else if (FONT_DICTIONARY_VALUE_MMTYPE.equals(subtype)
          || FONT_DICTIONARY_VALUE_TYPE1.equals(subtype)) {
        return new Type1FontValidator(handler, cObj);
      } else if (FONT_DICTIONARY_VALUE_TYPE3.equals(subtype)) {
        return new Type3FontValidator(handler, cObj);
      } else if (FONT_DICTIONARY_VALUE_COMPOSITE.equals(subtype)) {
       return new CompositeFontValidator(handler, cObj);
      } else if (FONT_DICTIONARY_VALUE_TYPE2.equals(subtype)
          || FONT_DICTIONARY_VALUE_TYPE1C.equals(subtype)
          || FONT_DICTIONARY_VALUE_TYPE0C.equals(subtype)
          || FONT_DICTIONARY_VALUE_TYPE0.equals(subtype)) {
        // ---- Font managed by a Composite font.
        // this dictionary will be checked by a CompositeFontValidator
        return null;
      } else {
        throw new ValidationException("Unknown font type : " + subtype);
      }
    }
  }
View Full Code Here

        processStream(page, page.findResources(), pstream.getStream());
      }
    } catch (ContentStreamException e) {
      errors.add(new ValidationError(e.getValidationError(), e.getMessage()));
    } catch (IOException e) {
      throw new ValidationException("Unable to check the ContentStream : "
          + e.getMessage(), e);
    }

    return errors;
  }
View Full Code Here

TOP

Related Classes of org.apache.padaf.preflight.ValidationException

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.