KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > table > navi > ClickableMemberTag


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.jpivot.table.navi;
14
15 import javax.servlet.jsp.JspException JavaDoc;
16 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
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 /**
32  * allows to click on a member in the table and pass the member
33  * as parameter to another jsp page
34  *
35  * @author av
36  */

37 public class ClickableMemberTag extends TagSupport JavaDoc {
38   String JavaDoc urlPattern;
39   String JavaDoc uniqueName;
40   String JavaDoc menuLabel;
41
42   String JavaDoc sessionParam;
43   String JavaDoc propertyName;
44   String JavaDoc propertyPrefix;
45   String JavaDoc providerClass;
46   String JavaDoc page;
47
48   private static Logger logger = Logger.getLogger(ClickableMemberTag.class);
49
50   public int doStartTag() throws JspException JavaDoc {
51     if (propertyPrefix != null && sessionParam != null)
52       throw new JspException JavaDoc("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 JavaDoc("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 JavaDoc {
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); // support legacy
90
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 JavaDoc e) {
109         logger.error(null, e);
110       } catch (IllegalAccessException JavaDoc e) {
111         logger.error(null, e);
112       } catch (ClassNotFoundException JavaDoc 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 JavaDoc string) {
126     uniqueName = string;
127   }
128
129   public void setUrlPattern(String JavaDoc string) {
130     urlPattern = string;
131   }
132
133   public void setSessionParam(String JavaDoc sessionParam) {
134     this.sessionParam = sessionParam;
135   }
136
137   public void setPropertyName(String JavaDoc propertyName) {
138     this.propertyName = propertyName;
139   }
140
141   public void setPropertyPrefix(String JavaDoc propertyPrefix) {
142     this.propertyPrefix = propertyPrefix;
143   }
144
145   public void setProviderClass(String JavaDoc providerClass) {
146     this.providerClass = providerClass;
147   }
148
149   public void setPage(String JavaDoc page) {
150     this.page = page;
151   }
152
153   public void setMenuLabel(String JavaDoc menuLabel) {
154     this.menuLabel = menuLabel;
155   }
156
157 }
Popular Tags