コード例 #1
0
  private void transferProperties(Node qualifPropsNode, Node tempNode) {
    // The QualifyingProperties node already has a child element for the current
    // type of properties.
    Element existingProps =
        DOMHelper.getFirstDescendant(
            (Element) qualifPropsNode, QualifyingProperty.XADES_XMLNS, propsElemName);
    // The new properties (Signed or Unsigned) were marshalled into the temp
    // node.
    Element newProps = DOMHelper.getFirstChildElement(tempNode);

    Element newSpecificProps = DOMHelper.getFirstChildElement(newProps);
    do {
      Element existingSpecificProps =
          DOMHelper.getFirstDescendant(
              existingProps, newSpecificProps.getNamespaceURI(), newSpecificProps.getLocalName());

      if (null == existingSpecificProps)
        // No element for these properties. Append the new element to the existing
        // properties.
        existingProps.appendChild(newSpecificProps);
      else
        // There are properties. Transfer all the new properties into the existing
        // element.
        transferChildren(newSpecificProps, existingSpecificProps);

      newSpecificProps = DOMHelper.getNextSiblingElement(newSpecificProps);

    } while (newSpecificProps != null);
  }
コード例 #2
0
  protected void doMarshal(
      SigAndDataObjsPropertiesData properties, Node qualifyingPropsNode, TXml xmlProps)
      throws MarshalException {
    if (properties.isEmpty()) return;

    Collection<PropertyDataObject> unknownSigProps = null;
    if (!properties.getSigProps().isEmpty()) {
      prepareSigProps(xmlProps);
      unknownSigProps = convert(properties.getSigProps(), xmlProps);
    }

    Collection<PropertyDataObject> unknownDataObjProps = null;
    if (!properties.getDataObjProps().isEmpty()) {
      prepareDataObjsProps(xmlProps);
      unknownDataObjProps = convert(properties.getDataObjProps(), xmlProps);
    }

    if (propsNotAlreadyPresent(qualifyingPropsNode))
      // If the QualifyingProperties node doesn't already have an element
      // for the current type of properties, do a JAXB marshalling into it.
      doJAXBMarshalling(qualifyingPropsNode, xmlProps);
    else {
      // If it has, marshall into a temp node and transfer the resulting
      // nodes into the appropriate QualifyingProperties children.
      Node tempNode =
          DOMHelper.createElement(
              qualifyingPropsNode.getOwnerDocument(), "temp", null, QualifyingProperty.XADES_XMLNS);
      // - A little work around to inherit the namespace node defined in
      //   the document. Its just a matter of style.
      qualifyingPropsNode.appendChild(tempNode);
      doJAXBMarshalling(tempNode, xmlProps);
      qualifyingPropsNode.removeChild(tempNode);
      transferProperties(qualifyingPropsNode, tempNode);
    }

    // The top-most XML element for the current type of properties.
    Element topMostPropsElem =
        DOMHelper.getFirstDescendant(
            (Element) qualifyingPropsNode, QualifyingProperty.XADES_XMLNS, propsElemName);

    if (!CollectionUtils.nullOrEmpty(unknownSigProps))
      marshallUnknownProps(unknownSigProps, DOMHelper.getFirstChildElement(topMostPropsElem));
    if (!CollectionUtils.nullOrEmpty(unknownDataObjProps))
      marshallUnknownProps(unknownDataObjProps, DOMHelper.getLastChildElement(topMostPropsElem));
  }
コード例 #3
0
 private boolean propsNotAlreadyPresent(Node qualifyingPropsNode) {
   return null
       == DOMHelper.getFirstDescendant(
           (Element) qualifyingPropsNode, QualifyingProperty.XADES_XMLNS, propsElemName);
 }