Exemplo n.º 1
0
        /*public int getPositon(){
         * return fib.size_Renamed_Field;
         * }*/
        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);
        }
Exemplo n.º 2
0
        private int getStringVal(VTDNav vn, int i)
        {
            int i1, t = vn.getTokenType(i);

            if (t == VTDNav.TOKEN_STARTING_TAG)
            {
                i1 = vn.getText();
                return(i1);
            }
            else if (t == VTDNav.TOKEN_ATTR_NAME ||
                     t == VTDNav.TOKEN_ATTR_NS || t == VTDNav.TOKEN_PI_NAME)
            {
                return(i + 1);
            }
            else /*if (t == VTDNav.TOKEN_CHARACTER_DATA
                 || t == VTDNav.TOKEN_CDATA_VAL)
                 || return i;*/
            {
                return(i);
            }
        }
Exemplo n.º 3
0
        public override double evalNumber(VTDNav vn)
        {
            switch (op)
            {
            case ADD: return(left.evalNumber(vn) + right.evalNumber(vn));

            case SUB: return(left.evalNumber(vn) - right.evalNumber(vn));

            case MULT: return(left.evalNumber(vn) * right.evalNumber(vn));

            case DIV: return(left.evalNumber(vn) / right.evalNumber(vn));

            case MOD: return(left.evalNumber(vn) % right.evalNumber(vn));

            default: if (evalBoolean(vn) == true)
                {
                    return(1);
                }
                return(0);
            }
        }
Exemplo n.º 4
0
 private System.String subStringBefore(VTDNav vn)
 {
     if (argCount() == 2)
     {
         String s1   = argumentList.e.evalString(vn);
         String s2   = argumentList.next.e.evalString(vn);
         int    len1 = s1.Length;
         int    len2 = s2.Length;
         for (int i = 0; i < len1; i++)
         {
             //System.String.Compare(s1,i,s2,0,len2);
             if (System.String.Compare(s1, i, s2, 0, len2) == 0)
             {
                 return(s1.Substring(0, i));
             }
         }
         return("");
     }
     throw new System.ArgumentException
               ("substring-after()'s argument count is invalid");
 }
Exemplo n.º 5
0
        public override double evalNumber(VTDNav vn)
        {
            int a = -1;

            vn.push2();
            int size = vn.contextStack2.size;

            try
            {
                a = evalNodeSet(vn);
                if (a != -1)
                {
                    if (vn.getTokenType(a) == VTDNav.TOKEN_ATTR_NAME)
                    {
                        a++;
                    }
                    else if (vn.getTokenType(a) == VTDNav.TOKEN_STARTING_TAG)
                    {
                        a = vn.getText();
                    }
                }
            }
            catch (System.Exception e)
            {
            }
            vn.contextStack2.size = size;
            reset(vn);
            vn.pop2();
            try
            {
                if (a != -1)
                {
                    return(vn.parseDouble(a));
                }
            }
            catch (NavException e)
            {
            }
            return(System.Double.NaN);
        }
Exemplo n.º 6
0
 private System.String subString(VTDNav vn)
 {
     if (argCount() == 2)
     {
         System.String s = argumentList.e.evalString(vn);
         if (s != null)
         {
             //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
             //s.Substring((int)argumentList.next.e.evalNumber(vn)+1);
             double d1 = Math.Floor(argumentList.next.e.evalNumber(vn) + 0.5d);
             if (d1 != d1 || d1 > s.Length)
             {
                 return("");
             }
             return(s.Substring(Math.Max((int)(d1 - 1), 0)));
         }
         return(null);
     }
     else if (argCount() == 3)
     {
         System.String s = argumentList.e.evalString(vn);
         if (s != null)
         {
             // double d1 = argumentList.next.next.e.evalNumber(vn);
             // double d2 = argumentList.next.e.evalNumber(vn);
             double d1 = Math.Floor(argumentList.next.e.evalNumber(vn) + 0.5d);
             double d2 = Math.Floor(argumentList.next.next.e.evalNumber(vn) + 0.5d);
             int    i  = Math.Max(0, (int)d1 - 1);
             if ((d1 + d2) != (d1 + d2) || d1 > s.Length)
             {
                 return("");
             }
             return(s.Substring(i, Math.Min(s.Length, (int)d2 - 1 + (int)d1) - i));
             //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
             //s.Substring((int)d1-1, ((int)d1) - ((int)d2));
         }
         return(null);
     }
     throw new System.ArgumentException("substring()'s argument count is invalid");
 }
Exemplo n.º 7
0
        public override System.String evalString(VTDNav vn)
        {
            vn.push2();
            int size = vn.contextStack2.size;
            int a    = -1;

            try
            {
                a = evalNodeSet(vn);
                if (a != -1)
                {
                    if (vn.getTokenType(a) == VTDNav.TOKEN_ATTR_NAME)
                    {
                        a++;
                    }
                    if (vn.getTokenType(a) == VTDNav.TOKEN_STARTING_TAG)
                    {
                        a = vn.getText();
                    }
                }
            }
            catch (System.Exception e)
            {
            }
            vn.contextStack2.size = size;
            reset(vn);
            vn.pop2();
            try
            {
                if (a != -1)
                {
                    return(vn.toString(a));
                }
            }
            catch (NavException e)
            {
            }
            return("");
        }
Exemplo n.º 8
0
 /// <summary> bind a BookMark object to a VTDNav object
 /// the cursor position is set to an invalid state
 /// </summary>
 /// <param name="vn">*
 /// </param>
 public void bind(VTDNav vn)
 {
     if (vn == null)
     {
         throw new System.ArgumentException("vn can't be null");
     }
     vn1 = vn;
     if (vn.shallowDepth)
     {
         if (ba == null || vn.nestingLevel + 8 != ba.Length)
         {
             ba = new int[vn.nestingLevel + 8];
         }
     }
     else
     {
         if (ba == null || vn.nestingLevel + 14 != ba.Length)
         {
             ba = new int[vn.nestingLevel + 14];
         }
     }
     ba[0] = -2; // this would never happen in a VTDNav obj's context
 }
Exemplo n.º 9
0
 public bool eval(VTDNav vn)
 {
     if (testType == NODE)
     {
         return(true);
     }
     else if (testType == NAMETEST)
     {
         if (vn.atTerminal == true)
         {
             return(false);
         }
         if (localName != null)
         {
             return(vn.matchElementNS(URL, localName));
         }
         else
         {
             return(vn.matchElement(nodeName));
         }
     }
     return(false);
 }
Exemplo n.º 10
0
        /// <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;*/
        }
Exemplo n.º 11
0
        /// <summary> Obtain the current navigation position and element info from VTDNav.
        /// So one can instantiate it once and use it for many different elements
        /// Creation date: (12/5/03 6:20:44 PM)
        /// </summary>
        /// <param name="vn">com.ximpleware.VTDNav
        /// </param>
        public void touch(VTDNav v)
        {
            if (v == null)
            {
                throw new System.ArgumentException(" VTDNav instance can't be null");
            }

            depth = v.context[0];
            if (depth == -1)
            {
                index = 0;
            }
            else
            {
                index = (depth != 0) ? v.context[depth] : v.rootIndex;
            }


            vn           = v;
            prevLocation = -1;
            lcIndex      = -1;
            lcUpper      = -1;
            lcLower      = -1;
        }
Exemplo n.º 12
0
 public override double evalNumber(VTDNav vn)
 {
     // TODO Auto-generated method stub
     return exprVal.evalNumber(vn);
 }
Exemplo n.º 13
0
 public override int evalNodeSet(VTDNav vn)
 {
     // TODO Auto-generated method stub
     return exprVal.evalNodeSet(vn);
 }
Exemplo n.º 14
0
        public override double evalNumber(VTDNav vn)
        {
            int ac = 0;

            switch (opCode)
            {
            case FuncName.LAST:  if (argCount() != 0)
                {
                    throw new System.ArgumentException("floor()'s argument count is invalid");
                }
                return(contextSize);

            case FuncName.POSITION:  if (argCount() != 0)
                {
                    throw new System.ArgumentException("position()'s argument count is invalid");
                }
                return(position);

            case FuncName.COUNT:  return(count(vn));

            case FuncName.NUMBER:  if (argCount() != 1)
                {
                    throw new System.ArgumentException("number()'s argument count is invalid");
                }
                return(argumentList.e.evalNumber(vn));


            case FuncName.SUM:  return(sum(vn));

            case FuncName.FLOOR:  if (argCount() != 1)
                {
                    throw new System.ArgumentException("floor()'s argument count is invalid");
                }
                return(System.Math.Floor(argumentList.e.evalNumber(vn)));


            case FuncName.CEILING:  if (argCount() != 1)
                {
                    throw new System.ArgumentException("ceiling()'s argument count is invalid");
                }
                return(System.Math.Ceiling(argumentList.e.evalNumber(vn)));


            case FuncName.STRING_LENGTH:
                ac = argCount();
                if (ac == 0)
                {
                    try
                    {
                        if (vn.atTerminal == true)
                        {
                            int type = vn.getTokenType(vn.LN);
                            if (type == VTDNav.TOKEN_ATTR_NAME || type == VTDNav.TOKEN_ATTR_NS)
                            {
                                return(vn.getStringLength(vn.LN + 1));
                            }
                            else
                            {
                                return(vn.getStringLength(vn.LN));
                            }
                        }
                        else
                        {
                            int i = vn.getText();
                            if (i == -1)
                            {
                                return(0);
                            }
                            else
                            {
                                return(vn.getStringLength(i));
                            }
                        }
                    }
                    catch (NavException e)
                    {
                        return(0);
                    }
                }
                else if (ac == 1)
                {
                    return(argumentList.e.evalString(vn).Length);
                }
                else
                {
                    throw new System.ArgumentException("string-length()'s argument count is invalid");
                }
            //goto case FuncName.ROUND;


            case FuncName.ROUND:  if (argCount() != 1)
                {
                    throw new System.ArgumentException("round()'s argument count is invalid");
                }
                //UPGRADE_TODO: Method 'java.lang.Math.round' was converted to 'System.Math.Round' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javalangMathround_double'"
                return((long)System.Math.Round(argumentList.e.evalNumber(vn)));


            default:  if (isBoolean_Renamed_Field)
                {
                    if (evalBoolean(vn))
                    {
                        return(1);
                    }
                    else
                    {
                        return(0);
                    }
                }
                else
                {
                    return(System.Double.Parse(evalString(vn)));
                }
                //break;
            }
        }
Exemplo n.º 15
0
 public void  reset(VTDNav vn)
 {
     ft = true;
     resetP(vn);
     position = 1;
 }
Exemplo n.º 16
0
 public void  reset(VTDNav vn)
 {
     count = 0;
     expr.reset(vn);             // is this really needed?
 }
Exemplo n.º 17
0
 public override void  reset(VTDNav vn)
 {
 }
Exemplo n.º 18
0
 public override int evalNodeSet(VTDNav vn)
 {
     throw new XPathEvalException("LiteralExpr can't eval to a node set!");
 }
Exemplo n.º 19
0
 abstract public void reset(VTDNav vn);
Exemplo n.º 20
0
        private String getLocalName(VTDNav vn)
        {
            if (argCount() == 0)
            {
                try
                {
                    int index = vn.getCurrentIndex();
                    int type  = vn.getTokenType(index);
                    if (vn.ns && (type == VTDNav.TOKEN_STARTING_TAG ||
                                  type == VTDNav.TOKEN_ATTR_NAME))
                    {
                        long offset = vn.getTokenOffset(index);
                        int  length = vn.getTokenLength(index);
                        if (length < 0x10000)
                        {
                            return(vn.toRawString(index));
                        }
                        else
                        {
                            int preLen = length >> 16;
                            int QLen   = length & 0xffff;
                            if (preLen != 0)
                            {
                                return(vn.toRawString(offset + preLen + 1, QLen
                                                      - preLen - 1));
                            }
                            else
                            {
                                return(vn.toRawString(offset, QLen));
                            }
                        }
                    }
                    else
                    {
                        return("");
                    }
                }
                catch (NavException e)
                {
                    return(""); // this will almost never occur
                }
            }
            else if (argCount() == 1)
            {
                int a = -1;
                vn.push2();
                try
                {
                    a = argumentList.e.evalNodeSet(vn);
                    argumentList.e.reset(vn);
                    vn.pop2();
                }
                catch (Exception e)
                {
                    argumentList.e.reset(vn);
                    vn.pop2();
                }

                if (a == -1 || vn.ns == false)
                {
                    return("");
                }
                int type = vn.getTokenType(a);
                if (type != VTDNav.TOKEN_STARTING_TAG && type != VTDNav.TOKEN_ATTR_NAME)
                {
                    return("");
                }
                try
                {
                    long offset = vn.getTokenOffset(a);
                    int  length = vn.getTokenLength(a);
                    if (length < 0x10000)
                    {
                        return(vn.toRawString(a));
                    }
                    else
                    {
                        int preLen = length >> 16;
                        int QLen   = length & 0xffff;
                        if (preLen != 0)
                        {
                            return(vn.toRawString(offset + preLen + 1,
                                                  QLen - preLen - 1));
                        }
                        else
                        {
                            return(vn.toRawString(offset, QLen));
                        }
                    }
                }
                catch (NavException e)
                {
                    return(""); // this will almost never occur
                }
            }
            else
            {
                throw new System.ArgumentException
                          ("local-name()'s argument count is invalid");
            }
        }
Exemplo n.º 21
0
 private bool contains(VTDNav vn)
 {
     System.String s1 = argumentList.e.evalString(vn);
     System.String s2 = argumentList.next.e.evalString(vn);
     return(s1.Contains(s2));
 }
Exemplo n.º 22
0
 private bool startsWith(VTDNav vn)
 {
     System.String s1 = argumentList.e.evalString(vn);
     System.String s2 = argumentList.next.e.evalString(vn);
     return(s1.StartsWith(s2));
 }
Exemplo n.º 23
0
        public override bool evalBoolean(VTDNav vn)
        {
            switch (opCode)
            {
            case FuncName.STARTS_WITH:
                if (argCount() != 2)
                {
                    throw new System.ArgumentException("starts-with()'s argument count is invalid");
                }
                return(startsWith(vn));

            case FuncName.CONTAINS:
                if (argCount() != 2)
                {
                    throw new System.ArgumentException("contains()'s argument count is invalid");
                }
                return(contains(vn));

            case FuncName.TRUE:  if (argCount() != 0)
                {
                    throw new System.ArgumentException("true() doesn't take any argument");
                }
                return(true);

            case FuncName.FALSE:  if (argCount() != 0)
                {
                    throw new System.ArgumentException("false() doesn't take any argument");
                }
                return(false);

            case FuncName.BOOLEAN:  if (argCount() != 1)
                {
                    throw new System.ArgumentException("boolean() doesn't take any argument");
                }
                return(argumentList.e.evalBoolean(vn));

            case FuncName.NOT:  if (argCount() != 1)
                {
                    throw new System.ArgumentException("not() doesn't take any argument");
                }
                return(!argumentList.e.evalBoolean(vn));

            case FuncName.LANG:
                if (argCount() != 1)
                {
                    throw new System.ArgumentException("lang()'s argument count is invalid");
                }
                return(lang(vn, argumentList.e.evalString(vn)));

            default:  if (Numerical)
                {
                    double d = evalNumber(vn);
                    if (d == 0 || Double.IsNaN(d))
                    {
                        return(false);
                    }
                    return(true);
                }
                else
                {
                    return(evalString(vn).Length != 0);
                }
                //break;
            }
        }
Exemplo n.º 24
0
 public override int evalNodeSet(VTDNav vn)
 {
     throw new XPathEvalException(" Function Expr can't eval to node set ");
 }
Exemplo n.º 25
0
 public override String evalString(VTDNav vn)
 {
     // TODO Auto-generated method stub
     return exprVal.evalString(vn);
 }
Exemplo n.º 26
0
 public override void reset(VTDNav vn)
 {
     // TODO Auto-generated method stub
     exprVal.reset(vn);
 }
Exemplo n.º 27
0
        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;
        }
Exemplo n.º 28
0
 public override System.String evalString(VTDNav vn)
 {
     return(s);
 }
Exemplo n.º 29
0
 abstract public System.String evalString(VTDNav vn);
Exemplo n.º 30
0
 public override bool evalBoolean(VTDNav vn)
 {
     return(s.Length != 0);
 }
Exemplo n.º 31
0
 public void  reset2(VTDNav vn)
 {
     e.reset(vn);
     p.reset(vn);
     //fib.clear();
 }
Exemplo n.º 32
0
 abstract public int evalNodeSet(VTDNav vn);
Exemplo n.º 33
0
 public override bool evalBoolean(VTDNav vn)
 {
     // TODO Auto-generated method stub
     return exprVal.evalBoolean(vn);
 }
Exemplo n.º 34
0
 public bool eval(VTDNav vn, Predicate p)
 {
     return(nt.eval(vn) && evalPredicates(vn, p));
 }
Exemplo n.º 35
0
        private String getName(VTDNav vn)
        {
            int a;

            if (argCount() == 0)
            {
                a = vn.getCurrentIndex();
                int type = vn.getTokenType(a);

                if ((type == VTDNav.TOKEN_STARTING_TAG ||
                     type == VTDNav.TOKEN_ATTR_NAME))
                {
                    try
                    {
                        return(vn.toString(a));
                    }
                    catch (Exception e)
                    {
                        return("");
                    }
                }
                else
                {
                    return("");
                }
            }
            else if (argCount() == 1)
            {
                a = -1;
                vn.push2();
                try
                {
                    a = argumentList.e.evalNodeSet(vn);
                    argumentList.e.reset(vn);
                    vn.pop2();
                }
                catch (Exception e)
                {
                    argumentList.e.reset(vn);
                    vn.pop2();
                }
                try
                {
                    if (a == -1 || vn.ns == false)
                    {
                        return("");
                    }
                    else
                    {
                        int type = vn.getTokenType(a);
                        if (type == VTDNav.TOKEN_STARTING_TAG ||
                            type == VTDNav.TOKEN_ATTR_NAME)
                        {
                            return(vn.toString(a));
                        }
                        return("");
                    }
                }
                catch (Exception e)
                {
                }
                return("");
            }
            else
            {
                throw new System.ArgumentException
                          ("name()'s argument count is invalid");
            }
        }