1
|
/* Copyright (c) 2006-2013 by OpenLayers Contributors (see authors.txt for
|
2
|
* full list of contributors). Published under the 2-clause BSD license.
|
3
|
* See license.txt in the OpenLayers distribution or repository for the
|
4
|
* full text of the license. */
|
5
|
|
6
|
/**
|
7
|
* @requires OpenLayers/Format/XML.js
|
8
|
* @requires OpenLayers/Format/CSWGetRecords.js
|
9
|
* @requires OpenLayers/Format/Filter/v1_0_0.js
|
10
|
* @requires OpenLayers/Format/Filter/v1_1_0.js
|
11
|
* @requires OpenLayers/Format/OWSCommon/v1_0_0.js
|
12
|
*/
|
13
|
|
14
|
/**
|
15
|
* Class: OpenLayers.Format.CSWGetRecords.v2_0_2
|
16
|
* A format for creating CSWGetRecords v2.0.2 transactions.
|
17
|
* Create a new instance with the
|
18
|
* <OpenLayers.Format.CSWGetRecords.v2_0_2> constructor.
|
19
|
*
|
20
|
* Inherits from:
|
21
|
* - <OpenLayers.Format.XML>
|
22
|
*/
|
23
|
OpenLayers.Format.CSWGetRecords.v2_0_2 = OpenLayers.Class(OpenLayers.Format.XML, {
|
24
|
|
25
|
/**
|
26
|
* Property: namespaces
|
27
|
* {Object} Mapping of namespace aliases to namespace URIs.
|
28
|
*/
|
29
|
namespaces: {
|
30
|
csw: "http://www.opengis.net/cat/csw/2.0.2",
|
31
|
dc: "http://purl.org/dc/elements/1.1/",
|
32
|
dct: "http://purl.org/dc/terms/",
|
33
|
gmd: "http://www.isotc211.org/2005/gmd",
|
34
|
geonet: "http://www.fao.org/geonetwork",
|
35
|
ogc: "http://www.opengis.net/ogc",
|
36
|
ows: "http://www.opengis.net/ows",
|
37
|
xlink: "http://www.w3.org/1999/xlink",
|
38
|
xsi: "http://www.w3.org/2001/XMLSchema-instance"
|
39
|
},
|
40
|
|
41
|
/**
|
42
|
* Property: defaultPrefix
|
43
|
* {String} The default prefix (used by Format.XML).
|
44
|
*/
|
45
|
defaultPrefix: "csw",
|
46
|
|
47
|
/**
|
48
|
* Property: version
|
49
|
* {String} CSW version number.
|
50
|
*/
|
51
|
version: "2.0.2",
|
52
|
|
53
|
/**
|
54
|
* Property: schemaLocation
|
55
|
* {String} http://www.opengis.net/cat/csw/2.0.2
|
56
|
* http://schemas.opengis.net/csw/2.0.2/CSW-discovery.xsd
|
57
|
*/
|
58
|
schemaLocation: "http://www.opengis.net/cat/csw/2.0.2 http://schemas.opengis.net/csw/2.0.2/CSW-discovery.xsd",
|
59
|
|
60
|
/**
|
61
|
* APIProperty: requestId
|
62
|
* {String} Value of the requestId attribute of the GetRecords element.
|
63
|
*/
|
64
|
requestId: null,
|
65
|
|
66
|
/**
|
67
|
* APIProperty: resultType
|
68
|
* {String} Value of the resultType attribute of the GetRecords element,
|
69
|
* specifies the result type in the GetRecords response, "hits" is
|
70
|
* the default.
|
71
|
*/
|
72
|
resultType: null,
|
73
|
|
74
|
/**
|
75
|
* APIProperty: outputFormat
|
76
|
* {String} Value of the outputFormat attribute of the GetRecords element,
|
77
|
* specifies the format of the GetRecords response,
|
78
|
* "application/xml" is the default.
|
79
|
*/
|
80
|
outputFormat: null,
|
81
|
|
82
|
/**
|
83
|
* APIProperty: outputSchema
|
84
|
* {String} Value of the outputSchema attribute of the GetRecords element,
|
85
|
* specifies the schema of the GetRecords response.
|
86
|
*/
|
87
|
outputSchema: null,
|
88
|
|
89
|
/**
|
90
|
* APIProperty: startPosition
|
91
|
* {String} Value of the startPosition attribute of the GetRecords element,
|
92
|
* specifies the start position (offset+1) for the GetRecords response,
|
93
|
* 1 is the default.
|
94
|
*/
|
95
|
startPosition: null,
|
96
|
|
97
|
/**
|
98
|
* APIProperty: maxRecords
|
99
|
* {String} Value of the maxRecords attribute of the GetRecords element,
|
100
|
* specifies the maximum number of records in the GetRecords response,
|
101
|
* 10 is the default.
|
102
|
*/
|
103
|
maxRecords: null,
|
104
|
|
105
|
/**
|
106
|
* APIProperty: DistributedSearch
|
107
|
* {String} Value of the csw:DistributedSearch element, used when writing
|
108
|
* a csw:GetRecords document.
|
109
|
*/
|
110
|
DistributedSearch: null,
|
111
|
|
112
|
/**
|
113
|
* APIProperty: ResponseHandler
|
114
|
* {Array({String})} Values of the csw:ResponseHandler elements, used when
|
115
|
* writting a csw:GetRecords document.
|
116
|
*/
|
117
|
ResponseHandler: null,
|
118
|
|
119
|
/**
|
120
|
* APIProperty: Query
|
121
|
* {String} Value of the csw:Query element, used when writing a csw:GetRecords
|
122
|
* document.
|
123
|
*/
|
124
|
Query: null,
|
125
|
|
126
|
/**
|
127
|
* Property: regExes
|
128
|
* Compiled regular expressions for manipulating strings.
|
129
|
*/
|
130
|
regExes: {
|
131
|
trimSpace: (/^\s*|\s*$/g),
|
132
|
removeSpace: (/\s*/g),
|
133
|
splitSpace: (/\s+/),
|
134
|
trimComma: (/\s*,\s*/g)
|
135
|
},
|
136
|
|
137
|
/**
|
138
|
* Constructor: OpenLayers.Format.CSWGetRecords.v2_0_2
|
139
|
* A class for parsing and generating CSWGetRecords v2.0.2 transactions.
|
140
|
*
|
141
|
* Parameters:
|
142
|
* options - {Object} Optional object whose properties will be set on the
|
143
|
* instance.
|
144
|
*
|
145
|
* Valid options properties (documented as class properties):
|
146
|
* - requestId
|
147
|
* - resultType
|
148
|
* - outputFormat
|
149
|
* - outputSchema
|
150
|
* - startPosition
|
151
|
* - maxRecords
|
152
|
* - DistributedSearch
|
153
|
* - ResponseHandler
|
154
|
* - Query
|
155
|
*/
|
156
|
initialize: function(options) {
|
157
|
OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
|
158
|
},
|
159
|
|
160
|
/**
|
161
|
* APIMethod: read
|
162
|
* Parse the response from a GetRecords request.
|
163
|
*/
|
164
|
read: function(data) {
|
165
|
if(typeof data == "string") {
|
166
|
data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
|
167
|
}
|
168
|
if(data && data.nodeType == 9) {
|
169
|
data = data.documentElement;
|
170
|
}
|
171
|
var obj = {};
|
172
|
this.readNode(data, obj);
|
173
|
return obj;
|
174
|
},
|
175
|
|
176
|
/**
|
177
|
* Property: readers
|
178
|
* Contains public functions, grouped by namespace prefix, that will
|
179
|
* be applied when a namespaced node is found matching the function
|
180
|
* name. The function will be applied in the scope of this parser
|
181
|
* with two arguments: the node being read and a context object passed
|
182
|
* from the parent.
|
183
|
*/
|
184
|
readers: {
|
185
|
"csw": {
|
186
|
"GetRecordsResponse": function(node, obj) {
|
187
|
obj.records = [];
|
188
|
this.readChildNodes(node, obj);
|
189
|
var version = this.getAttributeNS(node, "", 'version');
|
190
|
if (version != "") {
|
191
|
obj.version = version;
|
192
|
}
|
193
|
},
|
194
|
"RequestId": function(node, obj) {
|
195
|
obj.RequestId = this.getChildValue(node);
|
196
|
},
|
197
|
"SearchStatus": function(node, obj) {
|
198
|
obj.SearchStatus = {};
|
199
|
var timestamp = this.getAttributeNS(node, "", 'timestamp');
|
200
|
if (timestamp != "") {
|
201
|
obj.SearchStatus.timestamp = timestamp;
|
202
|
}
|
203
|
},
|
204
|
"SearchResults": function(node, obj) {
|
205
|
this.readChildNodes(node, obj);
|
206
|
var attrs = node.attributes;
|
207
|
var SearchResults = {};
|
208
|
for(var i=0, len=attrs.length; i<len; ++i) {
|
209
|
if ((attrs[i].name == "numberOfRecordsMatched") ||
|
210
|
(attrs[i].name == "numberOfRecordsReturned") ||
|
211
|
(attrs[i].name == "nextRecord")) {
|
212
|
SearchResults[attrs[i].name] = parseInt(attrs[i].nodeValue);
|
213
|
} else {
|
214
|
SearchResults[attrs[i].name] = attrs[i].nodeValue;
|
215
|
}
|
216
|
}
|
217
|
obj.SearchResults = SearchResults;
|
218
|
},
|
219
|
"SummaryRecord": function(node, obj) {
|
220
|
var record = {type: "SummaryRecord"};
|
221
|
this.readChildNodes(node, record);
|
222
|
obj.records.push(record);
|
223
|
},
|
224
|
"BriefRecord": function(node, obj) {
|
225
|
var record = {type: "BriefRecord"};
|
226
|
this.readChildNodes(node, record);
|
227
|
obj.records.push(record);
|
228
|
},
|
229
|
"DCMIRecord": function(node, obj) {
|
230
|
var record = {type: "DCMIRecord"};
|
231
|
this.readChildNodes(node, record);
|
232
|
obj.records.push(record);
|
233
|
},
|
234
|
"Record": function(node, obj) {
|
235
|
var record = {type: "Record"};
|
236
|
this.readChildNodes(node, record);
|
237
|
obj.records.push(record);
|
238
|
},
|
239
|
"*": function(node, obj) {
|
240
|
var name = node.localName || node.nodeName.split(":").pop();
|
241
|
obj[name] = this.getChildValue(node);
|
242
|
}
|
243
|
},
|
244
|
"geonet": {
|
245
|
"info": function(node, obj) {
|
246
|
var gninfo = {};
|
247
|
this.readChildNodes(node, gninfo);
|
248
|
obj.gninfo = gninfo;
|
249
|
}
|
250
|
},
|
251
|
"dc": {
|
252
|
// audience, contributor, coverage, creator, date, description, format,
|
253
|
// identifier, language, provenance, publisher, relation, rights,
|
254
|
// rightsHolder, source, subject, title, type, URI
|
255
|
"*": function(node, obj) {
|
256
|
var name = node.localName || node.nodeName.split(":").pop();
|
257
|
if (!(OpenLayers.Util.isArray(obj[name]))) {
|
258
|
obj[name] = [];
|
259
|
}
|
260
|
var dc_element = {};
|
261
|
var attrs = node.attributes;
|
262
|
for(var i=0, len=attrs.length; i<len; ++i) {
|
263
|
dc_element[attrs[i].name] = attrs[i].nodeValue;
|
264
|
}
|
265
|
dc_element.value = this.getChildValue(node);
|
266
|
if (dc_element.value != "") {
|
267
|
obj[name].push(dc_element);
|
268
|
}
|
269
|
}
|
270
|
},
|
271
|
"dct": {
|
272
|
// abstract, modified, spatial
|
273
|
"*": function(node, obj) {
|
274
|
var name = node.localName || node.nodeName.split(":").pop();
|
275
|
if (!(OpenLayers.Util.isArray(obj[name]))) {
|
276
|
obj[name] = [];
|
277
|
}
|
278
|
obj[name].push(this.getChildValue(node));
|
279
|
}
|
280
|
},
|
281
|
"ows": OpenLayers.Util.applyDefaults({
|
282
|
"BoundingBox": function(node, obj) {
|
283
|
if (obj.bounds) {
|
284
|
obj.BoundingBox = [{crs: obj.projection, value:
|
285
|
[
|
286
|
obj.bounds.left,
|
287
|
obj.bounds.bottom,
|
288
|
obj.bounds.right,
|
289
|
obj.bounds.top
|
290
|
]
|
291
|
}];
|
292
|
delete obj.projection;
|
293
|
delete obj.bounds;
|
294
|
}
|
295
|
OpenLayers.Format.OWSCommon.v1_0_0.prototype.readers["ows"]["BoundingBox"].apply(
|
296
|
this, arguments);
|
297
|
}
|
298
|
}, OpenLayers.Format.OWSCommon.v1_0_0.prototype.readers["ows"])
|
299
|
},
|
300
|
|
301
|
/**
|
302
|
* Method: write
|
303
|
* Given an configuration js object, write a CSWGetRecords request.
|
304
|
*
|
305
|
* Parameters:
|
306
|
* options - {Object} A object mapping the request.
|
307
|
*
|
308
|
* Returns:
|
309
|
* {String} A serialized CSWGetRecords request.
|
310
|
*/
|
311
|
write: function(options) {
|
312
|
var node = this.writeNode("csw:GetRecords", options);
|
313
|
node.setAttribute("xmlns:gmd", this.namespaces.gmd);
|
314
|
return OpenLayers.Format.XML.prototype.write.apply(this, [node]);
|
315
|
},
|
316
|
|
317
|
/**
|
318
|
* Property: writers
|
319
|
* As a compliment to the readers property, this structure contains public
|
320
|
* writing functions grouped by namespace alias and named like the
|
321
|
* node names they produce.
|
322
|
*/
|
323
|
writers: {
|
324
|
"csw": {
|
325
|
"GetRecords": function(options) {
|
326
|
if (!options) {
|
327
|
options = {};
|
328
|
}
|
329
|
var node = this.createElementNSPlus("csw:GetRecords", {
|
330
|
attributes: {
|
331
|
service: "CSW",
|
332
|
version: this.version,
|
333
|
requestId: options.requestId || this.requestId,
|
334
|
resultType: options.resultType || this.resultType,
|
335
|
outputFormat: options.outputFormat || this.outputFormat,
|
336
|
outputSchema: options.outputSchema || this.outputSchema,
|
337
|
startPosition: options.startPosition || this.startPosition,
|
338
|
maxRecords: options.maxRecords || this.maxRecords
|
339
|
}
|
340
|
});
|
341
|
if (options.DistributedSearch || this.DistributedSearch) {
|
342
|
this.writeNode(
|
343
|
"csw:DistributedSearch",
|
344
|
options.DistributedSearch || this.DistributedSearch,
|
345
|
node
|
346
|
);
|
347
|
}
|
348
|
var ResponseHandler = options.ResponseHandler || this.ResponseHandler;
|
349
|
if (OpenLayers.Util.isArray(ResponseHandler) && ResponseHandler.length > 0) {
|
350
|
// ResponseHandler must be a non-empty array
|
351
|
for(var i=0, len=ResponseHandler.length; i<len; i++) {
|
352
|
this.writeNode(
|
353
|
"csw:ResponseHandler",
|
354
|
ResponseHandler[i],
|
355
|
node
|
356
|
);
|
357
|
}
|
358
|
}
|
359
|
this.writeNode("Query", options.Query || this.Query, node);
|
360
|
return node;
|
361
|
},
|
362
|
"DistributedSearch": function(options) {
|
363
|
var node = this.createElementNSPlus("csw:DistributedSearch", {
|
364
|
attributes: {
|
365
|
hopCount: options.hopCount
|
366
|
}
|
367
|
});
|
368
|
return node;
|
369
|
},
|
370
|
"ResponseHandler": function(options) {
|
371
|
var node = this.createElementNSPlus("csw:ResponseHandler", {
|
372
|
value: options.value
|
373
|
});
|
374
|
return node;
|
375
|
},
|
376
|
"Query": function(options) {
|
377
|
if (!options) {
|
378
|
options = {};
|
379
|
}
|
380
|
var node = this.createElementNSPlus("csw:Query", {
|
381
|
attributes: {
|
382
|
typeNames: options.typeNames || "csw:Record"
|
383
|
}
|
384
|
});
|
385
|
var ElementName = options.ElementName;
|
386
|
if (OpenLayers.Util.isArray(ElementName) && ElementName.length > 0) {
|
387
|
// ElementName must be a non-empty array
|
388
|
for(var i=0, len=ElementName.length; i<len; i++) {
|
389
|
this.writeNode(
|
390
|
"csw:ElementName",
|
391
|
ElementName[i],
|
392
|
node
|
393
|
);
|
394
|
}
|
395
|
} else {
|
396
|
this.writeNode(
|
397
|
"csw:ElementSetName",
|
398
|
options.ElementSetName || {value: 'summary'},
|
399
|
node
|
400
|
);
|
401
|
}
|
402
|
if (options.Constraint) {
|
403
|
this.writeNode(
|
404
|
"csw:Constraint",
|
405
|
options.Constraint,
|
406
|
node
|
407
|
);
|
408
|
}
|
409
|
if (options.SortBy) {
|
410
|
this.writeNode(
|
411
|
"ogc:SortBy",
|
412
|
options.SortBy,
|
413
|
node
|
414
|
);
|
415
|
}
|
416
|
return node;
|
417
|
},
|
418
|
"ElementName": function(options) {
|
419
|
var node = this.createElementNSPlus("csw:ElementName", {
|
420
|
value: options.value
|
421
|
});
|
422
|
return node;
|
423
|
},
|
424
|
"ElementSetName": function(options) {
|
425
|
var node = this.createElementNSPlus("csw:ElementSetName", {
|
426
|
attributes: {
|
427
|
typeNames: options.typeNames
|
428
|
},
|
429
|
value: options.value
|
430
|
});
|
431
|
return node;
|
432
|
},
|
433
|
"Constraint": function(options) {
|
434
|
var node = this.createElementNSPlus("csw:Constraint", {
|
435
|
attributes: {
|
436
|
version: options.version
|
437
|
}
|
438
|
});
|
439
|
if (options.Filter) {
|
440
|
var format = new OpenLayers.Format.Filter({
|
441
|
version: options.version
|
442
|
});
|
443
|
node.appendChild(format.write(options.Filter));
|
444
|
} else if (options.CqlText) {
|
445
|
var child = this.createElementNSPlus("CqlText", {
|
446
|
value: options.CqlText.value
|
447
|
});
|
448
|
node.appendChild(child);
|
449
|
}
|
450
|
return node;
|
451
|
}
|
452
|
},
|
453
|
"ogc": OpenLayers.Format.Filter.v1_1_0.prototype.writers["ogc"]
|
454
|
},
|
455
|
|
456
|
CLASS_NAME: "OpenLayers.Format.CSWGetRecords.v2_0_2"
|
457
|
});
|