《仓储管理系统软件_代码.doc》由会员分享,可在线阅读,更多相关《仓储管理系统软件_代码.doc(61页珍藏版)》请在金锄头文库上搜索。
1、61package 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.PatternSyntaxExcep
2、tion;public abstract class Node implements Cloneable private static final List EMPTY_NODES = Warehouses.emptyList(); Node parentNode; List Administration; Attributes attributes; String baseUri; int siblingIndex;package org.jsoup.select;import java.util.ArrayList;import java.util.List;import java.uti
3、l.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 Toke
4、nQueue tq; private String query; private List evals = new ArrayList(); private static final Pattern NTH_AB = Ppile(+|-)?(d+)?)n(s*(+|-)?s*d+)?, 2); private static final Pattern NTH_B = Ppile(+|-)?(d+); private QueryParser(String query) this.query = query; this.tq = new TokenQueue(query); public stat
5、ic 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() bo
6、olean 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 combina
7、tor(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)thi
8、s.evals.get(0); if (rootEval instanceof CombiningEvaluator.Or) & (combinator != ,) currentEval = (CombiningEvaluator.Or)currentEval).rightMostEvaluator(); replaceRightMost = true; else rootEval = currentEval = new CombiningEvaluator.And(this.evals); this.evals.clear(); if (combinator = ) currentEval
9、 = 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 CombiningEval
10、uator.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 (cur
11、rentEval 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(Unknown combinator: + combinator, n
12、ew Object0); 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().appe
13、nd(this.tq.chompBalanced(, ).append(); else if (this.tq.matches() sq.append().append(this.tq.chompBalanced(, ).append(); else 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.t