diff options
author | Benjamin Jones <bjones@galois.com> | 2012-12-13 11:05:29 -0800 |
---|---|---|
committer | Benjamin Jones <bjones@galois.com> | 2012-12-13 11:05:29 -0800 |
commit | ca1e7ebf451c14c1e921f9666652bed92a487eec (patch) | |
tree | 07caa2781688d12ae387513015359c007e8b5a48 /contexts/data/fiveui | |
parent | 50bb191e68c134556daa3ce714b1a81d84b40095 (diff) |
added xpath calculation
Diffstat (limited to 'contexts/data/fiveui')
-rw-r--r-- | contexts/data/fiveui/injected/fiveui-injected-compute.js | 75 |
1 files changed, 74 insertions, 1 deletions
diff --git a/contexts/data/fiveui/injected/fiveui-injected-compute.js b/contexts/data/fiveui/injected/fiveui-injected-compute.js index b6a814f..2d35312 100644 --- a/contexts/data/fiveui/injected/fiveui-injected-compute.js +++ b/contexts/data/fiveui/injected/fiveui-injected-compute.js @@ -93,7 +93,8 @@ name: name, descr: rule.description, url: window.location.href, - severity: 1 + severity: 1, + xpath: core.getElementXPath(node) }; var nodeParents = function(node) { @@ -122,6 +123,78 @@ return prob; }; + /* The next two methods are provided under the following license: */ + /* Software License Agreement (BSD License) + + Copyright (c) 2007, Parakey Inc. + All rights reserved. + + Redistribution and use of this software in source and binary forms, with or without modification, + are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above + copyright notice, this list of conditions and the + following disclaimer. + + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other + materials provided with the distribution. + + * Neither the name of Parakey Inc. nor the names of its + contributors may be used to endorse or promote products + derived from this software without specific prior + written permission of Parakey Inc. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + /** + * Gets an XPath for an element which describes its hierarchical location. + */ + core.getElementXPath = function(element) + { + if (element && element.id) + return '//*[@id="' + element.id + '"]'; + else + return core.getElementTreeXPath(element); + }; + + core.getElementTreeXPath = function(element) + { + var paths = []; + + // Use nodeName (instead of localName) so namespace prefix is included (if any). + for (; element && element.nodeType == 1; element = element.parentNode) + { + var index = 0; + for (var sibling = element.previousSibling; sibling; sibling = sibling.previousSibling) + { + // Ignore document type declaration. + if (sibling.nodeType == Node.DOCUMENT_TYPE_NODE) + continue; + + if (sibling.nodeName == element.nodeName) + ++index; + } + + var tagName = element.nodeName.toLowerCase(); + var pathIndex = (index ? "[" + (index+1) + "]" : ""); + paths.splice(0, 0, tagName + pathIndex); + } + + return paths.length ? "/" + paths.join("/") : null; + }; + + /* END of BSD licensed code */ + core.evaluate = function(rs) { var i; var theRule = null; |