1 package com.icl.saxon.output; 2 import com.icl.saxon.*; 3 import java.util.Properties ; 4 import javax.xml.transform.TransformerException ; 5 import javax.xml.transform.ErrorListener ; 6 7 14 15 public final class StringOutputter extends Outputter { 16 17 StringBuffer buffer; 18 int ignoreElements = 0; 19 ErrorListener errorListener = null; 20 21 public StringOutputter(StringBuffer buffer) { 22 this.buffer = buffer; 23 emitter = new StringEmitter(buffer); 25 } 26 27 public void setErrorListener(ErrorListener listener) { 28 errorListener = listener; 29 } 30 31 public void reset() throws TransformerException { 32 } 34 35 36 public Properties getOutputProperties() { 37 return TextFragment.getProperties(); 38 } 39 40 46 47 public void write(String s) throws TransformerException { 48 if (ignoreElements==0) { 49 buffer.append(s); 50 } 51 } 52 53 60 61 public void writeContent(String s) throws TransformerException { 62 if (s==null) return; 63 if (ignoreElements==0) { 64 buffer.append(s); 65 } 66 } 67 68 77 78 public void writeContent(char[] chars, int start, int length) throws TransformerException { 79 if (ignoreElements==0) { 80 buffer.append(chars, start, length); 81 } 82 } 83 84 88 89 public void writeStartTag(int nameCode) throws TransformerException { 90 reportRecoverableError(); 91 ignoreElements++; 92 } 93 94 private void reportRecoverableError() throws TransformerException { 95 if (errorListener!=null) { 96 errorListener.warning( 97 new TransformerException ( 98 "Non-text output nodes are ignored when writing an attribute, comment, or PI")); 99 } 100 } 101 102 109 110 public int checkAttributePrefix(int nameCode) throws TransformerException { 111 return nameCode; 112 } 113 114 124 125 public void writeNamespaceDeclaration(int nscode) 126 throws TransformerException { 127 } 129 130 134 135 public void copyNamespaceNode(int nscode) throws TransformerException { 136 } 138 139 143 144 public boolean thereIsAnOpenStartTag() { 145 return false; 146 } 147 148 158 159 public void writeAttribute(int nameCode, String value, boolean noEscape) throws TransformerException { 160 reportRecoverableError(); 161 } 162 163 164 168 169 public void writeEndTag(int nameCode) throws TransformerException { 170 ignoreElements--; 171 } 172 173 177 178 public void writeComment(String comment) throws TransformerException { 179 reportRecoverableError(); 180 } 181 182 186 187 public void writePI(String target, String data) throws TransformerException { 188 reportRecoverableError(); 189 } 190 191 194 195 public void close() throws TransformerException { 196 } 198 199 } 200 201 | Popular Tags |