1 19 20 package com.sslexplorer.tabs.tags; 21 22 import javax.servlet.jsp.JspException ; 23 import javax.servlet.jsp.tagext.BodyTagSupport ; 24 25 import org.apache.struts.taglib.TagUtils; 26 27 import com.sslexplorer.tabs.TabModel; 28 29 39 public class TabHeadingsTag extends BodyTagSupport { 40 41 43 protected String text; 44 45 48 public int doStartTag() throws JspException { 49 Object value = findAncestorWithClass(this, TabSetTag.class); 50 if (value == null) { 51 throw new JspException ("TabHeadingsTag must be contained in a TabSetTag"); 52 } 53 TabModel model = ((TabSetTag)value).getModel(); 54 String bundle = ((TabSetTag)value).getBundle(); 55 String locale = ((TabSetTag)value).getLocale(); 56 String selectedTab = model.getSelectedTab(); 57 String resourcePrefix = ((TabSetTag)value).getResourcePrefix(); 58 StringBuffer buf = new StringBuffer (); 59 buf.append("<div class=\"tabHeadings\">"); 60 buf.append("<ul>"); 61 for(int i = 0 ; i < model.getTabCount(); i++) { 62 String tabName = model.getTabName(i); 63 String tabTitle = model.getTabTitle(i); 64 String tabBundle = model.getTabBundle(i); 65 66 buf.append("<li id=\"tab_item_"); 68 buf.append(tabName); 69 buf.append("\" class=\""); 70 if(selectedTab == null) { 71 buf.append(i == 0 ? "selectedTab" : "hiddenTab"); 72 } 73 else { 74 buf.append(selectedTab.equals(tabName) ? "selectedTab" : "hiddenTab"); 75 } 76 buf.append("\">"); 77 78 buf.append("<a id=\"tab_link_"); 80 buf.append(tabName); 81 buf.append("\" "); 82 if(selectedTab == null) { 83 buf.append(i == 0 ? "class=\"currentTab\" " : ""); 84 } 85 else { 86 buf.append(selectedTab.equals(tabName) ? "class=\"currentTab\" " : ""); 87 } 88 int idx = 0; 89 buf.append("onclick=\"javascript: var deselect = new Array();"); 90 for(int j = 0 ; j < model.getTabCount(); j++) { 91 String tn = model.getTabName(j); 92 boolean s = tabName.equals(tn); 93 if(!s) { 94 buf.append("deselect["); 95 buf.append(idx++); 96 buf.append("]='"); 97 buf.append(tn); 98 buf.append("';"); 99 } 100 } 101 buf.append("setSelectedTab('"); 102 buf.append(tabName); 103 buf.append("',deselect);\" HREF=\"#\">"); 104 if(tabTitle == null) { 105 tabTitle = 106 TagUtils.getInstance().message( 107 pageContext, 108 tabBundle == null ? bundle : tabBundle, 109 locale, 110 resourcePrefix + "." + tabName + ".title", 111 new String [] { }); 112 } 113 buf.append(tabTitle == null? tabName : tabTitle); 114 buf.append("</a>"); 115 buf.append("</li>"); 116 } 117 buf.append("</ul>"); 118 buf.append("</div>"); 119 text = buf.toString(); 120 return (SKIP_BODY); 121 } 122 123 126 public int doEndTag() throws JspException { 127 TagUtils.getInstance().write(this.pageContext, text); 128 return EVAL_PAGE; 129 } 130 131 132 } 133 | Popular Tags |