Package org.apache.padaf.preflight.ValidationResult

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


  protected boolean innerValid(List<ValidationError> error) {
    COSBase t = this.actionDictionnary.getItem(COSName
        .getPDFName(ACTION_DICTIONARY_KEY_T));
    // ---- T entry is mandatory
    if (t == null) {
      error.add(new ValidationError(ERROR_ACTION_MISING_KEY,
          "T entry is mandatory for the NamedActions"));
      return false;
    }

    if (!(COSUtils.isDictionary(t, cDoc) || COSUtils.isArray(t, cDoc) || COSUtils
        .isString(t, cDoc))) {
      error.add(new ValidationError(ERROR_ACTION_INVALID_TYPE,"T entry type is invalid"));
      return false;
    }

    /*
     * ---- H entry is optional but the default value is True (annotations of
     * the T entry will be hidden) according to the aim of a PDF/A it should be
     * false (annotations of the T entry will be shown).
     *
     * We check the H value and we throw an error if it is true because of the
     * PDF/A Application Notes sentence :
     *
     * The PDF Reference supports a concept whereby something will happen when
     * the user performs an explicit or implicit action in a PDF viewer - these
     * "things" are called Actions. PDF/A-1 permits a limited set of these
     * Actions, which are detailed in section 6.6.1. Specifically, any action
     * that could change the visual representation of the document or is not
     * documented in the PDF Reference is not permitted. This includes the /Hide
     * action which isn't specifically prohibited by PDF/A-1, but should have
     * been.
     */
    boolean h = this.actionDictionnary.getBoolean(COSName
        .getPDFName(ACTION_DICTIONARY_KEY_H), true);
    if (h) {
      error.add(new ValidationError(ERROR_ACTION_HIDE_H_INVALID,
          "H entry is \"true\""));
      return false;
    }

    return true;
View Full Code Here


    // ---- just check if they are present because of the Helper has already
    // checked them.
    if ((type == null || "".equals(type))
        || (subtype == null || "".equals(subtype))) {
      this.fontContainer.addError(new ValidationError(
          ERROR_FONTS_DICTIONARY_INVALID,
          "Type and/or Subtype keys are missing"));
      return false;
    }

    // ---- Check presence of baseFont, CMap and CIDFont
    this.basefont = fDictionary.getNameAsString(COSName
        .getPDFName(FONT_DICTIONARY_KEY_BASEFONT));
    this.descendantFonts = fDictionary.getItem(COSName
        .getPDFName(FONT_DICTIONARY_KEY_DESCENDANT_FONTS));
    this.encoding = fDictionary.getItem(COSName
        .getPDFName(FONT_DICTIONARY_KEY_ENCODING));

    if ((basefont == null || "".equals(basefont)) || descendantFonts == null
        || encoding == null) {
      // ---- baseFont syntax isn't checked because of it is a convention not a
      // rule
      this.fontContainer.addError(new ValidationError(
          ERROR_FONTS_DICTIONARY_INVALID,
          "BaseFont, Encoding or DescendantFonts keys are missing"));
      return false;
    }
View Full Code Here

    // ---- a CIDFont is contained in the DescendantFonts array
    COSDocument cDoc = this.handler.getDocument().getDocument();
    COSArray array = COSUtils.getAsArray(descendantFonts, cDoc);

    if (array == null) {
      this.fontContainer.addError(new ValidationError(
          ERROR_FONTS_CIDKEYED_INVALID,
          "CIDFont is missing from the DescendantFonts array"));
      return false;
    }
    // ---- in PDF 1.4, this array must contain only one element,
    // because of a PDF/A should be a PDF 1.4, this method returns an error if
    // the array
    // has more than one element.
    if (array.size() != 1) {
      this.fontContainer.addError(new ValidationError(
          ERROR_FONTS_CIDKEYED_INVALID,
          "The DescendantFonts array should have one element."));
      return false;
    }

    this.cidFont = COSUtils.getAsDictionary(array.get(0), cDoc);
    if (this.cidFont == null) {
      this.fontContainer
      .addError(new ValidationError(ERROR_FONTS_CIDKEYED_INVALID,
          "The DescendantFonts array should have one element with is a dictionary."));
      return false;
    }

    String type = cidFont.getNameAsString(COSName
        .getPDFName(DICTIONARY_KEY_TYPE));
    String subtype = cidFont.getNameAsString(COSName
        .getPDFName(DICTIONARY_KEY_SUBTYPE));

    if ((type == null || "".equals(type))
        || (subtype == null || "".equals(subtype))) {
      this.fontContainer.addError(new ValidationError(
          ERROR_FONTS_DICTIONARY_INVALID,
          "Type and/or Subtype keys are missing"));
      return false;
    }

    boolean isT0 = FONT_DICTIONARY_VALUE_TYPE0.equals(subtype);
    boolean isT2 = FONT_DICTIONARY_VALUE_TYPE2.equals(subtype);
    // ---- Even if these entries are present, values must be checked.
    if (!FONT_DICTIONARY_VALUE_FONT.equals(type) || !(isT0 || isT2)) {
      this.fontContainer.addError(new ValidationError(
          ERROR_FONTS_DICTIONARY_INVALID,
          "Type and/or Subtype keys are missing"));
      return false;
    }

    // ---- BaseFont is mandatory
    String bf = cidFont.getNameAsString(COSName
        .getPDFName(FONT_DICTIONARY_KEY_BASEFONT));
    if (bf == null || "".equals(bf)) {
      this.fontContainer.addError(new ValidationError(
          ERROR_FONTS_DICTIONARY_INVALID, "BaseFont is missing"));
      return false;
    }

    // ---- checks others mandatory fields
View Full Code Here

   * @return
   */
  private boolean checkCIDSystemInfo(COSBase sysinfo, COSDocument cDoc) {
    COSDictionary cidSysInfo = COSUtils.getAsDictionary(sysinfo, cDoc);
    if (cidSysInfo == null) {
      this.fontContainer.addError(new ValidationError(
          ERROR_FONTS_CIDKEYED_SYSINFO));
      return false;
    }

    COSBase reg = cidSysInfo.getItem(COSName
        .getPDFName(FONT_DICTIONARY_KEY_SYSINFO_REGISTRY));
    COSBase ord = cidSysInfo.getItem(COSName
        .getPDFName(FONT_DICTIONARY_KEY_SYSINFO_ORDERING));
    COSBase sup = cidSysInfo.getItem(COSName
        .getPDFName(FONT_DICTIONARY_KEY_SYSINFO_SUPPLEMENT));

    if (!(COSUtils.isString(reg, cDoc) && COSUtils.isString(ord, cDoc) && COSUtils
        .isInteger(sup, cDoc))) {
      this.fontContainer.addError(new ValidationError(
          ERROR_FONTS_CIDKEYED_SYSINFO));
      return false;
    }

    return true;
View Full Code Here

      boolean mandatory) {
    if (COSUtils.isString(ctog, cDoc)) {
      // ---- valid only if the string is Identity
      String ctogStr = COSUtils.getAsString(ctog, cDoc);
      if (!FONT_DICTIONARY_VALUE_CMAP_IDENTITY.equals(ctogStr)) {
        this.fontContainer.addError(new ValidationError(
            ERROR_FONTS_CIDKEYED_CIDTOGID,"The CIDToGID entry is invalid"));
        return false;
      }
    } else if (COSUtils.isStream(ctog, cDoc)) {
      try {
        COSStream ctogMap = COSUtils.getAsStream(ctog, cDoc);
        this.cidToGidMap = new CIDToGIDMap();
        this.cidToGidMap.parseStream(ctogMap);
      } catch (IOException e) {
        // ---- map can be invalid, return a Validation Error
        this.fontContainer.addError(new ValidationError(
            ERROR_FONTS_CIDKEYED_CIDTOGID));
        return false;
      }
    } else if (mandatory) {
      this.fontContainer.addError(new ValidationError(
          ERROR_FONTS_CIDKEYED_CIDTOGID));
      return false;
    }
    return true;
  }
View Full Code Here

    if (COSUtils.isString(aEncoding, cDoc)) {
      // ---- if encoding is a string, only 2 values are allowed
      String str = COSUtils.getAsString(aEncoding, cDoc);
      if (!(FONT_DICTIONARY_VALUE_CMAP_IDENTITY_V.equals(str) || FONT_DICTIONARY_VALUE_CMAP_IDENTITY_H
          .equals(str))) {
        this.fontContainer.addError(new ValidationError(
            ERROR_FONTS_CIDKEYED_INVALID,
            "The CMap is a string but it isn't an Identity-H/V"));
        return false;
      }
      isIdentityCMap = true;
    } else if (COSUtils.isStream(aEncoding, cDoc)) {
      // ---- If the CMap is a stream, some fields are mandatory
      // and the CIDSytemInfo must be compared with the CIDSystemInfo
      // entry of the CIDFont.
      return processCMapAsStream(COSUtils.getAsStream(aEncoding, cDoc));
    } else {
      // ---- CMap type is invalid
      this.fontContainer.addError(new ValidationError(
          ERROR_FONTS_CIDKEYED_CMAP_INVALID_OR_MISSING,
          "The CMap type is invalid"));
      return false;
    }
    return true;
View Full Code Here

    }
    COSBase cmapUsed = aCMap.getItem(COSName.getPDFName(FONT_DICTIONARY_KEY_CMAP_USECMAP));

    if (!FONT_DICTIONARY_VALUE_TYPE_CMAP.equals(type)) {
      // ---- CMap type is invalid
      this.fontContainer.addError(new ValidationError(
          ERROR_FONTS_CIDKEYED_CMAP_INVALID_OR_MISSING,
          "The CMap type is invalid"));
      return false;
    }

    // ---- check the content of the CIDSystemInfo
    if (!checkCIDSystemInfo(sysinfo, cDoc)) {
      return false;
    }

    if (cmapName == null || "".equals(cmapName) || wmode > 1) {
      this.fontContainer.addError(new ValidationError(
          ERROR_FONTS_CIDKEYED_CMAP_INVALID_OR_MISSING,
          "Some elements in the CMap dictionary are missing or invalid"));
      return false;
    }

    try {

      CMap fontboxCMap = new CMapParser().parse(null, aCMap.getUnfilteredStream());
      int wmValue = fontboxCMap.getWMode();
      String cmnValue = fontboxCMap.getName();


      if (wmValue != wmode) {

        this.fontContainer.addError(new ValidationError(
            ERROR_FONTS_CIDKEYED_CMAP_INVALID_OR_MISSING,
            "WMode is inconsistent"));
        return false;
      }

      if (!cmnValue.equals(cmapName)) {

        this.fontContainer.addError(new ValidationError(
            ERROR_FONTS_CIDKEYED_CMAP_INVALID_OR_MISSING,
            "CMapName is inconsistent"));
        return false;
      }

    } catch (IOException e) {
      this.fontContainer.addError(new ValidationError(
          ERROR_FONTS_CID_CMAP_DAMAGED, "The CMap type is damaged"));
      return false;
    }

    if (cmapUsed != null) {
View Full Code Here

          .getPDFName(FONT_DICTIONARY_KEY_SYSINFO_REGISTRY)), cDoc);
      String ordCF = COSUtils.getAsString(cfsi.getItem(COSName
          .getPDFName(FONT_DICTIONARY_KEY_SYSINFO_ORDERING)), cDoc);

      if (!regCF.equals(regCM) || !ordCF.equals(ordCM)) {
        this.fontContainer.addError(new ValidationError(
            ERROR_FONTS_CIDKEYED_SYSINFO, "The CIDSystemInfo is inconsistent"));
        return false;
      }
    } // else cmap is null because it is a Identity-H/V
    return true;
View Full Code Here

      }

    }

    if (!(fname && flags && itangle && cheight && fbbox && asc && desc && stemv)) {
      this.fontContainer.addError(new ValidationError(
          ERROR_FONTS_DESCRIPTOR_INVALID, "Some mandatory fields are missing"));
      return false;
    }

    return true;
View Full Code Here

        .getPDFName(TRANSPARENCY_DICTIONARY_KEY_SOFT_MASK));
    if (smVal != null) {
      // ---- Soft Mask is valid only if it is a COSName equals to None
      if (!(smVal instanceof COSName && TRANSPARENCY_DICTIONARY_VALUE_SOFT_MASK_NONE
          .equals(((COSName) smVal).getName()))) {
        error.add(new ValidationError(ERROR_TRANSPARENCY_EXT_GS_SOFT_MASK, "SoftMask must be null or None"));
        return false;
      }
    }
    return true;
  }
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.