making Protocol.WFS work with just featureType and featurePrefix configured. r=bartvde (closes #3368)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@12129 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2011-06-29 09:53:37 +00:00
parent 058008864e
commit eb7cc04254
12 changed files with 148 additions and 12 deletions

View File

@@ -124,7 +124,17 @@ OpenLayers.Format.Filter.v1_0_0 = OpenLayers.Class(
},
"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);

View File

@@ -139,7 +139,8 @@ OpenLayers.Format.Filter.v1_1_0 = OpenLayers.Class(
},
"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);

View File

@@ -62,7 +62,8 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
/**
* 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 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, {
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) {

View File

@@ -136,9 +136,10 @@ OpenLayers.Format.WFST.v1_0_0 = OpenLayers.Class(
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 @@ OpenLayers.Format.WFST.v1_0_0 = OpenLayers.Class(
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++) {

View File

@@ -148,15 +148,16 @@ OpenLayers.Format.WFST.v1_1_0 = OpenLayers.Class(
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++) {

View File

@@ -97,14 +97,21 @@ OpenLayers.Protocol.WFS.v1 = OpenLayers.Class(OpenLayers.Protocol, {
* 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 @@ OpenLayers.Protocol.WFS.v1 = OpenLayers.Class(OpenLayers.Protocol, {
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;
},
/**