| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.lib; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
public class NamespaceConstant { |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
public static final String NULL = ""; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public static final String XML = "http://www.w3.org/XML/1998/namespace"; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public static final String XSLT = "http://www.w3.org/1999/XSL/Transform"; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
public static final String SAXON = "http://saxon.sf.net/"; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public static final String SAXON6 = "http://icl.com/saxon"; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public static final String SAXON_XSLT_EXPORT = "http://ns.saxonica.com/xslt/export"; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
public static final String SCHEMA = "http://www.w3.org/2001/XMLSchema"; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
public static final String SCHEMA_INSTANCE = "http://www.w3.org/2001/XMLSchema-instance"; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public static final String SCHEMA_VERSIONING = "http://www.w3.org/2007/XMLSchema-versioning"; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
public static final String SQL = "http://saxon.sf.net/sql"; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
public static final String EXSLT_COMMON = "http://exslt.org/common"; |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
public static final String EXSLT_MATH = "http://exslt.org/math"; |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public static final String EXSLT_SETS = "http://exslt.org/sets"; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
public static final String EXSLT_DATES_AND_TIMES = "http://exslt.org/dates-and-times"; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
public static final String EXSLT_RANDOM = "http://exslt.org/random"; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
public static final String FN = "http://www.w3.org/2005/xpath-functions"; |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
public static final String OUTPUT = "http://www.w3.org/2010/xslt-xquery-serialization"; |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
public static final String ERR = "http://www.w3.org/2005/xqt-errors"; |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
public static final String LOCAL = "http://www.w3.org/2005/xquery-local-functions"; |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
public static final String MATH = "http://www.w3.org/2005/xpath-functions/math"; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
public final static String MAP_FUNCTIONS = "http://www.w3.org/2005/xpath-functions/map"; |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
public final static String MAP_FUNCTIONS_2011 = "http://www.w3.org/2011/xpath-functions/map"; |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
public final static String ARRAY_FUNCTIONS = "http://www.w3.org/2005/xpath-functions/array"; |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
public static final String XHTML = "http://www.w3.org/1999/xhtml"; |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
public static final String SVG = "http://www.w3.org/2000/svg"; |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
public static final String MATHML = "http://www.w3.org/1998/Math/MathML"; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
public static final String XMLNS = "http://www.w3.org/2000/xmlns/"; |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
public static final String XLINK = "http://www.w3.org/1999/xlink"; |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
public static final String XQUERY_OPTIONS = "http://www.w3.org/2011/xquery-options"; |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
public static final String XQUERY = "http://www.w3.org/2012/xquery"; |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
public static final String JAVA_TYPE = "http://saxon.sf.net/java-type"; |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
public static final String DOT_NET_TYPE = "http://saxon.sf.net/clitype"; |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
public static final String ANONYMOUS = "http://ns.saxonica.com/anonymous-type"; |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
public static final String SCM = "http://ns.saxonica.com/schema-component-model"; |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
public static final String OBJECT_MODEL_SAXON = "http://saxon.sf.net/jaxp/xpath/om"; |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
public static final String OBJECT_MODEL_XOM = "http://www.xom.nu/jaxp/xpath/xom"; |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
public static final String OBJECT_MODEL_JDOM = "http://jdom.org/jaxp/xpath/jdom"; |
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
public static final String OBJECT_MODEL_AXIOM = "http://ws.apache.org/jaxp/xpath/axiom"; |
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
public static final String OBJECT_MODEL_DOM4J = "http://www.dom4j.org/jaxp/xpath/dom4j"; |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
public static final String OBJECT_MODEL_DOT_NET_DOM = "http://saxon.sf.net/object-model/dotnet/dom"; |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
public static final String OBJECT_MODEL_DOMINO = "http://saxon.sf.net/object-model/domino"; |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
public static final String CODEPOINT_COLLATION_URI = "http://www.w3.org/2005/xpath-functions/collation/codepoint"; |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
public static final String HTML5_CASE_BLIND_COLLATION_URI = "http://www.w3.org/2005/xpath-functions/collation/html-ascii-case-insensitive"; |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
public static final String SAXON_GENERATED_VARIABLE = SAXON + "generated-variable"; |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
public static final String SAXON_CONFIGURATION = "http://saxon.sf.net/ns/configuration"; |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
public static final String EXPATH_ZIP = "http://expath.org/ns/zip"; |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
public static final String GLOBAL_JS = "http://saxonica.com/ns/globalJS"; |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
public static final String PHP = "http://php.net/xsl"; |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
public static final String IXSL = "http://saxonica.com/ns/interactiveXSLT"; |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
private NamespaceConstant() { |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
public static String getConventionalPrefix(String uri) { |
| 312 |
switch (uri) { |
| 313 |
case XSLT: |
| 314 |
return "xsl"; |
| 315 |
case FN: |
| 316 |
return "fn"; |
| 317 |
case MATH: |
| 318 |
return "math"; |
| 319 |
case MAP_FUNCTIONS: |
| 320 |
return "map"; |
| 321 |
case ARRAY_FUNCTIONS: |
| 322 |
return "array"; |
| 323 |
case XML: |
| 324 |
return "xml"; |
| 325 |
case SCHEMA: |
| 326 |
return "xs"; |
| 327 |
case SCHEMA_INSTANCE: |
| 328 |
return "xsi"; |
| 329 |
case IXSL: |
| 330 |
return "ixsl"; |
| 331 |
case GLOBAL_JS: |
| 332 |
return "js"; |
| 333 |
case SAXON: |
| 334 |
return "saxon"; |
| 335 |
case SAXON_GENERATED_VARIABLE: |
| 336 |
return "vv"; |
| 337 |
default: |
| 338 |
return null; |
| 339 |
} |
| 340 |
} |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
public static String getUriForConventionalPrefix(String prefix) { |
| 349 |
switch (prefix) { |
| 350 |
case "xsl": |
| 351 |
return XSLT; |
| 352 |
case "fn": |
| 353 |
return FN; |
| 354 |
case "xml": |
| 355 |
return XML; |
| 356 |
case "xs": |
| 357 |
return SCHEMA; |
| 358 |
case "xsi": |
| 359 |
return SCHEMA_INSTANCE; |
| 360 |
case "err": |
| 361 |
return ERR; |
| 362 |
case "ixsl": |
| 363 |
return IXSL; |
| 364 |
case "js": |
| 365 |
return GLOBAL_JS; |
| 366 |
case "saxon": |
| 367 |
return SAXON; |
| 368 |
case "vv": |
| 369 |
return SAXON_GENERATED_VARIABLE; |
| 370 |
case "math": |
| 371 |
return MATH; |
| 372 |
case "map": |
| 373 |
return MAP_FUNCTIONS; |
| 374 |
case "array": |
| 375 |
return ARRAY_FUNCTIONS; |
| 376 |
default: |
| 377 |
return null; |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
public static boolean isReserved( String uri) { |
| 389 |
return uri != null && |
| 390 |
(uri.equals(XSLT) || uri.equals(FN) || uri.equals(XML) || uri.equals(SCHEMA) || uri.equals(SCHEMA_INSTANCE)); |
| 391 |
} |
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
public static boolean isReservedInQuery(String uri) { |
| 401 |
return uri.equals(FN) || |
| 402 |
uri.equals(XML) || |
| 403 |
uri.equals(SCHEMA) || |
| 404 |
uri.equals(SCHEMA_INSTANCE); |
| 405 |
} |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
public static boolean isReservedInQuery30(String uri) { |
| 415 |
return uri.equals(FN) || |
| 416 |
uri.equals(XML) || |
| 417 |
uri.equals(SCHEMA) || |
| 418 |
uri.equals(SCHEMA_INSTANCE) || |
| 419 |
uri.equals(MATH) || |
| 420 |
uri.equals(XQUERY) || |
| 421 |
uri.equals(XQUERY_OPTIONS); |
| 422 |
} |
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
public static boolean isReservedInQuery31(String uri) { |
| 432 |
return uri.equals(FN) || |
| 433 |
uri.equals(XML) || |
| 434 |
uri.equals(SCHEMA) || |
| 435 |
uri.equals(SCHEMA_INSTANCE) || |
| 436 |
uri.equals(MATH) || |
| 437 |
uri.equals(XQUERY) || |
| 438 |
uri.equals(XQUERY_OPTIONS) || |
| 439 |
uri.equals(MAP_FUNCTIONS) || |
| 440 |
uri.equals(ARRAY_FUNCTIONS); |
| 441 |
} |
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
public static String findSimilarNamespace(String candidate) { |
| 451 |
if (isSimilar(candidate, XML)) { |
| 452 |
return XML; |
| 453 |
} else if (isSimilar(candidate, SCHEMA)) { |
| 454 |
return SCHEMA; |
| 455 |
} else if (isSimilar(candidate, XSLT)) { |
| 456 |
return XSLT; |
| 457 |
} else if (isSimilar(candidate, SCHEMA_INSTANCE)) { |
| 458 |
return SCHEMA_INSTANCE; |
| 459 |
} else if (isSimilar(candidate, FN)) { |
| 460 |
return FN; |
| 461 |
} else if (isSimilar(candidate, SAXON)) { |
| 462 |
return SAXON; |
| 463 |
} else if (isSimilar(candidate, EXSLT_COMMON)) { |
| 464 |
return EXSLT_COMMON; |
| 465 |
} else if (isSimilar(candidate, EXSLT_MATH)) { |
| 466 |
return EXSLT_MATH; |
| 467 |
} else if (isSimilar(candidate, EXSLT_DATES_AND_TIMES)) { |
| 468 |
return EXSLT_DATES_AND_TIMES; |
| 469 |
} else if (isSimilar(candidate, EXSLT_RANDOM)) { |
| 470 |
return EXSLT_RANDOM; |
| 471 |
} else if (isSimilar(candidate, XHTML)) { |
| 472 |
return XHTML; |
| 473 |
} else if (isSimilar(candidate, ERR)) { |
| 474 |
return ERR; |
| 475 |
} else if (isSimilar(candidate, JAVA_TYPE)) { |
| 476 |
return JAVA_TYPE; |
| 477 |
} else if (isSimilar(candidate, DOT_NET_TYPE)) { |
| 478 |
return DOT_NET_TYPE; |
| 479 |
} else { |
| 480 |
return null; |
| 481 |
} |
| 482 |
} |
| 483 |
|
| 484 |
private static boolean isSimilar(String s1, String s2) { |
| 485 |
if (s1.equalsIgnoreCase(s2)) { |
| 486 |
return true; |
| 487 |
} else if (s1.startsWith(s2) && s1.length() - s2.length() < 3) { |
| 488 |
return true; |
| 489 |
} else if (s2.startsWith(s1) && s2.length() - s1.length() < 3) { |
| 490 |
return true; |
| 491 |
} else if (s1.length() > 8 && Math.abs(s2.length() - s1.length()) < 3) { |
| 492 |
int diff = 0; |
| 493 |
for (int i = 0; i < s1.length(); i++) { |
| 494 |
char c1 = s1.charAt(i); |
| 495 |
if (!((i < s2.length() && c1 == s2.charAt(i)) |
| 496 |
|| (i > 0 && i < s2.length() - 1 && c1 == s2.charAt(i - 1)) |
| 497 |
|| (i + 1 < s2.length() && c1 == s2.charAt(i + 1)))) { |
| 498 |
diff++; |
| 499 |
} |
| 500 |
} |
| 501 |
return diff < 3; |
| 502 |
} else { |
| 503 |
return false; |
| 504 |
} |
| 505 |
} |
| 506 |
} |
| 507 |
|