Fri, 23 Aug 2013 09:57:21 +0100
8022885: Update JAX-WS RI integration to 2.2.9-b14140
8013016: Rebase 8009009 against the latest jdk8/jaxws
Reviewed-by: alanb, chegar
ohair@286 | 1 | /* |
mkos@397 | 2 | * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. |
ohair@286 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ohair@286 | 4 | * |
ohair@286 | 5 | * This code is free software; you can redistribute it and/or modify it |
ohair@286 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@286 | 7 | * published by the Free Software Foundation. Oracle designates this |
ohair@286 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@286 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
ohair@286 | 10 | * |
ohair@286 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ohair@286 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ohair@286 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ohair@286 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
ohair@286 | 15 | * accompanied this code). |
ohair@286 | 16 | * |
ohair@286 | 17 | * You should have received a copy of the GNU General Public License version |
ohair@286 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
ohair@286 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ohair@286 | 20 | * |
ohair@286 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@286 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@286 | 23 | * questions. |
ohair@286 | 24 | */ |
ohair@286 | 25 | |
ohair@286 | 26 | package com.sun.xml.internal.dtdparser; |
ohair@286 | 27 | |
ohair@286 | 28 | |
ohair@286 | 29 | /** |
ohair@286 | 30 | * This class contains static methods used to determine whether identifiers |
ohair@286 | 31 | * may appear in certain roles in XML documents. Such methods are used |
ohair@286 | 32 | * both to parse and to create such documents. |
ohair@286 | 33 | * |
ohair@286 | 34 | * @author David Brownell |
ohair@286 | 35 | * @version 1.1, 00/08/05 |
ohair@286 | 36 | */ |
ohair@286 | 37 | public class XmlNames { |
ohair@286 | 38 | private XmlNames() { |
ohair@286 | 39 | } |
ohair@286 | 40 | |
ohair@286 | 41 | |
ohair@286 | 42 | /** |
ohair@286 | 43 | * Returns true if the value is a legal XML name. |
ohair@286 | 44 | * |
ohair@286 | 45 | * @param value the string being tested |
ohair@286 | 46 | */ |
ohair@286 | 47 | public static boolean isName(String value) { |
ohair@286 | 48 | if (value == null) |
ohair@286 | 49 | return false; |
ohair@286 | 50 | |
ohair@286 | 51 | char c = value.charAt(0); |
ohair@286 | 52 | if (!XmlChars.isLetter(c) && c != '_' && c != ':') |
ohair@286 | 53 | return false; |
ohair@286 | 54 | for (int i = 1; i < value.length(); i++) |
ohair@286 | 55 | if (!XmlChars.isNameChar(value.charAt(i))) |
ohair@286 | 56 | return false; |
ohair@286 | 57 | return true; |
ohair@286 | 58 | } |
ohair@286 | 59 | |
ohair@286 | 60 | /** |
ohair@286 | 61 | * Returns true if the value is a legal "unqualified" XML name, as |
ohair@286 | 62 | * defined in the XML Namespaces proposed recommendation. |
ohair@286 | 63 | * These are normal XML names, except that they may not contain |
ohair@286 | 64 | * a "colon" character. |
ohair@286 | 65 | * |
ohair@286 | 66 | * @param value the string being tested |
ohair@286 | 67 | */ |
ohair@286 | 68 | public static boolean isUnqualifiedName(String value) { |
ohair@286 | 69 | if (value == null || value.length() == 0) |
ohair@286 | 70 | return false; |
ohair@286 | 71 | |
ohair@286 | 72 | char c = value.charAt(0); |
ohair@286 | 73 | if (!XmlChars.isLetter(c) && c != '_') |
ohair@286 | 74 | return false; |
ohair@286 | 75 | for (int i = 1; i < value.length(); i++) |
ohair@286 | 76 | if (!XmlChars.isNCNameChar(value.charAt(i))) |
ohair@286 | 77 | return false; |
ohair@286 | 78 | return true; |
ohair@286 | 79 | } |
ohair@286 | 80 | |
ohair@286 | 81 | /** |
ohair@286 | 82 | * Returns true if the value is a legal "qualified" XML name, as defined |
ohair@286 | 83 | * in the XML Namespaces proposed recommendation. Qualified names are |
ohair@286 | 84 | * composed of an optional prefix (an unqualified name), followed by a |
ohair@286 | 85 | * colon, and a required "local part" (an unqualified name). Prefixes are |
ohair@286 | 86 | * declared, and correspond to particular URIs which scope the "local |
ohair@286 | 87 | * part" of the name. (This method cannot check whether the prefix of a |
ohair@286 | 88 | * name has been declared.) |
ohair@286 | 89 | * |
ohair@286 | 90 | * @param value the string being tested |
ohair@286 | 91 | */ |
ohair@286 | 92 | public static boolean isQualifiedName(String value) { |
ohair@286 | 93 | if (value == null) |
ohair@286 | 94 | return false; |
ohair@286 | 95 | |
ohair@286 | 96 | // [6] QName ::= (Prefix ':')? LocalPart |
ohair@286 | 97 | // [7] Prefix ::= NCName |
ohair@286 | 98 | // [8] LocalPart ::= NCName |
ohair@286 | 99 | |
ohair@286 | 100 | int first = value.indexOf(':'); |
ohair@286 | 101 | |
ohair@286 | 102 | // no Prefix, only check LocalPart |
ohair@286 | 103 | if (first <= 0) |
ohair@286 | 104 | return isUnqualifiedName(value); |
ohair@286 | 105 | |
ohair@286 | 106 | // Prefix exists, check everything |
ohair@286 | 107 | |
ohair@286 | 108 | int last = value.lastIndexOf(':'); |
ohair@286 | 109 | if (last != first) |
ohair@286 | 110 | return false; |
ohair@286 | 111 | |
ohair@286 | 112 | return isUnqualifiedName(value.substring(0, first)) |
ohair@286 | 113 | && isUnqualifiedName(value.substring(first + 1)); |
ohair@286 | 114 | } |
ohair@286 | 115 | |
ohair@286 | 116 | /** |
ohair@286 | 117 | * This method returns true if the identifier is a "name token" |
ohair@286 | 118 | * as defined in the XML specification. Like names, these |
ohair@286 | 119 | * may only contain "name characters"; however, they do not need |
ohair@286 | 120 | * to have letters as their initial characters. Attribute values |
ohair@286 | 121 | * defined to be of type NMTOKEN(S) must satisfy this predicate. |
ohair@286 | 122 | * |
ohair@286 | 123 | * @param token the string being tested |
ohair@286 | 124 | */ |
ohair@286 | 125 | public static boolean isNmtoken(String token) { |
ohair@286 | 126 | int length = token.length(); |
ohair@286 | 127 | |
ohair@286 | 128 | for (int i = 0; i < length; i++) |
ohair@286 | 129 | if (!XmlChars.isNameChar(token.charAt(i))) |
ohair@286 | 130 | return false; |
ohair@286 | 131 | return true; |
ohair@286 | 132 | } |
ohair@286 | 133 | |
ohair@286 | 134 | |
ohair@286 | 135 | /** |
ohair@286 | 136 | * This method returns true if the identifier is a "name token" as |
ohair@286 | 137 | * defined by the XML Namespaces proposed recommendation. |
ohair@286 | 138 | * These are like XML "name tokens" but they may not contain the |
ohair@286 | 139 | * "colon" character. |
ohair@286 | 140 | * |
ohair@286 | 141 | * @param token the string being tested |
ohair@286 | 142 | * @see #isNmtoken |
ohair@286 | 143 | */ |
ohair@286 | 144 | public static boolean isNCNmtoken(String token) { |
ohair@286 | 145 | return isNmtoken(token) && token.indexOf(':') < 0; |
ohair@286 | 146 | } |
ohair@286 | 147 | } |