org.jcp.xml.dsig.internal.dom.DOMTransform Maven / Gradle / Ivy
The newest version!
/* */ package org.jcp.xml.dsig.internal.dom;
/* */
/* */ import java.io.OutputStream;
/* */ import java.security.InvalidAlgorithmParameterException;
/* */ import java.security.NoSuchAlgorithmException;
/* */ import java.security.spec.AlgorithmParameterSpec;
/* */ import javax.xml.crypto.Data;
/* */ import javax.xml.crypto.MarshalException;
/* */ import javax.xml.crypto.XMLCryptoContext;
/* */ import javax.xml.crypto.dom.DOMCryptoContext;
/* */ import javax.xml.crypto.dsig.Transform;
/* */ import javax.xml.crypto.dsig.TransformException;
/* */ import javax.xml.crypto.dsig.TransformService;
/* */ import javax.xml.crypto.dsig.dom.DOMSignContext;
/* */ import org.w3c.dom.Document;
/* */ import org.w3c.dom.Element;
/* */ import org.w3c.dom.Node;
/* */
/* */ public class DOMTransform extends DOMStructure
/* */ implements Transform
/* */ {
/* */ protected TransformService spi;
/* */
/* */ public DOMTransform(TransformService spi)
/* */ {
/* 40 */ this.spi = spi;
/* */ }
/* */
/* */ public DOMTransform(Element transElem, XMLCryptoContext context)
/* */ throws MarshalException
/* */ {
/* 52 */ Document ownerDoc = transElem.getOwnerDocument();
/* 53 */ String algorithm = DOMUtils.getAttributeValue(transElem, "Algorithm");
/* */ try {
/* 55 */ this.spi = TransformService.getInstance(algorithm, "DOM");
/* */ } catch (NoSuchAlgorithmException e) {
/* 57 */ throw new MarshalException(e);
/* */ }
/* */ try {
/* 60 */ this.spi.init(new javax.xml.crypto.dom.DOMStructure(transElem), context);
/* */ } catch (InvalidAlgorithmParameterException iape) {
/* 62 */ throw new MarshalException(iape);
/* */ }
/* */ }
/* */
/* */ public final AlgorithmParameterSpec getParameterSpec() {
/* 67 */ return this.spi.getParameterSpec();
/* */ }
/* */
/* */ public final String getAlgorithm() {
/* 71 */ return this.spi.getAlgorithm();
/* */ }
/* */
/* */ public void marshal(Node parent, String dsPrefix, DOMCryptoContext context)
/* */ throws MarshalException
/* */ {
/* 80 */ Document ownerDoc = DOMUtils.getOwnerDocument(parent);
/* */
/* 82 */ Element transformElem = null;
/* 83 */ if (parent.getLocalName().equals("Transforms")) {
/* 84 */ transformElem = DOMUtils.createElement(ownerDoc, "Transform", "http://www.w3.org/2000/09/xmldsig#", dsPrefix);
/* */ }
/* */ else {
/* 87 */ transformElem = DOMUtils.createElement(ownerDoc, "CanonicalizationMethod", "http://www.w3.org/2000/09/xmldsig#", dsPrefix);
/* */ }
/* */
/* 90 */ DOMUtils.setAttribute(transformElem, "Algorithm", getAlgorithm());
/* */
/* 92 */ this.spi.marshalParams(new javax.xml.crypto.dom.DOMStructure(transformElem), context);
/* */
/* 95 */ parent.appendChild(transformElem);
/* */ }
/* */
/* */ public Data transform(Data data, XMLCryptoContext xc)
/* */ throws TransformException
/* */ {
/* 111 */ return this.spi.transform(data, xc);
/* */ }
/* */
/* */ public Data transform(Data data, XMLCryptoContext xc, OutputStream os)
/* */ throws TransformException
/* */ {
/* 129 */ return this.spi.transform(data, xc, os);
/* */ }
/* */
/* */ public boolean equals(Object o) {
/* 133 */ if (this == o) {
/* 134 */ return true;
/* */ }
/* */
/* 137 */ if (!(o instanceof Transform)) {
/* 138 */ return false;
/* */ }
/* 140 */ Transform otransform = (Transform)o;
/* */
/* 142 */ return (getAlgorithm().equals(otransform.getAlgorithm())) && (DOMUtils.paramsEqual(getParameterSpec(), otransform.getParameterSpec()));
/* */ }
/* */
/* */ Data transform(Data data, XMLCryptoContext xc, DOMSignContext context)
/* */ throws MarshalException, TransformException
/* */ {
/* 165 */ marshal(context.getParent(), DOMUtils.getSignaturePrefix(context), context);
/* */
/* 167 */ return transform(data, xc);
/* */ }
/* */ }
/* Location: E:\HYN\Java\trunk\ref\lib-dep\xmldsig\xmldsig.jar
* Qualified Name: org.jcp.xml.dsig.internal.dom.DOMTransform
* JD-Core Version: 0.6.2
*/