PageRenderTime 4ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/src/test/java/org/sigmah/endtoend/xpath/ext/HtmlXPath.java

http://sigma-h.googlecode.com/
Java | 27 lines | 17 code | 6 blank | 4 comment | 1 complexity | 20be5cf678c94780c76cac22337a9787 MD5 | raw file
 1/*
 2 * All Sigmah code is released under the GNU General Public License v3
 3 * See COPYRIGHT.txt and LICENSE.txt.
 4 */
 5
 6package org.sigmah.endtoend.xpath.ext;
 7
 8import org.sigmah.endtoend.xpath.Predicate;
 9import org.sigmah.endtoend.xpath.PredicateLiteral;
10import org.sigmah.endtoend.xpath.XPath;
11
12public class HtmlXPath {
13
14    public static Predicate ofClass(final String className) {
15        return ofClasses(className);
16    }
17
18    public static Predicate ofClasses(String... classNames) {
19        StringBuilder predicate = new StringBuilder("@class");
20        for(String className : classNames) {
21            predicate.append(XPath.format(" and contains(concat(' ', normalize-space(@class), ' '), '%s')",
22                " " + className.trim() + " "));
23        }
24        return new PredicateLiteral(predicate.toString());
25    }
26
27}