Java Examples for org.w3c.dom.xpath.XPathResult

The following java examples will help you to understand the usage of org.w3c.dom.xpath.XPathResult. These source code samples are taken from different open source projects.

Example 1
Project: Jayes-master  File: XPathUtil.java View source code
public static Iterator<Node> evalXPath(XPathEvaluator eval, String xpath, Node context) {
    result = ((XPathResult) eval.evaluate(xpath, context, null, (short) 0, result));
    return new Iterator<Node>() {

        Node cache = null;

        @Override
        public boolean hasNext() {
            if (cache == null) {
                cache = result.iterateNext();
            }
            return cache != null;
        }

        @Override
        public Node next() {
            if (cache == null) {
                return result.iterateNext();
            }
            Node n = cache;
            cache = null;
            return n;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
Example 2
Project: ikvm-openjdk-master  File: XPathResultImpl.java View source code
/**
         *  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) {
            throw new XPathException(XPathException.TYPE_ERR, e.getMessage());
        }
    }
}
Example 3
Project: JamVM-PH-master  File: XIncludeFilter.java View source code
public int next() throws XMLStreamException {
    if (lookahead) {
        lookahead = false;
        return event;
    }
    buf = null;
    len = 0;
    if (walker != null) {
        Node c = walker.getCurrentNode();
        Node n = null;
        if (c.getNodeType() == Node.ELEMENT_NODE) {
            boolean isStartElement = !seen.contains(c);
            if (isStartElement) {
                seen.add(c);
                current = c;
                event = XMLStreamConstants.START_ELEMENT;
                return event;
            } else if (backtracking) {
                n = walker.nextSibling();
                if (n != null)
                    backtracking = false;
            } else {
                n = walker.firstChild();
                if (n == null)
                    n = walker.nextSibling();
            }
        } else {
            n = walker.firstChild();
            if (n == null)
                n = walker.nextSibling();
        }
        if (n == null) {
            current = walker.parentNode();
            if (current != null && current.getNodeType() == Node.ELEMENT_NODE) {
                // end-element
                backtracking = true;
                event = XMLStreamConstants.END_ELEMENT;
                return event;
            } else {
                walker = null;
                current = null;
            }
        } else {
            current = n;
            switch(n.getNodeType()) {
                case Node.ELEMENT_NODE:
                    return next();
                case Node.TEXT_NODE:
                    String text = n.getNodeValue();
                    buf = text.toCharArray();
                    len = buf.length;
                    event = isSpace(buf, len) ? XMLStreamConstants.SPACE : XMLStreamConstants.CHARACTERS;
                    return event;
                case Node.CDATA_SECTION_NODE:
                    event = XMLStreamConstants.CDATA;
                    return event;
                case Node.COMMENT_NODE:
                    event = XMLStreamConstants.COMMENT;
                    return event;
                case Node.PROCESSING_INSTRUCTION_NODE:
                    event = XMLStreamConstants.PROCESSING_INSTRUCTION;
                    return event;
                case Node.ENTITY_REFERENCE_NODE:
                    event = XMLStreamConstants.ENTITY_REFERENCE;
                    return event;
                default:
                    throw new IllegalStateException();
            }
        }
    }
    if (result != null) {
        switch(result.getResultType()) {
            case XPathResult.BOOLEAN_TYPE:
                boolean bval = result.getBooleanValue();
                String btext = bval ? "true" : "false";
                buf = btext.toCharArray();
                len = buf.length;
                result = null;
                event = XMLStreamConstants.CHARACTERS;
                return event;
            case XPathResult.NUMBER_TYPE:
                double nval = result.getNumberValue();
                String ntext = Double.toString(nval);
                buf = ntext.toCharArray();
                len = buf.length;
                result = null;
                event = XMLStreamConstants.CHARACTERS;
                return event;
            case XPathResult.STRING_TYPE:
                String stext = result.getStringValue();
                buf = stext.toCharArray();
                len = buf.length;
                result = null;
                event = isSpace(buf, len) ? XMLStreamConstants.SPACE : XMLStreamConstants.CHARACTERS;
                return event;
            case XPathResult.ANY_UNORDERED_NODE_TYPE:
            case XPathResult.FIRST_ORDERED_NODE_TYPE:
                Node n1 = result.getSingleNodeValue();
                Document d1 = getDocument(n1);
                walker = getDocumentTraversal(d1).createTreeWalker(n1, SHOW_FLAGS, null, expandERefs);
                result = null;
                return next();
            case XPathResult.ORDERED_NODE_ITERATOR_TYPE:
            case XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
                Node n2 = result.iterateNext();
                if (n2 == null) {
                    result = null;
                    return next();
                }
                Document d2 = getDocument(n2);
                walker = getDocumentTraversal(d2).createTreeWalker(n2, SHOW_FLAGS, null, expandERefs);
                return next();
            case XPathResult.ORDERED_NODE_SNAPSHOT_TYPE:
            case XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE:
                Node n3 = result.snapshotItem(snapshotIndex++);
                if (n3 == null) {
                    result = null;
                    return next();
                }
                Document d3 = getDocument(n3);
                walker = getDocumentTraversal(d3).createTreeWalker(n3, SHOW_FLAGS, null, expandERefs);
                return next();
            default:
                throw new IllegalStateException();
        }
    }
    if (includedText != null) {
        // fill buffer
        if (buf == null)
            buf = new char[2048];
        try {
            len = includedText.read(buf, 0, buf.length);
            if (len == -1) {
                includedText = null;
                buf = null;
                return next();
            }
            // chars or space?
            return (event = isSpace(buf, len) ? XMLStreamConstants.SPACE : XMLStreamConstants.CHARACTERS);
        } catch (IOException e) {
            XMLStreamException e2 = new XMLStreamException(e.getMessage());
            e2.initCause(e);
            throw e2;
        }
    }
    event = super.next();
    switch(event) {
        case XMLStreamConstants.START_ELEMENT:
            String uri = getNamespaceURI();
            if (XINCLUDE_NS_URI.equals(uri)) {
                String localName = getLocalName();
                if ("include".equals(localName)) {
                    href = getAttributeValue(null, "href");
                    String parse = getAttributeValue(null, "parse");
                    String xpointer = getAttributeValue(null, "xpointer");
                    String encoding = getAttributeValue(null, "encoding");
                    String accept = getAttributeValue(null, "accept");
                    String acceptLanguage = getAttributeValue(null, "accept-language");
                    if (includeResource(href, parse, xpointer, encoding, accept, acceptLanguage)) {
                        // Skip to xi:include end-element event
                        int depth = 0;
                        while (depth >= 0) {
                            event = super.next();
                            switch(event) {
                                case XMLStreamConstants.START_ELEMENT:
                                    depth++;
                                    break;
                                case XMLStreamConstants.END_ELEMENT:
                                    depth--;
                            }
                        }
                    } else
                        inInclude = true;
                } else if (inInclude && "fallback".equals(localName)) {
                    if (!seenFallback)
                        inFallback = seenFallback = true;
                    else
                        throw new XMLStreamException("duplicate xi:fallback element");
                } else if (inInclude) {
                    throw new XMLStreamException("illegal xi element '" + localName + "'");
                }
                return next();
            }
            break;
        case XMLStreamConstants.END_ELEMENT:
            String uri2 = getNamespaceURI();
            if (XINCLUDE_NS_URI.equals(uri2)) {
                String localName = getLocalName();
                if ("include".equals(localName)) {
                    if (!seenFallback && included) {
                        String msg = "Unable to read " + href + " and no xi:fallback element present";
                        throw new XMLStreamException(msg);
                    }
                    included = false;
                    href = null;
                    inInclude = inFallback = seenFallback = false;
                } else if ("fallback".equals(localName))
                    inFallback = false;
                return next();
            }
            break;
    }
    if (inInclude && !inFallback)
        return next();
    return event;
}
Example 4
Project: ggpserver-master  File: FileMatchReader.java View source code
public Match readMatch(MatchSet matchSet, File xmlFile) throws MatchParsingException {
    // Data available in the XML source
    String matchId;
    List<Player> players;
    List<Integer> scores;
    log.fine("processing XML file: " + xmlFile);
    try {
        /* parse matchId */
        XPathResult result = queryXPath(xmlFile, "/match/match-id");
        Node firstResult = result.iterateNext();
        if (firstResult != null) {
            // competition 2007 XML format: there is a node called "match-id"
            matchId = firstResult.getTextContent();
        } else {
            // competition 2008 XML format: "id" is an attribute of node "match"
            result = queryXPath(xmlFile, "/match");
            firstResult = result.iterateNext();
            if (firstResult == null) {
                throw new MatchParsingException("XPath query for match id returned no results!");
            }
            matchId = firstResult.getAttributes().getNamedItem("id").getTextContent();
        }
        if (result.iterateNext() != null) {
            throw new MatchParsingException("XPath query for match id returned more than one result!");
        }
        log.finest("matchId: " + matchId);
        /* parse roles */
        result = queryXPath(xmlFile, "/match/role");
        List<String> roles = new LinkedList<String>();
        for (Node n = result.iterateNext(); n != null; n = result.iterateNext()) {
            // n = <role>White</role>
            // firstChild = White
            Node firstChild = n.getFirstChild();
            log.finest("Role:    " + firstChild.getTextContent());
            roles.add(firstChild.getTextContent());
            if (n.getChildNodes().getLength() > 1) {
                throw new MatchParsingException("XPath query for roles returned a node with several children!");
            }
        }
        // TODO What an ugly hack. Fix this in the future when roles of a game are available directly and not only via the matches.  
        matchSet.getGame().setRoles(roles);
        /* parse players */
        result = queryXPath(xmlFile, "/match/player");
        players = new LinkedList<Player>();
        for (Node n = result.iterateNext(); n != null; n = result.iterateNext()) {
            // n = <player>FLUXPLAYER</player>
            // firstChild = FLUXPLAYER
            Node firstChild = n.getFirstChild();
            log.finest("Player:    " + firstChild.getTextContent());
            players.add(playerSet.getPlayer(firstChild.getTextContent()));
            if (n.getChildNodes().getLength() > 1) {
                throw new MatchParsingException("XPath query for players returned a node with several children!");
            }
        }
        /* parse scores */
        scores = new LinkedList<Integer>();
        // 2007 XML format
        result = queryXPath(xmlFile, "/match/scores/reward");
        List<Node> results = new LinkedList<Node>();
        for (Node n = result.iterateNext(); n != null; n = result.iterateNext()) {
            results.add(n);
        }
        if (results.size() == 0) {
            // 2008 XML format
            result = queryXPath(xmlFile, "/match/rewards/reward");
            for (Node n = result.iterateNext(); n != null; n = result.iterateNext()) {
                results.add(n);
            }
        }
        for (Node n : results) {
            // n = <reward>100</reward>
            // firstChild = 100
            Node firstChild = n.getFirstChild();
            log.finest("Score:    " + firstChild.getTextContent());
            scores.add(Integer.valueOf(firstChild.getTextContent()));
            if (n.getChildNodes().getLength() > 1) {
                throw new MatchParsingException("XPath query for players returned a node with several children!");
            }
        }
        // sanity check 
        if (roles.size() != players.size() || players.size() != scores.size() || roles.isEmpty()) {
            throw new MatchParsingException("All 3 lists (roles, players, scores) must have the same number of elements and must not be empty!");
        }
    } catch (FileNotFoundException e) {
        MatchParsingException thrown = new MatchParsingException("XML file was not found: " + xmlFile, e);
        throw thrown;
    } catch (SAXException e) {
        MatchParsingException thrown = new MatchParsingException("SAXException while parsing XML file: " + xmlFile, e);
        throw thrown;
    } catch (IOException e) {
        MatchParsingException thrown = new MatchParsingException("IOException while parsing XML file: " + xmlFile, e);
        throw thrown;
    } catch (ParserConfigurationException e) {
        MatchParsingException thrown = new MatchParsingException("ParserConfigurationException while parsing XML file: " + xmlFile, e);
        throw thrown;
    }
    return new Match(matchSet, matchId, players, scores);
}
Example 5
Project: openbd-core-master  File: XmlSearch.java View source code
public cfData execute(cfSession _session, List<cfData> parameters) throws cfmRunTimeException {
    try {
        // Get a DOM tree to query.
        DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
        fact.setNamespaceAware(true);
        DocumentBuilder parser = fact.newDocumentBuilder();
        Document doc = null;
        Node node = null;
        boolean caseSensitive = false;
        cfData xml = parameters.get(1);
        if (xml instanceof cfXmlData) {
            node = ((cfXmlData) xml).getXMLNode();
            doc = node.getOwnerDocument();
            caseSensitive = ((cfXmlData) xml).isCaseSensitive();
        } else {
            doc = parser.parse(new InputSource(new StringReader(xml.getString())));
            node = doc;
        }
        /*
			 * TODO: This is here due to a memory leak bug in the XALAN library
			 * https://issues.apache.org/jira/browse/XALANJ-1673
			 */
        ///node = node.cloneNode(true);
        // Use the DOM L3 XPath API to apply the xpath expression to the doc.
        // Create an XPath evaluator and pass in the document.
        XPathEvaluator evaluator = new org.apache.xpath.domapi.XPathEvaluatorImpl(doc);
        XPathNSResolver resolver = evaluator.createNSResolver(node);
        // Check the xpath expression
        String xpath = parameters.get(0).getString().trim();
        if (xpath.endsWith("/") && !xpath.equals("/"))
            xpath = xpath.substring(0, xpath.length() - 1);
        // Evaluate the xpath expression
        XPathResult result;
        synchronized (node) {
            result = (XPathResult) evaluator.evaluate(xpath, node, resolver, XPathResult.ANY_TYPE, null);
        }
        // If it's an iterator type
        if (result.getResultType() == XPathResult.UNORDERED_NODE_ITERATOR_TYPE) {
            // Return the array
            cfArrayData arr = cfArrayData.createArray(1);
            Node n = null;
            while ((n = result.iterateNext()) != null) arr.addElement(new cfXmlData(n, caseSensitive));
            return arr;
        } else // It's a number type
        if (result.getResultType() == XPathResult.NUMBER_TYPE) {
            return new cfNumberData(result.getNumberValue());
        } else // It's a boolean type
        if (result.getResultType() == XPathResult.BOOLEAN_TYPE) {
            return cfBooleanData.getcfBooleanData(result.getBooleanValue());
        } else // It's a string type
        if (result.getResultType() == XPathResult.STRING_TYPE) {
            return new cfStringData(result.getStringValue());
        } else // It's not a supported type
        {
            return null;
        }
    } catch (IOException ex) {
        throw new cfmRunTimeException(catchDataFactory.javaMethodException("errorCode.javaException", ex.getClass().getName(), ex.getMessage(), ex));
    } catch (SAXException ex) {
        throw new cfmRunTimeException(catchDataFactory.javaMethodException("errorCode.javaException", ex.getClass().getName(), ex.getMessage(), ex));
    } catch (ParserConfigurationException ex) {
        throw new cfmRunTimeException(catchDataFactory.javaMethodException("errorCode.javaException", ex.getClass().getName(), ex.getMessage(), ex));
    } catch (DOMException ex) {
        throw new cfmRunTimeException(catchDataFactory.javaMethodException("errorCode.javaException", ex.getClass().getName(), ex.getMessage(), ex));
    } catch (XPathException ex) {
        throw new cfmRunTimeException(catchDataFactory.javaMethodException("errorCode.javaException", ex.getClass().getName(), ex.getMessage(), ex));
    }
}
Example 6
Project: batik-master  File: AbstractDocument.java View source code
/**
         * <b>DOM</b>: Implements
         * {@link org.w3c.dom.xpath.XPathExpression#evaluate(Node,short,Object)}.
         */
public Object evaluate(Node contextNode, short type, Object res) throws XPathException, DOMException {
    if (contextNode.getNodeType() != DOCUMENT_NODE && contextNode.getOwnerDocument() != AbstractDocument.this || contextNode.getNodeType() == DOCUMENT_NODE && contextNode != AbstractDocument.this) {
        throw createDOMException(DOMException.WRONG_DOCUMENT_ERR, "node.from.wrong.document", new Object[] { new Integer(contextNode.getNodeType()), contextNode.getNodeName() });
    }
    if (type < 0 || type > 9) {
        throw createDOMException(DOMException.NOT_SUPPORTED_ERR, "xpath.invalid.result.type", new Object[] { new Integer(type) });
    }
    switch(contextNode.getNodeType()) {
        case ENTITY_REFERENCE_NODE:
        case ENTITY_NODE:
        case DOCUMENT_TYPE_NODE:
        case DOCUMENT_FRAGMENT_NODE:
        case NOTATION_NODE:
            throw createDOMException(DOMException.NOT_SUPPORTED_ERR, "xpath.invalid.context.node", new Object[] { new Integer(contextNode.getNodeType()), contextNode.getNodeName() });
    }
    context.reset();
    XObject result = null;
    try {
        result = xpath.execute(context, contextNode, prefixResolver);
    } catch (javax.xml.transform.TransformerException te) {
        throw createXPathException(XPathException.INVALID_EXPRESSION_ERR, "xpath.error", new Object[] { xpath.getPatternString(), te.getMessage() });
    }
    try {
        switch(type) {
            case XPathResult.ANY_UNORDERED_NODE_TYPE:
            case XPathResult.FIRST_ORDERED_NODE_TYPE:
                return convertSingleNode(result, type);
            case XPathResult.BOOLEAN_TYPE:
                return convertBoolean(result);
            case XPathResult.NUMBER_TYPE:
                return convertNumber(result);
            case XPathResult.ORDERED_NODE_ITERATOR_TYPE:
            case XPathResult.UNORDERED_NODE_ITERATOR_TYPE:
            case XPathResult.ORDERED_NODE_SNAPSHOT_TYPE:
            case XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE:
                return convertNodeIterator(result, type);
            case XPathResult.STRING_TYPE:
                return convertString(result);
            case XPathResult.ANY_TYPE:
                switch(result.getType()) {
                    case XObject.CLASS_BOOLEAN:
                        return convertBoolean(result);
                    case XObject.CLASS_NUMBER:
                        return convertNumber(result);
                    case XObject.CLASS_STRING:
                        return convertString(result);
                    case XObject.CLASS_NODESET:
                        return convertNodeIterator(result, XPathResult.UNORDERED_NODE_ITERATOR_TYPE);
                }
        }
    } catch (javax.xml.transform.TransformerException te) {
        throw createXPathException(XPathException.TYPE_ERR, "xpath.cannot.convert.result", new Object[] { new Integer(type), te.getMessage() });
    }
    return null;
}
Example 7
Project: recommenders-master  File: XPathUtil.java View source code
public static Iterator<Node> evalXPath(XPathEvaluator eval, String xpath, Node context) {
    final XPathResult result = (XPathResult) eval.evaluate(xpath, context, null, (short) 0, null);
    return new Iterator<Node>() {

        Node cache = null;

        @Override
        public boolean hasNext() {
            if (cache == null) {
                cache = result.iterateNext();
            }
            return cache != null;
        }

        @Override
        public Node next() {
            if (cache == null) {
                return result.iterateNext();
            }
            Node n = cache;
            cache = null;
            return n;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
Example 8
Project: jdk7u-jaxp-master  File: XPathResultImpl.java View source code
/**
         *  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) {
            throw new XPathException(XPathException.TYPE_ERR, e.getMessage());
        }
    }
}
Example 9
Project: JDK-master  File: XPathResultImpl.java View source code
/**
         *  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) {
            throw new XPathException(XPathException.TYPE_ERR, e.getMessage());
        }
    }
}
Example 10
Project: ManagedRuntimeInitiative-master  File: XPathResultImpl.java View source code
/**
         *  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) {
            throw new XPathException(XPathException.TYPE_ERR, e.getMessage());
        }
    }
}
Example 11
Project: JFugue-for-Android-master  File: XPathResultImpl.java View source code
/**
	 *  The value of this number result.
     * @exception org.w3c.dom.xpath.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) {
            throw new XPathException(XPathException.TYPE_ERR, e.getMessage());
        }
    }
}
Example 12
Project: classlib6-master  File: XPathResultImpl.java View source code
/**
	 *  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) {
            throw new XPathException(XPathException.TYPE_ERR, e.getMessage());
        }
    }
}
Example 13
Project: Loboevolution-master  File: XPathResultImpl.java View source code
/**
	 * The value of this number result.
	 *
	 * @return the number value
	 * @see org.w3c.dom.xpath.XPathResult#getNumberValue()
	 * @exception XPathException
	 *                TYPE_ERR: raised if <code>resultType</code> is not
	 *                <code>NUMBER_TYPE</code>.
	 */
@Override
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) {
            throw new XPathException(XPathException.TYPE_ERR, e.getMessage());
        }
    }
}