@Override
  public ISecurityHandler getSecurityHandler(COSEncryption encryption) throws COSSecurityException {
    COSName name = encryption.getFilter();
    if (name == null) {
      throw new COSSecurityException("security handler not specified"); // $NON-NLS-1$
    }
    if (name.equals(CN_Standard)) {
      int revision = encryption.getFieldInt(DK_R, 0);
      if (revision == 2) {
        return new StandardSecurityHandlerR2();
      } else if (revision == 3) {
        return new StandardSecurityHandlerR3();
      } else if (revision == 4) {
        return new StandardSecurityHandlerR4();
      } else {
        return new StandardSecurityHandlerR2();
      }
    }

    // maybe provide a registry some day
    throw new COSSecurityException(
        "no security handler '" //$NON-NLS-1$
            + name.stringValue()
            + "'"); //$NON-NLS-1$
  }
예제 #2
0
파일: PDFont.java 프로젝트: visik7/jpod
    /*
     * (non-Javadoc)
     *
     * @see
     * de.intarsys.pdf.cos.COSBasedObject.MetaClass#doDetermineClass(de.
     * intarsys.pdf.cos.COSObject)
     */
    @Override
    protected COSBasedObject.MetaClass doDetermineClass(COSObject object) {
      COSDictionary dict;

      dict = object.asDictionary();
      if (dict == null) {
        throw new IllegalArgumentException("font object is not a COSDictionary as required");
      }
      COSName type = dict.get(DK_Type).asName();
      if (type == null) {
        throw new IllegalArgumentException("Dictionary has no type");
      }
      if (!type.equals(CN_Type_Font)) {
        throw new IllegalArgumentException("type <" + type + "> is not a valid font type");
      }
      COSName subtype = dict.get(DK_Subtype).asName();
      if (subtype == null) {
        throw new IllegalArgumentException("font not identified by subtype");
      }
      if (subtype.equals(CN_Subtype_Type1)) {
        return PDFontType1.META;
      } else if (subtype.equals(CN_Subtype_TrueType)) {
        if (dict.get(DK_FontDescriptor).isNull()) {
          /*
           * treat as if Type1 was specified, because that's probably
           * what the creator meant; further processing would yield
           * wrong results anyway as FontDescriptor is a required
           * entry for TrueType fonts
           */
          return PDFontType1.META;
        }
        return PDFontTrueType.META;
      } else if (subtype.equals(CN_Subtype_MMType1)) {
        return PDFontMMType1.META;
      } else if (subtype.equals(CN_Subtype_Type0)) {
        return PDFontType0.META;
      } else if (subtype.equals(CN_Subtype_Type3)) {
        return PDFontType3.META;
      } else if (subtype.equals(CN_Subtype_CIDFontType0)) {
        return CIDFontType0.META;
      } else if (subtype.equals(CN_Subtype_CIDFontType2)) {
        return CIDFontType2.META;
      }
      throw new IllegalArgumentException("font subtype <" + subtype + "> not supported");
    }