01: /* ================================================================
02: * Cewolf : Chart enabling Web Objects Framework
03: * ================================================================
04: *
05: * Project Info: http://cewolf.sourceforge.net
06: * Project Lead: Guido Laures (guido@laures.de);
07: *
08: * (C) Copyright 2002, by Guido Laures
09: *
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.
13: *
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.
17: *
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.
21: */
22:
23: package de.laures.cewolf.taglib.util;
24:
25: import javax.servlet.jsp.PageContext;
26: import javax.servlet.jsp.tagext.Tag;
27:
28: import org.jfree.data.general.Dataset;
29:
30: import de.laures.cewolf.ChartHolder;
31: import de.laures.cewolf.DatasetProduceException;
32: import de.laures.cewolf.taglib.tags.CewolfRootTag;
33:
34: /**
35: * Helper class to easily retrieve some objects of page context.
36: * @author glaures
37: */
38: public class PageUtils {
39:
40: private final static String TOOLTIPS_ENABLED_ATTR = PageUtils.class
41: .getName()
42: + ".ttenabled";
43:
44: /** Creates a new instance of ChartDefinitionFactory */
45: private PageUtils() {
46: }
47:
48: public static ChartHolder getChartHolder(String chartId,
49: PageContext ctx) {
50: return (ChartHolder) ctx.getAttribute(chartId,
51: PageContext.PAGE_SCOPE);
52: }
53:
54: public static final ChartHolder getChartHolder(Tag tag,
55: PageContext ctx) {
56: CewolfRootTag root = findRoot(tag, ctx);
57: if (root instanceof ChartHolder) {
58: return (ChartHolder) root;
59: } else {
60: return getChartHolder(root.getChartId(), ctx);
61: }
62: }
63:
64: public static final Dataset getDataset(String chartId,
65: PageContext ctx) throws DatasetProduceException {
66: return (Dataset) getChartHolder(chartId, ctx).getDataset();
67: }
68:
69: public static final CewolfRootTag findRoot(Tag t, PageContext ctx) {
70: Tag res = t;
71: while (!(res instanceof CewolfRootTag)) {
72: res = res.getParent();
73: }
74: return (CewolfRootTag) res;
75: }
76:
77: public static final void setToolTipsEnabled(PageContext ctx) {
78: if (!isToolTipsEnabled(ctx)) {
79: ctx.setAttribute(TOOLTIPS_ENABLED_ATTR, "true",
80: PageContext.PAGE_SCOPE);
81: }
82: }
83:
84: public static final boolean isToolTipsEnabled(PageContext ctx) {
85: return ctx.getAttribute(TOOLTIPS_ENABLED_ATTR,
86: PageContext.PAGE_SCOPE) != null;
87: }
88:
89: }
|