-
Notifications
You must be signed in to change notification settings - Fork 12
/
StaticContext.js
139 lines (118 loc) · 4.21 KB
/
StaticContext.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
var cException = require('./../classes/Exception');
var cFunction = global.Function;
function cStaticContext(vNamespaceResolver, sBaseUri) {
this.namespaceResolver = vNamespaceResolver || null;
this.baseURI = sBaseUri || null;
//
this.dataTypes = {};
this.documents = {};
this.functions = {};
this.collations = {};
this.collections= {};
};
cStaticContext.prototype.baseURI = null;
//
cStaticContext.prototype.dataTypes = null;
cStaticContext.prototype.documents = null;
//
cStaticContext.prototype.functions = null;
cStaticContext.prototype.defaultFunctionNamespace = null;
//
cStaticContext.prototype.collations = null;
cStaticContext.prototype.defaultCollationName = "http://www.w3.org/2005/xpath-functions/collation/codepoint";
//
cStaticContext.prototype.collections = null;
cStaticContext.prototype.defaultCollection = null;
//
cStaticContext.prototype.namespaceResolver = null;
cStaticContext.prototype.defaultElementNamespace = null;
cStaticContext.NS_XSD = "http://www.w3.org/2001/XMLSchema";
cStaticContext.NS_XPF = "http://www.w3.org/2005/xpath-functions";
cStaticContext.NS_XNS = "http://www.w3.org/2000/xmlns/";
cStaticContext.NS_XML = "http://www.w3.org/XML/1998/namespace";
//
var rStaticContext_uri = /^(?:\{([^}]+)\})?(.+)$/;
//
cStaticContext.prototype.setDataType = function(sUri, fFunction) {
var aMatch = sUri.match(rStaticContext_uri);
if (aMatch)
if (aMatch[1] != cStaticContext.NS_XSD)
this.dataTypes[sUri] = fFunction;
};
cStaticContext.prototype.getDataType = function(sUri) {
var aMatch = sUri.match(rStaticContext_uri);
if (aMatch)
return aMatch[1] == cStaticContext.NS_XSD ? cStaticContext.dataTypes[aMatch[2]] : this.dataTypes[sUri];
};
cStaticContext.prototype.setDocument = function(sUri, fFunction) {
this.documents[sUri] = fFunction;
};
cStaticContext.prototype.getDocument = function(sUri) {
return this.documents[sUri];
};
cStaticContext.prototype.setFunction = function(sUri, fFunction) {
var aMatch = sUri.match(rStaticContext_uri);
if (aMatch)
if (aMatch[1] != cStaticContext.NS_XPF)
this.functions[sUri] = fFunction;
};
cStaticContext.prototype.getFunction = function(sUri) {
var aMatch = sUri.match(rStaticContext_uri);
if (aMatch)
return aMatch[1] == cStaticContext.NS_XPF ? cStaticContext.functions[aMatch[2]] : this.functions[sUri];
};
cStaticContext.prototype.setCollation = function(sUri, fFunction) {
this.collations[sUri] = fFunction;
};
cStaticContext.prototype.getCollation = function(sUri) {
return this.collations[sUri];
};
cStaticContext.prototype.setCollection = function(sUri, fFunction) {
this.collections[sUri] = fFunction;
};
cStaticContext.prototype.getCollection = function(sUri) {
return this.collections[sUri];
};
cStaticContext.prototype.getURIForPrefix = function(sPrefix) {
var oResolver = this.namespaceResolver,
fResolver = oResolver && oResolver.lookupNamespaceURI ? oResolver.lookupNamespaceURI : oResolver,
sNameSpaceURI;
if (fResolver instanceof cFunction && (sNameSpaceURI = fResolver.call(oResolver, sPrefix)))
return sNameSpaceURI;
if (sPrefix == 'fn')
return cStaticContext.NS_XPF;
if (sPrefix == 'xs')
return cStaticContext.NS_XSD;
if (sPrefix == "xml")
return cStaticContext.NS_XML;
if (sPrefix == "xmlns")
return cStaticContext.NS_XNS;
//
throw new cException("XPST0081"
//->Debug
, "Prefix '" + sPrefix + "' has not been declared"
//<-Debug
);
};
// Static members
// System functions with signatures, operators and types
cStaticContext.functions = {};
cStaticContext.signatures = {};
cStaticContext.dataTypes = {};
cStaticContext.operators = {};
cStaticContext.defineSystemFunction = function(sName, aParameters, fFunction) {
// Register function
cStaticContext.functions[sName] = fFunction;
// Register signature
cStaticContext.signatures[sName] = aParameters;
};
cStaticContext.defineSystemDataType = function(sName, fFunction) {
// Register dataType
cStaticContext.dataTypes[sName] = fFunction;
};
cStaticContext.defineSystemOperator = function(sName, fFunction) {
// Register operator function
cStaticContext.operators[sName] = fFunction;
};
//
module.exports = cStaticContext;