INT-3067 Xslt method=text StringResult coercion
Previously there was a need to add `result-type="StringResult"` to <int-xml:xslt-transformer> for xslt output `method='text'` in case payload was non-standard type (e.g. `File`), if we wanted to get result as text. * Add coercion to `StringResult` code, if `Transformer`'s property `method` is 'text' and there is no explicit `resultFactory` provided. * Add documentation to reference manual JIRA: https://jira.springsource.org/browse/INT-3067
This commit is contained in:
committed by
Gunnar Hillert
parent
d549734837
commit
41fe514469
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -25,9 +25,10 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Utility methods for the XML namespace.
|
||||
*
|
||||
*
|
||||
* @author Jonas Partner
|
||||
* @author Mark Fisher
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
abstract class XmlNamespaceUtils {
|
||||
|
||||
@@ -54,7 +55,7 @@ abstract class XmlNamespaceUtils {
|
||||
else if (resultType.equals(STRING_RESULT)) {
|
||||
builder.addPropertyValue("resultFactory", new StringResultFactory());
|
||||
}
|
||||
else {
|
||||
else if (resultType.equals(DOM_RESULT)) {
|
||||
builder.addPropertyValue("resultFactory", new DomResultFactory());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ import org.springframework.xml.transform.StringSource;
|
||||
* @author Jonas Partner
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
public class XsltPayloadTransformer extends AbstractTransformer {
|
||||
|
||||
@@ -93,6 +94,8 @@ public class XsltPayloadTransformer extends AbstractTransformer {
|
||||
|
||||
private volatile ResultFactory resultFactory = new DomResultFactory();
|
||||
|
||||
private volatile boolean resultFactoryExplicitlySet;
|
||||
|
||||
private volatile boolean alwaysUseSourceFactory = false;
|
||||
|
||||
private volatile boolean alwaysUseResultFactory = false;
|
||||
@@ -135,6 +138,7 @@ public class XsltPayloadTransformer extends AbstractTransformer {
|
||||
public void setResultFactory(ResultFactory resultFactory) {
|
||||
Assert.notNull(sourceFactory, "ResultFactory must not be null");
|
||||
this.resultFactory = resultFactory;
|
||||
this.resultFactoryExplicitlySet = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -214,7 +218,13 @@ public class XsltPayloadTransformer extends AbstractTransformer {
|
||||
}
|
||||
|
||||
private Object transformSource(Source source, Object payload, Transformer transformer) throws TransformerException {
|
||||
Result result = this.resultFactory.createResult(payload);
|
||||
Result result;
|
||||
if (!this.resultFactoryExplicitlySet && "text".equals(transformer.getOutputProperties().getProperty("method"))) {
|
||||
result = new StringResult();
|
||||
}
|
||||
else {
|
||||
result = this.resultFactory.createResult(payload);
|
||||
}
|
||||
transformer.transform(source, result);
|
||||
if (this.resultTransformer != null) {
|
||||
return this.resultTransformer.transformResult(result);
|
||||
|
||||
Reference in New Issue
Block a user