1 37 38 package net.sourceforge.cruisecontrol.taglib; 39 40 import java.io.IOException ; 41 import java.util.ArrayList ; 42 import java.util.Iterator ; 43 import java.util.List ; 44 import javax.servlet.jsp.JspTagException ; 45 import javax.servlet.jsp.JspWriter ; 46 import javax.servlet.jsp.tagext.BodyTag ; 47 import javax.servlet.jsp.tagext.Tag ; 48 49 import net.sourceforge.cruisecontrol.util.CCTagException; 50 51 57 public class TabSheetTag extends CruiseControlBodyTagSupport { 58 private List tabs = new ArrayList (); 59 private Tab selectedTab; 60 private static final Tab NONE_SELECTED = null; 61 private static final String EOL = "\r\n"; 62 private static final String START_SHEET = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">" 63 + "<tbody>" 64 + EOL 65 + " <tr>" 66 + EOL 67 + " <td bgcolor=\"#FFFFFF\"><img border=\"0\" SRC=\"images/bluestripestop.gif\"></td>" 68 + EOL 69 + " </tr>" 70 + EOL; 71 private static final String END_SHEET = " <tr>" 72 + EOL 73 + " <td bgcolor=\"#FFFFFF\"><img border=\"0\" SRC=\"images/bluestripesbottom.gif\"></td>" 74 + EOL 75 + " </tr>" 76 + EOL 77 + "</tbody></table>" 78 + EOL; 79 80 84 public int doStartTag() { 85 clearTabs(); 86 return BodyTag.EVAL_BODY_TAG; 87 } 88 89 93 public void addTab(Tab tab) { 94 if (tab.isSelected()) { 95 selectedTab = tab; 96 } 97 tabs.add(tab); 98 } 99 100 101 public void release() { 102 super.release(); 103 clearTabs(); 104 } 105 106 111 public int doEndTag() throws JspTagException { 112 try { 113 final JspWriter out = getPageContext().getOut(); 114 startTable(out); 115 printTabHeaders(out); 116 printBody(out); 117 endTable(out); 118 return Tag.EVAL_PAGE; 119 } catch (IOException e) { 120 err(e); 121 throw new CCTagException("IO Error: " + e.getMessage(), e); 122 } 123 } 124 125 private void endTable(final JspWriter out) throws IOException { 126 out.write(END_SHEET); 127 } 128 129 private void startTable(final JspWriter out) throws IOException { 130 out.write(START_SHEET); 131 } 132 133 private void clearTabs() { 134 selectedTab = NONE_SELECTED; 135 tabs.clear(); 136 } 137 138 142 private void printTabHeaders(JspWriter out) throws IOException { 143 out.write("<tr>"); 144 out.write("<td bgcolor=\"#FFFFFF\">"); 145 out.write("<div align=\"left\">"); 146 out.write("<table class=\"tab-table\" align=\"center\" valign=\"middle\" cellspacing=\"0\""); 147 out.write(" cellpadding=\"0\" border=\"1\"><tbody><tr>"); 148 for (Iterator iterator = tabs.iterator(); iterator.hasNext();) { 149 Tab tab = (Tab) iterator.next(); 150 if (tab.isRow()) { 151 out.write("</tr><tr>"); 152 } else if (tab == selectedTab) { 153 out.write("<td class=\"tabs-selected\">"); 154 out.write(tab.getLabel()); 155 out.write("</td>"); 156 } else { 157 out.write("<td class=\"tabs\">"); 158 out.write("<a class=\"tabs-link\" HREF=\""); 159 out.write(tab.getUrl() != null ? tab.getUrl() : createUrl("tab", tab.getName())); 160 out.write("\">"); 161 out.write(tab.getLabel()); 162 out.write("</a>"); 163 out.write("</td>"); 164 } 165 } 166 out.write("</tr></tbody></table></div>"); 167 out.write("</td>"); 168 out.write("</tr>"); 169 } 170 171 175 private void printBody(JspWriter out) throws IOException { 176 if (selectedTab != NONE_SELECTED) { 177 getBodyContent().writeOut(out); 178 } 179 } 180 181 public boolean hasTabs() { 182 return !tabs.isEmpty(); 183 } 184 } 185 | Popular Tags |