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

The following examples show how to use com.sun.org.apache.xpath.internal.objects.XObject#nodelist() . 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: XPathImplUtil.java    From openjdk-jdk9 with GNU General Public License v2.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 2
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 3
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 4
Source File: XPathImpl.java    From openjdk-jdk8u 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 5
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  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();
}
 
Example 6
Source File: XPathAPI.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 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();
}
 
Example 7
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 8
Source File: CachedXPathAPI.java    From openjdk-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  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();
}
 
Example 9
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 10
Source File: XPathExpressionImpl.java    From openjdk-jdk8u 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 11
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 12
Source File: XPathResultImpl.java    From Bytecoder with Apache License 2.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 13
Source File: XPathExpressionImpl.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();
    }
    // 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 14
Source File: XPathExpressionImpl.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();
    }
    // 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 15
Source File: CachedXPathAPI.java    From openjdk-jdk8u 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  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();
}
 
Example 16
Source File: XPathAPI.java    From openjdk-jdk9 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 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();
}
 
Example 17
Source File: XalanXPathAPI.java    From hottub with GNU General Public License v2.0 3 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 xpathnode
 *  @param str
 *  @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 NodeList selectNodeList(
    Node contextNode, Node xpathnode, String str, Node namespaceNode
) throws TransformerException {

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

    // Return a NodeList.
    return list.nodelist();
}
 
Example 18
Source File: XalanXPathAPI.java    From openjdk-8-source with GNU General Public License v2.0 3 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 xpathnode
 *  @param str
 *  @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 NodeList selectNodeList(
    Node contextNode, Node xpathnode, String str, Node namespaceNode
) throws TransformerException {

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

    // Return a NodeList.
    return list.nodelist();
}
 
Example 19
Source File: XalanXPathAPI.java    From JDKSourceCode1.8 with MIT License 3 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 xpathnode
 *  @param str
 *  @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 NodeList selectNodeList(
    Node contextNode, Node xpathnode, String str, Node namespaceNode
) throws TransformerException {

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

    // Return a NodeList.
    return list.nodelist();
}
 
Example 20
Source File: XalanXPathAPI.java    From jdk8u-jdk with GNU General Public License v2.0 3 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 xpathnode
 *  @param str
 *  @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 NodeList selectNodeList(
    Node contextNode, Node xpathnode, String str, Node namespaceNode
) throws TransformerException {

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

    // Return a NodeList.
    return list.nodelist();
}