1 5 package org.exoplatform.faces.context; 6 7 import java.io.IOException ; 8 import java.io.Writer ; 9 import javax.faces.context.ResponseWriter; 10 import javax.faces.component.UIComponent ; 11 12 16 public final class HtmlResponseWriter extends ResponseWriter { 17 private Writer writer_ ; 18 private boolean closeStart_ ; 19 20 public HtmlResponseWriter(Writer writer) { 21 writer_ = writer ; 22 closeStart_ = false ; 23 } 24 25 final public void close() throws IOException { 26 writer_.close(); 27 } 28 29 final public void flush() throws IOException { 30 } 32 33 final public void write(char cbuf[]) throws IOException { 34 closeStartIfNecessary() ; 35 writer_.write(cbuf); 36 } 37 38 final public void write(char cbuf[], int off, int len) throws IOException { 39 closeStartIfNecessary() ; 40 writer_.write(new String (cbuf, off, len)); 41 } 42 43 final public void write(int c) throws IOException { 44 closeStartIfNecessary() ; 45 writer_.write((char)(c & 0xffff)); 46 } 47 48 final public void write(String s) throws IOException { 49 closeStartIfNecessary() ; 50 writer_.write(s); 51 } 52 53 final public void write(String s, int off, int len) throws IOException { 54 closeStartIfNecessary() ; 55 writer_.write(s.substring(off, len)); 56 } 57 58 public String getContentType() { 59 throw new UnsupportedOperationException (); 60 } 61 62 public String getCharacterEncoding() { 63 throw new UnsupportedOperationException (); 64 } 65 66 public void startDocument() throws IOException { 67 } 69 70 public void endDocument() throws IOException { 71 } 73 74 public void startElement(String name, UIComponent comp) throws IOException { 75 closeStartIfNecessary() ; 76 writer_.write("<") ; writer_.write(name) ; 77 closeStart_ = true ; 78 } 79 80 public void endElement(String name) throws IOException { 81 if (closeStart_) { 82 writer_.write("/>") ; 83 closeStart_ = false ; 84 } else { 86 writer_.write("</"); writer_.write(name) ; writer_.write('>') ; 87 } 89 } 90 91 public void writeAttribute(String name, Object value, String prop) throws IOException { 92 writer_.write(' '); writer_.write(name); writer_.write("=\""); 93 writer_.write(value.toString()); 94 writer_.write("\"") ; 95 } 96 97 public void writeURIAttribute(String name, Object value) throws IOException { 98 writer_.write(' '); writer_.write(name); writer_.write("=\""); 99 writer_.write(value.toString()); 100 writer_.write("\"") ; 101 } 102 103 public void writeComment(Object comment) throws IOException { 104 throw new UnsupportedOperationException (); 105 } 106 107 public void writeText(Object text, String prop) throws IOException { 108 closeStartIfNecessary() ; 109 writer_.write(text.toString()); 110 } 111 112 public void writeText(char text[], int off, int len) throws IOException { 113 throw new UnsupportedOperationException (); 114 } 115 116 public ResponseWriter cloneWithWriter(Writer writer) { 117 return new HtmlResponseWriter(writer) ; 118 } 119 120 public void writeURIAttribute(String name, Object value, String property) throws IOException { 121 writer_.write(' '); writer_.write(name); writer_.write("=\""); 122 writer_.write(value.toString()); 123 writer_.write("\"") ; 124 } 125 126 private void closeStartIfNecessary() throws IOException { 127 if(closeStart_) { 128 writer_.write(">"); 129 closeStart_ = false; 131 } 132 } 133 } 134 | Popular Tags |