Java Code Examples for com.sun.org.apache.xpath.internal.objects.XObject#nodeset()

The following examples show how to use com.sun.org.apache.xpath.internal.objects.XObject#nodeset() . 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: XPathAPI.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  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();
}
 
Example 2
Source File: XPathImplUtil.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Get result depending on the QName type defined in XPathConstants
 * @param resultObject the result of an evaluation
 * @param returnType the return type
 * @return result per the return type
 * @throws TransformerException if the result can not be converted to
 * the specified return type.
 */
Object getResultAsType(XObject resultObject, QName returnType)
    throws TransformerException {
    // XPathConstants.STRING
    if (returnType.equals(XPathConstants.STRING)) {
        return resultObject.str();
    }
    // XPathConstants.NUMBER
    if (returnType.equals(XPathConstants.NUMBER)) {
        return resultObject.num();
    }
    // XPathConstants.BOOLEAN
    if (returnType.equals(XPathConstants.BOOLEAN)) {
        return 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();
    }
    // If isSupported check is already done then the execution path
    // shouldn't come here. Being defensive
    String fmsg = XSLMessages.createXPATHMessage(
            XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE,
            new Object[] { returnType.toString()});
    throw new IllegalArgumentException (fmsg);
}
 
Example 3
Source File: XPathAPI.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  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();
}
 
Example 4
Source File: XPathResultImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
    }
}
 
Example 5
Source File: CachedXPathAPI.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  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  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();
}
 
Example 6
Source File: XPathImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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 );
}
 
Example 7
Source File: XPathExpressionImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
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();
    }
    // If isSupported check is already done then the execution path
    // shouldn't come here. Being defensive
    String fmsg = XSLMessages.createXPATHMessage(
            XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE,
            new Object[] { returnType.toString()});
    throw new IllegalArgumentException ( fmsg );
}
 
Example 8
Source File: XPathImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
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 );
}
 
Example 9
Source File: XPathAPI.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 *  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();
}
 
Example 10
Source File: CachedXPathAPI.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  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  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();
}
 
Example 11
Source File: XPathResultImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Read the internal result object and return the value in accordance with
 * the type specified.
 *
 * @param <T> The expected class type.
 * @param resultObject internal XPath result object
 * @param type the class type
 * @return The value of the result, null in case of unexpected type.
 * @throws TransformerException  if there is an error reading the XPath
 * result.
 */
static <T> T getValue(XObject resultObject, Class<T> type) throws TransformerException {
    Objects.requireNonNull(type);
    if (type.isAssignableFrom(XPathEvaluationResult.class)) {
        return type.cast(new XPathResultImpl<T>(resultObject, type));
    }
    int resultType = classToInternalType(type);
    switch (resultType) {
        case XObject.CLASS_BOOLEAN:
            return type.cast(resultObject.bool());
        case XObject.CLASS_NUMBER:
            if (Double.class.isAssignableFrom(type)) {
                return type.cast(resultObject.num());
            } else if (Integer.class.isAssignableFrom(type)) {
                return type.cast((int)resultObject.num());
            } else if (Long.class.isAssignableFrom(type)) {
                return type.cast((long)resultObject.num());
            }
            /*
              This is to suppress warnings. By the current specification,
            among numeric types, only Double, Integer and Long are supported.
            */
            break;
        case XObject.CLASS_STRING:
            return type.cast(resultObject.str());
        case XObject.CLASS_NODESET:
            XPathNodes nodeSet = new XPathNodesImpl(resultObject.nodelist(),
                    Node.class);
            return type.cast(nodeSet);
        case XObject.CLASS_RTREEFRAG:  //NODE
            NodeIterator ni = resultObject.nodeset();
            //Return the first node, or null
            return type.cast(ni.nextNode());
    }

    return null;
}
 
Example 12
Source File: XPathImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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 );
}
 
Example 13
Source File: XPathImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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 );
}
 
Example 14
Source File: CachedXPathAPI.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  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  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();
}
 
Example 15
Source File: XPathExpressionImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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();
    }
    // If isSupported check is already done then the execution path
    // shouldn't come here. Being defensive
    String fmsg = XSLMessages.createXPATHMessage(
            XPATHErrorResources.ER_UNSUPPORTED_RETURN_TYPE,
            new Object[] { returnType.toString()});
    throw new IllegalArgumentException ( fmsg );
}
 
Example 16
Source File: XPathImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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 );
}
 
Example 17
Source File: CachedXPathAPI.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  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  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();
}
 
Example 18
Source File: XPathImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
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 );
}
 
Example 19
Source File: CachedXPathAPI.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 *  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  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();
}
 
Example 20
Source File: CachedXPathAPI.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 *  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  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();
}