Search in sources :

Example 1 with XmlSigPolicyQualifiersListType

use of xades4j.xml.bind.xades.XmlSigPolicyQualifiersListType in project xades4j by luisgoncalves.

the class ToXmlSignaturePolicyConverter method getSignaturePolicy.

private XmlSignaturePolicyIdType getSignaturePolicy(SignaturePolicyData sigPolicyData, Document doc) {
    XmlSignaturePolicyIdType xmlSigPolicyId = new XmlSignaturePolicyIdType();
    // Identifier
    xmlSigPolicyId.setSigPolicyId(ToXmlUtils.getXmlObjectId(sigPolicyData.getIdentifier()));
    // Hash
    XmlDigestMethodType xmlDigestMethod = new XmlDigestMethodType();
    xmlDigestMethod.setAlgorithm(sigPolicyData.getDigestAlgorithm());
    XmlDigestAlgAndValueType xmlDigest = new XmlDigestAlgAndValueType();
    xmlDigest.setDigestMethod(xmlDigestMethod);
    xmlDigest.setDigestValue(sigPolicyData.getDigestValue());
    xmlSigPolicyId.setSigPolicyHash(xmlDigest);
    // Qualifiers
    String url = sigPolicyData.getLocationUrl();
    if (url != null) {
        JAXBElement<String> xmlSPURI = new JAXBElement<String>(new QName(QualifyingProperty.XADES_XMLNS, "SPURI"), String.class, url);
        XmlAnyType xmlQualifier = new XmlAnyType();
        xmlQualifier.getContent().add(xmlSPURI);
        XmlSigPolicyQualifiersListType xmlQualifiers = new XmlSigPolicyQualifiersListType();
        xmlQualifiers.getSigPolicyQualifier().add(xmlQualifier);
        xmlSigPolicyId.setSigPolicyQualifiers(xmlQualifiers);
    }
    return xmlSigPolicyId;
}
Also used : XmlDigestAlgAndValueType(xades4j.xml.bind.xades.XmlDigestAlgAndValueType) XmlAnyType(xades4j.xml.bind.xades.XmlAnyType) QName(javax.xml.namespace.QName) XmlDigestMethodType(xades4j.xml.bind.xmldsig.XmlDigestMethodType) JAXBElement(javax.xml.bind.JAXBElement) XmlSignaturePolicyIdType(xades4j.xml.bind.xades.XmlSignaturePolicyIdType) XmlSigPolicyQualifiersListType(xades4j.xml.bind.xades.XmlSigPolicyQualifiersListType)

Example 2 with XmlSigPolicyQualifiersListType

use of xades4j.xml.bind.xades.XmlSigPolicyQualifiersListType in project xades4j by luisgoncalves.

the class FromXmlSignaturePolicyConverter method getLocationUrl.

private static String getLocationUrl(XmlSignaturePolicyIdType xmlPolicyId) throws PropertyUnmarshalException {
    XmlSigPolicyQualifiersListType sigPolicyQualifiers = xmlPolicyId.getSigPolicyQualifiers();
    if (null == sigPolicyQualifiers) {
        return null;
    }
    List<XmlAnyType> xmlQualifiers = sigPolicyQualifiers.getSigPolicyQualifier();
    for (XmlAnyType xmlQualifier : xmlQualifiers) {
        List content = xmlQualifier.getContent();
        if (content.size() == 1 && content.get(0) instanceof JAXBElement) {
            JAXBElement xmlSPURI = (JAXBElement) content.get(0);
            if (xmlSPURI.getName().getLocalPart().equals("SPURI") && xmlSPURI.getName().getNamespaceURI().equals(QualifyingProperty.XADES_XMLNS)) {
                return (String) xmlSPURI.getValue();
            }
        }
    }
    return null;
}
Also used : XmlAnyType(xades4j.xml.bind.xades.XmlAnyType) List(java.util.List) JAXBElement(javax.xml.bind.JAXBElement) XmlSigPolicyQualifiersListType(xades4j.xml.bind.xades.XmlSigPolicyQualifiersListType)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)2 XmlAnyType (xades4j.xml.bind.xades.XmlAnyType)2 XmlSigPolicyQualifiersListType (xades4j.xml.bind.xades.XmlSigPolicyQualifiersListType)2 List (java.util.List)1 QName (javax.xml.namespace.QName)1 XmlDigestAlgAndValueType (xades4j.xml.bind.xades.XmlDigestAlgAndValueType)1 XmlSignaturePolicyIdType (xades4j.xml.bind.xades.XmlSignaturePolicyIdType)1 XmlDigestMethodType (xades4j.xml.bind.xmldsig.XmlDigestMethodType)1