KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > faces > context > HtmlResponseWriter


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.faces.context;
6
7 import java.io.IOException JavaDoc;
8 import java.io.Writer JavaDoc ;
9 import javax.faces.context.ResponseWriter;
10 import javax.faces.component.UIComponent ;
11
12 /**
13  * @email: tuan08@users.sourceforge.net
14  * @version: $Id: HtmlResponseWriter.java,v 1.1 2004/04/29 14:39:24 tuan08 Exp $
15  */

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