/** * Creates a JAXP 1.3 {@code XPathExpression} from the given string expression and namespaces. * * @param expression the XPath expression * @param namespaces the namespaces * @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 = createXPath(); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); namespaceContext.setBindings(namespaces); xpath.setNamespaceContext(namespaceContext); javax.xml.xpath.XPathExpression xpathExpression = xpath.compile(expression); return new Jaxp13XPathExpression(xpathExpression, expression); } catch (XPathExpressionException ex) { throw new org.springframework.xml.xpath.XPathParseException( "Could not compile [" + expression + "] to a XPathExpression: " + ex.getMessage(), ex); } }
@Override public <T> List<T> evaluate(Node node, NodeMapper<T> nodeMapper) throws XPathException { NodeList nodes = (NodeList) evaluate(node, XPathConstants.NODESET); List<T> results = new ArrayList<T>(nodes.getLength()); for (int i = 0; i < nodes.getLength(); i++) { try { results.add(nodeMapper.mapNode(nodes.item(i), i)); } catch (DOMException ex) { throw new XPathException("Mapping resulted in DOMException", ex); } } return results; } }
/** * Creates a JAXP 1.3 <code>XPathExpression</code> from the given string expression and namespaces. * * @param expression the XPath expression * @param namespaces the namespaces * @return the compiled <code>XPathExpression</code> * @throws XPathParseException when the given expression cannot be parsed */ public static XPathExpression createXPathExpression(String expression, Map<String, String> namespaces) { try { XPath xpath = xpathFactory.newXPath(); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); namespaceContext.setBindings(namespaces); xpath.setNamespaceContext(namespaceContext); javax.xml.xpath.XPathExpression xpathExpression = xpath.compile(expression); return new Jaxp13XPathExpression(xpathExpression); } catch (XPathExpressionException ex) { throw new org.springframework.xml.xpath.XPathParseException( "Could not compile [" + expression + "] to a XPathExpression: " + ex.getMessage(), ex); } }
/** * Creates a JAXP 1.3 {@code XPathExpression} from the given string expression and namespaces. * * @param expression the XPath expression * @param namespaces the namespaces * @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 = createXPath(); SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); namespaceContext.setBindings(namespaces); xpath.setNamespaceContext(namespaceContext); javax.xml.xpath.XPathExpression xpathExpression = xpath.compile(expression); return new Jaxp13XPathExpression(xpathExpression, expression); } catch (XPathExpressionException ex) { throw new org.springframework.xml.xpath.XPathParseException( "Could not compile [" + expression + "] to a XPathExpression: " + ex.getMessage(), ex); } }
/** * Creates a JAXP 1.3 {@code XPathExpression} from the given string expression. * * @param expression the XPath expression * @return the compiled {@code XPathExpression} * @throws XPathParseException when the given expression cannot be parsed */ static XPathExpression createXPathExpression(String expression) { try { XPath xpath = createXPath(); javax.xml.xpath.XPathExpression xpathExpression = xpath.compile(expression); return new Jaxp13XPathExpression(xpathExpression, expression); } catch (XPathExpressionException ex) { throw new org.springframework.xml.xpath.XPathParseException( "Could not compile [" + expression + "] to a XPathExpression: " + ex.getMessage(), ex); } }
/** * Creates a JAXP 1.3 <code>XPathExpression</code> from the given string expression. * * @param expression the XPath expression * @return the compiled <code>XPathExpression</code> * @throws XPathParseException when the given expression cannot be parsed */ static XPathExpression createXPathExpression(String expression) { try { XPath xpath = xpathFactory.newXPath(); javax.xml.xpath.XPathExpression xpathExpression = xpath.compile(expression); return new Jaxp13XPathExpression(xpathExpression); } catch (XPathExpressionException ex) { throw new org.springframework.xml.xpath.XPathParseException( "Could not compile [" + expression + "] to a XPathExpression: " + ex.getMessage(), ex); } }
/** * Creates a JAXP 1.3 {@code XPathExpression} from the given string expression. * * @param expression the XPath expression * @return the compiled {@code XPathExpression} * @throws XPathParseException when the given expression cannot be parsed */ static XPathExpression createXPathExpression(String expression) { try { XPath xpath = createXPath(); javax.xml.xpath.XPathExpression xpathExpression = xpath.compile(expression); return new Jaxp13XPathExpression(xpathExpression, expression); } catch (XPathExpressionException ex) { throw new org.springframework.xml.xpath.XPathParseException( "Could not compile [" + expression + "] to a XPathExpression: " + ex.getMessage(), ex); } }
@Override public <T> T evaluateAsObject(Node node, NodeMapper<T> nodeMapper) throws XPathException { Node result = (Node) evaluate(node, XPathConstants.NODE); if (result != null) { try { return nodeMapper.mapNode(result, 0); } catch (DOMException ex) { throw new XPathException("Mapping resulted in DOMException", ex); } } else { return null; } }
public <T> List<T> evaluate(Node node, NodeMapper<T> nodeMapper) throws XPathException { NodeList nodes = (NodeList) evaluate(node, XPathConstants.NODESET); List<T> results = new ArrayList<T>(nodes.getLength()); for (int i = 0; i < nodes.getLength(); i++) { try { results.add(nodeMapper.mapNode(nodes.item(i), i)); } catch (DOMException ex) { throw new XPathException("Mapping resulted in DOMException", ex); } } return results; } }
public Node evaluateAsNode(Node node) { return (Node) evaluate(node, XPathConstants.NODE); }
public boolean evaluateAsBoolean(Node node) { return (Boolean) evaluate(node, XPathConstants.BOOLEAN); }
public String evaluateAsString(Node node) { return (String) evaluate(node, XPathConstants.STRING); }
public <T> T evaluateAsObject(Node node, NodeMapper<T> nodeMapper) throws XPathException { Node result = (Node) evaluate(node, XPathConstants.NODE); if (result != null) { try { return nodeMapper.mapNode(result, 0); } catch (DOMException ex) { throw new XPathException("Mapping resulted in DOMException", ex); } } else { return null; } }
@Override public double evaluateAsNumber(Node node) { return (Double) evaluate(node, XPathConstants.NUMBER); }
@Override public String evaluateAsString(Node node) { return (String) evaluate(node, XPathConstants.STRING); }
@Override public <T> T evaluateAsObject(Node node, NodeMapper<T> nodeMapper) throws XPathException { Node result = (Node) evaluate(node, XPathConstants.NODE); if (result != null) { try { return nodeMapper.mapNode(result, 0); } catch (DOMException ex) { throw new XPathException("Mapping resulted in DOMException", ex); } } else { return null; } }
@Override public <T> List<T> evaluate(Node node, NodeMapper<T> nodeMapper) throws XPathException { NodeList nodes = (NodeList) evaluate(node, XPathConstants.NODESET); List<T> results = new ArrayList<T>(nodes.getLength()); for (int i = 0; i < nodes.getLength(); i++) { try { results.add(nodeMapper.mapNode(nodes.item(i), i)); } catch (DOMException ex) { throw new XPathException("Mapping resulted in DOMException", ex); } } return results; } }
@Override public Node evaluateAsNode(Node node) { return (Node) evaluate(node, XPathConstants.NODE); }
@Override public boolean evaluateAsBoolean(Node node) { return (Boolean) evaluate(node, XPathConstants.BOOLEAN); }
@Override public String evaluateAsString(Node node) { return (String) evaluate(node, XPathConstants.STRING); }