1 17 package org.apache.servicemix.jbi.jaxp; 18 19 import javax.xml.transform.Source ; 20 import javax.xml.transform.TransformerException ; 21 import javax.xml.transform.stream.StreamResult ; 22 23 import java.io.StringWriter ; 24 25 28 public class SourceMarshaler { 29 private SourceTransformer transformer = new SourceTransformer(); 30 31 public Source asSource(String text) { 32 return new StringSource(text); 33 } 34 35 public String asString(Source source) throws TransformerException { 36 StringWriter buffer = new StringWriter (); 37 transformer.toResult(source, new StreamResult (buffer)); 38 return buffer.toString(); 39 } 40 41 public SourceTransformer getTransformer() { 42 return transformer; 43 } 44 45 public void setTransformer(SourceTransformer transformer) { 46 this.transformer = transformer; 47 } 48 } 49 | Popular Tags |