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.services.rundata;
1819// Java classes20import java.util.Stack;
2122// Jetspeed classes23import org.apache.jetspeed.om.security.JetspeedUser;
24import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
25import org.apache.jetspeed.services.logging.JetspeedLogger;
26import org.apache.jetspeed.portal.Portlet;
27import org.apache.jetspeed.om.profile.Profile;
28import org.apache.jetspeed.capability.CapabilityMap;
29import org.apache.jetspeed.capability.CapabilityMapFactory;
30import org.apache.jetspeed.services.statemanager.SessionState;
31import org.apache.jetspeed.services.statemanager.StateManagerService;
32import org.apache.turbine.services.rundata.DefaultTurbineRunData;
33import org.apache.turbine.services.TurbineServices;
34import org.apache.turbine.util.security.AccessControlList;
3536/***37 * This interface extends the RunData interface with methods38 * specific to the needs of a Jetspeed like portal implementation.39 *40 * <note>Several of these properties may be put in the base RunData41 * 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 */48publicclassDefaultJetspeedRunDataextends DefaultTurbineRunData
49 implements JetspeedRunData50 {
51/***52 * Static initialization of the logger for this class53 */54privatestaticfinalJetspeedLogger logger = JetspeedLogFactoryService.getLogger(DefaultJetspeedRunData.class.getName());
5556privateProfile profile = null;
57privateCapabilityMap map = null;
58private String peid = null;
59private String pid = null;
60privateint mode = NORMAL;
61private String template = null;
6263/***64 * Returns the portlet id referenced in this request65 *66 * @return the portlet id referenced or null67 */68public String getPortlet()
69 {
70return pid;
71 }
7273/***74 * Sets the portlet id referenced for this request75 *76 * @param id the portlet id referenced in this request77 */78publicvoid setPortlet(String id)
79 {
80this.pid = id;
81 }
8283/***84 * Returns the portlet id which should be customized for this request85 *86 * @return the portlet id being customized or null87 */88publicPortlet getCustomized()
89 {
90// customization state info is in the page's session state91SessionState customizationState = getPageSessionState();
92 Stack stack = (Stack)customizationState.getAttribute("customize-stack");
9394Portlet p = null;
9596if ((stack!=null)&&(!stack.empty()))
97 {
98 p = (Portlet)stack.peek();
99 }
100101/***102 * Save the title of this currently selected portlet103 * --------------------------------------------------------------------------104 * last modified: 11/06/01105 * Andreas Kempf, Siemens ICM S CP PE, Munich106 */107if ((p != null) && (stack.size() > 1))
108 customizationState.setAttribute ("customize-paneName", (String)p.getTitle());
109else110 customizationState.setAttribute ("customize-paneName", "*");
111112return (Portlet)p;
113 }
114115/***116 * Sets the portlet id to customize117 *118 * @param id the portlet id to customize or null;119 */120publicvoid setCustomized(Portlet p)
121 {
122// customization state info is in the page's session state123SessionState customizationState = getPageSessionState();
124 Stack stack = (Stack)customizationState.getAttribute("customize-stack");
125if (stack == null)
126 {
127 stack = new Stack();
128 customizationState.setAttribute("customize-stack", stack);
129 }
130131if (p==null)
132 {
133if (!stack.empty()) stack.pop();
134135 customizationState.setAttribute ("customize-paneName", "*");
136 }
137else138 {
139if (stack.size () > 0)
140 {
141Portlet last = (Portlet)stack.peek();
142143144if ((last!=null) && (p.getName().equals(last.getName())) && (p.getTitle().equals(last.getTitle())))
145 {
146//System.out.println ("Portlet already used!!!");147 }
148else149 stack.push(p);
150 }
151else152 stack.push(p);
153154155/***156 * Save the title of this currently selected portlet157 * --------------------------------------------------------------------------158 * last modified: 11/06/01159 * Andreas Kempf, Siemens ICM S CP PE, Munich160 */161162 customizationState.setAttribute ("customize-paneName", (String)p.getTitle());
163 }
164 }
165166/***167 * Get the psml profile being customized.168 * @return the Profile being customized.169 */170publicProfile getCustomizedProfile()
171 {
172// customization state info is in the page's session state173SessionState customizationState = getPageSessionState();
174175return (Profile) customizationState.getAttribute("customize-profile");
176177 } // getCustomizedProfile178179/***180 * Set the psml profile being customized.181 * @param profile The Profile being customized.182 */183publicvoid setCustomizedProfile(Profile profile)
184 {
185// customization state info is in the page's session state186SessionState customizationState = getPageSessionState();
187188 customizationState.setAttribute("customize-profile", profile);
189190 } // setCustomizedProfile191192/***193 * Clean up from customization194 */195publicvoid cleanupFromCustomization()
196 {
197// get the customization state for this page198SessionState customizationState = getPageSessionState();
199200 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");
207208 setMode("default");
209210 } // cleanupFromCustomization211212/***213 * Returns the portlet id which should be maximized for this request214 *215 * @return the portlet id being maximized or null216 */217publicint getMode()
218 {
219returnthis.mode;
220 }
221222/***223 * Sets the portlet id to maximize224 *225 * @param id the portlet id to maximize or null;226 */227publicvoid setMode(int mode)
228 {
229this.mode=mode;
230 }
231232/***233 * Sets the portlet id to maximize234 *235 * @param id the portlet id to maximize or null;236 */237publicvoid setMode(String mode)
238 {
239if ("customize".equals(mode))
240 {
241 setMode(CUSTOMIZE);
242 }
243elseif ("maximize".equals(mode))
244 {
245 setMode(MAXIMIZE);
246 }
247else248 {
249 setMode(NORMAL);
250 setCustomized(null);
251 }
252 }
253254/***255 * Returns the template path as requested from the parameters256 */257public String getRequestedTemplate()
258 {
259returnthis.template;
260 }
261262/***263 * Sets the template path as requested from the parameters264 */265publicvoid setRequestedTemplate(String id)
266 {
267this.template=id;
268 }
269270/***271 * Returns the capability map for the user agent issuing this request272 *273 * @return a capability map objet274 */275publicCapabilityMap getCapability()
276 {
277if (map == null)
278 {
279 map = CapabilityMapFactory.getCapabilityMap(this);
280 }
281282return map;
283 }
284285/***286 * Sets the user portal profile for the current request287 *288 * @param profile a profile implementation for the current request289 */290publicvoid setProfile(Profile profile)
291 {
292this.profile = profile;
293 }
294295/***296 * Gets the user portal profile for the current request297 *298 * @return a profile implementation for the current request299 */300publicProfile getProfile()
301 {
302returnthis.profile;
303 }
304305/*** Clears the state of this object for recycling... */306publicvoid dispose()
307 {
308 mode=0;
309 map = null;
310 peid = null;
311 pid = null;
312 profile = null;
313 template = null;
314315super.dispose();
316 }
317318/***319 * Returns the portlet id (PEID) referenced in this request320 *321 * @return the portlet id (PEID) referenced or null322 */323public String getJs_peid()
324 {
325return peid;
326 }
327328/***329 * Sets the portlet id (PEID) referenced for this request330 *331 * @param id the portlet id (PEID) referenced in this request332 */333publicvoid setJs_peid(String peid)
334 {
335this.peid = peid;
336 }
337338/***339 * Get the user id for the current user.340 * This method is provided as an abstraction to the very implementation341 * specific method of retrieving user ids in Turbine.342 *343 * @return int The current user's id.344 */345public String getUserId()
346 {
347JetspeedUser user = getJetspeedUser();
348if (user == null)
349 {
350return"";
351 }
352return user.getUserId();
353 }
354355/***356 * Access an identifier for the current request's PageSession.357 * A PageSession is a specific portal page being viewed in a specific358 * user session (and perhaps, but not yet [@todo] in a specific browser window).359 * @return the identifier for the current request's PageSession.360 */361public String getPageSessionId()
362 {
363// form based on the session and page's profile's id364// session365 String sessionId = "?";
366if (getSession() != null)
367 {
368 sessionId = getSession().getId();
369 }
370else371 {
372 logger.warn("DefaultJetspeedRunData.getPageSessionId: no session");
373 }
374375// profile376 String profileId = "?";
377if (getProfile() != null)
378 {
379 profileId = getProfile().getId();
380 }
381else382 {
383 logger.warn("DefaultJetspeedRunData.getPageSessionId: no profile");
384 }
385386return sessionId + profileId;
387388 } // getPageSessionId389390/***391 * Access the current request's UserSession state object.392 * @return the current request's UserSession state object (may be null).393 */394publicSessionState getUserSessionState()
395 {
396// get the StateManagerService397StateManagerService service = (StateManagerService)TurbineServices
398 .getInstance().getService(StateManagerService.SERVICE_NAME);
399400// handle no service401if (service == null) returnnull;
402403return service.getSessionState(getSession().getId());
404405 } // getUserSessionState406407/***408 * Access the current request's PageSession state object.409 * @return the current request's PageSession state object (may be null).410 */411publicSessionState getPageSessionState()
412 {
413// get the StateManagerService414StateManagerService service = (StateManagerService)TurbineServices
415 .getInstance().getService(StateManagerService.SERVICE_NAME);
416417// handle no service418if (service == null) returnnull;
419420return service.getSessionState(getPageSessionId());
421422 } // getPageSessionState423424/***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 */429publicSessionState getPortletSessionState(String id)
430 {
431// get the StateManagerService432StateManagerService service = (StateManagerService)TurbineServices
433 .getInstance().getService(StateManagerService.SERVICE_NAME);
434435// handle no service436if (service == null) returnnull;
437438// PageSession key439 String pageInstanceId = getPageSessionId();
440441return service.getSessionState(pageInstanceId + id);
442443 } // getPortletSessionState444445/***446 * Returns the Jetspeed User (same as getUser without cast)447 *448 * @return the current user.449 */450publicJetspeedUser getJetspeedUser()
451 {
452return (JetspeedUser)getUser();
453 }
454455/***456 * Function is deprecated by required to compile with Turbine457 *458 * @deprecated459 */460public AccessControlList getACL()
461 {
462returnnull;
463 }
464 }