Merge pull request #762 from bartvde/schema

parse annotation from WFS DescribeFeatureType schemas (r=@ahocevar)
This commit is contained in:
Bart van den Eijnden
2012-11-20 08:07:29 -08:00
2 changed files with 75 additions and 5 deletions
@@ -17,6 +17,14 @@
*/
OpenLayers.Format.WFSDescribeFeatureType = OpenLayers.Class(
OpenLayers.Format.XML, {
/**
* Property: regExes
* Compiled regular expressions for manipulating strings.
*/
regExes: {
trimSpace: (/^\s*|\s*$/g)
},
/**
* Property: namespaces
@@ -52,15 +60,16 @@ OpenLayers.Format.WFSDescribeFeatureType = OpenLayers.Class(
complexTypes: complexTypes,
customTypes: customTypes
};
var i, len;
this.readChildNodes(node, schema);
var attributes = node.attributes;
var attr, name;
for(var i=0, len=attributes.length; i<len; ++i) {
for(i=0, len=attributes.length; i<len; ++i) {
attr = attributes[i];
name = attr.name;
if(name.indexOf("xmlns") == 0) {
if(name.indexOf("xmlns") === 0) {
this.setNamespace(name.split(":")[1] || "", attr.value);
} else {
obj[name] = attr.value;
@@ -71,7 +80,7 @@ OpenLayers.Format.WFSDescribeFeatureType = OpenLayers.Class(
// map complexTypes to names of customTypes
var complexType, customType;
for(var i=0, len=complexTypes.length; i<len; ++i) {
for(i=0, len=complexTypes.length; i<len; ++i) {
complexType = complexTypes[i];
customType = customTypes[complexType.typeName];
if(customTypes[complexType.typeName]) {
@@ -103,6 +112,7 @@ OpenLayers.Format.WFSDescribeFeatureType = OpenLayers.Class(
obj.properties = sequence.elements;
},
"element": function(node, obj) {
var type;
if(obj.elements) {
var element = {};
var attributes = node.attributes;
@@ -112,7 +122,7 @@ OpenLayers.Format.WFSDescribeFeatureType = OpenLayers.Class(
element[attr.name] = attr.value;
}
var type = element.type;
type = element.type;
if(!type) {
type = {};
this.readChildNodes(node, type);
@@ -122,10 +132,11 @@ OpenLayers.Format.WFSDescribeFeatureType = OpenLayers.Class(
var fullType = type.base || type;
element.localType = fullType.split(":").pop();
obj.elements.push(element);
this.readChildNodes(node, element);
}
if(obj.complexTypes) {
var type = node.getAttribute("type");
type = node.getAttribute("type");
var localType = type.split(":").pop();
obj.customTypes[localType] = {
"name": node.getAttribute("name"),
@@ -133,6 +144,26 @@ OpenLayers.Format.WFSDescribeFeatureType = OpenLayers.Class(
};
}
},
"annotation": function(node, obj) {
obj.annotation = {};
this.readChildNodes(node, obj.annotation);
},
"appinfo": function(node, obj) {
if (!obj.appinfo) {
obj.appinfo = [];
}
obj.appinfo.push(this.getChildValue(node));
},
"documentation": function(node, obj) {
if (!obj.documentation) {
obj.documentation = [];
}
var value = this.getChildValue(node);
obj.documentation.push({
lang: node.getAttribute("xml:lang"),
textContent: value.replace(this.regExes.trimSpace, "")
});
},
"simpleType": function(node, obj) {
this.readChildNodes(node, obj);
},