@Override public double evaluateAsDouble(String expression, Source context) throws XPathException { Double result = (Double) evaluate(expression, context, XPathConstants.NUMBER); return result != null ? result : Double.NaN; }
/** * Returns true if given message is a XSL Template. * @param stringSource * @return */ boolean isTemplate(Source context) { Jaxp13XPathTemplate template = new Jaxp13XPathTemplate(); template.setNamespaces(NAMESPACES); return template.evaluateAsBoolean("count(/xs:stylesheet)>0", context); }
private Object evaluate(String expression, Source context, QName returnType) throws XPathException { XPath xpath = createXPath(); if (getNamespaces() != null && !getNamespaces().isEmpty()) { SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); namespaceContext.setBindings(getNamespaces()); xpath.setNamespaceContext(namespaceContext); } try { EvaluationCallback callback = new EvaluationCallback(xpath, expression, returnType); TraxUtils.doWithSource(context, callback); return callback.result; } catch (javax.xml.xpath.XPathException 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); } catch (Exception ex) { throw new XPathException(ex.getMessage(), ex); } }
private Object evaluate(String expression, Source context, QName returnType) throws XPathException { XPath xpath = xpathFactory.newXPath(); if (getNamespaces() != null && !getNamespaces().isEmpty()) { SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); namespaceContext.setBindings(getNamespaces()); xpath.setNamespaceContext(namespaceContext); Element element = getRootElement(context); return xpath.evaluate(expression, element, returnType);
public <T> T evaluateAsObject(String expression, Source context, NodeMapper<T> nodeMapper) throws XPathException { Node node = evaluateAsNode(expression, context); if (node != null) { try { return nodeMapper.mapNode(node, 0); } catch (DOMException ex) { throw new XPathException("Mapping resulted in DOMException", ex); } } else { return null; } }
private Object evaluate(String expression, Source context, QName returnType) throws XPathException { XPath xpath = createXPath(); if (getNamespaces() != null && !getNamespaces().isEmpty()) { SimpleNamespaceContext namespaceContext = new SimpleNamespaceContext(); namespaceContext.setBindings(getNamespaces()); xpath.setNamespaceContext(namespaceContext); } try { EvaluationCallback callback = new EvaluationCallback(xpath, expression, returnType); TraxUtils.doWithSource(context, callback); return callback.result; } catch (javax.xml.xpath.XPathException 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); } catch (Exception ex) { throw new XPathException(ex.getMessage(), ex); } }
@Override public <T> T evaluateAsObject(String expression, Source context, NodeMapper<T> nodeMapper) throws XPathException { Node node = evaluateAsNode(expression, context); if (node != null) { try { return nodeMapper.mapNode(node, 0); } catch (DOMException ex) { throw new XPathException("Mapping resulted in DOMException", ex); } } else { return null; } }
@Override public double evaluateAsDouble(String expression, Source context) throws XPathException { Double result = (Double) evaluate(expression, context, XPathConstants.NUMBER); return result != null ? result : Double.NaN; }
@Override public <T> T evaluateAsObject(String expression, Source context, NodeMapper<T> nodeMapper) throws XPathException { Node node = evaluateAsNode(expression, context); if (node != null) { try { return nodeMapper.mapNode(node, 0); } catch (DOMException ex) { throw new XPathException("Mapping resulted in DOMException", ex); } } else { return null; } }
/** * Returns true if the documents root is SOAP envelope. * @param document * @return */ public static boolean isSoap(Source source) { for (String prefix: SOAP_NAMESPACES.keySet()) { String expression = "/"+prefix+":Envelope"; Jaxp13XPathTemplate xpathTemplate = new Jaxp13XPathTemplate(); xpathTemplate.setNamespaces(SOAP_NAMESPACES); if (xpathTemplate.evaluateAsBoolean(expression, source)) { return true; } } return false; }
@Override public boolean evaluateAsBoolean(String expression, Source context) throws XPathException { Boolean result = (Boolean) evaluate(expression, context, XPathConstants.BOOLEAN); return result != null && result; }
public double evaluateAsDouble(String expression, Source context) throws XPathException { Double result = (Double) evaluate(expression, context, XPathConstants.NUMBER); return result != null ? result : Double.NaN; }
@Override public Node evaluateAsNode(String expression, Source context) throws XPathException { return (Node) evaluate(expression, context, XPathConstants.NODE); }
public boolean evaluateAsBoolean(String expression, Source context) throws XPathException { Boolean result = (Boolean) evaluate(expression, context, XPathConstants.BOOLEAN); return result != null && result; }
@Override public boolean evaluateAsBoolean(String expression, Source context) throws XPathException { Boolean result = (Boolean) evaluate(expression, context, XPathConstants.BOOLEAN); return result != null && result; }
@Override public Node evaluateAsNode(String expression, Source context) throws XPathException { return (Node) evaluate(expression, context, XPathConstants.NODE); }
@Override public String evaluateAsString(String expression, Source context) throws XPathException { return (String) evaluate(expression, context, XPathConstants.STRING); }
public String evaluateAsString(String expression, Source context) throws XPathException { return (String) evaluate(expression, context, XPathConstants.STRING); }
public Node evaluateAsNode(String expression, Source context) throws XPathException { return (Node) evaluate(expression, context, XPathConstants.NODE); }
@Override public String evaluateAsString(String expression, Source context) throws XPathException { return (String) evaluate(expression, context, XPathConstants.STRING); }