Example #1
0
        private Boolean Lang(IQuery qy)
        {
            String         str     = _qy.getValue(qy).ToString();
            XPathNavigator context = qy.peekElement().Clone();

            return(Lang(str, context));
        }
Example #2
0
        private String Normalize(IQuery qy)
        {
            String str1;

            if (_ArgList != null && _ArgList.Count > 0)
            {
                str1 = ((IQuery)_ArgList[0]).getValue(qy).ToString().Trim();
            }
            else
            {
                str1 = qy.peekElement().Value.Trim();
            }
            int           count      = 0;
            StringBuilder str2       = new StringBuilder();;
            bool          FirstSpace = true;

            while (count < str1.Length)
            {
                if (!XmlCharType.IsWhiteSpace(str1[count]))
                {
                    FirstSpace = true;
                    str2.Append(str1[count]);
                }
                else
                if (FirstSpace)
                {
                    FirstSpace = false;
                    str2.Append(str1[count]);
                }
                count++;
            }
            return(str2.ToString());
        }
Example #3
0
 internal override XPathNavigator peekElement()
 {
     if (_VarQuery != null)
     {
         return(_VarQuery.peekElement());
     }
     throw new XPathException(Res.Xp_UndefinedXsltContext, Prefix, Name);
 }
        private double Number(IQuery qyContext)
        {
            XPathNavigator value = null;

            if (_qy != null)
            {
                if (_qy.ReturnType() == XPathResultType.NodeSet)
                {
                    _qy.setContext(qyContext.peekElement().Clone());
                    value = _qy.advance();
                    if (value != null)
                    {
                        return(Number(value.Value));
                    }
                    else
                    {
                        return(double.NaN);
                    }
                }
                else
                if (_qy.ReturnType() == XPathResultType.String)
                {
                    return(Number(_qy.getValue(qyContext).ToString()));
                }
                else
                if (_qy.ReturnType() == XPathResultType.Boolean)
                {
                    return(Number(Convert.ToBoolean(_qy.getValue(qyContext))));
                }
                else
                {
                    return(XmlConvert.ToXPathDouble(_qy.getValue(qyContext)));
                }
            }
            else
            if ((value = qyContext.peekElement()) != null)
            {
                return(XmlConvert.ToXPathDouble(value.Value));
            }
            else
            {
                return(double.NaN);
            }
        }
Example #5
0
        private String toString(IQuery qyContext)
        {
            XPathNavigator value = null;

            if (_ArgList != null && _ArgList.Count > 0)
            {
                IQuery _qy = (IQuery)_ArgList[0];

                if (_qy.ReturnType() == XPathResultType.NodeSet)
                {
                    _qy.setContext(qyContext.peekElement().Clone());

                    value = _qy.advance();
                    if (value != null)
                    {
                        return(value.Value);
                    }
                    else
                    {
                        return(String.Empty);
                    }
                }
                else if (_qy.ReturnType() == XPathResultType.String)
                {
                    return(_qy.getValue(qyContext).ToString());
                }
                else if (_qy.ReturnType() == XPathResultType.Boolean)
                {
                    return(toString(Convert.ToBoolean(_qy.getValue(qyContext))));
                }
                return(toString(XmlConvert.ToXPathDouble(_qy.getValue(qyContext))));
            }
            else
            if ((value = qyContext.peekElement()) != null)
            {
                return(value.Value);
            }
            else
            {
                return(String.Empty);
            }
        }
        private double Sum(IQuery qyContext)
        {
            double sum = 0;

            _qy.setContext(qyContext.peekElement().Clone());
            XPathNavigator value = _qy.advance();

            while (value != null)
            {
                sum  += Number(value.Value);
                value = _qy.advance();
            }
            return(sum);
        }
Example #7
0
 private Double StringLength(IQuery qy)
 {
     if (_ArgList != null && _ArgList.Count > 0)
     {
         return(((IQuery)_ArgList[0]).getValue(qy).ToString().Length);
     }
     else
     {
         XPathNavigator temp = qy.peekElement();
         if (temp != null)
         {
             return(temp.Value.Length);
         }
         else
         {
             return(0);
         }
     }
 }
Example #8
0
        } // toBoolean

        internal Boolean toBoolean(IQuery qyContext)
        {
            if (_qy.ReturnType() == XPathResultType.NodeSet)
            {
                _qy.setContext(qyContext.peekElement().Clone());
                XPathNavigator value = _qy.advance();
                if (value != null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else if (_qy.ReturnType() == XPathResultType.String)
            {
                if (_qy.getValue(qyContext).ToString().Length > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else if (_qy.ReturnType() == XPathResultType.Boolean)
            {
                return(Convert.ToBoolean(_qy.getValue(qyContext)));
            }
            else if (_qy.ReturnType() == XPathResultType.Number)
            {
                return(toBoolean(XmlConvert.ToXPathDouble(_qy.getValue(qyContext))));
            }
            return(false);
        } // toBoolean
Example #9
0
        internal override object getValue(IQuery qyContext)
        {
            XPathNavigator eNext;

            switch (_FType)
            {
            case FT.FuncPosition:
                if (qyContext != null)
                {
                    return((double)qyContext.Position);
                }
                break;

            case FT.FuncLast:
                if (qyContext != null)
                {
                    if (checkWhitespace)
                    {
                        return((double)((PositionQuery)qyContext).getNonWSCount(context));
                    }
                    try {
                        return((double)((PositionQuery)qyContext).getCount());
                    }
                    catch (Exception) {
                        if (last == -1)
                        {
                            last = 0;
                            IQuery temp = qyContext.Clone();
                            while (temp.advance() != null)
                            {
                                last++;
                            }
                        }
                        return(last);
                    }
                }
                break;

            case FT.FuncCount:
                int i = 0;
                _Opnd.setContext(qyContext.peekElement());
                if (checkWhitespace)
                {
                    XPathNavigator nav;
                    while ((nav = _Opnd.advance()) != null)
                    {
                        if (nav.NodeType != XPathNodeType.Whitespace || context.PreserveWhitespace(nav))
                        {
                            i++;
                        }
                    }
                    return((double)i);
                }
                while (_Opnd.advance() != null)
                {
                    i++;
                }
                return((double)i);

            case FT.FuncNameSpaceUri:
                if (_Opnd != null)
                {
                    _Opnd.setContext(qyContext.peekElement());
                    if ((eNext = _Opnd.advance()) != null)
                    {
                        return(eNext.NamespaceURI);
                    }
                    else
                    {
                        return(String.Empty);
                    }
                }
                return(qyContext.peekElement().NamespaceURI);

            case FT.FuncLocalName:
                if (_Opnd != null)
                {
                    _Opnd.setContext(qyContext.peekElement().Clone());
                    if ((eNext = _Opnd.advance()) != null)
                    {
                        return(eNext.LocalName);
                    }
                    else
                    {
                        return(String.Empty);
                    }
                }
                return(qyContext.peekElement().LocalName);

            case FT.FuncName:
                if (_Opnd != null)
                {
                    _Opnd.setContext(qyContext.peekElement().Clone());
                    if ((eNext = _Opnd.advance()) != null)
                    {
                        return(eNext.Name);
                    }
                    else
                    {
                        return(String.Empty);
                    }
                }
                return(qyContext.peekElement().Name);
            }
            return(String.Empty);
        }
Example #10
0
 private Double StringLength(IQuery qy) {
     if (_ArgList != null && _ArgList.Count > 0)
         return((IQuery)_ArgList[0]).getValue(qy).ToString().Length;
     else {
         XPathNavigator temp = qy.peekElement();
         if (temp != null)
             return temp.Value.Length;
         else
             return 0;
     }
 }
Example #11
0
        private String Normalize(IQuery qy) {
            String str1;
            if (_ArgList != null && _ArgList.Count > 0)
                str1 = ((IQuery)_ArgList[0]).getValue(qy).ToString().Trim();
            else
                str1 = qy.peekElement().Value.Trim();
            int count = 0;
            StringBuilder str2 = new StringBuilder();;
            bool FirstSpace = true;
            while (count < str1.Length) {
                if (!XmlCharType.IsWhiteSpace(str1[count])) {
                    FirstSpace = true;
                    str2.Append(str1[count]);
                }
                else
                    if (FirstSpace) {
                    FirstSpace = false;
                    str2.Append(str1[count]);
                }
                count++;
            }
            return str2.ToString();

        }
Example #12
0
 internal override XPathNavigator peekElement()
 {
     Debug.Assert(_ResultQuery != null && _ResultQuery.ReturnType() == XPathResultType.NodeSet);
     return(_ResultQuery.peekElement());
 }
Example #13
0
        static bool compareQueryQuery1(
                                      IQuery opnd1,
                                      IQuery opnd2,
                                      IQuery qyContext,
                                      Operator.Op op) {
            XPathNavigator val1, val2; 
            String str1,str2;  
            opnd1.setContext(qyContext.peekElement().Clone()); 
            opnd2.setContext(qyContext.peekElement().Clone());
            while (true) {
                val1 = opnd1.advance();
                if (val1 != null)
                    str1 = val1.Value;
                else
                    return false;

                val2 = opnd2.advance();

                if (val2 != null)
                    str2 = val2.Value;
                else
                    return false;

                while (true) {
                    switch (op) {
                        case Operator.Op.EQ :
                            if (str1 == str2)
                                return true;
                            break;
                        case Operator.Op.NE :
                            if (str1 != str2)
                                return true;
			                break;
                    }
                    val2 = opnd2.advance();
                    if (val2 != null)
                        str2 = val2.Value;
                    else {
                        opnd2.reset();    
                        break;
                    }           
                }
            }
        }
Example #14
0
 private Boolean Lang(IQuery qy) {
     String str = _qy.getValue(qy).ToString();
     XPathNavigator context = qy.peekElement().Clone();
     return Lang(str, context);
 }
Example #15
0
        static bool compareStringQuery2(IQuery opnd1, IQuery opnd2, IQuery qyContext, Operator.Op op) {
            XPathNavigator val1;
            opnd1.setContext(qyContext.peekElement().Clone()); 
            double n2, n1 = NumberFunctions.Number(XmlConvert.ToXPathString(opnd1.getValue(qyContext)));

            while (true) {
                val1 = opnd2.advance();
                if (val1 != null)
                    n2 = NumberFunctions.Number(val1.Value);
                else
                    return false;

                switch (op) {
                    
                    case Operator.Op.LT :if (n1 <  n2) return true ;
                        break;
                    case Operator.Op.GT :if (n1 >  n2) return true ;
                        break;
                    case Operator.Op.LE :if (n1 <= n2) return true ;
                        break;
                    case Operator.Op.GE :if (n1 >= n2) return true ;
                        break;
                    case Operator.Op.EQ :if (n1 == n2) return true ;
                        break;
                    case Operator.Op.NE :if (n1 != n2) return true ;
                        break;

                }

            }
        }
Example #16
0
        private double Number(IQuery qyContext) {
            XPathNavigator value = null;
            if (_qy != null) {
                if (_qy.ReturnType() == XPathResultType.NodeSet) {
                    _qy.setContext(qyContext.peekElement().Clone());
                    value = _qy.advance();
                    if (value != null)
                        return Number(value.Value);
                    else return double.NaN;
                }
                else
                    if (_qy.ReturnType() == XPathResultType.String)
                    return  Number(_qy.getValue(qyContext).ToString());
                else
                    if (_qy.ReturnType() == XPathResultType.Boolean)
                    return Number(Convert.ToBoolean(_qy.getValue(qyContext)));
                else
                    return XmlConvert.ToXPathDouble(_qy.getValue(qyContext));
            }
            else
                if ((value = qyContext.peekElement()) != null)
                return XmlConvert.ToXPathDouble(value.Value);
            else
                return double.NaN;

        }
Example #17
0
        static bool compareStringQuery1(IQuery opnd1, IQuery opnd2, IQuery qyContext, Operator.Op op) {
            XPathNavigator val1;
            opnd2.setContext(qyContext.peekElement().Clone()); 
            String n2, n1 = XmlConvert.ToXPathString(opnd1.getValue(qyContext));

            while (true) {
                val1 = opnd2.advance();
                if (val1 != null)
                    n2 = val1.Value;
                else
                    return false;

                switch (op) {
                    
                    case Operator.Op.EQ : if (n1 == n2) return true ;
                        break;
                    case Operator.Op.NE : if (n1 != n2) return true ;
                        break;
                }

            }
        }
Example #18
0
 static bool compareQueryString1(IQuery opnd1, IQuery opnd2, IQuery qyContext, Operator.Op op) {
     XPathNavigator val1;
     opnd1.setContext(qyContext.peekElement().Clone()); 
     String n2 = XmlConvert.ToXPathString(opnd2.getValue(qyContext));
     while ((val1 = opnd1.advance()) != null) {
         if (op == Operator.Op.EQ) {
             if (val1.Value == n2) return true;
         }
         else if (val1.Value != n2) return true;
     }
     return false;
 }
Example #19
0
        static bool compareQueryQuery2(
                                      IQuery opnd1,
                                      IQuery opnd2,
                                      IQuery qyContext,
                                      Operator.Op op) {
            XPathNavigator val1, val2;
            double n1,n2;   
            opnd1.setContext(qyContext.peekElement().Clone()); 
            opnd2.setContext(qyContext.peekElement().Clone());
            while (true) {
                val1 = opnd1.advance();
                if (val1 != null)
                    n1 = NumberFunctions.Number(val1.Value);
                else
                    return false;
                val2 = opnd2.advance();

                if (val2 != null)
                    n2 = NumberFunctions.Number(val2.Value);
                else
                    return false;
                while (true) {

                    switch (op) {
                        case Operator.Op.LT : if (n1 < n2) return true;
                            break;
                        case Operator.Op.GT : if (n1 > n2) return true;
                            break;
                        case Operator.Op.LE : if (n1 <= n2) return true;
                            break;
                        case Operator.Op.GE : if (n1 >= n2) return true;
                            break;
                        case Operator.Op.EQ : if (n1 == n2) return true;
                            break;
		        case Operator.Op.NE : if (n1 != n2) return true;
			    break;
                    }
                    val2 = opnd2.advance();
                    if (val2 != null)
                        n2 = NumberFunctions.Number(val2.Value);
                    else {
                        opnd2.reset();    
                        break;
                    }

                }
            }

        }
Example #20
0
 internal override Object getValue(IQuery qy) {
     InvokeFunction(qy.peekElement().Clone());
     return _ResultQuery.getValue(qy);
 } 
Example #21
0
        internal override object getValue( IQuery  qyContext) {
            XPathNavigator eNext;
            switch (_FType) {
                
                case FT.FuncPosition:
                    if (qyContext != null) {
                        return (double)qyContext.Position;
                    }
                    break;
                case FT.FuncLast:
                    if (qyContext != null) {
                        if (checkWhitespace) {
                            return(double)((PositionQuery)qyContext).getNonWSCount(context);
                        }
                        try {
                            return(double)((PositionQuery)qyContext).getCount();
                        }
                        catch(Exception) {
                            if (last == -1) {
                                last = 0;
                                IQuery temp = qyContext.Clone();
                                while (temp.advance() != null) {
                                    last++;
                                }
                            }
                            return last;
                        }
                    }
                    break;
                case FT.FuncCount:
                    int i = 0;
                    _Opnd.setContext(qyContext.peekElement());
                    if (checkWhitespace) {
                        XPathNavigator nav;
                        while ((nav = _Opnd.advance())!= null) {
                            if (nav.NodeType != XPathNodeType.Whitespace || context.PreserveWhitespace(nav)) { 
                                i++;
                            }
                        }
                        return (double)i;
                    }
                    while (_Opnd.advance()!= null) {
                        i++;
                    }
                    return (double)i;
                case FT.FuncNameSpaceUri:
                    if (_Opnd != null) {
                        _Opnd.setContext(qyContext.peekElement());
                        if (( eNext = _Opnd.advance()) != null) {
                            return eNext.NamespaceURI;
                        }
                        else {
                            return String.Empty;
                        }
                    }
                    return qyContext.peekElement().NamespaceURI;

                case FT.FuncLocalName:
                    if (_Opnd != null) {
                        _Opnd.setContext(qyContext.peekElement().Clone());
                        if (( eNext = _Opnd.advance()) != null) {
                            return eNext.LocalName;
                        }
                        else {
                            return String.Empty;
                        }
                    }
                    return qyContext.peekElement().LocalName;

                case FT.FuncName :
                    if (_Opnd != null) {
                        _Opnd.setContext(qyContext.peekElement().Clone());
                        if (( eNext = _Opnd.advance()) != null) {
                            return eNext.Name;
                        }
                        else {
                            return String.Empty;
                        }
                    }
                    return qyContext.peekElement().Name;

            }
            return String.Empty;
        }
Example #22
0
        private String toString(IQuery qyContext) {
            XPathNavigator value = null;
            if (_ArgList != null && _ArgList.Count > 0) {
                IQuery _qy = (IQuery) _ArgList[0];

                if (_qy.ReturnType() == XPathResultType.NodeSet) {
  
                    _qy.setContext(qyContext.peekElement().Clone());
  
                    value = _qy.advance();
                    if (value  != null)
                        return value.Value;
                    else
                        return String.Empty;
                }
                else if (_qy.ReturnType() == XPathResultType.String) {
                    return  _qy.getValue(qyContext).ToString();
                }
                else if (_qy.ReturnType() == XPathResultType.Boolean) {
                    return toString(Convert.ToBoolean(_qy.getValue(qyContext)));
                }
                return toString(XmlConvert.ToXPathDouble(_qy.getValue(qyContext)));
            }
            else
                if ((value = qyContext.peekElement())!= null)
                return value.Value;
            else
                return String.Empty;
        }
Example #23
0
 internal override Object getValue(IQuery qy)
 {
     InvokeFunction(qy.peekElement().Clone());
     return(_ResultQuery.getValue(qy));
 }
Example #24
0
        static bool compareBoolQuery1(IQuery opnd1, IQuery opnd2, IQuery qyContext, Operator.Op op) {
            XPathNavigator val1;
            opnd2.setContext(qyContext.peekElement().Clone()); 
            Boolean n2 = false, n1 = Convert.ToBoolean(opnd1.getValue(qyContext));

                val1 = opnd2.advance();
                if (val1 != null)
                    n2 = true;
                else {
                    if (op ==  Operator.Op.EQ ) {
                        return (n2 == n1);
                    }
                    return (n2 != n1);
                }
                    

                switch (op) {
                    
                    case Operator.Op.EQ : return (n1 == n2) ;
                    case Operator.Op.NE : return (n1 != n2) ;
                }
                return false;

        }
Example #25
0
 private double Sum(IQuery qyContext) {
     double sum = 0;
     _qy.setContext(qyContext.peekElement().Clone());
     XPathNavigator value = _qy.advance();
     while (value != null) {
         sum += Number(value.Value);        
         value = _qy.advance();
     }
     return sum;
 }
Example #26
0
        static bool compareBoolQuery2(IQuery opnd1, IQuery opnd2, IQuery qyContext, Operator.Op op) {
            XPathNavigator val1;
            opnd2.setContext(qyContext.peekElement().Clone()); 
            double n2, n1 = NumberFunctions.Number(Convert.ToBoolean(opnd1.getValue(qyContext)));

                val1 = opnd2.advance();
                if (val1 != null)
                    n2 = 1.0;
               else {
                    n2 = 0;
                    switch (op) {                    
                        case Operator.Op.LT : return (n1 <  n2) ;
                        case Operator.Op.GT : return (n1 >  n2) ;
                        case Operator.Op.LE : return (n1 <= n2) ;
                        case Operator.Op.GE : return (n1 >= n2) ;

                    }
                }
                switch (op) {
                    
                    case Operator.Op.LT : return (n1 <  n2)  ;
                    case Operator.Op.GT : return (n1 >  n2)   ;
                    case Operator.Op.LE : return (n1 <= n2)  ;
                    case Operator.Op.GE : return (n1 >= n2)  ;
                }
                return false;

        }
Example #27
0
        } // toBoolean

        internal Boolean toBoolean(IQuery qyContext) {
            if (_qy.ReturnType() == XPathResultType.NodeSet) {
                _qy.setContext(qyContext.peekElement().Clone());
                XPathNavigator value = _qy.advance();
                if (value  != null)
                    return true;
                else
                    return false;
            }
            else if (_qy.ReturnType() == XPathResultType.String) {
                if (_qy.getValue(qyContext).ToString().Length > 0)
                    return true;
                else
                    return false;
            }
            else if (_qy.ReturnType() == XPathResultType.Boolean)
                return Convert.ToBoolean(_qy.getValue(qyContext));
            else if (_qy.ReturnType() == XPathResultType.Number) {
                return(toBoolean(XmlConvert.ToXPathDouble(_qy.getValue(qyContext))));
            }
            return false;

        } // toBoolean