KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > commons > xhtml > BaseXHTMLBuilder


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.commons.xhtml;
6
7 import java.io.IOException JavaDoc;
8 import java.io.Writer JavaDoc;
9 import org.exoplatform.Constants;
10 /**
11  * @email: tuan08@users.sourceforge.net
12  * @version: $Id: HtmlBasicRenderer.java,v 1.22 2004/10/16 21:13:51 tuan08 Exp $
13  */

14 abstract public class BaseXHTMLBuilder {
15   protected Writer JavaDoc w_ ;
16   
17   public BaseXHTMLBuilder(Writer JavaDoc w) {
18     w_ = w ;
19   }
20   
21   final public BaseXHTMLBuilder text(String JavaDoc s) throws IOException JavaDoc {
22     if(s != null) w_.write(s) ;
23     return this ;
24   }
25   
26   final public BaseXHTMLBuilder write(String JavaDoc s) throws IOException JavaDoc {
27     w_.write(s) ;
28     return this ;
29   }
30   //============================================================================
31
final public BaseXHTMLBuilder startHTML() throws IOException JavaDoc {
32     w_.write("<html>") ;
33     return this ;
34   }
35   
36   final public BaseXHTMLBuilder closeHTML() throws IOException JavaDoc {
37     w_.write("</html>") ;
38     return this ;
39   }
40   //============================================================================
41
final public BaseXHTMLBuilder startBODY() throws IOException JavaDoc {
42     w_.write("<body>") ;
43     return this ;
44   }
45   
46   final public BaseXHTMLBuilder closeBODY() throws IOException JavaDoc {
47     w_.write("</body>") ;
48     return this ;
49   }
50   //============================================================================
51
final public BaseXHTMLBuilder startTABLE() throws IOException JavaDoc {
52     w_.write("<table>") ;
53     return this ;
54   }
55   
56   final public BaseXHTMLBuilder startTABLE(String JavaDoc attributes) throws IOException JavaDoc {
57     w_.write("<table "); w_.write(attributes); w_.write("'>") ;
58     return this ;
59   }
60   
61   final public BaseXHTMLBuilder startTABLE(Attributes attrs) throws IOException JavaDoc {
62     w_.write("<table"); w_.write(attrs.toString()); w_.write('>');
63     return this ;
64   }
65   
66   final public BaseXHTMLBuilder closeTABLE() throws IOException JavaDoc {
67     w_.write("</table>") ;
68     return this ;
69   }
70   //============================================================================
71
final public BaseXHTMLBuilder startTR() throws IOException JavaDoc {
72     w_.write("<tr>") ;
73     return this ;
74   }
75   
76   final public BaseXHTMLBuilder startTR(String JavaDoc attributes) throws IOException JavaDoc {
77     w_.write("<tr "); w_.write(attributes); w_.write("'>") ;
78     return this ;
79   }
80   
81   final public BaseXHTMLBuilder startTR(Attributes attrs) throws IOException JavaDoc {
82     w_.write("<tr");w_.write(attrs.toString()); w_.write('>');
83     return this ;
84   }
85   
86   final public BaseXHTMLBuilder closeTR() throws IOException JavaDoc {
87     w_.write("</tr>") ;
88     return this ;
89   }
90   //============================================================================
91
final public BaseXHTMLBuilder startTD() throws IOException JavaDoc {
92     w_.write("<td>") ;
93     return this ;
94   }
95   
96   final public BaseXHTMLBuilder startTD(String JavaDoc attributes) throws IOException JavaDoc {
97     w_.write("<td "); w_.write(attributes); w_.write("'>") ;
98     return this ;
99   }
100   
101   final public BaseXHTMLBuilder startTD(Attributes attrs) throws IOException JavaDoc {
102     w_.write("<td");w_.write(attrs.toString()); w_.write('>');
103     return this ;
104   }
105   
106   final public BaseXHTMLBuilder closeTD() throws IOException JavaDoc {
107     w_.write("</td>") ;
108     return this ;
109   }
110   
111   final public BaseXHTMLBuilder TD(String JavaDoc text) throws IOException JavaDoc {
112     w_.write("<td>") ; w_.write(text) ; w_.write("</td>") ;
113     return this ;
114   }
115   
116   final public BaseXHTMLBuilder TD(Attributes attrs, String JavaDoc text) throws IOException JavaDoc {
117     w_.write("<td");w_.write(attrs.toString()); w_.write('>');
118     w_.write(text) ;
119     w_.write("</td>") ;
120     return this ;
121   }
122   //============================================================================
123
final public BaseXHTMLBuilder startTH() throws IOException JavaDoc {
124     w_.write("<th>") ;
125     return this ;
126   }
127   
128   final public BaseXHTMLBuilder startTH(String JavaDoc attributes) throws IOException JavaDoc {
129       w_.write("<th "); w_.write(attributes); w_.write("'>") ;
130     return this ;
131   }
132   
133   final public BaseXHTMLBuilder startTH(Attributes attrs) throws IOException JavaDoc {
134     w_.write("<th");w_.write(attrs.toString()); w_.write('>');
135     return this ;
136   }
137   
138   final public BaseXHTMLBuilder closeTH() throws IOException JavaDoc {
139     w_.write("</th>") ;
140     return this ;
141   }
142   
143   final public BaseXHTMLBuilder TH(String JavaDoc text) throws IOException JavaDoc {
144     w_.write("<th>") ; w_.write(text) ; w_.write("</th>") ;
145     return this ;
146   }
147   
148   final public BaseXHTMLBuilder TH(Attributes attrs, String JavaDoc text) throws IOException JavaDoc {
149     w_.write("<th");w_.write(attrs.toString()); w_.write('>');
150     w_.write(text) ; w_.write("</th>") ;
151     return this ;
152   }
153   //============================================================================
154
final public BaseXHTMLBuilder startDIV() throws IOException JavaDoc {
155     w_.write("<div>") ;
156     return this ;
157   }
158   
159   final public BaseXHTMLBuilder startDIV(String JavaDoc attributes) throws IOException JavaDoc {
160     w_.write("<div "); w_.write(attributes); w_.write("'>") ;
161     return this ;
162   }
163   
164   final public BaseXHTMLBuilder startDIV(Attributes attrs) throws IOException JavaDoc {
165     w_.write("<div"); w_.write(attrs.toString()); w_.write('>');
166     return this ;
167   }
168   
169   final public BaseXHTMLBuilder closeDIV() throws IOException JavaDoc {
170     w_.write("</div>") ;
171     return this ;
172   }
173   
174   final public BaseXHTMLBuilder DIV(String JavaDoc text) throws IOException JavaDoc {
175     w_.write("<div>") ; w_.write(text) ; w_.write("</div>") ;
176     return this ;
177   }
178   //============================================================================
179
final public BaseXHTMLBuilder p(String JavaDoc s) throws IOException JavaDoc {
180     w_.write("<p>") ; w_.write(s) ; w_.write("</p>") ;
181     return this ;
182   }
183   //============================================================================
184
final public BaseXHTMLBuilder a(String JavaDoc href, String JavaDoc s) throws IOException JavaDoc {
185     w_.write("<a HREF='"); w_.write(href); w_.write("'>") ;
186     w_.write(s) ; w_.write("</a>") ;
187     return this ;
188   }
189   //============================================================================
190
public BaseXHTMLBuilder link(String JavaDoc params, String JavaDoc label) throws IOException JavaDoc {
191     w_.write("<a HREF='"); w_.write(getBaseURL());
192       w_.write(Constants.AMPERSAND); w_.write(params) ; w_.write("'>") ;
193     w_.write(label) ; w_.write("</a>") ;
194     return this ;
195   }
196   
197   public BaseXHTMLBuilder link(Parameter[] params, String JavaDoc label) throws IOException JavaDoc {
198     w_.write("<a HREF='"); w_.write(getBaseURL());
199     for(int i = 0; i < params.length; i++) {
200       w_.write(Constants.AMPERSAND); w_.write(params[i].name_);w_.write('=');w_.write(params[i].value_);
201     }
202     w_.write("'>") ;
203     w_.write(label) ; w_.write("</a>") ;
204     return this ;
205   }
206   
207   public BaseXHTMLBuilder link(Parameters params, String JavaDoc label) throws IOException JavaDoc {
208     return link(params.parameter_, label) ;
209   }
210   //============================================================================
211
final public BaseXHTMLBuilder startFORM() throws IOException JavaDoc {
212     w_.write("<form ") ; w_.write("action='") ; w_.write(getBaseURL()); w_.write("'") ;
213     w_.write('>');
214     return this ;
215   }
216   
217   final public BaseXHTMLBuilder startFORM(Attributes attrs) throws IOException JavaDoc {
218     w_.write("<form") ; w_.write("action='") ; w_.write(getBaseURL()); w_.write("'") ;
219     w_.write(attrs.toString());
220     w_.write('>');
221     return this ;
222   }
223   
224   final public BaseXHTMLBuilder startFORM(String JavaDoc attrs) throws IOException JavaDoc {
225     w_.write("<form ") ; w_.write("action='") ; w_.write(getBaseURL()); w_.write("' ") ;
226     w_.write(attrs);
227     w_.write('>');
228     return this ;
229   }
230   
231   final public BaseXHTMLBuilder closeFORM() throws IOException JavaDoc {
232     w_.write("</form") ;
233     return this ;
234   }
235   //============================================================================
236
final public BaseXHTMLBuilder INPUT(String JavaDoc attrs) throws IOException JavaDoc {
237     w_.write("<input ") ; w_.write(attrs); w_.write("/>");
238     return this ;
239   }
240   
241   final public BaseXHTMLBuilder INPUT(Attributes attrs) throws IOException JavaDoc {
242     w_.write("<input") ; w_.write(attrs.toString()); w_.write("/>");
243     return this ;
244   }
245   //============================================================================
246
final public BaseXHTMLBuilder TEXTAREA(String JavaDoc attrs, String JavaDoc text) throws IOException JavaDoc {
247     if(attrs == null) w_.write("<textarea>") ;
248     else { w_.write("<textarea ") ; w_.write(attrs); w_.write("'>") ; }
249     w_.write(text);
250     w_.write("</textarea>");
251     return this ;
252   }
253   abstract protected String JavaDoc getBaseURL() ;
254 }
Popular Tags