Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2002-2011 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.router;
 
 import java.util.List;
 import java.util.Map;
 
Message Router that uses org.springframework.xml.xpath.XPathExpression evaluation to determine channel names.

Author(s):
Jonas Partner
Oleg Zhurakousky
 
 public class XPathRouter extends AbstractMappingMessageRouter {
 
 	private volatile NodeMapper<ObjectnodeMapper = new TextContentNodeMapper();
 
 	private final XPathExpression xPathExpression;
 
 	
 	private volatile boolean evaluateAsString = false;

Create a router that uses an XPath expression. The expression may contain zero or more namespace prefixes.

Parameters:
expression the XPath expression as a String
namespaces map of namespaces with prefixes as the map keys
 
 	public XPathRouter(String expressionMap<StringStringnamespaces) {
 		Assert.hasText(expression"expression must not be empty");
 		this. = XPathExpressionFactory.createXPathExpression(expressionnamespaces);
 	}

Create a router uses an XPath expression with one namespace. For example, expression='/ns1:one/@type' prefix='ns1' namespace='www.example.org'

Parameters:
expression the XPath expression as a String
prefix namespace prefix
namespace namespace uri
 
 	public XPathRouter(String expressionString prefixString namespace) {
 		Assert.hasText(expression"expression must not be empty");
 		Map<StringStringnamespaces = new HashMap<StringString>();
 		namespaces.put(prefixnamespace);
 		this. = XPathExpressionFactory.createXPathExpression(expressionnamespaces);
 	}

Create a router that uses an XPath expression with no namespaces. For example '/one/@type'

Parameters:
expression the XPath expression as a String
 
 	public XPathRouter(String expression) {
 		Assert.hasText(expression"expression must not be empty");
 		this. = XPathExpressionFactory.createXPathExpression(expression);
 	}

Create a router that uses the provided XPath expression.

Parameters:
expression the XPath expression
 
 	public XPathRouter(XPathExpression expression) {
 		Assert.notNull(expression"expression must not be null");
 		this. = expression;
 	}
 
 	public void setEvaluateAsString(boolean evaluateAsString) {
		this. = evaluateAsString;
	}

Specify the Converter to use when converting payloads prior to XPath evaluation.
	public void setConverter(XmlPayloadConverter converter) {
		Assert.notNull(converter"converter must not be null");
		this. = converter;
	}
		return "xml:xpath-router";
	}
	protected List<ObjectgetChannelKeys(Message<?> message) {
		Node node = this..convertToNode(message.getPayload());
		if (this.) {
			return Collections.singletonList((Objectthis..evaluateAsString(node));
		}
		else {
			return this..evaluate(nodethis.);
		}
	}
	private static class TextContentNodeMapper implements NodeMapper<Object> {
		public Object mapNode(Node nodeint nodeNumthrows DOMException {
			return node.getTextContent();
		}
	}
New to GrepCode? Check out our FAQ X