1 16 package org.apache.cocoon.serialization; 17 18 import javax.xml.transform.OutputKeys ; 19 import javax.xml.transform.sax.TransformerHandler ; 20 import javax.xml.transform.stream.StreamResult ; 21 22 import org.apache.avalon.framework.configuration.Configuration; 23 import org.apache.avalon.framework.configuration.ConfigurationException; 24 import org.apache.cocoon.CascadingIOException; 25 26 import java.io.IOException ; 27 import java.io.OutputStream ; 28 29 33 34 public class XMLSerializer extends AbstractTextSerializer { 35 36 39 public void configure(Configuration conf) 40 throws ConfigurationException { 41 super.configure( conf ); 42 this.format.put(OutputKeys.METHOD,"xml"); 43 } 44 45 49 public void setOutputStream(OutputStream out) throws IOException { 50 super.setOutputStream(out); 51 try { 52 TransformerHandler handler = this.getTransformerHandler(); 53 handler.getTransformer().setOutputProperties(this.format); 54 handler.setResult(new StreamResult (this.output)); 55 this.setContentHandler(handler); 56 this.setLexicalHandler(handler); 57 } catch (Exception e) { 58 final String message = "Cannot set XMLSerializer outputstream"; 59 throw new CascadingIOException(message, e); 60 } 61 } 62 63 } 64 | Popular Tags |