Bienvenue sur PostGIS.fr

Bienvenue sur PostGIS.fr , le site de la communauté des utilisateurs francophones de PostGIS.

PostGIS ajoute le support d'objets géographique à la base de données PostgreSQL. En effet, PostGIS "spatialise" le serverur PostgreSQL, ce qui permet de l'utiliser comme une base de données SIG.

Maintenu à jour, en fonction de nos disponibilités et des diverses sorties des outils que nous testons, nous vous proposons l'ensemble de nos travaux publiés en langue française.

source: trunk/workshop-routing-foss4g/web/OpenLayers/lib/OpenLayers/Format/CSWGetRecords/v2_0_2.js @ 76

Revision 76, 15.6 KB checked in by djay, 12 years ago (diff)

Ajout du répertoire web

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