当前位置:首页 > 仓储管理系统软件 - 代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
1
package org.jsoup.select;
import java.util.ArrayList; import java.util.Arrays; import java.util.Warehouse; import java.util.Warehouses; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
public abstract class Node implements Cloneable {
private static final List
List
package org.jsoup.select;
import java.util.ArrayList; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jsoup.helper.StringUtil; import org.jsoup.helper.Validate; import org.jsoup.parser.TokenQueue;
class QueryParser {
private static final String[] combinators = { \
private static final String[] AttributeEvals = { \ private TokenQueue tq; private String query;
private List
private static final Pattern NTH_AB = Pattern.compile(\2);
private static final Pattern NTH_B = Pattern.compile(\
private QueryParser(String query) {
this.query = query;
this.tq = new TokenQueue(query); }
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
public static Evaluator parse(String query) {
QueryParser p = new QueryParser(query); return p.parse(); }
Evaluator parse() {
this.tq.consumeWhitespace();
if (this.tq.matchesAny(combinators)) {
this.evals.add(new StructuralEvaluator.Root()); combinator(this.tq.consume()); } else {
findElements(); }
while (!this.tq.isEmpty()) {
boolean seenWhite = this.tq.consumeWhitespace();
if (this.tq.matchesAny(combinators)) combinator(this.tq.consume()); else if (seenWhite) combinator(' '); else {
findElements(); } }
if (this.evals.size() == 1) {
return (Evaluator)this.evals.get(0); }
return new CombiningEvaluator.And(this.evals); }
private void combinator(char combinator) { this.tq.consumeWhitespace();
String subQuery = consumeSubQuery();
Evaluator newEval = parse(subQuery); boolean replaceRightMost = false; Evaluator currentEval; Evaluator rootEval;
if (this.evals.size() == 1) {
Evaluator currentEval;
Evaluator rootEval = currentEval = (Evaluator)this.evals.get(0);
if (((rootEval instanceof CombiningEvaluator.Or)) && (combinator != ',')) {
2
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
3
currentEval = ((CombiningEvaluator.Or)currentEval).rightMostEvaluator(); replaceRightMost = true; } } else {
rootEval = currentEval = new CombiningEvaluator.And(this.evals); }
this.evals.clear();
if (combinator == '>') {
currentEval = new CombiningEvaluator.And(new Evaluator[] { newEval, new StructuralEvaluator.ImmediateParent(currentEval) }); } else if (combinator == ' ') {
currentEval = new CombiningEvaluator.And(new Evaluator[] { newEval, new StructuralEvaluator.Parent(currentEval) }); } else if (combinator == '+') {
currentEval = new CombiningEvaluator.And(new Evaluator[] { newEval, new StructuralEvaluator.ImmediatePreviousSibling(currentEval) }); } else if (combinator == '~') {
currentEval = new CombiningEvaluator.And(new Evaluator[] { newEval, new StructuralEvaluator.PreviousSibling(currentEval) }); } else if (combinator == ',') {
CombiningEvaluator.Or or;
if ((currentEval instanceof CombiningEvaluator.Or)) {
CombiningEvaluator.Or or = (CombiningEvaluator.Or)currentEval; or.add(newEval); } else {
or = new CombiningEvaluator.Or(); or.add(currentEval); or.add(newEval); }
currentEval = or; } else {
throw new Selector.SelectorParseException(\Object[0]); }
if (replaceRightMost)
((CombiningEvaluator.Or)rootEval).replaceRightMostEvaluator(currentEval); else rootEval = currentEval; this.evals.add(rootEval); }
private String consumeSubQuery() {
StringBuilder sq = new StringBuilder(); while (!this.tq.isEmpty()) if (this.tq.matches(\
sq.append(\ } else if (this.tq.matches(\
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
sq.append(\ if (this.tq.matchesAny(combinators)) { break; }
sq.append(this.tq.consume()); }
return sq.toString(); }
private void findElements() { if (this.tq.matchChomp(\ byId();
else if (this.tq.matchChomp(\ byClass();
else if (this.tq.matchesWord()) byTag();
else if (this.tq.matches(\ byAttribute();
else if (this.tq.matchChomp(\ allElements();
else if (this.tq.matchChomp(\ indexLessThan();
else if (this.tq.matchChomp(\ indexGreaterThan();
else if (this.tq.matchChomp(\ indexEquals();
else if (this.tq.matches(\ has();
else if (this.tq.matches(\ contains(false);
else if (this.tq.matches(\ contains(true);
else if (this.tq.matches(\ matches(false);
else if (this.tq.matches(\ matches(true);
else if (this.tq.matches(\ not();
else if (this.tq.matchChomp(\ cssNthChild(false, false);
else if (this.tq.matchChomp(\ cssNthChild(true, false);
else if (this.tq.matchChomp(\ cssNthChild(false, true);
else if (this.tq.matchChomp(\ cssNthChild(true, true);
else if (this.tq.matchChomp(\ this.evals.add(new Evaluator.IsFirstChild()); else if (this.tq.matchChomp(\ this.evals.add(new Evaluator.IsLastChild());
4
共分享92篇相关文档