1 package com.icl.saxon.output; 2 import com.icl.saxon.*; 3 import com.icl.saxon.om.NamePool; 4 import org.xml.sax.ContentHandler ; 5 import org.xml.sax.DocumentHandler ; 6 import org.xml.sax.Attributes ; 7 import org.xml.sax.Locator ; 8 import java.io.*; 9 import javax.xml.transform.Result ; 10 import javax.xml.transform.TransformerException ; 11 import java.util.Properties ; 12 13 23 24 public abstract class Emitter implements Result 25 { 26 27 protected NamePool namePool; 28 protected String systemId; 29 protected Writer writer; 30 protected OutputStream outputStream; 31 protected Properties outputProperties; 32 protected Locator locator; 33 34 37 38 public void setNamePool(NamePool namePool) { 39 this.namePool = namePool; 40 } 41 42 45 46 public NamePool getNamePool() { 47 return namePool; 48 } 49 50 53 54 public void setSystemId(String systemId) { 55 this.systemId = systemId; 56 } 57 58 61 62 public String getSystemId() { 63 return systemId; 64 } 65 66 69 70 public void setOutputProperties(Properties props) { 71 outputProperties = props; 72 } 73 74 77 78 public Properties getOutputProperties() { 79 return outputProperties; 80 } 81 82 86 87 public boolean usesWriter() { 88 return true; 89 } 90 91 94 95 public void setWriter(Writer writer) { 96 this.writer = writer; 97 } 98 99 102 103 public Writer getWriter() { 104 return writer; 105 } 106 107 110 111 public void setOutputStream(OutputStream stream) { 112 this.outputStream = stream; 113 } 114 115 118 119 public OutputStream getOutputStream() { 120 return outputStream; 121 } 122 123 126 127 public abstract void startDocument() throws TransformerException ; 128 129 132 133 public abstract void endDocument() throws TransformerException ; 134 135 144 145 public abstract void startElement(int nameCode, Attributes attributes, 146 int[] namespaces, int nscount) throws TransformerException ; 147 148 154 155 public abstract void endElement(int nameCode) throws TransformerException ; 156 157 160 161 public abstract void characters(char[] chars, int start, int len) throws TransformerException ; 162 163 166 167 public abstract void processingInstruction(String name, String data) throws TransformerException ; 168 169 173 174 public abstract void comment (char[] chars, int start, int length) throws TransformerException ; 175 176 181 182 public void setEscaping(boolean escaping) throws TransformerException {} 183 184 188 189 public void setDocumentLocator(Locator locator) { 190 this.locator = locator; 191 } 192 193 197 198 public void setUnparsedEntity(String name, String uri) throws TransformerException {} 199 200 203 204 public static Emitter makeEmitter (String className) throws TransformerException 205 { 206 Object handler = Loader.getInstance(className); 207 208 if (handler instanceof Emitter) { 209 return (Emitter)handler; 210 } else if (handler instanceof DocumentHandler ) { 211 DocumentHandlerProxy emitter = new DocumentHandlerProxy(); 212 emitter.setUnderlyingDocumentHandler((DocumentHandler )handler); 213 return emitter; 214 } else if (handler instanceof ContentHandler ) { 215 ContentHandlerProxy emitter = new ContentHandlerProxy(); 216 emitter.setUnderlyingContentHandler((ContentHandler )handler); 217 return emitter; 218 } else { 219 throw new TransformerException ("Failed to load emitter " + className + 220 ": it is not a SAX DocumentHandler or SAX2 ContentHandler"); 221 } 222 223 } 224 225 } 226 227 | Popular Tags |