Ejemplo n.º 1
0
 internal override XPathNavigator advance()
 {
     if (_VarQuery != null)
     {
         return(_VarQuery.advance());
     }
     throw new XPathException(Res.Xp_UndefinedXsltContext, Prefix, Name);
 } // Advance
Ejemplo n.º 2
0
 internal Boolean toBoolean(XPathNavigator qyContext, XPathNodeIterator iterator)
 {
     if (_qy.ReturnType() == XPathResultType.NodeSet)
     {
         _qy.setContext(qyContext.Clone());
         XPathNavigator value = _qy.advance();
         if (value != null)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else if (_qy.ReturnType() == XPathResultType.String)
     {
         object result = _qy.getValue(qyContext, iterator);
         if (result.ToString().Length > 0)
         {
             return(true);
         }
         else
         {
             if (result is string)
             {
                 return(false);
             }
             else
             {
                 Debug.Assert(result is XPathNavigator);
                 return(true);              // RTF can't be empty ?
             }
         }
     }
     else if (_qy.ReturnType() == XPathResultType.Boolean)
     {
         return(Convert.ToBoolean(_qy.getValue(qyContext, iterator)));
     }
     else if (_qy.ReturnType() == XPathResultType.Number)
     {
         return(toBoolean(XmlConvert.ToXPathDouble(_qy.getValue(qyContext, iterator))));
     }
     return(false);
 } // toBoolean
Ejemplo n.º 3
0
        internal bool matches(IQuery e, XPathNavigator context)
        {
            if (_opnd == null)
            {
                return(false);
            }
            XPathResultType resultType = _opnd.ReturnType();

            if (resultType == XPathResultType.Number)
            {
                double i = XmlConvert.ToXPathDouble(_opnd.getValue(e));
                return(i == e.Position);
            }
            if (resultType == XPathResultType.NodeSet)
            {
                _opnd.setContext(context);
                if (_opnd.advance() != null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            if (resultType == XPathResultType.Boolean)
            {
                return(Convert.ToBoolean(_opnd.getValue(e)));
            }
            if (resultType == XPathResultType.String)
            {
                if (_opnd.getValue(context, null).ToString().Length > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            return(false);
        }
Ejemplo n.º 4
0
 public override bool MoveNext()
 {
     nav = query.advance();
     if (nav != null)
     {
         position++;
         return(true);
     }
     else
     {
         return(false);
     }
 }
        public override bool MoveNext()
        {
            XPathNavigator n = query.advance();

            if (n != null)
            {
                position++;
                if (!nav.MoveTo(n))
                {
                    nav = n;
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 6
0
        private String toString(XPathNavigator qyContext, XPathNodeIterator iterator)
        {
            if (_ArgList != null && _ArgList.Count > 0)
            {
                IQuery _qy = (IQuery)_ArgList[0];

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

                    XPathNavigator value = _qy.advance();

                    if (value != null)
                    {
                        return(value.Value);
                    }
                    else
                    {
                        return(String.Empty);
                    }
                }
                else if (_qy.ReturnType() == XPathResultType.String)
                {
                    return(_qy.getValue(qyContext, iterator).ToString());
                }
                else if (_qy.ReturnType() == XPathResultType.Boolean)
                {
                    return(Convert.ToBoolean(_qy.getValue(qyContext, iterator)) ? "true" : "false");
                }
                else
                {
                    return(toString(XmlConvert.ToXPathDouble(_qy.getValue(qyContext, iterator))));
                }
            }
            else if (qyContext != null)
            {
                return(qyContext.Value);
            }
            else
            {
                return(String.Empty);
            }
        }
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 8
0
        private void BuildResultsList()
        {
            XPathNavigator eNext;
            SortKey        key;
            Int32          numSorts = _sortExpressions.Count;

            System.Diagnostics.Debug.Assert(numSorts > 0, "Why was the sort query created?");

            while (true)
            {
                eNext = _qyInput.advance();

                if (eNext == null)
                {
                    break;
                }

                // if this is the first time i.e., the cache is empty
                // and if we an xslt context to work with

                /* if (_ResultCount == 0 && _context != null)
                 *   for (Int32 i=0; i<numSorts; i++)
                 *       ((IQuery)_sortExpressions[i]).SetXsltContext(_context);*/

                // create the special object that represent the composite key
                // This key object will act as a container for the primary key value,
                // secondary key value etc.
                key = new SortKey(numSorts);

                for (Int32 j = 0; j < numSorts; j++)
                {
                    object keyval = ((IQuery)_sortExpressions[j]).getValue(_qyInput);
                    key.SetKeyValue(keyval, j);
                }

                _Results.Add(key, eNext.Clone());
                _ResultCount++;
            }
        }
Ejemplo n.º 9
0
        private void BuildResultsList()
        {
            Int32 numSorts = this.comparer.NumSorts;

            Debug.Assert(numSorts > 0, "Why was the sort query created?");

            XPathNavigator eNext;

            while ((eNext = _qyInput.advance()) != null)
            {
                SortKey key = new SortKey(numSorts, /*originalPosition:*/ this.results.Count, eNext.Clone());

                for (Int32 j = 0; j < numSorts; j++)
                {
                    object keyval = this.comparer.Expression(j).getValue(_qyInput);
                    key[j] = keyval;
                }

                results.Add(key);
            }
            results.Sort(this.comparer);
        }
Ejemplo n.º 10
0
 internal void FillList()
 {
     _elementList = new ArrayList();
     while (true)
     {
         if (_getInput1)
         {
             _getInput1 = false;
             if ((m_eNext = m_qyInput.advance()) == null)
             {
                 _top = _elementList.Count;
                 return;
             }
             _child.setContext(m_eNext);
         }
         while ((m_eNext = _child.advance()) != null)
         {
             //if ( matches( _child, m_eNext) ) {
             NotVisited(m_eNext);
             //}
         }
         _getInput1 = true;
     }
 }
Ejemplo n.º 11
0
 private double Number(XPathNavigator qyContext, XPathNodeIterator iterator)
 {
     if (_qy != null)
     {
         if (_qy.ReturnType() == XPathResultType.NodeSet)
         {
             _qy.setContext(qyContext.Clone());
             XPathNavigator 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, iterator).ToString()));
         }
         else
         if (_qy.ReturnType() == XPathResultType.Boolean)
         {
             return(Number(Convert.ToBoolean(_qy.getValue(qyContext, iterator))));
         }
         else
         {
             return(XmlConvert.ToXPathDouble(_qy.getValue(qyContext, iterator)));
         }
     }
     else
     if (qyContext != null)
     {
         return(XmlConvert.ToXPathDouble(qyContext.Value));
     }
     else
     {
         return(double.NaN);
     }
 }
Ejemplo n.º 12
0
 static bool compareQueryString1(IQuery opnd1, IQuery opnd2, XPathNavigator qyContext, Operator.Op op, XPathNodeIterator iterator) {
     XPathNavigator val1;
     opnd1.setContext(qyContext.Clone()); 
     String n2 = XmlConvert.ToXPathString(opnd2.getValue(qyContext, iterator));
     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;
 }
Ejemplo n.º 13
0
       static bool compareQueryString2(IQuery opnd1, IQuery opnd2, IQuery qyContext, Operator.Op op) {

            XPathNavigator val1;
            opnd1.setContext(qyContext.peekElement().Clone()); 
            double n1, n2 = NumberFunctions.Number(XmlConvert.ToXPathString(opnd2.getValue(qyContext)));

            while (true) {
                val1 = opnd1.advance();
                if (val1 != null)
                    n1 = 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;
                }
            }
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
0
        static bool compareStringQuery1(IQuery opnd1, IQuery opnd2, XPathNavigator qyContext, Operator.Op op , XPathNodeIterator iterator) {
            XPathNavigator val1;
            opnd2.setContext(qyContext.Clone()); 
            String n2, n1 = XmlConvert.ToXPathString(opnd1.getValue(qyContext, iterator));

            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;
                }

            }
        }
Ejemplo n.º 16
0
      static bool compareStringQuery2(IQuery opnd1, IQuery opnd2, XPathNavigator qyContext, Operator.Op op, XPathNodeIterator iterator) {
            XPathNavigator val1;
            opnd2.setContext(qyContext.Clone()); 
            double n2, n1 = NumberFunctions.Number(XmlConvert.ToXPathString(opnd1.getValue(qyContext, iterator)));

            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;

                }

            }
        }
Ejemplo n.º 17
0
 internal override XPathNavigator advance()
 {
     return(_ResultQuery.advance());
 }
Ejemplo n.º 18
0
        static bool compareQueryBool1(IQuery opnd1, IQuery opnd2, IQuery qyContext, Operator.Op op) {
            XPathNavigator val1;
            opnd1.setContext(qyContext.peekElement().Clone()); 
            Boolean n1 = false, n2 = Convert.ToBoolean(opnd2.getValue(qyContext));

                val1 = opnd1.advance();
                if (val1 != null) {
                    n1 = 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;

        }
Ejemplo n.º 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;
                    }

                }
            }

        }
Ejemplo n.º 20
0
        static bool compareQueryBool2(IQuery opnd1, IQuery opnd2, IQuery qyContext, Operator.Op op) {
            XPathNavigator val1;
            opnd1.setContext(qyContext.peekElement().Clone()); 
            double n1, n2 = NumberFunctions.Number(Convert.ToBoolean(opnd2.getValue(qyContext)));

                val1 = opnd1.advance();
                if (val1 != null)
                    n1 = 1.0;
                else {
                    n1 = 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;

        }
Ejemplo n.º 21
0
        static bool compareBoolQuery2(IQuery opnd1, IQuery opnd2, XPathNavigator qyContext, Operator.Op op, XPathNodeIterator iterator) {
            XPathNavigator val1;
            opnd2.setContext(qyContext.Clone()); 
            double n2, n1 = NumberFunctions.Number(Convert.ToBoolean(opnd1.getValue(qyContext, iterator)));

                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;

        }
Ejemplo n.º 22
0
      static bool compareBoolQuery1(IQuery opnd1, IQuery opnd2, XPathNavigator qyContext, Operator.Op op, XPathNodeIterator iterator) {
            XPathNavigator val1;
            opnd2.setContext(qyContext.Clone()); 
            Boolean n2 = false, n1 = Convert.ToBoolean(opnd1.getValue(qyContext, iterator));

                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;

        }
Ejemplo n.º 23
0
        internal override XPathNavigator advance()
        {
            XPathNavigator res1, res2;
            XmlNodeOrder   order = 0;

            if (advance1)
            {
                res1 = qy1.advance();
            }
            else
            {
                res1 = _last;
            }
            if (advance2)
            {
                res2 = qy2.advance();
            }
            else
            {
                res2 = _last;
            }

            if (res1 != null && res2 != null)
            {
                order = res1.ComparePosition(res2);
            }

            else if (res2 == null)
            {
                advance1 = true;
                advance2 = false;
                m_eNext  = res1;
                _last    = null;
                return(res1);
            }
            else
            {
                advance1 = false;
                advance2 = true;
                m_eNext  = res2;
                _last    = null;
                return(res2);
            }

            if (order == XmlNodeOrder.Same)
            {
                return(ProcessSamePosition(res1));
            }
            if (order == XmlNodeOrder.Before)
            {
                return(ProcessBeforePosition(res1, res2));
            }
            if (order == XmlNodeOrder.After)
            {
                return(ProcessAfterPosition(res1, res2));
            }
            //Now order is XmlNodeOrder.Unknown
            XPathNavigator dummyres1 = res1.Clone();

            dummyres1.MoveToRoot();

            XPathNavigator dummyres2 = res2.Clone();

            dummyres2.MoveToRoot();
            int uriOrder = context.CompareDocument(dummyres1.BaseURI, dummyres2.BaseURI);

            if (uriOrder == 0)
            {
                return(ProcessSamePosition(res1));
            }
            if (uriOrder < 0)
            {
                return(ProcessBeforePosition(res1, res2));
            }
            if (uriOrder > 0)
            {
                return(ProcessAfterPosition(res1, res2));
            }
            Debug.Assert(false, "should not be herein OrQuery.advance()");
            return(null);
        }
Ejemplo n.º 24
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;
                    }           
                }
            }
        }