1 26 27 package org.objectweb.jonas.webapp.taglib; 28 29 import java.io.IOException ; 30 import java.util.ArrayList ; 31 32 import javax.servlet.jsp.JspException ; 33 import javax.servlet.jsp.JspWriter ; 34 35 public class TabsTag extends WhereAreYouTag { 36 37 39 private static final String s_ImageSeparator = "dot.gif"; 40 41 43 private ArrayList m_LabelTabs = new ArrayList (); 44 private ArrayList m_HrefTabs = new ArrayList (); 45 private ArrayList m_SelectedTabs = new ArrayList (); 46 private String m_Body = null; 47 48 50 private int widthTab = 0; 51 private int heightTab = 0; 52 private String width = "100%"; 53 private String height = ""; 54 private int widthSeparator = 3; 55 private int heightSeparator = 1; 56 private int marginPanel = 5; 57 private String imagesDir = null; 58 59 62 public int getWidthTab() { 63 return widthTab; 64 } 65 66 public void setWidthTab(int widthTab) { 67 this.widthTab = widthTab; 68 } 69 70 73 public int getHeightTab() { 74 return heightTab; 75 } 76 77 public void setHeightTab(int heightTab) { 78 this.heightTab = heightTab; 79 } 80 81 84 public String getWidth() { 85 return width; 86 } 87 88 public void setWidth(String width) { 89 this.width = width; 90 } 91 92 95 public String getHeight() { 96 return height; 97 } 98 99 102 public void setHeight(String height) { 103 this.height = height; 104 } 105 106 109 public int getWidthSeparator() { 110 return widthSeparator; 111 } 112 113 public void setWidthSeparator(int widthSeparator) { 114 this.widthSeparator = widthSeparator; 115 } 116 117 120 public int getHeightSeparator() { 121 return heightSeparator; 122 } 123 124 public void setHeightSeparator(int heightSeparator) { 125 this.heightSeparator = heightSeparator; 126 } 127 128 131 public int getMarginPanel() { 132 return marginPanel; 133 } 134 135 public void setMarginPanel(int marginPanel) { 136 this.marginPanel = marginPanel; 137 } 138 139 142 public String getImagesDir() { 143 return imagesDir; 144 } 145 146 public void setImagesDir(String imagesDir) { 147 this.imagesDir = imagesDir; 148 } 149 150 152 public int doStartTag() 153 throws JspException { 154 155 this.m_LabelTabs.clear(); 156 this.m_HrefTabs.clear(); 157 this.m_SelectedTabs.clear(); 158 this.m_Body = null; 159 160 return (EVAL_BODY_BUFFERED); 161 } 162 163 168 public int doEndTag() 169 throws JspException { 170 JspWriter out = pageContext.getOut(); 171 try { 172 verifySelected(); 173 render(out); 174 } 175 catch (IOException e) { 176 throw new JspException (e); 177 } 178 return (EVAL_PAGE); 179 } 180 181 184 public void release() { 185 this.m_LabelTabs.clear(); 186 this.m_HrefTabs.clear(); 187 this.m_SelectedTabs.clear(); 188 this.m_Body = null; 189 this.width = null; 190 this.height = null; 191 this.imagesDir = null; 192 } 193 194 196 203 204 void addTab(String ps_Label, String ps_Href, boolean ps_Selected) { 205 m_LabelTabs.add(ps_Label); 206 m_HrefTabs.add(ps_Href); 207 m_SelectedTabs.add(new Boolean (ps_Selected)); 208 } 209 210 void setBody(String ps_Body) { 211 m_Body = ps_Body; 212 } 213 214 216 private void render(JspWriter out) 217 throws IOException , JspException { 218 out.println("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">"); 219 out.println("<tr>"); 220 out.println("<td>"); 221 renderTabs(out); 222 out.println("</td>"); 223 out.println("</tr>"); 224 out.println("<tr>"); 225 out.println("<td>"); 226 renderPanel(out); 227 out.println("</td>"); 228 out.println("</tr>"); 229 out.println("</table>"); 230 } 231 232 private void renderPanel(JspWriter out) 233 throws IOException , JspException { 234 out.print("<table border=\"0\" cellspacing=\"0\" cellpadding=\""); 236 out.print(marginPanel); 237 out.print("\""); 238 out.print(" width=\""); 239 out.print(width); 240 out.print("\""); 241 out.println(">"); 242 out.println("<tr valign=\"top\">"); 243 out.println("<td class=\"panel\">"); 244 out.print("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\""); 245 out.print(width); 246 out.print("\""); 247 out.println(">"); 248 out.println("<tr valign=\"top\">"); 249 out.print("<td height=\""); 250 out.print(height); 251 out.println("\" class=\"panel\">"); 252 if (m_Body != null) { 253 out.println(m_Body); 254 } 255 out.println("</td>"); 256 out.println("</tr>"); 257 out.println("</table>"); 258 out.println("</td>"); 259 out.println("</tr>"); 260 out.println("</table>"); 261 } 262 263 private void renderTabs(JspWriter out) 264 throws IOException , JspException { 265 int i = 0; 266 boolean bSelected = false; 267 StringBuffer sbLabel = null; 268 String sImageSep = null; 269 270 if (imagesDir != null) { 272 sImageSep = imagesDir + "/" + s_ImageSeparator; 273 } 274 else if (isUsingWhere()) { 275 sImageSep = getImagesRoot() + "/" + s_ImageSeparator; 276 } 277 else { 278 sImageSep = s_ImageSeparator; 279 } 280 try { 282 out.println("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" >"); 283 } 284 catch (IOException ex) { 285 } 286 287 int n = m_LabelTabs.size(); 289 out.println("<tr>"); 290 for (i = 0; i < n; i++) { 291 sbLabel = new StringBuffer (); 293 bSelected = ((Boolean ) m_SelectedTabs.get(i)).booleanValue(); 295 out.print("<td align=\"center\""); 297 if (widthTab > 0) { 299 out.print(" width=\""); 300 out.print(widthTab); 301 out.print("\""); 302 sbLabel.append(m_LabelTabs.get(i)); 303 } 304 else { 305 sbLabel.append(" "); 306 sbLabel.append(m_LabelTabs.get(i)); 307 sbLabel.append(" "); 308 } 309 out.print(" class=\""); 310 if (bSelected == true) { 311 out.print("tabSelect"); 312 } 313 else { 314 out.print("tab"); 315 } 316 out.print("\""); 317 if (heightTab > 0) { 319 out.print(" height=\""); 320 out.print(heightTab); 321 out.print("\""); 322 } 323 out.print(">"); 324 325 if ((bSelected == true) || (m_HrefTabs.get(i).toString().length() == 0)) { 327 out.print(sbLabel.toString()); 329 } 330 else { 331 out.print("<a HREF=\""); 333 out.print(m_HrefTabs.get(i).toString()); 334 out.print("\""); 335 out.print(" class=\""); 336 out.print("tab"); 337 out.print("\""); 338 out.print(">"); 339 out.print(sbLabel.toString()); 340 out.print("</a>"); 341 } 342 out.println("</td>"); 343 344 if (i < (n - 1)) { 345 out.print("<td"); 347 out.print(" class=\"tabSeparatorVertical\""); 348 out.print(">"); 349 out.print("<img SRC=\""); 351 out.print(sImageSep); 352 out.print("\" width=\""); 353 out.print(widthSeparator); 354 out.print("\" height=\""); 355 out.print(heightSeparator); 356 out.print("\" border=\"0\">"); 357 out.println("</td>"); 358 } 359 } 360 out.println("</tr>"); 361 362 out.println("<tr>"); 364 for (i = 0; i < n; i++) { 365 bSelected = ((Boolean ) m_SelectedTabs.get(i)).booleanValue(); 366 out.print("<td"); 368 out.print(" class=\""); 369 if (bSelected == true) { 370 out.print("tabSelect"); 371 } 372 else { 373 out.print("tabSeparatorHorizontal"); 374 } 375 out.print("\""); 376 out.print(">"); 377 out.print("<img SRC=\""); 378 out.print(sImageSep); 379 out.print("\" width=\""); 380 out.print(widthSeparator); 381 out.print("\" height=\""); 382 out.print(heightSeparator); 383 out.print("\" border=\"0\">"); 384 out.println("</td>"); 385 386 if (i < (n - 1)) { 388 out.print("<td"); 390 out.print(" class=\"tabSeparatorHorizontal\""); 391 out.print(">"); 392 out.print("<img SRC=\""); 393 out.print(sImageSep); 394 out.print("\" width=\""); 395 out.print(widthSeparator); 396 out.print("\" height=\""); 397 out.print(heightSeparator); 398 out.print("\" border=\"0\">"); 399 out.println("</td>"); 400 } 401 } 402 out.println("</tr>"); 404 out.println("</table>"); 405 } 406 407 410 private void verifySelected() { 411 boolean bFound = false; 412 for (int i = 0; i < m_SelectedTabs.size(); i++) { 413 if (bFound == true) { 414 m_SelectedTabs.set(i, new Boolean (false)); 416 } 417 else { 418 bFound = ((Boolean ) m_SelectedTabs.get(i)).booleanValue(); 420 } 421 } 422 if ((bFound == false) && (m_SelectedTabs.size() > 0)) { 423 m_SelectedTabs.set(0, new Boolean (true)); 424 } 425 } 426 } 427 | Popular Tags |