org.duuba.xades.ReferenceInfo Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (C) 2021 The Duuba team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
******************************************************************************/
package org.duuba.xades;
import javax.xml.crypto.MarshalException;
import javax.xml.crypto.XMLCryptoContext;
import javax.xml.namespace.QName;
import org.apache.jcp.xml.dsig.internal.dom.XmlWriter;
import org.holodeckb2b.commons.util.Utils;
/**
* A representation of the ReferenceInfo
element as defined in respectively ETSI TS 101 903
* V1.4.1 andETSI EN 319 132 v1.1.1 standards. The XML schema is defined as:
*
* <xsd:element name="ReferenceInfo" type="ReferenceInfoType"/>
* <xsd:complexType name="ReferenceInfoType">
* <xsd:sequence>
* <xsd:element ref="ds:DigestMethod"/>
* <xsd:element ref="ds:DigestValue"/>
* </xsd:sequence>
* <xsd:attribute name="Id" type="xsd:ID" use="optional"/>
* <xsd:attribute name="URI" type="xsd:anyURI" use="optional"/>
* </xsd:complexType>
*
*
* @author Sander Fieten (sander at chasquis-messaging.com)
*/
public class ReferenceInfo extends AbstractDigestAlgAndValueTypeElement {
private static final QName ELEMENT_NAME = new QName(Constants.XADES_132_NS_URI, "ReferenceInfo",
Constants.XADES_132_NS_PREFIX);
private String id;
private String uri;
ReferenceInfo(final String id, final String uri, final String digestAlg, final byte[] digestVal) {
super(digestAlg, digestVal);
this.id = id;
this.uri = uri;
}
/**
* @return the Id
attribute (may be null
if not specified)
*/
public String getId() {
return id;
}
/**
* @return reference to the object included in the timestamp.
*/
public String getURI() {
return uri;
}
/**
* Determines whether the other object is an instance of the same class and represents the same element, i.e. has
* the same content.
*
* @param o the other object
* @return true
iff o
represents the same element, i.e. has the same qualified name
* and list of child elements.
*/
@Override
public boolean equals(Object o) {
if (!super.equals(o))
return false;
ReferenceInfo other = (ReferenceInfo) o;
return Utils.nullSafeEqual(this.id, other.id) && Utils.nullSafeEqual(this.uri, other.uri);
}
@Override
protected QName getName() {
return ELEMENT_NAME;
}
@Override
protected void writeContent(XmlWriter xwriter, String nsPrefix, String dsPrefix, XMLCryptoContext context)
throws MarshalException {
// Write attributes
if (id != null && !id.isEmpty())
xwriter.writeIdAttribute("", Constants.XADES_141_NS_URI, "Id", id);
if (uri != null && !uri.isEmpty())
xwriter.writeIdAttribute("", Constants.XADES_132_NS_URI, "URI", uri);
super.writeContent(xwriter, nsPrefix, dsPrefix, context);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy