コード例 #1
0
  /**
   * Look up in the closest PDResources objects if there are a default ColorSpace. If there are,
   * check that is a authorized ColorSpace.
   *
   * @param colorSpace
   * @return true if the default colorspace is a right one, false otherwise.
   */
  protected boolean processDefaultColorSpace(PDColorSpace colorSpace) {
    boolean result = false;

    // get default color space
    PreflightPath vPath = context.getValidationPath();
    PDResources resources = vPath.getClosestPathElement(PDResources.class);
    if (resources != null) {
      PDColorSpace defaultCS = null;

      try {
        if (colorSpace.getName().equals(ColorSpaces.DeviceCMYK.getLabel())
            && resources.hasColorSpace(COSName.DEFAULT_CMYK)) {
          defaultCS = resources.getColorSpace(COSName.DEFAULT_CMYK);
        } else if (colorSpace.getName().equals(ColorSpaces.DeviceRGB.getLabel())
            && resources.hasColorSpace(COSName.DEFAULT_RGB)) {
          defaultCS = resources.getColorSpace(COSName.DEFAULT_RGB);
        } else if (colorSpace.getName().equals(ColorSpaces.DeviceGray.getLabel())
            && resources.hasColorSpace(COSName.DEFAULT_GRAY)) {
          defaultCS = resources.getColorSpace(COSName.DEFAULT_GRAY);
        }
      } catch (IOException e) {
        context.addValidationError(
            new ValidationError(
                ERROR_GRAPHIC_INVALID_COLOR_SPACE,
                "Unable to read default color space : " + e.getMessage(),
                e));
      }

      if (defaultCS != null) {
        // defaultCS is valid if the number of errors hasn't changed
        int nbOfErrors = context.getDocument().getResult().getErrorsList().size();
        processAllColorSpace(defaultCS);
        int newNbOfErrors = context.getDocument().getResult().getErrorsList().size();
        result = (nbOfErrors == newNbOfErrors);
      }
    }

    return result;
  }