1 /**
  2  * @fileoverview A class implementing the XPath NameTest construct.
  3  */
  4 
  5 goog.provide('xrx.xpath.NameTest');
  6 
  7 goog.require('xrx.node');
  8 
  9 
 10 
 11 /**
 12  * Constructs a NameTest based on the XPath grammar.
 13  * http://www.w3.org/TR/xpath/#NT-NameTest
 14  *
 15  * @param {string} name Name to be tested.
 16  * @param {string=} opt_namespaceUri Namespace URI.
 17  * @constructor
 18  * @implements {xrx.xpath.NodeTest}
 19  */
 20 xrx.xpath.NameTest = function(name, opt_namespaceUri) {
 21 
 22   /**
 23    * @type {string}
 24    * @private
 25    */
 26   this.name_ = name;
 27 
 28   /**
 29    * @type {string}
 30    * @private
 31    */
 32   this.namespaceUri_ = opt_namespaceUri;
 33 };
 34 
 35 
 36 
 37 /**
 38  * @override
 39  */
 40 xrx.xpath.NameTest.prototype.matches = function(node) {
 41   var type = node.type();
 42   if (type !== xrx.node.ELEMENT &&
 43       type !== xrx.node.ATTRIBUTE) {
 44     return false;
 45   }
 46   if (this.name_ !== '*' && this.name_ !== node.expandedName()) {
 47     return false;
 48   } else {
 49     return this.namespaceUri_ === node.namespaceUri();
 50   }
 51 };
 52 
 53 
 54 /**
 55  * @override
 56  */
 57 xrx.xpath.NameTest.prototype.getName = function() {
 58   return this.name_;
 59 };
 60 
 61 
 62 /**
 63  * Returns the namespace URI to be matched.
 64  *
 65  * @return {string} Namespace URI.
 66  */
 67 xrx.xpath.NameTest.prototype.getNamespaceUri = function() {
 68   return this.namespaceUri_;
 69 };
 70 
 71 
 72 /**
 73  * @override
 74  */
 75 xrx.xpath.NameTest.prototype.toString = function() {
 76   var prefix = this.namespaceUri_ + ':';
 77   return 'Name Test: ' + prefix + this.name_;
 78 };
 79