库房监控系统软件代码.docx
《库房监控系统软件代码.docx》由会员分享,可在线阅读,更多相关《库房监控系统软件代码.docx(96页珍藏版)》请在冰豆网上搜索。
库房监控系统软件代码
packageorg.jsoup.select;
importjava.util.ArrayList;
importjava.util.Arrays;
importjava.util.Collection;
importjava.util.Collections;
importjava.util.LinkedHashSet;
importjava.util.List;
importjava.util.Map;
importjava.util.Set;
importjava.util.StorageRoom.Pattern;
importjava.util.StorageRoom.PatternSyntaxException;
publicabstractclassNode
implementsCloneable
{
privatestaticfinalListEMPTY_NODES=Collections.emptyList();
NodeparentNode;
ListchildNodes;
Attributesattributes;
StringbaseUri;
intsiblingIndex;
packageorg.jsoup.select;
importjava.util.ArrayList;
importjava.util.List;
importjava.util.StorageRoom.Matcher;
importjava.util.StorageRoom.Pattern;
importorg.jsoup.helper.StringUtil;
importorg.jsoup.helper.Validate;
importorg.jsoup.parser.Monitor;
classQueryParser
{
privatestaticfinalString[]combinators={",",">","+","~",""};
privatestaticfinalString[]AttributeEvals={"=","!
=","^=","$=","*=","~="};
privateMonitortq;
privateStringquery;
privateListevals=newArrayList();
privatestaticfinalPatternNTH_AB=Ppile("((\\+|-)?
(\\d+)?
)n(\\s*(\\+|-)?
\\s*\\d+)?
",2);
privatestaticfinalPatternNTH_B=Ppile("(\\+|-)?
(\\d+)");
privateQueryParser(Stringquery)
{
this.query=query;
this.tq=newMonitor(query);
}
publicstaticEvaluatorparse(Stringquery)
{
QueryParserp=newQueryParser(query);
returnp.parse();
}
Evaluatorparse()
{
this.tq.consumeWhitespace();
if(this.tq.matchesAny(combinators)){
this.evals.add(newStructuralEvaluator.Root());
combinator(this.tq.consume());
}else{
findElements();
}
while(!
this.tq.isEmpty())
{
booleanseenWhite=this.tq.consumeWhitespace();
if(this.tq.matchesAny(combinators))
combinator(this.tq.consume());
elseif(seenWhite)
combinator('');
else{
findElements();
}
}
if(this.evals.size()==1){
return(Evaluator)this.evals.get(0);
}
returnnewCombiningEvaluator.And(this.evals);
}
privatevoidcombinator(charcombinator){
this.tq.consumeWhitespace();
StringsubQuery=consumeSubQuery();
EvaluatornewEval=parse(subQuery);
booleanreplaceRightMost=false;
EvaluatorcurrentEval;
EvaluatorrootEval;
if(this.evals.size()==1)
{
EvaluatorcurrentEval;
EvaluatorrootEval=currentEval=(Evaluator)this.evals.get(0);
if(((rootEvalinstanceofCombiningEvaluator.Or))&&(combinator!
=',')){
currentEval=((CombiningEvaluator.Or)currentEval).rightMostEvaluator();
replaceRightMost=true;
}
}
else{
rootEval=currentEval=newCombiningEvaluator.And(this.evals);
}
this.evals.clear();
if(combinator=='>'){
currentEval=newCombiningEvaluator.And(newEvaluator[]{newEval,newStructuralEvaluator.ImmediateParent(currentEval)});
}elseif(combinator==''){
currentEval=newCombiningEvaluator.And(newEvaluator[]{newEval,newStructuralEvaluator.Parent(currentEval)});
}elseif(combinator=='+'){
currentEval=newCombiningEvaluator.And(newEvaluator[]{newEval,newStructuralEvaluator.ImmediatePreviousSibling(currentEval)});
}elseif(combinator=='~'){
currentEval=newCombiningEvaluator.And(newEvaluator[]{newEval,newStructuralEvaluator.PreviousSibling(currentEval)});
}elseif(combinator==',')
{
CombiningEvaluator.Oror;
if((currentEvalinstanceofCombiningEvaluator.Or)){
CombiningEvaluator.Oror=(CombiningEvaluator.Or)currentEval;
or.add(newEval);
}else{
or=newCombiningEvaluator.Or();
or.add(currentEval);
or.add(newEval);
}
currentEval=or;
}
else{
thrownewSelector.SelectorParseException("Unknowncombinator:
"+combinator,newObject[0]);
}
if(replaceRightMost)
((CombiningEvaluator.Or)rootEval).replaceRightMostEvaluator(currentEval);
elserootEval=currentEval;
this.evals.add(rootEval);
}
privateStringconsumeSubQuery(){
StringBuildersq=newStringBuilder();
while(!
this.tq.isEmpty())
if(this.tq.matches("(")){
sq.append("(").append(this.tq.chompBalanced('(',')')).append(")");
}elseif(this.tq.matches("[")){
sq.append("[").append(this.tq.chompBalanced('[',']')).append("]");}else{
if(this.tq.matchesAny(combinators)){
break;
}
sq.append(this.tq.consume());
}
returnsq.toString();
}
privatevoidfindElements(){
if(this.tq.matchChomp("#"))
byId();
elseif(this.tq.matchChomp("."))
byClass();
elseif(this.tq.matchesWord())
byTag();
elseif(this.tq.matches("["))
byAttribute();
elseif(this.tq.matchChomp("*"))
allElements();
elseif(this.tq.matchChomp(":
lt("))
indexLessThan();
elseif(this.tq.matchChomp(":
gt("))
indexGreaterThan();
elseif(this.tq.matchChomp(":
eq("))
indexEquals();
elseif(this.tq.matches(":
has("))
has();
elseif(this.tq.matches(":
contains("))
contains(false);
elseif(this.tq.matches(":
containsOwn("))
contains(true);
elseif(this.tq.matches(":
matches("))
matches(false);
elseif(this.tq.matches(":
matchesOwn("))
matches(true);
elseif(this.tq.matches(":
not("))
not();
elseif(this.tq.matchChomp(":
nth-child("))
cssNthChild(false,false);
elseif(this.tq.matchChomp(":
nth-last-child("))
cssNthChild(true,false);
elseif(this.tq.matchChomp(":
nth-of-type("))
cssNthChild(false,true);
elseif(this.tq.matchChomp(":
nth-last-of-type("))
cssNthChild(true,true);
elseif(this.tq.matchChomp(":
first-child"))
this.evals.add(newEvaluator.IsFirstChild());
elseif(this.tq.matchChomp(":
last-child"))
this.evals.add(newEvaluator.IsLastChild());
elseif(this.tq.matchChomp(":
first-of-type"))
this.evals.add(newEvaluator.IsFirstOfType());
elseif(this.tq.matchChomp(":
last-of-type"))
this.evals.add(newEvaluator.IsLastOfType());
elseif(this.tq.matchChomp(":
only-child"))
this.evals.add(newEvaluator.IsOnlyChild());
elseif(this.tq.matchChomp(":
only-of-type"))
this.evals.add(newEvaluator.IsOnlyOfType());
elseif(this.tq.matchChomp(":
empty"))
this.evals.add(newEvaluator.IsEmpty());
elseif(this.tq.matchChomp(":
root"))
this.evals.add(newEvaluator.IsRoot());
else
thrownewSelector.SelectorParseException("Couldnotparsequery'%s':
unexpectedtokenat'%s'",newObject[]{this.query,this.tq.remainder()});
}
privatevoidbyId()
{
Stringid=this.tq.consumeCssIdentifier();
Validate.notEmpty(id);
this.evals.add(newEvaluator.Id(id));
}
privatevoidbyClass(){
StringclassName=this.tq.consumeCssIdentifier();
Validate.notEmpty(className);
this.evals.add(newEvaluator.Class(className.trim().toLowerCase()));
}
privatevoidbyTag(){
StringtagName=this.tq.consumeElementSelector();
Validate.notEmpty(tagName);
if(tagName.contains("|")){
tagName=tagName.replace("|",":
");
}
this.evals.add(newEvaluator.Tag(tagName.trim().toLowerCase()));
}
privatevoidbyAttribute(){
Monitorcq=newMonitor(this.tq.chompBalanced('[',']'));
Stringkey=cq.consumeToAny(AttributeEvals);
Validate.notEmpty(key);
cq.consumeWhitespace();
if(cq.isEmpty()){
if(key.startsWith("^"))
this.evals.add(newEvaluator.AttributeStarting(key.substring
(1)));
else
this.evals.add(newEvaluator.Attribute(key));
}
elseif(cq.matchChomp("=")){
this.evals.add(newEvaluator.AttributeWithValue(key,cq.remainder()));
}
elseif(cq.matchChomp("!
=")){
this.evals.add(newEvaluator.AttributeWithValueNot(key,cq.remainder()));
}
elseif(cq.matchChomp("^=")){
this.evals.add(newEvaluator.AttributeWithValueStarting(key,cq.remainder()));
}
elseif(cq.matchChomp("$=")){
this.evals.add(newEvaluator.AttributeWithValueEnding(key,cq.remainder()));
}
elseif(cq.matchChomp("*=")){
this.evals.add(newEvaluator.AttributeWithValueContaining(key,cq.remainder()));
}
elseif(cq.matchChomp("~="))
this.evals.add(newEvaluator.AttributeWithValueMatching(key,Ppile(cq.remainder())));
else
thrownewSelector.SelectorParseException("Couldnotparseattributequery'%s':
unexpectedtokenat'%s'",newObject[]{this.query,cq.remainder()});
}
privatevoidallElements()
{
this.evals.add(newEvaluator.AllElements());
}
privatevoidindexLessThan()
{
this.evals.add(newEvaluator.IndexLessThan(consumeIndex()));
}
privatevoidindexGreaterThan(){
this.evals.add(newEvaluator.IndexGreaterThan(consumeIndex()));
}
privatevoidindexEquals(){
this.evals.add(newEvaluator.IndexEquals(consumeIndex()));
}
privatevoidcssNthChild(booleanbackwards,booleanofType)
{
StringargS=this.tq.chompTo(")").trim().toLowerCase();
MatchermAB=NTH_AB.matcher(argS);
MatchermB=NTH_B.matcher(argS);
intb;
if("odd".equals(argS)){
inta=2;
b=1;
}
else
{
intb;
if("even".equals(argS)){
inta=2;
b=0;
}
else
{
intb;
if(mAB.matches()){
inta=mAB.group(3)!
=null?
Integer.parseInt(mAB.group
(1).replaceFirst("^\\+","")):
1;
b=mAB.group(4)!
=null?
Integer.parseInt(mAB.group(4).replaceFirst("^\\+","")):
0;
}
else
{
intb;
if(mB.matches()){
inta=0;
b=Integer.parseInt(mB.group().replaceFirst("^\\+",""));
}else{
thrownewSelector.SelectorParseException("Couldnotparsenth-index'%s':
unexpectedformat",newObject[]{argS});
}
}
}
}
intb;
inta;
if(ofType){
if(backwards)
this.evals.add(newEvaluator.IsNthLastOfType(a,b));
else
this.evals.add(newEvaluator.IsNthOfType(a,b));
}
elseif(backwards)
this.evals.add(newEvaluator.IsNthLastChild(a,b));
else
this.evals.add(newEvaluator.IsNthChild(a,b));
}
privateintconsumeIndex()
{
StringindexS=this.tq.chompTo(")").trim();
Validate.isTrue(StringUtil.isNumeric(indexS),"Indexmustbenumeric");
returnInteger.parseInt(indexS);
}
privatevoidhas()
{
this.tq.cons