1 14 package com.sun.facelets.mock; 15 16 17 import java.io.IOException ; 18 import java.io.Writer ; 19 20 import javax.faces.component.UIComponent; 21 import javax.faces.context.ResponseWriter; 22 23 24 28 public class MockResponseWriter extends ResponseWriter { 29 30 private final Writer writer; 31 private boolean startOpen; 32 33 public MockResponseWriter(Writer writer) { 34 this.writer = writer; 35 } 36 37 40 public String getContentType() { 41 return "text/html"; 42 } 43 44 47 public String getCharacterEncoding() { 48 return "UTF-8"; 49 } 50 51 54 public void flush() throws IOException { 55 57 } 58 59 62 public void startDocument() throws IOException { 63 65 } 66 67 70 public void endDocument() throws IOException { 71 73 } 74 75 private void closeStart() throws IOException { 76 if (this.startOpen) { 77 this.writer.write('>'); 78 } 79 this.startOpen = false; 80 } 81 82 85 public void startElement(String arg0, UIComponent arg1) throws IOException { 86 this.closeStart(); 87 this.writer.write('<'); 88 this.writer.write(arg0); 89 this.startOpen = true; 90 } 91 92 95 public void endElement(String arg0) throws IOException { 96 if (this.startOpen) { 97 this.writer.write("/>"); 98 this.startOpen = false; 99 } else { 100 this.writer.write("</"); 101 this.writer.write(arg0); 102 this.writer.write('>'); 103 } 104 105 } 106 107 110 public void writeAttribute(String arg0, Object arg1, String arg2) 111 throws IOException { 112 if (arg1 != null) { 113 writer.write(' '); 114 writer.write(arg0); 115 writer.write("=\""); 116 writer.write(arg1.toString()); 117 writer.write('"'); 118 } 119 } 120 121 124 public void writeURIAttribute(String arg0, Object arg1, String arg2) 125 throws IOException { 126 this.writeAttribute(arg0, arg1, arg2); 127 } 128 129 132 public void writeComment(Object arg0) throws IOException { 133 this.closeStart(); 134 this.writer.write("<!-- "); 135 this.writer.write(arg0 != null ? arg0.toString() : "null"); 136 this.writer.write(" -->"); 137 } 138 139 142 public void writeText(Object arg0, String arg1) throws IOException { 143 this.closeStart(); 144 this.writer.write(arg0 != null ? arg0.toString() : "null"); 145 } 146 147 150 public void writeText(char[] arg0, int arg1, int arg2) throws IOException { 151 this.closeStart(); 152 this.writer.write(arg0, arg1, arg2); 153 } 154 155 158 public ResponseWriter cloneWithWriter(Writer arg0) { 159 return new MockResponseWriter(arg0); 160 } 161 162 165 public void write(char[] cbuf, int off, int len) throws IOException { 166 this.writer.write(cbuf, off, len); 167 } 168 169 172 public void close() throws IOException { 173 175 } 176 177 } 178 | Popular Tags |