org.w3c.dom.xpath.XPathResult#com.sun.org.apache.xpath.internal.objects.XObject源码实例Demo

下面列出了org.w3c.dom.xpath.XPathResult#com.sun.org.apache.xpath.internal.objects.XObject 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Bytecoder   文件: FuncQname.java
/**
 * 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
{

  int context = getArg0AsNode(xctxt);
  XObject val;

  if (DTM.NULL != context)
  {
    DTM dtm = xctxt.getDTM(context);
    String qname = dtm.getNodeNameX(context);
    val = (null == qname) ? XString.EMPTYSTRING : new XString(qname);
  }
  else
  {
    val = XString.EMPTYSTRING;
  }

  return val;
}
 
源代码2 项目: openjdk-jdk8u   文件: XPathResultImpl.java
/**
   * Given an XObject, determine the corresponding DOM XPath type
   *
   * @return type string
   */
  private short getTypeFromXObject(XObject object) {
      switch (object.getType()) {
        case XObject.CLASS_BOOLEAN: return BOOLEAN_TYPE;
        case XObject.CLASS_NODESET: return UNORDERED_NODE_ITERATOR_TYPE;
        case XObject.CLASS_NUMBER: return NUMBER_TYPE;
        case XObject.CLASS_STRING: return STRING_TYPE;
        // XPath 2.0 types
//          case XObject.CLASS_DATE:
//          case XObject.CLASS_DATETIME:
//          case XObject.CLASS_DTDURATION:
//          case XObject.CLASS_GDAY:
//          case XObject.CLASS_GMONTH:
//          case XObject.CLASS_GMONTHDAY:
//          case XObject.CLASS_GYEAR:
//          case XObject.CLASS_GYEARMONTH:
//          case XObject.CLASS_TIME:
//          case XObject.CLASS_YMDURATION: return STRING_TYPE; // treat all date types as strings?

        case XObject.CLASS_RTREEFRAG: return UNORDERED_NODE_ITERATOR_TYPE;
        case XObject.CLASS_NULL: return ANY_TYPE; // throw exception ?
        default: return ANY_TYPE; // throw exception ?
    }

  }
 
源代码3 项目: jdk8u60   文件: StepPattern.java
/**
 * Get the match score of the given node.
 *
 * @param xctxt The XPath runtime context.
 * @param context The node to be tested.
 *
 * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public double getMatchScore(XPathContext xctxt, int context)
        throws javax.xml.transform.TransformerException
{

  xctxt.pushCurrentNode(context);
  xctxt.pushCurrentExpressionNode(context);

  try
  {
    XObject score = execute(xctxt);

    return score.num();
  }
  finally
  {
    xctxt.popCurrentNode();
    xctxt.popCurrentExpressionNode();
  }

  // return XPath.MATCH_SCORE_NONE;
}
 
源代码4 项目: JDKSourceCode1.8   文件: VariableStack.java
/**
 * Get a local variable or parameter in the current stack frame.
 *
 *
 * @param xctxt The XPath context, which must be passed in order to
 * lazy evaluate variables.
 *
 * @param index Local variable index relative to the current stack
 * frame bottom.
 *
 * @return The value of the variable.
 *
 * @throws TransformerException
 */
public XObject getLocalVariable(XPathContext xctxt, int index)
        throws TransformerException
{

  index += _currentFrameBottom;

  XObject val = _stackFrames[index];

  if(null == val)
    throw new TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_VARIABLE_ACCESSED_BEFORE_BIND, null),
                   xctxt.getSAXLocator());
    // "Variable accessed before it is bound!", xctxt.getSAXLocator());

  // Lazy execution of variables.
  if (val.getType() == XObject.CLASS_UNRESOLVEDVARIABLE)
    return (_stackFrames[index] = val.execute(xctxt));

  return val;
}
 
源代码5 项目: jdk8u60   文件: VariableStack.java
/**
 * Get a local variable or parameter in the current stack frame.
 *
 *
 * @param xctxt The XPath context, which must be passed in order to
 * lazy evaluate variables.
 *
 * @param index Local variable index relative to the current stack
 * frame bottom.
 *
 * @return The value of the variable.
 *
 * @throws TransformerException
 */
public XObject getLocalVariable(XPathContext xctxt, int index, boolean destructiveOK)
        throws TransformerException
{

  index += _currentFrameBottom;

  XObject val = _stackFrames[index];

  if(null == val)
    throw new TransformerException(XSLMessages.createXPATHMessage(XPATHErrorResources.ER_VARIABLE_ACCESSED_BEFORE_BIND, null),
                   xctxt.getSAXLocator());
    // "Variable accessed before it is bound!", xctxt.getSAXLocator());

  // Lazy execution of variables.
  if (val.getType() == XObject.CLASS_UNRESOLVEDVARIABLE)
    return (_stackFrames[index] = val.execute(xctxt));

  return destructiveOK ? val : val.getFresh();
}
 
源代码6 项目: openjdk-jdk8u-backup   文件: FuncCount.java
/**
   * 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
  {

//    DTMIterator nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());

//    // We should probably make a function on the iterator for this,
//    // as a given implementation could optimize.
//    int i = 0;
//
//    while (DTM.NULL != nl.nextNode())
//    {
//      i++;
//    }
//    nl.detach();
        DTMIterator nl = m_arg0.asIterator(xctxt, xctxt.getCurrentNode());
        int i = nl.getLength();
        nl.detach();

    return new XNumber((double) i);
  }
 
源代码7 项目: jdk1.8-source-analysis   文件: FuncQname.java
/**
 * 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
{

  int context = getArg0AsNode(xctxt);
  XObject val;

  if (DTM.NULL != context)
  {
    DTM dtm = xctxt.getDTM(context);
    String qname = dtm.getNodeNameX(context);
    val = (null == qname) ? XString.EMPTYSTRING : new XString(qname);
  }
  else
  {
    val = XString.EMPTYSTRING;
  }

  return val;
}
 
源代码8 项目: jdk8u60   文件: FuncGenerateId.java
/**
 * 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
{

  int which = getArg0AsNode(xctxt);

  if (DTM.NULL != which)
  {
    // Note that this is a different value than in previous releases
    // of Xalan. It's sensitive to the exact encoding of the node
    // handle anyway, so fighting to maintain backward compatability
    // really didn't make sense; it may change again as we continue
    // to experiment with balancing document and node numbers within
    // that value.
    return new XString("N" + Integer.toHexString(which).toUpperCase());
  }
  else
    return XString.EMPTYSTRING;
}
 
源代码9 项目: openjdk-8-source   文件: XPathResultImpl.java
/**
   * Given an XObject, determine the corresponding DOM XPath type
   *
   * @return type string
   */
  private short getTypeFromXObject(XObject object) {
      switch (object.getType()) {
        case XObject.CLASS_BOOLEAN: return BOOLEAN_TYPE;
        case XObject.CLASS_NODESET: return UNORDERED_NODE_ITERATOR_TYPE;
        case XObject.CLASS_NUMBER: return NUMBER_TYPE;
        case XObject.CLASS_STRING: return STRING_TYPE;
        // XPath 2.0 types
//          case XObject.CLASS_DATE:
//          case XObject.CLASS_DATETIME:
//          case XObject.CLASS_DTDURATION:
//          case XObject.CLASS_GDAY:
//          case XObject.CLASS_GMONTH:
//          case XObject.CLASS_GMONTHDAY:
//          case XObject.CLASS_GYEAR:
//          case XObject.CLASS_GYEARMONTH:
//          case XObject.CLASS_TIME:
//          case XObject.CLASS_YMDURATION: return STRING_TYPE; // treat all date types as strings?

        case XObject.CLASS_RTREEFRAG: return UNORDERED_NODE_ITERATOR_TYPE;
        case XObject.CLASS_NULL: return ANY_TYPE; // throw exception ?
        default: return ANY_TYPE; // throw exception ?
    }

  }
 
源代码10 项目: openjdk-jdk9   文件: FuncCurrent.java
/**
 * 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());
}
 
源代码11 项目: TencentKona-8   文件: FuncGenerateId.java
/**
 * 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
{

  int which = getArg0AsNode(xctxt);

  if (DTM.NULL != which)
  {
    // Note that this is a different value than in previous releases
    // of Xalan. It's sensitive to the exact encoding of the node
    // handle anyway, so fighting to maintain backward compatability
    // really didn't make sense; it may change again as we continue
    // to experiment with balancing document and node numbers within
    // that value.
    return new XString("N" + Integer.toHexString(which).toUpperCase());
  }
  else
    return XString.EMPTYSTRING;
}
 
源代码12 项目: Bytecoder   文件: XPathResultImpl.java
/**
 * Map the specified class type to the internal result type
 *
 * @param <T> The expected class type.
 * @param type the class type
 * @return the internal XObject type.
 */
static <T> int classToInternalType(Class<T> type) {
    if (type.isAssignableFrom(Boolean.class)) {
        return XObject.CLASS_BOOLEAN;
    } else if (Number.class.isAssignableFrom(type)) {
        return XObject.CLASS_NUMBER;
    } else if (type.isAssignableFrom(String.class)) {
        return XObject.CLASS_STRING;
    } else if (type.isAssignableFrom(XPathNodes.class)) {
        return XObject.CLASS_NODESET;
    } else if (type.isAssignableFrom(Node.class)) {
        return XObject.CLASS_RTREEFRAG;
    }
    return XObject.CLASS_NULL;
}
 
源代码13 项目: Bytecoder   文件: FunctionPattern.java
/**
 * Test a node to see if it matches the given node test.
 *
 * @param xctxt XPath runtime context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt, int context)
        throws javax.xml.transform.TransformerException
{

  DTMIterator nl = m_functionExpr.asIterator(xctxt, context);
  XNumber score = SCORE_NONE;

  if (null != nl)
  {
    int n;

    while (DTM.NULL != (n = nl.nextNode()))
    {
      score = (n == context) ? SCORE_OTHER : SCORE_NONE;

      if (score == SCORE_OTHER)
      {
        context = n;

        break;
      }
    }

    // nl.detach();
  }
  nl.detach();

  return score;
}
 
源代码14 项目: Bytecoder   文件: FuncLang.java
/**
 * 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
{

  String lang = m_arg0.execute(xctxt).str();
  int parent = xctxt.getCurrentNode();
  boolean isLang = false;
  DTM dtm = xctxt.getDTM(parent);

  while (DTM.NULL != parent)
  {
    if (DTM.ELEMENT_NODE == dtm.getNodeType(parent))
    {
      int langAttr = dtm.getAttributeNode(parent, "http://www.w3.org/XML/1998/namespace", "lang");

      if (DTM.NULL != langAttr)
      {
        String langVal = dtm.getNodeValue(langAttr);
        // %OPT%
        if (langVal.toLowerCase().startsWith(lang.toLowerCase()))
        {
          int valLen = lang.length();

          if ((langVal.length() == valLen)
                  || (langVal.charAt(valLen) == '-'))
          {
            isLang = true;
          }
        }

        break;
      }
    }

    parent = dtm.getParent(parent);
  }

  return isLang ? XBoolean.S_TRUE : XBoolean.S_FALSE;
}
 
源代码15 项目: JDKSourceCode1.8   文件: XPathAPI.java
/**
 *  Use an XPath string to select a nodelist.
 *  XPath namespace prefixes are resolved from the namespaceNode.
 *
 *  @param contextNode The node to start searching from.
 *  @param str A valid XPath string.
 *  @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
 *  @return A NodeIterator, should never be null.
 *
 * @throws TransformerException
 */
public static NodeIterator selectNodeIterator(
        Node contextNode, String str, Node namespaceNode)
          throws TransformerException
{

  // Execute the XPath, and have it return the result
  XObject list = eval(contextNode, str, namespaceNode);

  // Have the XObject return its result as a NodeSetDTM.
  return list.nodeset();
}
 
源代码16 项目: openjdk-8-source   文件: XPathImpl.java
private XObject eval(String expression, Object contextItem)
    throws javax.xml.transform.TransformerException {
    com.sun.org.apache.xpath.internal.XPath xpath = new com.sun.org.apache.xpath.internal.XPath( expression,
        null, prefixResolver, com.sun.org.apache.xpath.internal.XPath.SELECT );
    com.sun.org.apache.xpath.internal.XPathContext xpathSupport = null;
    if ( functionResolver != null ) {
        JAXPExtensionsProvider jep = new JAXPExtensionsProvider(
                functionResolver, featureSecureProcessing, featureManager );
        xpathSupport = new com.sun.org.apache.xpath.internal.XPathContext( jep );
    } else {
        xpathSupport = new com.sun.org.apache.xpath.internal.XPathContext();
    }

    XObject xobj = null;

    xpathSupport.setVarStack(new JAXPVariableStack(variableResolver));

    // If item is null, then we will create a a Dummy contextNode
    if ( contextItem instanceof Node ) {
        xobj = xpath.execute (xpathSupport, (Node)contextItem,
                prefixResolver );
    } else {
        xobj = xpath.execute ( xpathSupport, DTM.NULL, prefixResolver );
    }

    return xobj;
}
 
源代码17 项目: jdk8u60   文件: UnionChildIterator.java
/**
 * Test whether a specified node is visible in the logical view of a
 * TreeWalker or NodeIterator. This function will be called by the
 * implementation of TreeWalker and NodeIterator; it is not intended to
 * be called directly from user code.
 * @param n  The node to check to see if it passes the filter or not.
 * @return  a constant to determine whether the node is accepted,
 *   rejected, or skipped, as defined  above .
 */
public short acceptNode(int n)
{
  XPathContext xctxt = getXPathContext();
  try
  {
    xctxt.pushCurrentNode(n);
    for (int i = 0; i < m_nodeTests.length; i++)
    {
      PredicatedNodeTest pnt = m_nodeTests[i];
      XObject score = pnt.execute(xctxt, n);
      if (score != NodeTest.SCORE_NONE)
      {
        // Note that we are assuming there are no positional predicates!
        if (pnt.getPredicateCount() > 0)
        {
          if (pnt.executePredicates(n, xctxt))
            return DTMIterator.FILTER_ACCEPT;
        }
        else
          return DTMIterator.FILTER_ACCEPT;

      }
    }
  }
  catch (javax.xml.transform.TransformerException se)
  {

    // TODO: Fix this.
    throw new RuntimeException(se.getMessage());
  }
  finally
  {
    xctxt.popCurrentNode();
  }
  return DTMIterator.FILTER_SKIP;
}
 
源代码18 项目: hottub   文件: XPathImpl.java
private Object getResultAsType( XObject resultObject, QName returnType )
    throws javax.xml.transform.TransformerException {
    // XPathConstants.STRING
    if ( returnType.equals( XPathConstants.STRING ) ) {
        return resultObject.str();
    }
    // XPathConstants.NUMBER
    if ( returnType.equals( XPathConstants.NUMBER ) ) {
        return new Double ( resultObject.num());
    }
    // XPathConstants.BOOLEAN
    if ( returnType.equals( XPathConstants.BOOLEAN ) ) {
        return new Boolean( resultObject.bool());
    }
    // XPathConstants.NODESET ---ORdered, UNOrdered???
    if ( returnType.equals( XPathConstants.NODESET ) ) {
        return resultObject.nodelist();
    }
    // XPathConstants.NODE
    if ( returnType.equals( XPathConstants.NODE ) ) {
        NodeIterator ni = resultObject.nodeset();
        //Return the first node, or null
        return ni.nextNode();
    }
    String fmsg = XSLMessages.createXPATHMessage(
            XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE,
            new Object[] { returnType.toString()});
    throw new IllegalArgumentException( fmsg );
}
 
源代码19 项目: TencentKona-8   文件: XPathAPI.java
/**
 *  Use an XPath string to select a nodelist.
 *  XPath namespace prefixes are resolved from the namespaceNode.
 *
 *  @param contextNode The node to start searching from.
 *  @param str A valid XPath string.
 *  @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
 *  @return A NodeIterator, should never be null.
 *
 * @throws TransformerException
 */
public static NodeIterator selectNodeIterator(
        Node contextNode, String str, Node namespaceNode)
          throws TransformerException
{

  // Execute the XPath, and have it return the result
  XObject list = eval(contextNode, str, namespaceNode);

  // Have the XObject return its result as a NodeSetDTM.
  return list.nodeset();
}
 
源代码20 项目: jdk1.8-source-analysis   文件: Arg.java
/**
 * Construct a parameter argument.
 *
 * @param qname Name of the argument, expressed as a QName object.
 * @param val Value of the argument, expressed as an XObject
 * @param isFromWithParam True if this is a parameter variable.
 */
public Arg(QName qname, XObject val, boolean isFromWithParam)
{

  m_qname = qname;
  m_val = val;
  m_isFromWithParam = isFromWithParam;
  m_isVisible = !isFromWithParam;
  m_expression = null;
}
 
源代码21 项目: openjdk-8-source   文件: UnionChildIterator.java
/**
 * Test whether a specified node is visible in the logical view of a
 * TreeWalker or NodeIterator. This function will be called by the
 * implementation of TreeWalker and NodeIterator; it is not intended to
 * be called directly from user code.
 * @param n  The node to check to see if it passes the filter or not.
 * @return  a constant to determine whether the node is accepted,
 *   rejected, or skipped, as defined  above .
 */
public short acceptNode(int n)
{
  XPathContext xctxt = getXPathContext();
  try
  {
    xctxt.pushCurrentNode(n);
    for (int i = 0; i < m_nodeTests.length; i++)
    {
      PredicatedNodeTest pnt = m_nodeTests[i];
      XObject score = pnt.execute(xctxt, n);
      if (score != NodeTest.SCORE_NONE)
      {
        // Note that we are assuming there are no positional predicates!
        if (pnt.getPredicateCount() > 0)
        {
          if (pnt.executePredicates(n, xctxt))
            return DTMIterator.FILTER_ACCEPT;
        }
        else
          return DTMIterator.FILTER_ACCEPT;

      }
    }
  }
  catch (javax.xml.transform.TransformerException se)
  {

    // TODO: Fix this.
    throw new RuntimeException(se.getMessage());
  }
  finally
  {
    xctxt.popCurrentNode();
  }
  return DTMIterator.FILTER_SKIP;
}
 
源代码22 项目: jdk8u60   文件: XPath.java
/**
 * Get the match score of the given node.
 *
 * @param xctxt XPath runtime context.
 * @param context The current source tree context node.
 *
 * @return score, one of {@link #MATCH_SCORE_NODETEST},
 * {@link #MATCH_SCORE_NONE}, {@link #MATCH_SCORE_OTHER},
 * or {@link #MATCH_SCORE_QNAME}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public double getMatchScore(XPathContext xctxt, int context)
        throws javax.xml.transform.TransformerException
{

  xctxt.pushCurrentNode(context);
  xctxt.pushCurrentExpressionNode(context);

  try
  {
    XObject score = m_mainExp.execute(xctxt);

    if (DEBUG_MATCHES)
    {
      DTM dtm = xctxt.getDTM(context);
      System.out.println("score: " + score.num() + " for "
                         + dtm.getNodeName(context) + " for xpath "
                         + this.getPatternString());
    }

    return score.num();
  }
  finally
  {
    xctxt.popCurrentNode();
    xctxt.popCurrentExpressionNode();
  }

  // return XPath.MATCH_SCORE_NONE;
}
 
源代码23 项目: hottub   文件: VariableStack.java
/**
 * Reset the stack to a start position.
 *
 * @return the total size of the execution stack.
 */
public void reset()
{

  _frameTop = 0;
  _linksTop = 0;

  // Adding one here to the stack of frame positions will allow us always
  // to look one under without having to check if we're at zero.
  // (As long as the caller doesn't screw up link/unlink.)
  _links[_linksTop++] = 0;
  _stackFrames = new XObject[_stackFrames.length];
}
 
源代码24 项目: openjdk-jdk8u   文件: UnionPattern.java
/**
 * Test a node to see if it matches any of the patterns in the union.
 *
 * @param xctxt XPath runtime context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XObject bestScore = null;
  int n = m_patterns.length;

  for (int i = 0; i < n; i++)
  {
    XObject score = m_patterns[i].execute(xctxt);

    if (score != NodeTest.SCORE_NONE)
    {
      if (null == bestScore)
        bestScore = score;
      else if (score.num() > bestScore.num())
        bestScore = score;
    }
  }

  if (null == bestScore)
  {
    bestScore = NodeTest.SCORE_NONE;
  }

  return bestScore;
}
 
源代码25 项目: hottub   文件: Equals.java
/**
 * Execute a binary operation by calling execute on each of the operands,
 * and then calling the operate method on the derived class.
 *
 *
 * @param xctxt The runtime execution context.
 *
 * @return The XObject result of the operation.
 *
 * @throws javax.xml.transform.TransformerException
 */
public boolean bool(XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{
  XObject left = m_left.execute(xctxt, true);
  XObject right = m_right.execute(xctxt, true);

  boolean result = left.equals(right) ? true : false;
      left.detach();
      right.detach();
  return result;
}
 
源代码26 项目: openjdk-jdk9   文件: XPathResultImpl.java
/**
 * Read the XObject and set values in accordance with the result type
 * @param resultObject  internal XPath result object
 * @throws TransformerException  if there is an error reading the XPath
 * result.
 */
private void getResult(XObject resultObject) throws TransformerException {
    switch (resultType) {
        case XObject.CLASS_BOOLEAN:
            boolValue = resultObject.bool();
            mapToType = XPathResultType.BOOLEAN;
            break;
        case XObject.CLASS_NUMBER:
            numValue = resultObject.num();
            mapToType = XPathResultType.NUMBER;
            break;
        case XObject.CLASS_STRING:
            strValue = resultObject.str();
            mapToType = XPathResultType.STRING;
            break;
        case XObject.CLASS_NODESET:
            mapToType = XPathResultType.NODESET;
            nodeList = resultObject.nodelist();
            break;
        case XObject.CLASS_RTREEFRAG:  //NODE
            mapToType = XPathResultType.NODE;
            NodeIterator ni = resultObject.nodeset();
            //Return the first node, or null
            node = ni.nextNode();
            break;
    }
}
 
源代码27 项目: TencentKona-8   文件: XPathAPI.java
/**
 *  Use an XPath string to select a nodelist.
 *  XPath namespace prefixes are resolved from the namespaceNode.
 *
 *  @param contextNode The node to start searching from.
 *  @param str A valid XPath string.
 *  @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
 *  @return A NodeIterator, should never be null.
 *
 * @throws TransformerException
 */
public static NodeList selectNodeList(
        Node contextNode, String str, Node namespaceNode)
          throws TransformerException
{

  // Execute the XPath, and have it return the result
  XObject list = eval(contextNode, str, namespaceNode);

  // Return a NodeList.
  return list.nodelist();
}
 
源代码28 项目: hottub   文件: FuncRound.java
/**
 * 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
{
        final XObject obj = m_arg0.execute(xctxt);
        final double val= obj.num();
        if (val >= -0.5 && val < 0) return new XNumber(-0.0);
        if (val == 0.0) return new XNumber(val);
        return new XNumber(java.lang.Math.floor(val
                                          + 0.5));
}
 
源代码29 项目: jdk1.8-source-analysis   文件: XPathAPI.java
/**
 *  Use an XPath string to select a nodelist.
 *  XPath namespace prefixes are resolved from the namespaceNode.
 *
 *  @param contextNode The node to start searching from.
 *  @param str A valid XPath string.
 *  @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
 *  @return A NodeIterator, should never be null.
 *
 * @throws TransformerException
 */
public static NodeList selectNodeList(
        Node contextNode, String str, Node namespaceNode)
          throws TransformerException
{

  // Execute the XPath, and have it return the result
  XObject list = eval(contextNode, str, namespaceNode);

  // Return a NodeList.
  return list.nodelist();
}
 
源代码30 项目: hottub   文件: FunctionPattern.java
/**
 * Test a node to see if it matches the given node test.
 *
 * @param xctxt XPath runtime context.
 *
 * @return {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NODETEST},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NONE},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_NSWILD},
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_QNAME}, or
 *         {@link com.sun.org.apache.xpath.internal.patterns.NodeTest#SCORE_OTHER}.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt, int context,
                       DTM dtm, int expType)
        throws javax.xml.transform.TransformerException
{

  DTMIterator nl = m_functionExpr.asIterator(xctxt, context);
  XNumber score = SCORE_NONE;

  if (null != nl)
  {
    int n;

    while (DTM.NULL != (n = nl.nextNode()))
    {
      score = (n == context) ? SCORE_OTHER : SCORE_NONE;

      if (score == SCORE_OTHER)
      {
        context = n;

        break;
      }
    }

    nl.detach();
  }

  return score;
}