1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/java/cewolf-1.0/src/main/java/de/laures/cewolf/taglib/tags/LegendTag.java Sat Feb 28 21:31:02 2009 +0100
1.3 @@ -0,0 +1,135 @@
1.4 +/* ================================================================
1.5 + * Cewolf : Chart enabling Web Objects Framework
1.6 + * ================================================================
1.7 + *
1.8 + * Project Info: http://cewolf.sourceforge.net
1.9 + * Project Lead: Guido Laures (guido@laures.de);
1.10 + *
1.11 + * (C) Copyright 2002, by Guido Laures
1.12 + *
1.13 + * This library is free software; you can redistribute it and/or modify it under the terms
1.14 + * of the GNU Lesser General Public License as published by the Free Software Foundation;
1.15 + * either version 2.1 of
1.16 + * the License, or (at your option) any later version.
1.17 + *
1.18 + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
1.19 + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1.20 + * See the GNU Lesser General Public License for more details.
1.21 + *
1.22 + * You should have received a copy of the GNU Lesser General Public License along with this
1.23 + * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
1.24 + * Boston, MA 02111-1307, USA.
1.25 + */
1.26 +
1.27 +package de.laures.cewolf.taglib.tags;
1.28 +
1.29 +import java.io.IOException;
1.30 +
1.31 +import javax.servlet.jsp.JspException;
1.32 +
1.33 +import de.laures.cewolf.CewolfException;
1.34 +import de.laures.cewolf.ChartHolder;
1.35 +import de.laures.cewolf.ChartImage;
1.36 +import de.laures.cewolf.Configuration;
1.37 +import de.laures.cewolf.Storage;
1.38 +import de.laures.cewolf.WebConstants;
1.39 +import de.laures.cewolf.taglib.ChartImageDefinition;
1.40 +import de.laures.cewolf.taglib.TaglibConstants;
1.41 +import de.laures.cewolf.taglib.html.HTMLImgTag;
1.42 +import de.laures.cewolf.taglib.util.PageUtils;
1.43 +
1.44 +/**
1.45 + * Tag <legend> which can be used to render a chart's legend
1.46 + * separately somewhere in the page.
1.47 + * @author Guido Laures
1.48 + */
1.49 +public class LegendTag extends HTMLImgTag implements CewolfRootTag, TaglibConstants, WebConstants {
1.50 +
1.51 + private static final String DEFAULT_MIME_TYPE = MIME_PNG;
1.52 + private static final int DEFAULT_TIMEOUT = 300;
1.53 + private int timeout = DEFAULT_TIMEOUT;
1.54 + private transient String sessionKey;
1.55 + private transient String renderer;
1.56 + private String mimeType = DEFAULT_MIME_TYPE;
1.57 +
1.58 + public int doStartTag() throws JspException {
1.59 + ChartHolder cd = PageUtils.getChartHolder(getChartId(), pageContext);
1.60 + ChartImage cid = new ChartImageDefinition(cd, width, height, ChartImage.IMG_TYPE_LEGEND, mimeType,timeout);
1.61 + Storage storage = Configuration.getInstance(pageContext.getServletContext()).getStorage();
1.62 + try {
1.63 + this.sessionKey = storage.storeChartImage(cid, pageContext);
1.64 + } catch(CewolfException cwex){
1.65 + log.error(cwex);
1.66 + throw new JspException(cwex.getMessage());
1.67 + }
1.68 + return SKIP_BODY;
1.69 + }
1.70 +
1.71 + public int doEndTag() throws JspException {
1.72 + super.doStartTag();
1.73 + final StringBuffer buffer = new StringBuffer(" src=\"");
1.74 + buffer.append(getImgURL());
1.75 + buffer.append("\"");
1.76 + try {
1.77 + pageContext.getOut().write(buffer.toString());
1.78 + } catch (IOException ioex) {
1.79 + reset();
1.80 + log.error(ioex);
1.81 + throw new JspException(ioex.getMessage());
1.82 + }
1.83 + return super.doEndTag();
1.84 + }
1.85 +
1.86 + /**
1.87 + * To enable further server side scriptings on JSP output the session ID is always
1.88 + * encoded into the image URL even if cookies are enabled on the client side.
1.89 + */
1.90 + protected String getImgURL() {
1.91 + return ChartImgTag.buildImgURL(renderer, pageContext, sessionKey, width, height, mimeType, forceSessionId,removeAfterRender);
1.92 + }
1.93 +
1.94 + protected void reset() {
1.95 + // as of a weird JSP compiler in resin
1.96 + // a reused tag's attribute is only set if
1.97 + // it changes. So width an height may not
1.98 + // be unset to ensure correct values.
1.99 + int lHeight = this.height;
1.100 + int lWidth = this.width;
1.101 + int lTimeout = this.timeout;
1.102 + super.reset();
1.103 + this.height = lHeight;
1.104 + this.width = lWidth;
1.105 + this.timeout = lTimeout;
1.106 + }
1.107 +
1.108 + public String getChartId() {
1.109 + return getId();
1.110 + }
1.111 +
1.112 + public void setRenderer(String rend) {
1.113 + this.renderer = rend;
1.114 + }
1.115 +
1.116 + /**
1.117 + * Sets the mimeType.
1.118 + * @param mimeType The mimeType to set
1.119 + */
1.120 + public void setMime(String mimeType) {
1.121 + this.mimeType = mimeType;
1.122 + }
1.123 +
1.124 + /**
1.125 + * @return Returns the timeout.
1.126 + */
1.127 + public int getTimeout()
1.128 + {
1.129 + return timeout;
1.130 + }
1.131 + /**
1.132 + * @param timeout The timeout to set.
1.133 + */
1.134 + public void setTimeout( int timeout )
1.135 + {
1.136 + this.timeout = timeout;
1.137 + }
1.138 +}