1 17 package org.apache.servicemix.components.util; 18 19 import org.apache.servicemix.jbi.jaxp.SourceTransformer; 20 import org.w3c.dom.Node ; 21 22 import javax.jbi.messaging.MessageExchange; 23 import javax.jbi.messaging.NormalizedMessage; 24 import javax.xml.transform.OutputKeys ; 25 import javax.xml.transform.Source ; 26 import javax.xml.transform.Transformer ; 27 import javax.xml.transform.TransformerFactory ; 28 import javax.xml.transform.dom.DOMSource ; 29 import javax.xml.transform.stream.StreamResult ; 30 31 import java.io.OutputStream ; 32 33 38 public class StreamWriterComponent extends OutBinding { 39 40 private OutputStream out = System.out; 41 42 45 public OutputStream getOut() { 46 return out; 47 } 48 49 52 public void setOut(OutputStream out) { 53 this.out = out; 54 } 55 56 57 58 61 62 protected void process(MessageExchange exchange, NormalizedMessage message) throws Exception { 63 TransformerFactory tFactory = TransformerFactory.newInstance(); 64 Transformer transformer = tFactory.newTransformer(); 65 transformer.setOutputProperty(OutputKeys.INDENT, "yes"); 66 Source content = null; 67 Node document = (Node ) message.getProperty(SourceTransformer.CONTENT_DOCUMENT_PROPERTY); 68 if (document != null) { 69 content = new DOMSource (document); 70 } 71 else { 72 content = message.getContent(); 73 } 74 transformer.transform(content, new StreamResult (out)); 75 done(exchange); 76 } 77 } 78 | Popular Tags |