java/cewolf-1.0/src/main/java/de/laures/cewolf/taglib/util/PageUtils.java
changeset 1 639991d0808a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/java/cewolf-1.0/src/main/java/de/laures/cewolf/taglib/util/PageUtils.java	Sat Feb 28 21:31:02 2009 +0100
     1.3 @@ -0,0 +1,80 @@
     1.4 +/* ================================================================
     1.5 + * Cewolf : Chart enabling Web Objects Framework
     1.6 + * ================================================================
     1.7 + *
     1.8 + * Project Info:  http://cewolf.sourceforge.net
     1.9 + * Project Lead:  Guido Laures (guido@laures.de);
    1.10 + *
    1.11 + * (C) Copyright 2002, by Guido Laures
    1.12 + *
    1.13 + * This library is free software; you can redistribute it and/or modify it under the terms
    1.14 + * of the GNU Lesser General Public License as published by the Free Software Foundation;
    1.15 + * either version 2.1 of the License, or (at your option) any later version.
    1.16 + *
    1.17 + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
    1.18 + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    1.19 + * See the GNU Lesser General Public License for more details.
    1.20 + *
    1.21 + * You should have received a copy of the GNU Lesser General Public License along with this
    1.22 + * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
    1.23 + * Boston, MA 02111-1307, USA.
    1.24 + */
    1.25 +
    1.26 +package de.laures.cewolf.taglib.util;
    1.27 +
    1.28 +import javax.servlet.jsp.PageContext;
    1.29 +import javax.servlet.jsp.tagext.Tag;
    1.30 +
    1.31 +import org.jfree.data.general.Dataset;
    1.32 +
    1.33 +import de.laures.cewolf.ChartHolder;
    1.34 +import de.laures.cewolf.DatasetProduceException;
    1.35 +import de.laures.cewolf.taglib.tags.CewolfRootTag;
    1.36 +
    1.37 +/**
    1.38 + * Helper class to easily retrieve some objects of page context.
    1.39 + * @author  glaures
    1.40 + */
    1.41 +public class PageUtils {
    1.42 +    
    1.43 +    private final static String TOOLTIPS_ENABLED_ATTR = PageUtils.class.getName() + ".ttenabled";
    1.44 +    
    1.45 +    /** Creates a new instance of ChartDefinitionFactory */
    1.46 +    private PageUtils() {}
    1.47 +    
    1.48 +    public static ChartHolder getChartHolder(String chartId, PageContext ctx){
    1.49 +        return (ChartHolder)ctx.getAttribute(chartId, PageContext.PAGE_SCOPE);
    1.50 +    }
    1.51 +    
    1.52 +    public static final ChartHolder getChartHolder(Tag tag, PageContext ctx){
    1.53 +        CewolfRootTag root = findRoot(tag, ctx);
    1.54 +        if(root instanceof ChartHolder){
    1.55 +            return (ChartHolder)root;
    1.56 +        } else {
    1.57 +            return getChartHolder(root.getChartId(), ctx);
    1.58 +        }
    1.59 +    }
    1.60 +    
    1.61 +    public static final Dataset getDataset(String chartId, PageContext ctx) throws DatasetProduceException {
    1.62 +        return (Dataset) getChartHolder(chartId, ctx).getDataset();
    1.63 +    }
    1.64 +
    1.65 +    public static final CewolfRootTag findRoot(Tag t, PageContext ctx){
    1.66 +        Tag res = t;
    1.67 +        while(!(res instanceof CewolfRootTag)){
    1.68 +            res = res.getParent();
    1.69 +        }
    1.70 +        return (CewolfRootTag)res;
    1.71 +    }
    1.72 +    
    1.73 +    public static final void setToolTipsEnabled(PageContext ctx){
    1.74 +        if(!isToolTipsEnabled(ctx)){
    1.75 +            ctx.setAttribute(TOOLTIPS_ENABLED_ATTR, "true", PageContext.PAGE_SCOPE);
    1.76 +        }
    1.77 +    }
    1.78 +    
    1.79 +    public static final boolean isToolTipsEnabled(PageContext ctx){
    1.80 +        return ctx.getAttribute(TOOLTIPS_ENABLED_ATTR, PageContext.PAGE_SCOPE) != null;
    1.81 +    }
    1.82 +    
    1.83 +}