Package org.jaxen

Examples of org.jaxen.XPath


public class JaxenXPathTemplate extends AbstractXPathTemplate {

    @Override
    public boolean evaluateAsBoolean(String expression, Source context) throws XPathException {
        try {
            XPath xpath = createXPath(expression);
            Element element = getRootElement(context);
            return xpath.booleanValueOf(element);
        }
        catch (JaxenException ex) {
            throw new XPathException("Could not evaluate XPath expression [" + expression + "]", ex);
        }
        catch (TransformerException ex) {
View Full Code Here


    }

    @Override
    public Node evaluateAsNode(String expression, Source context) throws XPathException {
        try {
            XPath xpath = createXPath(expression);
            Element element = getRootElement(context);
            return (Node) xpath.selectSingleNode(element);
        }
        catch (JaxenException ex) {
            throw new XPathException("Could not evaluate XPath expression [" + expression + "]", ex);
        }
        catch (TransformerException ex) {
View Full Code Here

    @Override
    @SuppressWarnings("unchecked")
    public List<Node> evaluateAsNodeList(String expression, Source context) throws XPathException {
        try {
            XPath xpath = createXPath(expression);
            Element element = getRootElement(context);
            return xpath.selectNodes(element);
        }
        catch (JaxenException ex) {
            throw new XPathException("Could not evaluate XPath expression [" + expression + "]", ex);
        }
        catch (TransformerException ex) {
View Full Code Here

    }

    @Override
    public double evaluateAsDouble(String expression, Source context) throws XPathException {
        try {
            XPath xpath = createXPath(expression);
            Element element = getRootElement(context);
            return xpath.numberValueOf(element).doubleValue();
        }
        catch (JaxenException ex) {
            throw new XPathException("Could not evaluate XPath expression [" + expression + "]", ex);
        }
        catch (TransformerException ex) {
View Full Code Here

    }

    @Override
    public String evaluateAsString(String expression, Source context) throws XPathException {
        try {
            XPath xpath = createXPath(expression);
            Element element = getRootElement(context);
            return xpath.stringValueOf(element);
        }
        catch (JaxenException ex) {
            throw new XPathException("Could not evaluate XPath expression [" + expression + "]", ex);
        }
        catch (TransformerException ex) {
View Full Code Here

    }

    @Override
    public <T> T evaluateAsObject(String expression, Source context, NodeMapper<T> nodeMapper) throws XPathException {
        try {
            XPath xpath = createXPath(expression);
            Element element = getRootElement(context);
            Node node = (Node) xpath.selectSingleNode(element);
            if (node != null) {
                try {
                    return nodeMapper.mapNode(node, 0);
                }
                catch (DOMException ex) {
View Full Code Here

    }

    @Override
    public <T> List<T> evaluate(String expression, Source context, NodeMapper<T> nodeMapper) throws XPathException {
        try {
            XPath xpath = createXPath(expression);
            Element element = getRootElement(context);
            List<?> nodes = xpath.selectNodes(element);
            List<T> results = new ArrayList<T>(nodes.size());
            for (int i = 0; i < nodes.size(); i++) {
                Node node = (Node) nodes.get(i);
                try {
                    results.add(nodeMapper.mapNode(node, i));
View Full Code Here

            throw new XPathException("Could not transform context to DOM Node", ex);
        }
    }

    private XPath createXPath(String expression) throws JaxenException {
        XPath xpath = new DOMXPath(expression);
        if (getNamespaces() != null && !getNamespaces().isEmpty()) {
            xpath.setNamespaceContext(new SimpleNamespaceContext(getNamespaces()));
        }
        return xpath;
    }
View Full Code Here

     * @return the compiled {@code XPathExpression}
     * @throws XPathParseException when the given expression cannot be parsed
     */
    static XPathExpression createXPathExpression(String expression) {
        try {
            XPath xpath = new DOMXPath(expression);
            return new JaxenXpathExpression(xpath);
        }
        catch (JaxenException ex) {
            throw new org.springframework.xml.xpath.XPathParseException(
                    "Could not compile [" + expression + "] to a XPathExpression: " + ex.getMessage(), ex);
View Full Code Here

     * @return the compiled {@code XPathExpression}
     * @throws XPathParseException when the given expression cannot be parsed
     */
    public static XPathExpression createXPathExpression(String expression, Map<String, String> namespaces) {
        try {
            XPath xpath = new DOMXPath(expression);
            xpath.setNamespaceContext(new SimpleNamespaceContext(namespaces));
            return new JaxenXpathExpression(xpath);
        }
        catch (JaxenException ex) {
            throw new org.springframework.xml.xpath.XPathParseException(
                    "Could not compile [" + expression + "] to a XPathExpression: " + ex.getMessage(), ex);
View Full Code Here

TOP

Related Classes of org.jaxen.XPath

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.