From 993add338d0cafb394a1faf1c9444408ce67232b Mon Sep 17 00:00:00 2001 From: tschaub Date: Thu, 25 Oct 2012 10:52:54 -0600 Subject: [PATCH] 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. --- lib/OpenLayers/Format/Filter/v1.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/OpenLayers/Format/Filter/v1.js b/lib/OpenLayers/Format/Filter/v1.js index bfc563c11a..74c5e7a381 100644 --- a/lib/OpenLayers/Format/Filter/v1.js +++ b/lib/OpenLayers/Format/Filter/v1.js @@ -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 + * 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) {