View Javadoc

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.services.rundata;
18  
19  // Java classes
20  import java.util.Stack;
21  
22  // Jetspeed classes
23  import org.apache.jetspeed.om.security.JetspeedUser;
24  import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
25  import org.apache.jetspeed.services.logging.JetspeedLogger;
26  import org.apache.jetspeed.portal.Portlet;
27  import org.apache.jetspeed.om.profile.Profile;
28  import org.apache.jetspeed.capability.CapabilityMap;
29  import org.apache.jetspeed.capability.CapabilityMapFactory;
30  import org.apache.jetspeed.services.statemanager.SessionState;
31  import org.apache.jetspeed.services.statemanager.StateManagerService;
32  import org.apache.turbine.services.rundata.DefaultTurbineRunData;
33  import org.apache.turbine.services.TurbineServices;
34  import org.apache.turbine.util.security.AccessControlList;
35  
36  /***
37   * This interface extends the RunData interface with methods
38   * specific to the needs of a Jetspeed like portal implementation.
39   *
40   * <note>Several of these properties may be put in the base RunData
41   * interface in future releases of Turbine</note>
42   *
43   * @author <a href="mailto:raphael@apache.org">RaphaŽl Luta</a>
44   * @author <a href="mailto:sgala@apache.org">Santiago Gala</a>
45   * @author <a href="mailto:paulsp@apache.org">Paul Spencer</a>
46   * @version $Id: DefaultJetspeedRunData.java,v 1.20 2004/02/23 03:36:10 jford Exp $
47   */
48  public class DefaultJetspeedRunData extends DefaultTurbineRunData
49      implements JetspeedRunData
50  {
51      /***
52       * Static initialization of the logger for this class
53       */    
54      private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(DefaultJetspeedRunData.class.getName());
55      
56      private Profile profile = null;
57      private CapabilityMap map = null;
58      private String peid = null;
59      private String pid = null;
60      private int mode = NORMAL;
61      private String template = null;
62  
63      /***
64       * Returns the portlet id referenced in this request
65       *
66       * @return the portlet id referenced or null
67       */
68      public String getPortlet()
69      {
70        return pid;
71      }
72  
73      /***
74       * Sets the portlet id referenced for this request
75       *
76       * @param id the portlet id referenced in this request
77       */
78      public void setPortlet(String id)
79      {
80          this.pid = id;
81      }
82  
83      /***
84       * Returns the portlet id which should be customized for this request
85       *
86       * @return the portlet id being customized or null
87       */
88      public Portlet getCustomized()
89      {
90          // customization state info is in the page's session state
91          SessionState customizationState = getPageSessionState();
92          Stack stack = (Stack)customizationState.getAttribute("customize-stack");
93  
94          Portlet p = null;
95  
96          if ((stack!=null)&&(!stack.empty()))
97          {
98              p = (Portlet)stack.peek();
99          }
100 
101         /***
102          * Save the title of this currently selected portlet
103          * --------------------------------------------------------------------------
104          * last modified: 11/06/01
105          * Andreas Kempf, Siemens ICM S CP PE, Munich
106          */
107         if ((p != null) && (stack.size() > 1))
108           customizationState.setAttribute ("customize-paneName", (String)p.getTitle());
109         else
110           customizationState.setAttribute ("customize-paneName", "*");
111 
112         return (Portlet)p;
113     }
114 
115     /***
116      * Sets the portlet id to customize
117      *
118      * @param id the portlet id to customize or null;
119      */
120     public void setCustomized(Portlet p)
121     {
122         // customization state info is in the page's session state
123         SessionState customizationState = getPageSessionState();
124         Stack stack = (Stack)customizationState.getAttribute("customize-stack");
125         if (stack == null)
126         {
127             stack = new Stack();
128             customizationState.setAttribute("customize-stack", stack);
129         }
130 
131         if (p==null)
132         {
133             if (!stack.empty()) stack.pop();
134 
135             customizationState.setAttribute ("customize-paneName", "*");
136         }
137         else
138         {
139           if (stack.size () > 0)
140           {
141             Portlet last = (Portlet)stack.peek();
142 
143 
144             if ((last!=null) && (p.getName().equals(last.getName())) && (p.getTitle().equals(last.getTitle())))
145             {
146                 //System.out.println ("Portlet already used!!!");
147             }
148             else
149               stack.push(p);
150           }
151           else
152             stack.push(p);
153 
154 
155           /***
156            * Save the title of this currently selected portlet
157            * --------------------------------------------------------------------------
158            * last modified: 11/06/01
159            * Andreas Kempf, Siemens ICM S CP PE, Munich
160            */
161 
162            customizationState.setAttribute ("customize-paneName", (String)p.getTitle());
163         }
164     }
165 
166     /***
167     * Get the psml profile being customized.
168     * @return the Profile being customized.
169     */
170     public Profile getCustomizedProfile()
171     {
172         // customization state info is in the page's session state
173         SessionState customizationState = getPageSessionState();
174 
175         return (Profile) customizationState.getAttribute("customize-profile");
176 
177     }   // getCustomizedProfile
178 
179     /***
180     * Set the psml profile being customized.
181     * @param profile The Profile being customized.
182     */
183     public void setCustomizedProfile(Profile profile)
184     {
185         // customization state info is in the page's session state
186         SessionState customizationState = getPageSessionState();
187 
188         customizationState.setAttribute("customize-profile", profile);
189 
190     }   // setCustomizedProfile
191 
192     /***
193     * Clean up from customization
194     */
195     public void cleanupFromCustomization()
196     {
197         // get the customization state for this page
198         SessionState customizationState = getPageSessionState();
199 
200         customizationState.removeAttribute("customize-stack");
201         customizationState.removeAttribute("customize-paneName");
202         customizationState.removeAttribute("customize-profile");
203         //customizationState.removeAttribute("customize-type");
204         customizationState.removeAttribute("customize-columns");
205         customizationState.removeAttribute("customize-mode");
206         customizationState.removeAttribute("customize-parameters");
207 
208        setMode("default");
209 
210     }   // cleanupFromCustomization
211 
212     /***
213      * Returns the portlet id which should be maximized for this request
214      *
215      * @return the portlet id being maximized or null
216      */
217     public int getMode()
218     {
219         return this.mode;
220     }
221 
222     /***
223      * Sets the portlet id to maximize
224      *
225      * @param id the portlet id to maximize or null;
226      */
227     public void setMode(int mode)
228     {
229         this.mode=mode;
230     }
231 
232     /***
233      * Sets the portlet id to maximize
234      *
235      * @param id the portlet id to maximize or null;
236      */
237     public void setMode(String mode)
238     {
239         if ("customize".equals(mode))
240         {
241             setMode(CUSTOMIZE);
242         }
243         else if ("maximize".equals(mode))
244         {
245             setMode(MAXIMIZE);
246         }
247         else
248         {
249             setMode(NORMAL);
250             setCustomized(null);
251         }
252     }
253 
254     /***
255      * Returns the template path as requested from the parameters
256      */
257     public String getRequestedTemplate()
258     {
259         return this.template;
260     }
261 
262     /***
263      * Sets the template path as requested from the parameters
264      */
265     public void setRequestedTemplate(String id)
266     {
267         this.template=id;
268     }
269 
270     /***
271      * Returns the capability map for the user agent issuing this request
272      *
273      * @return a capability map objet
274      */
275     public CapabilityMap getCapability()
276     {
277         if (map == null)
278         {
279             map = CapabilityMapFactory.getCapabilityMap(this);
280         }
281 
282         return map;
283     }
284 
285     /***
286      * Sets the user portal profile for the current request
287      *
288      * @param profile a profile implementation for the current request
289      */
290     public void setProfile(Profile profile)
291     {
292         this.profile = profile;
293     }
294 
295     /***
296      * Gets the user portal profile for the current request
297      *
298      * @return a profile implementation for the current request
299      */
300     public Profile getProfile()
301     {
302         return this.profile;
303     }
304 
305     /*** Clears the state of this object for recycling... */
306     public void dispose()
307     {
308         mode=0;
309         map = null;
310         peid = null;
311         pid = null;
312         profile = null;
313         template = null;
314 
315         super.dispose();
316     }
317 
318     /***
319      * Returns the portlet id (PEID) referenced in this request
320      *
321      * @return the portlet id (PEID) referenced or null
322      */
323     public String getJs_peid()
324     {
325         return peid;
326     }
327 
328     /***
329      * Sets the portlet id (PEID) referenced for this request
330      *
331      * @param id the portlet id (PEID) referenced in this request
332      */
333     public void setJs_peid(String peid)
334     {
335         this.peid = peid;
336     }
337 
338     /***
339      * Get the user id for the current user.
340      * This method is provided as an abstraction to the very implementation
341      * specific method of retrieving user ids in Turbine.
342      *
343      * @return int The current user's id.
344      */
345     public String getUserId()
346     {
347         JetspeedUser user = getJetspeedUser();
348         if (user == null)
349         {
350             return "";
351         }
352         return user.getUserId();
353     }
354 
355     /***
356      * Access an identifier for the current request's PageSession.
357      * A PageSession is a specific portal page being viewed in a specific
358      * user session (and perhaps, but not yet [@todo] in a specific browser window).
359      * @return the identifier for the current request's PageSession.
360      */
361     public String getPageSessionId()
362     {
363         // form based on the session and page's profile's id
364         // session
365         String sessionId = "?";
366         if (getSession() != null)
367         {
368             sessionId = getSession().getId();
369         }
370         else
371         {
372             logger.warn("DefaultJetspeedRunData.getPageSessionId: no session");
373         }
374 
375         // profile
376         String profileId = "?";
377         if (getProfile() != null)
378         {
379             profileId = getProfile().getId();
380         }
381         else
382         {
383             logger.warn("DefaultJetspeedRunData.getPageSessionId: no profile");
384         }
385 
386         return sessionId + profileId;
387 
388     }   // getPageSessionId
389 
390     /***
391      * Access the current request's UserSession state object.
392      * @return the current request's UserSession state object (may be null).
393      */
394     public SessionState getUserSessionState()
395     {
396         // get the StateManagerService
397         StateManagerService service = (StateManagerService)TurbineServices
398                 .getInstance().getService(StateManagerService.SERVICE_NAME);
399 
400         // handle no service
401         if (service == null) return null;
402 
403         return service.getSessionState(getSession().getId());
404 
405     }   // getUserSessionState
406 
407     /***
408      * Access the current request's PageSession state object.
409      * @return the current request's PageSession state object (may be null).
410      */
411     public SessionState getPageSessionState()
412     {
413         // get the StateManagerService
414         StateManagerService service = (StateManagerService)TurbineServices
415                 .getInstance().getService(StateManagerService.SERVICE_NAME);
416 
417         // handle no service
418         if (service == null) return null;
419 
420         return service.getSessionState(getPageSessionId());
421 
422     }   // getPageSessionState
423 
424     /***
425      * Access the current request's PortletSession state object.
426      * @param id The Portlet's unique id.
427      * @return the current request's PortletSession state object. (may be null).
428      */
429     public SessionState getPortletSessionState(String id)
430     {
431         // get the StateManagerService
432         StateManagerService service = (StateManagerService)TurbineServices
433                 .getInstance().getService(StateManagerService.SERVICE_NAME);
434 
435         // handle no service
436         if (service == null) return null;
437 
438         // PageSession key
439         String pageInstanceId = getPageSessionId();
440 
441         return service.getSessionState(pageInstanceId + id);
442 
443     }   // getPortletSessionState
444 
445     /***
446      * Returns the Jetspeed User (same as getUser without cast)
447      *
448      * @return the current user.
449      */
450     public JetspeedUser getJetspeedUser()
451     {
452         return (JetspeedUser)getUser();
453     }
454 
455     /***
456      * Function is deprecated by required to compile with Turbine
457      *
458      * @deprecated
459      */
460     public AccessControlList getACL()
461     {
462         return null;
463     }
464 }