1 5 package org.exoplatform.commons.xhtml; 6 7 import java.io.IOException ; 8 import java.io.Writer ; 9 import org.exoplatform.Constants; 10 14 abstract public class BaseXHTMLBuilder { 15 protected Writer w_ ; 16 17 public BaseXHTMLBuilder(Writer w) { 18 w_ = w ; 19 } 20 21 final public BaseXHTMLBuilder text(String s) throws IOException { 22 if(s != null) w_.write(s) ; 23 return this ; 24 } 25 26 final public BaseXHTMLBuilder write(String s) throws IOException { 27 w_.write(s) ; 28 return this ; 29 } 30 final public BaseXHTMLBuilder startHTML() throws IOException { 32 w_.write("<html>") ; 33 return this ; 34 } 35 36 final public BaseXHTMLBuilder closeHTML() throws IOException { 37 w_.write("</html>") ; 38 return this ; 39 } 40 final public BaseXHTMLBuilder startBODY() throws IOException { 42 w_.write("<body>") ; 43 return this ; 44 } 45 46 final public BaseXHTMLBuilder closeBODY() throws IOException { 47 w_.write("</body>") ; 48 return this ; 49 } 50 final public BaseXHTMLBuilder startTABLE() throws IOException { 52 w_.write("<table>") ; 53 return this ; 54 } 55 56 final public BaseXHTMLBuilder startTABLE(String attributes) throws IOException { 57 w_.write("<table "); w_.write(attributes); w_.write("'>") ; 58 return this ; 59 } 60 61 final public BaseXHTMLBuilder startTABLE(Attributes attrs) throws IOException { 62 w_.write("<table"); w_.write(attrs.toString()); w_.write('>'); 63 return this ; 64 } 65 66 final public BaseXHTMLBuilder closeTABLE() throws IOException { 67 w_.write("</table>") ; 68 return this ; 69 } 70 final public BaseXHTMLBuilder startTR() throws IOException { 72 w_.write("<tr>") ; 73 return this ; 74 } 75 76 final public BaseXHTMLBuilder startTR(String attributes) throws IOException { 77 w_.write("<tr "); w_.write(attributes); w_.write("'>") ; 78 return this ; 79 } 80 81 final public BaseXHTMLBuilder startTR(Attributes attrs) throws IOException { 82 w_.write("<tr");w_.write(attrs.toString()); w_.write('>'); 83 return this ; 84 } 85 86 final public BaseXHTMLBuilder closeTR() throws IOException { 87 w_.write("</tr>") ; 88 return this ; 89 } 90 final public BaseXHTMLBuilder startTD() throws IOException { 92 w_.write("<td>") ; 93 return this ; 94 } 95 96 final public BaseXHTMLBuilder startTD(String attributes) throws IOException { 97 w_.write("<td "); w_.write(attributes); w_.write("'>") ; 98 return this ; 99 } 100 101 final public BaseXHTMLBuilder startTD(Attributes attrs) throws IOException { 102 w_.write("<td");w_.write(attrs.toString()); w_.write('>'); 103 return this ; 104 } 105 106 final public BaseXHTMLBuilder closeTD() throws IOException { 107 w_.write("</td>") ; 108 return this ; 109 } 110 111 final public BaseXHTMLBuilder TD(String text) throws IOException { 112 w_.write("<td>") ; w_.write(text) ; w_.write("</td>") ; 113 return this ; 114 } 115 116 final public BaseXHTMLBuilder TD(Attributes attrs, String text) throws IOException { 117 w_.write("<td");w_.write(attrs.toString()); w_.write('>'); 118 w_.write(text) ; 119 w_.write("</td>") ; 120 return this ; 121 } 122 final public BaseXHTMLBuilder startTH() throws IOException { 124 w_.write("<th>") ; 125 return this ; 126 } 127 128 final public BaseXHTMLBuilder startTH(String attributes) throws IOException { 129 w_.write("<th "); w_.write(attributes); w_.write("'>") ; 130 return this ; 131 } 132 133 final public BaseXHTMLBuilder startTH(Attributes attrs) throws IOException { 134 w_.write("<th");w_.write(attrs.toString()); w_.write('>'); 135 return this ; 136 } 137 138 final public BaseXHTMLBuilder closeTH() throws IOException { 139 w_.write("</th>") ; 140 return this ; 141 } 142 143 final public BaseXHTMLBuilder TH(String text) throws IOException { 144 w_.write("<th>") ; w_.write(text) ; w_.write("</th>") ; 145 return this ; 146 } 147 148 final public BaseXHTMLBuilder TH(Attributes attrs, String text) throws IOException { 149 w_.write("<th");w_.write(attrs.toString()); w_.write('>'); 150 w_.write(text) ; w_.write("</th>") ; 151 return this ; 152 } 153 final public BaseXHTMLBuilder startDIV() throws IOException { 155 w_.write("<div>") ; 156 return this ; 157 } 158 159 final public BaseXHTMLBuilder startDIV(String attributes) throws IOException { 160 w_.write("<div "); w_.write(attributes); w_.write("'>") ; 161 return this ; 162 } 163 164 final public BaseXHTMLBuilder startDIV(Attributes attrs) throws IOException { 165 w_.write("<div"); w_.write(attrs.toString()); w_.write('>'); 166 return this ; 167 } 168 169 final public BaseXHTMLBuilder closeDIV() throws IOException { 170 w_.write("</div>") ; 171 return this ; 172 } 173 174 final public BaseXHTMLBuilder DIV(String text) throws IOException { 175 w_.write("<div>") ; w_.write(text) ; w_.write("</div>") ; 176 return this ; 177 } 178 final public BaseXHTMLBuilder p(String s) throws IOException { 180 w_.write("<p>") ; w_.write(s) ; w_.write("</p>") ; 181 return this ; 182 } 183 final public BaseXHTMLBuilder a(String href, String s) throws IOException { 185 w_.write("<a HREF='"); w_.write(href); w_.write("'>") ; 186 w_.write(s) ; w_.write("</a>") ; 187 return this ; 188 } 189 public BaseXHTMLBuilder link(String params, String label) throws IOException { 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 label) throws IOException { 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 label) throws IOException { 208 return link(params.parameter_, label) ; 209 } 210 final public BaseXHTMLBuilder startFORM() throws IOException { 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 { 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 attrs) throws IOException { 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 { 232 w_.write("</form") ; 233 return this ; 234 } 235 final public BaseXHTMLBuilder INPUT(String attrs) throws IOException { 237 w_.write("<input ") ; w_.write(attrs); w_.write("/>"); 238 return this ; 239 } 240 241 final public BaseXHTMLBuilder INPUT(Attributes attrs) throws IOException { 242 w_.write("<input") ; w_.write(attrs.toString()); w_.write("/>"); 243 return this ; 244 } 245 final public BaseXHTMLBuilder TEXTAREA(String attrs, String text) throws IOException { 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 getBaseURL() ; 254 } | Popular Tags |