public Document checkStockLevel(Document doc) { String isbn = isbnSelectingXPath.evaluateAsString(doc); boolean inStock = false; // we only carry stock of one book currently if ("0321200683".equals(isbn)) { inStock = true; } doc.getDocumentElement().setAttribute("in-stock", String.valueOf(inStock)); return doc; }
public Object unmarshal(Source source) throws IOException, XmlMappingException { //this.writeXml(((DOMSource)source).getNode().getOwnerDocument()); DOMResult result = null; try { Transformer transformer = transformerFactory.newTransformer(); result = new DOMResult(); transformer.transform(source, result); } catch (Exception e) { throw new MarshallingFailureException("Failed to unmarshal SOAP Response", e); } Weather weather = new Weather(); String expression = xpathPrefix + "p:City"; String city = XPathExpressionFactory.createXPathExpression(expression, namespacePrefixes).evaluateAsString(result.getNode()); weather.setCity(city); expression = xpathPrefix + "p:State"; String state = XPathExpressionFactory.createXPathExpression(expression, namespacePrefixes).evaluateAsString(result.getNode()); weather.setState(state); expression = xpathPrefix + "p:Temperature"; String temperature = XPathExpressionFactory.createXPathExpression(expression, namespacePrefixes).evaluateAsString(result.getNode()); weather.setTemperature(temperature); expression = xpathPrefix + "p:Description"; String description = XPathExpressionFactory.createXPathExpression(expression, namespacePrefixes).evaluateAsString(result.getNode()); weather.setDescription(description); return weather; }
public Object evaluateXPath(XPathExpression expression, Node node) { return expression.evaluateAsString(node); } },
@Override protected List<Object> getChannelKeys(Message<?> message) { Node node = this.converter.convertToNode(message.getPayload()); if (this.evaluateAsString) { return Collections.singletonList((Object) this.xPathExpression.evaluateAsString(node)); } else { return this.xPathExpression.evaluate(node, this.nodeMapper); } }
/** * Evaluate the payload and return true if the value returned by the * {@link XPathExpression} matches the <code>regex</code>. */ @Override public boolean accept(Message<?> message) { Node nodeToTest = getConverter().convertToNode(message.getPayload()); String xPathResult = getXPathExpresion().evaluateAsString(nodeToTest); return StringUtils.hasText(xPathResult) && xPathResult.matches(this.regex); }
/** * Evaluate the payload and return true if the value returned by the * {@link XPathExpression} is equal to the <code>valueToTestFor</code>. */ @Override public boolean accept(Message<?> message) { Node nodeToTest = getConverter().convertToNode(message.getPayload()); String xPathResult = getXPathExpresion().evaluateAsString(nodeToTest); if (this.caseSensitive) { return this.valueToTestFor.equals(xPathResult); } else { return this.valueToTestFor.equalsIgnoreCase(xPathResult); } }
return (T) expression.evaluateAsString(node);
@Test public void testStringExpressionWithNamespaceMapReference() throws Exception { StringBuffer xmlDoc = new StringBuffer("<si-xml:xpath-expression id='xpathExpression' expression='/ns1:name' namespace-map='myNamespaces' />"); xmlDoc.append("<util:map id='myNamespaces'><entry key='ns1' value='www.example.org' /></util:map>"); XPathExpression xPathExpression = getXPathExpression(xmlDoc.toString()); assertEquals("outputOne", xPathExpression.evaluateAsString(XmlTestUtil.getDocumentForString("<ns1:name xmlns:ns1='www.example.org'>outputOne</ns1:name>"))); assertEquals("", xPathExpression.evaluateAsString(XmlTestUtil.getDocumentForString("<name>outputOne</name>"))); }
@Test public void testStringExpressionWithNamespaceInnerBean() throws Exception { StringBuilder xmlDoc = new StringBuilder("<si-xml:xpath-expression id='xpathExpression' expression='/ns1:name'>") .append(" <map><entry key='ns1' value='www.example.org' /></map>") .append("</si-xml:xpath-expression>"); XPathExpression xPathExpression = getXPathExpression(xmlDoc.toString()); assertEquals("outputOne", xPathExpression.evaluateAsString(XmlTestUtil.getDocumentForString("<ns1:name xmlns:ns1='www.example.org'>outputOne</ns1:name>"))); assertEquals("", xPathExpression.evaluateAsString(XmlTestUtil.getDocumentForString("<name>outputOne</name>"))); }
@Test(expected = BeanDefinitionStoreException.class) public void testNamespacePrefixButNoUri() throws Exception { String xmlDoc = "<si-xml:xpath-expression id='xpathExpression' expression='/ns1:name' ns-prefix='ns1' />"; XPathExpression xPathExpression = getXPathExpression(xmlDoc); assertEquals("outputOne", xPathExpression.evaluateAsString(XmlTestUtil.getDocumentForString("<ns1:name xmlns:ns1='www.example.org'>outputOne</ns1:name>"))); assertEquals("", xPathExpression.evaluateAsString(XmlTestUtil.getDocumentForString("<name>outputOne</name>"))); }
@Test public void testNamespacedStringExpression() throws Exception { String xmlDoc = "<si-xml:xpath-expression id='xpathExpression' expression='/ns1:name' ns-prefix='ns1' ns-uri='www.example.org' />"; XPathExpression xPathExpression = getXPathExpression(xmlDoc); assertEquals("outputOne", xPathExpression.evaluateAsString(XmlTestUtil.getDocumentForString("<ns1:name xmlns:ns1='www.example.org'>outputOne</ns1:name>"))); assertEquals("", xPathExpression.evaluateAsString(XmlTestUtil.getDocumentForString("<name>outputOne</name>"))); }
@Test public void testSimpleStringExpression() throws Exception { String xmlDoc = "<si-xml:xpath-expression id='xpathExpression' expression='/name' />"; XPathExpression xPathExpression = getXPathExpression(xmlDoc); assertEquals("outputOne", xPathExpression.evaluateAsString(XmlTestUtil.getDocumentForString("<name>outputOne</name>"))); }
private URI getUri(Node node, XPathExpression expression) { String messageId = expression.evaluateAsString(node); if (!StringUtils.hasLength(messageId)) { return null; } try { return new URI(messageId); } catch (URISyntaxException e) { return null; } }
private URI getUri(Node node, XPathExpression expression) { String messageId = expression.evaluateAsString(node); if (!StringUtils.hasLength(messageId)) { return null; } try { return new URI(messageId); } catch (URISyntaxException e) { return null; } }
@Override protected String getLookupKeyForMessage(MessageContext messageContext) throws Exception { Element payloadElement = getMessagePayloadElement(messageContext.getRequest()); return expression.evaluateAsString(payloadElement); }
@Override protected String getLookupKeyForMessage(MessageContext messageContext) throws Exception { Element payloadElement = getMessagePayloadElement(messageContext.getRequest()); return expression.evaluateAsString(payloadElement); }
@Override protected String getLookupKeyForMessage(MessageContext messageContext) throws Exception { Element payloadElement = getMessagePayloadElement(messageContext.getRequest()); return expression.evaluateAsString(payloadElement); }
public void match(WebServiceMessage message) throws IOException, AssertionError { Node payload = transformToNode(message); String result = expression.evaluateAsString(payload); assertEquals("Evaluation of XPath expression \"" + expressionString + "\" failed.", expectedValue, result, "Payload", message.getPayloadSource()); } };
public void match(WebServiceMessage message) throws IOException, AssertionError { Node payload = transformToNode(message); String result = expression.evaluateAsString(payload); assertEquals("Evaluation of XPath expression \"" + expressionString + "\" failed.", expectedValue, result, "Payload", message.getPayloadSource()); } };
private String getXPathResult(MessageContext messageContext, XPathExpression expression) throws TransformerException, XMLStreamException, ParserConfigurationException, IOException, SAXException { if (expression != null) { Node domNode = xmlConverter.toDOMNode(messageContext.getRequest().getPayloadSource()); if (domNode != null) { return expression.evaluateAsString(domNode.getFirstChild()); } } return null; }