1 37 package net.sourceforge.cruisecontrol.taglib; 38 39 import java.io.IOException ; 40 41 import java.text.ParseException ; 42 43 import javax.servlet.jsp.JspException ; 44 import javax.servlet.jsp.JspTagException ; 45 import javax.servlet.jsp.tagext.BodyContent ; 46 47 import net.sourceforge.cruisecontrol.LogFile; 48 import net.sourceforge.cruisecontrol.util.CCTagException; 49 50 55 public class ArtifactsLinkTag extends CruiseControlBodyTagSupport { 56 57 static final String URL_ATTRIBUTE = "artifacts_url"; 58 static final String ARTIFACTS_SERVLET_CONTEXT = "artifacts"; 59 60 public void doInitBody() throws JspException { 61 String url = getArtifactURL(); 62 info("artifactURL is " + url); 63 getPageContext().setAttribute(URL_ATTRIBUTE, url); 64 } 65 66 public int doAfterBody() throws JspTagException { 67 try { 68 BodyContent out = getBodyContent(); 69 out.writeOut(out.getEnclosingWriter()); 70 } catch (IOException e) { 71 err(e); 72 throw new CCTagException("IO Error: " + e.getMessage(), e); 73 74 } 75 return SKIP_BODY; 76 } 77 78 private String getArtifactURL() throws JspException { 79 StringBuffer urlBuffer = new StringBuffer (); 80 urlBuffer.append(ARTIFACTS_SERVLET_CONTEXT); 81 String project = getProject(); 82 if (project.length() > 0) { 83 info("project is " + project); 84 urlBuffer.append(project); 85 } else { 86 info("getProject().length() is " + project.length()); 87 } 88 89 String timeString = getTimeString(); 90 urlBuffer.append("/"); 93 urlBuffer.append(timeString); 94 return urlBuffer.toString(); 95 } 96 97 String getTimeString() throws JspException { 98 String timeString = null; 99 LogFile latestFile = findLogFile(); 100 101 try { 102 timeString = latestFile.getBuildInfo().getDateStamp(); 103 } catch (ParseException pex) { 104 throw new CCTagException(pex.getMessage(), pex); 105 } 106 return timeString; 107 } 108 } 109 | Popular Tags |