1 28 29 package com.caucho.jsf.html; 30 31 import java.io.*; 32 33 import javax.faces.component.*; 34 import javax.faces.context.*; 35 import javax.faces.render.*; 36 37 public class HtmlResponseWriter extends ResponseWriter 38 { 39 private String _contentType; 40 private String _encoding; 41 42 private Writer _out; 43 private boolean _inElement; 44 45 HtmlResponseWriter(Writer out, String contentType, String encoding) 46 { 47 _out = out; 48 _contentType = contentType; 49 _encoding = encoding; 50 } 51 52 public void write(char []buffer, int offset, int length) 53 throws IOException 54 { 55 if (_inElement) 56 closeElement(); 57 58 _out.write(buffer, offset, length); 59 } 60 61 public void write(char ch) 62 throws IOException 63 { 64 if (_inElement) 65 closeElement(); 66 67 _out.write(ch); 68 } 69 70 public void write(String v) 71 throws IOException 72 { 73 if (_inElement) 74 closeElement(); 75 76 _out.write(v); 77 } 78 79 public String getContentType() 80 { 81 return _contentType; 82 } 83 84 public String getCharacterEncoding() 85 { 86 return _encoding; 87 } 88 89 public void flush() 90 throws IOException 91 { 92 _out.flush(); 93 } 94 95 public void startDocument() 96 throws IOException 97 { 98 } 99 100 public void endDocument() 101 throws IOException 102 { 103 } 104 105 public void startElement(String name, UIComponent component) 106 throws IOException 107 { 108 if (_inElement) 109 closeElement(); 110 111 _out.write("<"); 112 _out.write(name); 113 _inElement = true; 114 } 115 116 public void endElement(String name) 117 throws IOException 118 { 119 if (_inElement) 120 closeElement(); 121 122 _out.write("</"); 123 _out.write(name); 124 _out.write(">"); 125 } 126 127 public void writeAttribute(String name, 128 Object value, 129 String property) 130 throws IOException 131 { 132 _out.write(' '); 133 _out.write(name); 134 _out.write("=\""); 135 _out.write(String.valueOf(value)); 136 _out.write("\""); 137 } 138 139 public void writeURIAttribute(String name, 140 Object value, 141 String property) 142 throws IOException 143 { 144 writeAttribute(name, value, property); 145 } 146 147 public void writeComment(Object comment) 148 throws IOException 149 { 150 if (_inElement) 151 closeElement(); 152 153 _out.write("<!--"); 154 _out.write(String.valueOf(comment)); 155 _out.write("-->"); 156 } 157 158 public void writeText(Object text, 159 String property) 160 throws IOException 161 { 162 if (_inElement) 163 closeElement(); 164 165 _out.write(String.valueOf(text)); 166 } 167 168 public void writeText(char []text, int offset, int length) 169 throws IOException 170 { 171 if (_inElement) 172 closeElement(); 173 174 _out.write(text, offset, length); 175 } 176 177 public ResponseWriter cloneWithWriter(Writer out) 178 { 179 return new HtmlResponseWriter(out, _contentType, _encoding); 180 } 181 182 private void closeElement() 183 throws IOException 184 { 185 _out.write(">"); 186 _inElement = false; 187 } 188 189 public void close() 190 throws IOException 191 { 192 } 193 194 public String toString() 195 { 196 return "HtmlResponseWriter[]"; 197 } 198 } 199 | Popular Tags |