1 19 20 package org.netbeans.modules.xml.wsdl.validator.visitor; 21 22 27 public class ValidationUtils { 28 29 30 34 private ValidationUtils() { 35 super(); 36 } 37 38 42 43 48 public static boolean isCombiningChar(char ch) { 49 50 52 return false; 53 54 } 56 60 public static boolean isDigit(char ch) { 61 return Character.isDigit(ch); 62 } 64 65 69 public static boolean isLetter(char ch) { 70 return Character.isLetter(ch); 71 } 73 80 public static boolean isNCName(String str) { 81 82 if ((str == null) || (str.length() == 0)) return false; 83 84 85 char[] chars = str.toCharArray(); 86 87 char ch = chars[0]; 88 89 if ((!isLetter(ch)) && (ch != '_')) 91 return false; 92 93 for (int i = 1; i < chars.length; i++) { 94 if (!isNCNameChar(chars[i])) return false; 95 } 96 return true; 97 } 99 106 public static boolean isNCNameChar(char ch) { 107 if (isLetter(ch) || isDigit(ch)) return true; 108 if (isExtender(ch) || isCombiningChar(ch)) return true; 109 switch(ch) { 110 case '.': 111 case '-': 112 case '_': 113 return true; 114 default: 115 return false; 116 } 117 } 119 120 126 public static boolean isNMToken(String str) { 127 128 if (str == null) return false; 129 char[] chars = str.toCharArray(); 130 131 for (int i = 0; i < chars.length; i++) { 132 char ch = chars[i]; 133 if (isLetter(ch) || isDigit(ch)) continue; 134 if (isExtender(ch) || isCombiningChar(ch)) continue; 135 switch(ch) { 136 case '.': 137 case '-': 138 case '_': 139 case ':': 140 break; 141 default: 142 return false; 143 } 144 } 145 return true; 146 } 148 154 public static boolean isCDATA(String str) { 155 156 if (str == null) return false; 157 char[] chars = str.toCharArray(); 158 159 for (int i = 0; i < chars.length; i++) { 160 char ch = chars[i]; 161 switch(ch) { 162 case '\r': 163 case '\n': 164 case '\t': 165 return false; 166 default: 167 continue; 168 } 169 } 170 return true; 171 } 173 179 public static boolean isExtender(char ch) { 180 181 if ((ch >= 0x3031) && (ch <= 0x3035)) return true; 182 if ((ch >= 0x30FC) && (ch <= 0x30FE)) return true; 183 184 switch(ch) { 185 case 0x00B7: 186 case 0x02D0: 187 case 0x02D1: 188 case 0x0387: 189 case 0x0640: 190 case 0x0E46: 191 case 0x0EC6: 192 case 0x3005: 193 case 0x309D: 194 case 0x309E: 195 return true; 196 default: 197 break; 198 } 199 return false; 200 } 202 209 public static boolean isQName(String str) { 210 211 if ((str == null) || (str.length() == 0)) return false; 212 213 214 char[] chars = str.toCharArray(); 215 216 char ch = chars[0]; 217 218 if ((!isLetter(ch)) && (ch != '_')) 220 return false; 221 222 for (int i = 1; i < chars.length; i++) { 223 if (chars[i] == ':') continue; 224 if (!isNCNameChar(chars[i])) return false; 225 } 226 return true; 227 } 229 236 241 public static boolean areEqualXMLValues(String s1, String s2) { 242 243 return ((s1 == null && s2 == null) 244 || (s1 == null && isEmpty(s2)) 245 || (isEmpty(s1) && s2 == null) 246 || (s1 != null && s1.equals(s2))); 247 } 248 249 253 public static boolean isEmpty(String s) { 254 return ((null == s) || (s.trim().length() == 0)); 255 } 256 } 257 258 | Popular Tags |