Created
June 12, 2012 08:05
-
-
Save yamanyar/2916071 to your computer and use it in GitHub Desktop.
XsltPayloadTransformer with a custom xslt factory.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.yamanyar.esb.transformers; | |
import net.sf.saxon.TransformerFactoryImpl; | |
import org.springframework.core.io.Resource; | |
import org.springframework.integration.xml.transformer.ResultTransformer; | |
import org.springframework.integration.xml.transformer.XsltPayloadTransformer; | |
import javax.xml.transform.TransformerFactory; | |
import javax.xml.transform.stream.StreamSource; | |
import java.io.IOException; | |
/** | |
* Created by IntelliJ IDEA. | |
* User: U068169 | |
* Date: 6/12/12 | |
* Time: 10:41 AM | |
* To change this template use File | Settings | File Templates. | |
*/ | |
public class SaxonXsltTransformer extends XsltPayloadTransformer { | |
public SaxonXsltTransformer(Resource xslResource, ResultTransformer resultTransformer) throws Exception { | |
super(TransformerFactoryImpl.newInstance().newTemplates( | |
createStreamSourceOnResource(xslResource)), resultTransformer); | |
} | |
/** | |
* Compensate for the fact that a Resource <i>may</i> not be a File or even | |
* addressable through a URI. If it is, we want the created StreamSource to | |
* read other resources relative to the provided one. If it isn't, it loads | |
* from the default path. | |
*/ | |
private static StreamSource createStreamSourceOnResource(Resource xslResource) throws IOException { | |
try { | |
String systemId = xslResource.getURI().toString(); | |
return new StreamSource(xslResource.getInputStream(), systemId); | |
} catch (IOException e) { | |
return new StreamSource(xslResource.getInputStream()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment