1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.pluto.tags;
21
22 import java.io.IOException;
23 import java.lang.reflect.Field;
24 import java.util.Hashtable;
25
26 import javax.portlet.PortletMode;
27 import javax.portlet.PortletURL;
28 import javax.portlet.WindowState;
29 import javax.servlet.jsp.JspException;
30 import javax.servlet.jsp.JspWriter;
31 import javax.servlet.jsp.PageContext;
32 import javax.servlet.jsp.tagext.TagData;
33 import javax.servlet.jsp.tagext.TagExtraInfo;
34 import javax.servlet.jsp.tagext.TagSupport;
35 import javax.servlet.jsp.tagext.VariableInfo;
36
37 /***
38 * Supporting class for the <CODE>actionURL</CODE> and <CODE>renderURL</CODE> tag.
39 * Creates a url that points to the current Portlet and triggers an action request
40 * with the supplied parameters.
41 *
42 */
43 public abstract class BasicURLTag extends TagSupport
44 {
45
46 public static class TEI extends TagExtraInfo
47 {
48 public final static Hashtable definedWindowStates = getDefinedWindowStates();
49 public final static Hashtable portletModes = getDefinedPortletModes();
50
51 /***
52 * Provides a list of all static PortletMode available in the specifications by
53 * using introspection
54 * @return Hashtable
55 */
56 private static Hashtable getDefinedPortletModes()
57 {
58 Hashtable portletModes = new Hashtable();
59 Field[] f = PortletMode.class.getDeclaredFields();
60
61 for (int i = 0; i < f.length; i++)
62 {
63 if (f[i].getType().isAssignableFrom(javax.portlet.PortletMode.class))
64 {
65 try
66 {
67 portletModes.put(f[i].get(f[i]).toString().toUpperCase(), f[i].get(f[i]));
68 }
69 catch (IllegalAccessException e)
70 {
71 }
72 }
73 }
74
75 return portletModes;
76 }
77
78 /***
79 * Provides a list of all static WindowsStates available in the specifications by
80 * using introspection
81 * @return Hashtable
82 */
83 private static Hashtable getDefinedWindowStates()
84 {
85 Hashtable definedWindowStates = new Hashtable();
86 Field[] f = WindowState.class.getDeclaredFields();
87
88 for (int i = 0; i < f.length; i++)
89 {
90 if (f[i].getType().isAssignableFrom(javax.portlet.WindowState.class))
91 {
92 try
93 {
94 definedWindowStates.put(f[i].get(f[i]).toString().toUpperCase(), f[i].get(f[i]));
95 }
96 catch (IllegalAccessException e)
97 {
98
99 }
100 }
101 }
102 return definedWindowStates;
103 }
104
105 public VariableInfo[] getVariableInfo(TagData tagData)
106 {
107 VariableInfo vi[] = null;
108 String var = tagData.getAttributeString("var");
109 if (var != null)
110 {
111 vi = new VariableInfo[1];
112 vi[0] = new VariableInfo(var, "java.lang.String", true, VariableInfo.AT_BEGIN);
113 }
114 return vi;
115 }
116
117 }
118
119 protected String portletMode;
120 protected String secure;
121 protected Boolean secureBoolean;
122 protected String windowState;
123 protected PortletURL url;
124 protected String var;
125
126 /***
127 * Processes the <CODE>actionURL</CODE> or <CODE>renderURL</CODE> tag.
128 * @return int
129 */
130 public abstract int doStartTag() throws JspException;
131
132 /***
133 *
134 * @return int
135 */
136 public int doEndTag() throws JspException {
137 if (var == null)
138 {
139 try
140 {
141 JspWriter writer = pageContext.getOut();
142 writer.print(url);
143 writer.flush();
144 }
145 catch (IOException ioe)
146 {
147 throw new JspException("actionURL/renderURL Tag Exception: cannot write to the output writer.");
148 }
149 } else {
150 pageContext.setAttribute (var, url.toString(), PageContext.PAGE_SCOPE);
151 }
152 return EVAL_PAGE;
153 }
154
155 /***
156 * Returns the portletMode.
157 * @return String
158 */
159 public String getPortletMode()
160 {
161 return portletMode;
162 }
163
164 /***
165 * @return secure as String
166 */
167 public String getSecure()
168 {
169 return secure;
170 }
171
172 /***
173 * @return secure as Boolean
174 */
175 public boolean getSecureBoolean()
176 {
177 return this.secureBoolean.booleanValue();
178 }
179
180 /***
181 * Returns the windowState.
182 * @return String
183 */
184 public String getWindowState()
185 {
186 return windowState;
187 }
188
189 /***
190 * @return PortletURL
191 */
192 public PortletURL getUrl()
193 {
194 return url;
195 }
196
197 /***
198 * Returns the var.
199 * @return String
200 */
201 public String getVar()
202 {
203 return var;
204 }
205
206 /***
207 * Sets the portletMode.
208 * @param portletMode The portletMode to set
209 */
210 public void setPortletMode(String portletMode)
211 {
212 this.portletMode = portletMode;
213 }
214
215 /***
216 * Sets secure to boolean value of the string
217 * @param secure
218 */
219 public void setSecure(String secure)
220 {
221 this.secure = secure;
222 this.secureBoolean = new Boolean(secure);
223 }
224
225 /***
226 * Sets the windowState.
227 * @param windowState The windowState to set
228 */
229 public void setWindowState(String windowState)
230 {
231 this.windowState = windowState;
232 }
233
234 /***
235 * Sets the url.
236 * @param url The url to set
237 */
238 public void setUrl(PortletURL url)
239 {
240 this.url = url;
241 }
242
243 /***
244 * Sets the var.
245 * @param var The var to set
246 */
247 public void setVar(String var)
248 {
249 this.var = var;
250 }
251 }