1 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 38 public class PageUtils { 39 40 private final static String TOOLTIPS_ENABLED_ATTR = PageUtils.class.getName() + ".ttenabled"; 41 42 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 } 81 | Popular Tags |