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 the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License along with this
19 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307, USA.
23 package de.laures.cewolf.taglib.util;
25 import javax.servlet.jsp.PageContext;
26 import javax.servlet.jsp.tagext.Tag;
28 import org.jfree.data.general.Dataset;
30 import de.laures.cewolf.ChartHolder;
31 import de.laures.cewolf.DatasetProduceException;
32 import de.laures.cewolf.taglib.tags.CewolfRootTag;
35 * Helper class to easily retrieve some objects of page context.
38 public class PageUtils {
40 private final static String TOOLTIPS_ENABLED_ATTR = PageUtils.class.getName() + ".ttenabled";
42 /** Creates a new instance of ChartDefinitionFactory */
43 private PageUtils() {}
45 public static ChartHolder getChartHolder(String chartId, PageContext ctx){
46 return (ChartHolder)ctx.getAttribute(chartId, PageContext.PAGE_SCOPE);
49 public static final ChartHolder getChartHolder(Tag tag, PageContext ctx){
50 CewolfRootTag root = findRoot(tag, ctx);
51 if(root instanceof ChartHolder){
52 return (ChartHolder)root;
54 return getChartHolder(root.getChartId(), ctx);
58 public static final Dataset getDataset(String chartId, PageContext ctx) throws DatasetProduceException {
59 return (Dataset) getChartHolder(chartId, ctx).getDataset();
62 public static final CewolfRootTag findRoot(Tag t, PageContext ctx){
64 while(!(res instanceof CewolfRootTag)){
65 res = res.getParent();
67 return (CewolfRootTag)res;
70 public static final void setToolTipsEnabled(PageContext ctx){
71 if(!isToolTipsEnabled(ctx)){
72 ctx.setAttribute(TOOLTIPS_ENABLED_ATTR, "true", PageContext.PAGE_SCOPE);
76 public static final boolean isToolTipsEnabled(PageContext ctx){
77 return ctx.getAttribute(TOOLTIPS_ENABLED_ATTR, PageContext.PAGE_SCOPE) != null;