/// <summary> /// /// </summary> /// <param name="vn"></param> /// <returns></returns> public override double evalNumber(VTDNav vn) { double d = Double.NaN; int a = 0x7fffffff, k = -1; vn.push2(); int size = vn.contextStack2.size; try { while ((k = evalNodeSet(vn)) != -1) { //a = evalNodeSet(vn); if (k < a) a = k; } if (a == 0x7fffffff) a = -1; if (a != -1) { int t = vn.getTokenType(a); if (t == VTDNav.TOKEN_ATTR_NAME) { d = vn.parseDouble(a + 1); } else if (t == VTDNav.TOKEN_STARTING_TAG || t == VTDNav.TOKEN_DOCUMENT) { d = vn.XPathStringVal2Double(a);//Double.parseDouble(s); } else if (t == VTDNav.TOKEN_PI_NAME) { if (a + 1 < vn.vtdSize || vn.getTokenType(a + 1) == VTDNav.TOKEN_PI_VAL) //s = vn.toString(a+1); d = vn.parseDouble(a + 1); else d = Double.NaN; } else d = vn.parseDouble(a); } } catch (Exception e) { } vn.contextStack2.size = size; reset(vn); vn.pop2(); //return s; return d; }
protected internal int computeContextSize4FollowingSibling(Predicate p, VTDNav vn) { int i=0; //AutoPilot ap = (AutoPilot)currentStep.o; vn.push2(); while(vn.toElement(VTDNav.NEXT_SIBLING)){ if (currentStep.eval(vn,p)){ i++; } } vn.pop2(); currentStep.resetP(vn,p); currentStep.out_of_range=false; //currentStep.o = ap; return i; }
protected internal int computeContextSize4PrecedingSibling2(Predicate p, VTDNav vn) { int i=0; vn.push2(); while(vn.toNode(VTDNav.PREV_SIBLING)){ if (currentStep.eval2(vn,p)){ i++; } } vn.pop2(); currentStep.resetP(vn,p); currentStep.out_of_range=false; //currentStep.o = ap; return i; }
public override System.String evalString(VTDNav vn) { String s = ""; int a = -1; vn.push2(); int size = vn.contextStack2.size; try { a = evalNodeSet(vn); if (a != -1) { int t = vn.getTokenType(a); switch (t) { case VTDNav.TOKEN_STARTING_TAG: case VTDNav.TOKEN_DOCUMENT: s = vn.getXPathStringVal2(a,(short)0); break; case VTDNav.TOKEN_ATTR_NAME: s = vn.toString(a + 1); break; case VTDNav.TOKEN_PI_NAME: //if (a + 1 < vn.vtdSize // || vn.getTokenType(a + 1) == VTDNav.TOKEN_PI_VAL) s = vn.toString(a + 1); break; default: s = vn.toString(a); break; } } } catch (Exception e) { } vn.contextStack2.size = size; reset(vn); vn.pop2(); return s; }
protected internal int computeContextSize4DDFP(Predicate p, VTDNav vn) { String helper = null; int i=0; AutoPilot ap = (AutoPilot)currentStep.o; if (currentStep.nt.testType == NodeTest.NODE){ helper = "*"; }else if (currentStep.nt.testType == NodeTest.NAMETEST){ helper = currentStep.nt.nodeName; }else throw new XPathEvalException("can't run descendant " + "following, or following-sibling axis over comment(), pi(), and text()"); if (ap==null) ap = new AutoPilot(vn); else ap.bind(vn); if (currentStep.axis_type == AxisType.DESCENDANT_OR_SELF0 ) if (currentStep.nt.testType == NodeTest.NODE || helper.Equals("*")) ap.Special=true; else ap.Special=true; //currentStep.o = ap = new AutoPilot(vn); if (currentStep.axis_type == AxisType.DESCENDANT_OR_SELF0) if (currentStep.nt.localName!=null) ap.selectElementNS(currentStep.nt.URL,currentStep.nt.localName); else ap.selectElement(helper); else if (currentStep.axis_type == AxisType.DESCENDANT0) if (currentStep.nt.localName!=null) ap.selectElementNS_D(currentStep.nt.URL,currentStep.nt.localName); else ap.selectElement_D(helper); else if (currentStep.axis_type == AxisType.PRECEDING0) if (currentStep.nt.localName!=null) ap.selectElementNS_P(currentStep.nt.URL,currentStep.nt.localName); else ap.selectElement_P(helper); else if (currentStep.nt.localName!=null) ap.selectElementNS_F(currentStep.nt.URL,currentStep.nt.localName); else ap.selectElement_F(helper); vn.push2(); while(ap.iterate()){ if (currentStep.evalPredicates(vn,p)){ i++; } } vn.pop2(); currentStep.resetP(vn,p); currentStep.out_of_range=false; currentStep.o = ap; return i; }
private int process_preceding_sibling(VTDNav vn) { bool b = false, b1 = false; Predicate t = null; int result; switch (state) { case START: case FORWARD: t = currentStep.p; while (t != null) { if (t.requireContext) { int i = computeContextSize(t, vn); if (i == 0) { b1 = true; break; } else t.ContextSize=(i); } t = t.nextP; } if (b1) { if (state == FORWARD) { state = BACKWARD; currentStep = currentStep.prevS; } else state = END; break; } if (state == START) state = END; else state = BACKWARD; vn.push2(); while (vn.toElement(VTDNav.PS)) { if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; break; } else { state = TERMINAL; result = vn.getCurrentIndex2(); if (isUnique(result)) return result; } } } if(state == END) { if (currentStep.hasPredicate) currentStep.resetP(vn); vn.pop2(); }else if (state == BACKWARD) { if (currentStep.hasPredicate) currentStep.resetP(vn); vn.pop2(); currentStep = currentStep.prevS; } break; case END: currentStep = null; // reset(); return -1; case BACKWARD: if (currentStep.out_of_range) { currentStep.out_of_range = false; transition_preceding_sibling(vn); break; } while (vn.toElement(VTDNav.PS)) { if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; b = true; break; } else { state = TERMINAL; result = vn.getCurrentIndex2(); if (isUnique(result)) return result; } } } if (b == false) { currentStep.out_of_range = false; transition_preceding_sibling(vn); } break; case TERMINAL: if (currentStep.out_of_range) { currentStep.out_of_range = false; transition_preceding_sibling(vn); break; } while (vn.toElement(VTDNav.PS)) { if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { // state = TERMINAL; result = vn.getCurrentIndex2(); if (isUnique(result)) return result; } } currentStep.out_of_range = false; transition_preceding_sibling(vn); break; default: throw new XPathEvalException("unknown state"); } return -2; }
private void transition_preceding_sibling(VTDNav vn) { vn.pop2(); if (currentStep.hasPredicate) currentStep.resetP(vn); if(currentStep.prevS!=null){ currentStep = currentStep.prevS; state = BACKWARD; }else{ state = END; } }
private double sum(VTDNav vn) { double d = 0; /*if (argCount() != 1 || argumentList.e.NodeSet == false) throw new System.ArgumentException("sum()'s argument count is invalid");*/ vn.push2(); try { a = 0; int i1; while ((a = argumentList.e.evalNodeSet(vn)) != -1) { int t = vn.getTokenType(a); if (t == VTDNav.TOKEN_STARTING_TAG) { i1 = vn.getText(); if (i1 != -1) d = d + vn.parseDouble(i1); if (System.Double.IsNaN(d)) break; } else if (t == VTDNav.TOKEN_ATTR_NAME || t == VTDNav.TOKEN_ATTR_NS) { d = d + vn.parseDouble(a + 1); if (System.Double.IsNaN(d)) break; } else if (t == VTDNav.TOKEN_CHARACTER_DATA || t == VTDNav.TOKEN_CDATA_VAL || t == VTDNav.TOKEN_COMMENT) { d = d + vn.parseDouble(a); if (System.Double.IsNaN(d)) break; } else if (t == VTDNav.TOKEN_PI_NAME) { if (a + 1 < vn.vtdSize && vn.getTokenType(a + 1) == VTDNav.TOKEN_PI_VAL) { d += vn.parseDouble(a + 1); } else { d = Double.NaN; break; } } // fib1.append(i); } argumentList.e.reset(vn); vn.pop2(); return d; } catch (System.Exception e) { argumentList.e.reset(vn); vn.pop2(); return System.Double.NaN; } }
/// <summary> /// /// </summary> /// <param name="vn"></param> /// <param name="s"></param> /// <returns></returns> private bool lang(VTDNav vn, String s) { // check the length of s bool b = false; vn.push2(); try { while (vn.getCurrentDepth() >= 0) { int i = vn.getAttrVal("xml:lang"); if (i != -1) { b = vn.matchTokenString(i, s); break; } vn.toElement(VTDNav.P); } } catch (NavException e) { } vn.pop2(); return b; }
/* * (non-Javadoc) * * @see com.ximpleware.xpath.Expr#evalString(com.ximpleware.VTDNav) */ public override System.String evalString(VTDNav vn) { if (e.NodeSet == false) return e.evalString(vn); else { String s = ""; int a = -1; vn.push2(); int size = vn.contextStack2.size; try { a = evalNodeSet(vn); if (a != -1) { int t = vn.getTokenType(a); switch (t) { case VTDNav.TOKEN_STARTING_TAG: case VTDNav.TOKEN_DOCUMENT: s = vn.getXPathStringVal(); break; case VTDNav.TOKEN_ATTR_NAME: s = vn.toString(a + 1); break; case VTDNav.TOKEN_PI_NAME: //if (a + 1 < vn.vtdSize // || vn.getTokenType(a + 1) == VTDNav.TOKEN_PI_VAL) s = vn.toString(a + 1); break; default: s = vn.toString(a); break; } /*if (t == VTDNav.TOKEN_ATTR_NAME) { s = vn.toString(a + 1); } else if (t == VTDNav.TOKEN_STARTING_TAG || t == VTDNav.TOKEN_DOCUMENT) { s = vn.getXPathStringVal(); } else if (t == VTDNav.TOKEN_PI_NAME) { if (a + 1 < vn.vtdSize || vn.getTokenType(a + 1) == VTDNav.TOKEN_PI_VAL) s = vn.toString(a + 1); // s = vn.toString(a+1); } else s = vn.toString(a);*/ } } catch (Exception ee) { } vn.contextStack2.size = size; reset(vn); vn.pop2(); return s; } }
private int count(VTDNav vn) { int a = -1; //if (argCount1 != 1 || argumentList.e.NodeSet == false) // throw new System.ArgumentException("Count()'s argument count is invalid"); vn.push2(); int size = vn.contextStack2.size; try { a = 0; argumentList.e.adjust(vn.getTokenCount()); while (argumentList.e.evalNodeSet(vn) != -1) { a++; } } catch (System.Exception e) { } argumentList.e.reset(vn); vn.contextStack2.size = size; vn.pop2(); return a; }
/// <summary> /// /// </summary> /// <param name="vn"></param> /// <returns></returns> public override int evalNodeSet(VTDNav vn) { int a; /*if (this.next == null) { return e.evalNodeSet(vn); } else {*/ while (true) { switch (state) { case 0: if (ih == null) ih = new intHash(); if (current != null) { vn.push2(); while ((a = current.e.evalNodeSet(vn)) != -1) { if (isUnique(a)) { state = 1; return a; } } state = 2; vn.pop2(); break; } else state = 3; break; case 1: while ((a = current.e.evalNodeSet(vn)) != -1) { if (isUnique(a)) { state = 1; return a; } } state = 2; vn.pop2(); break; case 2: current = current.next; if (current != null) { vn.push2(); while ((a = current.e.evalNodeSet(vn)) != -1) { if (isUnique(a)) { state = 1; return a; } } vn.pop2(); break; } else state = 3; break; case 3: return -1; default: throw new XPathEvalException("Invalid state evaluating PathExpr"); } } // } /* * default: throw new XPathEvalException( "Invalid state evaluating * PathExpr"); */ }
/// <summary> /// /// </summary> /// <param name="vn"></param> /// <returns></returns> public override bool evalBoolean(VTDNav vn) { bool a = false; vn.push2(); // record teh stack size int size = vn.contextStack2.size; try { a = (evalNodeSet(vn) != -1); } catch (System.Exception ee) { } //rewind stack vn.contextStack2.size = size; reset(vn); vn.pop2(); return a; //} /*if (e.Numerical) { double dval = e.evalNumber(vn); if (dval == 0.0 || System.Double.IsNaN(dval)) return false; return true; } String s = e.evalString(vn); if (s == null || s.Length == 0) return false; return true;*/ }
public override int evalNodeSet(VTDNav vn) { int a; while (true) { switch (evalState) { case 0: //this state is teh initial state; a = fe.evalNodeSet(vn); if (a == - 1) { evalState = 4; } else evalState = 1; break; case 1: // fe returns valid value, then iterate the locationPath vn.push2(); a = lpe.evalNodeSet(vn); if (a == - 1) { lpe.reset(vn); evalState = 3; } else { evalState = 2; if (isUnique(a)) return a; } break; case 2: a = lpe.evalNodeSet(vn); if (a == - 1) { lpe.reset(vn); evalState = 3; } else { if (isUnique(a)) return a; //return a; } break; case 3: vn.pop2(); a = fe.evalNodeSet(vn); if (a == - 1) evalState = 4; else { vn.push2(); evalState = 2; } break; case 4: return - 1; default: throw new XPathEvalException("Invalid state evaluating PathExpr"); } } //return -1; }
private int process_namespace(VTDNav vn) { AutoPilot ap = null; bool b1 = false; Predicate t = null; int temp; switch (state) { case START: case FORWARD: t = currentStep.p; while (t != null) { if (t.requireContext) { int i = computeContextSize(t, vn); if (i == 0) { b1 = true; break; } else t.ContextSize=(i); } t = t.nextP; } if (b1) { if (state == FORWARD) { state = BACKWARD; currentStep = currentStep.prevS; } else state = END; break; } if (vn.atTerminal) { if (state == START) state = END; else { state = BACKWARD; currentStep = currentStep.prevS; } } else { if (currentStep.ft) { if (currentStep.o == null) currentStep.o = ap = new AutoPilot(vn); else { ap = (AutoPilot)currentStep.o; ap.bind(vn); //ap.set_ft(true); } if (currentStep.nt.testType == NodeTest.NODE) ap.selectNameSpace("*"); else ap.selectNameSpace(currentStep.nt.nodeName); currentStep.ft = false; } if (state == START) state = END; vn.push2(); //vn.setAtTerminal(true); while ((temp = ap.iterateNameSpace()) != -1) { if ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn)) { break; } } if (temp == -1) { vn.pop2(); currentStep.ft = true; if (currentStep.hasPredicate) currentStep.resetP(vn); vn.atTerminal=(false); if (state == FORWARD) { state = BACKWARD; currentStep = currentStep.prevS; } } else { vn.atTerminal=(true); if (currentStep.nextS != null) { vn.LN = temp; state = FORWARD; currentStep = currentStep.nextS; } else { //vn.pop(); state = TERMINAL; if (isUnique(temp)) { vn.LN = temp; return temp; } } } } break; case END: currentStep = null; // reset(); return -1; case BACKWARD: ap = (AutoPilot)currentStep.o; //vn.push(); while ((temp = ap.iterateNameSpace()) != -1) { if ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn)) { break; } } if (temp == -1) { vn.pop2(); currentStep.ft = true; if (currentStep.hasPredicate) currentStep.resetP(vn); vn.atTerminal=(false); if (currentStep.prevS != null) { state = BACKWARD; currentStep = currentStep.prevS; } else state = END; } else { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; } else { state = TERMINAL; if (isUnique(temp)) { vn.LN = temp; return temp; } } } break; case TERMINAL: ap = (AutoPilot)currentStep.o; while ((temp = ap.iterateNameSpace()) != -1) { if (!currentStep.hasPredicate || currentStep.evalPredicates(vn)) { break; } } if (temp != -1) if (isUnique(temp)) { vn.LN = temp; return temp; } vn.atTerminal=(false); if (currentStep.hasPredicate) currentStep.resetP(vn); if (currentStep.prevS == null) { currentStep.ft = true; vn.pop2(); state = END; } else { state = BACKWARD; vn.pop2(); currentStep.ft = true; currentStep = currentStep.prevS; } break; default: throw new XPathEvalException("unknown state"); } return -2; }
private int evalFirstArgumentListNodeSet(VTDNav vn) { vn.push2(); int size = vn.contextStack2.size; int a = 0x7fffffff, k = -1; try { if (argumentList.e.needReordering) { while ((k = argumentList.e.evalNodeSet(vn)) != -1) { //a = evalNodeSet(vn); if (k < a) a = k; } if (a == 0x7fffffff) a = -1; } else a = argumentList.e.evalNodeSet(vn); if (a != -1) { int t = vn.getTokenType(a); if (t == VTDNav.TOKEN_ATTR_NAME) { a++; } /*else if (t == VTDNav.TOKEN_STARTING_TAG) { a = vn.getText(); }*/ else if (t == VTDNav.TOKEN_PI_NAME) { //if (a + 1 < vn.vtdSize || vn.getTokenType(a + 1) == VTDNav.TOKEN_PI_VAL) a++; //else // a = -1; } } } catch (Exception e) { } vn.contextStack2.size = size; argumentList.e.reset(vn); vn.pop2(); return a; }
private int process_parent(VTDNav vn) { bool b1 = false; Predicate t = null; int result; switch (state) { case START: case FORWARD: t = currentStep.p; while (t != null) { if (t.requireContext) { int i = computeContextSize(t, vn); if (i == 0) { b1 = true; break; } else t.ContextSize=(i); } t = t.nextP; } if (b1) { if (state == FORWARD) { state = BACKWARD; currentStep = currentStep.prevS; } else state = END; break; } if (vn.getCurrentDepth() == -1) { if (state == START) state = END; else { //vn.pop(); state = BACKWARD; currentStep = currentStep.prevS; } } else { vn.push2(); vn.toElement(VTDNav.P); // must return true if ((currentStep.nt_eval || currentStep.nt.eval(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; } else { state = TERMINAL; result = vn.getCurrentIndex2(); if (isUnique(result)) return result; } } else { vn.pop2(); if (currentStep.hasPredicate) currentStep.resetP(vn); if (state == START) state = END; else { state = BACKWARD; currentStep = currentStep.prevS; } } } break; case END: currentStep = null; // reset(); return -1; case BACKWARD: case TERMINAL: if (currentStep.prevS == null) { vn.pop2(); state = END; break; } else { vn.pop2(); state = BACKWARD; currentStep = currentStep.prevS; break; } default: throw new XPathEvalException("unknown state"); } return -2; }
private int evalFirstArgumentListNodeSet2(VTDNav vn) { vn.push2(); int size = vn.contextStack2.size; int a = 0x7ffffff, k = -1; try { if (argumentList.e.needReordering) { while ((k = argumentList.e.evalNodeSet(vn)) != -1) { //a = evalNodeSet(vn); if (k < a) a = k; } if (k == 0x7fffffff) a = -1; } else a = argumentList.e.evalNodeSet(vn); } catch (Exception e) { } vn.contextStack2.size = size; argumentList.e.reset(vn); vn.pop2(); return a; }
private void transition_ancestor_or_self(VTDNav vn) { //currentStep.out_of_range = false; vn.pop2(); if (currentStep.prevS != null) { if (currentStep.hasPredicate) currentStep.resetP(vn); state = BACKWARD; currentStep = currentStep.prevS; } else { state = END; } }
private String getNameSpaceURI(VTDNav vn) { if (argCount1 == 0) { try { int i = vn.getCurrentIndex(); int type = vn.getTokenType(i); if (vn.ns && (type == VTDNav.TOKEN_STARTING_TAG || type == VTDNav.TOKEN_ATTR_NAME)) { int a = vn.lookupNS(); if (a == 0) return ""; else return vn.toString(a); } return ""; } catch (Exception e) { return ""; } } else if (argCount1 == 1 && argumentList.e.NodeSet) { vn.push2(); int size = vn.contextStack2.size; int a = -1; try { a = argumentList.e.evalNodeSet(vn); } catch (Exception e) { } String s = ""; // return a; try { if (a == -1 || vn.ns == false) { } else { int type = vn.getTokenType(a); if (type == VTDNav.TOKEN_STARTING_TAG || type == VTDNav.TOKEN_ATTR_NAME) s = vn.toString(vn.lookupNS()); } } catch (Exception e) { }; vn.contextStack2.size = size; argumentList.e.reset(vn); vn.pop2(); return s; } else throw new System.ArgumentException ("namespace-uri()'s argument count is invalid"); }
public override double evalNumber(VTDNav vn) { double d = Double.NaN; int a = -1; vn.push2(); int size = vn.contextStack2.size; try { a = evalNodeSet(vn); if (a != -1) { int t = vn.getTokenType(a); if (t == VTDNav.TOKEN_ATTR_NAME) { d = vn.parseDouble(a + 1); } else if (t == VTDNav.TOKEN_STARTING_TAG || t == VTDNav.TOKEN_DOCUMENT) { String s = vn.getXPathStringVal(); d = Double.Parse(s); } else if (t == VTDNav.TOKEN_PI_NAME) { if (a + 1 < vn.vtdSize || vn.getTokenType(a + 1) == VTDNav.TOKEN_PI_VAL) d = vn.parseDouble(a + 1); } else d = vn.parseDouble(a); } } catch (Exception e) { } vn.contextStack2.size = size; reset(vn); vn.pop2(); //return s; return d; }
protected internal void transition_DDFP(VTDNav vn) { vn.pop2(); currentStep.ft = true; if (currentStep.hasPredicate) currentStep.resetP(vn); //System.out.println(" --++ pop in //"); if (currentStep.prevS != null) { state = BACKWARD; currentStep = currentStep.prevS; } else state = END; }
protected internal int computeContextSize4AncestorOrSelf2(Predicate p, VTDNav vn) { int i=0; AutoPilot ap = (AutoPilot)currentStep.o; vn.push2(); i = 0; do { if (currentStep.eval2(vn, p)) { i++; } }while(vn.toNode(VTDNav.PARENT)); vn.pop2(); currentStep.resetP(vn,p); currentStep.out_of_range=false; currentStep.o = ap; return i; }
/// <summary> /// /// </summary> /// <param name="p"></param> /// <param name="vn"></param> /// <returns></returns> public int computeContextSize(Predicate p, VTDNav vn) { bool b = false; //Predicate tp = null; int i = 0; AutoPilot ap = (AutoPilot)currentStep.o; switch (currentStep.axis_type) { case AxisType.CHILD0: return computeContextSize4Child(p, vn); case AxisType.CHILD: return computeContextSize4Child2(p, vn); case AxisType.DESCENDANT_OR_SELF0: case AxisType.DESCENDANT0: case AxisType.PRECEDING0: case AxisType.FOLLOWING0: return computeContextSize4DDFP(p, vn); case AxisType.DESCENDANT_OR_SELF: case AxisType.DESCENDANT: case AxisType.PRECEDING: case AxisType.FOLLOWING: return computeContextSize4DDFP2(p, vn); case AxisType.PARENT: return computeContextSize4Parent2(p, vn); case AxisType.ANCESTOR: return computeContextSize4Ancestor2(p, vn); case AxisType.ANCESTOR_OR_SELF: return computeContextSize4AncestorOrSelf2(p, vn); case AxisType.SELF: return computeContextSize4Self2(p, vn); case AxisType.FOLLOWING_SIBLING: return computeContextSize4FollowingSibling2(p, vn); case AxisType.FOLLOWING_SIBLING0: return computeContextSize4FollowingSibling(p, vn); case AxisType.PRECEDING_SIBLING: return computeContextSize4PrecedingSibling2(p, vn); case AxisType.PRECEDING_SIBLING0: return computeContextSize4PrecedingSibling(p, vn); case AxisType.ATTRIBUTE: if (ap == null) ap = new AutoPilot(vn); else ap.bind(vn); if (currentStep.nt.testType == NodeTest.NODE) ap.selectAttr("*"); else if (currentStep.nt.localName != null) ap.selectAttrNS(currentStep.nt.URL, currentStep.nt.localName); else ap.selectAttr(currentStep.nt.nodeName); i = 0; while (ap.iterateAttr2() != -1) { if (currentStep.evalPredicates(vn, p)) { i++; } } currentStep.resetP(vn, p); currentStep.o = ap; return i; case AxisType.NAMESPACE: if (ap == null) ap = new AutoPilot(vn); else ap.bind(vn); if (currentStep.nt.testType == NodeTest.NODE) ap.selectNameSpace("*"); else ap.selectNameSpace(currentStep.nt.nodeName); i = 0; vn.push2(); while (ap.iterateNameSpace() != -1) { if (currentStep.evalPredicates(vn, p)) { i++; } } vn.pop2(); currentStep.resetP(vn, p); currentStep.o = ap; return i; default: throw new XPathEvalException("axis not supported"); } //return 8; //return 8; }
protected internal int computeContextSize4DDFP2(Predicate p, VTDNav vn) { int i=0; AutoPilot ap = (AutoPilot)currentStep.o; if (ap==null) ap = new AutoPilot(vn); else ap.bind(vn); //currentStep.o = ap = new AutoPilot(vn); if (currentStep.axis_type == AxisType.DESCENDANT_OR_SELF) ap.selectNode(); else if (currentStep.axis_type == AxisType.DESCENDANT) ap.selectDescendantNode(); else if (currentStep.axis_type == AxisType.PRECEDING) ap.selectPrecedingNode(); else ap.selectFollowingNode(); vn.push2(); while(ap.iterate2()){ if (currentStep.eval2(vn,p)){ i++; } } vn.pop2(); currentStep.resetP(vn,p); currentStep.out_of_range=false; currentStep.o = ap; return i; }
private int process_DDFP(VTDNav vn) { AutoPilot ap; bool b = false, b1 = false; Predicate t = null; int result; switch (state) { case START: case FORWARD: t = currentStep.p; while (t != null) { if (t.requireContext) { int i = computeContextSize(t, vn); if (i == 0) { b1 = true; break; } else t.ContextSize=(i); } t = t.nextP; } if (b1) { if (state == START) state = END; else { currentStep = currentStep.prevS; state = BACKWARD; } break; } String helper = null; if (currentStep.nt.testType == NodeTest.NAMETEST) { helper = currentStep.nt.nodeName; } else if (currentStep.nt.testType == NodeTest.NODE) { helper = "*"; } else throw new XPathEvalException("can't run descendant " + "following, or following-sibling axis over comment(), pi(), and text()"); if (currentStep.o == null) currentStep.o = ap = new AutoPilot(vn); else { ap = (AutoPilot)currentStep.o; ap.bind(vn); } if (currentStep.ft) { if (currentStep.axis_type == AxisType.DESCENDANT_OR_SELF0) if (currentStep.nt.testType == NodeTest.NODE || helper.Equals("*")) ap.Special=(true); else ap.Special=(false); //currentStep.o = ap = new AutoPilot(vn); if (currentStep.axis_type == AxisType.DESCENDANT_OR_SELF0) ap.selectElement(helper); else if (currentStep.axis_type == AxisType.DESCENDANT0) ap.selectElement_D(helper); else if (currentStep.axis_type == AxisType.PRECEDING0) ap.selectElement_P(helper); else ap.selectElement_F(helper); currentStep.ft = false; } if (state == START) state = END; vn.push2(); // not the most efficient. good for now //System.out.println(" --++ push in //"); b = false; while (ap.iterate()) { if (!currentStep.hasPredicate || currentStep.evalPredicates(vn)) { b = true; break; } } if (b == false) { vn.pop2(); //System.out.println(" --++ pop in //"); currentStep.ft = true; if (currentStep.hasPredicate) currentStep.resetP(vn); if (state == FORWARD) { state = BACKWARD; currentStep = currentStep.prevS; } } else { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; } else { //vn.pop(); state = TERMINAL; result = vn.getCurrentIndex2(); if (isUnique(result)) return result; } } break; case END: currentStep = null; // reset(); return -1; case BACKWARD: //currentStep = currentStep.prevS; if (currentStep.out_of_range) { currentStep.out_of_range = false; transition_DDFP(vn); break; } ap = (AutoPilot)currentStep.o; //vn.push(); //b = false; while (ap.iterate()) { if (!currentStep.hasPredicate || currentStep.evalPredicates(vn)) { b = true; break; } } if (b) { //if (currentStep.nextS != null) //{ //vn.push(); //System.out.println(" --++ push in //"); state = FORWARD; currentStep = currentStep.nextS; //} //else //{ // state = TERMINAL; // result = vn.getCurrentIndex(); // if (isUnique(result)) // return result; //} } else { currentStep.out_of_range = false; transition_DDFP(vn); } break; case TERMINAL: if (currentStep.out_of_range) { currentStep.out_of_range = false; transition_DDFP(vn); break; } ap = (AutoPilot)currentStep.o; b = false; while (ap.iterate()) { if (!currentStep.hasPredicate || currentStep.evalPredicates(vn)) { b = true; break; } } if (b) { //if (currentStep.evalPredicates(vn)) { result = vn.getCurrentIndex2(); if (isUnique(result)) return result; //} } else { currentStep.out_of_range = false; transition_DDFP(vn); } break; default: throw new XPathEvalException("unknown state"); } return -2; }
protected internal int computeContextSize4Parent(Predicate p, VTDNav vn) { int i=0; AutoPilot ap = (AutoPilot)currentStep.o; vn.push2(); i = 0; if (vn.toElement(VTDNav.PARENT)){ if (currentStep.eval(vn,p)){ i++; } } vn.pop2(); currentStep.resetP(vn,p); currentStep.out_of_range=false; currentStep.o = ap; return i; }
public override bool evalBoolean(VTDNav vn) { bool a = false; vn.push2(); // record stack size int size = vn.contextStack2.size; try { a = (evalNodeSet(vn) != -1); } catch (System.Exception e) { } //rewind stack vn.contextStack2.size = size; reset(vn); vn.pop2(); return a; }
protected internal int process_ancestor2( VTDNav vn) { int result; bool b = false, b1 = false; //int contextSize; Predicate t= null; switch(state){ case START: t = currentStep.p; while (t != null) { if (t.requireContext) { int i = computeContextSize( t, vn); if (i == 0) { b1 = true; break; } else t.ContextSize=(i); } t = t.nextP; } if (b1) { state = END; break; } state = END; //if (vn.getCurrentDepth() != -1) { vn.push2(); while (vn.toNode(VTDNav.P)) { if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS != null) { state = FORWARD; currentStep = currentStep.nextS; break; } else { //vn.pop(); state = TERMINAL; result = vn.getCurrentIndex2(); if (isUnique(result)) return result; } } } if (state == END) { if (currentStep.hasPredicate) currentStep.resetP(vn); vn.pop2(); } // } break; case END: currentStep =null; // reset(); return -1; case FORWARD: t = currentStep.p; while(t!=null){ if (t.requireContext){ int i = computeContextSize(t,vn); if (i==0){ b1 = true; break; }else t.ContextSize=(i); } t = t.nextP; } if (b1){ currentStep = currentStep.prevS; state = BACKWARD; break; } state = BACKWARD; vn.push2(); while(vn.toNode(VTDNav.P)){ if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))){ if (currentStep.nextS != null){ state = FORWARD; currentStep = currentStep.nextS; break; } else { //vn.pop(); state = TERMINAL; result = vn.getCurrentIndex2(); if ( isUnique(result)) return result; } } } if ( state == BACKWARD){ if (currentStep.hasPredicate) currentStep.resetP(vn); vn.pop2(); currentStep=currentStep.prevS; } break; case BACKWARD: b = false; //vn.push2(); if (currentStep.out_of_range) { currentStep.out_of_range = false; transition_ancestor(vn); break; } while (vn.toNode(VTDNav.P)) { if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { if (currentStep.nextS!= null) { state = FORWARD; currentStep = currentStep.nextS; b = true; break; } else { //vn.pop(); state = TERMINAL; result = vn.getCurrentIndex2(); if ( isUnique(result)) return result; } } } if (b==false){ currentStep.out_of_range = false; transition_ancestor(vn); } break; case TERMINAL: if (currentStep.out_of_range) { currentStep.out_of_range = false; transition_ancestor(vn); break; } while (vn.toNode(VTDNav.P)) { if ((currentStep.nt_eval || currentStep.nt.eval2(vn)) && ((!currentStep.hasPredicate) || currentStep.evalPredicates(vn))) { result = vn.getCurrentIndex2(); if ( isUnique(result)) return result; } } currentStep.out_of_range = false; transition_ancestor(vn); break; default: throw new XPathEvalException("unknown state"); } return -2; }
public override System.String evalString(VTDNav vn) { String s = ""; int a = 0x7fffffff, k = -1; vn.push2(); int size = vn.contextStack2.size; try { //a = evalNodeSet(vn); if (needReordering) { while ((k = evalNodeSet(vn)) != -1) { // a = evalNodeSet(vn); if (k < a) a = k; } if (a == 0x7fffffff) a = -1; } else { a = evalNodeSet(vn); } if (a != -1) { int t = vn.getTokenType(a); switch (t) { case VTDNav.TOKEN_STARTING_TAG: case VTDNav.TOKEN_DOCUMENT: s = vn.getXPathStringVal(); break; case VTDNav.TOKEN_ATTR_NAME: s = vn.toString(a + 1); break; case VTDNav.TOKEN_PI_NAME: //if (a + 1 < vn.vtdSize // || vn.getTokenType(a + 1) == VTDNav.TOKEN_PI_VAL) s = vn.toString(a + 1); break; default: s = vn.toString(a); break; } } } catch (Exception e) { } vn.contextStack2.size = size; reset(vn); vn.pop2(); return s; }