--- old/src/share/classes/org/jcp/xml/dsig/internal/dom/ApacheCanonicalizer.java 2013-06-28 11:34:40.860334066 -0400 +++ new/src/share/classes/org/jcp/xml/dsig/internal/dom/ApacheCanonicalizer.java 2013-06-28 11:34:40.688339419 -0400 @@ -2,44 +2,42 @@ * 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 +/** + * 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 * - * 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. + * 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: ApacheCanonicalizer.java,v 1.2 2008/07/24 15:20:32 mullan Exp $ + * $Id: ApacheCanonicalizer.java 1333869 2012-05-04 10:42:44Z coheigea $ */ package org.jcp.xml.dsig.internal.dom; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.IOException; import java.io.OutputStream; import java.security.spec.AlgorithmParameterSpec; import java.security.InvalidAlgorithmParameterException; import java.util.Set; -import java.util.logging.Logger; -import java.util.logging.Level; import javax.xml.crypto.*; import javax.xml.crypto.dom.DOMCryptoContext; import javax.xml.crypto.dsig.TransformException; import javax.xml.crypto.dsig.TransformService; -import javax.xml.crypto.dsig.XMLSignatureException; import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec; import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer; @@ -48,7 +46,7 @@ import com.sun.org.apache.xml.internal.security.transforms.Transform; import org.w3c.dom.Document; import org.w3c.dom.Element; -import org.w3c.dom.NodeList; +import org.w3c.dom.Node; public abstract class ApacheCanonicalizer extends TransformService { @@ -56,59 +54,69 @@ com.sun.org.apache.xml.internal.security.Init.init(); } - private static Logger log = Logger.getLogger("org.jcp.xml.dsig.internal.dom"); + private static java.util.logging.Logger log = + java.util.logging.Logger.getLogger("org.jcp.xml.dsig.internal.dom"); protected Canonicalizer apacheCanonicalizer; private Transform apacheTransform; protected String inclusiveNamespaces; protected C14NMethodParameterSpec params; protected Document ownerDoc; protected Element transformElem; - - public final AlgorithmParameterSpec getParameterSpec() { + + public final AlgorithmParameterSpec getParameterSpec() + { return params; } public void init(XMLStructure parent, XMLCryptoContext context) - throws InvalidAlgorithmParameterException { + throws InvalidAlgorithmParameterException + { if (context != null && !(context instanceof DOMCryptoContext)) { throw new ClassCastException ("context must be of type DOMCryptoContext"); } + if (parent == null || !(parent instanceof javax.xml.crypto.dom.DOMStructure)) { + throw new ClassCastException("parent must be of type DOMStructure"); + } transformElem = (Element) - ((javax.xml.crypto.dom.DOMStructure) parent).getNode(); + ((javax.xml.crypto.dom.DOMStructure)parent).getNode(); ownerDoc = DOMUtils.getOwnerDocument(transformElem); } public void marshalParams(XMLStructure parent, XMLCryptoContext context) - throws MarshalException { + throws MarshalException + { if (context != null && !(context instanceof DOMCryptoContext)) { throw new ClassCastException ("context must be of type DOMCryptoContext"); } + if (parent == null || !(parent instanceof javax.xml.crypto.dom.DOMStructure)) { + throw new ClassCastException("parent must be of type DOMStructure"); + } transformElem = (Element) - ((javax.xml.crypto.dom.DOMStructure) parent).getNode(); + ((javax.xml.crypto.dom.DOMStructure)parent).getNode(); ownerDoc = DOMUtils.getOwnerDocument(transformElem); } - - public Data canonicalize(Data data, XMLCryptoContext xc) - throws TransformException { + + public Data canonicalize(Data data, XMLCryptoContext xc) + throws TransformException + { return canonicalize(data, xc, null); } - public Data canonicalize(Data data, XMLCryptoContext xc, OutputStream os) - throws TransformException { - + public Data canonicalize(Data data, XMLCryptoContext xc, OutputStream os) + throws TransformException + { if (apacheCanonicalizer == null) { try { apacheCanonicalizer = Canonicalizer.getInstance(getAlgorithm()); - if (log.isLoggable(Level.FINE)) { - log.log(Level.FINE, "Created canonicalizer for algorithm: " - + getAlgorithm()); + if (log.isLoggable(java.util.logging.Level.FINE)) { + log.log(java.util.logging.Level.FINE, "Created canonicalizer for algorithm: " + getAlgorithm()); } } catch (InvalidCanonicalizerException ice) { throw new TransformException ("Couldn't find Canonicalizer for: " + getAlgorithm() + - ": " + ice.getMessage(), ice); + ": " + ice.getMessage(), ice); } } @@ -119,10 +127,10 @@ } try { - Set nodeSet = null; + Set nodeSet = null; if (data instanceof ApacheData) { - XMLSignatureInput in = - ((ApacheData) data).getXMLSignatureInput(); + XMLSignatureInput in = + ((ApacheData)data).getXMLSignatureInput(); if (in.isElement()) { if (inclusiveNamespaces != null) { return new OctetStreamData(new ByteArrayInputStream @@ -141,7 +149,7 @@ Utils.readBytesFromStream(in.getOctetStream())))); } } else if (data instanceof DOMSubTreeData) { - DOMSubTreeData subTree = (DOMSubTreeData) data; + DOMSubTreeData subTree = (DOMSubTreeData)data; if (inclusiveNamespaces != null) { return new OctetStreamData(new ByteArrayInputStream (apacheCanonicalizer.canonicalizeSubtree @@ -152,12 +160,13 @@ (subTree.getRoot()))); } } else if (data instanceof NodeSetData) { - NodeSetData nsd = (NodeSetData) data; + NodeSetData nsd = (NodeSetData)data; // convert Iterator to Set - nodeSet = Utils.toNodeSet(nsd.iterator()); - if (log.isLoggable(Level.FINE)) { - log.log(Level.FINE, "Canonicalizing " + nodeSet.size() - + " nodes"); + @SuppressWarnings("unchecked") + Set ns = Utils.toNodeSet(nsd.iterator()); + nodeSet = ns; + if (log.isLoggable(java.util.logging.Level.FINE)) { + log.log(java.util.logging.Level.FINE, "Canonicalizing " + nodeSet.size() + " nodes"); } } else { return new OctetStreamData(new ByteArrayInputStream( @@ -179,7 +188,8 @@ } public Data transform(Data data, XMLCryptoContext xc, OutputStream os) - throws TransformException { + throws TransformException + { if (data == null) { throw new NullPointerException("data must not be null"); } @@ -193,12 +203,11 @@ if (apacheTransform == null) { try { - apacheTransform = new Transform - (ownerDoc, getAlgorithm(), transformElem.getChildNodes()); + apacheTransform = + new Transform(ownerDoc, getAlgorithm(), transformElem.getChildNodes()); apacheTransform.setElement(transformElem, xc.getBaseURI()); - if (log.isLoggable(Level.FINE)) { - log.log(Level.FINE, "Created transform for algorithm: " - + getAlgorithm()); + if (log.isLoggable(java.util.logging.Level.FINE)) { + log.log(java.util.logging.Level.FINE, "Created transform for algorithm: " + getAlgorithm()); } } catch (Exception ex) { throw new TransformException @@ -208,26 +217,27 @@ XMLSignatureInput in; if (data instanceof ApacheData) { - if (log.isLoggable(Level.FINE)) { - log.log(Level.FINE, "ApacheData = true"); + if (log.isLoggable(java.util.logging.Level.FINE)) { + log.log(java.util.logging.Level.FINE, "ApacheData = true"); } - in = ((ApacheData) data).getXMLSignatureInput(); + in = ((ApacheData)data).getXMLSignatureInput(); } else if (data instanceof NodeSetData) { - if (log.isLoggable(Level.FINE)) { - log.log(Level.FINE, "isNodeSet() = true"); + if (log.isLoggable(java.util.logging.Level.FINE)) { + log.log(java.util.logging.Level.FINE, "isNodeSet() = true"); } if (data instanceof DOMSubTreeData) { - DOMSubTreeData subTree = (DOMSubTreeData) data; + DOMSubTreeData subTree = (DOMSubTreeData)data; in = new XMLSignatureInput(subTree.getRoot()); in.setExcludeComments(subTree.excludeComments()); } else { - Set nodeSet = - Utils.toNodeSet(((NodeSetData) data).iterator()); + @SuppressWarnings("unchecked") + Set nodeSet = + Utils.toNodeSet(((NodeSetData)data).iterator()); in = new XMLSignatureInput(nodeSet); } } else { - if (log.isLoggable(Level.FINE)) { - log.log(Level.FINE, "isNodeSet() = false"); + if (log.isLoggable(java.util.logging.Level.FINE)) { + log.log(java.util.logging.Level.FINE, "isNodeSet() = false"); } try { in = new XMLSignatureInput