[OpenLayers-Commits] r12129 - in trunk/openlayers:
lib/OpenLayers/Format/Filter lib/OpenLayers/Format/GML
lib/OpenLayers/Format/WFST lib/OpenLayers/Protocol/WFS
tests/Format/Filter tests/Format/GML tests/Format/WFST
tests/Protocol
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Wed Jun 29 05:53:38 EDT 2011
Author: ahocevar
Date: 2011-06-29 02:53:37 -0700 (Wed, 29 Jun 2011)
New Revision: 12129
Modified:
trunk/openlayers/lib/OpenLayers/Format/Filter/v1_0_0.js
trunk/openlayers/lib/OpenLayers/Format/Filter/v1_1_0.js
trunk/openlayers/lib/OpenLayers/Format/GML/Base.js
trunk/openlayers/lib/OpenLayers/Format/WFST/v1_0_0.js
trunk/openlayers/lib/OpenLayers/Format/WFST/v1_1_0.js
trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1.js
trunk/openlayers/tests/Format/Filter/v1_0_0.html
trunk/openlayers/tests/Format/Filter/v1_1_0.html
trunk/openlayers/tests/Format/GML/v3.html
trunk/openlayers/tests/Format/WFST/v1_0_0.html
trunk/openlayers/tests/Format/WFST/v1_1_0.html
trunk/openlayers/tests/Protocol/WFS.html
Log:
making Protocol.WFS work with just featureType and featurePrefix configured. r=bartvde (closes #3368)
Modified: trunk/openlayers/lib/OpenLayers/Format/Filter/v1_0_0.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/Filter/v1_0_0.js 2011-06-27 18:12:24 UTC (rev 12128)
+++ trunk/openlayers/lib/OpenLayers/Format/Filter/v1_0_0.js 2011-06-29 09:53:37 UTC (rev 12129)
@@ -124,7 +124,17 @@
},
"BBOX": function(filter) {
var node = this.createElementNSPlus("ogc:BBOX");
- this.writeNode("PropertyName", filter, node);
+ // PropertyName is mandatory in 1.0.0, but e.g. GeoServer also
+ // accepts filters without it. When this is used with
+ // OpenLayers.Protocol.WFS, OpenLayers.Format.WFST will set a
+ // missing filter.property to the geometryName that is
+ // configured with the protocol, which defaults to "the_geom".
+ // So the only way to omit this mandatory property is to not
+ // set the property on the filter and to set the geometryName
+ // on the WFS protocol to null. The latter also happens when
+ // the protocol is configured without a geometryName and a
+ // featureNS.
+ filter.property && this.writeNode("PropertyName", filter, node);
var box = this.writeNode("gml:Box", filter.value, node);
if(filter.projection) {
box.setAttribute("srsName", filter.projection);
Modified: trunk/openlayers/lib/OpenLayers/Format/Filter/v1_1_0.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/Filter/v1_1_0.js 2011-06-27 18:12:24 UTC (rev 12128)
+++ trunk/openlayers/lib/OpenLayers/Format/Filter/v1_1_0.js 2011-06-29 09:53:37 UTC (rev 12129)
@@ -139,7 +139,8 @@
},
"BBOX": function(filter) {
var node = this.createElementNSPlus("ogc:BBOX");
- this.writeNode("PropertyName", filter, node);
+ // PropertyName is optional in 1.1.0
+ filter.property && this.writeNode("PropertyName", filter, node);
var box = this.writeNode("gml:Envelope", filter.value);
if(filter.projection) {
box.setAttribute("srsName", filter.projection);
Modified: trunk/openlayers/lib/OpenLayers/Format/GML/Base.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/GML/Base.js 2011-06-27 18:12:24 UTC (rev 12128)
+++ trunk/openlayers/lib/OpenLayers/Format/GML/Base.js 2011-06-29 09:53:37 UTC (rev 12129)
@@ -62,7 +62,8 @@
/**
* APIProperty: geometry
- * {String} Name of geometry element. Defaults to "geometry".
+ * {String} Name of geometry element. Defaults to "geometry". If null, it
+ * will be set on <read> when the first geometry is parsed.
*/
geometryName: "geometry",
@@ -440,6 +441,9 @@
obj.features.push(feature);
},
"_geometry": function(node, obj) {
+ if (!this.geometryName) {
+ this.geometryName = node.nodeName.split(":").pop();
+ }
this.readChildNodes(node, obj);
},
"_attribute": function(node, obj) {
Modified: trunk/openlayers/lib/OpenLayers/Format/WFST/v1_0_0.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/WFST/v1_0_0.js 2011-06-27 18:12:24 UTC (rev 12128)
+++ trunk/openlayers/lib/OpenLayers/Format/WFST/v1_0_0.js 2011-06-29 09:53:37 UTC (rev 12129)
@@ -136,9 +136,10 @@
srsName: this.srsName,
srsNameInQuery: this.srsNameInQuery
}, options);
+ var prefix = options.featurePrefix;
var node = this.createElementNSPlus("wfs:Query", {
attributes: {
- typeName: (options.featureNS ? options.featurePrefix + ":" : "") +
+ typeName: (prefix ? prefix + ":" : "") +
options.featureType
}
});
@@ -146,7 +147,7 @@
node.setAttribute("srsName", options.srsName);
}
if(options.featureNS) {
- node.setAttribute("xmlns:" + options.featurePrefix, options.featureNS);
+ node.setAttribute("xmlns:" + prefix, options.featureNS);
}
if(options.propertyNames) {
for(var i=0,len = options.propertyNames.length; i<len; i++) {
Modified: trunk/openlayers/lib/OpenLayers/Format/WFST/v1_1_0.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/WFST/v1_1_0.js 2011-06-27 18:12:24 UTC (rev 12128)
+++ trunk/openlayers/lib/OpenLayers/Format/WFST/v1_1_0.js 2011-06-29 09:53:37 UTC (rev 12129)
@@ -148,15 +148,16 @@
featureType: this.featureType,
srsName: this.srsName
}, options);
+ var prefix = options.featurePrefix;
var node = this.createElementNSPlus("wfs:Query", {
attributes: {
- typeName: (options.featureNS ? options.featurePrefix + ":" : "") +
+ typeName: (prefix ? prefix + ":" : "") +
options.featureType,
srsName: options.srsName
}
});
if(options.featureNS) {
- node.setAttribute("xmlns:" + options.featurePrefix, options.featureNS);
+ node.setAttribute("xmlns:" + prefix, options.featureNS);
}
if(options.propertyNames) {
for(var i=0,len = options.propertyNames.length; i<len; i++) {
Modified: trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1.js 2011-06-27 18:12:24 UTC (rev 12128)
+++ trunk/openlayers/lib/OpenLayers/Protocol/WFS/v1.js 2011-06-29 09:53:37 UTC (rev 12129)
@@ -97,14 +97,21 @@
* url - {String} URL to send requests to (required).
* featureType - {String} Local (without prefix) feature typeName (required).
* featureNS - {String} Feature namespace (required, but can be autodetected
- * for reading if featurePrefix is provided and identical to the prefix
- * in the server response).
+ * during the first query if GML is used as readFormat and
+ * featurePrefix is provided and matches the prefix used by the server
+ * for this featureType).
* featurePrefix - {String} Feature namespace alias (optional - only used
* for writing if featureNS is provided). Default is 'feature'.
- * geometryName - {String} Name of geometry attribute. Default is 'the_geom'.
+ * geometryName - {String} Name of geometry attribute. If featureNS is not
+ * configured, the default is null to avoid failing on BBOX filters,
+ * and it will be set on <read>. Otherwise, the default is 'the_geom'.
*/
initialize: function(options) {
OpenLayers.Protocol.prototype.initialize.apply(this, [options]);
+ if (!options.geometryName && !options.featureNS) {
+ // poorly configured protocol - try to not fail on BBOX filters
+ this.geometryName = null;
+ }
if(!options.format) {
this.format = OpenLayers.Format.WFST(OpenLayers.Util.extend({
version: this.version,
@@ -281,8 +288,18 @@
if(!doc || doc.length <= 0) {
return null;
}
- return (this.readFormat !== null) ? this.readFormat.read(doc) :
+ var result = (this.readFormat !== null) ? this.readFormat.read(doc) :
this.format.read(doc, options);
+ if (!this.featureNS) {
+ var format = this.readFormat || this.format;
+ this.featureNS = format.featureNS;
+ // no need to auto-configure again on subsequent reads
+ format.autoConfig = false;
+ if (!this.geometryName) {
+ this.setGeometryName(format.geometryName);
+ }
+ }
+ return result;
},
/**
Modified: trunk/openlayers/tests/Format/Filter/v1_0_0.html
===================================================================
--- trunk/openlayers/tests/Format/Filter/v1_0_0.html 2011-06-27 18:12:24 UTC (rev 12128)
+++ trunk/openlayers/tests/Format/Filter/v1_0_0.html 2011-06-29 09:53:37 UTC (rev 12129)
@@ -78,6 +78,31 @@
t.xml_eq(node, out, "bbox correctly written");
}
+ function test_BBOX_noGeometryName(t) {
+ t.plan(1);
+ // WFS 1.0.0 does not allow BBOX filters without property, but
+ // GeoServer accepts them.
+ var filter = new OpenLayers.Filter.Spatial({
+ type: OpenLayers.Filter.Spatial.BBOX,
+ value: new OpenLayers.Bounds(-180, -90, 180, 90),
+ projection: "EPSG:4326"
+ });
+
+ var out =
+ '<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
+ '<ogc:BBOX>' +
+ '<gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">' +
+ '<gml:coordinates decimal="." cs="," ts=" ">-180,-90 180,90</gml:coordinates>' +
+ '</gml:Box>' +
+ '</ogc:BBOX>' +
+ '</ogc:Filter>';
+
+ var parser = new OpenLayers.Format.Filter.v1_0_0();
+ var node = parser.write(filter);
+
+ t.xml_eq(node, out, "bbox correctly written");
+ }
+
function test_DWithin(t) {
t.plan(6);
Modified: trunk/openlayers/tests/Format/Filter/v1_1_0.html
===================================================================
--- trunk/openlayers/tests/Format/Filter/v1_1_0.html 2011-06-27 18:12:24 UTC (rev 12128)
+++ trunk/openlayers/tests/Format/Filter/v1_1_0.html 2011-06-29 09:53:37 UTC (rev 12129)
@@ -167,6 +167,31 @@
t.xml_eq(node, out, "bbox correctly written");
}
+ function test_BBOX_noGeometryName(t) {
+ t.plan(1);
+ var filter = new OpenLayers.Filter.Spatial({
+ type: OpenLayers.Filter.Spatial.BBOX,
+ value: new OpenLayers.Bounds(-180, -90, 180, 90),
+ projection: "EPSG:4326"
+ });
+
+ var out =
+ '<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">' +
+ '<ogc:BBOX>' +
+ '<gml:Envelope xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">' +
+ '<gml:lowerCorner>-180 -90</gml:lowerCorner>' +
+ '<gml:upperCorner>180 90</gml:upperCorner>' +
+ '</gml:Envelope>' +
+ '</ogc:BBOX>' +
+ '</ogc:Filter>';
+
+ var parser = new OpenLayers.Format.Filter.v1_1_0();
+ var node = parser.write(filter);
+
+ t.xml_eq(node, out, "bbox correctly written");
+ }
+
+
function test_Intersects(t) {
t.plan(4);
Modified: trunk/openlayers/tests/Format/GML/v3.html
===================================================================
--- trunk/openlayers/tests/Format/GML/v3.html 2011-06-27 18:12:24 UTC (rev 12128)
+++ trunk/openlayers/tests/Format/GML/v3.html 2011-06-29 09:53:37 UTC (rev 12129)
@@ -50,6 +50,19 @@
}
+ function test_read_setGeometryName(t) {
+ t.plan(1);
+ var doc = readXML("v3/topp-states-gml.xml");
+ var format = new OpenLayers.Format.GML.v3({
+ featureType: "states",
+ featureNS: "http://www.openplans.org/topp",
+ geometryName: null
+ });
+ var features = format.read(doc.documentElement);
+
+ t.eq(format.geometryName, "the_geom", "geometryName set when parsing features");
+ }
+
function test_readNode_bounds(t) {
var files = ["v3/envelope.xml"];
Modified: trunk/openlayers/tests/Format/WFST/v1_0_0.html
===================================================================
--- trunk/openlayers/tests/Format/WFST/v1_0_0.html 2011-06-27 18:12:24 UTC (rev 12128)
+++ trunk/openlayers/tests/Format/WFST/v1_0_0.html 2011-06-29 09:53:37 UTC (rev 12129)
@@ -67,6 +67,17 @@
}
}
+
+ function test_write_poorconfig(t) {
+ t.plan(1);
+ var format = new OpenLayers.Format.WFST.v1_0_0({
+ featureType: "states",
+ featurePrefix: "topp"
+ });
+ var exp = "topp:states";
+ var got = format.writeNode("wfs:Query").getAttribute("typeName");
+ t.eq(got, exp, "Query without featureNS but with featurePrefix queries for the correct featureType");
+ }
var xmlFormat = new OpenLayers.Format.XML();
function readXML(id) {
Modified: trunk/openlayers/tests/Format/WFST/v1_1_0.html
===================================================================
--- trunk/openlayers/tests/Format/WFST/v1_1_0.html 2011-06-27 18:12:24 UTC (rev 12128)
+++ trunk/openlayers/tests/Format/WFST/v1_1_0.html 2011-06-29 09:53:37 UTC (rev 12129)
@@ -95,6 +95,17 @@
}
}
+ function test_write_poorconfig(t) {
+ t.plan(1);
+ var format = new OpenLayers.Format.WFST.v1_1_0({
+ featureType: "states",
+ featurePrefix: "topp"
+ });
+ var exp = "topp:states";
+ var got = format.writeNode("wfs:Query").getAttribute("typeName");
+ t.eq(got, exp, "Query without featureNS but with featurePrefix queries for the correct featureType");
+ }
+
var xmlFormat = new OpenLayers.Format.XML();
function readXML(id) {
var xml = document.getElementById(id).firstChild.nodeValue;
Modified: trunk/openlayers/tests/Protocol/WFS.html
===================================================================
--- trunk/openlayers/tests/Protocol/WFS.html 2011-06-27 18:12:24 UTC (rev 12128)
+++ trunk/openlayers/tests/Protocol/WFS.html 2011-06-29 09:53:37 UTC (rev 12129)
@@ -104,7 +104,21 @@
OpenLayers.Request.POST = _POST;
}
+
+ function test_parseResponse_poorconfig(t) {
+ t.plan(2);
+ var protocol = new OpenLayers.Protocol.WFS({
+ url: "http://some.url.org",
+ featurePrefix: "topp",
+ featureType: "tasmania_roads"
+ });
+
+ protocol.parseResponse({responseText: document.getElementById("query_response").firstChild.nodeValue});
+ t.eq(protocol.geometryName, "geom", "geometryName configured correctly");
+ t.eq(protocol.featureNS, "http://www.openplans.org/topp", "featureNS configured correctly");
+ }
+
function test_exception(t) {
t.plan(8);
var url = "http://some.url.org";
@@ -439,7 +453,6 @@
<wfs:Delete typeName="feature:type" xmlns:feature="http://namespace.org">
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:BBOX>
- <ogc:PropertyName/>
<gml:Box xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
<gml:coordinates decimal="." cs="," ts=" ">-5,-5 5,5</gml:coordinates>
</gml:Box>
@@ -448,5 +461,9 @@
</wfs:Delete>
</wfs:Transaction>
--></div>
+<div id="query_response"><!--
+<?xml version="1.0" encoding="UTF-8"?>
+<wfs:FeatureCollection xmlns:ogc="http://www.opengis.net/ogc" xmlns:wfs="http://www.opengis.net/wfs" xmlns:topp="http://www.openplans.org/topp" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ows="http://www.opengis.net/ows" xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink"><gml:boundedBy><gml:Envelope srsDimension="2" srsName="urn:x-ogc:def:crs:EPSG:4326"><gml:lowerCorner>5450000.0 500000.0</gml:lowerCorner><gml:upperCorner>5450000.0 540000.0</gml:upperCorner></gml:Envelope></gml:boundedBy><gml:featureMembers><topp:tasmania_roads gml:id="tasmania_roads.1"><gml:boundedBy><gml:Envelope srsDimension="2" srsName="urn:x-ogc:def:crs:EPSG:4326"><gml:lowerCorner>5450000.0 500000.0</gml:lowerCorner><gml:upperCorner>5450000.0 540000.0</gml:upperCorner></gml:Envelope></gml:boundedBy><topp:geom><gml:MultiLineString srsDimension="2" srsName="urn:x-ogc:def:crs:EPSG:4326"><gml:lineStringMember><gml:LineString><gml:posList>5450000.0 500000.0 5450
000.0 540000.0</gml:posList></gml:LineString></gml:lineStringMember></gml:MultiLineString></topp:geom><topp:TYPE>street</topp:TYPE></topp:tasmania_roads></gml:featureMembers></wfs:FeatureCollection>
+--></div>
</body>
</html>
More information about the Commits
mailing list