Package org.apache.padaf.preflight.ValidationResult

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


  protected COSDictionary getShadingDictionary(List<ValidationError> errors) {
    if (pattern.getItem(COSName.getPDFName(PATTERN_KEY_SHADING_TYPE)) == null
        && !"Shading".equals(pattern.getNameAsString(COSName.getPDFName(DICTIONARY_KEY_TYPE)))) {
      COSBase shading = pattern.getItem(COSName.getPDFName(PATTERN_KEY_SHADING));
      if (shading == null) {
        errors.add(new ValidationError(ERROR_GRAPHIC_INVALID_PATTERN_DEFINITION));
        return null;
      }
      return COSUtils.getAsDictionary(shading, cosDoc);
    } else {
      return pattern;
View Full Code Here


    // ---- the Widths value can be a reference to an object
    // ---- Access the object using the COSkey
    COSArray wArr = COSUtils.getAsArray(this.widths, cDoc);
    if (wArr == null) {
      this.fontContainer.addError(new ValidationError(
          ERROR_FONTS_DICTIONARY_INVALID,
          "The Witdhs array is unreachable"));
      return false;
    }

    COSDictionary charProcsDictionary = COSUtils.getAsDictionary(this.charProcs, cDoc);
    if (charProcsDictionary == null) {
      this.fontContainer.addError(new ValidationError(
          ERROR_FONTS_DICTIONARY_INVALID,
          "The CharProcs element isn't a dictionary"));
      return false;
    }

    // ---- firstChar and lastChar must be integer.
    int fc = ((COSInteger) this.firstChar).intValue();
    int lc = ((COSInteger) this.lastChar).intValue();

    // ---- wArr length = (lc - fc) +1 and it is an array of int.
    // ---- If FirstChar is greater than LastChar, the validation will fail
    // because of
    // ---- the array will have an expected size <= 0.
    int expectedLength = (lc - fc) + 1;
    if (wArr.size() != expectedLength) {
      this.fontContainer.addError(new ValidationError(
          ERROR_FONTS_DICTIONARY_INVALID,
          "The length of Witdhs array is invalid. Expected : \""
              + expectedLength + "\" Current : \"" + wArr.size() + "\""));
      return false;
    }

    // ---- Check width consistency
    for (int i = 0; i < expectedLength; i++) {
      int cid = fc + i;
      COSBase arrContent = wArr.get(i);
      if (COSUtils.isNumeric(arrContent, cDoc)) {
        float width = COSUtils.getAsFloat(arrContent, cDoc);

        String charName = null;
        try {
          charName = this.type3Encoding.getName(cid);
        } catch (IOException e) {
          // shouldn't occur
          throw new ValidationException("Unable to check Widths consistency", e);
        }

        COSBase item = charProcsDictionary.getItem(COSName.getPDFName(charName));
        COSStream charStream = COSUtils.getAsStream(item, cDoc);
        if (charStream == null) {
          /* There are no character description, we declare the Glyph as Invalid.
           * If the character is used in a Stream, the GlyphDetail will throw an exception.
           */
          GlyphException glyphEx = new GlyphException(ERROR_FONTS_METRICS, cid,
              "The CharProcs \"" + charName
              + "\" doesn't exist, the width defines in the Font Dictionary is " + width);
          GlyphDetail glyphDetail = new GlyphDetail(cid, glyphEx);
          this.fontContainer.addKnownCidElement(glyphDetail);
        } else {
          try {
            // --- Parse the Glyph description to obtain the Width
            PDFAType3StreamParser parser = new PDFAType3StreamParser(
                this.handler);
            PDResources pRes = null;
            if (this.resources != null) {
              COSDictionary resAsDict = COSUtils.getAsDictionary(
                  this.resources, cDoc);
              if (resAsDict != null) {
                pRes = new PDResources(resAsDict);
              }
            }
            parser.resetEngine();
            parser.processSubStream(null, pRes, charStream);

            if (width != parser.getWidth()) {
              GlyphException glyphEx = new GlyphException(ERROR_FONTS_METRICS, cid,
                  "The CharProcs \"" + charName
                  + "\" should have a width equals to " + width);
              GlyphDetail glyphDetail = new GlyphDetail(cid, glyphEx);
              this.fontContainer.addKnownCidElement(glyphDetail);
            } else {
              // Glyph is OK, we keep the CID.
              GlyphDetail glyphDetail = new GlyphDetail(cid);
              this.fontContainer.addKnownCidElement(glyphDetail);
            }
          } catch (ContentStreamException e) {
            this.fontContainer.addError(new ValidationError(e
                .getValidationError()));
            return false;
          } catch (IOException e) {
            this.fontContainer.addError(new ValidationError(
                ERROR_FONTS_TYPE3_DAMAGED,
                "The CharProcs references an element which can't be read"));
            return false;
          }
        }

      } else {
        this.fontContainer.addError(new ValidationError(
            ERROR_FONTS_DICTIONARY_INVALID,
            "The Witdhs array is invalid. (some element aren't integer)"));
        return false;
      }
    }
View Full Code Here

    }

    COSDocument cDoc = this.handler.getDocument().getDocument();
    COSDictionary dictionary = COSUtils.getAsDictionary(this.resources, cDoc);
    if (dictionary == null) {
      this.fontContainer.addError(new ValidationError(
          ERROR_FONTS_DICTIONARY_INVALID,
          "The Resources element isn't a dictionary"));
      return false;
    }

    COSBase cbImg = dictionary.getItem(COSName
        .getPDFName(DICTIONARY_KEY_XOBJECT));
    COSBase cbFont = dictionary
        .getItem(COSName.getPDFName(DICTIONARY_KEY_FONT));



    if (cbImg != null) {
      // ---- the referenced objects must be present in the PDF file
      COSDictionary dicImgs = COSUtils.getAsDictionary(cbImg, cDoc);
      Set<COSName> keyList = dicImgs.keySet();
      for (Object key : keyList) {

        COSBase item = dictionary.getItem((COSName) key);
        COSDictionary xObjImg = COSUtils.getAsDictionary(item, cDoc);
        if (xObjImg == null) {
          this.fontContainer.addError(new ValidationError(
              ERROR_FONTS_DICTIONARY_INVALID,
              "The Resources dictionary of type 3 font is invalid"));
          return false;
        }

        if (!XOBJECT_DICTIONARY_VALUE_SUBTYPE_IMG.equals(xObjImg
            .getString(COSName.getPDFName(DICTIONARY_KEY_SUBTYPE)))) {
          this.fontContainer.addError(new ValidationError(
              ERROR_FONTS_DICTIONARY_INVALID,
              "The Resources dictionary of type 3 font is invalid"));
          return false;
        }
      }
    }

    if (cbFont != null) {
      // ---- the referenced object must be present in the PDF file
      COSDictionary dicFonts = COSUtils.getAsDictionary(cbFont, cDoc);
      Set<COSName> keyList = dicFonts.keySet();
      for (Object key : keyList) {

        COSBase item = dictionary.getItem((COSName) key);
        COSDictionary xObjFont = COSUtils.getAsDictionary(item, cDoc);
        if (xObjFont == null) {
          this.fontContainer.addError(new ValidationError(
              ERROR_FONTS_DICTIONARY_INVALID,
              "The Resources dictionary of type 3 font is invalid"));
          return false;
        }

        if (!FONT_DICTIONARY_VALUE_FONT.equals(xObjFont.getString(COSName
            .getPDFName(DICTIONARY_KEY_TYPE)))) {
          this.fontContainer.addError(new ValidationError(
              ERROR_FONTS_DICTIONARY_INVALID,
              "The Resources dictionary of type 3 font is invalid"));
          return false;
        }

        try {
          PDFont aFont = PDFontFactory.createFont(xObjFont);
          // FontContainer aContainer = this.handler.retrieveFontContainer(aFont);
          AbstractFontContainer aContainer = this.handler.getFont(aFont.getCOSObject());
          // ---- another font is used in the Type3, check if the font is valid.
          if (aContainer.isValid() != State.VALID) {
            this.fontContainer
            .addError(new ValidationError(ERROR_FONTS_TYPE3_DAMAGED,
                "The Resources dictionary of type 3 font contains invalid font"));
            return false;
          }
        } catch (IOException e) {
          throw new ValidationException("Unable to valid the Type3 : "
View Full Code Here

   * @throws ValidationException
   */
  protected boolean checkShadingDictionary(COSDictionary shadingDict,
      List<ValidationError> errors) throws ValidationException {
    if (shadingDict.getItem(COSName.getPDFName(PATTERN_KEY_SHADING_TYPE)) == null) {
      errors.add(new ValidationError(ERROR_GRAPHIC_INVALID_PATTERN_DEFINITION));
      return false;
    }

    COSBase csImg = shadingDict.getItem(COSName
        .getPDFName(XOBJECT_DICTIONARY_KEY_COLOR_SPACE));
View Full Code Here

    AnnotationValidator av = null;

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

    if (subtype == null || "".equals(subtype)) {
      errors.add(new ValidationError(ERROR_ANNOT_MISSING_SUBTYPE));
    } else {
      if (ANNOT_DICTIONARY_VALUE_SUBTYPE_TEXT.equals(subtype)) {
        av = new TextAnnotationValidator(handler, annotDic);
      } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_LINK.equals(subtype)) {
        av = new LinkAnnotationValidator(handler, annotDic);
      } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_FREETEXT.equals(subtype)) {
        av = new FreeTextAnnotationValidator(handler, annotDic);
      } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_LINE.equals(subtype)) {
        av = new LineAnnotationValidator(handler, annotDic);
      } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_SQUARE.equals(subtype)
          || ANNOT_DICTIONARY_VALUE_SUBTYPE_CIRCLE.equals(subtype)) {
        av = new SquareCircleAnnotationValidator(handler, annotDic);
      } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_HIGHLIGHT.equals(subtype)
          || ANNOT_DICTIONARY_VALUE_SUBTYPE_UNDERLINE.equals(subtype)
          || ANNOT_DICTIONARY_VALUE_SUBTYPE_STRIKEOUT.equals(subtype)
          || ANNOT_DICTIONARY_VALUE_SUBTYPE_SQUILGGLY.equals(subtype)) {
        av = new MarkupAnnotationValidator(handler, annotDic);
      } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_STAMP.equals(subtype)) {
        av = new RubberStampAnnotationValidator(handler, annotDic);
      } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_INK.equals(subtype)) {
        av = new InkAnnotationValdiator(handler, annotDic);
      } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_POPUP.equals(subtype)) {
        av = new PopupAnnotationValidator(handler, annotDic);
      } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_WIDGET.equals(subtype)) {
        av = new WidgetAnnotationValidator(handler, annotDic);
      } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_PRINTERMARK.equals(subtype)) {
        av = new PrintMarkAnnotationValidator(handler, annotDic);
      } else if (ANNOT_DICTIONARY_VALUE_SUBTYPE_TRAPNET.equals(subtype)) {
        av = new TrapNetAnnotationValidator(handler, annotDic);
      } else {
        errors.add(new ValidationError(ERROR_ANNOT_FORBIDDEN_SUBTYPE,
            "The subtype isn't authorized : " + subtype));
      }
    }

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

  /**
   * This method updates the given list with a ValidationError
   * (ERROR_GRAPHIC_INVALID_PATTERN_COLOR_SPACE_FORBIDDEN) and returns false.
   */
  protected boolean processPatternColorSpace(List<ValidationError> result) {
    result.add(new ValidationError(
        ERROR_GRAPHIC_INVALID_PATTERN_COLOR_SPACE_FORBIDDEN, "Pattern color space is forbidden"));
    return false;
  }
View Full Code Here

    res = res
        && pattern.getItem(COSName.getPDFName(PATTERN_KEY_TILING_TYPE)) != null;
    res = res && pattern.getItem(COSName.getPDFName(PATTERN_KEY_XSTEP)) != null;
    res = res && pattern.getItem(COSName.getPDFName(PATTERN_KEY_YSTEP)) != null;
    if (!res) {
      errors.add(new ValidationError(ERROR_GRAPHIC_INVALID_PATTERN_DEFINITION));
    }
    return res;
  }
View Full Code Here

  protected boolean checkSpecificMandatoryFields() {
    // ---- name is required only in a PDF-1.0.
    // ---- Currently our grammar matches only with PDF-1.[1-4]
    // ---- BaseFont is required and is usually the FontName
    if (basefont == null || "".equals(basefont)) {
      this.fontContainer.addError(new ValidationError(
          ERROR_FONTS_DICTIONARY_INVALID, "BaseFont is missing"));
      // continue to process this font dictionary is useless
      return false;
    }

    boolean allPresent = (firstChar != null && lastChar != null && widths != null);
    if (!allPresent) {
      this.fontContainer.addError(new ValidationError(
          ERROR_FONTS_DICTIONARY_INVALID, "Required keys are missing"));
      return false;
    } // else  ok

View Full Code Here

        .getPDFName(ANNOT_DICTIONARY_VALUE_SUBTYPE_POPUP));
    if (cosPopup != null) {
      COSDictionary popupDict = COSUtils.getAsDictionary(cosPopup, this.cosDoc);
      if (popupDict == null) {
        errors
            .add(new ValidationError(
                ERROR_SYNTAX_DICT_INVALID,
                "An Annotation has a Popup entry, but the value is missing or isn't a dictionary"));
        return false;
      }
      AnnotationValidator popupVal = this.annotFact.getAnnotationValidator(popupDict, handler,
View Full Code Here

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

    if (this.fDescriptor == null) {
      this.fontContainer
          .addError(new ValidationError(ERROR_FONTS_FONT_FILEX_INVALID,
              "The FontDescriptor is missing, so the Font Program isn't embedded."));
      this.fontContainer.setFontProgramEmbedded(false);
      return false;
    }

    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;
    } else {
      extractElementsToCheck();
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.