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/WFSDescribeFeatureType.js @ 76

Revision 76, 6.9 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 *
9 * Class: OpenLayers.Format.WFSDescribeFeatureType
10 * Read WFS DescribeFeatureType response
11 *
12 * Inherits from:
13 *  - <OpenLayers.Format.XML>
14 */
15OpenLayers.Format.WFSDescribeFeatureType = OpenLayers.Class(
16    OpenLayers.Format.XML, {
17   
18    /**
19     * Property: namespaces
20     * {Object} Mapping of namespace aliases to namespace URIs.
21     */
22    namespaces: {
23        xsd: "http://www.w3.org/2001/XMLSchema"
24    },
25   
26    /**
27     * Constructor: OpenLayers.Format.WFSDescribeFeatureType
28     * Create a new parser for WFS DescribeFeatureType responses.
29     *
30     * Parameters:
31     * options - {Object} An optional object whose properties will be set on
32     *     this instance.
33     */
34    initialize: function(options) {
35        OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
36    },
37   
38    /**
39     * Property: readers
40     * Contains public functions, grouped by namespace prefix, that will
41     *     be applied when a namespaced node is found matching the function
42     *     name.  The function will be applied in the scope of this parser
43     *     with two arguments: the node being read and a context object passed
44     *     from the parent.
45     */
46    readers: {
47        "xsd": {
48            "schema": function(node, obj) {
49                var complexTypes = [];
50                var customTypes = {};
51                var schema = {
52                    complexTypes: complexTypes,
53                    customTypes: customTypes
54                };
55               
56                this.readChildNodes(node, schema);
57
58                var attributes = node.attributes;
59                var attr, name;
60                for(var i=0, len=attributes.length; i<len; ++i) {
61                    attr = attributes[i];
62                    name = attr.name;
63                    if(name.indexOf("xmlns") == 0) {
64                        this.setNamespace(name.split(":")[1] || "", attr.value);
65                    } else {
66                        obj[name] = attr.value;
67                    }
68                }
69                obj.featureTypes = complexTypes;               
70                obj.targetPrefix = this.namespaceAlias[obj.targetNamespace];
71               
72                // map complexTypes to names of customTypes
73                var complexType, customType;
74                for(var i=0, len=complexTypes.length; i<len; ++i) {
75                    complexType = complexTypes[i];
76                    customType = customTypes[complexType.typeName];
77                    if(customTypes[complexType.typeName]) {
78                        complexType.typeName = customType.name;
79                    }
80                }
81            },
82            "complexType": function(node, obj) {
83                var complexType = {
84                    // this is a temporary typeName, it will be overwritten by
85                    // the schema reader with the metadata found in the
86                    // customTypes hash
87                    "typeName": node.getAttribute("name")
88                };
89                this.readChildNodes(node, complexType);
90                obj.complexTypes.push(complexType);
91            },
92            "complexContent": function(node, obj) {
93                this.readChildNodes(node, obj);
94            },
95            "extension": function(node, obj) {
96                this.readChildNodes(node, obj);
97            },
98            "sequence": function(node, obj) {
99                var sequence = {
100                    elements: []
101                };
102                this.readChildNodes(node, sequence);
103                obj.properties = sequence.elements;
104            },
105            "element": function(node, obj) {
106                if(obj.elements) {
107                    var element = {};
108                    var attributes = node.attributes;
109                    var attr;
110                    for(var i=0, len=attributes.length; i<len; ++i) {
111                        attr = attributes[i];
112                        element[attr.name] = attr.value;
113                    }
114                   
115                    var type = element.type;
116                    if(!type) {
117                        type = {};
118                        this.readChildNodes(node, type);
119                        element.restriction = type;
120                        element.type = type.base;
121                    }
122                    var fullType = type.base || type;
123                    element.localType = fullType.split(":").pop();
124                    obj.elements.push(element);
125                }
126               
127                if(obj.complexTypes) {
128                    var type = node.getAttribute("type");
129                    var localType = type.split(":").pop();
130                    obj.customTypes[localType] = {
131                        "name": node.getAttribute("name"),
132                        "type": type
133                    };
134                }
135            },
136            "simpleType": function(node, obj) {
137                this.readChildNodes(node, obj);
138            },
139            "restriction": function(node, obj) {
140                obj.base = node.getAttribute("base");
141                this.readRestriction(node, obj);
142            }
143        }
144    },
145   
146    /**
147     * Method: readRestriction
148     * Reads restriction defined in the child nodes of a restriction element
149     *
150     * Parameters:
151     * node {DOMElement} - the node to parse
152     * obj {Object} - the object that receives the read result
153     */
154    readRestriction: function(node, obj) {
155        var children = node.childNodes;
156        var child, nodeName, value;
157        for(var i=0, len=children.length; i<len; ++i) {
158            child = children[i];
159            if(child.nodeType == 1) {
160                nodeName = child.nodeName.split(":").pop();
161                value = child.getAttribute("value");
162                if(!obj[nodeName]) {
163                    obj[nodeName] = value;
164                } else {
165                    if(typeof obj[nodeName] == "string") {
166                        obj[nodeName] = [obj[nodeName]];
167                    }
168                    obj[nodeName].push(value);
169                }
170            }
171        }
172    },
173   
174    /**
175     * Method: read
176     *
177     * Parameters:
178     * data - {DOMElement|String} A WFS DescribeFeatureType document.
179     *
180     * Returns:
181     * {Object} An object representing the WFS DescribeFeatureType response.
182     */
183    read: function(data) {
184        if(typeof data == "string") { 
185            data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
186        }
187        if(data && data.nodeType == 9) {
188            data = data.documentElement;
189        }
190        var schema = {};
191        this.readNode(data, schema);
192       
193        return schema;
194    },
195   
196    CLASS_NAME: "OpenLayers.Format.WFSDescribeFeatureType" 
197
198});
Note: See TracBrowser for help on using the repository browser.