1 package net.sf.saxon.event; 2 import net.sf.saxon.charcode.UnicodeCharacterSet; 3 import net.sf.saxon.trans.DynamicError; 4 import net.sf.saxon.trans.XPathException; 5 6 import javax.xml.transform.OutputKeys ; 7 8 12 13 public class TEXTEmitter extends XMLEmitter { 14 15 18 19 public void open () throws XPathException 20 { 21 declarationIsWritten = true; 23 24 empty = true; 25 26 String byteOrderMark = outputProperties.getProperty(SaxonOutputKeys.BYTE_ORDER_MARK); 28 29 if ("yes".equals(byteOrderMark) && 30 "UTF-8".equalsIgnoreCase(outputProperties.getProperty(OutputKeys.ENCODING))) { 31 try { 32 openDocument(); 33 writer.write('\uFEFF'); 34 empty = false; 35 } catch (java.io.IOException err) { 36 } 38 } 39 40 if (characterSet==null) { 41 characterSet = UnicodeCharacterSet.getInstance(); 42 } 43 } 44 45 52 53 public void characters(CharSequence chars, int locationId, int properties) throws XPathException { 54 if (empty) { 55 openDocument(); 56 } 57 if ((properties & ReceiverOptions.NO_SPECIAL_CHARS) == 0) { 58 int badchar = testCharacters(chars); 59 if (badchar != 0) { 60 throw new DynamicError( 61 "Output character not available in this encoding (decimal " + badchar + ")"); 62 } 63 } 64 try { 65 writer.write(chars.toString()); 66 } catch (java.io.IOException err) { 67 throw new DynamicError(err); 68 } 69 } 70 71 78 79 public void startElement(int nameCode, int typeCode, int locationId, int properties) { 80 } 82 83 public void namespace(int namespaceCode, int properties) {} 84 85 public void attribute(int nameCode, int typeCode, CharSequence value, int locationId, int properties) {} 86 87 88 92 93 public void endElement() { 94 } 96 97 101 102 public void processingInstruction(String name, CharSequence value, int locationId, int properties) throws XPathException {} 103 104 108 109 public void comment(CharSequence chars, int locationId, int properties) throws XPathException {} 110 111 } 112 113 | Popular Tags |