--- old/src/share/classes/org/jcp/xml/dsig/internal/dom/DOMTransform.java 2013-06-28 11:34:59.931740420 -0400 +++ new/src/share/classes/org/jcp/xml/dsig/internal/dom/DOMTransform.java 2013-06-28 11:34:59.763745650 -0400 @@ -2,27 +2,29 @@ * reserved comment block * DO NOT REMOVE OR ALTER! */ -/* - * Copyright 2005 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ /* * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved. */ /* - * $Id: DOMTransform.java,v 1.2 2008/07/24 15:20:32 mullan Exp $ + * $Id: DOMTransform.java 1333415 2012-05-03 12:03:51Z coheigea $ */ package org.jcp.xml.dsig.internal.dom; @@ -35,13 +37,11 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; -import org.w3c.dom.NodeList; import javax.xml.crypto.*; import javax.xml.crypto.dsig.*; import javax.xml.crypto.dom.DOMCryptoContext; import javax.xml.crypto.dsig.dom.DOMSignContext; -import javax.xml.crypto.dsig.spec.TransformParameterSpec; /** * DOM-based abstract implementation of Transform. @@ -69,15 +69,26 @@ * @param transElem a Transform element */ public DOMTransform(Element transElem, XMLCryptoContext context, - Provider provider) throws MarshalException { + Provider provider) + throws MarshalException + { String algorithm = DOMUtils.getAttributeValue(transElem, "Algorithm"); - try { - spi = TransformService.getInstance(algorithm, "DOM"); - } catch (NoSuchAlgorithmException e1) { + + if (provider == null) { + try { + spi = TransformService.getInstance(algorithm, "DOM"); + } catch (NoSuchAlgorithmException e1) { + throw new MarshalException(e1); + } + } else { try { spi = TransformService.getInstance(algorithm, "DOM", provider); - } catch (NoSuchAlgorithmException e2) { - throw new MarshalException(e2); + } catch (NoSuchAlgorithmException nsae) { + try { + spi = TransformService.getInstance(algorithm, "DOM"); + } catch (NoSuchAlgorithmException e2) { + throw new MarshalException(e2); + } } } try { @@ -96,25 +107,29 @@ } /** - * This method invokes the abstract {@link #marshalParams marshalParams} + * This method invokes the abstract {@link #marshalParams marshalParams} * method to marshal any algorithm-specific parameters. */ public void marshal(Node parent, String dsPrefix, DOMCryptoContext context) - throws MarshalException { + throws MarshalException + { Document ownerDoc = DOMUtils.getOwnerDocument(parent); Element transformElem = null; if (parent.getLocalName().equals("Transforms")) { - transformElem = DOMUtils.createElement - (ownerDoc, "Transform", XMLSignature.XMLNS, dsPrefix); + transformElem = DOMUtils.createElement(ownerDoc, "Transform", + XMLSignature.XMLNS, + dsPrefix); } else { - transformElem = DOMUtils.createElement - (ownerDoc, "CanonicalizationMethod", XMLSignature.XMLNS, dsPrefix); + transformElem = DOMUtils.createElement(ownerDoc, + "CanonicalizationMethod", + XMLSignature.XMLNS, + dsPrefix); } DOMUtils.setAttribute(transformElem, "Algorithm", getAlgorithm()); - spi.marshalParams - (new javax.xml.crypto.dom.DOMStructure(transformElem), context); + spi.marshalParams(new javax.xml.crypto.dom.DOMStructure(transformElem), + context); parent.appendChild(transformElem); } @@ -131,7 +146,8 @@ * executing the transform */ public Data transform(Data data, XMLCryptoContext xc) - throws TransformException { + throws TransformException + { return spi.transform(data, xc); } @@ -149,10 +165,12 @@ * executing the transform */ public Data transform(Data data, XMLCryptoContext xc, OutputStream os) - throws TransformException { + throws TransformException + { return spi.transform(data, xc, os); } + @Override public boolean equals(Object o) { if (this == o) { return true; @@ -161,13 +179,25 @@ if (!(o instanceof Transform)) { return false; } - Transform otransform = (Transform) o; + Transform otransform = (Transform)o; return (getAlgorithm().equals(otransform.getAlgorithm()) && - DOMUtils.paramsEqual - (getParameterSpec(), otransform.getParameterSpec())); + DOMUtils.paramsEqual(getParameterSpec(), + otransform.getParameterSpec())); } + @Override + public int hashCode() { + int result = 17; + result = 31 * result + getAlgorithm().hashCode(); + AlgorithmParameterSpec spec = getParameterSpec(); + if (spec != null) { + result = 31 * result + spec.hashCode(); + } + + return result; + } + /** * Transforms the specified data using the underlying transform algorithm. * This method invokes the {@link #marshal marshal} method and passes it @@ -179,15 +209,16 @@ * @param context the marshalling context * @return the transformed data * @throws MarshalException if an exception occurs while marshalling - * @throws NullPointerException if data or context + * @throws NullPointerException if data or context * is null * @throws XMLSignatureException if an unexpected error occurs while * executing the transform */ Data transform(Data data, XMLCryptoContext xc, DOMSignContext context) - throws MarshalException, TransformException { + throws MarshalException, TransformException + { marshal(context.getParent(), - DOMUtils.getSignaturePrefix(context), context); + DOMUtils.getSignaturePrefix(context), context); return transform(data, xc); } }