public void marshal(Node parent, String dsPrefix, DOMCryptoContext context)
      throws MarshalException {
    Document ownerDoc = DOMUtils.getOwnerDocument(parent);

    Element pdElem = DOMUtils.createElement(ownerDoc, "PGPData", XMLSignature.XMLNS, dsPrefix);

    // create and append PGPKeyID element
    if (keyId != null) {
      Element keyIdElem =
          DOMUtils.createElement(ownerDoc, "PGPKeyID", XMLSignature.XMLNS, dsPrefix);
      keyIdElem.appendChild(ownerDoc.createTextNode(Base64.encode(keyId)));
      pdElem.appendChild(keyIdElem);
    }

    // create and append PGPKeyPacket element
    if (keyPacket != null) {
      Element keyPktElem =
          DOMUtils.createElement(ownerDoc, "PGPKeyPacket", XMLSignature.XMLNS, dsPrefix);
      keyPktElem.appendChild(ownerDoc.createTextNode(Base64.encode(keyPacket)));
      pdElem.appendChild(keyPktElem);
    }

    // create and append any elements
    for (int i = 0, size = externalElements.size(); i < size; i++) {
      DOMUtils.appendChild(
          pdElem, ((javax.xml.crypto.dom.DOMStructure) externalElements.get(i)).getNode());
    }

    parent.appendChild(pdElem);
  }
  public void marshal(Node parent, String dsPrefix, DOMCryptoContext context)
      throws MarshalException {
    if (log.isLoggable(Level.FINE)) {
      log.log(Level.FINE, "Marshalling Reference");
    }
    Document ownerDoc = DOMUtils.getOwnerDocument(parent);

    refElem = DOMUtils.createElement(ownerDoc, "Reference", XMLSignature.XMLNS, dsPrefix);

    // set attributes
    DOMUtils.setAttributeID(refElem, "Id", id);
    DOMUtils.setAttribute(refElem, "URI", uri);
    DOMUtils.setAttribute(refElem, "Type", type);

    // create and append Transforms element
    if (!transforms.isEmpty() || !appliedTransforms.isEmpty()) {
      Element transformsElem =
          DOMUtils.createElement(ownerDoc, "Transforms", XMLSignature.XMLNS, dsPrefix);
      refElem.appendChild(transformsElem);
      for (int i = 0, size = appliedTransforms.size(); i < size; i++) {
        DOMStructure transform = (DOMStructure) appliedTransforms.get(i);
        transform.marshal(transformsElem, dsPrefix, context);
      }
      for (int i = 0, size = transforms.size(); i < size; i++) {
        DOMStructure transform = (DOMStructure) transforms.get(i);
        transform.marshal(transformsElem, dsPrefix, context);
      }
    }

    // create and append DigestMethod element
    ((DOMDigestMethod) digestMethod).marshal(refElem, dsPrefix, context);

    // create and append DigestValue element
    if (log.isLoggable(Level.FINE)) {
      log.log(Level.FINE, "Adding digestValueElem");
    }
    Element digestValueElem =
        DOMUtils.createElement(ownerDoc, "DigestValue", XMLSignature.XMLNS, dsPrefix);
    if (digestValue != null) {
      digestValueElem.appendChild(ownerDoc.createTextNode(Base64.encode(digestValue)));
    }
    refElem.appendChild(digestValueElem);

    parent.appendChild(refElem);
    here = refElem.getAttributeNodeNS(null, "URI");
  }
  public void marshal(Node parent, String dsPrefix, DOMCryptoContext context)
      throws MarshalException {
    Document ownerDoc = DOMUtils.getOwnerDocument(parent);

    Element propElem =
        DOMUtils.createElement(ownerDoc, "SignatureProperty", XMLSignature.XMLNS, dsPrefix);

    // set attributes
    DOMUtils.setAttributeID(propElem, "Id", id);
    DOMUtils.setAttribute(propElem, "Target", target);

    // create and append any elements and mixed content
    for (int i = 0, size = content.size(); i < size; i++) {
      javax.xml.crypto.dom.DOMStructure property =
          (javax.xml.crypto.dom.DOMStructure) content.get(i);
      DOMUtils.appendChild(propElem, property.getNode());
    }

    parent.appendChild(propElem);
  }
Esempio n. 4
0
  public void marshal(Node parent, String dsPrefix, DOMCryptoContext context)
      throws MarshalException {
    Document ownerDoc = DOMUtils.getOwnerDocument(parent);

    Element objElem = DOMUtils.createElement(ownerDoc, "Object", XMLSignature.XMLNS, dsPrefix);

    // set attributes
    DOMUtils.setAttributeID(objElem, "Id", id);
    DOMUtils.setAttribute(objElem, "MimeType", mimeType);
    DOMUtils.setAttribute(objElem, "Encoding", encoding);

    // create and append any elements and mixed content, if necessary
    for (int i = 0, size = content.size(); i < size; i++) {
      XMLStructure object = (XMLStructure) content.get(i);
      if (object instanceof DOMStructure) {
        ((DOMStructure) object).marshal(objElem, dsPrefix, context);
      } else {
        javax.xml.crypto.dom.DOMStructure domObject = (javax.xml.crypto.dom.DOMStructure) object;
        DOMUtils.appendChild(objElem, domObject.getNode());
      }
    }

    parent.appendChild(objElem);
  }
  public void marshalParams(XMLStructure parent, XMLCryptoContext context) throws MarshalException {
    super.marshalParams(parent, context);
    XPathFilter2ParameterSpec xp = (XPathFilter2ParameterSpec) getParameterSpec();
    String prefix = DOMUtils.getNSPrefix(context, Transform.XPATH2);
    String qname = (prefix == null || prefix.length() == 0) ? "xmlns" : "xmlns:" + prefix;
    @SuppressWarnings("unchecked")
    List<XPathType> xpathList = xp.getXPathList();
    for (XPathType xpathType : xpathList) {
      Element elem = DOMUtils.createElement(ownerDoc, "XPath", Transform.XPATH2, prefix);
      elem.appendChild(ownerDoc.createTextNode(xpathType.getExpression()));
      DOMUtils.setAttribute(elem, "Filter", xpathType.getFilter().toString());
      elem.setAttributeNS("http://www.w3.org/2000/xmlns/", qname, Transform.XPATH2);

      // add namespace attributes, if necessary
      @SuppressWarnings("unchecked")
      Set<Map.Entry<String, String>> entries = xpathType.getNamespaceMap().entrySet();
      for (Map.Entry<String, String> entry : entries) {
        elem.setAttributeNS(
            "http://www.w3.org/2000/xmlns/", "xmlns:" + entry.getKey(), entry.getValue());
      }

      transformElem.appendChild(elem);
    }
  }