jdk/src/share/classes/com/sun/org/apache/xml/internal/security/c14n/helper/AttrCompare.java
author mullan
Mon, 26 Sep 2011 17:20:45 -0700
changeset 10694 cf59e2badd14
parent 1337 e8d6cef36199
child 18780 f47b920867e7
permissions -rw-r--r--
7088502: Security libraries don't build with javac -Werror Summary: Changes to files in src/share/classes/com/sun/org/apache/xml/internal/security and its subpackages to remove warnings Reviewed-by: mullan Contributed-by: kurchi.subhra.hazra@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * Copyright  1999-2004 The Apache Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *  Licensed under the Apache License, Version 2.0 (the "License");
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *  you may not use this file except in compliance with the License.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *  You may obtain a copy of the License at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *      http://www.apache.org/licenses/LICENSE-2.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *  Unless required by applicable law or agreed to in writing, software
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 *  distributed under the License is distributed on an "AS IS" BASIS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *  See the License for the specific language governing permissions and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *  limitations under the License.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
package com.sun.org.apache.xml.internal.security.c14n.helper;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
import com.sun.org.apache.xml.internal.security.utils.Constants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
import org.w3c.dom.Attr;
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    25
import java.io.Serializable;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    26
import java.util.Comparator;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * Compares two attributes based on the C14n specification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * <UL>
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    32
 * <LI>Namespace nodes have a lesser document order position than attribute
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    33
 *   nodes.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * <LI> An element's namespace nodes are sorted lexicographically by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *   local name (the default namespace node, if one exists, has no
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *   local name and is therefore lexicographically least).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <LI> An element's attribute nodes are sorted lexicographically with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *   namespace URI as the primary key and local name as the secondary
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *   key (an empty namespace URI is lexicographically least).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @author Christian Geuer-Pollmann
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
    44
public class AttrCompare implements Comparator<Attr>, Serializable {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    46
    private final static long serialVersionUID = -7113259629930576230L;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    47
    private final static int ATTR0_BEFORE_ATTR1 = -1;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    48
    private final static int ATTR1_BEFORE_ATTR0 = 1;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    49
    private final static String XMLNS=Constants.NamespaceSpecNS;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    51
    /**
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    52
     * Compares two attributes based on the C14n specification.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    53
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    54
     * <UL>
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    55
     * <LI>Namespace nodes have a lesser document order position than
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    56
     *   attribute nodes.
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    57
     * <LI> An element's namespace nodes are sorted lexicographically by
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    58
     *   local name (the default namespace node, if one exists, has no
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    59
     *   local name and is therefore lexicographically least).
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    60
     * <LI> An element's attribute nodes are sorted lexicographically with
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    61
     *   namespace URI as the primary key and local name as the secondary
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    62
     *   key (an empty namespace URI is lexicographically least).
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    63
     * </UL>
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    64
     *
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
    65
     * @param attr0
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
    66
     * @param attr1
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    67
     * @return returns a negative integer, zero, or a positive integer as
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    68
     *   obj0 is less than, equal to, or greater than obj1
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    69
     *
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    70
     */
10694
cf59e2badd14 7088502: Security libraries don't build with javac -Werror
mullan
parents: 1337
diff changeset
    71
    public int compare(Attr attr0, Attr attr1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    73
        String namespaceURI0 = attr0.getNamespaceURI();
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    74
        String namespaceURI1 = attr1.getNamespaceURI();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    76
        boolean isNamespaceAttr0 = XMLNS==namespaceURI0;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    77
        boolean isNamespaceAttr1 = XMLNS==namespaceURI1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    79
        if (isNamespaceAttr0) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    80
            if (isNamespaceAttr1) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    81
                // both are namespaces
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    82
                String localname0 = attr0.getLocalName();
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    83
                String localname1 = attr1.getLocalName();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    85
                if (localname0.equals("xmlns")) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    86
                    localname0 = "";
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    87
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    89
                if (localname1.equals("xmlns")) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    90
                    localname1 = "";
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    91
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    93
                return localname0.compareTo(localname1);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    94
            }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    95
            // attr0 is a namespace, attr1 is not
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    96
            return ATTR0_BEFORE_ATTR1;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    97
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
    99
        if (isNamespaceAttr1) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            // attr1 is a namespace, attr0 is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            return ATTR1_BEFORE_ATTR0;
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   102
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   104
        // none is a namespace
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   105
        if (namespaceURI0 == null) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   106
            if (namespaceURI1 == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                String name0 = attr0.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                String name1 = attr1.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                return name0.compareTo(name1);
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   110
            }
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   111
            return ATTR0_BEFORE_ATTR1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   114
        if (namespaceURI1 == null) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   115
            return ATTR1_BEFORE_ATTR0;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   116
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   118
        int a = namespaceURI0.compareTo(namespaceURI1);
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   119
        if (a != 0) {
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   120
            return a;
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   121
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
1337
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   123
        return (attr0.getLocalName()).compareTo(attr1.getLocalName());
e8d6cef36199 6469266: Integrate Apache XMLSec 1.4.2 into JDK 7
mullan
parents: 2
diff changeset
   124
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
}