com.sun.org.apache.xpath.internal.objects.XNodeSet Java Examples

The following examples show how to use com.sun.org.apache.xpath.internal.objects.XNodeSet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Expression.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Given an select expression and a context, evaluate the XPath
 * and return the resulting iterator, but do not clone.
 *
 * @param xctxt The execution context.
 * @param contextNode The node that "." expresses.
 *
 *
 * @return A valid DTMIterator.
 * @throws TransformerException thrown if the active ProblemListener decides
 * the error condition is severe enough to halt processing.
 *
 * @throws javax.xml.transform.TransformerException
 * @xsl.usage experimental
 */
public DTMIterator asIteratorRaw(XPathContext xctxt, int contextNode)
        throws javax.xml.transform.TransformerException
{

  try
  {
    xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);

    XNodeSet nodeset = (XNodeSet)execute(xctxt);
    return nodeset.iterRaw();
  }
  finally
  {
    xctxt.popCurrentNodeAndExpression();
  }
}
 
Example #2
Source File: Expression.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Given an select expression and a context, evaluate the XPath
 * and return the resulting iterator, but do not clone.
 *
 * @param xctxt The execution context.
 * @param contextNode The node that "." expresses.
 *
 *
 * @return A valid DTMIterator.
 * @throws TransformerException thrown if the active ProblemListener decides
 * the error condition is severe enough to halt processing.
 *
 * @throws javax.xml.transform.TransformerException
 * @xsl.usage experimental
 */
public DTMIterator asIteratorRaw(XPathContext xctxt, int contextNode)
        throws javax.xml.transform.TransformerException
{

  try
  {
    xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);

    XNodeSet nodeset = (XNodeSet)execute(xctxt);
    return nodeset.iterRaw();
  }
  finally
  {
    xctxt.popCurrentNodeAndExpression();
  }
}
 
Example #3
Source File: ExsltDynamic.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The dyn:evaluate function evaluates a string as an XPath expression and returns
 * the resulting value, which might be a boolean, number, string, node set, result
 * tree fragment or external object. The sole argument is the string to be evaluated.
 * <p>
 * If the expression string passed as the second argument is an invalid XPath
 * expression (including an empty string), this function returns an empty node set.
 * <p>
 * You should only use this function if the expression must be constructed dynamically,
 * otherwise it is much more efficient to use the expression literally.
 *
 * @param myContext The ExpressionContext passed by the extension processor
 * @param xpathExpr The XPath expression string
 *
 * @return The evaluation result
 */
public static XObject evaluate(ExpressionContext myContext, String xpathExpr)
  throws SAXNotSupportedException
{
  if (myContext instanceof XPathContext.XPathExpressionContext)
  {
    XPathContext xctxt = null;
    try
    {
      xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
      XPath dynamicXPath = new XPath(xpathExpr, xctxt.getSAXLocator(),
                                     xctxt.getNamespaceContext(),
                                     XPath.SELECT);

      return dynamicXPath.execute(xctxt, myContext.getContextNode(),
                                  xctxt.getNamespaceContext());
    }
    catch (TransformerException e)
    {
      return new XNodeSet(xctxt.getDTMManager());
    }
  }
  else
    throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext })); //"Invalid context passed to evaluate "
}
 
Example #4
Source File: Expression.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Given an select expression and a context, evaluate the XPath
 * and return the resulting iterator, but do not clone.
 *
 * @param xctxt The execution context.
 * @param contextNode The node that "." expresses.
 *
 *
 * @return A valid DTMIterator.
 * @throws TransformerException thrown if the active ProblemListener decides
 * the error condition is severe enough to halt processing.
 *
 * @throws javax.xml.transform.TransformerException
 * @xsl.usage experimental
 */
public DTMIterator asIteratorRaw(XPathContext xctxt, int contextNode)
        throws javax.xml.transform.TransformerException
{

  try
  {
    xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);

    XNodeSet nodeset = (XNodeSet)execute(xctxt);
    return nodeset.iterRaw();
  }
  finally
  {
    xctxt.popCurrentNodeAndExpression();
  }
}
 
Example #5
Source File: FuncCurrent.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  SubContextList subContextList = xctxt.getCurrentNodeList();
  int currentNode = DTM.NULL;

  if (null != subContextList) {
      if (subContextList instanceof PredicatedNodeTest) {
          LocPathIterator iter = ((PredicatedNodeTest)subContextList)
                                                        .getLocPathIterator();
          currentNode = iter.getCurrentContextNode();
       } else if(subContextList instanceof StepPattern) {
         throw new RuntimeException(XSLMessages.createMessage(
            XSLTErrorResources.ER_PROCESSOR_ERROR,null));
       }
  } else {
      // not predicate => ContextNode == CurrentNode
      currentNode = xctxt.getContextNode();
  }
  return new XNodeSet(currentNode, xctxt.getDTMManager());
}
 
Example #6
Source File: Expression.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Given an select expression and a context, evaluate the XPath
 * and return the resulting iterator, but do not clone.
 *
 * @param xctxt The execution context.
 * @param contextNode The node that "." expresses.
 *
 *
 * @return A valid DTMIterator.
 * @throws TransformerException thrown if the active ProblemListener decides
 * the error condition is severe enough to halt processing.
 *
 * @throws javax.xml.transform.TransformerException
 * @xsl.usage experimental
 */
public DTMIterator asIteratorRaw(XPathContext xctxt, int contextNode)
        throws javax.xml.transform.TransformerException
{

  try
  {
    xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);

    XNodeSet nodeset = (XNodeSet)execute(xctxt);
    return nodeset.iterRaw();
  }
  finally
  {
    xctxt.popCurrentNodeAndExpression();
  }
}
 
Example #7
Source File: ExsltDynamic.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The dyn:evaluate function evaluates a string as an XPath expression and returns
 * the resulting value, which might be a boolean, number, string, node set, result
 * tree fragment or external object. The sole argument is the string to be evaluated.
 * <p>
 * If the expression string passed as the second argument is an invalid XPath
 * expression (including an empty string), this function returns an empty node set.
 * <p>
 * You should only use this function if the expression must be constructed dynamically,
 * otherwise it is much more efficient to use the expression literally.
 *
 * @param myContext The ExpressionContext passed by the extension processor
 * @param xpathExpr The XPath expression string
 *
 * @return The evaluation result
 */
public static XObject evaluate(ExpressionContext myContext, String xpathExpr)
  throws SAXNotSupportedException
{
  if (myContext instanceof XPathContext.XPathExpressionContext)
  {
    XPathContext xctxt = null;
    try
    {
      xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
      XPath dynamicXPath = new XPath(xpathExpr, xctxt.getSAXLocator(),
                                     xctxt.getNamespaceContext(),
                                     XPath.SELECT);

      return dynamicXPath.execute(xctxt, myContext.getContextNode(),
                                  xctxt.getNamespaceContext());
    }
    catch (TransformerException e)
    {
      return new XNodeSet(xctxt.getDTMManager());
    }
  }
  else
    throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext })); //"Invalid context passed to evaluate "
}
 
Example #8
Source File: FuncCurrent.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  SubContextList subContextList = xctxt.getCurrentNodeList();
  int currentNode = DTM.NULL;

  if (null != subContextList) {
      if (subContextList instanceof PredicatedNodeTest) {
          LocPathIterator iter = ((PredicatedNodeTest)subContextList)
                                                        .getLocPathIterator();
          currentNode = iter.getCurrentContextNode();
       } else if(subContextList instanceof StepPattern) {
         throw new RuntimeException(XSLMessages.createMessage(
            XSLTErrorResources.ER_PROCESSOR_ERROR,null));
       }
  } else {
      // not predicate => ContextNode == CurrentNode
      currentNode = xctxt.getContextNode();
  }
  return new XNodeSet(currentNode, xctxt.getDTMManager());
}
 
Example #9
Source File: Expression.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Given an select expression and a context, evaluate the XPath
 * and return the resulting iterator, but do not clone.
 *
 * @param xctxt The execution context.
 * @param contextNode The node that "." expresses.
 *
 *
 * @return A valid DTMIterator.
 * @throws TransformerException thrown if the active ProblemListener decides
 * the error condition is severe enough to halt processing.
 *
 * @throws javax.xml.transform.TransformerException
 * @xsl.usage experimental
 */
public DTMIterator asIteratorRaw(XPathContext xctxt, int contextNode)
        throws javax.xml.transform.TransformerException
{

  try
  {
    xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);

    XNodeSet nodeset = (XNodeSet)execute(xctxt);
    return nodeset.iterRaw();
  }
  finally
  {
    xctxt.popCurrentNodeAndExpression();
  }
}
 
Example #10
Source File: FuncCurrent.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  SubContextList subContextList = xctxt.getCurrentNodeList();
  int currentNode = DTM.NULL;

  if (null != subContextList) {
      if (subContextList instanceof PredicatedNodeTest) {
          LocPathIterator iter = ((PredicatedNodeTest)subContextList)
                                                        .getLocPathIterator();
          currentNode = iter.getCurrentContextNode();
       } else if(subContextList instanceof StepPattern) {
         throw new RuntimeException(XSLMessages.createMessage(
            XSLTErrorResources.ER_PROCESSOR_ERROR,null));
       }
  } else {
      // not predicate => ContextNode == CurrentNode
      currentNode = xctxt.getContextNode();
  }
  return new XNodeSet(currentNode, xctxt.getDTMManager());
}
 
Example #11
Source File: ExsltDynamic.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The dyn:evaluate function evaluates a string as an XPath expression and returns
 * the resulting value, which might be a boolean, number, string, node set, result
 * tree fragment or external object. The sole argument is the string to be evaluated.
 * <p>
 * If the expression string passed as the second argument is an invalid XPath
 * expression (including an empty string), this function returns an empty node set.
 * <p>
 * You should only use this function if the expression must be constructed dynamically,
 * otherwise it is much more efficient to use the expression literally.
 *
 * @param myContext The ExpressionContext passed by the extension processor
 * @param xpathExpr The XPath expression string
 *
 * @return The evaluation result
 */
public static XObject evaluate(ExpressionContext myContext, String xpathExpr)
  throws SAXNotSupportedException
{
  if (myContext instanceof XPathContext.XPathExpressionContext)
  {
    XPathContext xctxt = null;
    try
    {
      xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
      XPath dynamicXPath = new XPath(xpathExpr, xctxt.getSAXLocator(),
                                     xctxt.getNamespaceContext(),
                                     XPath.SELECT);

      return dynamicXPath.execute(xctxt, myContext.getContextNode(),
                                  xctxt.getNamespaceContext());
    }
    catch (TransformerException e)
    {
      return new XNodeSet(xctxt.getDTMManager());
    }
  }
  else
    throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext })); //"Invalid context passed to evaluate "
}
 
Example #12
Source File: FuncCurrent.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  SubContextList subContextList = xctxt.getCurrentNodeList();
  int currentNode = DTM.NULL;

  if (null != subContextList) {
      if (subContextList instanceof PredicatedNodeTest) {
          LocPathIterator iter = ((PredicatedNodeTest)subContextList)
                                                        .getLocPathIterator();
          currentNode = iter.getCurrentContextNode();
       } else if(subContextList instanceof StepPattern) {
         throw new RuntimeException(XSLMessages.createMessage(
            XSLTErrorResources.ER_PROCESSOR_ERROR,null));
       }
  } else {
      // not predicate => ContextNode == CurrentNode
      currentNode = xctxt.getContextNode();
  }
  return new XNodeSet(currentNode, xctxt.getDTMManager());
}
 
Example #13
Source File: FuncCurrent.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  SubContextList subContextList = xctxt.getCurrentNodeList();
  int currentNode = DTM.NULL;

  if (null != subContextList) {
      if (subContextList instanceof PredicatedNodeTest) {
          LocPathIterator iter = ((PredicatedNodeTest)subContextList)
                                                        .getLocPathIterator();
          currentNode = iter.getCurrentContextNode();
       } else if(subContextList instanceof StepPattern) {
         throw new RuntimeException(XSLMessages.createMessage(
            XSLTErrorResources.ER_PROCESSOR_ERROR,null));
       }
  } else {
      // not predicate => ContextNode == CurrentNode
      currentNode = xctxt.getContextNode();
  }
  return new XNodeSet(currentNode, xctxt.getDTMManager());
}
 
Example #14
Source File: ExsltDynamic.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * The dyn:evaluate function evaluates a string as an XPath expression and returns
 * the resulting value, which might be a boolean, number, string, node set, result
 * tree fragment or external object. The sole argument is the string to be evaluated.
 * <p>
 * If the expression string passed as the second argument is an invalid XPath
 * expression (including an empty string), this function returns an empty node set.
 * <p>
 * You should only use this function if the expression must be constructed dynamically,
 * otherwise it is much more efficient to use the expression literally.
 *
 * @param myContext The ExpressionContext passed by the extension processor
 * @param xpathExpr The XPath expression string
 *
 * @return The evaluation result
 */
public static XObject evaluate(ExpressionContext myContext, String xpathExpr)
  throws SAXNotSupportedException
{
  if (myContext instanceof XPathContext.XPathExpressionContext)
  {
    XPathContext xctxt = null;
    try
    {
      xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
      XPath dynamicXPath = new XPath(xpathExpr, xctxt.getSAXLocator(),
                                     xctxt.getNamespaceContext(),
                                     XPath.SELECT);

      return dynamicXPath.execute(xctxt, myContext.getContextNode(),
                                  xctxt.getNamespaceContext());
    }
    catch (TransformerException e)
    {
      return new XNodeSet(xctxt.getDTMManager());
    }
  }
  else
    throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext })); //"Invalid context passed to evaluate "
}
 
Example #15
Source File: Expression.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Given an select expression and a context, evaluate the XPath
 * and return the resulting iterator, but do not clone.
 *
 * @param xctxt The execution context.
 * @param contextNode The node that "." expresses.
 *
 *
 * @return A valid DTMIterator.
 * @throws TransformerException thrown if the active ProblemListener decides
 * the error condition is severe enough to halt processing.
 *
 * @throws javax.xml.transform.TransformerException
 * @xsl.usage experimental
 */
public DTMIterator asIteratorRaw(XPathContext xctxt, int contextNode)
        throws javax.xml.transform.TransformerException
{

  try
  {
    xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);

    XNodeSet nodeset = (XNodeSet)execute(xctxt);
    return nodeset.iterRaw();
  }
  finally
  {
    xctxt.popCurrentNodeAndExpression();
  }
}
 
Example #16
Source File: ExsltDynamic.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * The dyn:evaluate function evaluates a string as an XPath expression and returns
 * the resulting value, which might be a boolean, number, string, node set, result
 * tree fragment or external object. The sole argument is the string to be evaluated.
 * <p>
 * If the expression string passed as the second argument is an invalid XPath
 * expression (including an empty string), this function returns an empty node set.
 * <p>
 * You should only use this function if the expression must be constructed dynamically,
 * otherwise it is much more efficient to use the expression literally.
 *
 * @param myContext The ExpressionContext passed by the extension processor
 * @param xpathExpr The XPath expression string
 *
 * @return The evaluation result
 */
public static XObject evaluate(ExpressionContext myContext, String xpathExpr)
  throws SAXNotSupportedException
{
  if (myContext instanceof XPathContext.XPathExpressionContext)
  {
    XPathContext xctxt = null;
    try
    {
      xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
      XPath dynamicXPath = new XPath(xpathExpr, xctxt.getSAXLocator(),
                                     xctxt.getNamespaceContext(),
                                     XPath.SELECT);

      return dynamicXPath.execute(xctxt, myContext.getContextNode(),
                                  xctxt.getNamespaceContext());
    }
    catch (TransformerException e)
    {
      return new XNodeSet(xctxt.getDTMManager());
    }
  }
  else
    throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext })); //"Invalid context passed to evaluate "
}
 
Example #17
Source File: ExsltDynamic.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The dyn:evaluate function evaluates a string as an XPath expression and returns
 * the resulting value, which might be a boolean, number, string, node set, result
 * tree fragment or external object. The sole argument is the string to be evaluated.
 * <p>
 * If the expression string passed as the second argument is an invalid XPath
 * expression (including an empty string), this function returns an empty node set.
 * <p>
 * You should only use this function if the expression must be constructed dynamically,
 * otherwise it is much more efficient to use the expression literally.
 *
 * @param myContext The ExpressionContext passed by the extension processor
 * @param xpathExpr The XPath expression string
 *
 * @return The evaluation result
 */
public static XObject evaluate(ExpressionContext myContext, String xpathExpr)
  throws SAXNotSupportedException
{
  if (myContext instanceof XPathContext.XPathExpressionContext)
  {
    XPathContext xctxt = null;
    try
    {
      xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
      XPath dynamicXPath = new XPath(xpathExpr, xctxt.getSAXLocator(),
                                     xctxt.getNamespaceContext(),
                                     XPath.SELECT);

      return dynamicXPath.execute(xctxt, myContext.getContextNode(),
                                  xctxt.getNamespaceContext());
    }
    catch (TransformerException e)
    {
      return new XNodeSet(xctxt.getDTMManager());
    }
  }
  else
    throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext })); //"Invalid context passed to evaluate "
}
 
Example #18
Source File: FuncCurrent.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  SubContextList subContextList = xctxt.getCurrentNodeList();
  int currentNode = DTM.NULL;

  if (null != subContextList) {
      if (subContextList instanceof PredicatedNodeTest) {
          LocPathIterator iter = ((PredicatedNodeTest)subContextList)
                                                        .getLocPathIterator();
          currentNode = iter.getCurrentContextNode();
       } else if(subContextList instanceof StepPattern) {
         throw new RuntimeException(XSLMessages.createMessage(
            XSLTErrorResources.ER_PROCESSOR_ERROR,null));
       }
  } else {
      // not predicate => ContextNode == CurrentNode
      currentNode = xctxt.getContextNode();
  }
  return new XNodeSet(currentNode, xctxt.getDTMManager());
}
 
Example #19
Source File: FuncCurrent.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  SubContextList subContextList = xctxt.getCurrentNodeList();
  int currentNode = DTM.NULL;

  if (null != subContextList) {
      if (subContextList instanceof PredicatedNodeTest) {
          LocPathIterator iter = ((PredicatedNodeTest)subContextList)
                                                        .getLocPathIterator();
          currentNode = iter.getCurrentContextNode();
       } else if(subContextList instanceof StepPattern) {
         throw new RuntimeException(XSLMessages.createMessage(
            XSLTErrorResources.ER_PROCESSOR_ERROR,null));
       }
  } else {
      // not predicate => ContextNode == CurrentNode
      currentNode = xctxt.getContextNode();
  }
  return new XNodeSet(currentNode, xctxt.getDTMManager());
}
 
Example #20
Source File: ExsltDynamic.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The dyn:evaluate function evaluates a string as an XPath expression and returns
 * the resulting value, which might be a boolean, number, string, node set, result
 * tree fragment or external object. The sole argument is the string to be evaluated.
 * <p>
 * If the expression string passed as the second argument is an invalid XPath
 * expression (including an empty string), this function returns an empty node set.
 * <p>
 * You should only use this function if the expression must be constructed dynamically,
 * otherwise it is much more efficient to use the expression literally.
 *
 * @param myContext The ExpressionContext passed by the extension processor
 * @param xpathExpr The XPath expression string
 *
 * @return The evaluation result
 */
public static XObject evaluate(ExpressionContext myContext, String xpathExpr)
  throws SAXNotSupportedException
{
  if (myContext instanceof XPathContext.XPathExpressionContext)
  {
    XPathContext xctxt = null;
    try
    {
      xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
      XPath dynamicXPath = new XPath(xpathExpr, xctxt.getSAXLocator(),
                                     xctxt.getNamespaceContext(),
                                     XPath.SELECT);

      return dynamicXPath.execute(xctxt, myContext.getContextNode(),
                                  xctxt.getNamespaceContext());
    }
    catch (TransformerException e)
    {
      return new XNodeSet(xctxt.getDTMManager());
    }
  }
  else
    throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext })); //"Invalid context passed to evaluate "
}
 
Example #21
Source File: Expression.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Given an select expression and a context, evaluate the XPath
 * and return the resulting iterator, but do not clone.
 *
 * @param xctxt The execution context.
 * @param contextNode The node that "." expresses.
 *
 *
 * @return A valid DTMIterator.
 * @throws TransformerException thrown if the active ProblemListener decides
 * the error condition is severe enough to halt processing.
 *
 * @throws javax.xml.transform.TransformerException
 * @xsl.usage experimental
 */
public DTMIterator asIteratorRaw(XPathContext xctxt, int contextNode)
        throws javax.xml.transform.TransformerException
{

  try
  {
    xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);

    XNodeSet nodeset = (XNodeSet)execute(xctxt);
    return nodeset.iterRaw();
  }
  finally
  {
    xctxt.popCurrentNodeAndExpression();
  }
}
 
Example #22
Source File: Expression.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Given an select expression and a context, evaluate the XPath
 * and return the resulting iterator, but do not clone.
 *
 * @param xctxt The execution context.
 * @param contextNode The node that "." expresses.
 *
 *
 * @return A valid DTMIterator.
 * @throws TransformerException thrown if the active ProblemListener decides
 * the error condition is severe enough to halt processing.
 *
 * @throws javax.xml.transform.TransformerException
 * @xsl.usage experimental
 */
public DTMIterator asIteratorRaw(XPathContext xctxt, int contextNode)
        throws javax.xml.transform.TransformerException
{

  try
  {
    xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);

    XNodeSet nodeset = (XNodeSet)execute(xctxt);
    return nodeset.iterRaw();
  }
  finally
  {
    xctxt.popCurrentNodeAndExpression();
  }
}
 
Example #23
Source File: FuncCurrent.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  SubContextList subContextList = xctxt.getCurrentNodeList();
  int currentNode = DTM.NULL;

  if (null != subContextList) {
      if (subContextList instanceof PredicatedNodeTest) {
          LocPathIterator iter = ((PredicatedNodeTest)subContextList)
                                                        .getLocPathIterator();
          currentNode = iter.getCurrentContextNode();
       } else if(subContextList instanceof StepPattern) {
         throw new RuntimeException(XSLMessages.createMessage(
            XSLTErrorResources.ER_PROCESSOR_ERROR,null));
       }
  } else {
      // not predicate => ContextNode == CurrentNode
      currentNode = xctxt.getContextNode();
  }
  return new XNodeSet(currentNode, xctxt.getDTMManager());
}
 
Example #24
Source File: ExsltDynamic.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The dyn:evaluate function evaluates a string as an XPath expression and returns
 * the resulting value, which might be a boolean, number, string, node set, result
 * tree fragment or external object. The sole argument is the string to be evaluated.
 * <p>
 * If the expression string passed as the second argument is an invalid XPath
 * expression (including an empty string), this function returns an empty node set.
 * <p>
 * You should only use this function if the expression must be constructed dynamically,
 * otherwise it is much more efficient to use the expression literally.
 *
 * @param myContext The ExpressionContext passed by the extension processor
 * @param xpathExpr The XPath expression string
 *
 * @return The evaluation result
 */
public static XObject evaluate(ExpressionContext myContext, String xpathExpr)
  throws SAXNotSupportedException
{
  if (myContext instanceof XPathContext.XPathExpressionContext)
  {
    XPathContext xctxt = null;
    try
    {
      xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
      XPath dynamicXPath = new XPath(xpathExpr, xctxt.getSAXLocator(),
                                     xctxt.getNamespaceContext(),
                                     XPath.SELECT);

      return dynamicXPath.execute(xctxt, myContext.getContextNode(),
                                  xctxt.getNamespaceContext());
    }
    catch (TransformerException e)
    {
      return new XNodeSet(xctxt.getDTMManager());
    }
  }
  else
    throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext })); //"Invalid context passed to evaluate "
}
 
Example #25
Source File: ExsltDynamic.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * The dyn:evaluate function evaluates a string as an XPath expression and returns
 * the resulting value, which might be a boolean, number, string, node set, result
 * tree fragment or external object. The sole argument is the string to be evaluated.
 * <p>
 * If the expression string passed as the second argument is an invalid XPath
 * expression (including an empty string), this function returns an empty node set.
 * <p>
 * You should only use this function if the expression must be constructed dynamically,
 * otherwise it is much more efficient to use the expression literally.
 *
 * @param myContext The ExpressionContext passed by the extension processor
 * @param xpathExpr The XPath expression string
 *
 * @return The evaluation result
 */
public static XObject evaluate(ExpressionContext myContext, String xpathExpr)
  throws SAXNotSupportedException
{
  if (myContext instanceof XPathContext.XPathExpressionContext)
  {
    XPathContext xctxt = null;
    try
    {
      xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
      XPath dynamicXPath = new XPath(xpathExpr, xctxt.getSAXLocator(),
                                     xctxt.getNamespaceContext(),
                                     XPath.SELECT);

      return dynamicXPath.execute(xctxt, myContext.getContextNode(),
                                  xctxt.getNamespaceContext());
    }
    catch (TransformerException e)
    {
      return new XNodeSet(xctxt.getDTMManager());
    }
  }
  else
    throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext })); //"Invalid context passed to evaluate "
}
 
Example #26
Source File: Expression.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Given an select expression and a context, evaluate the XPath
 * and return the resulting iterator, but do not clone.
 *
 * @param xctxt The execution context.
 * @param contextNode The node that "." expresses.
 *
 *
 * @return A valid DTMIterator.
 * @throws TransformerException thrown if the active ProblemListener decides
 * the error condition is severe enough to halt processing.
 *
 * @throws javax.xml.transform.TransformerException
 * @xsl.usage experimental
 */
public DTMIterator asIteratorRaw(XPathContext xctxt, int contextNode)
        throws javax.xml.transform.TransformerException
{

  try
  {
    xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);

    XNodeSet nodeset = (XNodeSet)execute(xctxt);
    return nodeset.iterRaw();
  }
  finally
  {
    xctxt.popCurrentNodeAndExpression();
  }
}
 
Example #27
Source File: FuncCurrent.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  SubContextList subContextList = xctxt.getCurrentNodeList();
  int currentNode = DTM.NULL;

  if (null != subContextList) {
      if (subContextList instanceof PredicatedNodeTest) {
          LocPathIterator iter = ((PredicatedNodeTest)subContextList)
                                                        .getLocPathIterator();
          currentNode = iter.getCurrentContextNode();
       } else if(subContextList instanceof StepPattern) {
         throw new RuntimeException(XSLMessages.createMessage(
            XSLTErrorResources.ER_PROCESSOR_ERROR,null));
       }
  } else {
      // not predicate => ContextNode == CurrentNode
      currentNode = xctxt.getContextNode();
  }
  return new XNodeSet(currentNode, xctxt.getDTMManager());
}
 
Example #28
Source File: FuncCurrent.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  SubContextList subContextList = xctxt.getCurrentNodeList();
  int currentNode = DTM.NULL;

  if (null != subContextList) {
      if (subContextList instanceof PredicatedNodeTest) {
          LocPathIterator iter = ((PredicatedNodeTest)subContextList)
                                                        .getLocPathIterator();
          currentNode = iter.getCurrentContextNode();
       } else if(subContextList instanceof StepPattern) {
         throw new RuntimeException(XSLMessages.createMessage(
            XSLTErrorResources.ER_PROCESSOR_ERROR,null));
       }
  } else {
      // not predicate => ContextNode == CurrentNode
      currentNode = xctxt.getContextNode();
  }
  return new XNodeSet(currentNode, xctxt.getDTMManager());
}
 
Example #29
Source File: ExsltDynamic.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * The dyn:evaluate function evaluates a string as an XPath expression and returns
 * the resulting value, which might be a boolean, number, string, node set, result
 * tree fragment or external object. The sole argument is the string to be evaluated.
 * <p>
 * If the expression string passed as the second argument is an invalid XPath
 * expression (including an empty string), this function returns an empty node set.
 * <p>
 * You should only use this function if the expression must be constructed dynamically,
 * otherwise it is much more efficient to use the expression literally.
 *
 * @param myContext The ExpressionContext passed by the extension processor
 * @param xpathExpr The XPath expression string
 *
 * @return The evaluation result
 */
public static XObject evaluate(ExpressionContext myContext, String xpathExpr)
  throws SAXNotSupportedException
{
  if (myContext instanceof XPathContext.XPathExpressionContext)
  {
    XPathContext xctxt = null;
    try
    {
      xctxt = ((XPathContext.XPathExpressionContext) myContext).getXPathContext();
      XPath dynamicXPath = new XPath(xpathExpr, xctxt.getSAXLocator(),
                                     xctxt.getNamespaceContext(),
                                     XPath.SELECT);

      return dynamicXPath.execute(xctxt, myContext.getContextNode(),
                                  xctxt.getNamespaceContext());
    }
    catch (TransformerException e)
    {
      return new XNodeSet(xctxt.getDTMManager());
    }
  }
  else
    throw new SAXNotSupportedException(XSLMessages.createMessage(XSLTErrorResources.ER_INVALID_CONTEXT_PASSED, new Object[]{myContext })); //"Invalid context passed to evaluate "
}
 
Example #30
Source File: Expression.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Given an select expression and a context, evaluate the XPath
 * and return the resulting iterator, but do not clone.
 *
 * @param xctxt The execution context.
 * @param contextNode The node that "." expresses.
 *
 *
 * @return A valid DTMIterator.
 * @throws TransformerException thrown if the active ProblemListener decides
 * the error condition is severe enough to halt processing.
 *
 * @throws javax.xml.transform.TransformerException
 * @xsl.usage experimental
 */
public DTMIterator asIteratorRaw(XPathContext xctxt, int contextNode)
        throws javax.xml.transform.TransformerException
{

  try
  {
    xctxt.pushCurrentNodeAndExpression(contextNode, contextNode);

    XNodeSet nodeset = (XNodeSet)execute(xctxt);
    return nodeset.iterRaw();
  }
  finally
  {
    xctxt.popCurrentNodeAndExpression();
  }
}