private Object splitNode(Node node) throws ParserConfigurationException { if (this.iterator) { try { NodeList nodeList = (NodeList) this.jaxpExpression.evaluate(node, XPathConstants.NODESET); return new NodeListIterator(nodeList); } catch (XPathExpressionException e) { throw new XPathException("Could not evaluate XPath expression:" + e.getMessage(), e); } } else { List<Node> nodeList = this.xpathExpression.evaluateAsNodeList(node); if (this.createDocuments) { return convertNodesToDocuments(nodeList); } return nodeList; } }
throw new XPathException("Unable to create 'documentBuilder'.", e);
public Jaxp13XPathTemplate(String xpathFactoryUri) { try { xpathFactory = XPathFactory.newInstance(xpathFactoryUri); } catch (XPathFactoryConfigurationException ex) { throw new XPathException("Could not create XPathFactory", ex); } }
public Jaxp13XPathTemplate(String xpathFactoryUri) { try { xpathFactory = XPathFactory.newInstance(xpathFactoryUri); } catch (XPathFactoryConfigurationException ex) { throw new XPathException("Could not create XPathFactory", ex); } }
private Object evaluate(Node node, QName returnType) { try { // XPathExpression is not thread-safe synchronized (xpathExpression) { return xpathExpression.evaluate(node, returnType); } } catch (XPathExpressionException ex) { throw new XPathException("Could not evaluate XPath expression:" + ex.getMessage(), ex); } }
@Override public <T> List<T> evaluate(String expression, Source context, NodeMapper<T> nodeMapper) throws XPathException { NodeList nodes = (NodeList) evaluate(expression, context, 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 <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 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) { throw new XPathException("Could not transform context to DOM Node", ex); } }
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) { throw new XPathException("Could not transform context to DOM Node", ex); } }
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) { throw new XPathException("Could not transform context to DOM Node", ex); } }
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) { throw new XPathException("Could not transform context to DOM Node", ex); } }
@Override public double evaluateAsNumber(Node node) { try { return xpath.numberValueOf(node).doubleValue(); } catch (JaxenException ex) { throw new XPathException("Could not evaluate XPath expression [" + xpath + "] :" + ex.getMessage(), ex); } }
@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) { throw new XPathException("Could not transform context to DOM Node", ex); } }
@SuppressWarnings("unchecked") public List<Node> evaluateAsNodeList(Node node) { try { return xpath.selectNodes(node); } catch (JaxenException ex) { throw new XPathException("Could not evaluate XPath expression [" + xpath + "] :" + ex.getMessage(), ex); } }
@Override public boolean evaluateAsBoolean(Node node) { try { return xpath.booleanValueOf(node); } catch (JaxenException ex) { throw new XPathException("Could not evaluate XPath expression [" + xpath + "] :" + ex.getMessage(), ex); } }
@Override @SuppressWarnings("unchecked") public List<Node> evaluateAsNodeList(Node node) { try { return xpath.selectNodes(node); } catch (JaxenException ex) { throw new XPathException("Could not evaluate XPath expression [" + xpath + "] :" + ex.getMessage(), ex); } }
@Override public Node evaluateAsNode(Node node) { try { return (Node) xpath.selectSingleNode(node); } catch (JaxenException ex) { throw new XPathException("Could not evaluate XPath expression [" + xpath + "] :" + ex.getMessage(), ex); } }
@Override public String evaluateAsString(Node node) { try { return xpath.stringValueOf(node); } catch (JaxenException ex) { throw new XPathException("Could not evaluate XPath expression [" + xpath + "] :" + ex.getMessage(), ex); } }
@Override public Node evaluateAsNode(Node node) { try { return (Node) xpath.selectSingleNode(node); } catch (JaxenException ex) { throw new XPathException("Could not evaluate XPath expression [" + xpath + "] :" + ex.getMessage(), ex); } }
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; } }