1 58 59 package com.sun.imageio.metadata; 60 61 69 public class XmlNames 70 { 71 74 public static final String 75 SPEC_XML_URI = "http://www.w3.org/XML/1998/namespace"; 76 public static final String 77 SPEC_XMLNS_URI = "http://www.w3.org/2000/xmlns/"; 78 79 private XmlNames () { } 80 81 82 87 public static boolean isName (String value) 88 { 89 if (value == null || "".equals(value)) 90 return false; 91 92 char c = value.charAt (0); 93 if (!XmlChars.isLetter (c) && c != '_' && c != ':') 94 return false; 95 for (int i = 1; i < value.length (); i++) 96 if (!XmlChars.isNameChar (value.charAt (i))) 97 return false; 98 return true; 99 } 100 101 109 public static boolean isUnqualifiedName (String value) 110 { 111 if (value == null || value.length() == 0) 112 return false; 113 114 char c = value.charAt (0); 115 if (!XmlChars.isLetter (c) && c != '_') 116 return false; 117 for (int i = 1; i < value.length (); i++) 118 if (!XmlChars.isNCNameChar (value.charAt (i))) 119 return false; 120 return true; 121 } 122 123 134 public static boolean isQualifiedName (String value) 135 { 136 if (value == null) 137 return false; 138 139 143 int first = value.indexOf (':'); 144 145 if (first <= 0) 147 return isUnqualifiedName (value); 148 149 151 int last = value.lastIndexOf (':'); 152 if (last != first) 153 return false; 154 155 return isUnqualifiedName (value.substring (0, first)) 156 && isUnqualifiedName (value.substring (first + 1)); 157 } 158 159 168 public static boolean isNmtoken (String token) 169 { 170 int length = token.length (); 171 172 for (int i = 0; i < length; i++) 173 if (!XmlChars.isNameChar (token.charAt (i))) 174 return false; 175 return true; 176 } 177 178 179 189 public static boolean isNCNmtoken (String token) 190 { 191 return isNmtoken (token) && token.indexOf (':') < 0; 192 } 193 194 201 public static String getPrefix(String qualifiedName) { 202 int index = qualifiedName.indexOf(':'); 205 return index <= 0 ? null : qualifiedName.substring(0, index); 206 } 207 208 215 public static String getLocalPart(String qualifiedName) { 216 int index = qualifiedName.indexOf(':'); 219 if (index < 0) { 220 return qualifiedName; 221 } 222 223 if (index == qualifiedName.length() - 1) { 225 return null; 226 } 227 228 return qualifiedName.substring(index + 1); 229 } 230 } 231 | Popular Tags |