Debian Codegraph @

net/sf/saxon/lib/NamespaceConstant.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.lib;
9
10 /**
11 * This class is not instantiated, it exists to hold a set of constants representing known
12 * namespaces. For each of these, there is a constant for the namespace URI and for many of
13 * them, there is a numeric constant used as the code for this namespace in the name pool.
14 * <p>This class also defines constant URIs for some objects other than namespaces -
15 * for example, URIs that identify the various object models used in the JAXP XPath API,
16 * and the Unicode codepoint collation URI.</p>
17 *
18 * @author Michael H. Kay
19 */
20
21 public class NamespaceConstant {
22
23 /**
24 * A URI representing the null namespace (actually, an empty string)
25 */
26
27 public static final String NULL = "";
28
29 /**
30 * Fixed namespace name for XML: "http://www.w3.org/XML/1998/namespace".
31 */
32 public static final String XML = "http://www.w3.org/XML/1998/namespace";
33
34 /**
35 * Fixed namespace name for XSLT: "http://www.w3.org/1999/XSL/Transform"
36 */
37 public static final String XSLT = "http://www.w3.org/1999/XSL/Transform";
38
39 /**
40 * Current namespace name for SAXON (from 7.0 onwards): "http://saxon.sf.net/"
41 */
42 public static final String SAXON = "http://saxon.sf.net/";
43
44 /**
45 * Old namespace name for SAXON6: "http://icl.com/saxon"
46 */
47 public static final String SAXON6 = "http://icl.com/saxon";
48
49 /**
50 * Fixed namespace name for the export of a Saxon stylesheet package
51 */
52 public static final String SAXON_XSLT_EXPORT = "http://ns.saxonica.com/xslt/export";
53
54 /**
55 * Namespace name for XML Schema: "http://www.w3.org/2001/XMLSchema"
56 */
57 public static final String SCHEMA = "http://www.w3.org/2001/XMLSchema";
58
59 /**
60 * XML-schema-defined namespace for use in instance documents ("xsi")
61 */
62 public static final String SCHEMA_INSTANCE = "http://www.w3.org/2001/XMLSchema-instance";
63
64 /**
65 * Namespace defined in XSD 1.1 for schema versioning
66 */
67 public static final String SCHEMA_VERSIONING = "http://www.w3.org/2007/XMLSchema-versioning";
68
69 /**
70 * Fixed namespace name for SAXON SQL extension: "http://saxon.sf.net/sql"
71 */
72 public static final String SQL = "http://saxon.sf.net/sql";
73
74 /**
75 * Fixed namespace name for EXSLT/Common: "http://exslt.org/common"
76 */
77 public static final String EXSLT_COMMON = "http://exslt.org/common";
78
79 /**
80 * Fixed namespace name for EXSLT/math: "http://exslt.org/math"
81 */
82 public static final String EXSLT_MATH = "http://exslt.org/math";
83
84 /**
85 * Fixed namespace name for EXSLT/sets: "http://exslt.org/sets"
86 */
87 public static final String EXSLT_SETS = "http://exslt.org/sets";
88
89 /**
90 * Fixed namespace name for EXSLT/date: "http://exslt.org/dates-and-times"
91 */
92 public static final String EXSLT_DATES_AND_TIMES = "http://exslt.org/dates-and-times";
93
94 /**
95 * Fixed namespace name for EXSLT/random: "http://exslt.org/random"
96 */
97 public static final String EXSLT_RANDOM = "http://exslt.org/random";
98
99 /**
100 * The standard namespace for functions and operators
101 */
102 public static final String FN = "http://www.w3.org/2005/xpath-functions";
103
104 /**
105 * The standard namespace for XQuery output declarations
106 */
107 public static final String OUTPUT = "http://www.w3.org/2010/xslt-xquery-serialization";
108
109
110 /**
111 * The standard namespace for system error codes
112 */
113 public static final String ERR = "http://www.w3.org/2005/xqt-errors";
114
115
116 /**
117 * Predefined XQuery namespace for local functions
118 */
119 public static final String LOCAL = "http://www.w3.org/2005/xquery-local-functions";
120
121 /**
122 * Math namespace for the XPath 3.0 math functions
123 */
124
125 public static final String MATH = "http://www.w3.org/2005/xpath-functions/math";
126
127 /**
128 * Namespace URI for XPath 3.0 functions associated with maps
129 */
130 public final static String MAP_FUNCTIONS = "http://www.w3.org/2005/xpath-functions/map";
131
132 /**
133 * Namespace URI for XPath 3.0 functions associated with maps as defined in the 2013 XSLT specification
134 */
135 public final static String MAP_FUNCTIONS_2011 = "http://www.w3.org/2011/xpath-functions/map";
136
137 /**
138 * Namespace URI for XPath 3.1 functions associated with arrays
139 */
140 public final static String ARRAY_FUNCTIONS = "http://www.w3.org/2005/xpath-functions/array";
141
142 /**
143 * The XHTML namespace http://www.w3.org/1999/xhtml
144 */
145
146 public static final String XHTML = "http://www.w3.org/1999/xhtml";
147
148 /**
149 * The SVG namespace
150 */
151
152 public static final String SVG = "http://www.w3.org/2000/svg";
153
154 /**
155 * The MathML namespace
156 */
157
158 public static final String MATHML = "http://www.w3.org/1998/Math/MathML";
159
160 /**
161 * The XMLNS namespace (used in DOM)
162 */
163
164 public static final String XMLNS = "http://www.w3.org/2000/xmlns/";
165
166 /**
167 * The XLink namespace
168 */
169
170 public static final String XLINK = "http://www.w3.org/1999/xlink";
171
172 /**
173 * The xquery-option namespace for the XQuery 3.0 feature names
174 */
175
176 public static final String XQUERY_OPTIONS = "http://www.w3.org/2011/xquery-options";
177
178 /**
179 * The xquery namespace for the XQuery 3.0 declare option
180 */
181
182 public static final String XQUERY = "http://www.w3.org/2012/xquery";
183
184 /**
185 * Namespace for types representing external Java objects
186 */
187
188 public static final String JAVA_TYPE = "http://saxon.sf.net/java-type";
189
190 /**
191 * Namespace for types representing external .NET objects
192 */
193
194 public static final String DOT_NET_TYPE = "http://saxon.sf.net/clitype";
195
196 /**
197 * Namespace for names allocated to anonymous types. This exists so that
198 * a name fingerprint can be allocated for use as a type annotation.
199 */
200
201 public static final String ANONYMOUS = "http://ns.saxonica.com/anonymous-type";
202
203 /**
204 * Namespace for the Saxon serialization of the schema component model
205 */
206
207 public static final String SCM = "http://ns.saxonica.com/schema-component-model";
208
209 /**
210 * URI identifying the Saxon object model for use in the JAXP 1.3 XPath API
211 */
212
213 public static final String OBJECT_MODEL_SAXON = "http://saxon.sf.net/jaxp/xpath/om";
214
215
216 /**
217 * URI identifying the XOM object model for use in the JAXP 1.3 XPath API
218 */
219
220 public static final String OBJECT_MODEL_XOM = "http://www.xom.nu/jaxp/xpath/xom";
221
222 /**
223 * URI identifying the JDOM object model for use in the JAXP 1.3 XPath API
224 */
225
226 public static final String OBJECT_MODEL_JDOM = "http://jdom.org/jaxp/xpath/jdom";
227
228 /**
229 * URI identifying the AXIOM object model for use in the JAXP 1.3 XPath API
230 */
231
232 // Note: this URI is a Saxon invention
233 public static final String OBJECT_MODEL_AXIOM = "http://ws.apache.org/jaxp/xpath/axiom";
234
235 /**
236 * URI identifying the DOM4J object model for use in the JAXP 1.3 XPath API
237 */
238
239 public static final String OBJECT_MODEL_DOM4J = "http://www.dom4j.org/jaxp/xpath/dom4j";
240
241 /**
242 * URI identifying the .NET DOM object model (not used, but needed for consistency)
243 */
244
245 public static final String OBJECT_MODEL_DOT_NET_DOM = "http://saxon.sf.net/object-model/dotnet/dom";
246
247 /**
248 * URI identifying the DOMINO object model (not used, but needed for consistency)
249 */
250
251 public static final String OBJECT_MODEL_DOMINO = "http://saxon.sf.net/object-model/domino";
252
253 /**
254 * URI identifying the Unicode codepoint collation
255 */
256
257 public static final String CODEPOINT_COLLATION_URI = "http://www.w3.org/2005/xpath-functions/collation/codepoint";
258
259 /**
260 * URI identifying the HTML5 ascii-case-blind collation
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 * URI for the names of generated variables
267 */
268
269 public static final String SAXON_GENERATED_VARIABLE = SAXON + "generated-variable";
270
271 /**
272 * URI for the Saxon configuration file
273 */
274
275 public static final String SAXON_CONFIGURATION = "http://saxon.sf.net/ns/configuration";
276
277 /**
278 * URI for the EXPath zip module
279 */
280
281 public static final String EXPATH_ZIP = "http://expath.org/ns/zip";
282
283 /**
284 * URI for the user extension calls in Saxon.js
285 */
286 public static final String GLOBAL_JS = "http://saxonica.com/ns/globalJS";
287
288 /**
289 * URI for the user extension calls in Saxon/C for C++ and PHP
290 */
291 public static final String PHP = "http://php.net/xsl";
292
293 /**
294 * URI for interactive XSLT extensions in Saxon-CE and Saxon-JS
295 */
296 public static final String IXSL = "http://saxonica.com/ns/interactiveXSLT";
297
298 /**
299 * Private constructor: class is never instantiated
300 */
301
302 private NamespaceConstant() {
303 }
304
305 /**
306 * Get the conventional prefix for a common namespace
307 * @param uri the namespace URI
308 * @return the conventional prefix for this URI if there is one, or null otherwise
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 * Get the URI associated with a commonly-used conventional prefix
344 * @param prefix the namespace prefix
345 * @return the namespace URI associated with this conventional prefix
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 * Determine whether a namespace is a reserved namespace
383 *
384 * @param uri the namespace URI to be tested
385 * @return true if this namespace URI is a reserved namespace
386 */
387
388 public static boolean isReserved(/*@Nullable*/ 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 * Determine whether a namespace is a reserved namespace
395 *
396 * @param uri the namespace URI to be tested
397 * @return true if this namespace URI is reserved in XQuery
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 * Determine whether a namespace is a reserved namespace
409 *
410 * @param uri the namespace URI to be tested
411 * @return true if this namespace URI is reserved in XQuery
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 * Determine whether a namespace is a reserved namespace
426 *
427 * @param uri the namespace URI to be tested
428 * @return true if this namespace URI is reserved in XQuery
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 * Find a similar namespace to one that is a possible mis-spelling
445 *
446 * @param candidate the possibly mis-spelt namespace
447 * @return the correct spelling of the namespace
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