Allow user to customize literal encoding

As suggested by @mpriour, it would be nice if the user could determine how
date values are encoded in literal elements.  Extending this beyond date
values, we can provide an `encodeLiteral` method that can be overridden to
provide application specific behavior.
This commit is contained in:
tschaub
2012-10-25 10:52:54 -06:00
parent ed66271be3
commit 993add338d

View File

@@ -247,6 +247,25 @@ OpenLayers.Format.Filter.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
obj.filters.push(filter);
},
/**
* APIMethod: encodeLiteral
* Generates the string representation of a value for use in <Literal>
* elements. The default encoder writes Date values as ISO 8601
* strings.
*
* Parameters:
* value - {Object} Literal value to encode
*
* Returns:
* {String} String representation of the provided value.
*/
encodeLiteral: function(value) {
if (value instanceof Date) {
value = OpenLayers.Date.toISOString(value);
}
return value;
},
/**
* Method: writeOgcExpression
* Limited support for writing OGC expressions. Currently it supports
@@ -406,11 +425,8 @@ OpenLayers.Format.Filter.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
});
},
"Literal": function(value) {
if (value instanceof Date) {
value = OpenLayers.Date.toISOString(value);
}
return this.createElementNSPlus("ogc:Literal", {
value: value
value: this.encodeLiteral(value)
});
},
"LowerBoundary": function(filter) {