refactored namespace support for xpath-router and xpath-selector
This commit is contained in:
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.xml.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.xml.xpath.XPathExpressionFactory;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
public class XPathExpressionBeanDefintionBuilder {
|
||||
|
||||
public AbstractBeanDefinition handleXpathExpression(Element element, ParserContext parserContext) {
|
||||
String strXpathExpression = element.getAttribute("xpath-expression");
|
||||
String strXpathExpressionPrefix = element.getAttribute("ns-prefix");
|
||||
String strXpathExpressionNamespace = element.getAttribute("ns-uri");
|
||||
String nameSpaceMapRef = element.getAttribute("namespace-map");
|
||||
|
||||
Assert.hasText(strXpathExpression, "xpath-expression attribute is required");
|
||||
|
||||
|
||||
|
||||
boolean prefixProvided = StringUtils.hasText(strXpathExpressionPrefix);
|
||||
boolean namespaceProvided = StringUtils.hasText(strXpathExpressionNamespace);
|
||||
boolean namespaceMapProvided = StringUtils.hasText(nameSpaceMapRef);
|
||||
|
||||
if (prefixProvided || namespaceProvided) {
|
||||
Assert.isTrue(prefixProvided && namespaceProvided,
|
||||
"Both xpath-prefix and xpath-namespace must be specified if one is specified");
|
||||
Assert.isTrue(!namespaceMapProvided, "It is not valid to sepcify both xpath-namespace and namespace-map");
|
||||
}
|
||||
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(XPathExpressionFactory.class);
|
||||
builder.setFactoryMethod("createXPathExpression");
|
||||
builder.addConstructorArgValue(strXpathExpression);
|
||||
|
||||
if (prefixProvided) {
|
||||
Map<String, String> namespaceMap = new HashMap<String, String>();
|
||||
namespaceMap.put(strXpathExpressionPrefix, strXpathExpressionNamespace);
|
||||
builder.addConstructorArgValue(namespaceMap);
|
||||
}
|
||||
else if (StringUtils.hasText(nameSpaceMapRef)) {
|
||||
builder.addConstructorArgReference(nameSpaceMapRef);
|
||||
}
|
||||
else if (element.getChildNodes().getLength() > 0) {
|
||||
NodeList nodeList = element.getChildNodes();
|
||||
Element mapElement = null;
|
||||
int elementCount = 0;
|
||||
for (int i = 0; i < nodeList.getLength(); i++) {
|
||||
Node currentNode = nodeList.item(i);
|
||||
if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
|
||||
mapElement = (Element) currentNode;
|
||||
elementCount++;
|
||||
}
|
||||
}
|
||||
Assert.isTrue(elementCount == 1, "Only one namespace map child allowed");
|
||||
if (mapElement != null) {
|
||||
Map namespaceMap = parseNamespaceMapElement(mapElement, parserContext, builder.getBeanDefinition());
|
||||
builder.getBeanDefinition().getConstructorArgumentValues().addGenericArgumentValue(namespaceMap);
|
||||
}
|
||||
}
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
|
||||
protected Map parseNamespaceMapElement(Element element, ParserContext parserContext, BeanDefinition parentDefinition) {
|
||||
BeanDefinitionParserDelegate beanParser = new BeanDefinitionParserDelegate(parserContext.getReaderContext());
|
||||
beanParser.initDefaults(element.getOwnerDocument().getDocumentElement());
|
||||
return beanParser.parseMapElement(element, parentDefinition);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,7 +36,7 @@ import org.w3c.dom.NodeList;
|
||||
*
|
||||
*/
|
||||
public class XPathExpressionParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateId() {
|
||||
return false;
|
||||
@@ -47,15 +47,17 @@ public class XPathExpressionParser extends AbstractSingleBeanDefinitionParser {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected Class getBeanClass(Element element) {
|
||||
return XPathExpressionFactory.class;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
String strXpathExpression = element.getAttribute("xpath-expression");
|
||||
String strXpathExpression = element.getAttribute("expression");
|
||||
String strXpathExpressionPrefix = element.getAttribute("ns-prefix");
|
||||
String strXpathExpressionNamespace = element.getAttribute("ns-uri");
|
||||
String nameSpaceMapRef = element.getAttribute("namespace-map");
|
||||
@@ -105,6 +107,7 @@ public class XPathExpressionParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Map parseNamespaceMapElement(Element element, ParserContext parserContext, BeanDefinition parentDefinition) {
|
||||
BeanDefinitionParserDelegate beanParser = new BeanDefinitionParserDelegate(parserContext.getReaderContext());
|
||||
beanParser.initDefaults(element.getOwnerDocument().getDocumentElement());
|
||||
|
||||
@@ -16,24 +16,25 @@
|
||||
|
||||
package org.springframework.integration.xml.config;
|
||||
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
import org.springframework.integration.xml.router.XPathMultiChannelNameResolver;
|
||||
import org.springframework.integration.xml.router.XPathSingleChannelNameResolver;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
/**
|
||||
* @author Jonas Partner
|
||||
*/
|
||||
public class XPathRouterParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
private XPathExpressionBeanDefintionBuilder xpathBuilder = new XPathExpressionBeanDefintionBuilder();
|
||||
|
||||
private XPathExpressionParser xpathParser = new XPathExpressionParser();
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateId() {
|
||||
return false;
|
||||
@@ -48,18 +49,15 @@ public class XPathRouterParser extends AbstractSingleBeanDefinitionParser {
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
|
||||
boolean multiChannel = Boolean.parseBoolean(element.getAttribute("multi-channel"));
|
||||
String xPathExpression = element.getAttribute("xpath-expression");
|
||||
String strXpathExpressionPrefix = element.getAttribute("xpath-prefix");
|
||||
String strXpathExpressionNamespace = element.getAttribute("xpath-namespace");
|
||||
String nameSpaceMapRef = element.getAttribute("namespace-map");
|
||||
|
||||
String xPathExpressionRef = element.getAttribute("xpath-expression-ref");
|
||||
|
||||
boolean strXpathAttSpecified = StringUtils.hasText(xPathExpression)
|
||||
|| StringUtils.hasText(strXpathExpressionPrefix) || StringUtils.hasText(nameSpaceMapRef)
|
||||
|| StringUtils.hasText(strXpathExpressionNamespace);
|
||||
if ((strXpathAttSpecified && StringUtils.hasText(xPathExpressionRef))
|
||||
|| (!StringUtils.hasText(xPathExpression) && !StringUtils.hasText(xPathExpressionRef))) {
|
||||
NodeList xPathExpressionNodes = element.getElementsByTagNameNS(element.getNamespaceURI(), "xpath-expression");
|
||||
Assert.isTrue(xPathExpressionNodes.getLength() < 2, "Only one xpath-expression child can be specified");
|
||||
boolean xPathExpressionChildPresent = xPathExpressionNodes.getLength() == 1;
|
||||
boolean xPathReferencePresent = StringUtils.hasText(xPathExpressionRef);
|
||||
|
||||
if ((xPathExpressionChildPresent && xPathReferencePresent)
|
||||
|| (!xPathExpressionChildPresent && !xPathReferencePresent)) {
|
||||
throw new ConfigurationException("Exactly one of 'xpath-expression' or 'xpath-expression-ref' is required.");
|
||||
}
|
||||
|
||||
@@ -69,16 +67,15 @@ public class XPathRouterParser extends AbstractSingleBeanDefinitionParser {
|
||||
else {
|
||||
builder.getBeanDefinition().setBeanClass(XPathSingleChannelNameResolver.class);
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(xPathExpression)) {
|
||||
AbstractBeanDefinition xPathExpressionBeanDefinition = xpathBuilder.handleXpathExpression(element, parserContext);
|
||||
String xpathExpressionBeanName = BeanDefinitionReaderUtils.registerWithGeneratedName(
|
||||
xPathExpressionBeanDefinition, parserContext.getRegistry());
|
||||
builder.addConstructorArgReference(xpathExpressionBeanName);
|
||||
}
|
||||
else {
|
||||
|
||||
if (xPathExpressionChildPresent) {
|
||||
BeanDefinition beanDefinition = xpathParser.parse((Element) xPathExpressionNodes.item(0), parserContext);
|
||||
builder.addConstructorArgValue(beanDefinition);
|
||||
} else {
|
||||
builder.addConstructorArgReference(xPathExpressionRef);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -15,9 +15,8 @@
|
||||
*/
|
||||
package org.springframework.integration.xml.config;
|
||||
|
||||
import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.ConfigurationException;
|
||||
@@ -26,15 +25,16 @@ import org.springframework.integration.xml.selector.StringValueTestXPathMessageS
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jonas Partner
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class XPathSelectorParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
private XPathExpressionBeanDefintionBuilder xpathBuilder = new XPathExpressionBeanDefintionBuilder();
|
||||
|
||||
private XPathExpressionParser xpathParser = new XPathExpressionParser();
|
||||
|
||||
@Override
|
||||
protected boolean shouldGenerateId() {
|
||||
@@ -50,40 +50,40 @@ public class XPathSelectorParser extends AbstractSingleBeanDefinitionParser {
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
|
||||
String evaluationType = element.getAttribute("evaluation-result-type");
|
||||
String xPathExpression = element.getAttribute("xpath-expression");
|
||||
String strXpathExpressionPrefix = element.getAttribute("xpath-prefix");
|
||||
String strXpathExpressionNamespace = element.getAttribute("xpath-namespace");
|
||||
String nameSpaceMapRef = element.getAttribute("namespace-map");
|
||||
String xPathExpressionRef = element.getAttribute("xpath-expression-ref");
|
||||
String stringTestValue = element.getAttribute("string-test-value");
|
||||
|
||||
boolean strXpathAttSpecified = StringUtils.hasText(xPathExpression)
|
||||
|| StringUtils.hasText(strXpathExpressionPrefix) || StringUtils.hasText(nameSpaceMapRef)
|
||||
|| StringUtils.hasText(strXpathExpressionNamespace);
|
||||
|
||||
if ((strXpathAttSpecified && StringUtils.hasText(xPathExpressionRef))
|
||||
|| (!StringUtils.hasText(xPathExpression) && !StringUtils.hasText(xPathExpressionRef))) {
|
||||
|
||||
NodeList xPathExpressionNodes = element.getElementsByTagNameNS(element.getNamespaceURI(), "xpath-expression");
|
||||
Assert.isTrue(xPathExpressionNodes.getLength() < 2, "Only one xpath-expression child can be specified");
|
||||
boolean xPathExpressionChildPresent = xPathExpressionNodes.getLength() == 1;
|
||||
boolean xPathReferencePresent = StringUtils.hasText(xPathExpressionRef);
|
||||
|
||||
if ((xPathExpressionChildPresent && xPathReferencePresent)
|
||||
|| (!xPathExpressionChildPresent && !xPathReferencePresent)) {
|
||||
throw new ConfigurationException("Exactly one of 'xpath-expression' or 'xpath-expression-ref' is required.");
|
||||
}
|
||||
|
||||
if (evaluationType.equals("boolean")) {
|
||||
builder.getBeanDefinition().setBeanClass(BooleanTestXPathMessageSelector.class);
|
||||
Assert.state(!StringUtils.hasText(stringTestValue), "string-test-value should not be specified when evaluation-result-type is boolean");
|
||||
Assert.state(!StringUtils.hasText(stringTestValue),
|
||||
"string-test-value should not be specified when evaluation-result-type is boolean");
|
||||
}
|
||||
else if (evaluationType.equals("string")){
|
||||
Assert.hasText(stringTestValue, "string-test-value must be specified when evaluation-result-type is string");
|
||||
else if (evaluationType.equals("string")) {
|
||||
Assert
|
||||
.hasText(stringTestValue,
|
||||
"string-test-value must be specified when evaluation-result-type is string");
|
||||
builder.addConstructorArgValue(stringTestValue);
|
||||
builder.getBeanDefinition().setBeanClass(StringValueTestXPathMessageSelector.class);
|
||||
|
||||
} else {
|
||||
throw new ConfigurationException("Unrecognised value: " + evaluationType + " for evaluation-result-type only boolean or string supported");
|
||||
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(xPathExpression)) {
|
||||
AbstractBeanDefinition xPathExpressionBeanDefinition = xpathBuilder.handleXpathExpression(element, null);
|
||||
String xpathExpressionBeanName = BeanDefinitionReaderUtils.registerWithGeneratedName(
|
||||
xPathExpressionBeanDefinition, parserContext.getRegistry());
|
||||
builder.addConstructorArgReference(xpathExpressionBeanName);
|
||||
else {
|
||||
throw new ConfigurationException("Unrecognised value: " + evaluationType
|
||||
+ " for evaluation-result-type only boolean or string supported");
|
||||
}
|
||||
|
||||
if (xPathExpressionChildPresent) {
|
||||
BeanDefinition beanDefinition = xpathParser.parse((Element) xPathExpressionNodes.item(0), parserContext);
|
||||
builder.addConstructorArgValue(beanDefinition);
|
||||
}
|
||||
else {
|
||||
builder.addConstructorArgReference(xPathExpressionRef);
|
||||
|
||||
@@ -83,6 +83,7 @@
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="xpath-router">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
@@ -91,23 +92,16 @@
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:sequence>
|
||||
<xsd:element ref="beans:map" minOccurs="0" maxOccurs="1"/>
|
||||
<xsd:element ref="xpath-expression" maxOccurs="1" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="id" type="xsd:string" use="required" />
|
||||
<xsd:attribute name="xpath-expression-ref" type="xsd:string"
|
||||
use="optional" />
|
||||
<xsd:attribute name="xpath-expression" type="xsd:string"
|
||||
use="optional" />
|
||||
<xsd:attribute name="ns-prefix" type="xsd:string"
|
||||
use="optional" />
|
||||
<xsd:attribute name="ns-uri" type="xsd:string"
|
||||
use="optional" />
|
||||
<xsd:attribute name="multi-channel" type="xsd:boolean"
|
||||
default="false" />
|
||||
<xsd:attribute name="namespace-map" type="xsd:string"
|
||||
use="optional" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="xpath-selector">
|
||||
<xsd:complexType>
|
||||
<xsd:annotation>
|
||||
@@ -116,16 +110,10 @@
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:sequence>
|
||||
<xsd:element ref="beans:map" minOccurs="0" maxOccurs="1"/>
|
||||
<xsd:element ref="xpath-expression" maxOccurs="1" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="id" type="xsd:string" use="required" />
|
||||
<xsd:attribute name="xpath-expression-ref" type="xsd:string"
|
||||
use="optional" />
|
||||
<xsd:attribute name="xpath-expression" type="xsd:string"
|
||||
use="optional" />
|
||||
<xsd:attribute name="ns-prefix" type="xsd:string"
|
||||
use="optional" />
|
||||
<xsd:attribute name="ns-uri" type="xsd:string"
|
||||
<xsd:attribute name="xpath-expression-ref" type="xsd:string"
|
||||
use="optional" />
|
||||
<xsd:attribute name="evaluation-result-type" use="required">
|
||||
<xsd:simpleType>
|
||||
@@ -135,8 +123,6 @@
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="namespace-map" type="xsd:string"
|
||||
use="optional" />
|
||||
<xsd:attribute name="string-test-value" type="xsd:string"
|
||||
use="optional" />
|
||||
|
||||
@@ -154,7 +140,7 @@
|
||||
<xsd:element ref="beans:map" minOccurs="0" maxOccurs="1"/>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="id" type="xsd:string" use="optional" />
|
||||
<xsd:attribute name="xpath-expression" type="xsd:string"
|
||||
<xsd:attribute name="expression" type="xsd:string"
|
||||
use="optional" />
|
||||
<xsd:attribute name="ns-prefix" type="xsd:string"
|
||||
use="optional" />
|
||||
|
||||
@@ -26,14 +26,14 @@ public class XPathExpressionParserTests {
|
||||
|
||||
@Test
|
||||
public void testSimpleStringExpression() throws Exception {
|
||||
String xmlDoc = "<si-xml:xpath-expression id='xpathExpression' xpath-expression='/name' />";
|
||||
String xmlDoc = "<si-xml:xpath-expression id='xpathExpression' expression='/name' />";
|
||||
XPathExpression xPathExpression = getXPathExpression(xmlDoc);
|
||||
assertEquals("outputOne",xPathExpression.evaluateAsString(XmlTestUtil.getDocumentForString("<name>outputOne</name>")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamespacedStringExpression() throws Exception {
|
||||
String xmlDoc = "<si-xml:xpath-expression id='xpathExpression' xpath-expression='/ns1:name' ns-prefix='ns1' ns-uri='www.example.org' />";
|
||||
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>")));
|
||||
@@ -41,7 +41,7 @@ public class XPathExpressionParserTests {
|
||||
|
||||
@Test
|
||||
public void testStringExpressionWithNamespaceMapReference() throws Exception {
|
||||
StringBuffer xmlDoc = new StringBuffer("<si-xml:xpath-expression id='xpathExpression' xpath-expression='/ns1:name' namespace-map='myNamespaces' />");
|
||||
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>")));
|
||||
@@ -50,7 +50,7 @@ public class XPathExpressionParserTests {
|
||||
|
||||
@Test
|
||||
public void testStringExpressionWithNamespaceInnerBean() throws Exception {
|
||||
StringBuffer xmlDoc = new StringBuffer("<si-xml:xpath-expression id='xpathExpression' xpath-expression='/ns1:name' >");
|
||||
StringBuffer xmlDoc = new StringBuffer("<si-xml:xpath-expression id='xpathExpression' expression='/ns1:name' >");
|
||||
xmlDoc.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>")));
|
||||
@@ -60,7 +60,7 @@ public class XPathExpressionParserTests {
|
||||
|
||||
@Test(expected=BeanDefinitionStoreException.class)
|
||||
public void testNamespacePrefixButNoUri() throws Exception {
|
||||
String xmlDoc = "<si-xml:xpath-expression id='xpathExpression' xpath-expression='/ns1:name' ns-prefix='ns1' />";
|
||||
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>")));
|
||||
|
||||
@@ -36,7 +36,7 @@ public class XPathRouterParserTests {
|
||||
Document doc = XmlTestUtil.getDocumentForString("<name>outputOne</name>");
|
||||
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
|
||||
|
||||
TestXmlApplicationContext ctx = TestXmlApplicationContextHelper.getTestAppContext("<si-xml:xpath-router id='router' xpath-expression='/name' />");
|
||||
TestXmlApplicationContext ctx = TestXmlApplicationContextHelper.getTestAppContext("<si-xml:xpath-router id='router'><si-xml:xpath-expression expression='/name'/></si-xml:xpath-router>");
|
||||
XPathSingleChannelNameResolver router = (XPathSingleChannelNameResolver) ctx.getBean("router");
|
||||
|
||||
String[] channelNames = router.resolveChannelNames(docMessage);
|
||||
@@ -50,7 +50,8 @@ public class XPathRouterParserTests {
|
||||
Document doc = XmlTestUtil.getDocumentForString("<ns1:name xmlns:ns1='www.example.org'>outputOne</ns1:name>");
|
||||
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
|
||||
|
||||
TestXmlApplicationContext ctx = TestXmlApplicationContextHelper.getTestAppContext("<si-xml:xpath-router id='router' xpath-expression='/ns2:name' ns-prefix='ns2' ns-uri='www.example.org' />");
|
||||
TestXmlApplicationContext ctx =
|
||||
TestXmlApplicationContextHelper.getTestAppContext("<si-xml:xpath-router id='router'><si-xml:xpath-expression expression='/ns2:name' ns-prefix='ns2' ns-uri='www.example.org' /></si-xml:xpath-router>");
|
||||
XPathSingleChannelNameResolver router = (XPathSingleChannelNameResolver) ctx.getBean("router");
|
||||
|
||||
String[] channelNames = router.resolveChannelNames(docMessage);
|
||||
@@ -65,10 +66,10 @@ public class XPathRouterParserTests {
|
||||
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
|
||||
|
||||
StringBuffer buffer = new StringBuffer(
|
||||
"<si-xml:xpath-router id='router' xpath-expression='/ns1:name/ns2:type' >");
|
||||
"<si-xml:xpath-router id='router'><si-xml:xpath-expression expression='/ns1:name/ns2:type'> ");
|
||||
buffer
|
||||
.append("<map><entry key='ns1' value='www.example.org' /> <entry key='ns2' value='www.example.org2'/></map>");
|
||||
buffer.append("</si-xml:xpath-router>");
|
||||
buffer.append("</si-xml:xpath-expression></si-xml:xpath-router>");
|
||||
|
||||
TestXmlApplicationContext ctx = TestXmlApplicationContextHelper.getTestAppContext(buffer.toString());
|
||||
XPathSingleChannelNameResolver router = (XPathSingleChannelNameResolver) ctx.getBean("router");
|
||||
@@ -84,7 +85,7 @@ public class XPathRouterParserTests {
|
||||
.getDocumentForString("<ns1:name xmlns:ns1='www.example.org' xmlns:ns2='www.example.org2'><ns2:type>outputOne</ns2:type></ns1:name>");
|
||||
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
|
||||
StringBuffer buffer = new StringBuffer(
|
||||
"<si-xml:xpath-router id='router' xpath-expression='/ns1:name/ns2:type' namespace-map='nsMap'>");
|
||||
"<si-xml:xpath-router id='router' ><si-xml:xpath-expression expression='/ns1:name/ns2:type' namespace-map='nsMap'/>");
|
||||
buffer
|
||||
.append("</si-xml:xpath-router>")
|
||||
.append("<util:map id='nsMap'><entry key='ns1' value='www.example.org' /><entry key='ns2' value='www.example.org2' /></util:map>");
|
||||
@@ -98,14 +99,6 @@ public class XPathRouterParserTests {
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void testNamespacedWithNoPrefixStringExpression() throws Exception {
|
||||
TestXmlApplicationContextHelper.getTestAppContext("<si-xml:xpath-router id='router' xpath-expression='/ns2:name' xpath-namespace='www.example.org' />");
|
||||
}
|
||||
|
||||
@Test(expected = Exception.class)
|
||||
public void testPrefixWithNoNamespaceStringExpression() throws Exception {
|
||||
TestXmlApplicationContextHelper.getTestAppContext("<si-xml:xpath-router id='router' xpath-expression='/ns2:name' xpath-prefix='ns2' />");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class XPathSelectorParserTests {
|
||||
|
||||
@Test
|
||||
public void testSimpleStringExpressionBoolean() throws Exception {
|
||||
String contextXml = "<si-xml:xpath-selector id='selector' xpath-expression='/name' evaluation-result-type='boolean' />";
|
||||
String contextXml = "<si-xml:xpath-selector id='selector' evaluation-result-type='boolean' ><si-xml:xpath-expression expression='/name'/></si-xml:xpath-selector>";
|
||||
MessageSelector selector =getSelector( contextXml);
|
||||
|
||||
assertTrue(selector.accept(new GenericMessage<Document>(XmlTestUtil.getDocumentForString("<name>outputOne</name>"))));
|
||||
@@ -37,7 +37,7 @@ public class XPathSelectorParserTests {
|
||||
|
||||
@Test
|
||||
public void testStringExpressionWithNamespaceBoolean() throws Exception {
|
||||
String contextXml = "<si-xml:xpath-selector id='selector' xpath-expression='/ns:name' ns-prefix='ns' ns-uri='www.example.org' evaluation-result-type='boolean' />";
|
||||
String contextXml = "<si-xml:xpath-selector id='selector' evaluation-result-type='boolean'><si-xml:xpath-expression expression='/ns:name' ns-prefix='ns' ns-uri='www.example.org'/> </si-xml:xpath-selector>";
|
||||
MessageSelector selector = getSelector(contextXml);
|
||||
|
||||
assertTrue(selector.accept(new GenericMessage<Document>(XmlTestUtil.getDocumentForString("<ns1:name xmlns:ns1='www.example.org'>outputOne</ns1:name>"))));
|
||||
@@ -47,7 +47,7 @@ public class XPathSelectorParserTests {
|
||||
|
||||
@Test
|
||||
public void testStringExpressionWithNestedMap() throws Exception {
|
||||
String contextXml = "<si-xml:xpath-selector id='selector' xpath-expression='/ns:name' ns-prefix='ns' ns-uri='www.example.org' evaluation-result-type='boolean' />";
|
||||
String contextXml = "<si-xml:xpath-selector id='selector' evaluation-result-type='boolean'><si-xml:xpath-expression expression='/ns:name' ns-prefix='ns' ns-uri='www.example.org' /></si-xml:xpath-selector>";
|
||||
MessageSelector selector = getSelector(contextXml);
|
||||
|
||||
assertTrue(selector.accept(new GenericMessage<Document>(XmlTestUtil.getDocumentForString("<ns1:name xmlns:ns1='www.example.org'>outputOne</ns1:name>"))));
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
package org.springframework.integration.xml.transformer;
|
||||
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.*;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
import javax.xml.transform.sax.SAXResult;
|
||||
@@ -26,7 +27,6 @@ import org.junit.Test;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.xml.util.XmlTestUtil;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
public class ResultToStringTransfomerTests {
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.integration.xml.util;
|
||||
|
||||
import java.io.StringReader;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
Reference in New Issue
Block a user