org.jcp.xml.dsig.internal.dom.DOMXMLObject Maven / Gradle / Ivy
The newest version!
/* */ package org.jcp.xml.dsig.internal.dom;
/* */
/* */ import java.util.ArrayList;
/* */ import java.util.Collections;
/* */ import java.util.List;
/* */ import javax.xml.crypto.MarshalException;
/* */ import javax.xml.crypto.XMLCryptoContext;
/* */ import javax.xml.crypto.XMLStructure;
/* */ import javax.xml.crypto.dom.DOMCryptoContext;
/* */ import javax.xml.crypto.dsig.XMLObject;
/* */ import org.w3c.dom.Document;
/* */ import org.w3c.dom.Element;
/* */ import org.w3c.dom.Node;
/* */ import org.w3c.dom.NodeList;
/* */
/* */ public final class DOMXMLObject extends DOMStructure
/* */ implements XMLObject
/* */ {
/* */ private final String id;
/* */ private final String mimeType;
/* */ private final String encoding;
/* */ private final List content;
/* */
/* */ public DOMXMLObject(List content, String id, String mimeType, String encoding)
/* */ {
/* 46 */ if ((content == null) || (content.isEmpty())) {
/* 47 */ this.content = Collections.EMPTY_LIST;
/* */ } else {
/* 49 */ List contentCopy = new ArrayList(content);
/* 50 */ int i = 0; for (int size = contentCopy.size(); i < size; i++) {
/* 51 */ if (!(contentCopy.get(i) instanceof XMLStructure)) {
/* 52 */ throw new ClassCastException("content[" + i + "] is not a valid type");
/* */ }
/* */ }
/* */
/* 56 */ this.content = Collections.unmodifiableList(contentCopy);
/* */ }
/* 58 */ this.id = id;
/* 59 */ this.mimeType = mimeType;
/* 60 */ this.encoding = encoding;
/* */ }
/* */
/* */ public DOMXMLObject(Element objElem, XMLCryptoContext context)
/* */ throws MarshalException
/* */ {
/* 72 */ this.encoding = DOMUtils.getAttributeValue(objElem, "Encoding");
/* 73 */ this.id = DOMUtils.getAttributeValue(objElem, "Id");
/* 74 */ this.mimeType = DOMUtils.getAttributeValue(objElem, "MimeType");
/* */
/* 76 */ NodeList nodes = objElem.getChildNodes();
/* 77 */ int length = nodes.getLength();
/* 78 */ List content = new ArrayList(length);
/* 79 */ for (int i = 0; i < length; i++) {
/* 80 */ Node child = nodes.item(i);
/* 81 */ if (child.getNodeType() == 1) {
/* 82 */ Element childElem = (Element)child;
/* 83 */ String tag = childElem.getLocalName();
/* 84 */ if (tag.equals("Manifest")) {
/* 85 */ content.add(new DOMManifest(childElem, context));
/* 86 */ continue;
/* 87 */ }if (tag.equals("SignatureProperties")) {
/* 88 */ content.add(new DOMSignatureProperties(childElem));
/* 89 */ continue;
/* 90 */ }if (tag.equals("X509Data")) {
/* 91 */ content.add(new DOMX509Data(childElem));
/* 92 */ continue;
/* */ }
/* */ }
/* */
/* 96 */ content.add(new javax.xml.crypto.dom.DOMStructure(child));
/* */ }
/* 98 */ if (content.isEmpty())
/* 99 */ this.content = Collections.EMPTY_LIST;
/* */ else
/* 101 */ this.content = Collections.unmodifiableList(content);
/* */ }
/* */
/* */ public List getContent()
/* */ {
/* 106 */ return this.content;
/* */ }
/* */
/* */ public String getId() {
/* 110 */ return this.id;
/* */ }
/* */
/* */ public String getMimeType() {
/* 114 */ return this.mimeType;
/* */ }
/* */
/* */ public String getEncoding() {
/* 118 */ return this.encoding;
/* */ }
/* */
/* */ public void marshal(Node parent, String dsPrefix, DOMCryptoContext context) throws MarshalException
/* */ {
/* 123 */ Document ownerDoc = DOMUtils.getOwnerDocument(parent);
/* */
/* 125 */ Element objElem = DOMUtils.createElement(ownerDoc, "Object", "http://www.w3.org/2000/09/xmldsig#", dsPrefix);
/* */
/* 129 */ DOMUtils.setAttributeID(objElem, "Id", this.id);
/* 130 */ DOMUtils.setAttribute(objElem, "MimeType", this.mimeType);
/* 131 */ DOMUtils.setAttribute(objElem, "Encoding", this.encoding);
/* */
/* 134 */ int i = 0; for (int size = this.content.size(); i < size; i++) {
/* 135 */ XMLStructure object = (XMLStructure)this.content.get(i);
/* 136 */ if ((object instanceof DOMStructure)) {
/* 137 */ ((DOMStructure)object).marshal(objElem, dsPrefix, context);
/* */ } else {
/* 139 */ javax.xml.crypto.dom.DOMStructure domObject = (javax.xml.crypto.dom.DOMStructure)object;
/* */
/* 141 */ DOMUtils.appendChild(objElem, domObject.getNode());
/* */ }
/* */ }
/* */
/* 145 */ parent.appendChild(objElem);
/* */ }
/* */
/* */ public boolean equals(Object o) {
/* 149 */ if (this == o) {
/* 150 */ return true;
/* */ }
/* */
/* 153 */ if (!(o instanceof XMLObject)) {
/* 154 */ return false;
/* */ }
/* 156 */ XMLObject oxo = (XMLObject)o;
/* */
/* 158 */ boolean idsEqual = this.id == null ? false : oxo.getId() == null ? true : this.id.equals(oxo.getId());
/* */
/* 160 */ boolean encodingsEqual = this.encoding == null ? false : oxo.getEncoding() == null ? true : this.encoding.equals(oxo.getEncoding());
/* */
/* 162 */ boolean mimeTypesEqual = this.mimeType == null ? false : oxo.getMimeType() == null ? true : this.mimeType.equals(oxo.getMimeType());
/* */
/* 165 */ return (idsEqual) && (encodingsEqual) && (mimeTypesEqual) && (equalsContent(oxo.getContent()));
/* */ }
/* */
/* */ private boolean equalsContent(List otherContent)
/* */ {
/* 170 */ if (this.content.size() != otherContent.size()) {
/* 171 */ return false;
/* */ }
/* 173 */ int i = 0; for (int osize = otherContent.size(); i < osize; i++) {
/* 174 */ XMLStructure oxs = (XMLStructure)otherContent.get(i);
/* 175 */ XMLStructure xs = (XMLStructure)this.content.get(i);
/* 176 */ if ((oxs instanceof javax.xml.crypto.dom.DOMStructure)) {
/* 177 */ if (!(xs instanceof javax.xml.crypto.dom.DOMStructure)) {
/* 178 */ return false;
/* */ }
/* 180 */ Node onode = ((javax.xml.crypto.dom.DOMStructure)oxs).getNode();
/* */
/* 182 */ Node node = ((javax.xml.crypto.dom.DOMStructure)xs).getNode();
/* */
/* 184 */ if (!DOMUtils.nodesEqual(node, onode)) {
/* 185 */ return false;
/* */ }
/* */ }
/* 188 */ else if (!xs.equals(oxs)) {
/* 189 */ return false;
/* */ }
/* */
/* */ }
/* */
/* 194 */ return true;
/* */ }
/* */ }
/* Location: E:\HYN\Java\trunk\ref\lib-dep\xmldsig\xmldsig.jar
* Qualified Name: org.jcp.xml.dsig.internal.dom.DOMXMLObject
* JD-Core Version: 0.6.2
*/