1 package net.sf.saxon; 2 import net.sf.saxon.event.PipelineConfiguration; 3 import net.sf.saxon.event.ReceivingContentHandler; 4 import net.sf.saxon.event.ResultWrapper; 5 import net.sf.saxon.trans.XPathException; 6 import org.xml.sax.SAXException ; 7 8 import javax.xml.transform.Result ; 9 import javax.xml.transform.Transformer ; 10 import javax.xml.transform.sax.TransformerHandler ; 11 import javax.xml.transform.stream.StreamResult ; 12 import java.util.Properties ; 13 14 21 22 public class IdentityTransformerHandler extends ReceivingContentHandler implements TransformerHandler { 23 24 private Result result; 25 private String systemId; 26 private Controller controller; 27 28 33 34 protected IdentityTransformerHandler(Controller controller) { 35 this.controller = controller; 36 setPipelineConfiguration(controller.makePipelineConfiguration()); 37 38 } 39 40 43 44 public Transformer getTransformer() { 45 return controller; 46 } 47 48 51 52 public void setSystemId(String url) { 53 systemId = url; 54 } 55 56 59 60 public String getSystemId() { 61 return systemId; 62 } 63 64 67 68 public void setResult(Result result) { 69 if (result==null) { 70 throw new IllegalArgumentException ("Result must not be null"); 71 } 72 this.result = result; 73 } 74 75 78 79 public Result getResult() { 80 return result; 81 } 82 83 86 87 public void startDocument() throws SAXException { 88 if (result==null) { 89 result = new StreamResult (System.out); 90 } 91 try { 92 Properties props = controller.getOutputProperties(); 93 PipelineConfiguration pipe = controller.makePipelineConfiguration(); 94 setReceiver(ResultWrapper.getReceiver(result, pipe, props)); 95 setPipelineConfiguration(pipe); 96 } catch (XPathException err) { 97 throw new SAXException (err); 98 } 99 super.startDocument(); 100 } 101 102 } 103 104 | Popular Tags |