franta-hg@1: /* ================================================================ franta-hg@1: * Cewolf : Chart enabling Web Objects Framework franta-hg@1: * ================================================================ franta-hg@1: * franta-hg@1: * Project Info: http://cewolf.sourceforge.net franta-hg@1: * Project Lead: Guido Laures (guido@laures.de); franta-hg@1: * franta-hg@1: * (C) Copyright 2002, by Guido Laures franta-hg@1: * franta-hg@1: * This library is free software; you can redistribute it and/or modify it under the terms franta-hg@1: * of the GNU Lesser General Public License as published by the Free Software Foundation; franta-hg@1: * either version 2.1 of franta-hg@1: * the License, or (at your option) any later version. franta-hg@1: * franta-hg@1: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; franta-hg@1: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. franta-hg@1: * See the GNU Lesser General Public License for more details. franta-hg@1: * franta-hg@1: * You should have received a copy of the GNU Lesser General Public License along with this franta-hg@1: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, franta-hg@1: * Boston, MA 02111-1307, USA. franta-hg@1: */ franta-hg@1: franta-hg@1: package de.laures.cewolf.taglib.tags; franta-hg@1: franta-hg@1: import java.io.IOException; franta-hg@1: franta-hg@1: import javax.servlet.jsp.JspException; franta-hg@1: franta-hg@1: import de.laures.cewolf.CewolfException; franta-hg@1: import de.laures.cewolf.ChartHolder; franta-hg@1: import de.laures.cewolf.ChartImage; franta-hg@1: import de.laures.cewolf.Configuration; franta-hg@1: import de.laures.cewolf.Storage; franta-hg@1: import de.laures.cewolf.WebConstants; franta-hg@1: import de.laures.cewolf.taglib.ChartImageDefinition; franta-hg@1: import de.laures.cewolf.taglib.TaglibConstants; franta-hg@1: import de.laures.cewolf.taglib.html.HTMLImgTag; franta-hg@1: import de.laures.cewolf.taglib.util.PageUtils; franta-hg@1: franta-hg@1: /** franta-hg@1: * Tag <legend> which can be used to render a chart's legend franta-hg@1: * separately somewhere in the page. franta-hg@1: * @author Guido Laures franta-hg@1: */ franta-hg@1: public class LegendTag extends HTMLImgTag implements CewolfRootTag, TaglibConstants, WebConstants { franta-hg@1: franta-hg@1: private static final String DEFAULT_MIME_TYPE = MIME_PNG; franta-hg@1: private static final int DEFAULT_TIMEOUT = 300; franta-hg@1: private int timeout = DEFAULT_TIMEOUT; franta-hg@1: private transient String sessionKey; franta-hg@1: private transient String renderer; franta-hg@1: private String mimeType = DEFAULT_MIME_TYPE; franta-hg@1: franta-hg@1: public int doStartTag() throws JspException { franta-hg@1: ChartHolder cd = PageUtils.getChartHolder(getChartId(), pageContext); franta-hg@1: ChartImage cid = new ChartImageDefinition(cd, width, height, ChartImage.IMG_TYPE_LEGEND, mimeType,timeout); franta-hg@1: Storage storage = Configuration.getInstance(pageContext.getServletContext()).getStorage(); franta-hg@1: try { franta-hg@1: this.sessionKey = storage.storeChartImage(cid, pageContext); franta-hg@1: } catch(CewolfException cwex){ franta-hg@1: log.error(cwex); franta-hg@1: throw new JspException(cwex.getMessage()); franta-hg@1: } franta-hg@1: return SKIP_BODY; franta-hg@1: } franta-hg@1: franta-hg@1: public int doEndTag() throws JspException { franta-hg@1: super.doStartTag(); franta-hg@1: final StringBuffer buffer = new StringBuffer(" src=\""); franta-hg@1: buffer.append(getImgURL()); franta-hg@1: buffer.append("\""); franta-hg@1: try { franta-hg@1: pageContext.getOut().write(buffer.toString()); franta-hg@1: } catch (IOException ioex) { franta-hg@1: reset(); franta-hg@1: log.error(ioex); franta-hg@1: throw new JspException(ioex.getMessage()); franta-hg@1: } franta-hg@1: return super.doEndTag(); franta-hg@1: } franta-hg@1: franta-hg@1: /** franta-hg@1: * To enable further server side scriptings on JSP output the session ID is always franta-hg@1: * encoded into the image URL even if cookies are enabled on the client side. franta-hg@1: */ franta-hg@1: protected String getImgURL() { franta-hg@1: return ChartImgTag.buildImgURL(renderer, pageContext, sessionKey, width, height, mimeType, forceSessionId,removeAfterRender); franta-hg@1: } franta-hg@1: franta-hg@1: protected void reset() { franta-hg@1: // as of a weird JSP compiler in resin franta-hg@1: // a reused tag's attribute is only set if franta-hg@1: // it changes. So width an height may not franta-hg@1: // be unset to ensure correct values. franta-hg@1: int lHeight = this.height; franta-hg@1: int lWidth = this.width; franta-hg@1: int lTimeout = this.timeout; franta-hg@1: super.reset(); franta-hg@1: this.height = lHeight; franta-hg@1: this.width = lWidth; franta-hg@1: this.timeout = lTimeout; franta-hg@1: } franta-hg@1: franta-hg@1: public String getChartId() { franta-hg@1: return getId(); franta-hg@1: } franta-hg@1: franta-hg@1: public void setRenderer(String rend) { franta-hg@1: this.renderer = rend; franta-hg@1: } franta-hg@1: franta-hg@1: /** franta-hg@1: * Sets the mimeType. franta-hg@1: * @param mimeType The mimeType to set franta-hg@1: */ franta-hg@1: public void setMime(String mimeType) { franta-hg@1: this.mimeType = mimeType; franta-hg@1: } franta-hg@1: franta-hg@1: /** franta-hg@1: * @return Returns the timeout. franta-hg@1: */ franta-hg@1: public int getTimeout() franta-hg@1: { franta-hg@1: return timeout; franta-hg@1: } franta-hg@1: /** franta-hg@1: * @param timeout The timeout to set. franta-hg@1: */ franta-hg@1: public void setTimeout( int timeout ) franta-hg@1: { franta-hg@1: this.timeout = timeout; franta-hg@1: } franta-hg@1: }