Java Code Examples for org.jsoup.select.Evaluator#AttributeWithValueEnding
The following examples show how to use
org.jsoup.select.Evaluator#AttributeWithValueEnding .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XPathParser.java From zongtui-webcrawler with GNU General Public License v2.0 | 4 votes |
@Override public Evaluator call(String... param) { Validate.isTrue(param.length == 2, String.format("Error argument of %s", "ends-with")); return new Evaluator.AttributeWithValueEnding(param[0], param[1]); }
Example 2
Source File: XPathParser.java From zongtui-webcrawler with GNU General Public License v2.0 | 4 votes |
private Evaluator byAttribute(XTokenQueue cq) { cq.matchChomp("@"); String key = cq.consumeToAny("=", "!=", "^=", "$=", "*=", "~="); // eq, not, start, end, contain, match, (no val) Validate.notEmpty(key); cq.consumeWhitespace(); Evaluator evaluator; if (cq.isEmpty()) { if ("*".equals(key)) { evaluator = new XEvaluators.HasAnyAttribute(); } else { evaluator = new Evaluator.Attribute(key); } } else { if (cq.matchChomp("=")) { String value = chompEqualValue(cq); //to support select one class out of all if (key.equals("class")) { String className = XTokenQueue.trimQuotes(value); if (!className.contains(" ")) { evaluator = new Evaluator.Class(className); } else { evaluator = new Evaluator.AttributeWithValue(key, className); } } else { evaluator = new Evaluator.AttributeWithValue(key, XTokenQueue.trimQuotes(value)); } } else if (cq.matchChomp("!=")) evaluator = new Evaluator.AttributeWithValueNot(key, XTokenQueue.trimQuotes(chompEqualValue(cq))); else if (cq.matchChomp("^=")) evaluator = new Evaluator.AttributeWithValueStarting(key, XTokenQueue.trimQuotes(chompEqualValue(cq))); else if (cq.matchChomp("$=")) evaluator = new Evaluator.AttributeWithValueEnding(key, XTokenQueue.trimQuotes(chompEqualValue(cq))); else if (cq.matchChomp("*=")) evaluator = new Evaluator.AttributeWithValueContaining(key, XTokenQueue.trimQuotes(chompEqualValue(cq))); else if (cq.matchChomp("~=")) evaluator = new Evaluator.AttributeWithValueMatching(key, Pattern.compile(XTokenQueue.trimQuotes(chompEqualValue(cq)))); else throw new Selector.SelectorParseException("Could not parse attribute query '%s': unexpected token at '%s'", query, chompEqualValue(cq)); } return evaluator; }
Example 3
Source File: XPathParser.java From xsoup with MIT License | 4 votes |
@Override public Evaluator call(String... param) { Validate.isTrue(param.length == 2, String.format("Error argument of %s", "ends-with")); return new Evaluator.AttributeWithValueEnding(param[0], param[1]); }
Example 4
Source File: XPathParser.java From xsoup with MIT License | 4 votes |
private Evaluator byAttribute(XTokenQueue cq) { cq.matchChomp("@"); String key = cq.consumeToAny("=", "!=", "^=", "$=", "*=", "~="); // eq, not, start, end, contain, match, (no val) Validate.notEmpty(key); cq.consumeWhitespace(); Evaluator evaluator; if (cq.isEmpty()) { if ("*".equals(key)) { evaluator = new XEvaluators.HasAnyAttribute(); } else { evaluator = new Evaluator.Attribute(key); } } else { if (cq.matchChomp("=")) { String value = chompEqualValue(cq); //to support select one class out of all if (key.equals("class")) { String className = XTokenQueue.trimQuotes(value); if (!className.contains(" ")) { evaluator = new Evaluator.Class(className); } else { evaluator = new Evaluator.AttributeWithValue(key, className); } } else { evaluator = new Evaluator.AttributeWithValue(key, XTokenQueue.trimQuotes(value)); } } else if (cq.matchChomp("!=")) evaluator = new Evaluator.AttributeWithValueNot(key, XTokenQueue.trimQuotes(chompEqualValue(cq))); else if (cq.matchChomp("^=")) evaluator = new Evaluator.AttributeWithValueStarting(key, XTokenQueue.trimQuotes(chompEqualValue(cq))); else if (cq.matchChomp("$=")) evaluator = new Evaluator.AttributeWithValueEnding(key, XTokenQueue.trimQuotes(chompEqualValue(cq))); else if (cq.matchChomp("*=")) evaluator = new Evaluator.AttributeWithValueContaining(key, XTokenQueue.trimQuotes(chompEqualValue(cq))); else if (cq.matchChomp("~=")) evaluator = new Evaluator.AttributeWithValueMatching(key, Pattern.compile(XTokenQueue.trimQuotes(chompEqualValue(cq)))); else throw new Selector.SelectorParseException("Could not parse attribute query '%s': unexpected token at '%s'", query, chompEqualValue(cq)); } return evaluator; }