From 827ae44a5f00b59c7566dd7b749f9955262fb57b Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Thu, 23 Jan 2014 10:43:47 +0100 Subject: [PATCH 1/3] Use ol.format.XSD.readString in ol.format.KML --- src/ol/format/kmlformat.js | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/ol/format/kmlformat.js b/src/ol/format/kmlformat.js index 9fca0f4b50..ff17920099 100644 --- a/src/ol/format/kmlformat.js +++ b/src/ol/format/kmlformat.js @@ -18,6 +18,7 @@ goog.require('goog.string'); goog.require('ol.Feature'); goog.require('ol.feature'); goog.require('ol.format.XML'); +goog.require('ol.format.XSD'); goog.require('ol.geom.GeometryCollection'); goog.require('ol.geom.GeometryType'); goog.require('ol.geom.LineString'); @@ -395,17 +396,6 @@ ol.format.KML.readNumber_ = function(node) { }; -/** - * @param {Node} node Node. - * @private - * @return {string} String. - */ -ol.format.KML.readString_ = function(node) { - var s = ol.xml.getAllTextContent(node, false); - return goog.string.trim(s); -}; - - /** * @param {Node} node Node. * @private @@ -1070,7 +1060,7 @@ ol.format.KML.SimpleDataParser_ = function(node, objectStack) { goog.asserts.assert(node.localName == 'SimpleData'); var name = node.getAttribute('name'); if (!goog.isNull(name)) { - var data = ol.format.KML.readString_(node); + var data = ol.format.XSD.readString(node); var featureObject = /** @type {Object} */ (objectStack[objectStack.length - 1]); goog.object.set(featureObject, name, data); @@ -1177,7 +1167,7 @@ ol.format.KML.whenParser_ = function(node, objectStack) { */ ol.format.KML.DATA_PARSERS_ = ol.xml.makeParsersNS( ol.format.KML.NAMESPACE_URIS_, { - 'value': ol.xml.makeReplacer(ol.format.KML.readString_) + 'value': ol.xml.makeReplacer(ol.format.XSD.readString) }); @@ -1248,7 +1238,7 @@ ol.format.KML.GEOMETRY_FLAT_COORDINATES_PARSERS_ = ol.xml.makeParsersNS( */ ol.format.KML.ICON_PARSERS_ = ol.xml.makeParsersNS( ol.format.KML.NAMESPACE_URIS_, { - 'href': ol.xml.makeObjectPropertySetter(ol.format.KML.readString_) + 'href': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString) }); @@ -1334,7 +1324,7 @@ ol.format.KML.OUTER_BOUNDARY_IS_PARSERS_ = ol.xml.makeParsersNS( ol.format.KML.PAIR_PARSERS_ = ol.xml.makeParsersNS( ol.format.KML.NAMESPACE_URIS_, { 'Style': ol.xml.makeObjectPropertySetter(ol.format.KML.readStyle_), - 'key': ol.xml.makeObjectPropertySetter(ol.format.KML.readString_), + 'key': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString), 'styleUrl': ol.xml.makeObjectPropertySetter(ol.format.KML.readStyleUrl_) }); @@ -1359,11 +1349,11 @@ ol.format.KML.PLACEMARK_PARSERS_ = ol.xml.makeParsersNS( ol.format.KML.readPolygon_, 'geometry'), 'Style': ol.xml.makeObjectPropertySetter(ol.format.KML.readStyle_), 'StyleMap': ol.format.KML.StyleMapParser_, - 'address': ol.xml.makeObjectPropertySetter(ol.format.KML.readString_), - 'description': ol.xml.makeObjectPropertySetter(ol.format.KML.readString_), - 'name': ol.xml.makeObjectPropertySetter(ol.format.KML.readString_), + 'address': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString), + 'description': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString), + 'name': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString), 'open': ol.xml.makeObjectPropertySetter(ol.format.KML.readBoolean_), - 'phoneNumber': ol.xml.makeObjectPropertySetter(ol.format.KML.readString_), + 'phoneNumber': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString), 'styleUrl': ol.xml.makeObjectPropertySetter(ol.format.KML.readURI_), 'visibility': ol.xml.makeObjectPropertySetter(ol.format.KML.readBoolean_) }, ol.xml.makeParsersNS( @@ -1661,7 +1651,7 @@ ol.format.KML.prototype.readNameFromNode = function(node) { if (goog.array.indexOf(ol.format.KML.NAMESPACE_URIS_, n.namespaceURI) != -1 && n.localName == 'name') { - return ol.format.KML.readString_(n); + return ol.format.XSD.readString(n); } } for (n = node.firstElementChild; !goog.isNull(n); n = n.nextElementSibling) { From cb25267341302e279e99c7945fca5f79f3102989 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Thu, 23 Jan 2014 10:54:40 +0100 Subject: [PATCH 2/3] Add ol.format.XSD.readBoolean function --- src/ol/format/xsdformat.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/ol/format/xsdformat.js b/src/ol/format/xsdformat.js index 71a2a9f9dd..a0b2685ff9 100644 --- a/src/ol/format/xsdformat.js +++ b/src/ol/format/xsdformat.js @@ -11,6 +11,21 @@ goog.require('ol.xml'); ol.format.XSD.NAMESPACE_URI = 'http://www.w3.org/2001/XMLSchema'; +/** + * @param {Node} node Node. + * @return {boolean|undefined} Boolean. + */ +ol.format.XSD.readBoolean = function(node) { + var s = ol.xml.getAllTextContent(node, false); + var m = /^\s*(true|1)|(false|0)\s*$/.exec(s); + if (m) { + return goog.isDef(m[1]) || false; + } else { + return undefined; + } +}; + + /** * @param {Node} node Node. * @return {number|undefined} DateTime. From 9fe5eff8657a62a2ccbef5da10c2a0b56273fd30 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Thu, 23 Jan 2014 10:55:02 +0100 Subject: [PATCH 3/3] Use ol.format.XSD.readBoolean in ol.format.KML --- src/ol/format/kmlformat.js | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/ol/format/kmlformat.js b/src/ol/format/kmlformat.js index ff17920099..02c75e0a08 100644 --- a/src/ol/format/kmlformat.js +++ b/src/ol/format/kmlformat.js @@ -312,22 +312,6 @@ ol.format.KML.makeFeatureStyleFunction_ = function(style) { }; -/** - * @param {Node} node Node. - * @private - * @return {boolean|undefined} Boolean. - */ -ol.format.KML.readBoolean_ = function(node) { - var s = ol.xml.getAllTextContent(node, false); - var m = /^\s*(0|1)\s*$/.exec(s); - if (m) { - return m[1] == '1'; - } else { - return undefined; - } -}; - - /** * @param {Node} node Node. * @private @@ -1352,10 +1336,10 @@ ol.format.KML.PLACEMARK_PARSERS_ = ol.xml.makeParsersNS( 'address': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString), 'description': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString), 'name': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString), - 'open': ol.xml.makeObjectPropertySetter(ol.format.KML.readBoolean_), + 'open': ol.xml.makeObjectPropertySetter(ol.format.XSD.readBoolean), 'phoneNumber': ol.xml.makeObjectPropertySetter(ol.format.XSD.readString), 'styleUrl': ol.xml.makeObjectPropertySetter(ol.format.KML.readURI_), - 'visibility': ol.xml.makeObjectPropertySetter(ol.format.KML.readBoolean_) + 'visibility': ol.xml.makeObjectPropertySetter(ol.format.XSD.readBoolean) }, ol.xml.makeParsersNS( ol.format.KML.GX_NAMESPACE_URIS_, { 'MultiTrack': ol.xml.makeObjectPropertySetter( @@ -1374,8 +1358,8 @@ ol.format.KML.PLACEMARK_PARSERS_ = ol.xml.makeParsersNS( ol.format.KML.POLY_STYLE_PARSERS_ = ol.xml.makeParsersNS( ol.format.KML.NAMESPACE_URIS_, { 'color': ol.xml.makeObjectPropertySetter(ol.format.KML.readColor_), - 'fill': ol.xml.makeObjectPropertySetter(ol.format.KML.readBoolean_), - 'outline': ol.xml.makeObjectPropertySetter(ol.format.KML.readBoolean_) + 'fill': ol.xml.makeObjectPropertySetter(ol.format.XSD.readBoolean), + 'outline': ol.xml.makeObjectPropertySetter(ol.format.XSD.readBoolean) });