Project

General

Profile

Download (12.6 KB) Statistics
| Branch: | Tag: | Revision:
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/OWSCommon.js
8
 */
9

    
10
/**
11
 * Class: OpenLayers.Format.OWSCommon.v1
12
 * Common readers and writers for OWSCommon v1.X formats
13
 *
14
 * Inherits from:
15
 *  - <OpenLayers.Format.XML>
16
 */
17
OpenLayers.Format.OWSCommon.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
18
   
19
    /**
20
     * Property: regExes
21
     * Compiled regular expressions for manipulating strings.
22
     */
23
    regExes: {
24
        trimSpace: (/^\s*|\s*$/g),
25
        removeSpace: (/\s*/g),
26
        splitSpace: (/\s+/),
27
        trimComma: (/\s*,\s*/g)
28
    },
29

    
30
    /**
31
     * Method: read
32
     *
33
     * Parameters:
34
     * data - {DOMElement} An OWSCommon document element.
35
     * options - {Object} Options for the reader.
36
     *
37
     * Returns:
38
     * {Object} An object representing the OWSCommon document.
39
     */
40
    read: function(data, options) {
41
        options = OpenLayers.Util.applyDefaults(options, this.options);
42
        var ows = {};
43
        this.readChildNodes(data, ows);
44
        return ows;
45
    },
46

    
47
    /**
48
     * Property: readers
49
     * Contains public functions, grouped by namespace prefix, that will
50
     *     be applied when a namespaced node is found matching the function
51
     *     name.  The function will be applied in the scope of this parser
52
     *     with two arguments: the node being read and a context object passed
53
     *     from the parent.
54
     */
55
    readers: {
56
        "ows": {
57
            "Exception": function(node, exceptionReport) {
58
                var exception = {
59
                    code: node.getAttribute('exceptionCode'),
60
                    locator: node.getAttribute('locator'),
61
                    texts: []
62
                };
63
                exceptionReport.exceptions.push(exception);
64
                this.readChildNodes(node, exception);
65
            },
66
            "ExceptionText": function(node, exception) {
67
                var text = this.getChildValue(node);
68
                exception.texts.push(text);
69
            },
70
            "ServiceIdentification": function(node, obj) {
71
                obj.serviceIdentification = {};
72
                this.readChildNodes(node, obj.serviceIdentification);
73
            },
74
            "Title": function(node, obj) {
75
                obj.title = this.getChildValue(node);
76
            },
77
            "Abstract": function(node, serviceIdentification) {
78
                serviceIdentification["abstract"] = this.getChildValue(node);
79
            },
80
            "Keywords": function(node, serviceIdentification) {
81
                serviceIdentification.keywords = {};
82
                this.readChildNodes(node, serviceIdentification.keywords);
83
            },
84
            "Keyword": function(node, keywords) {
85
                keywords[this.getChildValue(node)] = true;
86
            },
87
            "ServiceType": function(node, serviceIdentification) {
88
                serviceIdentification.serviceType = {
89
                    codeSpace: node.getAttribute('codeSpace'), 
90
                    value: this.getChildValue(node)};
91
            },
92
            "ServiceTypeVersion": function(node, serviceIdentification) {
93
                serviceIdentification.serviceTypeVersion = this.getChildValue(node);
94
            },
95
            "Fees": function(node, serviceIdentification) {
96
                serviceIdentification.fees = this.getChildValue(node);
97
            },
98
            "AccessConstraints": function(node, serviceIdentification) {
99
                serviceIdentification.accessConstraints = 
100
                    this.getChildValue(node);
101
            },
102
            "ServiceProvider": function(node, obj) {
103
                obj.serviceProvider = {};
104
                this.readChildNodes(node, obj.serviceProvider);
105
            },
106
            "ProviderName": function(node, serviceProvider) {
107
                serviceProvider.providerName = this.getChildValue(node);
108
            },
109
            "ProviderSite": function(node, serviceProvider) {
110
                serviceProvider.providerSite = this.getAttributeNS(node, 
111
                    this.namespaces.xlink, "href");
112
            },
113
            "ServiceContact": function(node, serviceProvider) {
114
                serviceProvider.serviceContact = {};
115
                this.readChildNodes(node, serviceProvider.serviceContact);
116
            },
117
            "IndividualName": function(node, serviceContact) {
118
                serviceContact.individualName = this.getChildValue(node);
119
            },
120
            "PositionName": function(node, serviceContact) {
121
                serviceContact.positionName = this.getChildValue(node);
122
            },
123
            "ContactInfo": function(node, serviceContact) {
124
                serviceContact.contactInfo = {};
125
                this.readChildNodes(node, serviceContact.contactInfo);
126
            },
127
            "Phone": function(node, contactInfo) {
128
                contactInfo.phone = {};
129
                this.readChildNodes(node, contactInfo.phone);
130
            },
131
            "Voice": function(node, phone) {
132
                phone.voice = this.getChildValue(node);
133
            },
134
            "Address": function(node, contactInfo) {
135
                contactInfo.address = {};
136
                this.readChildNodes(node, contactInfo.address);
137
            },
138
            "DeliveryPoint": function(node, address) {
139
                address.deliveryPoint = this.getChildValue(node);
140
            },
141
            "City": function(node, address) {
142
                address.city = this.getChildValue(node);
143
            },
144
            "AdministrativeArea": function(node, address) {
145
                address.administrativeArea = this.getChildValue(node);
146
            },
147
            "PostalCode": function(node, address) {
148
                address.postalCode = this.getChildValue(node);
149
            },
150
            "Country": function(node, address) {
151
                address.country = this.getChildValue(node);
152
            },
153
            "ElectronicMailAddress": function(node, address) {
154
                address.electronicMailAddress = this.getChildValue(node);
155
            },
156
            "Role": function(node, serviceContact) {
157
                serviceContact.role = this.getChildValue(node);
158
            },
159
            "OperationsMetadata": function(node, obj) {
160
                obj.operationsMetadata = {};
161
                this.readChildNodes(node, obj.operationsMetadata);
162
            },
163
            "Operation": function(node, operationsMetadata) {
164
                var name = node.getAttribute("name");
165
                operationsMetadata[name] = {};
166
                this.readChildNodes(node, operationsMetadata[name]);
167
            },
168
            "DCP": function(node, operation) {
169
                operation.dcp = {};
170
                this.readChildNodes(node, operation.dcp);
171
            },
172
            "HTTP": function(node, dcp) {
173
                dcp.http = {};
174
                this.readChildNodes(node, dcp.http);
175
            },
176
            "Get": function(node, http) {
177
                if (!http.get) {
178
                    http.get = [];
179
                }
180
                var obj = {
181
                    url: this.getAttributeNS(node, this.namespaces.xlink, "href")
182
                };
183
                this.readChildNodes(node, obj);
184
                http.get.push(obj);
185
            },
186
            "Post": function(node, http) {
187
                if (!http.post) {
188
                    http.post = [];
189
                }
190
                var obj = {
191
                    url: this.getAttributeNS(node, this.namespaces.xlink, "href")
192
                };
193
                this.readChildNodes(node, obj);
194
                http.post.push(obj);
195
            },
196
            "Parameter": function(node, operation) {
197
                if (!operation.parameters) {
198
                    operation.parameters = {};
199
                }
200
                var name = node.getAttribute("name");
201
                operation.parameters[name] = {};
202
                this.readChildNodes(node, operation.parameters[name]);
203
            },
204
            "Constraint": function(node, obj) {
205
                if (!obj.constraints) {
206
                    obj.constraints = {};
207
                }
208
                var name = node.getAttribute("name");
209
                obj.constraints[name] = {};
210
                this.readChildNodes(node, obj.constraints[name]);
211
            },
212
            "Value": function(node, allowedValues) {
213
                allowedValues[this.getChildValue(node)] = true;
214
            },
215
            "OutputFormat": function(node, obj) {
216
                obj.formats.push({value: this.getChildValue(node)});
217
                this.readChildNodes(node, obj);
218
            },
219
            "WGS84BoundingBox": function(node, obj) {
220
                var boundingBox = {};
221
                boundingBox.crs = node.getAttribute("crs");
222
                if (obj.BoundingBox) {
223
                    obj.BoundingBox.push(boundingBox);
224
                } else {
225
                    obj.projection = boundingBox.crs;
226
                    boundingBox = obj;
227
               }
228
               this.readChildNodes(node, boundingBox);
229
            },
230
            "BoundingBox": function(node, obj) {
231
                // FIXME: We consider that BoundingBox is the same as WGS84BoundingBox
232
                // LowerCorner = "min_x min_y"
233
                // UpperCorner = "max_x max_y"
234
                // It should normally depend on the projection
235
                this.readers['ows']['WGS84BoundingBox'].apply(this, [node, obj]);
236
            },
237
            "LowerCorner": function(node, obj) {
238
                var str = this.getChildValue(node).replace(
239
                    this.regExes.trimSpace, "");
240
                str = str.replace(this.regExes.trimComma, ",");
241
                var pointList = str.split(this.regExes.splitSpace);
242
                obj.left = pointList[0];
243
                obj.bottom = pointList[1];
244
            },
245
            "UpperCorner": function(node, obj) {
246
                var str = this.getChildValue(node).replace(
247
                    this.regExes.trimSpace, "");
248
                str = str.replace(this.regExes.trimComma, ",");
249
                var pointList = str.split(this.regExes.splitSpace);
250
                obj.right = pointList[0];
251
                obj.top = pointList[1];
252
                obj.bounds = new OpenLayers.Bounds(obj.left, obj.bottom,
253
                    obj.right, obj.top);
254
                delete obj.left;
255
                delete obj.bottom;
256
                delete obj.right;
257
                delete obj.top;
258
            },
259
            "Language": function(node, obj) {
260
                obj.language = this.getChildValue(node);
261
            }
262
        }
263
    },
264

    
265
    /**
266
     * Property: writers
267
     * As a compliment to the readers property, this structure contains public
268
     *     writing functions grouped by namespace alias and named like the
269
     *     node names they produce.
270
     */
271
    writers: {
272
        "ows": {
273
            "BoundingBox": function(options, nodeName) {
274
                var node = this.createElementNSPlus(nodeName || "ows:BoundingBox", {
275
                    attributes: {
276
                        crs: options.projection
277
                    }
278
                });
279
                this.writeNode("ows:LowerCorner", options, node);
280
                this.writeNode("ows:UpperCorner", options, node);
281
                return node;
282
            },
283
            "LowerCorner": function(options) {
284
                var node = this.createElementNSPlus("ows:LowerCorner", {
285
                    value: options.bounds.left + " " + options.bounds.bottom });
286
                return node;
287
            },
288
            "UpperCorner": function(options) {
289
                var node = this.createElementNSPlus("ows:UpperCorner", {
290
                    value: options.bounds.right + " " + options.bounds.top });
291
                return node;
292
            },
293
            "Identifier": function(identifier) {
294
                var node = this.createElementNSPlus("ows:Identifier", {
295
                    value: identifier });
296
                return node;
297
            },
298
            "Title": function(title) {
299
                var node = this.createElementNSPlus("ows:Title", {
300
                    value: title });
301
                return node;
302
            },
303
            "Abstract": function(abstractValue) {
304
                var node = this.createElementNSPlus("ows:Abstract", {
305
                    value: abstractValue });
306
                return node;
307
            },
308
            "OutputFormat": function(format) {
309
                var node = this.createElementNSPlus("ows:OutputFormat", {
310
                    value: format });
311
                return node;
312
            }
313
        }
314
    },
315

    
316
    CLASS_NAME: "OpenLayers.Format.OWSCommon.v1"
317

    
318
});
(1-1/3)