KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > laures > cewolf > taglib > util > PageUtils


1 /* ================================================================
2  * Cewolf : Chart enabling Web Objects Framework
3  * ================================================================
4  *
5  * Project Info: http://cewolf.sourceforge.net
6  * Project Lead: Guido Laures (guido@laures.de);
7  *
8  * (C) Copyright 2002, by Guido Laures
9  *
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 JavaDoc;
26 import javax.servlet.jsp.tagext.Tag JavaDoc;
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 JavaDoc TOOLTIPS_ENABLED_ATTR = PageUtils.class.getName() + ".ttenabled";
41     
42     /** Creates a new instance of ChartDefinitionFactory */
43     private PageUtils() {}
44     
45     public static ChartHolder getChartHolder(String JavaDoc chartId, PageContext JavaDoc ctx){
46         return (ChartHolder)ctx.getAttribute(chartId, PageContext.PAGE_SCOPE);
47     }
48     
49     public static final ChartHolder getChartHolder(Tag JavaDoc tag, PageContext JavaDoc ctx){
50         CewolfRootTag root = findRoot(tag, ctx);
51         if(root instanceof ChartHolder){
52             return (ChartHolder)root;
53         } else {
54             return getChartHolder(root.getChartId(), ctx);
55         }
56     }
57     
58     public static final Dataset getDataset(String JavaDoc chartId, PageContext JavaDoc ctx) throws DatasetProduceException {
59         return (Dataset) getChartHolder(chartId, ctx).getDataset();
60     }
61
62     public static final CewolfRootTag findRoot(Tag JavaDoc t, PageContext JavaDoc ctx){
63         Tag JavaDoc res = t;
64         while(!(res instanceof CewolfRootTag)){
65             res = res.getParent();
66         }
67         return (CewolfRootTag)res;
68     }
69     
70     public static final void setToolTipsEnabled(PageContext JavaDoc ctx){
71         if(!isToolTipsEnabled(ctx)){
72             ctx.setAttribute(TOOLTIPS_ENABLED_ATTR, "true", PageContext.PAGE_SCOPE);
73         }
74     }
75     
76     public static final boolean isToolTipsEnabled(PageContext JavaDoc ctx){
77         return ctx.getAttribute(TOOLTIPS_ENABLED_ATTR, PageContext.PAGE_SCOPE) != null;
78     }
79     
80 }
81
Popular Tags