1 16 17 18 package org.apache.webapp.admin; 19 20 21 import java.io.IOException ; 22 import java.net.URLEncoder ; 23 import java.util.ArrayList ; 24 import javax.servlet.jsp.JspException ; 25 import javax.servlet.jsp.JspWriter ; 26 import javax.servlet.jsp.PageContext ; 27 import javax.servlet.jsp.tagext.BodyTagSupport ; 28 29 30 49 50 public class TableTag extends BodyTagSupport { 51 52 53 55 56 61 64 65 67 68 71 protected ArrayList labels = new ArrayList (); 72 73 74 77 protected ArrayList datas = new ArrayList (); 78 79 80 83 protected ArrayList labelStyles = new ArrayList (); 84 85 86 89 protected ArrayList dataStyles = new ArrayList (); 90 91 94 protected ArrayList headers = new ArrayList (); 95 96 99 protected ArrayList styleIds = new ArrayList (); 100 101 102 104 105 108 protected int columns = 2; 109 110 public int getColumns() { 111 return (this.columns); 112 } 113 114 public void setColumns(int columns) { 115 this.columns = columns; 116 } 117 118 119 123 protected String tableStyle = null; 124 125 public String getTableStyle() { 126 return (this.tableStyle); 127 } 128 129 public void setTableStyle(String tableStyle) { 130 this.tableStyle = tableStyle; 131 } 132 133 136 protected String lineStyle = null; 137 138 public String getLineStyle() { 139 return (this.lineStyle); 140 } 141 142 public void setLineStyle(String lineStyle) { 143 this.lineStyle = lineStyle; 144 } 145 146 148 149 public int doStartTag() throws JspException { 150 151 this.headers.clear(); 152 this.labels.clear(); 153 this.datas.clear(); 154 this.labelStyles.clear(); 155 this.dataStyles.clear(); 156 this.styleIds.clear(); 157 158 return (EVAL_BODY_TAG); 159 160 } 161 162 163 168 public int doEndTag() throws JspException { 169 170 JspWriter out = pageContext.getOut(); 171 172 try { 173 174 out.println(); 176 out.print("<table "); 177 if (columns > 2) { 178 out.print(" columns=\""); 179 out.print(columns); 180 out.print("\""); 181 } 182 if (tableStyle != null) { 183 out.print(" class=\""); 184 out.print(tableStyle); 185 out.print("\""); 186 out.print(" border=\"1\" cellspacing=\"0\" "); 187 out.print(" cellpadding=\"0\" width=\"100%\" "); 188 } 189 out.println(">"); 190 191 192 int n = labels.size(); 194 for (int i = 0; i < n; i++) { 195 String label = (String ) labels.get(i); 196 boolean header = ((Boolean ) headers.get(i)).booleanValue(); 197 String data = (String ) datas.get(i); 198 String labelStyle = (String ) labelStyles.get(i); 199 String dataStyle = (String ) dataStyles.get(i); 200 String styleId = (String ) styleIds.get(i); 201 202 if (header) { 203 out.println("<tr class=\"header-row\" >"); 204 out.println(" <th scope=\"col\" width=\"27%\"> "); 205 206 out.print(" <div align=\"left\""); 207 if (labelStyle != null) 208 out.print( " class=\"" + labelStyle +"\""); 209 out.print(">"); 210 if (styleId != null) { 211 out.print("<label for=\"" + styleId + "\">"); 212 } 213 out.print(label); 214 if (styleId != null) { 215 out.print("</label>"); 216 } 217 out.println(" </div>"); 218 out.println(" </th>"); 219 220 out.println(" <th scope=\"col\" width=\"73%\"> "); 221 out.print(" <div align=\"left\"" ); 222 if (dataStyle != null) 223 out.print(" class=\"" + dataStyle + "\""); 224 out.print(">"); 225 out.print(data); 226 out.println(" </div>"); 227 out.print(" </th>"); 228 out.println("</tr>"); 229 } else { 230 out.println("<tr>"); 231 232 out.println(" <td scope=\"row\" width=\"27%\"> "); 233 234 out.print(" <div align=\"left\""); 235 if (labelStyle != null) 236 out.print( " class=\"" + labelStyle +"\""); 237 out.print(">"); 238 if (styleId != null) { 239 out.print("<label for=\"" + styleId + "\">"); 240 } 241 out.print(label); 242 if (styleId != null) { 243 out.print("</label>"); 244 } 245 out.println(" </div>"); 246 out.println(" </td>"); 247 248 out.println(" <td width=\"73%\"> "); 249 out.print(" <div align=\"left\"" ); 250 if (dataStyle != null) 251 out.print(" class=\"" + dataStyle + "\""); 252 out.print(">"); 253 out.print(data); 254 out.println(" </div>"); 255 out.print(" </td>"); 256 out.println("</tr>"); 257 } 258 259 268 } 269 270 out.println("</table>"); 272 out.println(); 273 274 } catch (IOException e) { 275 throw new JspException (e); 276 } 277 278 return (EVAL_PAGE); 279 280 } 281 282 283 286 public void release() { 287 288 this.headers.clear(); 289 this.labels.clear(); 290 this.datas.clear(); 291 this.labelStyles.clear(); 292 this.dataStyles.clear(); 293 this.columns = 2; 294 this.tableStyle = null; 295 this.lineStyle = null; 296 this.styleIds.clear(); 297 298 } 299 300 301 303 304 311 312 void addRow(boolean header, String label, String data, 313 String labelStyle, String dataStyle, String styleId) { 314 315 headers.add(new Boolean (header)); 316 labels.add(label); 317 datas.add(data); 318 labelStyles.add(labelStyle); 319 dataStyles.add(dataStyle); 320 styleIds.add(styleId); 321 322 } 323 324 326 327 } 328 | Popular Tags |