1 37 package net.sourceforge.cruisecontrol.taglib; 38 39 import java.io.IOException ; 40 import java.util.Arrays ; 41 42 import javax.servlet.jsp.JspException ; 43 import javax.servlet.jsp.tagext.BodyContent ; 44 45 48 public class ProjectNavigationTag extends CruiseControlBodyTagSupport { 49 static final String STATUS_PAGE_TEXT = "-- STATUS PAGE --"; 50 static final String SELECTED_ATTR_VALUE = "selected=\"selected\""; 51 public static final String SELECTED_ATTR = "selected"; 52 public static final String LINK_TEXT_ATTR = "linktext"; 53 public static final String URL_ATTR = "projecturl"; 54 55 private int count; private int endPoint; private String [] projects; 59 public int doStartTag() throws JspException { 60 projects = findProjects(); 61 Arrays.sort(projects); 62 count = -1; 63 endPoint = projects.length; 64 if (count < endPoint) { 65 return EVAL_BODY_TAG; 66 } else { 67 return SKIP_BODY; 68 } 69 } 70 71 72 public void doInitBody() throws JspException { 73 setupLinkVariables(); 74 } 75 76 void setupLinkVariables() { 77 if (count == -1) { 78 getPageContext().setAttribute(LINK_TEXT_ATTR, STATUS_PAGE_TEXT); 79 getPageContext().setAttribute(URL_ATTR, getRequest().getContextPath() + "/"); 80 getPageContext().setAttribute(SELECTED_ATTR, ""); 81 } else { 82 final String projectName = projects[count]; 83 getPageContext().setAttribute(LINK_TEXT_ATTR, projectName); 84 getPageContext().setAttribute(URL_ATTR, getURL(projectName)); 85 getPageContext().setAttribute(SELECTED_ATTR, getSelected(projectName)); 86 } 87 count++; 88 } 89 90 private String getSelected(final String projectName) { 91 if (getProject().length() > 0 && getProject().substring(1).compareTo(projectName) == 0) { 92 return SELECTED_ATTR_VALUE; 93 } 94 return ""; 95 } 96 97 private String getURL(String projectName) { 98 return getServletPath() + "/" + projectName; 99 } 100 101 102 public int doAfterBody() throws JspException { 103 if (count < endPoint) { 104 setupLinkVariables(); 105 return EVAL_BODY_TAG; 106 } else { 107 try { 108 BodyContent out = getBodyContent(); 109 out.writeOut(out.getEnclosingWriter()); 110 } catch (IOException e) { 111 err(e); 112 } 113 return SKIP_BODY; 114 } 115 } 116 } 117 | Popular Tags |