add matchCase attribute for PropertyIsLike, r=tschaub (closes #3247)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@11878 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
bartvde
2011-04-05 19:23:23 +00:00
parent fd145c82b1
commit 29133b05ab
3 changed files with 42 additions and 5 deletions

View File

@@ -55,7 +55,7 @@ OpenLayers.Filter.Comparison = OpenLayers.Class(OpenLayers.Filter, {
* elements. This property will be serialized with those elements only
* if using the v1.1.0 filter format. However, when evaluating filters
* here, the matchCase property will always be respected (for EQUAL_TO
* and NOT_EQUAL_TO). Default is true.
* and NOT_EQUAL_TO). Default is true.
*/
matchCase: true,
@@ -90,6 +90,12 @@ OpenLayers.Filter.Comparison = OpenLayers.Class(OpenLayers.Filter, {
*/
initialize: function(options) {
OpenLayers.Filter.prototype.initialize.apply(this, [options]);
// since matchCase on PropertyIsLike is not schema compliant, we only
// want to use this if explicitly asked for
if (this.type === OpenLayers.Filter.Comparison.LIKE
&& options.matchCase === undefined) {
this.matchCase = null;
}
},
/**

View File

@@ -15,9 +15,9 @@
* Differences from the v1.0.0 parser:
* - uses GML v3 instead of GML v2
* - reads matchCase attribute on ogc:PropertyIsEqual and
* ogc:PropertyIsNotEqualelements.
* - writes matchCase attribute from comparison filters of type EQUAL_TO and
* type NOT_EQUAL_TO.
* ogc:PropertyIsNotEqual elements.
* - writes matchCase attribute from comparison filters of type EQUAL_TO,
* NOT_EQUAL_TO and LIKE.
*
* Inherits from:
* - <OpenLayers.Format.Filter.v1>
@@ -127,6 +127,7 @@ OpenLayers.Format.Filter.v1_1_0 = OpenLayers.Class(
"PropertyIsLike": function(filter) {
var node = this.createElementNSPlus("ogc:PropertyIsLike", {
attributes: {
matchCase: filter.matchCase,
wildCard: "*", singleChar: ".", escapeChar: "!"
}
});
@@ -185,4 +186,4 @@ OpenLayers.Format.Filter.v1_1_0 = OpenLayers.Class(
CLASS_NAME: "OpenLayers.Format.Filter.v1_1_0"
});
});

View File

@@ -314,9 +314,39 @@
t.xml_eq(node, out, "spatial dwithin filter with nested functions correctly written");
}
function test_write_like_matchcase(t) {
t.plan(1);
var filter = new OpenLayers.Filter.Comparison({
type: OpenLayers.Filter.Comparison.LIKE,
property: "person",
value: "*me*",
matchCase: false
});
var format = new OpenLayers.Format.Filter.v1_1_0();
var got = format.write(filter);
var exp = readXML("LikeMatchCase");
t.xml_eq(got, exp, "wrote matchCase attribute on PropertyIsLike");
}
function readXML(id) {
var xml = document.getElementById(id).firstChild.nodeValue;
return new OpenLayers.Format.XML().read(xml).documentElement;
}
</script>
</head>
<body>
<div id="LikeMatchCase"><!--
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:PropertyIsLike wildCard="*" singleChar="." escapeChar="!" matchCase="false">
<ogc:PropertyName>person</ogc:PropertyName>
<ogc:Literal>*me*</ogc:Literal>
</ogc:PropertyIsLike>
</ogc:Filter>
--></div>
</body>
</html>