src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMUtils.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 27747 jdk/src/java.xml.crypto/share/classes/org/jcp/xml/dsig/internal/dom/DOMUtils.java@3a271dc8b758
child 50614 3810c9a2efa1
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
     2
 * reserved comment block
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 */
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
     5
/**
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
     7
 * or more contributor license agreements. See the NOTICE file
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
     8
 * distributed with this work for additional information
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
     9
 * regarding copyright ownership. The ASF licenses this file
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    10
 * to you under the Apache License, Version 2.0 (the
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    11
 * "License"); you may not use this file except in compliance
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    12
 * with the License. You may obtain a copy of the License at
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    13
 *
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    14
 * http://www.apache.org/licenses/LICENSE-2.0
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    15
 *
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    16
 * Unless required by applicable law or agreed to in writing,
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    17
 * software distributed under the License is distributed on an
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    18
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    19
 * KIND, either express or implied. See the License for the
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    20
 * specific language governing permissions and limitations
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    21
 * under the License.
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    22
 */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    23
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 19051
diff changeset
    24
 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    25
 */
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    26
/*
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    27
 * $Id: DOMUtils.java 1333415 2012-05-03 12:03:51Z coheigea $
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
package org.jcp.xml.dsig.internal.dom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.spec.AlgorithmParameterSpec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import org.w3c.dom.Attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import org.w3c.dom.Document;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import org.w3c.dom.Element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import org.w3c.dom.Node;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import org.w3c.dom.NodeList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.xml.crypto.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.xml.crypto.dsig.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.xml.crypto.dsig.spec.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Useful static DOM utility methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @author Sean Mullan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
public class DOMUtils {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    // class cannot be instantiated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private DOMUtils() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * Returns the owner document of the specified node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * @param node the node
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * @return the owner document
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public static Document getOwnerDocument(Node node) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        if (node.getNodeType() == Node.DOCUMENT_NODE) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    60
            return (Document)node;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            return node.getOwnerDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Creates an element in the specified namespace, with the specified tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * and namespace prefix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @param doc the owner document
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @param tag the tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * @param nsURI the namespace URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @param prefix the namespace prefix
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @return the newly created element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    76
    public static Element createElement(Document doc, String tag,
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    77
                                        String nsURI, String prefix)
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    78
    {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    79
        String qName = (prefix == null || prefix.length() == 0)
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    80
                       ? tag : prefix + ":" + tag;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        return doc.createElementNS(nsURI, qName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Sets an element's attribute (using DOM level 2) with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * specified value and namespace prefix.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @param elem the element to set the attribute on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @param name the name of the attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @param value the attribute value. If null, no attribute is set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public static void setAttribute(Element elem, String name, String value) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    93
        if (value == null) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    94
            return;
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
    95
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        elem.setAttributeNS(null, name, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Sets an element's attribute (using DOM level 2) with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * specified value and namespace prefix AND registers the ID value with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * the specified element. This is for resolving same-document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * ID references.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @param elem the element to set the attribute on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @param name the name of the attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @param value the attribute value. If null, no attribute is set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public static void setAttributeID(Element elem, String name, String value) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   110
        if (value == null) {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   111
            return;
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   112
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        elem.setAttributeNS(null, name, value);
18240
cda839ac048f 6741606: Integrate Apache Santuario
mullan
parents: 5506
diff changeset
   114
        elem.setIdAttributeNS(null, name, true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Returns the first child element of the specified node, or null if there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * is no such element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @param node the node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @return the first child element of the specified node, or null if there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *    is no such element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @throws NullPointerException if <code>node == null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public static Element getFirstChildElement(Node node) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        Node child = node.getFirstChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        while (child != null && child.getNodeType() != Node.ELEMENT_NODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            child = child.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   131
        return (Element)child;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
19051
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   135
     * Returns the first child element of the specified node and checks that
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   136
     * the local name is equal to {@code localName}.
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   137
     *
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   138
     * @param node the node
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   139
     * @return the first child element of the specified node
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   140
     * @throws NullPointerException if {@code node == null}
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   141
     * @throws MarshalException if no such element or the local name is not
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   142
     *    equal to {@code localName}
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   143
     */
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   144
    public static Element getFirstChildElement(Node node, String localName)
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   145
        throws MarshalException
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   146
    {
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   147
        return verifyElement(getFirstChildElement(node), localName);
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   148
    }
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   149
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   150
    private static Element verifyElement(Element elem, String localName)
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   151
        throws MarshalException
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   152
    {
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   153
        if (elem == null) {
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   154
            throw new MarshalException("Missing " + localName + " element");
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   155
        }
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   156
        String name = elem.getLocalName();
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   157
        if (!name.equals(localName)) {
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   158
            throw new MarshalException("Invalid element name: " +
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   159
                                       name + ", expected " + localName);
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   160
        }
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   161
        return elem;
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   162
    }
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   163
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   164
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Returns the last child element of the specified node, or null if there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * is no such element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @param node the node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @return the last child element of the specified node, or null if there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *    is no such element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @throws NullPointerException if <code>node == null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public static Element getLastChildElement(Node node) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        Node child = node.getLastChild();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        while (child != null && child.getNodeType() != Node.ELEMENT_NODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            child = child.getPreviousSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   178
        return (Element)child;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * Returns the next sibling element of the specified node, or null if there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * is no such element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @param node the node
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @return the next sibling element of the specified node, or null if there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *    is no such element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @throws NullPointerException if <code>node == null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public static Element getNextSiblingElement(Node node) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        Node sibling = node.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        while (sibling != null && sibling.getNodeType() != Node.ELEMENT_NODE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            sibling = sibling.getNextSibling();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   195
        return (Element)sibling;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
19051
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   199
     * Returns the next sibling element of the specified node and checks that
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   200
     * the local name is equal to {@code localName}.
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   201
     *
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   202
     * @param node the node
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   203
     * @return the next sibling element of the specified node
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   204
     * @throws NullPointerException if {@code node == null}
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   205
     * @throws MarshalException if no such element or the local name is not
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   206
     *    equal to {@code localName}
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   207
     */
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   208
    public static Element getNextSiblingElement(Node node, String localName)
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   209
        throws MarshalException
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   210
    {
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   211
        return verifyElement(getNextSiblingElement(node), localName);
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   212
    }
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   213
6c0cfc00b3ed 8012288: XML DSig API allows wrong tag names and extra elements in SignedInfo
mullan
parents: 18780
diff changeset
   214
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * Returns the attribute value for the attribute with the specified name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Returns null if there is no such attribute, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * the empty string if the attribute value is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * <p>This works around a limitation of the DOM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * <code>Element.getAttributeNode</code> method, which does not distinguish
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * between an unspecified attribute and an attribute with a value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * "" (it returns "" for both cases).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @param elem the element containing the attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @param name the name of the attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @return the attribute value (may be null if unspecified)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public static String getAttributeValue(Element elem, String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        Attr attr = elem.getAttributeNodeNS(null, name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return (attr == null) ? null : attr.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * Returns a Set of <code>Node</code>s, backed by the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * <code>NodeList</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @param nl the NodeList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @return a Set of Nodes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   240
    public static Set<Node> nodeSet(NodeList nl) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        return new NodeSet(nl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   244
    static class NodeSet extends AbstractSet<Node> {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        private NodeList nl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        public NodeSet(NodeList nl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            this.nl = nl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        public int size() { return nl.getLength(); }
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   251
        public Iterator<Node> iterator() {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   252
            return new Iterator<Node>() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                public void remove() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                    throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                }
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   258
                public Node next() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                    if (!hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                        throw new NoSuchElementException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    return nl.item(index++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                public boolean hasNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                    return index < nl.getLength() ? true : false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Returns the prefix associated with the specified namespace URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @param context contains the namespace map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @param nsURI the namespace URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @return the prefix associated with the specified namespace URI, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *    null if not set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public static String getNSPrefix(XMLCryptoContext context, String nsURI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if (context != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            return context.getNamespacePrefix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                (nsURI, context.getDefaultNamespacePrefix());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * Returns the prefix associated with the XML Signature namespace URI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * @param context contains the namespace map
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @return the prefix associated with the specified namespace URI, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *    null if not set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public static String getSignaturePrefix(XMLCryptoContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return getNSPrefix(context, XMLSignature.XMLNS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Removes all children nodes from the specified node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @param node the parent node whose children are to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public static void removeAllChildren(Node node) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        NodeList children = node.getChildNodes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        for (int i = 0, length = children.getLength(); i < length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            node.removeChild(children.item(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * Compares 2 nodes for equality. Implementation is not complete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public static boolean nodesEqual(Node thisNode, Node otherNode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        if (thisNode == otherNode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        if (thisNode.getNodeType() != otherNode.getNodeType()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        // FIXME - test content, etc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * Checks if child element has same owner document before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * appending to the parent, and imports it to the parent's document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    public static void appendChild(Node parent, Node child) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        Document ownerDoc = getOwnerDocument(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if (child.getOwnerDocument() != ownerDoc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            parent.appendChild(ownerDoc.importNode(child, true));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            parent.appendChild(child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    public static boolean paramsEqual(AlgorithmParameterSpec spec1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        AlgorithmParameterSpec spec2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        if (spec1 == spec2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        if (spec1 instanceof XPathFilter2ParameterSpec &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            spec2 instanceof XPathFilter2ParameterSpec) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   346
            return paramsEqual((XPathFilter2ParameterSpec)spec1,
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   347
                               (XPathFilter2ParameterSpec)spec2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        if (spec1 instanceof ExcC14NParameterSpec &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            spec2 instanceof ExcC14NParameterSpec) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            return paramsEqual((ExcC14NParameterSpec) spec1,
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   352
                               (ExcC14NParameterSpec)spec2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        if (spec1 instanceof XPathFilterParameterSpec &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            spec2 instanceof XPathFilterParameterSpec) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   356
            return paramsEqual((XPathFilterParameterSpec)spec1,
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   357
                               (XPathFilterParameterSpec)spec2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        if (spec1 instanceof XSLTTransformParameterSpec &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            spec2 instanceof XSLTTransformParameterSpec) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   361
            return paramsEqual((XSLTTransformParameterSpec)spec1,
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   362
                               (XSLTTransformParameterSpec)spec2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    private static boolean paramsEqual(XPathFilter2ParameterSpec spec1,
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   368
                                       XPathFilter2ParameterSpec spec2)
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   369
    {
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   370
        List<XPathType> types = spec1.getXPathList();
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   371
        List<XPathType> otypes = spec2.getXPathList();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        int size = types.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        if (size != otypes.size()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        for (int i = 0; i < size; i++) {
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   377
            XPathType type = types.get(i);
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   378
            XPathType otype = otypes.get(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            if (!type.getExpression().equals(otype.getExpression()) ||
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   380
                !type.getNamespaceMap().equals(otype.getNamespaceMap()) ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                type.getFilter() != otype.getFilter()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    private static boolean paramsEqual(ExcC14NParameterSpec spec1,
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   389
                                       ExcC14NParameterSpec spec2)
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   390
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        return spec1.getPrefixList().equals(spec2.getPrefixList());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    private static boolean paramsEqual(XPathFilterParameterSpec spec1,
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   395
                                       XPathFilterParameterSpec spec2)
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   396
    {
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   397
        return (spec1.getXPath().equals(spec2.getXPath()) &&
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   398
                spec1.getNamespaceMap().equals(spec2.getNamespaceMap()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    private static boolean paramsEqual(XSLTTransformParameterSpec spec1,
18780
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   402
                                       XSLTTransformParameterSpec spec2)
f47b920867e7 8011547: Update XML Signature implementation to Apache Santuario 1.5.4
mullan
parents: 18240
diff changeset
   403
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        XMLStructure ostylesheet = spec2.getStylesheet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        if (!(ostylesheet instanceof javax.xml.crypto.dom.DOMStructure)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        Node ostylesheetElem =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            ((javax.xml.crypto.dom.DOMStructure) ostylesheet).getNode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        XMLStructure stylesheet = spec1.getStylesheet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        Node stylesheetElem =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            ((javax.xml.crypto.dom.DOMStructure) stylesheet).getNode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        return nodesEqual(stylesheetElem, ostylesheetElem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
}