1 package com.icl.saxon; 2 import com.icl.saxon.om.NamePool; 3 import com.icl.saxon.output.Outputter; 4 import com.icl.saxon.output.GeneralOutputter; 5 import com.icl.saxon.output.Emitter; 6 7 import javax.xml.transform.*; 8 import javax.xml.transform.sax.TransformerHandler ; 9 import javax.xml.transform.stream.StreamResult ; 10 11 import org.xml.sax.*; 12 13 import java.util.Properties ; 14 15 22 23 public class IdentityTransformerHandler extends ContentEmitter implements TransformerHandler { 24 25 Result result; 26 String systemId; 27 Controller controller; 28 GeneralOutputter outputter; 29 30 35 36 protected IdentityTransformerHandler(Controller controller) { 37 this.controller = controller; 38 setNamePool(controller.getNamePool()); 39 40 } 41 42 45 46 public Transformer getTransformer() { 47 return controller; 48 } 49 50 53 54 public void setSystemId(String url) { 55 systemId = url; 56 } 57 58 61 62 public String getSystemId() { 63 return systemId; 64 } 65 66 69 70 public void setResult(Result result) { 71 if (result==null) { 72 throw new IllegalArgumentException ("Result must not be null"); 73 } 74 this.result = result; 75 } 76 77 80 81 public Result getResult() { 82 return result; 83 } 84 85 88 89 public void startDocument() throws SAXException { 90 if (result==null) { 91 result = new StreamResult (System.out); 92 } 93 try { 94 NamePool pool = controller.getNamePool(); 95 Properties props = controller.getOutputProperties(); 96 outputter = new GeneralOutputter(pool); 97 outputter.setOutputDestination(props, result); 98 Emitter emitter = outputter.getEmitter(); 99 setNamePool(pool); 100 setEmitter(emitter); 101 } catch (TransformerException err) { 102 throw new SAXException(err); 103 } 104 super.startDocument(); 105 } 106 107 110 111 public void endDocument() throws SAXException { 112 try { 113 outputter.close(); 114 } catch (TransformerException err) { 115 throw new SAXException(err); 116 } 117 } 118 119 120 121 122 } 123 124 | Popular Tags |