Package org.apache.xpath

Examples of org.apache.xpath.XPathContext$XPathExpressionContext


   */
  public void setRoot(int nodeHandle, Object environment)
  {
    if(null != m_iter)
    {
      XPathContext xctxt = (XPathContext)environment;
      m_dtmMgr = xctxt.getDTMManager();
      m_iter.setRoot(nodeHandle, environment);
      if(!m_iter.isDocOrdered())
      {
        if(!hasCache())
          setShouldCacheNodes(true);
View Full Code Here


    }

    if (refNodes == null) {
     //  create an empty XNodeSet
      KeyIterator ki = (KeyIterator) (m_keyNodes).getContainedIter();
      XPathContext xctxt = ki.getXPathContext();
      refNodes = new XNodeSet(xctxt.getDTMManager()) {
        public void setRoot(int nodeHandle, Object environment) {
          // Root cannot be set on non-iterated node sets. Ignore it.
        }
      };
      refNodes.reset();
View Full Code Here

    if (m_refsTable == null)
    {
      m_refsTable = new Hashtable(89)// initial capacity set to a prime number to improve hash algorithm performance

      KeyIterator ki = (KeyIterator) (m_keyNodes).getContainedIter();
      XPathContext xctxt = ki.getXPathContext();

      KeyDeclaration keyDeclaration = getKeyDeclaration();

      int currentNode;
      m_keyNodes.reset();
      while (DTM.NULL != (currentNode = m_keyNodes.nextNode()))
      {
        try
        {
          XObject xuse = keyDeclaration.getUse().execute(xctxt, currentNode, ki.getPrefixResolver());

          if (xuse.getType() != xuse.CLASS_NODESET)
          {
            XMLString exprResult = xuse.xstr();
            addValueInRefsTable(xctxt, exprResult, currentNode);
          }
          else
          {
            DTMIterator i = ((XNodeSet)xuse).iterRaw();
            int currentNodeInUseClause;

            while (DTM.NULL != (currentNodeInUseClause = i.nextNode()))
            {
              DTM dtm = xctxt.getDTM(currentNodeInUseClause);
              XMLString exprResult = dtm.getStringValue(currentNodeInUseClause);
              addValueInRefsTable(xctxt, exprResult, currentNode);
            }
          }
        }
View Full Code Here

   */
  public static double max(ExpressionContext myContext, NodeList nl, String expr)
    throws SAXNotSupportedException
  {

    XPathContext xctxt = null;
    if (myContext instanceof XPathContext.XPathExpressionContext)
      xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
    else
      throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext }));

    if (expr == null || expr.length() == 0)
      return Double.NaN;
     
    NodeSetDTM contextNodes = new NodeSetDTM(nl, xctxt);
    xctxt.pushContextNodeList(contextNodes);
   
    double maxValue = Double.MIN_VALUE;
    for (int i = 0; i < contextNodes.getLength(); i++)
    {
      int contextNode = contextNodes.item(i);
      xctxt.pushCurrentNode(contextNode);
     
      double result = 0;
      try
      {
        XPath dynamicXPath = new XPath(expr, xctxt.getSAXLocator(),
                                       xctxt.getNamespaceContext(),
                                       XPath.SELECT);
        result = dynamicXPath.execute(xctxt, contextNode, xctxt.getNamespaceContext()).num();
      }
      catch (TransformerException e)
      {
        xctxt.popCurrentNode();
        xctxt.popContextNodeList();
        return Double.NaN;
      }
     
      xctxt.popCurrentNode();
             
      if (result > maxValue)
          maxValue = result;
    }     
     
    xctxt.popContextNodeList();
    return maxValue;
       
  }
View Full Code Here

   */
  public static double min(ExpressionContext myContext, NodeList nl, String expr)
    throws SAXNotSupportedException
  {
   
    XPathContext xctxt = null;
    if (myContext instanceof XPathContext.XPathExpressionContext)
      xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
    else
      throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext }));

    if (expr == null || expr.length() == 0)
      return Double.NaN;
     
    NodeSetDTM contextNodes = new NodeSetDTM(nl, xctxt);
    xctxt.pushContextNodeList(contextNodes);
   
    double minValue = Double.MAX_VALUE;
    for (int i = 0; i < nl.getLength(); i++)
    {
      int contextNode = contextNodes.item(i);
      xctxt.pushCurrentNode(contextNode);
     
      double result = 0;
      try
      {
        XPath dynamicXPath = new XPath(expr, xctxt.getSAXLocator(),
                                       xctxt.getNamespaceContext(),
                                       XPath.SELECT);
        result = dynamicXPath.execute(xctxt, contextNode, xctxt.getNamespaceContext()).num();
      }
      catch (TransformerException e)
      {
        xctxt.popCurrentNode();
        xctxt.popContextNodeList();
        return Double.NaN;
      }
     
      xctxt.popCurrentNode();
             
      if (result < minValue)
          minValue = result;
    }     
     
    xctxt.popContextNodeList();
    return minValue;
 
  }
View Full Code Here

    public void testIteration() throws Exception {
        expect(pageContext.findAttribute("doc")).andStubReturn(test);
        tag.setSelect("$doc/root/a/num");
        replay(pageContext);
        tag.prepare();
        XPathContext context = tag.getContext();
        Assert.assertTrue(tag.hasNext());
        Node one = (Node) tag.next();
        Assert.assertEquals("one", one.getTextContent());
        Assert.assertTrue(tag.hasNext());
        Node two = (Node) tag.next();
        Assert.assertEquals("two", two.getTextContent());
        Assert.assertTrue(tag.hasNext());
        Node three = (Node) tag.next();
        Assert.assertEquals("three", three.getTextContent());
        Assert.assertFalse(tag.hasNext());
        tag.doFinally();
        Assert.assertTrue(context.getContextNodeListsStack().isEmpty());
        verify(pageContext);
    }
View Full Code Here

        replay(pageContext);
        XPath dot = new XPath(".", null, null, XPath.SELECT);
        XPath position = new XPath("position()", null, null, XPath.SELECT);
        XPath last = new XPath("last()", null, null, XPath.SELECT);
        tag.prepare();
        XPathContext context = tag.getContext();
        tag.hasNext();
        tag.next();
        Assert.assertEquals("3", last.execute(context, context.getCurrentNode(), null).str());
        Assert.assertEquals("one", dot.execute(context, context.getCurrentNode(), null).str());
        Assert.assertEquals("1", position.execute(context, context.getCurrentNode(), null).str());
        tag.hasNext();
        tag.next();
        Assert.assertEquals("two", dot.execute(context, context.getCurrentNode(), null).str());
        Assert.assertEquals("2", position.execute(context, context.getCurrentNode(), null).str());
        tag.hasNext();
        tag.next();
        Assert.assertEquals("three", dot.execute(context, context.getCurrentNode(), null).str());
        Assert.assertEquals("3", position.execute(context, context.getCurrentNode(), null).str());
        verify(pageContext);
    }
View Full Code Here

    @Test
    public void testEmptyContext() {
        expect(tag.getParent()).andReturn(null);
        replay(pageContext, tag);
        XPathContext context = XalanUtil.getContext(tag, pageContext);
        // verify current node is an empty Document
        int node = context.getCurrentNode();
        Node doc = context.getDTM(node).getNode(node);
        Assert.assertTrue(doc instanceof Document);
        Assert.assertNull(doc.getFirstChild());
        verify(pageContext, tag);
    }
View Full Code Here

    public void testContextSupportsMultipleVariables() throws Exception {
        expect(tag.getParent()).andReturn(null);
        expect(pageContext.findAttribute("a")).andReturn("Hello");
        expect(pageContext.getAttribute("b", PageContext.REQUEST_SCOPE)).andReturn("World");
        replay(pageContext, tag);
        XPathContext context = XalanUtil.getContext(tag, pageContext);
        XPath xpath = new XPath("concat($a, ' ', $requestScope:b)", null, null, XPath.SELECT);
        Assert.assertEquals("Hello World", xpath.execute(context, context.getCurrentNode(), null).str());
        verify(pageContext, tag);
    }
View Full Code Here

    private XString hello;

    @Before
    public void setup() {
        pageContext = createMock(PageContext.class);
        xpathContext = new XPathContext(false);
        hello = (XString) XObjectFactory.create("Hello");
        stack = new JSTLVariableStack(pageContext);

    }
View Full Code Here

TOP

Related Classes of org.apache.xpath.XPathContext$XPathExpressionContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.