1/*2 * Copyright 2000-2001,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 at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.portal;
1819//standard java stuff20import java.util.Hashtable;
21import java.util.Map;
2223//turbine support24import org.apache.turbine.services.servlet.TurbineServlet;
2526//jetspeed support27import org.apache.jetspeed.capability.CapabilityMap;
28import org.apache.jetspeed.om.SecurityReference;
29import org.apache.jetspeed.util.BaseConfig;
30import org.apache.jetspeed.util.MetaData;
3132/***33 * Defines a configuration for Portlets. A PortletConfig provides information34 * about the running environment of a given Portlet.35 *36 * @author <a href="mailto:burton@apache.org">Kevin A. Burton</a>37 * @version $Id: BasePortletConfig.java,v 1.11 2004/02/23 04:05:35 jford Exp $38 */39publicclassBasePortletConfigextendsBaseConfig implements PortletConfig40 {
4142private String url;
43privateMetaData metainfo;
44private PortletSet.Constraints layoutConstraints = null;
45privateint layoutPosition = -1;
46privatePortletSkin skin;
47privatetransientPortletSet currentSet;
48privateCapabilityMap cm = null;
49privateboolean cachedOnURL = true;
50private String pageId;
51private String portletId;
52privateSecurityReference securityRef = null;
5354/***55 Init this PortletConfig providing the basic info.56 */57publicvoid init( String url, Map init_params )
58 {
59if (init_params == null)
60 {
61this.setInitParameters(new Hashtable());
62 }
63else64 {
65this.setInitParameters( init_params );
66 }
6768this.setURL( url );
69 }
7071/***72 Returns the portlet current PortletSet73 */74publicPortletSet getPortletSet()
75 {
76returnthis.currentSet;
77 }
7879/***80 Set the context (PortletSet) for this portlet81 */82publicvoid setPortletSet(PortletSet set)
83 {
84this.currentSet=set;
85 }
8687/***88 Returns the portlet current PortletSet89 @deprecated use getConstraints instead90 */91public Map getLayout()
92 {
93returnthis.layoutConstraints;
94 }
9596/***97 Set the context (PortletSet) for this portlet98 @deprecated use setConstraints instead99 */100publicvoid setLayout(Map constraints)
101 {
102//obsolete103 }
104105/***106 * Returns the current skin mapping. This method is used for configuration. Use107 * getPortletSkin() to find skin use by the Layout engine.108 *109 * @return Current skin mapping or null if no skin is defined in PSML.110 */111public Map getSkin()
112 {
113returnthis.skin;
114 }
115116/***117 * Set the context (PortletSet) for this portlet118 *119 * @deprecated use setPortletSkin instead120 */121publicvoid setSkin(Map skin)
122 {
123//obsolete124 }
125126/***127 Returns the portlet current PortletSet128 */129publicint getPosition()
130 {
131returnthis.layoutPosition;
132 }
133134/***135 Set the context (PortletSet) for this portlet136 */137publicvoid setPosition(int position)
138 {
139this.layoutPosition=position;
140 }
141142/***143 Returns this Portlet's Metainfo or null it none exists. The Metainfo can144 be used to determine an optional title or description for this Portlet.145 */146publicMetaData getMetainfo()
147 {
148returnthis.metainfo;
149 }
150151/***152 Set the metainfo for the Portlet153 */154publicvoid setMetainfo(MetaData metainfo)
155 {
156this.metainfo = metainfo;
157 }
158159/***160 Portlets can have external configuration information other than just161 parameters. A URL can define an external configuration file or HTML file162 that this Portlet can parse out.163164 The main reason for using setURL/getURL is because the remote URL is cached165 within Jetspeed so future requests won't have any latency.166 */167public String getURL()
168 {
169returnthis.url;
170 }
171172/***173 Used to define a Portlet's URL.174 */175publicvoid setURL(String url)
176 {
177if ( url == null )
178 {
179return;
180 }
181182//if the given URL doesn not include a protocol... ie http:// or ftp://183//then resolve it relative to the current URL context184if ( url.indexOf("://") < 0 )
185 {
186this.url = TurbineServlet.getResource( url ).toString();
187 }
188else189 {
190this.url = url;
191 }
192 }
193194publicboolean isCachedOnURL()
195 {
196return cachedOnURL;
197 }
198199publicvoid setCachedOnURL(boolean cached)
200 {
201 cachedOnURL = cached;
202 }
203204205/***206 Returns a parameter (or defaultValue) that was given to a Portlet. This can be207 by a Portlet to obtain further information of itself.208 The parameter is returned even if it is defined in the context and not directly209 in the portlet config210 */211public String getLayout(String name, String defaultValue)
212 {
213 String value = null;
214215if (name!=null && layoutConstraints != null)
216 {
217 value=(String)layoutConstraints.get(name.toLowerCase());
218 }
219220if (value==null)
221 {
222 value=defaultValue;
223 }
224225return value;
226 }
227228/***229 Returns a parameter (or defaultValue) that was given to a Portlet. This can be230 by a Portlet to obtain further information of itself.231 The parameter is returned even if it is defined in the context and not directly232 in the portlet config233 */234public String getSkin(String name, String defaultValue)
235 {
236 String value = null;
237238try239 {
240 value=(String)skin.get(name.toLowerCase());
241if (value==null)
242 {
243 value=(String)currentSet.getPortletConfig().getSkin(name, defaultValue);
244 }
245if (value==null) value=defaultValue;
246 }
247catch (RuntimeException e)
248 {
249 value=defaultValue;
250 }
251252return value;
253 }
254255/***256 Sets a skin parameter value in the local config257 */258publicvoid setSkin(String name, String value)
259 {
260if (name!=null)
261 {
262if (getSkin()==null)
263 {
264 setPortletSkin(getPortletSkin());
265 }
266267if (value==null)
268 {
269 getSkin().remove(name);
270 }
271else272 {
273 getSkin().put(name,value);
274 }
275 }
276 }
277278/***279 * Retrieves the Skin object that should be used for this portlet. If 280 * the current portlet does not have a skin, then skin is retrieve from281 * the parent portlet set of the system default is now skins are defined282 * in the portlet set.283 *284 * getSkin() can be used for configuration.285 *286 * @return the Skin object that should be used.287 */288publicPortletSkin getPortletSkin()
289 {
290if ((this.skin==null)&&(getPortletSet()!=null))
291 {
292return getPortletSet().getPortletConfig().getPortletSkin();
293 }
294295returnthis.skin;
296 }
297298/***299 * Sets the PortletSkin to use for this Portlet300 *301 * @param skin the new skin to use302 */303publicvoid setPortletSkin(PortletSkin skin)
304 {
305this.skin = skin;
306 }
307308/***309 * Retrieves the constraints associated with this portlet310 *311 * @return the Constraints object312 */313public PortletSet.Constraints getConstraints()
314 {
315returnthis.layoutConstraints;
316 }
317318/***319 * Sets the layout constraints in the current portlet set320 *321 * @param constraints the constrints object associated with this portlet322 * in the current set323 */324publicvoid setConstraints(PortletSet.Constraints constraints)
325 {
326this.layoutConstraints = constraints;
327 }
328329/***330 */331publicCapabilityMap getCapabilityMap()
332 {
333returnthis.cm;
334 }
335336/***337 */338publicvoid setCapabilityMap( CapabilityMap cm )
339 {
340this.cm = cm;
341 }
342343publicvoid setPageId(String pageId)
344 {
345this.pageId = pageId;
346 }
347348public String getPageId()
349 {
350returnthis.pageId;
351 }
352353publicvoid setPortletId(String portletId)
354 {
355this.portletId = portletId;
356 }
357358public String getPortletId()
359 {
360returnthis.portletId;
361 }
362363/*** Getter for property securityRef.364 * @return Value of property securityRef.365 */366publicSecurityReference getSecurityRef()
367 {
368returnthis.securityRef;
369 }
370371/*** Setter for property securityRef.372 * @param securityRef New value of property securityRef.373 */374publicvoid setSecurityRef(SecurityReference securityRef)
375 {
376this.securityRef = securityRef;
377 }
378379 }