KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > services > jsp > tags > JetspeedParameterStyleTag


1 /*
2  * Copyright 2000-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.jetspeed.services.jsp.tags;
18
19 // java classes
20
import java.util.Hashtable JavaDoc;
21 import java.util.StringTokenizer JavaDoc;
22
23 // jsp api
24
import javax.servlet.jsp.PageContext JavaDoc;
25 import javax.servlet.jsp.JspException JavaDoc;
26 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
27
28 // Turbine Classes
29
import org.apache.turbine.util.RunData;
30 import org.apache.turbine.services.jsp.JspService;
31
32 // jetspeed
33
import org.apache.jetspeed.modules.ParameterLoader;
34 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
35 import org.apache.jetspeed.services.logging.JetspeedLogger;
36 import org.apache.jetspeed.services.security.PortalResource;
37 import org.apache.jetspeed.om.registry.Parameter;
38 import org.apache.jetspeed.om.registry.PortletEntry;
39 import org.apache.jetspeed.services.JetspeedSecurity;
40 import org.apache.jetspeed.om.security.JetspeedUser;
41 import org.apache.jetspeed.services.Registry;
42
43 /**
44  * Supporting class for the parameter style tag.
45  * Sends a parameter rendered using specific style to the output stream.
46  *
47  * The following tag attributes are supported:
48  *
49  * <UL>
50  * <LI><code>name</code>: parameter name (required).</li>
51  * <LI><code>style</code>: parameter style name (required)</LI>
52  * <LI><code>value</code>: parameter current value</LI>
53  * <LI><code>portlet</code>: portlet name to check security against</LI>
54  * </UL>
55  * <p>Note: tag body may also contain parameter style options in format: option1=value1;optionN=valueN. Check
56  * documentation for individual parameter style to see what options are supported</p>
57  * <p>Note: Use care when specifying style options in the tag body - the body is not cleansed to remove
58  * embedded carriage returns and tabs.</p>
59  * Examples:
60  * <UL>
61  * <LI><code>&lt;jetspeed:parameterStyle name="portlet-list" style="RegistryEntryListBox"/&gt;</CODE>
62  * <LI><code>&lt;jetspeed:parameterStyle name="skin-list" style="RegistryEntryListBox"&gt;registry=Skin&lt;/jetspeed:parameterStyle/&gt;</CODE>
63  * <LI><code>&lt;jetspeed:parameterStyle name="control-list" style="RegistryEntryListBox" value="TabControl"&gt;registry=PortletControl&lt;/jetspeed:parameterStyle/&gt;</CODE>
64  * </UL>
65  *
66  * @author <a HREF="mailto:morciuch@apache.org">Mark Orciuch</a>
67  * @version $Id: JetspeedParameterStyleTag.java,v 1.4 2004/02/23 03:59:40 jford Exp $
68  */

69 public class JetspeedParameterStyleTag extends BodyTagSupport JavaDoc
70 {
71     /**
72      * Static initialization of the logger for this class
73      */

74     private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(JetspeedParameterStyleTag.class.getName());
75     
76     /**
77      * name parameter defines parameter name
78      */

79     private String JavaDoc name = null;
80
81     /**
82      * name parameter defines parameter style
83      */

84     private String JavaDoc style = null;
85
86     /**
87      * name parameter defines current parameter style value
88      */

89     private String JavaDoc value = null;
90
91     /**
92      * name parameter defines portlet name to check security against
93      */

94     private String JavaDoc portlet = null;
95
96     /**
97      * The setter for name parameter
98      *
99      * @param value
100      */

101     public void setName(String JavaDoc value)
102     {
103         this.name = value;
104     }
105
106     /**
107      * The setter for value parameter
108      *
109      * @param value
110      */

111     public void setValue(String JavaDoc value)
112     {
113         this.value = value;
114     }
115
116     /**
117      * The setter for syle parameter
118      *
119      * @param value
120      */

121     public void setStyle(String JavaDoc value)
122     {
123         this.style = value;
124     }
125
126     /**
127      * The setter for value parameter
128      *
129      * @param value
130      */

131     public void setPortlet(String JavaDoc value)
132     {
133         this.portlet = value;
134     }
135
136     /**
137      *
138      * @return code
139      * @exception JspException
140      */

141     public int doStartTag() throws JspException JavaDoc
142     {
143         return EVAL_BODY_TAG;
144     }
145
146     /**
147      *
148      * @return code
149      * @exception JspException
150      */

151     public int doEndTag() throws JspException JavaDoc
152     {
153         RunData data = (RunData) pageContext.getAttribute(JspService.RUNDATA, PageContext.REQUEST_SCOPE);
154         String JavaDoc result = null;
155
156         try
157         {
158
159             // See if body contains any parameter options
160
String JavaDoc body = this.getBodyContent() == null ? null : this.getBodyContent().getString();
161             Hashtable JavaDoc options = new Hashtable JavaDoc();
162
163             if (body != null && !body.trim().equalsIgnoreCase(""))
164             {
165                 StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(body, ";");
166                 String JavaDoc prefix = this.name + ".style.";
167                 while (st.hasMoreTokens())
168                 {
169                     StringTokenizer JavaDoc pair = new StringTokenizer JavaDoc(st.nextToken(), "=");
170                     if (pair.countTokens() == 2)
171                     {
172                         options.put(prefix + pair.nextToken().trim(), pair.nextToken().trim());
173                     }
174                 }
175             }
176
177             boolean canAccess = true;
178
179             // If portlet name is specified, it will be used to check security for the parameter
180
if (this.portlet != null)
181             {
182                 // Retrieve registry entry and its parameter
183
PortletEntry entry = (PortletEntry) Registry.getEntry(Registry.PORTLET, this.portlet);
184                 Parameter param = entry.getParameter(this.name);
185
186                 // Verify security for the parameter
187
canAccess = JetspeedSecurity.checkPermission((JetspeedUser) data.getUser(),
188                                                              new PortalResource(entry, param),
189                                                              JetspeedSecurity.PERMISSION_CUSTOMIZE);
190             }
191
192             if (canAccess)
193             {
194                 result = ParameterLoader.getInstance().eval(data,
195                                                             this.style,
196                                                             this.name,
197                                                             this.value,
198                                                             options);
199             }
200
201             pageContext.getOut().print(result);
202
203
204         }
205         catch (Exception JavaDoc e)
206         {
207             result = "<input type=\"text\" name=\"" + this.name + "\" value=\"" + this.value + "\"";
208
209             String JavaDoc message = "Error processing portlet (PortletTag): [" + name + "]";
210             logger.error(message, e);
211             try
212             {
213                 pageContext.getOut().print(result);
214             }
215             catch (java.io.IOException JavaDoc ioe)
216             {
217             }
218         }
219
220         return EVAL_PAGE;
221     }
222
223 }
Popular Tags