1 23 24 package de.laures.cewolf.taglib.tags; 25 26 import java.io.IOException ; 27 28 import javax.servlet.jsp.JspException ; 29 30 import de.laures.cewolf.CewolfException; 31 import de.laures.cewolf.ChartHolder; 32 import de.laures.cewolf.ChartImage; 33 import de.laures.cewolf.Configuration; 34 import de.laures.cewolf.Storage; 35 import de.laures.cewolf.WebConstants; 36 import de.laures.cewolf.taglib.ChartImageDefinition; 37 import de.laures.cewolf.taglib.TaglibConstants; 38 import de.laures.cewolf.taglib.html.HTMLImgTag; 39 import de.laures.cewolf.taglib.util.PageUtils; 40 41 46 public class LegendTag extends HTMLImgTag implements CewolfRootTag, TaglibConstants, WebConstants { 47 48 private static final String DEFAULT_MIME_TYPE = MIME_PNG; 49 private static final int DEFAULT_TIMEOUT = 300; 50 private int timeout = DEFAULT_TIMEOUT; 51 private transient String sessionKey; 52 private transient String renderer; 53 private String mimeType = DEFAULT_MIME_TYPE; 54 55 public int doStartTag() throws JspException { 56 ChartHolder cd = PageUtils.getChartHolder(getChartId(), pageContext); 57 ChartImage cid = new ChartImageDefinition(cd, width, height, ChartImage.IMG_TYPE_LEGEND, mimeType,timeout); 58 Storage storage = Configuration.getInstance(pageContext.getServletContext()).getStorage(); 59 try { 60 this.sessionKey = storage.storeChartImage(cid, pageContext); 61 } catch(CewolfException cwex){ 62 log.error(cwex); 63 throw new JspException (cwex.getMessage()); 64 } 65 return SKIP_BODY; 66 } 67 68 public int doEndTag() throws JspException { 69 super.doStartTag(); 70 final StringBuffer buffer = new StringBuffer (" SRC=\""); 71 buffer.append(getImgURL()); 72 buffer.append("\""); 73 try { 74 pageContext.getOut().write(buffer.toString()); 75 } catch (IOException ioex) { 76 reset(); 77 log.error(ioex); 78 throw new JspException (ioex.getMessage()); 79 } 80 return super.doEndTag(); 81 } 82 83 87 protected String getImgURL() { 88 return ChartImgTag.buildImgURL(renderer, pageContext, sessionKey, width, height, mimeType, forceSessionId,removeAfterRender); 89 } 90 91 protected void reset() { 92 int lHeight = this.height; 97 int lWidth = this.width; 98 int lTimeout = this.timeout; 99 super.reset(); 100 this.height = lHeight; 101 this.width = lWidth; 102 this.timeout = lTimeout; 103 } 104 105 public String getChartId() { 106 return getId(); 107 } 108 109 public void setRenderer(String rend) { 110 this.renderer = rend; 111 } 112 113 117 public void setMime(String mimeType) { 118 this.mimeType = mimeType; 119 } 120 121 124 public int getTimeout() 125 { 126 return timeout; 127 } 128 131 public void setTimeout( int timeout ) 132 { 133 this.timeout = timeout; 134 } 135 } 136 | Popular Tags |