From 14f009e2f75efd52d04ba77a548583a1e76da3ef Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Tue, 20 Nov 2012 15:48:48 +0100 Subject: [PATCH 1/4] parse annotation from WFS DescribeFeatureType schemas --- .../Format/WFSDescribeFeatureType.js | 48 +++++++++++++++++-- tests/Format/WFSDescribeFeatureType.html | 39 +++++++++++++++ 2 files changed, 82 insertions(+), 5 deletions(-) diff --git a/lib/OpenLayers/Format/WFSDescribeFeatureType.js b/lib/OpenLayers/Format/WFSDescribeFeatureType.js index a946da060c..b71291e0f8 100644 --- a/lib/OpenLayers/Format/WFSDescribeFeatureType.js +++ b/lib/OpenLayers/Format/WFSDescribeFeatureType.js @@ -6,6 +6,7 @@ /** * @requires OpenLayers/Format/XML.js * @requires OpenLayers/Format/OGCExceptionReport.js + * @requires OpenLayers/Format/JSON.js */ /** @@ -17,6 +18,22 @@ */ OpenLayers.Format.WFSDescribeFeatureType = OpenLayers.Class( OpenLayers.Format.XML, { + + /** + * Property: jsonFormat + * {OpenLayers.Format.JSON} + * Parser instance used to parse JSON for cross browser support. The native + * JSON.parse method will be used where available (all except IE<8). + */ + jsonFormat: null, + + /** + * Property: regExes + * Compiled regular expressions for manipulating strings. + */ + regExes: { + trimSpace: (/^\s*|\s*$/g) + }, /** * Property: namespaces @@ -52,15 +69,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' + + '' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' {"title":{"en":"Population"}}' + + ' Number of persons living in the state' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ' ' + + ''; + var format = new OpenLayers.Format.WFSDescribeFeatureType(); + var res = format.read(text); + var property = res.featureTypes[0].properties[0]; + t.eq(property.annotation.appinfo.title["en"], "Population", "appinfo read correctly"); + t.eq(property.annotation.documentation["en"], "Number of persons living in the state", "documentation read correctly"); + } + From f410cd7e413d801cc76e3006c09c33becd9a45fa Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Tue, 20 Nov 2012 16:36:12 +0100 Subject: [PATCH 2/4] remove JSON parsing from format, applications should handle this, as suggested by @ahocevar --- lib/OpenLayers/Format/WFSDescribeFeatureType.js | 14 +------------- tests/Format/WFSDescribeFeatureType.html | 2 +- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/lib/OpenLayers/Format/WFSDescribeFeatureType.js b/lib/OpenLayers/Format/WFSDescribeFeatureType.js index b71291e0f8..b0bb1b694a 100644 --- a/lib/OpenLayers/Format/WFSDescribeFeatureType.js +++ b/lib/OpenLayers/Format/WFSDescribeFeatureType.js @@ -6,7 +6,6 @@ /** * @requires OpenLayers/Format/XML.js * @requires OpenLayers/Format/OGCExceptionReport.js - * @requires OpenLayers/Format/JSON.js */ /** @@ -19,14 +18,6 @@ OpenLayers.Format.WFSDescribeFeatureType = OpenLayers.Class( OpenLayers.Format.XML, { - /** - * Property: jsonFormat - * {OpenLayers.Format.JSON} - * Parser instance used to parse JSON for cross browser support. The native - * JSON.parse method will be used where available (all except IE<8). - */ - jsonFormat: null, - /** * Property: regExes * Compiled regular expressions for manipulating strings. @@ -158,10 +149,7 @@ OpenLayers.Format.WFSDescribeFeatureType = OpenLayers.Class( this.readChildNodes(node, obj.annotation); }, "appinfo": function(node, obj) { - if (!this.jsonFormat) { - this.jsonFormat = new OpenLayers.Format.JSON(); - } - obj.appinfo = this.jsonFormat.read(this.getChildValue(node)); + obj.appinfo = this.getChildValue(node); }, "documentation": function(node, obj) { if (!obj.documentation) { diff --git a/tests/Format/WFSDescribeFeatureType.html b/tests/Format/WFSDescribeFeatureType.html index d1ee22e80a..6e9812a766 100644 --- a/tests/Format/WFSDescribeFeatureType.html +++ b/tests/Format/WFSDescribeFeatureType.html @@ -425,7 +425,7 @@ var format = new OpenLayers.Format.WFSDescribeFeatureType(); var res = format.read(text); var property = res.featureTypes[0].properties[0]; - t.eq(property.annotation.appinfo.title["en"], "Population", "appinfo read correctly"); + t.eq(property.annotation.appinfo, '{"title":{"en":"Population"}}', "appinfo read correctly"); t.eq(property.annotation.documentation["en"], "Number of persons living in the state", "documentation read correctly"); } From cbd9a90477be526e741364705927b540abb192d1 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Tue, 20 Nov 2012 16:42:06 +0100 Subject: [PATCH 3/4] appinfo can be specified multiple times, so use an array instead thanks @ahocevar --- lib/OpenLayers/Format/WFSDescribeFeatureType.js | 5 ++++- tests/Format/WFSDescribeFeatureType.html | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/Format/WFSDescribeFeatureType.js b/lib/OpenLayers/Format/WFSDescribeFeatureType.js index b0bb1b694a..dbd524f50e 100644 --- a/lib/OpenLayers/Format/WFSDescribeFeatureType.js +++ b/lib/OpenLayers/Format/WFSDescribeFeatureType.js @@ -149,7 +149,10 @@ OpenLayers.Format.WFSDescribeFeatureType = OpenLayers.Class( this.readChildNodes(node, obj.annotation); }, "appinfo": function(node, obj) { - obj.appinfo = this.getChildValue(node); + if (!obj.appinfo) { + obj.appinfo = []; + } + obj.appinfo.push(this.getChildValue(node)); }, "documentation": function(node, obj) { if (!obj.documentation) { diff --git a/tests/Format/WFSDescribeFeatureType.html b/tests/Format/WFSDescribeFeatureType.html index 6e9812a766..3821c2dc1b 100644 --- a/tests/Format/WFSDescribeFeatureType.html +++ b/tests/Format/WFSDescribeFeatureType.html @@ -425,7 +425,7 @@ var format = new OpenLayers.Format.WFSDescribeFeatureType(); var res = format.read(text); var property = res.featureTypes[0].properties[0]; - t.eq(property.annotation.appinfo, '{"title":{"en":"Population"}}', "appinfo read correctly"); + t.eq(property.annotation.appinfo[0], '{"title":{"en":"Population"}}', "appinfo read correctly"); t.eq(property.annotation.documentation["en"], "Number of persons living in the state", "documentation read correctly"); } From 52d69ecfda9e7a393e2dd909d42876b1c4a148d9 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Tue, 20 Nov 2012 16:48:50 +0100 Subject: [PATCH 4/4] documentation is also an array, and lang is optional thanks @ahocevar for the catch --- lib/OpenLayers/Format/WFSDescribeFeatureType.js | 8 +++++--- tests/Format/WFSDescribeFeatureType.html | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/OpenLayers/Format/WFSDescribeFeatureType.js b/lib/OpenLayers/Format/WFSDescribeFeatureType.js index dbd524f50e..9823aef232 100644 --- a/lib/OpenLayers/Format/WFSDescribeFeatureType.js +++ b/lib/OpenLayers/Format/WFSDescribeFeatureType.js @@ -156,11 +156,13 @@ OpenLayers.Format.WFSDescribeFeatureType = OpenLayers.Class( }, "documentation": function(node, obj) { if (!obj.documentation) { - obj.documentation = {}; + obj.documentation = []; } - var lang = node.getAttribute("xml:lang"); var value = this.getChildValue(node); - obj.documentation[lang] = value.replace(this.regExes.trimSpace, ""); + obj.documentation.push({ + lang: node.getAttribute("xml:lang"), + textContent: value.replace(this.regExes.trimSpace, "") + }); }, "simpleType": function(node, obj) { this.readChildNodes(node, obj); diff --git a/tests/Format/WFSDescribeFeatureType.html b/tests/Format/WFSDescribeFeatureType.html index 3821c2dc1b..77f348d872 100644 --- a/tests/Format/WFSDescribeFeatureType.html +++ b/tests/Format/WFSDescribeFeatureType.html @@ -426,7 +426,7 @@ var res = format.read(text); var property = res.featureTypes[0].properties[0]; t.eq(property.annotation.appinfo[0], '{"title":{"en":"Population"}}', "appinfo read correctly"); - t.eq(property.annotation.documentation["en"], "Number of persons living in the state", "documentation read correctly"); + t.eq(property.annotation.documentation[0], {lang: "en", textContent: 'Number of persons living in the state'}, "documentation read correctly"); }