Search in sources :

Example 6 with PropertyDataObject

use of xades4j.properties.data.PropertyDataObject in project xades4j by luisgoncalves.

the class BaseJAXBMarshaller method doMarshal.

protected void doMarshal(SigAndDataObjsPropertiesData properties, Node qualifyingPropsNode, TXml xmlProps) throws MarshalException {
    if (properties.isEmpty()) {
        return;
    }
    Document doc = qualifyingPropsNode.getOwnerDocument();
    Collection<PropertyDataObject> unknownSigProps = null;
    if (!properties.getSigProps().isEmpty()) {
        prepareSigProps(xmlProps);
        unknownSigProps = convert(properties.getSigProps(), xmlProps, doc);
    }
    Collection<PropertyDataObject> unknownDataObjProps = null;
    if (!properties.getDataObjProps().isEmpty()) {
        prepareDataObjsProps(xmlProps);
        unknownDataObjProps = convert(properties.getDataObjProps(), xmlProps, doc);
    }
    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));
    }
}
Also used : Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) PropertyDataObject(xades4j.properties.data.PropertyDataObject) Document(org.w3c.dom.Document)

Example 7 with PropertyDataObject

use of xades4j.properties.data.PropertyDataObject in project xades4j by luisgoncalves.

the class BaseJAXBMarshaller method marshallUnknownProps.

private void marshallUnknownProps(Collection<PropertyDataObject> unknownProps, Element parent) throws MarshalException {
    for (PropertyDataObject pData : unknownProps) {
        if (!(pData instanceof GenericDOMData)) {
            throw new UnsupportedDataObjectException(pData);
        }
        Node propElem = ((GenericDOMData) pData).getPropertyElement();
        if (propElem.getOwnerDocument() != parent.getOwnerDocument()) {
            propElem = parent.getOwnerDocument().importNode(propElem, true);
        }
        parent.appendChild(propElem);
    }
}
Also used : GenericDOMData(xades4j.properties.data.GenericDOMData) Node(org.w3c.dom.Node) PropertyDataObject(xades4j.properties.data.PropertyDataObject)

Example 8 with PropertyDataObject

use of xades4j.properties.data.PropertyDataObject in project xades4j by luisgoncalves.

the class BaseJAXBMarshaller method convert.

private Collection<PropertyDataObject> convert(Collection<PropertyDataObject> props, TXml xmlProps, Document doc) throws MarshalException {
    Collection<PropertyDataObject> unknownProps = null;
    // Convert each property to the corresponding JAXB object. Each converter
    // will add the corresponding object to the tree.
    // If a converter is not found, it means that the property is unknown in
    // this version of XAdES; it will be converted afterwards.
    QualifyingPropertyDataToXmlConverter<TXml> conv;
    for (PropertyDataObject p : props) {
        conv = this.converters.get(p.getClass());
        if (null == conv) {
            unknownProps = CollectionUtils.newIfNull(unknownProps, 1);
            unknownProps.add(p);
        } else {
            conv.convertIntoObjectTree(p, xmlProps, doc);
        }
    }
    return unknownProps;
}
Also used : PropertyDataObject(xades4j.properties.data.PropertyDataObject)

Aggregations

PropertyDataObject (xades4j.properties.data.PropertyDataObject)8 Node (org.w3c.dom.Node)4 ArrayList (java.util.ArrayList)2 Element (org.w3c.dom.Element)2 QualifyingProperty (xades4j.properties.QualifyingProperty)2 X509Certificate (java.security.cert.X509Certificate)1 Collection (java.util.Collection)1 Date (java.util.Date)1 XMLSecurityException (org.apache.xml.security.exceptions.XMLSecurityException)1 XMLSignature (org.apache.xml.security.signature.XMLSignature)1 Document (org.w3c.dom.Document)1 UnsupportedAlgorithmException (xades4j.UnsupportedAlgorithmException)1 Algorithm (xades4j.algorithms.Algorithm)1 CommitmentTypeData (xades4j.properties.data.CommitmentTypeData)1 GenericDOMData (xades4j.properties.data.GenericDOMData)1 ValidationData (xades4j.providers.ValidationData)1 RawSignatureVerifierContext (xades4j.verification.RawSignatureVerifier.RawSignatureVerifierContext)1 KeyInfoRes (xades4j.verification.SignatureUtils.KeyInfoRes)1 ReferencesRes (xades4j.verification.SignatureUtils.ReferencesRes)1 XmlAnyType (xades4j.xml.bind.xades.XmlAnyType)1