1 /* ================================================================
2 * Cewolf : Chart enabling Web Objects Framework
3 * ================================================================
5 * Project Info: http://cewolf.sourceforge.net
6 * Project Lead: Guido Laures (guido@laures.de);
8 * (C) Copyright 2002, by Guido Laures
10 * This library is free software; you can redistribute it and/or modify it under the terms
11 * of the GNU Lesser General Public License as published by the Free Software Foundation;
12 * either version 2.1 of
13 * the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
16 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 * See the GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License along with this
20 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21 * Boston, MA 02111-1307, USA.
24 package de.laures.cewolf.taglib.tags;
26 import java.io.IOException;
28 import javax.servlet.jsp.JspException;
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;
42 * Tag <legend> which can be used to render a chart's legend
43 * separately somewhere in the page.
44 * @author Guido Laures
46 public class LegendTag extends HTMLImgTag implements CewolfRootTag, TaglibConstants, WebConstants {
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;
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();
60 this.sessionKey = storage.storeChartImage(cid, pageContext);
61 } catch(CewolfException cwex){
63 throw new JspException(cwex.getMessage());
68 public int doEndTag() throws JspException {
70 final StringBuffer buffer = new StringBuffer(" src=\"");
71 buffer.append(getImgURL());
74 pageContext.getOut().write(buffer.toString());
75 } catch (IOException ioex) {
78 throw new JspException(ioex.getMessage());
80 return super.doEndTag();
84 * To enable further server side scriptings on JSP output the session ID is always
85 * encoded into the image URL even if cookies are enabled on the client side.
87 protected String getImgURL() {
88 return ChartImgTag.buildImgURL(renderer, pageContext, sessionKey, width, height, mimeType, forceSessionId,removeAfterRender);
91 protected void reset() {
92 // as of a weird JSP compiler in resin
93 // a reused tag's attribute is only set if
94 // it changes. So width an height may not
95 // be unset to ensure correct values.
96 int lHeight = this.height;
97 int lWidth = this.width;
98 int lTimeout = this.timeout;
100 this.height = lHeight;
102 this.timeout = lTimeout;
105 public String getChartId() {
109 public void setRenderer(String rend) {
110 this.renderer = rend;
115 * @param mimeType The mimeType to set
117 public void setMime(String mimeType) {
118 this.mimeType = mimeType;
122 * @return Returns the timeout.
124 public int getTimeout()
129 * @param timeout The timeout to set.
131 public void setTimeout( int timeout )
133 this.timeout = timeout;