1 package com.icl.saxon; 2 import com.icl.saxon.om.Builder; 3 import com.icl.saxon.om.NamePool; 4 import com.icl.saxon.om.DocumentInfo; 5 6 import javax.xml.transform.*; 7 import javax.xml.transform.sax.TransformerHandler ; 8 9 import org.xml.sax.*; 10 11 12 19 20 public class TransformerHandlerImpl extends ContentEmitter implements TransformerHandler { 21 22 Controller controller; 23 Builder builder; 24 Result result; 25 String systemId; 26 27 32 33 protected TransformerHandlerImpl(Controller controller) { 34 this.controller = controller; 35 setNamePool(controller.getNamePool()); 36 builder = controller.makeBuilder(); 37 builder.setNamePool(controller.getNamePool()); 38 this.setEmitter(builder); 39 41 } 42 43 46 47 public Transformer getTransformer() { 48 return controller; 49 } 50 51 54 55 public void setSystemId(String url) { 56 systemId = url; 57 builder.setSystemId(url); 58 } 59 60 63 64 public String getSystemId() { 65 return systemId; 66 } 67 68 71 72 public void setResult(Result result) { 73 if (result==null) { 74 throw new IllegalArgumentException ("Result must not be null"); 75 } 76 this.result = result; 77 } 78 79 82 83 public Result getResult() { 84 return result; 85 } 86 87 91 92 public void endDocument() throws SAXException { 93 super.endDocument(); 95 DocumentInfo doc = builder.getCurrentDocument(); 96 if (doc==null) { 97 throw new SAXException("No source document has been built"); 98 } 99 controller.getDocumentPool().add(doc, null); 100 try { 101 controller.transformDocument(doc, result); 102 } catch (TransformerException err) { 103 throw new SAXException(err); 105 } 106 } 107 108 109 110 111 } 112 113 | Popular Tags |