Package org.apache.padaf.preflight.ValidationResult

Examples of org.apache.padaf.preflight.ValidationResult.ValidationError


    COSBase bitsPerComp = this.xobject.getItem(COSName.getPDFName("BitsPerComponent"));
    COSBase mask = this.xobject.getItem(COSName.getPDFName("Mask"));

    if (isImageMaskTrue()) {
      if ( csImg != null || mask != null) {
        result.add(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_KEY, "ImageMask entry is true, ColorSpace and Mask are forbidden."));
      }

      Integer bitsPerCompValue = COSUtils.getAsInteger(bitsPerComp, cosDocument);
      if (bitsPerCompValue != 1 ) {
        result.add(new ValidationError(ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY, "ImageMask entry is true, BitsPerComponent must be 1."));
      }

    } else {
      ColorSpaceHelper csh = ColorSpaceHelperFactory.getColorSpaceHelper(csImg, handler, ColorSpaceRestriction.NO_PATTERN);
      csh.validate(result);
View Full Code Here


  public List<ValidationError> innerValidate(DocumentHandler handler)
  throws ValidationException {
    List<ValidationError> errors = new ArrayList<ValidationError>();
    COSDocument document = handler.getDocument().getDocument();
    if ( document.getObjects().size() > ValidationConstants.MAX_INDIRECT_OBJ ) {
      errors.add(new ValidationError(ERROR_SYNTAX_INDIRECT_OBJ_RANGE, "Too many indirect objects"));
    }
    return errors;
  }
View Full Code Here

        if (!FilterHelper.isAuthorizedFilter(fName, result)) {
          return;
        }
      } else {
        // ---- The filter type is invalid
        result.add(new ValidationError(ERROR_SYNTAX_STREAM_INVALID_FILTER,
            "Filter should be a Name or an Array"));
      }
    }
    //  else Filter entry is optional
  }
View Full Code Here

      XpacketParsingException {
    COSObject catalog = cdocument.getCatalog();
    COSBase cb = catalog.getDictionaryObject(COSName.METADATA);
    if (cb == null) {
      // missing Metadata Key in catalog
      ValidationError error = new ValidationError(
          ValidationConstants.ERROR_METADATA_FORMAT,
          "Missing Metadata Key in catalog");
      throw new XpacketParsingException("Failed while retrieving xpacket",
          error);
    }
    // no filter key
    COSDictionary metadataDictionnary = COSUtils.getAsDictionary(cb, cdocument);
    if (metadataDictionnary.getItem(COSName.FILTER) != null) {
      // should not be defined
      ValidationError error = new ValidationError(
          ValidationConstants.ERROR_SYNTAX_STREAM_INVALID_FILTER,
          "Filter specified in metadata dictionnary");
      throw new XpacketParsingException("Failed while retrieving xpacket",
          error);
    }
View Full Code Here

      }
      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) {
View Full Code Here

   */
  protected List<ValidationError> checkStreamFilterUsage(PDDocument doc) {
    List<ValidationError> ve = new ArrayList<ValidationError>();
    List<?> filters = doc.getDocumentCatalog().getMetadata().getFilters();
    if (filters != null && !filters.isEmpty()) {
      ve.add(new ValidationError(ValidationConstants.ERROR_METADATA_MAIN,
          "Using stream filter on metadata dictionary is forbidden"));
    }
    return ve;
  }
View Full Code Here

    // ---- Check dictionary entries
    // ---- Only the EF entry is forbidden
    if (fileSpec.getItem(COSName
        .getPDFName(FILE_SPECIFICATION_KEY_EMBEDDED_FILE)) != null) {
      result.add(new ValidationError(ERROR_SYNTAX_EMBEDDED_FILES,"EmbeddedFile entry is present in a FileSpecification dictionary"));
    }

    return result;
  }
View Full Code Here

     * @return
     */
    protected ValidationResult createErrorResult(ParseException e) {
        if (e instanceof PdfParseException) {
            if (e.getCause()==null) {
                return new ValidationResult(new ValidationError(((PdfParseException) e)
                        .getErrorCode()));

            } else if (e.getCause().getMessage()==null) {
                return new ValidationResult(new ValidationError(((PdfParseException) e)
                        .getErrorCode()));
            } else {
                return new ValidationResult(new ValidationError(((PdfParseException) e)
                        .getErrorCode(),e.getCause().getMessage()));

            }
        }
        return createUnknownErrorResult();
View Full Code Here

     * ValidationError(UNKNOWN_ERROR)
     *
     * @return
     */
    protected ValidationResult createUnknownErrorResult() {
        ValidationError error = new ValidationError(
                ValidationConstants.ERROR_UNKOWN_ERROR);
        ValidationResult result = new ValidationResult(error);
        return result;
    }
View Full Code Here

  protected boolean checkFontFileMetaData(PDFontDescriptor fontDesc, PDStream fontFile) throws ValidationException {
    PDMetadata metadata = null;
    try {
      metadata = fontFile.getMetadata();
    } catch (IllegalStateException e) {
        fontContainer.addError(new ValidationError(ValidationConstants.ERROR_METADATA_FORMAT_UNKOWN,
        "The Metadata entry doesn't reference a stream object"));
        return false;
    }
    if (metadata != null) {
      // --- Filters are forbidden in a XMP stream
      if (metadata.getFilters() != null && !metadata.getFilters().isEmpty()) {
        fontContainer.addError(new ValidationError(ValidationConstants.ERROR_SYNTAX_STREAM_INVALID_FILTER,
        "Filter specified in font file metadata dictionnary"));
        return false;
      }

      // --- extract the meta data content
      byte[] mdAsBytes = null;
      try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        InputStream metaDataContent = metadata.createInputStream();
        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);
      }
View Full Code Here

TOP

Related Classes of org.apache.padaf.preflight.ValidationResult.ValidationError

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.