KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > portal > BasePortletConfig


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 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.portal;
18
19 //standard java stuff
20
import java.util.Hashtable JavaDoc;
21 import java.util.Map JavaDoc;
22
23 //turbine support
24
import org.apache.turbine.services.servlet.TurbineServlet;
25
26 //jetspeed support
27
import org.apache.jetspeed.capability.CapabilityMap;
28 import org.apache.jetspeed.om.SecurityReference;
29 import org.apache.jetspeed.util.BaseConfig;
30 import org.apache.jetspeed.util.MetaData;
31
32 /**
33  * Defines a configuration for Portlets. A PortletConfig provides information
34  * 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  */

39 public class BasePortletConfig extends BaseConfig implements PortletConfig
40 {
41
42     private String JavaDoc url;
43     private MetaData metainfo;
44     private PortletSet.Constraints layoutConstraints = null;
45     private int layoutPosition = -1;
46     private PortletSkin skin;
47     private transient PortletSet currentSet;
48     private CapabilityMap cm = null;
49     private boolean cachedOnURL = true;
50     private String JavaDoc pageId;
51     private String JavaDoc portletId;
52     private SecurityReference securityRef = null;
53
54     /**
55     Init this PortletConfig providing the basic info.
56     */

57     public void init( String JavaDoc url, Map JavaDoc init_params )
58     {
59         if (init_params == null)
60         {
61             this.setInitParameters(new Hashtable JavaDoc());
62         }
63         else
64         {
65             this.setInitParameters( init_params );
66         }
67
68         this.setURL( url );
69     }
70
71     /**
72     Returns the portlet current PortletSet
73     */

74     public PortletSet getPortletSet()
75     {
76         return this.currentSet;
77     }
78
79     /**
80     Set the context (PortletSet) for this portlet
81     */

82     public void setPortletSet(PortletSet set)
83     {
84         this.currentSet=set;
85     }
86
87     /**
88     Returns the portlet current PortletSet
89      @deprecated use getConstraints instead
90     */

91     public Map JavaDoc getLayout()
92     {
93         return this.layoutConstraints;
94     }
95
96     /**
97      Set the context (PortletSet) for this portlet
98      @deprecated use setConstraints instead
99     */

100     public void setLayout(Map JavaDoc constraints)
101     {
102         //obsolete
103
}
104
105     /**
106      * Returns the current skin mapping. This method is used for configuration. Use
107      * 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      */

111     public Map JavaDoc getSkin()
112     {
113         return this.skin;
114     }
115
116     /**
117      * Set the context (PortletSet) for this portlet
118      *
119      * @deprecated use setPortletSkin instead
120      */

121     public void setSkin(Map JavaDoc skin)
122     {
123         //obsolete
124
}
125
126     /**
127     Returns the portlet current PortletSet
128     */

129     public int getPosition()
130     {
131         return this.layoutPosition;
132     }
133
134     /**
135     Set the context (PortletSet) for this portlet
136     */

137     public void setPosition(int position)
138     {
139         this.layoutPosition=position;
140     }
141
142     /**
143     Returns this Portlet's Metainfo or null it none exists. The Metainfo can
144     be used to determine an optional title or description for this Portlet.
145     */

146     public MetaData getMetainfo()
147     {
148         return this.metainfo;
149     }
150
151     /**
152     Set the metainfo for the Portlet
153     */

154     public void setMetainfo(MetaData metainfo)
155     {
156         this.metainfo = metainfo;
157     }
158
159     /**
160     Portlets can have external configuration information other than just
161     parameters. A URL can define an external configuration file or HTML file
162     that this Portlet can parse out.
163
164     The main reason for using setURL/getURL is because the remote URL is cached
165     within Jetspeed so future requests won't have any latency.
166     */

167     public String JavaDoc getURL()
168     {
169         return this.url;
170     }
171
172     /**
173     Used to define a Portlet's URL.
174     */

175     public void setURL(String JavaDoc url)
176     {
177         if ( url == null )
178         {
179             return;
180         }
181
182         //if the given URL doesn not include a protocol... ie http:// or ftp://
183
//then resolve it relative to the current URL context
184
if ( url.indexOf("://") < 0 )
185         {
186             this.url = TurbineServlet.getResource( url ).toString();
187         }
188         else
189         {
190             this.url = url;
191         }
192     }
193
194     public boolean isCachedOnURL()
195     {
196         return cachedOnURL;
197     }
198
199     public void setCachedOnURL(boolean cached)
200     {
201         cachedOnURL = cached;
202     }
203
204
205     /**
206     Returns a parameter (or defaultValue) that was given to a Portlet. This can be
207     by a Portlet to obtain further information of itself.
208     The parameter is returned even if it is defined in the context and not directly
209     in the portlet config
210     */

211     public String JavaDoc getLayout(String JavaDoc name, String JavaDoc defaultValue)
212     {
213         String JavaDoc value = null;
214
215         if (name!=null && layoutConstraints != null)
216         {
217             value=(String JavaDoc)layoutConstraints.get(name.toLowerCase());
218         }
219
220         if (value==null)
221         {
222             value=defaultValue;
223         }
224
225         return value;
226     }
227
228     /**
229     Returns a parameter (or defaultValue) that was given to a Portlet. This can be
230     by a Portlet to obtain further information of itself.
231     The parameter is returned even if it is defined in the context and not directly
232     in the portlet config
233     */

234     public String JavaDoc getSkin(String JavaDoc name, String JavaDoc defaultValue)
235     {
236         String JavaDoc value = null;
237
238         try
239         {
240             value=(String JavaDoc)skin.get(name.toLowerCase());
241             if (value==null)
242             {
243                 value=(String JavaDoc)currentSet.getPortletConfig().getSkin(name, defaultValue);
244             }
245             if (value==null) value=defaultValue;
246         }
247         catch (RuntimeException JavaDoc e)
248         {
249             value=defaultValue;
250         }
251
252         return value;
253     }
254
255     /**
256     Sets a skin parameter value in the local config
257     */

258     public void setSkin(String JavaDoc name, String JavaDoc value)
259     {
260         if (name!=null)
261         {
262             if (getSkin()==null)
263             {
264                 setPortletSkin(getPortletSkin());
265             }
266             
267             if (value==null)
268             {
269                 getSkin().remove(name);
270             }
271             else
272             {
273                 getSkin().put(name,value);
274             }
275         }
276     }
277
278     /**
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 from
281      * the parent portlet set of the system default is now skins are defined
282      * in the portlet set.
283      *
284      * getSkin() can be used for configuration.
285      *
286      * @return the Skin object that should be used.
287      */

288     public PortletSkin getPortletSkin()
289     {
290         if ((this.skin==null)&&(getPortletSet()!=null))
291         {
292             return getPortletSet().getPortletConfig().getPortletSkin();
293         }
294             
295         return this.skin;
296     }
297     
298     /**
299      * Sets the PortletSkin to use for this Portlet
300      *
301      * @param skin the new skin to use
302      */

303     public void setPortletSkin(PortletSkin skin)
304     {
305         this.skin = skin;
306     }
307     
308     /**
309      * Retrieves the constraints associated with this portlet
310      *
311      * @return the Constraints object
312      */

313     public PortletSet.Constraints getConstraints()
314     {
315         return this.layoutConstraints;
316     }
317     
318     /**
319      * Sets the layout constraints in the current portlet set
320      *
321      * @param constraints the constrints object associated with this portlet
322      * in the current set
323      */

324     public void setConstraints(PortletSet.Constraints constraints)
325     {
326         this.layoutConstraints = constraints;
327     }
328     
329     /**
330     */

331     public CapabilityMap getCapabilityMap()
332     {
333         return this.cm;
334     }
335     
336     /**
337     */

338     public void setCapabilityMap( CapabilityMap cm )
339     {
340         this.cm = cm;
341     }
342
343     public void setPageId(String JavaDoc pageId)
344     {
345         this.pageId = pageId;
346     }
347
348     public String JavaDoc getPageId()
349     {
350         return this.pageId;
351     }
352
353     public void setPortletId(String JavaDoc portletId)
354     {
355         this.portletId = portletId;
356     }
357
358     public String JavaDoc getPortletId()
359     {
360         return this.portletId;
361     }
362
363     /** Getter for property securityRef.
364      * @return Value of property securityRef.
365      */

366     public SecurityReference getSecurityRef()
367     {
368         return this.securityRef;
369     }
370     
371     /** Setter for property securityRef.
372      * @param securityRef New value of property securityRef.
373      */

374     public void setSecurityRef(SecurityReference securityRef)
375     {
376         this.securityRef = securityRef;
377     }
378     
379 }
380
Popular Tags