Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2002-2014 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.transformer;
 
 
Transformer implementation that evaluates an XPath expression against the inbound Message payload and returns a Message whose payload is the result of that evaluation. Prior to evaluation, the payload may be converted by the configured org.springframework.integration.xml.XmlPayloadConverter instance. The default converter type is org.springframework.integration.xml.DefaultXmlPayloadConverter.

The evaluation result type will depend on either the enumeration value provided to setEvaluationType(org.springframework.integration.xml.xpath.XPathEvaluationType) or the presence of a org.springframework.xml.xpath.NodeMapper, which takes precedence. If no org.springframework.xml.xpath.NodeMapper or evaluation type is configured explicitly, the default evaluation type is org.springframework.integration.xml.xpath.XPathEvaluationType.STRING_RESULT.

Author(s):
Mark Fisher
Since:
2.0
 
 public class XPathTransformer extends AbstractTransformer {
 
 	private final XPathExpression xpathExpression;
 
 
 
 	private volatile NodeMapper<?> nodeMapper;


Create an XPathTransformer that will create an XPath expression from the given String to be evaluated against converted inbound Message payloads.

Parameters:
expression The expression.
 
 	public XPathTransformer(String expression) {
 		this. = XPathExpressionFactory.createXPathExpression(expression);
 	}

Create an XPathTransformer that will evaluate the given org.springframework.xml.xpath.XPathExpression against converted inbound Message payloads.

Parameters:
expression The expression.
 
 	public XPathTransformer(XPathExpression expression) {
 		Assert.notNull(expression"expression must not be null");
 		this. = expression;
 	}


 
 	public void setEvaluationType(XPathEvaluationType evaluationType) {
 		Assert.notNull(evaluationType"evaluationType must not be null.");
 		this. = evaluationType;
 	}

Set a org.springframework.xml.xpath.NodeMapper to use for generating the result object. By default the NodeMapper is null, but if explicitly set, type determination is the responsibility of the NodeMapper, taking precedence over any configured evaluationType.

Parameters:
nodeMapper The node mapper.
 
 	public void setNodeMapper(NodeMapper<?> nodeMapper) {
 		this. = nodeMapper;
 	}

Specify the org.springframework.integration.xml.XmlPayloadConverter to use when converting a Message payload prior to XPath evaluation.

Parameters:
converter The payload converter.
	public void setConverter(XmlPayloadConverter converter) {
		Assert.notNull(converter"converter must not be null");
		this. = converter;
	}
		return "xml:xpath-transformer";
	}
	protected Object doTransform(Message<?> messagethrows Exception {
		Node node = this..convertToNode(message.getPayload());
		Object result = null;
		if (this. != null) {
			result = this..evaluateAsObject(nodethis.);
		}
		else {
			result = this..evaluateXPath(this.node);
		}
		return result;
	}
New to GrepCode? Check out our FAQ X