1 13 package com.tonbeller.jpivot.table.navi; 14 15 import javax.servlet.jsp.JspException ; 16 import javax.servlet.jsp.tagext.TagSupport ; 17 18 import org.apache.log4j.Logger; 19 20 import com.tonbeller.jpivot.param.MemberParamProvider; 21 import com.tonbeller.jpivot.param.ParameterProvider; 22 import com.tonbeller.jpivot.param.PropertyParamProvider; 23 import com.tonbeller.jpivot.param.PropertyPrefixParamProvider; 24 import com.tonbeller.jpivot.table.AxisBuilder; 25 import com.tonbeller.jpivot.table.ClickableMember; 26 import com.tonbeller.jpivot.table.SpanBuilder; 27 import com.tonbeller.jpivot.table.TableComponent; 28 import com.tonbeller.jpivot.table.TableComponentTag; 29 import com.tonbeller.jpivot.tags.OlapModelTag; 30 31 37 public class ClickableMemberTag extends TagSupport { 38 String urlPattern; 39 String uniqueName; 40 String menuLabel; 41 42 String sessionParam; 43 String propertyName; 44 String propertyPrefix; 45 String providerClass; 46 String page; 47 48 private static Logger logger = Logger.getLogger(ClickableMemberTag.class); 49 50 public int doStartTag() throws JspException { 51 if (propertyPrefix != null && sessionParam != null) 52 throw new JspException ("propertyPrefix and sessionParam can not be specified both"); 53 54 if (logger.isInfoEnabled()) 55 logger.info("creating clickable member for URL: " + urlPattern + ", uniqueName: " 56 + uniqueName); 57 58 TableComponentTag tct = (TableComponentTag) findAncestorWithClass(this, TableComponentTag.class); 59 if (tct != null) { 60 createStaticClickable(tct); 61 return SKIP_BODY; 62 } 63 64 OlapModelTag omt = (OlapModelTag) findAncestorWithClass(this, OlapModelTag.class); 65 if (omt != null) { 66 createDynamicClickable(omt); 67 return SKIP_BODY; 68 } 69 70 throw new JspException ("ClickableMemberTag must be nested in a table or query tag"); 71 } 72 73 private void createDynamicClickable(OlapModelTag omt) { 74 ParameterProvider provider = createProvider(); 75 ClickableMember clickable = createClickable(provider); 76 omt.addClickable(clickable); 77 } 78 79 private void createStaticClickable(TableComponentTag tct) throws JspException { 80 TableComponent tc = (TableComponent) tct.getComponent(); 81 ParameterProvider provider = createProvider(); 82 decorate(tc.getRowAxisBuilder(), createClickable(provider)); 83 decorate(tc.getColumnAxisBuilder(), createClickable(provider)); 84 } 85 86 private ClickableMember createClickable(ParameterProvider provider) { 87 if (provider != null) { 88 DynamicClickableMember dcm = new DynamicClickableMember(uniqueName, menuLabel, provider, page); 89 dcm.setUrlPattern(urlPattern); return dcm; 91 } 92 return new UrlClickableMember(uniqueName, menuLabel, urlPattern); 93 } 94 95 private ParameterProvider createProvider() { 96 ParameterProvider provider = null; 97 98 if (sessionParam != null) { 99 if (propertyName != null) 100 provider = new PropertyParamProvider(sessionParam, propertyName); 101 else 102 provider = new MemberParamProvider(sessionParam); 103 } else if (propertyPrefix != null) { 104 provider = new PropertyPrefixParamProvider(propertyPrefix); 105 } else if (providerClass != null) { 106 try { 107 provider = (ParameterProvider) Class.forName(providerClass).newInstance(); 108 } catch (InstantiationException e) { 109 logger.error(null, e); 110 } catch (IllegalAccessException e) { 111 logger.error(null, e); 112 } catch (ClassNotFoundException e) { 113 logger.error(null, e); 114 } 115 } 116 return provider; 117 } 118 119 private void decorate(AxisBuilder axisBuilder, ClickableMember clickable) { 120 SpanBuilder decoree = axisBuilder.getSpanBuilder(); 121 SpanBuilder decorator = new StaticClickableMember(decoree, clickable); 122 axisBuilder.setSpanBuilder(decorator); 123 } 124 125 public void setUniqueName(String string) { 126 uniqueName = string; 127 } 128 129 public void setUrlPattern(String string) { 130 urlPattern = string; 131 } 132 133 public void setSessionParam(String sessionParam) { 134 this.sessionParam = sessionParam; 135 } 136 137 public void setPropertyName(String propertyName) { 138 this.propertyName = propertyName; 139 } 140 141 public void setPropertyPrefix(String propertyPrefix) { 142 this.propertyPrefix = propertyPrefix; 143 } 144 145 public void setProviderClass(String providerClass) { 146 this.providerClass = providerClass; 147 } 148 149 public void setPage(String page) { 150 this.page = page; 151 } 152 153 public void setMenuLabel(String menuLabel) { 154 this.menuLabel = menuLabel; 155 } 156 157 } | Popular Tags |