コード例 #1
0
 /**
  * End Element handler
  *
  * @param namespaceURI namespace URI
  * @param lName local name
  * @param qName qualified name
  */
 public void endElement(String namespaceURI, String sName, String qName) throws SAXException {
   String tName = qName;
   if (tName.indexOf(":") != -1) tName = qName.substring(tName.indexOf(":") + 1);
   if (m_logger.isDebugEnabled()) m_logger.debug("End Element: " + tName);
   // remove last tag from stack
   String currTag = (String) m_tags.pop();
   //	<KeyName>
   if (tName.equals("KeyName")) {
     checkEncryptedData();
     EncryptedKey ekey = m_doc.getLastEncryptedKey();
     checkEncryptedKey(ekey);
     ekey.setKeyName(m_sbCollectChars.toString());
     m_sbCollectChars = null; // stop collecting
   }
   //	<CarriedKeyName>
   if (tName.equals("CarriedKeyName")) {
     checkEncryptedData();
     EncryptedKey ekey = m_doc.getLastEncryptedKey();
     checkEncryptedKey(ekey);
     ekey.setCarriedKeyName(m_sbCollectChars.toString());
     m_sbCollectChars = null; // stop collecting
   }
   //	<X509Certificate>
   if (tName.equals("X509Certificate")) {
     checkEncryptedData();
     EncryptedKey ekey = m_doc.getLastEncryptedKey();
     checkEncryptedKey(ekey);
     try {
       X509Certificate cert =
           SignedDoc.readCertificate(Base64Util.decode(m_sbCollectChars.toString().getBytes()));
       ekey.setRecipientsCertificate(cert);
     } catch (DigiDocException ex) {
       SAXDigiDocException.handleException(ex);
     }
     m_sbCollectChars = null; // stop collecting
   }
   //	<CipherValue>
   if (tName.equals("CipherValue")) {
     checkEncryptedData();
     if (m_tags.search("EncryptedKey") != -1) { // child of <EncryptedKey>
       EncryptedKey ekey = m_doc.getLastEncryptedKey();
       checkEncryptedKey(ekey);
       ekey.setTransportKeyData(Base64Util.decode(m_sbCollectChars.toString().getBytes()));
     } else { // child of <EncryptedData>
       m_doc.setData(Base64Util.decode(m_sbCollectChars.toString().getBytes()));
       if (m_doc.getMimeType() != null
           && m_doc.getMimeType().equals(EncryptedData.DENC_ENCDATA_MIME_ZLIB))
         m_doc.setDataStatus(EncryptedData.DENC_DATA_STATUS_ENCRYPTED_AND_COMPRESSED);
       else
         m_doc.setDataStatus(EncryptedData.DENC_DATA_STATUS_ENCRYPTED_AND_NOT_COMPRESSED); // ???		
     }
     m_sbCollectChars = null; // stop collecting
   }
   // <EncryptionProperty>
   if (tName.equals("EncryptionProperty")) {
     checkEncryptedData();
     EncryptionProperty eprop = m_doc.getLastProperty();
     try {
       eprop.setContent(m_sbCollectChars.toString());
     } catch (DigiDocException ex) {
       SAXDigiDocException.handleException(ex);
     }
     m_sbCollectChars = null; // stop collecting
   }
 }
コード例 #2
0
  /**
   * Start Element handler
   *
   * @param namespaceURI namespace URI
   * @param lName local name
   * @param qName qualified name
   * @param attrs attributes
   */
  public void startElement(String namespaceURI, String lName, String qName, Attributes attrs)
      throws SAXDigiDocException {
    String tName = qName;
    if (tName.indexOf(":") != -1) tName = qName.substring(qName.indexOf(":") + 1);
    if (m_logger.isDebugEnabled())
      m_logger.debug(
          "Start Element: "
              + tName
              + " qname: "
              + qName
              + " lname: "
              + lName
              + " uri: "
              + namespaceURI);
    m_tags.push(tName);
    if (tName.equals("KeyName")
        || tName.equals("CarriedKeyName")
        || tName.equals("X509Certificate")
        || tName.equals("CipherValue")
        || tName.equals("EncryptionProperty")) m_sbCollectChars = new StringBuffer();

    // <EncryptedData>
    if (tName.equals("EncryptedData")) {
      String str = findAtributeValue(attrs, "xmlns");
      try {
        m_doc = new EncryptedData(str);
        str = findAtributeValue(attrs, "Id");
        if (str != null) m_doc.setId(str);
        str = findAtributeValue(attrs, "Type");
        if (str != null) m_doc.setType(str);
        str = findAtributeValue(attrs, "MimeType");
        if (str != null) m_doc.setMimeType(str);
      } catch (DigiDocException ex) {
        SAXDigiDocException.handleException(ex);
      }
    }
    // <EncryptionMethod>
    if (tName.equals("EncryptionMethod")) {
      checkEncryptedData();
      if (m_tags.search("EncryptedKey") != -1) { // child of <EncryptedKey>
        EncryptedKey ekey = m_doc.getLastEncryptedKey();
        checkEncryptedKey(ekey);
        try {
          ekey.setEncryptionMethod(findAtributeValue(attrs, "Algorithm"));
        } catch (DigiDocException ex) {
          SAXDigiDocException.handleException(ex);
        }
      } else { // child of <EncryptedData>
        try {
          m_doc.setEncryptionMethod(findAtributeValue(attrs, "Algorithm"));
        } catch (DigiDocException ex) {
          SAXDigiDocException.handleException(ex);
        }
      }
    }
    // <EncryptedKey>
    if (tName.equals("EncryptedKey")) {
      checkEncryptedData();
      EncryptedKey ekey = new EncryptedKey();
      m_doc.addEncryptedKey(ekey);
      String str = findAtributeValue(attrs, "Recipient");
      if (str != null) ekey.setRecipient(str);
      str = findAtributeValue(attrs, "Id");
      if (str != null) ekey.setId(str);
    }
    // <EncryptionProperties>
    if (tName.equals("EncryptionProperties")) {
      checkEncryptedData();
      String str = findAtributeValue(attrs, "Id");
      if (str != null) m_doc.setEncryptionPropertiesId(str);
    }
    // <EncryptionProperty>
    if (tName.equals("EncryptionProperty")) {
      checkEncryptedData();
      EncryptionProperty eprop = new EncryptionProperty();
      m_doc.addProperty(eprop);
      String str = findAtributeValue(attrs, "Id");
      if (str != null) eprop.setId(str);
      str = findAtributeValue(attrs, "Target");
      if (str != null) eprop.setTarget(str);
      str = findAtributeValue(attrs, "Name");
      try {
        if (str != null) eprop.setName(str);
      } catch (DigiDocException ex) {
        SAXDigiDocException.handleException(ex);
      }
    }
  }