org.w3c.dom.xpath.XPathException Java Examples

The following examples show how to use org.w3c.dom.xpath.XPathException. 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: XPathEvaluatorImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
* Creates a parsed XPath expression with resolved namespaces. This is
* useful when an expression will be reused in an application since it
* makes it possible to compile the expression string into a more
* efficient internal form and preresolve all namespace prefixes which
* occur within the expression.
*
* @param expression The XPath expression string to be parsed.
* @param resolver The <code>resolver</code> permits translation of
*   prefixes within the XPath expression into appropriate namespace URIs
*   . If this is specified as <code>null</code>, any namespace prefix
*   within the expression will result in <code>DOMException</code>
*   being thrown with the code <code>NAMESPACE_ERR</code>.
* @return The compiled form of the XPath expression.
* @exception XPathException
*   INVALID_EXPRESSION_ERR: Raised if the expression is not legal
*   according to the rules of the <code>XPathEvaluator</code>i
* @exception DOMException
*   NAMESPACE_ERR: Raised if the expression contains namespace prefixes
*   which cannot be resolved by the specified
*   <code>XPathNSResolver</code>.
*
    * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
    */
   public XPathExpression createExpression(
           String expression,
           XPathNSResolver resolver)
           throws XPathException, DOMException {

           try {

                   // If the resolver is null, create a dummy prefix resolver
                   XPath xpath =  new XPath(expression,null,
                        ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
                         XPath.SELECT);

       return new XPathExpressionImpl(xpath, m_doc);

           } catch (TransformerException e) {
                   // Need to pass back exception code DOMException.NAMESPACE_ERR also.
                   // Error found in DOM Level 3 XPath Test Suite.
                   if(e instanceof XPathStylesheetDOM3Exception)
                           throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
                   else
                           throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());

           }
   }
 
Example #2
Source File: XPathEvaluatorImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
* Creates a parsed XPath expression with resolved namespaces. This is
* useful when an expression will be reused in an application since it
* makes it possible to compile the expression string into a more
* efficient internal form and preresolve all namespace prefixes which
* occur within the expression.
*
* @param expression The XPath expression string to be parsed.
* @param resolver The <code>resolver</code> permits translation of
*   prefixes within the XPath expression into appropriate namespace URIs
*   . If this is specified as <code>null</code>, any namespace prefix
*   within the expression will result in <code>DOMException</code>
*   being thrown with the code <code>NAMESPACE_ERR</code>.
* @return The compiled form of the XPath expression.
* @exception XPathException
*   INVALID_EXPRESSION_ERR: Raised if the expression is not legal
*   according to the rules of the <code>XPathEvaluator</code>i
* @exception DOMException
*   NAMESPACE_ERR: Raised if the expression contains namespace prefixes
*   which cannot be resolved by the specified
*   <code>XPathNSResolver</code>.
*
    * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
    */
   public XPathExpression createExpression(
           String expression,
           XPathNSResolver resolver)
           throws XPathException, DOMException {

           try {

                   // If the resolver is null, create a dummy prefix resolver
                   XPath xpath =  new XPath(expression,null,
                        ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
                         XPath.SELECT);

       return new XPathExpressionImpl(xpath, m_doc);

           } catch (TransformerException e) {
                   // Need to pass back exception code DOMException.NAMESPACE_ERR also.
                   // Error found in DOM Level 3 XPath Test Suite.
                   if(e instanceof XPathStylesheetDOM3Exception)
                           throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
                   else
                           throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());

           }
   }
 
Example #3
Source File: XPathEvaluatorImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
* Creates a parsed XPath expression with resolved namespaces. This is
* useful when an expression will be reused in an application since it
* makes it possible to compile the expression string into a more
* efficient internal form and preresolve all namespace prefixes which
* occur within the expression.
*
* @param expression The XPath expression string to be parsed.
* @param resolver The <code>resolver</code> permits translation of
*   prefixes within the XPath expression into appropriate namespace URIs
*   . If this is specified as <code>null</code>, any namespace prefix
*   within the expression will result in <code>DOMException</code>
*   being thrown with the code <code>NAMESPACE_ERR</code>.
* @return The compiled form of the XPath expression.
* @exception XPathException
*   INVALID_EXPRESSION_ERR: Raised if the expression is not legal
*   according to the rules of the <code>XPathEvaluator</code>i
* @exception DOMException
*   NAMESPACE_ERR: Raised if the expression contains namespace prefixes
*   which cannot be resolved by the specified
*   <code>XPathNSResolver</code>.
*
    * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
    */
   public XPathExpression createExpression(
           String expression,
           XPathNSResolver resolver)
           throws XPathException, DOMException {

           try {

                   // If the resolver is null, create a dummy prefix resolver
                   XPath xpath =  new XPath(expression,null,
                        ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
                         XPath.SELECT);

       return new XPathExpressionImpl(xpath, m_doc);

           } catch (TransformerException e) {
                   // Need to pass back exception code DOMException.NAMESPACE_ERR also.
                   // Error found in DOM Level 3 XPath Test Suite.
                   if(e instanceof XPathStylesheetDOM3Exception)
                           throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
                   else
                           throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());

           }
   }
 
Example #4
Source File: XPathResultImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Returns the <code>index</code>th item in the snapshot collection. If
     * <code>index</code> is greater than or equal to the number of nodes in
     * the list, this method returns <code>null</code>. Unlike the iterator
     * result, the snapshot does not become invalid, but may not correspond
     * to the current document if it is mutated.
     * @param index Index into the snapshot collection.
     * @return The node at the <code>index</code>th position in the
     *   <code>NodeList</code>, or <code>null</code> if that is not a valid
     *   index.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or
     *   <code>ORDERED_NODE_SNAPSHOT_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#snapshotItem(int)
         */
        public Node snapshotItem(int index) throws XPathException {

                if ((m_resultType != UNORDERED_NODE_SNAPSHOT_TYPE) &&
                    (m_resultType != ORDERED_NODE_SNAPSHOT_TYPE)) {
           String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NON_SNAPSHOT_TYPE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
           throw new XPathException(XPathException.TYPE_ERR, fmsg);
//              "The method snapshotItem cannot be called on the XPathResult of XPath expression {0} because its XPathResultType is {1}.
//              This method applies only to types UNORDERED_NODE_SNAPSHOT_TYPE and ORDERED_NODE_SNAPSHOT_TYPE."},
            }

        Node node = m_list.item(index);

        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
            return node;
        }
        }
 
Example #5
Source File: XPathResultImpl.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
     * Returns the <code>index</code>th item in the snapshot collection. If
     * <code>index</code> is greater than or equal to the number of nodes in
     * the list, this method returns <code>null</code>. Unlike the iterator
     * result, the snapshot does not become invalid, but may not correspond
     * to the current document if it is mutated.
     * @param index Index into the snapshot collection.
     * @return The node at the <code>index</code>th position in the
     *   <code>NodeList</code>, or <code>null</code> if that is not a valid
     *   index.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or
     *   <code>ORDERED_NODE_SNAPSHOT_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#snapshotItem(int)
         */
        public Node snapshotItem(int index) throws XPathException {

                if ((m_resultType != UNORDERED_NODE_SNAPSHOT_TYPE) &&
                    (m_resultType != ORDERED_NODE_SNAPSHOT_TYPE)) {
           String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NON_SNAPSHOT_TYPE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
           throw new XPathException(XPathException.TYPE_ERR, fmsg);
//              "The method snapshotItem cannot be called on the XPathResult of XPath expression {0} because its XPathResultType is {1}.
//              This method applies only to types UNORDERED_NODE_SNAPSHOT_TYPE and ORDERED_NODE_SNAPSHOT_TYPE."},
            }

        Node node = m_list.item(index);

        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
            return node;
        }
        }
 
Example #6
Source File: XPathResultImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Returns the <code>index</code>th item in the snapshot collection. If
     * <code>index</code> is greater than or equal to the number of nodes in
     * the list, this method returns <code>null</code>. Unlike the iterator
     * result, the snapshot does not become invalid, but may not correspond
     * to the current document if it is mutated.
     * @param index Index into the snapshot collection.
     * @return The node at the <code>index</code>th position in the
     *   <code>NodeList</code>, or <code>null</code> if that is not a valid
     *   index.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or
     *   <code>ORDERED_NODE_SNAPSHOT_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#snapshotItem(int)
         */
        public Node snapshotItem(int index) throws XPathException {

                if ((m_resultType != UNORDERED_NODE_SNAPSHOT_TYPE) &&
                    (m_resultType != ORDERED_NODE_SNAPSHOT_TYPE)) {
           String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NON_SNAPSHOT_TYPE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
           throw new XPathException(XPathException.TYPE_ERR, fmsg);
//              "The method snapshotItem cannot be called on the XPathResult of XPath expression {0} because its XPathResultType is {1}.
//              This method applies only to types UNORDERED_NODE_SNAPSHOT_TYPE and ORDERED_NODE_SNAPSHOT_TYPE."},
            }

        Node node = m_list.item(index);

        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
            return node;
        }
        }
 
Example #7
Source File: XPathResultImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Returns the <code>index</code>th item in the snapshot collection. If
     * <code>index</code> is greater than or equal to the number of nodes in
     * the list, this method returns <code>null</code>. Unlike the iterator
     * result, the snapshot does not become invalid, but may not correspond
     * to the current document if it is mutated.
     * @param index Index into the snapshot collection.
     * @return The node at the <code>index</code>th position in the
     *   <code>NodeList</code>, or <code>null</code> if that is not a valid
     *   index.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or
     *   <code>ORDERED_NODE_SNAPSHOT_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#snapshotItem(int)
         */
        public Node snapshotItem(int index) throws XPathException {

                if ((m_resultType != UNORDERED_NODE_SNAPSHOT_TYPE) &&
                    (m_resultType != ORDERED_NODE_SNAPSHOT_TYPE)) {
           String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NON_SNAPSHOT_TYPE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
           throw new XPathException(XPathException.TYPE_ERR, fmsg);
//              "The method snapshotItem cannot be called on the XPathResult of XPath expression {0} because its XPathResultType is {1}.
//              This method applies only to types UNORDERED_NODE_SNAPSHOT_TYPE and ORDERED_NODE_SNAPSHOT_TYPE."},
            }

        Node node = m_list.item(index);

        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
            return node;
        }
        }
 
Example #8
Source File: XPathResultImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Returns the <code>index</code>th item in the snapshot collection. If
     * <code>index</code> is greater than or equal to the number of nodes in
     * the list, this method returns <code>null</code>. Unlike the iterator
     * result, the snapshot does not become invalid, but may not correspond
     * to the current document if it is mutated.
     * @param index Index into the snapshot collection.
     * @return The node at the <code>index</code>th position in the
     *   <code>NodeList</code>, or <code>null</code> if that is not a valid
     *   index.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or
     *   <code>ORDERED_NODE_SNAPSHOT_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#snapshotItem(int)
         */
        public Node snapshotItem(int index) throws XPathException {

                if ((m_resultType != UNORDERED_NODE_SNAPSHOT_TYPE) &&
                    (m_resultType != ORDERED_NODE_SNAPSHOT_TYPE)) {
           String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NON_SNAPSHOT_TYPE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
           throw new XPathException(XPathException.TYPE_ERR, fmsg);
//              "The method snapshotItem cannot be called on the XPathResult of XPath expression {0} because its XPathResultType is {1}.
//              This method applies only to types UNORDERED_NODE_SNAPSHOT_TYPE and ORDERED_NODE_SNAPSHOT_TYPE."},
            }

        Node node = m_list.item(index);

        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
            return node;
        }
        }
 
Example #9
Source File: XPathEvaluatorImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
* Creates a parsed XPath expression with resolved namespaces. This is
* useful when an expression will be reused in an application since it
* makes it possible to compile the expression string into a more
* efficient internal form and preresolve all namespace prefixes which
* occur within the expression.
*
* @param expression The XPath expression string to be parsed.
* @param resolver The <code>resolver</code> permits translation of
*   prefixes within the XPath expression into appropriate namespace URIs
*   . If this is specified as <code>null</code>, any namespace prefix
*   within the expression will result in <code>DOMException</code>
*   being thrown with the code <code>NAMESPACE_ERR</code>.
* @return The compiled form of the XPath expression.
* @exception XPathException
*   INVALID_EXPRESSION_ERR: Raised if the expression is not legal
*   according to the rules of the <code>XPathEvaluator</code>i
* @exception DOMException
*   NAMESPACE_ERR: Raised if the expression contains namespace prefixes
*   which cannot be resolved by the specified
*   <code>XPathNSResolver</code>.
*
    * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
    */
   public XPathExpression createExpression(
           String expression,
           XPathNSResolver resolver)
           throws XPathException, DOMException {

           try {

                   // If the resolver is null, create a dummy prefix resolver
                   XPath xpath =  new XPath(expression,null,
                        ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
                         XPath.SELECT);

       return new XPathExpressionImpl(xpath, m_doc);

           } catch (TransformerException e) {
                   // Need to pass back exception code DOMException.NAMESPACE_ERR also.
                   // Error found in DOM Level 3 XPath Test Suite.
                   if(e instanceof XPathStylesheetDOM3Exception)
                           throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
                   else
                           throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());

           }
   }
 
Example #10
Source File: XPathResultImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Returns the <code>index</code>th item in the snapshot collection. If
     * <code>index</code> is greater than or equal to the number of nodes in
     * the list, this method returns <code>null</code>. Unlike the iterator
     * result, the snapshot does not become invalid, but may not correspond
     * to the current document if it is mutated.
     * @param index Index into the snapshot collection.
     * @return The node at the <code>index</code>th position in the
     *   <code>NodeList</code>, or <code>null</code> if that is not a valid
     *   index.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or
     *   <code>ORDERED_NODE_SNAPSHOT_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#snapshotItem(int)
         */
        public Node snapshotItem(int index) throws XPathException {

                if ((m_resultType != UNORDERED_NODE_SNAPSHOT_TYPE) &&
                    (m_resultType != ORDERED_NODE_SNAPSHOT_TYPE)) {
           String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NON_SNAPSHOT_TYPE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
           throw new XPathException(XPathException.TYPE_ERR, fmsg);
//              "The method snapshotItem cannot be called on the XPathResult of XPath expression {0} because its XPathResultType is {1}.
//              This method applies only to types UNORDERED_NODE_SNAPSHOT_TYPE and ORDERED_NODE_SNAPSHOT_TYPE."},
            }

        Node node = m_list.item(index);

        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
            return node;
        }
        }
 
Example #11
Source File: XPathEvaluatorImpl.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
* Creates a parsed XPath expression with resolved namespaces. This is
* useful when an expression will be reused in an application since it
* makes it possible to compile the expression string into a more
* efficient internal form and preresolve all namespace prefixes which
* occur within the expression.
*
* @param expression The XPath expression string to be parsed.
* @param resolver The <code>resolver</code> permits translation of
*   prefixes within the XPath expression into appropriate namespace URIs
*   . If this is specified as <code>null</code>, any namespace prefix
*   within the expression will result in <code>DOMException</code>
*   being thrown with the code <code>NAMESPACE_ERR</code>.
* @return The compiled form of the XPath expression.
* @exception XPathException
*   INVALID_EXPRESSION_ERR: Raised if the expression is not legal
*   according to the rules of the <code>XPathEvaluator</code>i
* @exception DOMException
*   NAMESPACE_ERR: Raised if the expression contains namespace prefixes
*   which cannot be resolved by the specified
*   <code>XPathNSResolver</code>.
*
    * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
    */
   public XPathExpression createExpression(
           String expression,
           XPathNSResolver resolver)
           throws XPathException, DOMException {

           try {

                   // If the resolver is null, create a dummy prefix resolver
                   XPath xpath =  new XPath(expression,null,
                        ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
                         XPath.SELECT);

       return new XPathExpressionImpl(xpath, m_doc);

           } catch (TransformerException e) {
                   // Need to pass back exception code DOMException.NAMESPACE_ERR also.
                   // Error found in DOM Level 3 XPath Test Suite.
                   if(e instanceof XPathStylesheetDOM3Exception)
                           throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
                   else
                           throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());

           }
   }
 
Example #12
Source File: XPathEvaluatorImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
* Creates a parsed XPath expression with resolved namespaces. This is
* useful when an expression will be reused in an application since it
* makes it possible to compile the expression string into a more
* efficient internal form and preresolve all namespace prefixes which
* occur within the expression.
*
* @param expression The XPath expression string to be parsed.
* @param resolver The <code>resolver</code> permits translation of
*   prefixes within the XPath expression into appropriate namespace URIs
*   . If this is specified as <code>null</code>, any namespace prefix
*   within the expression will result in <code>DOMException</code>
*   being thrown with the code <code>NAMESPACE_ERR</code>.
* @return The compiled form of the XPath expression.
* @exception XPathException
*   INVALID_EXPRESSION_ERR: Raised if the expression is not legal
*   according to the rules of the <code>XPathEvaluator</code>i
* @exception DOMException
*   NAMESPACE_ERR: Raised if the expression contains namespace prefixes
*   which cannot be resolved by the specified
*   <code>XPathNSResolver</code>.
*
    * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
    */
   public XPathExpression createExpression(
           String expression,
           XPathNSResolver resolver)
           throws XPathException, DOMException {

           try {

                   // If the resolver is null, create a dummy prefix resolver
                   XPath xpath =  new XPath(expression,null,
                        ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
                         XPath.SELECT);

       return new XPathExpressionImpl(xpath, m_doc);

           } catch (TransformerException e) {
                   // Need to pass back exception code DOMException.NAMESPACE_ERR also.
                   // Error found in DOM Level 3 XPath Test Suite.
                   if(e instanceof XPathStylesheetDOM3Exception)
                           throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
                   else
                           throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());

           }
   }
 
Example #13
Source File: XPathResultImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Returns the <code>index</code>th item in the snapshot collection. If
     * <code>index</code> is greater than or equal to the number of nodes in
     * the list, this method returns <code>null</code>. Unlike the iterator
     * result, the snapshot does not become invalid, but may not correspond
     * to the current document if it is mutated.
     * @param index Index into the snapshot collection.
     * @return The node at the <code>index</code>th position in the
     *   <code>NodeList</code>, or <code>null</code> if that is not a valid
     *   index.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or
     *   <code>ORDERED_NODE_SNAPSHOT_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#snapshotItem(int)
         */
        public Node snapshotItem(int index) throws XPathException {

                if ((m_resultType != UNORDERED_NODE_SNAPSHOT_TYPE) &&
                    (m_resultType != ORDERED_NODE_SNAPSHOT_TYPE)) {
           String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NON_SNAPSHOT_TYPE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
           throw new XPathException(XPathException.TYPE_ERR, fmsg);
//              "The method snapshotItem cannot be called on the XPathResult of XPath expression {0} because its XPathResultType is {1}.
//              This method applies only to types UNORDERED_NODE_SNAPSHOT_TYPE and ORDERED_NODE_SNAPSHOT_TYPE."},
            }

        Node node = m_list.item(index);

        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
            return node;
        }
        }
 
Example #14
Source File: XPathResultImpl.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
     * Returns the <code>index</code>th item in the snapshot collection. If
     * <code>index</code> is greater than or equal to the number of nodes in
     * the list, this method returns <code>null</code>. Unlike the iterator
     * result, the snapshot does not become invalid, but may not correspond
     * to the current document if it is mutated.
     * @param index Index into the snapshot collection.
     * @return The node at the <code>index</code>th position in the
     *   <code>NodeList</code>, or <code>null</code> if that is not a valid
     *   index.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or
     *   <code>ORDERED_NODE_SNAPSHOT_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#snapshotItem(int)
         */
        public Node snapshotItem(int index) throws XPathException {

                if ((m_resultType != UNORDERED_NODE_SNAPSHOT_TYPE) &&
                    (m_resultType != ORDERED_NODE_SNAPSHOT_TYPE)) {
           String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NON_SNAPSHOT_TYPE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
           throw new XPathException(XPathException.TYPE_ERR, fmsg);
//              "The method snapshotItem cannot be called on the XPathResult of XPath expression {0} because its XPathResultType is {1}.
//              This method applies only to types UNORDERED_NODE_SNAPSHOT_TYPE and ORDERED_NODE_SNAPSHOT_TYPE."},
            }

        Node node = m_list.item(index);

        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
            return node;
        }
        }
 
Example #15
Source File: XPathEvaluatorImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
* Creates a parsed XPath expression with resolved namespaces. This is
* useful when an expression will be reused in an application since it
* makes it possible to compile the expression string into a more
* efficient internal form and preresolve all namespace prefixes which
* occur within the expression.
*
* @param expression The XPath expression string to be parsed.
* @param resolver The <code>resolver</code> permits translation of
*   prefixes within the XPath expression into appropriate namespace URIs
*   . If this is specified as <code>null</code>, any namespace prefix
*   within the expression will result in <code>DOMException</code>
*   being thrown with the code <code>NAMESPACE_ERR</code>.
* @return The compiled form of the XPath expression.
* @exception XPathException
*   INVALID_EXPRESSION_ERR: Raised if the expression is not legal
*   according to the rules of the <code>XPathEvaluator</code>i
* @exception DOMException
*   NAMESPACE_ERR: Raised if the expression contains namespace prefixes
*   which cannot be resolved by the specified
*   <code>XPathNSResolver</code>.
*
    * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
    */
   public XPathExpression createExpression(
           String expression,
           XPathNSResolver resolver)
           throws XPathException, DOMException {

           try {

                   // If the resolver is null, create a dummy prefix resolver
                   XPath xpath =  new XPath(expression,null,
                        ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
                         XPath.SELECT);

       return new XPathExpressionImpl(xpath, m_doc);

           } catch (TransformerException e) {
                   // Need to pass back exception code DOMException.NAMESPACE_ERR also.
                   // Error found in DOM Level 3 XPath Test Suite.
                   if(e instanceof XPathStylesheetDOM3Exception)
                           throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
                   else
                           throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());

           }
   }
 
Example #16
Source File: XPathEvaluatorImpl.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
* Creates a parsed XPath expression with resolved namespaces. This is
* useful when an expression will be reused in an application since it
* makes it possible to compile the expression string into a more
* efficient internal form and preresolve all namespace prefixes which
* occur within the expression.
*
* @param expression The XPath expression string to be parsed.
* @param resolver The <code>resolver</code> permits translation of
*   prefixes within the XPath expression into appropriate namespace URIs
*   . If this is specified as <code>null</code>, any namespace prefix
*   within the expression will result in <code>DOMException</code>
*   being thrown with the code <code>NAMESPACE_ERR</code>.
* @return The compiled form of the XPath expression.
* @exception XPathException
*   INVALID_EXPRESSION_ERR: Raised if the expression is not legal
*   according to the rules of the <code>XPathEvaluator</code>i
* @exception DOMException
*   NAMESPACE_ERR: Raised if the expression contains namespace prefixes
*   which cannot be resolved by the specified
*   <code>XPathNSResolver</code>.
*
    * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
    */
   public XPathExpression createExpression(
           String expression,
           XPathNSResolver resolver)
           throws XPathException, DOMException {

           try {

                   // If the resolver is null, create a dummy prefix resolver
                   XPath xpath =  new XPath(expression,null,
                        ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
                         XPath.SELECT);

       return new XPathExpressionImpl(xpath, m_doc);

           } catch (TransformerException e) {
                   // Need to pass back exception code DOMException.NAMESPACE_ERR also.
                   // Error found in DOM Level 3 XPath Test Suite.
                   if(e instanceof XPathStylesheetDOM3Exception)
                           throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
                   else
                           throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());

           }
   }
 
Example #17
Source File: XPathEvaluatorImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
* Creates a parsed XPath expression with resolved namespaces. This is
* useful when an expression will be reused in an application since it
* makes it possible to compile the expression string into a more
* efficient internal form and preresolve all namespace prefixes which
* occur within the expression.
*
* @param expression The XPath expression string to be parsed.
* @param resolver The <code>resolver</code> permits translation of
*   prefixes within the XPath expression into appropriate namespace URIs
*   . If this is specified as <code>null</code>, any namespace prefix
*   within the expression will result in <code>DOMException</code>
*   being thrown with the code <code>NAMESPACE_ERR</code>.
* @return The compiled form of the XPath expression.
* @exception XPathException
*   INVALID_EXPRESSION_ERR: Raised if the expression is not legal
*   according to the rules of the <code>XPathEvaluator</code>i
* @exception DOMException
*   NAMESPACE_ERR: Raised if the expression contains namespace prefixes
*   which cannot be resolved by the specified
*   <code>XPathNSResolver</code>.
*
    * @see org.w3c.dom.xpath.XPathEvaluator#createExpression(String, XPathNSResolver)
    */
   public XPathExpression createExpression(
           String expression,
           XPathNSResolver resolver)
           throws XPathException, DOMException {

           try {

                   // If the resolver is null, create a dummy prefix resolver
                   XPath xpath =  new XPath(expression,null,
                        ((null == resolver) ? new DummyPrefixResolver() : ((PrefixResolver)resolver)),
                         XPath.SELECT);

       return new XPathExpressionImpl(xpath, m_doc);

           } catch (TransformerException e) {
                   // Need to pass back exception code DOMException.NAMESPACE_ERR also.
                   // Error found in DOM Level 3 XPath Test Suite.
                   if(e instanceof XPathStylesheetDOM3Exception)
                           throw new DOMException(DOMException.NAMESPACE_ERR,e.getMessageAndLocation());
                   else
                           throw new XPathException(XPathException.INVALID_EXPRESSION_ERR,e.getMessageAndLocation());

           }
   }
 
Example #18
Source File: XPathResultImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Returns the <code>index</code>th item in the snapshot collection. If
     * <code>index</code> is greater than or equal to the number of nodes in
     * the list, this method returns <code>null</code>. Unlike the iterator
     * result, the snapshot does not become invalid, but may not correspond
     * to the current document if it is mutated.
     * @param index Index into the snapshot collection.
     * @return The node at the <code>index</code>th position in the
     *   <code>NodeList</code>, or <code>null</code> if that is not a valid
     *   index.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or
     *   <code>ORDERED_NODE_SNAPSHOT_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#snapshotItem(int)
         */
        public Node snapshotItem(int index) throws XPathException {

                if ((m_resultType != UNORDERED_NODE_SNAPSHOT_TYPE) &&
                    (m_resultType != ORDERED_NODE_SNAPSHOT_TYPE)) {
           String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_NON_SNAPSHOT_TYPE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
           throw new XPathException(XPathException.TYPE_ERR, fmsg);
//              "The method snapshotItem cannot be called on the XPathResult of XPath expression {0} because its XPathResultType is {1}.
//              This method applies only to types UNORDERED_NODE_SNAPSHOT_TYPE and ORDERED_NODE_SNAPSHOT_TYPE."},
            }

        Node node = m_list.item(index);

        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
            return node;
        }
        }
 
Example #19
Source File: XPathResultImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
         * @see org.w3c.dom.xpath.XPathResult#getBooleanValue()
         */
        public boolean getBooleanValue() throws XPathException {
                if (getResultType() != BOOLEAN_TYPE) {
                        String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_BOOLEAN, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
                        throw new XPathException(XPathException.TYPE_ERR,fmsg);
//              "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a boolean."
                } else {
                        try {
                           return m_resultObj.bool();
                        } catch (TransformerException e) {
                                // Type check above should prevent this exception from occurring.
                                throw new XPathException(XPathException.TYPE_ERR,e.getMessage());
                        }
                }
        }
 
Example #20
Source File: XPathResultImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
         * The number of nodes in the result snapshot. Valid values for
     * snapshotItem indices are <code>0</code> to
     * <code>snapshotLength-1</code> inclusive.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or
     *   <code>ORDERED_NODE_SNAPSHOT_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#getSnapshotLength()
         */
        public int getSnapshotLength() throws XPathException {

                if ((m_resultType != UNORDERED_NODE_SNAPSHOT_TYPE) &&
                    (m_resultType != ORDERED_NODE_SNAPSHOT_TYPE)) {
                                String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_GET_SNAPSHOT_LENGTH, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
                                throw new XPathException(XPathException.TYPE_ERR,fmsg);
//                              "The method getSnapshotLength cannot be called on the XPathResult of XPath expression {0} because its XPathResultType is {1}.
            }

                return m_list.getLength();
        }
 
Example #21
Source File: XPathResultImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
         * The number of nodes in the result snapshot. Valid values for
     * snapshotItem indices are <code>0</code> to
     * <code>snapshotLength-1</code> inclusive.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or
     *   <code>ORDERED_NODE_SNAPSHOT_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#getSnapshotLength()
         */
        public int getSnapshotLength() throws XPathException {

                if ((m_resultType != UNORDERED_NODE_SNAPSHOT_TYPE) &&
                    (m_resultType != ORDERED_NODE_SNAPSHOT_TYPE)) {
                                String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_GET_SNAPSHOT_LENGTH, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
                                throw new XPathException(XPathException.TYPE_ERR,fmsg);
//                              "The method getSnapshotLength cannot be called on the XPathResult of XPath expression {0} because its XPathResultType is {1}.
            }

                return m_list.getLength();
        }
 
Example #22
Source File: XPathResultImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
         * The value of this single node result, which may be <code>null</code>.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>ANY_UNORDERED_NODE_TYPE</code> or
     *   <code>FIRST_ORDERED_NODE_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#getSingleNodeValue()
         */
        public Node getSingleNodeValue() throws XPathException {

                if ((m_resultType != ANY_UNORDERED_NODE_TYPE) &&
                    (m_resultType != FIRST_ORDERED_NODE_TYPE)) {
                                String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_SINGLENODE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
                                throw new XPathException(XPathException.TYPE_ERR,fmsg);
//                              "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a single node.
//                               This method applies only to types ANY_UNORDERED_NODE_TYPE and FIRST_ORDERED_NODE_TYPE."
            }

                NodeIterator result = null;
                try {
                        result = m_resultObj.nodeset();
                } catch (TransformerException te) {
                        throw new XPathException(XPathException.TYPE_ERR,te.getMessage());
                }

        if (null == result) return null;

        Node node = result.nextNode();

        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
            return node;
        }
        }
 
Example #23
Source File: XPathResultImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
         * The value of this string result.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>STRING_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#getStringValue()
         */
        public String getStringValue() throws XPathException {
                if (getResultType() != STRING_TYPE) {
                        String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_STRING, new Object[] {m_xpath.getPatternString(), m_resultObj.getTypeString()});
                        throw new XPathException(XPathException.TYPE_ERR,fmsg);
//              "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a string."
                } else {
                        try {
                           return m_resultObj.str();
                        } catch (Exception e) {
                                // Type check above should prevent this exception from occurring.
                                throw new XPathException(XPathException.TYPE_ERR,e.getMessage());
                        }
                }
        }
 
Example #24
Source File: XPathResultImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
         * @see org.w3c.dom.xpath.XPathResult#getBooleanValue()
         */
        public boolean getBooleanValue() throws XPathException {
                if (getResultType() != BOOLEAN_TYPE) {
                        String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_BOOLEAN, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
                        throw new XPathException(XPathException.TYPE_ERR,fmsg);
//              "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a boolean."
                } else {
                        try {
                           return m_resultObj.bool();
                        } catch (TransformerException e) {
                                // Type check above should prevent this exception from occurring.
                                throw new XPathException(XPathException.TYPE_ERR,e.getMessage());
                        }
                }
        }
 
Example #25
Source File: XPathResultImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
         * @see org.w3c.dom.xpath.XPathResult#getBooleanValue()
         */
        public boolean getBooleanValue() throws XPathException {
                if (getResultType() != BOOLEAN_TYPE) {
                        String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_BOOLEAN, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
                        throw new XPathException(XPathException.TYPE_ERR,fmsg);
//              "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a boolean."
                } else {
                        try {
                           return m_resultObj.bool();
                        } catch (TransformerException e) {
                                // Type check above should prevent this exception from occurring.
                                throw new XPathException(XPathException.TYPE_ERR,e.getMessage());
                        }
                }
        }
 
Example #26
Source File: XPathResultImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
         * The value of this string result.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>STRING_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#getStringValue()
         */
        public String getStringValue() throws XPathException {
                if (getResultType() != STRING_TYPE) {
                        String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_STRING, new Object[] {m_xpath.getPatternString(), m_resultObj.getTypeString()});
                        throw new XPathException(XPathException.TYPE_ERR,fmsg);
//              "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a string."
                } else {
                        try {
                           return m_resultObj.str();
                        } catch (Exception e) {
                                // Type check above should prevent this exception from occurring.
                                throw new XPathException(XPathException.TYPE_ERR,e.getMessage());
                        }
                }
        }
 
Example #27
Source File: XPathResultImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
         *  The value of this number result.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>NUMBER_TYPE</code>.
         * @see org.w3c.dom.xpath.XPathResult#getNumberValue()
         */
        public double getNumberValue() throws XPathException {
                if (getResultType() != NUMBER_TYPE) {
                        String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_XPATHRESULTTYPE_TO_NUMBER, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
                        throw new XPathException(XPathException.TYPE_ERR,fmsg);
//              "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a number"
                } else {
                        try {
                           return m_resultObj.num();
                        } catch (Exception e) {
                                // Type check above should prevent this exception from occurring.
                                throw new XPathException(XPathException.TYPE_ERR,e.getMessage());
                        }
                }
        }
 
Example #28
Source File: XPathResultImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
         * The value of this single node result, which may be <code>null</code>.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>ANY_UNORDERED_NODE_TYPE</code> or
     *   <code>FIRST_ORDERED_NODE_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#getSingleNodeValue()
         */
        public Node getSingleNodeValue() throws XPathException {

                if ((m_resultType != ANY_UNORDERED_NODE_TYPE) &&
                    (m_resultType != FIRST_ORDERED_NODE_TYPE)) {
                                String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_TO_SINGLENODE, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
                                throw new XPathException(XPathException.TYPE_ERR,fmsg);
//                              "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a single node.
//                               This method applies only to types ANY_UNORDERED_NODE_TYPE and FIRST_ORDERED_NODE_TYPE."
            }

                NodeIterator result = null;
                try {
                        result = m_resultObj.nodeset();
                } catch (TransformerException te) {
                        throw new XPathException(XPathException.TYPE_ERR,te.getMessage());
                }

        if (null == result) return null;

        Node node = result.nextNode();

        // Wrap "namespace node" in an XPathNamespace
        if (isNamespaceNode(node)) {
            return new XPathNamespaceImpl(node);
        } else {
            return node;
        }
        }
 
Example #29
Source File: XPathResultImpl.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
         * The number of nodes in the result snapshot. Valid values for
     * snapshotItem indices are <code>0</code> to
     * <code>snapshotLength-1</code> inclusive.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>UNORDERED_NODE_SNAPSHOT_TYPE</code> or
     *   <code>ORDERED_NODE_SNAPSHOT_TYPE</code>.
     *
         * @see org.w3c.dom.xpath.XPathResult#getSnapshotLength()
         */
        public int getSnapshotLength() throws XPathException {

                if ((m_resultType != UNORDERED_NODE_SNAPSHOT_TYPE) &&
                    (m_resultType != ORDERED_NODE_SNAPSHOT_TYPE)) {
                                String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_GET_SNAPSHOT_LENGTH, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
                                throw new XPathException(XPathException.TYPE_ERR,fmsg);
//                              "The method getSnapshotLength cannot be called on the XPathResult of XPath expression {0} because its XPathResultType is {1}.
            }

                return m_list.getLength();
        }
 
Example #30
Source File: XPathResultImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
         *  The value of this number result.
     * @exception XPathException
     *   TYPE_ERR: raised if <code>resultType</code> is not
     *   <code>NUMBER_TYPE</code>.
         * @see org.w3c.dom.xpath.XPathResult#getNumberValue()
         */
        public double getNumberValue() throws XPathException {
                if (getResultType() != NUMBER_TYPE) {
                        String fmsg = XPATHMessages.createXPATHMessage(XPATHErrorResources.ER_CANT_CONVERT_XPATHRESULTTYPE_TO_NUMBER, new Object[] {m_xpath.getPatternString(), getTypeString(m_resultType)});
                        throw new XPathException(XPathException.TYPE_ERR,fmsg);
//              "The XPathResult of XPath expression {0} has an XPathResultType of {1} which cannot be converted to a number"
                } else {
                        try {
                           return m_resultObj.num();
                        } catch (Exception e) {
                                // Type check above should prevent this exception from occurring.
                                throw new XPathException(XPathException.TYPE_ERR,e.getMessage());
                        }
                }
        }