From b87a912ecce7e8042b7344c241f0d449e46a4dc4 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 2 Mar 2016 12:20:57 +0100 Subject: [PATCH 1/9] Remove ol.xml.getLocalName workaround for IE This property is available for IE >= 9 --- src/ol/format/gml/gmlbaseformat.js | 4 +-- src/ol/format/kmlformat.js | 8 +++--- src/ol/format/wmsgetfeatureinfoformat.js | 2 +- src/ol/xml.js | 35 ------------------------ 4 files changed, 7 insertions(+), 42 deletions(-) diff --git a/src/ol/format/gml/gmlbaseformat.js b/src/ol/format/gml/gmlbaseformat.js index 3afda6975d..64d0fe914d 100644 --- a/src/ol/format/gml/gmlbaseformat.js +++ b/src/ol/format/gml/gmlbaseformat.js @@ -111,7 +111,7 @@ ol.format.GMLBase.ONLY_WHITESPACE_RE_ = /^[\s\xa0]*$/; ol.format.GMLBase.prototype.readFeaturesInternal = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT, 'node.nodeType should be ELEMENT'); - var localName = ol.xml.getLocalName(node); + var localName = node.localName; var features; if (localName == 'FeatureCollection') { if (node.namespaceURI === 'http://www.opengis.net/wfs') { @@ -219,7 +219,7 @@ ol.format.GMLBase.prototype.readFeatureElement = function(node, objectStack) { ol.xml.getAttributeNS(node, ol.format.GMLBase.GMLNS, 'id'); var values = {}, geometryName; for (n = node.firstElementChild; n; n = n.nextElementSibling) { - var localName = ol.xml.getLocalName(n); + var localName = n.localName; // Assume attribute elements have one child node and that the child // is a text or CDATA node (to be treated as text). // Otherwise assume it is a geometry node. diff --git a/src/ol/format/kmlformat.js b/src/ol/format/kmlformat.js index 66dc5301b4..936ae8b294 100644 --- a/src/ol/format/kmlformat.js +++ b/src/ol/format/kmlformat.js @@ -1745,7 +1745,7 @@ ol.format.KML.prototype.getExtensions = function() { ol.format.KML.prototype.readDocumentOrFolder_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT, 'node.nodeType should be ELEMENT'); - var localName = ol.xml.getLocalName(node); + var localName = node.localName; goog.asserts.assert(localName == 'Document' || localName == 'Folder', 'localName should be Document or Folder'); // FIXME use scope somehow @@ -1923,7 +1923,7 @@ ol.format.KML.prototype.readFeaturesFromNode = function(node, opt_options) { return []; } var features; - var localName = ol.xml.getLocalName(node); + var localName = node.localName; if (localName == 'Document' || localName == 'Folder') { features = this.readDocumentOrFolder_( node, [this.getReadOptions(node, opt_options)]); @@ -2009,7 +2009,7 @@ ol.format.KML.prototype.readNameFromNode = function(node) { } } for (n = node.firstElementChild; n; n = n.nextElementSibling) { - var localName = ol.xml.getLocalName(n); + var localName = n.localName; if (ol.array.includes(ol.format.KML.NAMESPACE_URIS_, n.namespaceURI) && (localName == 'Document' || localName == 'Folder' || @@ -2080,7 +2080,7 @@ ol.format.KML.prototype.readNetworkLinksFromNode = function(node) { } } for (n = node.firstElementChild; n; n = n.nextElementSibling) { - var localName = ol.xml.getLocalName(n); + var localName = n.localName; if (ol.array.includes(ol.format.KML.NAMESPACE_URIS_, n.namespaceURI) && (localName == 'Document' || localName == 'Folder' || diff --git a/src/ol/format/wmsgetfeatureinfoformat.js b/src/ol/format/wmsgetfeatureinfoformat.js index 6b669742a6..f8437b91bd 100644 --- a/src/ol/format/wmsgetfeatureinfoformat.js +++ b/src/ol/format/wmsgetfeatureinfoformat.js @@ -75,7 +75,7 @@ ol.format.WMSGetFeatureInfo.prototype.readFeatures_ = function(node, objectStack node.setAttribute('namespaceURI', this.featureNS_); goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT, 'node.nodeType should be ELEMENT'); - var localName = ol.xml.getLocalName(node); + var localName = node.localName; /** @type {Array.} */ var features = []; if (node.childNodes.length === 0) { diff --git a/src/ol/xml.js b/src/ol/xml.js index 2d86b031b5..80c5ec1a99 100644 --- a/src/ol/xml.js +++ b/src/ol/xml.js @@ -114,41 +114,6 @@ ol.xml.getAllTextContent_ = function(node, normalizeWhitespace, accumulator) { }; -/** - * @param {Node} node Node. - * @private - * @return {string} Local name. - */ -ol.xml.getLocalName_ = function(node) { - return node.localName; -}; - - -/** - * @param {Node} node Node. - * @private - * @return {string} Local name. - */ -ol.xml.getLocalNameIE_ = function(node) { - var localName = node.localName; - if (localName !== undefined) { - return localName; - } - var baseName = node.baseName; - goog.asserts.assert(baseName, - 'Failed to get localName/baseName of node %s', node); - return baseName; -}; - - -/** - * @param {Node} node Node. - * @return {string} Local name. - */ -ol.xml.getLocalName = goog.userAgent.IE ? - ol.xml.getLocalNameIE_ : ol.xml.getLocalName_; - - /** * @param {?} value Value. * @private From 1e98f1227bbebb559c179afa13f1c8aacd737bd2 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 2 Mar 2016 13:16:24 +0100 Subject: [PATCH 2/9] Remove ol.xml.createElementNS workaround for IE --- src/ol/xml.js | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/src/ol/xml.js b/src/ol/xml.js index 80c5ec1a99..5f1f3991e4 100644 --- a/src/ol/xml.js +++ b/src/ol/xml.js @@ -42,37 +42,12 @@ ol.xml.DOCUMENT = goog.dom.xml.createDocument(); * @param {string} namespaceURI Namespace URI. * @param {string} qualifiedName Qualified name. * @return {Node} Node. - * @private */ -ol.xml.createElementNS_ = function(namespaceURI, qualifiedName) { +ol.xml.createElementNS = function(namespaceURI, qualifiedName) { return ol.xml.DOCUMENT.createElementNS(namespaceURI, qualifiedName); }; -/** - * @param {string} namespaceURI Namespace URI. - * @param {string} qualifiedName Qualified name. - * @return {Node} Node. - * @private - */ -ol.xml.createElementNSActiveX_ = function(namespaceURI, qualifiedName) { - if (!namespaceURI) { - namespaceURI = ''; - } - return ol.xml.DOCUMENT.createNode(1, qualifiedName, namespaceURI); -}; - - -/** - * @param {string} namespaceURI Namespace URI. - * @param {string} qualifiedName Qualified name. - * @return {Node} Node. - */ -ol.xml.createElementNS = - (document.implementation && document.implementation.createDocument) ? - ol.xml.createElementNS_ : ol.xml.createElementNSActiveX_; - - /** * Recursively grab all text content of child nodes into a single string. * @param {Node} node Node. From e210328dba054830169af3bb5026a835cf5344de Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 2 Mar 2016 13:17:30 +0100 Subject: [PATCH 3/9] Remove ol.xml.getAttributeNS workaround for IE --- src/ol/xml.js | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/src/ol/xml.js b/src/ol/xml.js index 5f1f3991e4..6807cfe5ab 100644 --- a/src/ol/xml.js +++ b/src/ol/xml.js @@ -149,41 +149,12 @@ ol.xml.isNode = goog.userAgent.IE ? ol.xml.isNodeIE_ : ol.xml.isNode_; * @param {?string} namespaceURI Namespace URI. * @param {string} name Attribute name. * @return {string} Value - * @private */ -ol.xml.getAttributeNS_ = function(node, namespaceURI, name) { +ol.xml.getAttributeNS = function(node, namespaceURI, name) { return node.getAttributeNS(namespaceURI, name) || ''; }; -/** - * @param {Node} node Node. - * @param {?string} namespaceURI Namespace URI. - * @param {string} name Attribute name. - * @return {string} Value - * @private - */ -ol.xml.getAttributeNSActiveX_ = function(node, namespaceURI, name) { - var attributeValue = ''; - var attributeNode = ol.xml.getAttributeNodeNS(node, namespaceURI, name); - if (attributeNode !== undefined) { - attributeValue = attributeNode.nodeValue; - } - return attributeValue; -}; - - -/** - * @param {Node} node Node. - * @param {?string} namespaceURI Namespace URI. - * @param {string} name Attribute name. - * @return {string} Value - */ -ol.xml.getAttributeNS = - (document.implementation && document.implementation.createDocument) ? - ol.xml.getAttributeNS_ : ol.xml.getAttributeNSActiveX_; - - /** * @param {Node} node Node. * @param {?string} namespaceURI Namespace URI. From 811eea0d3adcd1bfe960f8c1f663a452db8bfaa6 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 2 Mar 2016 13:18:26 +0100 Subject: [PATCH 4/9] Remove ol.xml.getAttributeNodeNS workaround for IE --- src/ol/xml.js | 40 +--------------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/src/ol/xml.js b/src/ol/xml.js index 6807cfe5ab..265da09316 100644 --- a/src/ol/xml.js +++ b/src/ol/xml.js @@ -160,50 +160,12 @@ ol.xml.getAttributeNS = function(node, namespaceURI, name) { * @param {?string} namespaceURI Namespace URI. * @param {string} name Attribute name. * @return {?Node} Attribute node or null if none found. - * @private */ -ol.xml.getAttributeNodeNS_ = function(node, namespaceURI, name) { +ol.xml.getAttributeNodeNS = function(node, namespaceURI, name) { return node.getAttributeNodeNS(namespaceURI, name); }; -/** - * @param {Node} node Node. - * @param {?string} namespaceURI Namespace URI. - * @param {string} name Attribute name. - * @return {?Node} Attribute node or null if none found. - * @private - */ -ol.xml.getAttributeNodeNSActiveX_ = function(node, namespaceURI, name) { - var attributeNode = null; - var attributes = node.attributes; - var potentialNode, fullName; - for (var i = 0, len = attributes.length; i < len; ++i) { - potentialNode = attributes[i]; - if (potentialNode.namespaceURI == namespaceURI) { - fullName = (potentialNode.prefix) ? - (potentialNode.prefix + ':' + name) : name; - if (fullName == potentialNode.nodeName) { - attributeNode = potentialNode; - break; - } - } - } - return attributeNode; -}; - - -/** - * @param {Node} node Node. - * @param {?string} namespaceURI Namespace URI. - * @param {string} name Attribute name. - * @return {?Node} Attribute node or null if none found. - */ -ol.xml.getAttributeNodeNS = - (document.implementation && document.implementation.createDocument) ? - ol.xml.getAttributeNodeNS_ : ol.xml.getAttributeNodeNSActiveX_; - - /** * @param {Node} node Node. * @param {?string} namespaceURI Namespace URI. From 544de3b91c7a5de3066090a2ddd51cb117349960 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 2 Mar 2016 13:19:18 +0100 Subject: [PATCH 5/9] Remove ol.xml.setAttributeNS workaround for IE --- src/ol/xml.js | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/src/ol/xml.js b/src/ol/xml.js index 265da09316..7549ff7bad 100644 --- a/src/ol/xml.js +++ b/src/ol/xml.js @@ -171,42 +171,12 @@ ol.xml.getAttributeNodeNS = function(node, namespaceURI, name) { * @param {?string} namespaceURI Namespace URI. * @param {string} name Attribute name. * @param {string|number} value Value. - * @private */ -ol.xml.setAttributeNS_ = function(node, namespaceURI, name, value) { +ol.xml.setAttributeNS = function(node, namespaceURI, name, value) { node.setAttributeNS(namespaceURI, name, value); }; -/** - * @param {Node} node Node. - * @param {?string} namespaceURI Namespace URI. - * @param {string} name Attribute name. - * @param {string|number} value Value. - * @private - */ -ol.xml.setAttributeNSActiveX_ = function(node, namespaceURI, name, value) { - if (namespaceURI) { - var attribute = node.ownerDocument.createNode(2, name, namespaceURI); - attribute.nodeValue = value; - node.setAttributeNode(attribute); - } else { - node.setAttribute(name, value); - } -}; - - -/** - * @param {Node} node Node. - * @param {?string} namespaceURI Namespace URI. - * @param {string} name Attribute name. - * @param {string|number} value Value. - */ -ol.xml.setAttributeNS = - (document.implementation && document.implementation.createDocument) ? - ol.xml.setAttributeNS_ : ol.xml.setAttributeNSActiveX_; - - /** * Parse an XML string to an XML Document. * @param {string} xml XML. From 90b4eea1cddeaa21df5f97bb929b9905b8abfee2 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 2 Mar 2016 13:23:50 +0100 Subject: [PATCH 6/9] Remove ol.xml.isDocument workaround for IE --- src/ol/xml.js | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/src/ol/xml.js b/src/ol/xml.js index 7549ff7bad..160bac74f5 100644 --- a/src/ol/xml.js +++ b/src/ol/xml.js @@ -91,32 +91,13 @@ ol.xml.getAllTextContent_ = function(node, normalizeWhitespace, accumulator) { /** * @param {?} value Value. - * @private * @return {boolean} Is document. */ -ol.xml.isDocument_ = function(value) { +ol.xml.isDocument = function(value) { return value instanceof Document; }; -/** - * @param {?} value Value. - * @private - * @return {boolean} Is document. - */ -ol.xml.isDocumentIE_ = function(value) { - return goog.isObject(value) && value.nodeType == goog.dom.NodeType.DOCUMENT; -}; - - -/** - * @param {?} value Value. - * @return {boolean} Is document. - */ -ol.xml.isDocument = goog.userAgent.IE ? - ol.xml.isDocumentIE_ : ol.xml.isDocument_; - - /** * @param {?} value Value. * @private From 57f7811cd04a62295f59a8f0884a3b9dcb3f2ed5 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 2 Mar 2016 13:24:20 +0100 Subject: [PATCH 7/9] Remove ol.xml.isNode workaround for IE --- src/ol/xml.js | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/src/ol/xml.js b/src/ol/xml.js index 160bac74f5..da78d717ad 100644 --- a/src/ol/xml.js +++ b/src/ol/xml.js @@ -3,7 +3,6 @@ goog.provide('ol.xml'); goog.require('goog.asserts'); goog.require('goog.dom.NodeType'); goog.require('goog.dom.xml'); -goog.require('goog.userAgent'); goog.require('ol.array'); @@ -100,31 +99,13 @@ ol.xml.isDocument = function(value) { /** * @param {?} value Value. - * @private * @return {boolean} Is node. */ -ol.xml.isNode_ = function(value) { +ol.xml.isNode = function(value) { return value instanceof Node; }; -/** - * @param {?} value Value. - * @private - * @return {boolean} Is node. - */ -ol.xml.isNodeIE_ = function(value) { - return goog.isObject(value) && value.nodeType !== undefined; -}; - - -/** - * @param {?} value Value. - * @return {boolean} Is node. - */ -ol.xml.isNode = goog.userAgent.IE ? ol.xml.isNodeIE_ : ol.xml.isNode_; - - /** * @param {Node} node Node. * @param {?string} namespaceURI Namespace URI. From b09f7e30b22dacdc7017f4ece9c3a2387191ba59 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 2 Mar 2016 13:55:30 +0100 Subject: [PATCH 8/9] Get rid of goog.dom.xml.serialize Use XMLSerializer.serializeToString() function instead, available for IE >= 9 --- src/ol/format/xmlfeatureformat.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ol/format/xmlfeatureformat.js b/src/ol/format/xmlfeatureformat.js index cbee017f33..dbb742afde 100644 --- a/src/ol/format/xmlfeatureformat.js +++ b/src/ol/format/xmlfeatureformat.js @@ -2,7 +2,6 @@ goog.provide('ol.format.XMLFeature'); goog.require('goog.asserts'); goog.require('goog.dom.NodeType'); -goog.require('goog.dom.xml'); goog.require('ol.array'); goog.require('ol.format.Feature'); goog.require('ol.format.FormatType'); @@ -20,6 +19,13 @@ goog.require('ol.xml'); * @extends {ol.format.Feature} */ ol.format.XMLFeature = function() { + + /** + * @type {XMLSerializer} + * @private + */ + this.xmlSerializer_ = new XMLSerializer(); + goog.base(this); }; goog.inherits(ol.format.XMLFeature, ol.format.Feature); @@ -206,7 +212,7 @@ ol.format.XMLFeature.prototype.writeFeature = function(feature, opt_options) { var node = this.writeFeatureNode(feature, opt_options); goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT, 'node.nodeType should be ELEMENT'); - return goog.dom.xml.serialize(/** @type {Element} */(node)); + return this.xmlSerializer_.serializeToString(node); }; @@ -226,7 +232,7 @@ ol.format.XMLFeature.prototype.writeFeatures = function(features, opt_options) { var node = this.writeFeaturesNode(features, opt_options); goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT, 'node.nodeType should be ELEMENT'); - return goog.dom.xml.serialize(/** @type {Element} */(node)); + return this.xmlSerializer_.serializeToString(node); }; @@ -245,7 +251,7 @@ ol.format.XMLFeature.prototype.writeGeometry = function(geometry, opt_options) { var node = this.writeGeometryNode(geometry, opt_options); goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT, 'node.nodeType should be ELEMENT'); - return goog.dom.xml.serialize(/** @type {Element} */(node)); + return this.xmlSerializer_.serializeToString(node); }; From 7da7cba81285f3073126fefa52eb535c3c941dc8 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Wed, 2 Mar 2016 14:06:31 +0100 Subject: [PATCH 9/9] Don't use goog.dom.xml.createDocument Use DOMImplementation.createDocument instead, available for IE >= 9 --- src/ol/xml.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ol/xml.js b/src/ol/xml.js index da78d717ad..a3b772a568 100644 --- a/src/ol/xml.js +++ b/src/ol/xml.js @@ -2,7 +2,6 @@ goog.provide('ol.xml'); goog.require('goog.asserts'); goog.require('goog.dom.NodeType'); -goog.require('goog.dom.xml'); goog.require('ol.array'); @@ -34,7 +33,7 @@ ol.xml.Serializer; * @const * @type {Document} */ -ol.xml.DOCUMENT = goog.dom.xml.createDocument(); +ol.xml.DOCUMENT = document.implementation.createDocument('', '', null); /**