java/cewolf-1.0/src/main/java/de/laures/cewolf/taglib/util/PageUtils.java
author František Kučera <franta-hg@frantovo.cz>
Sat, 28 Feb 2009 21:31:02 +0100
changeset 1 639991d0808a
permissions -rw-r--r--
Rozbalená knihovna verze 1.0
     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;
    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.getName() + ".ttenabled";
    41     
    42     /** Creates a new instance of ChartDefinitionFactory */
    43     private PageUtils() {}
    44     
    45     public static ChartHolder getChartHolder(String chartId, PageContext ctx){
    46         return (ChartHolder)ctx.getAttribute(chartId, PageContext.PAGE_SCOPE);
    47     }
    48     
    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;
    53         } else {
    54             return getChartHolder(root.getChartId(), ctx);
    55         }
    56     }
    57     
    58     public static final Dataset getDataset(String chartId, PageContext ctx) throws DatasetProduceException {
    59         return (Dataset) getChartHolder(chartId, ctx).getDataset();
    60     }
    61 
    62     public static final CewolfRootTag findRoot(Tag t, PageContext ctx){
    63         Tag 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 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 ctx){
    77         return ctx.getAttribute(TOOLTIPS_ENABLED_ATTR, PageContext.PAGE_SCOPE) != null;
    78     }
    79     
    80 }