1 37 38 package net.sourceforge.cruisecontrol.taglib; 39 40 import javax.servlet.jsp.JspException ; 41 import javax.servlet.jsp.JspTagException ; 42 import javax.servlet.jsp.tagext.Tag ; 43 44 48 public class TabTag extends CruiseControlTagSupport { 49 private String name; 50 private String url; 51 private String label; 52 private Tab tab; 53 54 public int doStartTag() throws JspException { 55 Tag parentTag = getParent(); 56 if (!(parentTag instanceof TabSheetTag)) { 57 throw new JspTagException ("TabTag needs to be directly enclosed in a TabSheetTag"); 58 } 59 TabSheetTag tabSheet = (TabSheetTag) parentTag; 60 final boolean selected = isSelected(tabSheet); 61 tab = new Tab(name, url, label, selected); 62 tabSheet.addTab(tab); 63 return selected ? Tag.EVAL_BODY_INCLUDE : Tag.SKIP_BODY; 64 } 65 66 public int doEndTag() throws JspException { 67 tab.setUrl(url); 68 return EVAL_PAGE; 69 } 70 71 public void setName(String name) { 72 this.name = name; 73 } 74 75 public void setUrl(String url) { 76 this.url = url; 77 } 78 79 public void setLabel(String label) { 80 this.label = label; 81 } 82 83 private boolean isSelected(TabSheetTag tabSheet) { 84 final String expectedTab = getPageContext().getRequest().getParameter("tab"); 85 if (expectedTab == null && !tabSheet.hasTabs()) { 86 return true; 87 } 88 return name.equals(expectedTab); 89 } 90 } 91 | Popular Tags |