Upgrade Selenium on Rails to r140

This commit is contained in:
Eric Allen 2009-12-14 11:51:36 -05:00
parent 156862200b
commit 40074c71ad
117 changed files with 16789 additions and 8867 deletions

View file

@ -1,16 +1,10 @@
// Copyright 2005 Google Inc.
// All Rights Reserved
//
// Author: Steffen Meschkat <mesch@google.com>
//
// An XML parse and a minimal DOM implementation that just supportes
// the subset of the W3C DOM that is used in the XSLT implementation.
//
// References:
//
// [DOM] W3C DOM Level 3 Core Specification
// <http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/>.
//
//
// Author: Steffen Meschkat <mesch@google.com>
// NOTE: The split() method in IE omits empty result strings. This is
// utterly annoying. So we don't use it here.
@ -20,69 +14,90 @@
// the API level. I.e. no entity references are passed through the
// API. See "Entities and the DOM core", p.12, DOM 2 Core
// Spec. However, different browsers actually pass very different
// values at the API.
//
// values at the API. See <http://mesch.nyc/test-xml-quote>.
function xmlResolveEntities(s) {
var parts = stringSplit(s, '&');
var ret = parts[0];
for (var i = 1; i < parts.length; ++i) {
var rp = stringSplit(parts[i], ';');
if (rp.length == 1) {
var rp = parts[i].indexOf(';');
if (rp == -1) {
// no entity reference: just a & but no ;
ret += parts[i];
continue;
}
var entityName = parts[i].substring(0, rp);
var remainderText = parts[i].substring(rp + 1);
var ch;
switch (rp[0]) {
case 'lt':
switch (entityName) {
case 'lt':
ch = '<';
break;
case 'gt':
case 'gt':
ch = '>';
break;
case 'amp':
case 'amp':
ch = '&';
break;
case 'quot':
case 'quot':
ch = '"';
break;
case 'apos':
case 'apos':
ch = '\'';
break;
case 'nbsp':
case 'nbsp':
ch = String.fromCharCode(160);
break;
default:
// Cool trick: let the DOM do the entity decoding. We assign
// the entity text through non-W3C DOM properties and read it
// through the W3C DOM. W3C DOM access is specified to resolve
// entities.
var span = window.document.createElement('span');
span.innerHTML = '&' + rp[0] + '; ';
// entities.
var span = domCreateElement(window.document, 'span');
span.innerHTML = '&' + entityName + '; ';
ch = span.childNodes[0].nodeValue.charAt(0);
}
ret += ch + rp[1];
ret += ch + remainderText;
}
return ret;
}
var XML10_TAGNAME_REGEXP = new RegExp('^(' + XML10_NAME + ')');
var XML10_ATTRIBUTE_REGEXP = new RegExp(XML10_ATTRIBUTE, 'g');
var XML11_TAGNAME_REGEXP = new RegExp('^(' + XML11_NAME + ')');
var XML11_ATTRIBUTE_REGEXP = new RegExp(XML11_ATTRIBUTE, 'g');
// Parses the given XML string with our custom, JavaScript XML parser. Written
// by Steffen Meschkat (mesch@google.com).
function xmlParse(xml) {
Timer.start('xmlparse');
var regex_empty = /\/$/;
// See also <http://www.w3.org/TR/REC-xml/#sec-common-syn> for
// allowed chars in a tag and attribute name. TODO(mesch): the
// following is still not completely correct.
var regex_tagname = /^([\w:-]*)/;
var regex_attribute = /([\w:-]+)\s?=\s?('([^\']*)'|"([^\"]*)")/g;
var regex_tagname;
var regex_attribute;
if (xml.match(/^<\?xml/)) {
// When an XML document begins with an XML declaration
// VersionInfo must appear.
if (xml.search(new RegExp(XML10_VERSION_INFO)) == 5) {
regex_tagname = XML10_TAGNAME_REGEXP;
regex_attribute = XML10_ATTRIBUTE_REGEXP;
} else if (xml.search(new RegExp(XML11_VERSION_INFO)) == 5) {
regex_tagname = XML11_TAGNAME_REGEXP;
regex_attribute = XML11_ATTRIBUTE_REGEXP;
} else {
// VersionInfo is missing, or unknown version number.
// TODO : Fallback to XML 1.0 or XML 1.1, or just return null?
alert('VersionInfo is missing, or unknown version number.');
}
} else {
// When an XML declaration is missing it's an XML 1.0 document.
regex_tagname = XML10_TAGNAME_REGEXP;
regex_attribute = XML10_ATTRIBUTE_REGEXP;
}
var xmldoc = new XDocument();
var root = xmldoc;
@ -100,13 +115,67 @@ function xmlParse(xml) {
var parent = root;
stack.push(parent);
// The token that delimits a section that contains markup as
// content: CDATA or comments.
var slurp = '';
var x = stringSplit(xml, '<');
for (var i = 1; i < x.length; ++i) {
var xx = stringSplit(x[i], '>');
var tag = xx[0];
var text = xmlResolveEntities(xx[1] || '');
if (tag.charAt(0) == '/') {
if (slurp) {
// In a "slurp" section (CDATA or comment): only check for the
// end of the section, otherwise append the whole text.
var end = x[i].indexOf(slurp);
if (end != -1) {
var data = x[i].substring(0, end);
parent.nodeValue += '<' + data;
stack.pop();
parent = stack[stack.length-1];
text = x[i].substring(end + slurp.length);
slurp = '';
} else {
parent.nodeValue += '<' + x[i];
text = null;
}
} else if (tag.indexOf('![CDATA[') == 0) {
var start = '![CDATA['.length;
var end = x[i].indexOf(']]>');
if (end != -1) {
var data = x[i].substring(start, end);
var node = domCreateCDATASection(xmldoc, data);
domAppendChild(parent, node);
} else {
var data = x[i].substring(start);
text = null;
var node = domCreateCDATASection(xmldoc, data);
domAppendChild(parent, node);
parent = node;
stack.push(node);
slurp = ']]>';
}
} else if (tag.indexOf('!--') == 0) {
var start = '!--'.length;
var end = x[i].indexOf('-->');
if (end != -1) {
var data = x[i].substring(start, end);
var node = domCreateComment(xmldoc, data);
domAppendChild(parent, node);
} else {
var data = x[i].substring(start);
text = null;
var node = domCreateComment(xmldoc, data);
domAppendChild(parent, node);
parent = node;
stack.push(node);
slurp = '-->';
}
} else if (tag.charAt(0) == '/') {
stack.pop();
parent = stack[stack.length-1];
@ -117,43 +186,87 @@ function xmlParse(xml) {
} else {
var empty = tag.match(regex_empty);
var tagname = regex_tagname.exec(tag)[1];
var node = xmldoc.createElement(tagname);
var node = domCreateElement(xmldoc, tagname);
var att;
while (att = regex_attribute.exec(tag)) {
var val = xmlResolveEntities(att[3] || att[4] || '');
node.setAttribute(att[1], val);
var val = xmlResolveEntities(att[5] || att[7] || '');
domSetAttribute(node, att[1], val);
}
if (empty) {
parent.appendChild(node);
} else {
parent.appendChild(node);
domAppendChild(parent, node);
if (!empty) {
parent = node;
stack.push(node);
}
}
if (text && parent != root) {
parent.appendChild(xmldoc.createTextNode(text));
domAppendChild(parent, domCreateTextNode(xmldoc, text));
}
}
Timer.end('xmlparse');
return root;
}
// Based on <http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/
// core.html#ID-1950641247>
var DOM_ELEMENT_NODE = 1;
var DOM_ATTRIBUTE_NODE = 2;
var DOM_TEXT_NODE = 3;
var DOM_CDATA_SECTION_NODE = 4;
var DOM_ENTITY_REFERENCE_NODE = 5;
var DOM_ENTITY_NODE = 6;
var DOM_PROCESSING_INSTRUCTION_NODE = 7;
var DOM_COMMENT_NODE = 8;
var DOM_DOCUMENT_NODE = 9;
var DOM_DOCUMENT_TYPE_NODE = 10;
var DOM_DOCUMENT_FRAGMENT_NODE = 11;
var DOM_NOTATION_NODE = 12;
// Traverses the element nodes in the DOM section underneath the given
// node and invokes the given callbacks as methods on every element
// node encountered. Function opt_pre is invoked before a node's
// children are traversed; opt_post is invoked after they are
// traversed. Traversal will not be continued if a callback function
// returns boolean false. NOTE(mesch): copied from
// <//google3/maps/webmaps/javascript/dom.js>.
function domTraverseElements(node, opt_pre, opt_post) {
var ret;
if (opt_pre) {
ret = opt_pre.call(null, node);
if (typeof ret == 'boolean' && !ret) {
return false;
}
}
for (var c = node.firstChild; c; c = c.nextSibling) {
if (c.nodeType == DOM_ELEMENT_NODE) {
ret = arguments.callee.call(this, c, opt_pre, opt_post);
if (typeof ret == 'boolean' && !ret) {
return false;
}
}
}
if (opt_post) {
ret = opt_post.call(null, node);
if (typeof ret == 'boolean' && !ret) {
return false;
}
}
}
// Our W3C DOM Node implementation. Note we call it XNode because we
// can't define the identifier Node. We do this mostly for Opera,
// where we can't reuse the HTML DOM for parsing our own XML, and for
// Safari, where it is too expensive to have the template processor
// operate on native DOM nodes.
function XNode(type, name, value, owner) {
function XNode(type, name, opt_value, opt_owner) {
this.attributes = [];
this.childNodes = [];
XNode.init.call(this, type, name, value, owner);
XNode.init.call(this, type, name, opt_value, opt_owner);
}
// Don't call as method, use apply() or call().
@ -242,18 +355,18 @@ XNode.prototype.replaceChild = function(newNode, oldNode) {
for (var i = 0; i < this.childNodes.length; ++i) {
if (this.childNodes[i] == oldNode) {
this.childNodes[i] = newNode;
var p = oldNode.parentNode;
oldNode.parentNode = null;
newNode.parentNode = p;
p = oldNode.previousSibling;
oldNode.previousSibling = null;
newNode.previousSibling = p;
if (newNode.previousSibling) {
newNode.previousSibling.nextSibling = newNode;
}
p = oldNode.nextSibling;
oldNode.nextSibling = null;
newNode.nextSibling = p;
@ -274,6 +387,7 @@ XNode.prototype.replaceChild = function(newNode, oldNode) {
}
}
XNode.prototype.insertBefore = function(newNode, oldNode) {
if (oldNode == newNode) {
return;
@ -300,7 +414,7 @@ XNode.prototype.insertBefore = function(newNode, oldNode) {
if (newNode.previousSibling) {
newNode.previousSibling.nextSibling = newNode;
}
newNode.nextSibling = oldNode;
if (this.firstChild == oldNode) {
@ -312,6 +426,7 @@ XNode.prototype.insertBefore = function(newNode, oldNode) {
this.childNodes = newChildren;
}
XNode.prototype.removeChild = function(node) {
var newChildren = [];
for (var i = 0; i < this.childNodes.length; ++i) {
@ -349,7 +464,7 @@ XNode.prototype.setAttribute = function(name, value) {
return;
}
}
this.attributes.push(new XNode(DOM_ATTRIBUTE_NODE, name, value));
this.attributes.push(XNode.create(DOM_ATTRIBUTE_NODE, name, value, this));
}
@ -362,6 +477,7 @@ XNode.prototype.getAttribute = function(name) {
return null;
}
XNode.prototype.removeAttribute = function(name) {
var a = [];
for (var i = 0; i < this.attributes.length; ++i) {
@ -373,8 +489,42 @@ XNode.prototype.removeAttribute = function(name) {
}
XNode.prototype.getElementsByTagName = function(name) {
var ret = [];
var self = this;
if ("*" == name) {
domTraverseElements(this, function(node) {
if (self == node) return;
ret.push(node);
}, null);
} else {
domTraverseElements(this, function(node) {
if (self == node) return;
if (node.nodeName == name) {
ret.push(node);
}
}, null);
}
return ret;
}
XNode.prototype.getElementById = function(id) {
var ret = null;
domTraverseElements(this, function(node) {
if (node.getAttribute('id') == id) {
ret = node;
return false;
}
}, null);
return ret;
}
function XDocument() {
XNode.call(this, DOM_DOCUMENT_NODE, '#document', null, this);
// NOTE(mesch): Acocording to the DOM Spec, ownerDocument of a
// document node is null.
XNode.call(this, DOM_DOCUMENT_NODE, '#document', null, null);
this.documentElement = null;
}
@ -411,18 +561,6 @@ XDocument.prototype.createComment = function(data) {
return XNode.create(DOM_COMMENT_NODE, '#comment', data, this);
}
XNode.prototype.getElementsByTagName = function(name, list) {
if (!list) {
list = [];
}
if (this.nodeName == name) {
list.push(this);
}
for (var i = 0; i < this.childNodes.length; ++i) {
this.childNodes[i].getElementsByTagName(name, list);
}
return list;
XDocument.prototype.createCDATASection = function(data) {
return XNode.create(DOM_CDATA_SECTION_NODE, '#cdata-section', data, this);
}

File diff suppressed because it is too large Load diff

View file

@ -1,255 +0,0 @@
// Copyright 2005 Google Inc.
// All Rights Reserved
//
// Miscellania that support the ajaxslt implementation.
//
// Author: Steffen Meschkat <mesch@google.com>
//
function el(i) {
return document.getElementById(i);
}
function px(x) {
return x + 'px';
}
// Split a string s at all occurrences of character c. This is like
// the split() method of the string object, but IE omits empty
// strings, which violates the invariant (s.split(x).join(x) == s).
function stringSplit(s, c) {
var a = s.indexOf(c);
if (a == -1) {
return [ s ];
}
var parts = [];
parts.push(s.substr(0,a));
while (a != -1) {
var a1 = s.indexOf(c, a + 1);
if (a1 != -1) {
parts.push(s.substr(a + 1, a1 - a - 1));
} else {
parts.push(s.substr(a + 1));
}
a = a1;
}
return parts;
}
// Returns the text value if a node; for nodes without children this
// is the nodeValue, for nodes with children this is the concatenation
// of the value of all children.
function xmlValue(node) {
if (!node) {
return '';
}
var ret = '';
if (node.nodeType == DOM_TEXT_NODE ||
node.nodeType == DOM_CDATA_SECTION_NODE ||
node.nodeType == DOM_ATTRIBUTE_NODE) {
ret += node.nodeValue;
} else if (node.nodeType == DOM_ELEMENT_NODE ||
node.nodeType == DOM_DOCUMENT_NODE ||
node.nodeType == DOM_DOCUMENT_FRAGMENT_NODE) {
for (var i = 0; i < node.childNodes.length; ++i) {
ret += arguments.callee(node.childNodes[i]);
}
}
return ret;
}
// Returns the representation of a node as XML text.
function xmlText(node) {
var ret = '';
if (node.nodeType == DOM_TEXT_NODE) {
ret += xmlEscapeText(node.nodeValue);
} else if (node.nodeType == DOM_ELEMENT_NODE) {
ret += '<' + node.nodeName;
for (var i = 0; i < node.attributes.length; ++i) {
var a = node.attributes[i];
if (a && a.nodeName && a.nodeValue) {
ret += ' ' + a.nodeName;
ret += '="' + xmlEscapeAttr(a.nodeValue) + '"';
}
}
if (node.childNodes.length == 0) {
ret += '/>';
} else {
ret += '>';
for (var i = 0; i < node.childNodes.length; ++i) {
ret += arguments.callee(node.childNodes[i]);
}
ret += '</' + node.nodeName + '>';
}
} else if (node.nodeType == DOM_DOCUMENT_NODE ||
node.nodeType == DOM_DOCUMENT_FRAGMENT_NODE) {
for (var i = 0; i < node.childNodes.length; ++i) {
ret += arguments.callee(node.childNodes[i]);
}
}
return ret;
}
// Applies the given function to each element of the array.
function mapExec(array, func) {
for (var i = 0; i < array.length; ++i) {
func(array[i]);
}
}
// Returns an array that contains the return value of the given
// function applied to every element of the input array.
function mapExpr(array, func) {
var ret = [];
for (var i = 0; i < array.length; ++i) {
ret.push(func(array[i]));
}
return ret;
};
// Reverses the given array in place.
function reverseInplace(array) {
for (var i = 0; i < array.length / 2; ++i) {
var h = array[i];
var ii = array.length - i - 1;
array[i] = array[ii];
array[ii] = h;
}
}
// Shallow-copies an array.
function copyArray(dst, src) {
for (var i = 0; i < src.length; ++i) {
dst.push(src[i]);
}
}
function assert(b) {
if (!b) {
throw 'assertion failed';
}
}
// Based on
// <http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#ID-1950641247>
var DOM_ELEMENT_NODE = 1;
var DOM_ATTRIBUTE_NODE = 2;
var DOM_TEXT_NODE = 3;
var DOM_CDATA_SECTION_NODE = 4;
var DOM_ENTITY_REFERENCE_NODE = 5;
var DOM_ENTITY_NODE = 6;
var DOM_PROCESSING_INSTRUCTION_NODE = 7;
var DOM_COMMENT_NODE = 8;
var DOM_DOCUMENT_NODE = 9;
var DOM_DOCUMENT_TYPE_NODE = 10;
var DOM_DOCUMENT_FRAGMENT_NODE = 11;
var DOM_NOTATION_NODE = 12;
var xpathdebug = false; // trace xpath parsing
var xsltdebug = false; // trace xslt processing
// Escape XML special markup chracters: tag delimiter < > and entity
// reference start delimiter &. The escaped string can be used in XML
// text portions (i.e. between tags).
function xmlEscapeText(s) {
return s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
// Escape XML special markup characters: tag delimiter < > entity
// reference start delimiter & and quotes ". The escaped string can be
// used in double quoted XML attribute value portions (i.e. in
// attributes within start tags).
function xmlEscapeAttr(s) {
return xmlEscapeText(s).replace(/\"/g, '&quot;');
}
// Escape markup in XML text, but don't touch entity references. The
// escaped string can be used as XML text (i.e. between tags).
function xmlEscapeTags(s) {
return s.replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
// An implementation of the debug log.
var logging__ = false;
function Log() {};
Log.lines = [];
Log.write = function(s) {
if (logging__) {
this.lines.push(xmlEscapeText(s));
this.show();
}
};
// Writes the given XML with every tag on a new line.
Log.writeXML = function(xml) {
if (logging__) {
var s0 = xml.replace(/</g, '\n<');
var s1 = xmlEscapeText(s0);
var s2 = s1.replace(/\s*\n(\s|\n)*/g, '<br/>');
this.lines.push(s2);
this.show();
}
}
// Writes without any escaping
Log.writeRaw = function(s) {
if (logging__) {
this.lines.push(s);
this.show();
}
}
Log.clear = function() {
if (logging__) {
var l = this.div();
l.innerHTML = '';
this.lines = [];
}
}
Log.show = function() {
var l = this.div();
l.innerHTML += this.lines.join('<br/>') + '<br/>';
this.lines = [];
l.scrollTop = l.scrollHeight;
}
Log.div = function() {
var l = document.getElementById('log');
if (!l) {
l = document.createElement('div');
l.id = 'log';
l.style.position = 'absolute';
l.style.right = '5px';
l.style.top = '5px';
l.style.width = '250px';
l.style.height = '150px';
l.style.overflow = 'auto';
l.style.backgroundColor = '#f0f0f0';
l.style.border = '1px solid gray';
l.style.fontSize = '10px';
l.style.padding = '5px';
document.body.appendChild(l);
}
return l;
}
function Timer() {}
Timer.start = function() {}
Timer.end = function() {}

View file

@ -0,0 +1,549 @@
// Copyright 2005 Google
//
// Author: Steffen Meschkat <mesch@google.com>
//
// Miscellaneous utility and placeholder functions.
// Dummy implmentation for the logging functions. Replace by something
// useful when you want to debug.
function xpathLog(msg) {};
function xsltLog(msg) {};
function xsltLogXml(msg) {};
var ajaxsltIsIE6 = navigator.appVersion.match(/MSIE 6.0/);
// Throws an exception if false.
function assert(b) {
if (!b) {
throw "Assertion failed";
}
}
// Splits a string s at all occurrences of character c. This is like
// the split() method of the string object, but IE omits empty
// strings, which violates the invariant (s.split(x).join(x) == s).
function stringSplit(s, c) {
var a = s.indexOf(c);
if (a == -1) {
return [ s ];
}
var parts = [];
parts.push(s.substr(0,a));
while (a != -1) {
var a1 = s.indexOf(c, a + 1);
if (a1 != -1) {
parts.push(s.substr(a + 1, a1 - a - 1));
} else {
parts.push(s.substr(a + 1));
}
a = a1;
}
return parts;
}
// The following function does what document.importNode(node, true)
// would do for us here; however that method is broken in Safari/1.3,
// so we have to emulate it.
function xmlImportNode(doc, node) {
if (node.nodeType == DOM_TEXT_NODE) {
return domCreateTextNode(doc, node.nodeValue);
} else if (node.nodeType == DOM_CDATA_SECTION_NODE) {
return domCreateCDATASection(doc, node.nodeValue);
} else if (node.nodeType == DOM_ELEMENT_NODE) {
var newNode = domCreateElement(doc, node.nodeName);
for (var i = 0; i < node.attributes.length; ++i) {
var an = node.attributes[i];
var name = an.nodeName;
var value = an.nodeValue;
domSetAttribute(newNode, name, value);
}
for (var c = node.firstChild; c; c = c.nextSibling) {
var cn = arguments.callee(doc, c);
domAppendChild(newNode, cn);
}
return newNode;
} else {
return domCreateComment(doc, node.nodeName);
}
}
// A set data structure. It can also be used as a map (i.e. the keys
// can have values other than 1), but we don't call it map because it
// would be ambiguous in this context. Also, the map is iterable, so
// we can use it to replace for-in loops over core javascript Objects.
// For-in iteration breaks when Object.prototype is modified, which
// some clients of the maps API do.
//
// NOTE(mesch): The set keys by the string value of its element, NOT
// by the typed value. In particular, objects can't be used as keys.
//
// @constructor
function Set() {
this.keys = [];
}
Set.prototype.size = function() {
return this.keys.length;
}
// Adds the entry to the set, ignoring if it is present.
Set.prototype.add = function(key, opt_value) {
var value = opt_value || 1;
if (!this.contains(key)) {
this[':' + key] = value;
this.keys.push(key);
}
}
// Sets the entry in the set, adding if it is not yet present.
Set.prototype.set = function(key, opt_value) {
var value = opt_value || 1;
if (!this.contains(key)) {
this[':' + key] = value;
this.keys.push(key);
} else {
this[':' + key] = value;
}
}
// Increments the key's value by 1. This works around the fact that
// numbers are always passed by value, never by reference, so that we
// can't increment the value returned by get(), or the iterator
// argument. Sets the key's value to 1 if it doesn't exist yet.
Set.prototype.inc = function(key) {
if (!this.contains(key)) {
this[':' + key] = 1;
this.keys.push(key);
} else {
this[':' + key]++;
}
}
Set.prototype.get = function(key) {
if (this.contains(key)) {
return this[':' + key];
} else {
var undefined;
return undefined;
}
}
// Removes the entry from the set.
Set.prototype.remove = function(key) {
if (this.contains(key)) {
delete this[':' + key];
removeFromArray(this.keys, key, true);
}
}
// Tests if an entry is in the set.
Set.prototype.contains = function(entry) {
return typeof this[':' + entry] != 'undefined';
}
// Gets a list of values in the set.
Set.prototype.items = function() {
var list = [];
for (var i = 0; i < this.keys.length; ++i) {
var k = this.keys[i];
var v = this[':' + k];
list.push(v);
}
return list;
}
// Invokes function f for every key value pair in the set as a method
// of the set.
Set.prototype.map = function(f) {
for (var i = 0; i < this.keys.length; ++i) {
var k = this.keys[i];
f.call(this, k, this[':' + k]);
}
}
Set.prototype.clear = function() {
for (var i = 0; i < this.keys.length; ++i) {
delete this[':' + this.keys[i]];
}
this.keys.length = 0;
}
// Applies the given function to each element of the array, preserving
// this, and passing the index.
function mapExec(array, func) {
for (var i = 0; i < array.length; ++i) {
func.call(this, array[i], i);
}
}
// Returns an array that contains the return value of the given
// function applied to every element of the input array.
function mapExpr(array, func) {
var ret = [];
for (var i = 0; i < array.length; ++i) {
ret.push(func(array[i]));
}
return ret;
};
// Reverses the given array in place.
function reverseInplace(array) {
for (var i = 0; i < array.length / 2; ++i) {
var h = array[i];
var ii = array.length - i - 1;
array[i] = array[ii];
array[ii] = h;
}
}
// Removes value from array. Returns the number of instances of value
// that were removed from array.
function removeFromArray(array, value, opt_notype) {
var shift = 0;
for (var i = 0; i < array.length; ++i) {
if (array[i] === value || (opt_notype && array[i] == value)) {
array.splice(i--, 1);
shift++;
}
}
return shift;
}
// Shallow-copies an array to the end of another array
// Basically Array.concat, but works with other non-array collections
function copyArray(dst, src) {
if (!src) return;
var dstLength = dst.length;
for (var i = src.length - 1; i >= 0; --i) {
dst[i+dstLength] = src[i];
}
}
/**
* This is an optimization for copying attribute lists in IE. IE includes many
* extraneous properties in its DOM attribute lists, which take require
* significant extra processing when evaluating attribute steps. With this
* function, we ignore any such attributes that has an empty string value.
*/
function copyArrayIgnoringAttributesWithoutValue(dst, src)
{
if (!src) return;
for (var i = src.length - 1; i >= 0; --i) {
// this test will pass so long as the attribute has a non-empty string
// value, even if that value is "false", "0", "undefined", etc.
if (src[i].nodeValue) {
dst.push(src[i]);
}
}
}
// Returns the text value of a node; for nodes without children this
// is the nodeValue, for nodes with children this is the concatenation
// of the value of all children. Browser-specific optimizations are used by
// default; they can be disabled by passing "true" in as the second parameter.
function xmlValue(node, disallowBrowserSpecificOptimization) {
if (!node) {
return '';
}
var ret = '';
if (node.nodeType == DOM_TEXT_NODE ||
node.nodeType == DOM_CDATA_SECTION_NODE) {
ret += node.nodeValue;
} else if (node.nodeType == DOM_ATTRIBUTE_NODE) {
if (ajaxsltIsIE6) {
ret += xmlValueIE6Hack(node);
} else {
ret += node.nodeValue;
}
} else if (node.nodeType == DOM_ELEMENT_NODE ||
node.nodeType == DOM_DOCUMENT_NODE ||
node.nodeType == DOM_DOCUMENT_FRAGMENT_NODE) {
if (!disallowBrowserSpecificOptimization) {
// IE, Safari, Opera, and friends
var innerText = node.innerText;
if (innerText != undefined) {
return innerText;
}
// Firefox
var textContent = node.textContent;
if (textContent != undefined) {
return textContent;
}
}
// pobrecito!
var len = node.childNodes.length;
for (var i = 0; i < len; ++i) {
ret += arguments.callee(node.childNodes[i]);
}
}
return ret;
}
function xmlValueIE6Hack(node) {
// Issue 19, IE6 mangles href attribute when it's a javascript: url
var nodeName = node.nodeName;
var nodeValue = node.nodeValue;
if (nodeName.length != 4) return nodeValue;
if (!/^href$/i.test(nodeName)) return nodeValue;
if (!/^javascript:/.test(nodeValue)) return nodeValue;
return unescape(nodeValue);
}
// Returns the representation of a node as XML text.
function xmlText(node, opt_cdata) {
var buf = [];
xmlTextR(node, buf, opt_cdata);
return buf.join('');
}
function xmlTextR(node, buf, cdata) {
if (node.nodeType == DOM_TEXT_NODE) {
buf.push(xmlEscapeText(node.nodeValue));
} else if (node.nodeType == DOM_CDATA_SECTION_NODE) {
if (cdata) {
buf.push(node.nodeValue);
} else {
buf.push('<![CDATA[' + node.nodeValue + ']]>');
}
} else if (node.nodeType == DOM_COMMENT_NODE) {
buf.push('<!--' + node.nodeValue + '-->');
} else if (node.nodeType == DOM_ELEMENT_NODE) {
buf.push('<' + xmlFullNodeName(node));
for (var i = 0; i < node.attributes.length; ++i) {
var a = node.attributes[i];
if (a && a.nodeName && a.nodeValue) {
buf.push(' ' + xmlFullNodeName(a) + '="' +
xmlEscapeAttr(a.nodeValue) + '"');
}
}
if (node.childNodes.length == 0) {
buf.push('/>');
} else {
buf.push('>');
for (var i = 0; i < node.childNodes.length; ++i) {
arguments.callee(node.childNodes[i], buf, cdata);
}
buf.push('</' + xmlFullNodeName(node) + '>');
}
} else if (node.nodeType == DOM_DOCUMENT_NODE ||
node.nodeType == DOM_DOCUMENT_FRAGMENT_NODE) {
for (var i = 0; i < node.childNodes.length; ++i) {
arguments.callee(node.childNodes[i], buf, cdata);
}
}
}
function xmlFullNodeName(n) {
if (n.prefix && n.nodeName.indexOf(n.prefix + ':') != 0) {
return n.prefix + ':' + n.nodeName;
} else {
return n.nodeName;
}
}
// Escape XML special markup chracters: tag delimiter < > and entity
// reference start delimiter &. The escaped string can be used in XML
// text portions (i.e. between tags).
function xmlEscapeText(s) {
return ('' + s).replace(/&/g, '&amp;').replace(/</g, '&lt;').
replace(/>/g, '&gt;');
}
// Escape XML special markup characters: tag delimiter < > entity
// reference start delimiter & and quotes ". The escaped string can be
// used in double quoted XML attribute value portions (i.e. in
// attributes within start tags).
function xmlEscapeAttr(s) {
return xmlEscapeText(s).replace(/\"/g, '&quot;');
}
// Escape markup in XML text, but don't touch entity references. The
// escaped string can be used as XML text (i.e. between tags).
function xmlEscapeTags(s) {
return s.replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
/**
* Wrapper function to access the owner document uniformly for document
* and other nodes: for the document node, the owner document is the
* node itself, for all others it's the ownerDocument property.
*
* @param {Node} node
* @return {Document}
*/
function xmlOwnerDocument(node) {
if (node.nodeType == DOM_DOCUMENT_NODE) {
return node;
} else {
return node.ownerDocument;
}
}
// Wrapper around DOM methods so we can condense their invocations.
function domGetAttribute(node, name) {
return node.getAttribute(name);
}
function domSetAttribute(node, name, value) {
return node.setAttribute(name, value);
}
function domRemoveAttribute(node, name) {
return node.removeAttribute(name);
}
function domAppendChild(node, child) {
return node.appendChild(child);
}
function domRemoveChild(node, child) {
return node.removeChild(child);
}
function domReplaceChild(node, newChild, oldChild) {
return node.replaceChild(newChild, oldChild);
}
function domInsertBefore(node, newChild, oldChild) {
return node.insertBefore(newChild, oldChild);
}
function domRemoveNode(node) {
return domRemoveChild(node.parentNode, node);
}
function domCreateTextNode(doc, text) {
return doc.createTextNode(text);
}
function domCreateElement(doc, name) {
return doc.createElement(name);
}
function domCreateAttribute(doc, name) {
return doc.createAttribute(name);
}
function domCreateCDATASection(doc, data) {
return doc.createCDATASection(data);
}
function domCreateComment(doc, text) {
return doc.createComment(text);
}
function domCreateDocumentFragment(doc) {
return doc.createDocumentFragment();
}
function domGetElementById(doc, id) {
return doc.getElementById(id);
}
// Same for window methods.
function windowSetInterval(win, fun, time) {
return win.setInterval(fun, time);
}
function windowClearInterval(win, id) {
return win.clearInterval(id);
}
/**
* Escape the special regular expression characters when the regular expression
* is specified as a string.
*
* Based on: http://simonwillison.net/2006/Jan/20/escape/
*/
RegExp.escape = (function() {
var specials = [
'/', '.', '*', '+', '?', '|', '^', '$',
'(', ')', '[', ']', '{', '}', '\\'
];
var sRE = new RegExp(
'(\\' + specials.join('|\\') + ')', 'g'
);
return function(text) {
return text.replace(sRE, '\\$1');
}
})();
/**
* Determines whether a predicate expression contains a "positional selector".
* A positional selector filters nodes from the nodelist input based on their
* position within that list. When such selectors are encountered, the
* evaluation of the predicate cannot be depth-first, because the positional
* selector may be based on the result of evaluating predicates that precede
* it.
*/
function predicateExprHasPositionalSelector(expr, isRecursiveCall) {
if (!expr) {
return false;
}
if (!isRecursiveCall && exprReturnsNumberValue(expr)) {
// this is a "proximity position"-based predicate
return true;
}
if (expr instanceof FunctionCallExpr) {
var value = expr.name.value;
return (value == 'last' || value == 'position');
}
if (expr instanceof BinaryExpr) {
return (
predicateExprHasPositionalSelector(expr.expr1, true) ||
predicateExprHasPositionalSelector(expr.expr2, true));
}
return false;
}
function exprReturnsNumberValue(expr) {
if (expr instanceof FunctionCallExpr) {
var isMember = {
last: true
, position: true
, count: true
, 'string-length': true
, number: true
, sum: true
, floor: true
, ceiling: true
, round: true
};
return isMember[expr.name.value];
}
else if (expr instanceof UnaryMinusExpr) {
return true;
}
else if (expr instanceof BinaryExpr) {
var isMember = {
'+': true
, '-': true
, '*': true
, mod: true
, div: true
};
return isMember[expr.op.value];
}
else if (expr instanceof NumberExpr) {
return true;
}
return false;
}

View file

@ -0,0 +1,149 @@
// Copyright 2006 Google Inc.
// All Rights Reserved
//
// Defines regular expression patterns to extract XML tokens from string.
// See <http://www.w3.org/TR/REC-xml/#sec-common-syn>,
// <http://www.w3.org/TR/xml11/#sec-common-syn> and
// <http://www.w3.org/TR/REC-xml-names/#NT-NCName> for the specifications.
//
// Author: Junji Takagi <jtakagi@google.com>
// Detect whether RegExp supports Unicode characters or not.
var REGEXP_UNICODE = function() {
var tests = [' ', '\u0120', -1, // Konquerer 3.4.0 fails here.
'!', '\u0120', -1,
'\u0120', '\u0120', 0,
'\u0121', '\u0120', -1,
'\u0121', '\u0120|\u0121', 0,
'\u0122', '\u0120|\u0121', -1,
'\u0120', '[\u0120]', 0, // Safari 2.0.3 fails here.
'\u0121', '[\u0120]', -1,
'\u0121', '[\u0120\u0121]', 0, // Safari 2.0.3 fails here.
'\u0122', '[\u0120\u0121]', -1,
'\u0121', '[\u0120-\u0121]', 0, // Safari 2.0.3 fails here.
'\u0122', '[\u0120-\u0121]', -1];
for (var i = 0; i < tests.length; i += 3) {
if (tests[i].search(new RegExp(tests[i + 1])) != tests[i + 2]) {
return false;
}
}
return true;
}();
// Common tokens in XML 1.0 and XML 1.1.
var XML_S = '[ \t\r\n]+';
var XML_EQ = '(' + XML_S + ')?=(' + XML_S + ')?';
var XML_CHAR_REF = '&#[0-9]+;|&#x[0-9a-fA-F]+;';
// XML 1.0 tokens.
var XML10_VERSION_INFO = XML_S + 'version' + XML_EQ + '("1\\.0"|' + "'1\\.0')";
var XML10_BASE_CHAR = (REGEXP_UNICODE) ?
'\u0041-\u005a\u0061-\u007a\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u00ff' +
'\u0100-\u0131\u0134-\u013e\u0141-\u0148\u014a-\u017e\u0180-\u01c3' +
'\u01cd-\u01f0\u01f4-\u01f5\u01fa-\u0217\u0250-\u02a8\u02bb-\u02c1\u0386' +
'\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03ce\u03d0-\u03d6\u03da\u03dc' +
'\u03de\u03e0\u03e2-\u03f3\u0401-\u040c\u040e-\u044f\u0451-\u045c' +
'\u045e-\u0481\u0490-\u04c4\u04c7-\u04c8\u04cb-\u04cc\u04d0-\u04eb' +
'\u04ee-\u04f5\u04f8-\u04f9\u0531-\u0556\u0559\u0561-\u0586\u05d0-\u05ea' +
'\u05f0-\u05f2\u0621-\u063a\u0641-\u064a\u0671-\u06b7\u06ba-\u06be' +
'\u06c0-\u06ce\u06d0-\u06d3\u06d5\u06e5-\u06e6\u0905-\u0939\u093d' +
'\u0958-\u0961\u0985-\u098c\u098f-\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2' +
'\u09b6-\u09b9\u09dc-\u09dd\u09df-\u09e1\u09f0-\u09f1\u0a05-\u0a0a' +
'\u0a0f-\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32-\u0a33\u0a35-\u0a36' +
'\u0a38-\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8b\u0a8d' +
'\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2-\u0ab3\u0ab5-\u0ab9' +
'\u0abd\u0ae0\u0b05-\u0b0c\u0b0f-\u0b10\u0b13-\u0b28\u0b2a-\u0b30' +
'\u0b32-\u0b33\u0b36-\u0b39\u0b3d\u0b5c-\u0b5d\u0b5f-\u0b61\u0b85-\u0b8a' +
'\u0b8e-\u0b90\u0b92-\u0b95\u0b99-\u0b9a\u0b9c\u0b9e-\u0b9f\u0ba3-\u0ba4' +
'\u0ba8-\u0baa\u0bae-\u0bb5\u0bb7-\u0bb9\u0c05-\u0c0c\u0c0e-\u0c10' +
'\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c60-\u0c61\u0c85-\u0c8c' +
'\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cde\u0ce0-\u0ce1' +
'\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d28\u0d2a-\u0d39\u0d60-\u0d61' +
'\u0e01-\u0e2e\u0e30\u0e32-\u0e33\u0e40-\u0e45\u0e81-\u0e82\u0e84' +
'\u0e87-\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5' +
'\u0ea7\u0eaa-\u0eab\u0ead-\u0eae\u0eb0\u0eb2-\u0eb3\u0ebd\u0ec0-\u0ec4' +
'\u0f40-\u0f47\u0f49-\u0f69\u10a0-\u10c5\u10d0-\u10f6\u1100\u1102-\u1103' +
'\u1105-\u1107\u1109\u110b-\u110c\u110e-\u1112\u113c\u113e\u1140\u114c' +
'\u114e\u1150\u1154-\u1155\u1159\u115f-\u1161\u1163\u1165\u1167\u1169' +
'\u116d-\u116e\u1172-\u1173\u1175\u119e\u11a8\u11ab\u11ae-\u11af' +
'\u11b7-\u11b8\u11ba\u11bc-\u11c2\u11eb\u11f0\u11f9\u1e00-\u1e9b' +
'\u1ea0-\u1ef9\u1f00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d' +
'\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc' +
'\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec' +
'\u1ff2-\u1ff4\u1ff6-\u1ffc\u2126\u212a-\u212b\u212e\u2180-\u2182' +
'\u3041-\u3094\u30a1-\u30fa\u3105-\u312c\uac00-\ud7a3' :
'A-Za-z';
var XML10_IDEOGRAPHIC = (REGEXP_UNICODE) ?
'\u4e00-\u9fa5\u3007\u3021-\u3029' :
'';
var XML10_COMBINING_CHAR = (REGEXP_UNICODE) ?
'\u0300-\u0345\u0360-\u0361\u0483-\u0486\u0591-\u05a1\u05a3-\u05b9' +
'\u05bb-\u05bd\u05bf\u05c1-\u05c2\u05c4\u064b-\u0652\u0670\u06d6-\u06dc' +
'\u06dd-\u06df\u06e0-\u06e4\u06e7-\u06e8\u06ea-\u06ed\u0901-\u0903\u093c' +
'\u093e-\u094c\u094d\u0951-\u0954\u0962-\u0963\u0981-\u0983\u09bc\u09be' +
'\u09bf\u09c0-\u09c4\u09c7-\u09c8\u09cb-\u09cd\u09d7\u09e2-\u09e3\u0a02' +
'\u0a3c\u0a3e\u0a3f\u0a40-\u0a42\u0a47-\u0a48\u0a4b-\u0a4d\u0a70-\u0a71' +
'\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0b01-\u0b03' +
'\u0b3c\u0b3e-\u0b43\u0b47-\u0b48\u0b4b-\u0b4d\u0b56-\u0b57\u0b82-\u0b83' +
'\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0c01-\u0c03\u0c3e-\u0c44' +
'\u0c46-\u0c48\u0c4a-\u0c4d\u0c55-\u0c56\u0c82-\u0c83\u0cbe-\u0cc4' +
'\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5-\u0cd6\u0d02-\u0d03\u0d3e-\u0d43' +
'\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1' +
'\u0eb4-\u0eb9\u0ebb-\u0ebc\u0ec8-\u0ecd\u0f18-\u0f19\u0f35\u0f37\u0f39' +
'\u0f3e\u0f3f\u0f71-\u0f84\u0f86-\u0f8b\u0f90-\u0f95\u0f97\u0f99-\u0fad' +
'\u0fb1-\u0fb7\u0fb9\u20d0-\u20dc\u20e1\u302a-\u302f\u3099\u309a' :
'';
var XML10_DIGIT = (REGEXP_UNICODE) ?
'\u0030-\u0039\u0660-\u0669\u06f0-\u06f9\u0966-\u096f\u09e6-\u09ef' +
'\u0a66-\u0a6f\u0ae6-\u0aef\u0b66-\u0b6f\u0be7-\u0bef\u0c66-\u0c6f' +
'\u0ce6-\u0cef\u0d66-\u0d6f\u0e50-\u0e59\u0ed0-\u0ed9\u0f20-\u0f29' :
'0-9';
var XML10_EXTENDER = (REGEXP_UNICODE) ?
'\u00b7\u02d0\u02d1\u0387\u0640\u0e46\u0ec6\u3005\u3031-\u3035' +
'\u309d-\u309e\u30fc-\u30fe' :
'';
var XML10_LETTER = XML10_BASE_CHAR + XML10_IDEOGRAPHIC;
var XML10_NAME_CHAR = XML10_LETTER + XML10_DIGIT + '\\._:' +
XML10_COMBINING_CHAR + XML10_EXTENDER + '-';
var XML10_NAME = '[' + XML10_LETTER + '_:][' + XML10_NAME_CHAR + ']*';
var XML10_ENTITY_REF = '&' + XML10_NAME + ';';
var XML10_REFERENCE = XML10_ENTITY_REF + '|' + XML_CHAR_REF;
var XML10_ATT_VALUE = '"(([^<&"]|' + XML10_REFERENCE + ')*)"|' +
"'(([^<&']|" + XML10_REFERENCE + ")*)'";
var XML10_ATTRIBUTE =
'(' + XML10_NAME + ')' + XML_EQ + '(' + XML10_ATT_VALUE + ')';
// XML 1.1 tokens.
// TODO(jtakagi): NameStartChar also includes \u10000-\ueffff.
// ECMAScript Language Specifiction defines UnicodeEscapeSequence as
// "\u HexDigit HexDigit HexDigit HexDigit" and we may need to use
// surrogate pairs, but any browser doesn't support surrogate paris in
// character classes of regular expression, so avoid including them for now.
var XML11_VERSION_INFO = XML_S + 'version' + XML_EQ + '("1\\.1"|' + "'1\\.1')";
var XML11_NAME_START_CHAR = (REGEXP_UNICODE) ?
':A-Z_a-z\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02ff\u0370-\u037d' +
'\u037f-\u1fff\u200c-\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff' +
'\uf900-\ufdcf\ufdf0-\ufffd' :
':A-Z_a-z';
var XML11_NAME_CHAR = XML11_NAME_START_CHAR +
((REGEXP_UNICODE) ? '\\.0-9\u00b7\u0300-\u036f\u203f-\u2040-' : '\\.0-9-');
var XML11_NAME = '[' + XML11_NAME_START_CHAR + '][' + XML11_NAME_CHAR + ']*';
var XML11_ENTITY_REF = '&' + XML11_NAME + ';';
var XML11_REFERENCE = XML11_ENTITY_REF + '|' + XML_CHAR_REF;
var XML11_ATT_VALUE = '"(([^<&"]|' + XML11_REFERENCE + ')*)"|' +
"'(([^<&']|" + XML11_REFERENCE + ")*)'";
var XML11_ATTRIBUTE =
'(' + XML11_NAME + ')' + XML_EQ + '(' + XML11_ATT_VALUE + ')';
// XML Namespace tokens.
// Used in XML parser and XPath parser.
var XML_NC_NAME_CHAR = XML10_LETTER + XML10_DIGIT + '\\._' +
XML10_COMBINING_CHAR + XML10_EXTENDER + '-';
var XML_NC_NAME = '[' + XML10_LETTER + '_][' + XML_NC_NAME_CHAR + ']*';

File diff suppressed because it is too large Load diff