1 16 17 package org.apache.jetspeed.services.rundata; 18 19 import java.util.Stack ; 21 22 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 48 public class DefaultJetspeedRunData extends DefaultTurbineRunData 49 implements JetspeedRunData 50 { 51 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 68 public String getPortlet() 69 { 70 return pid; 71 } 72 73 78 public void setPortlet(String id) 79 { 80 this.pid = id; 81 } 82 83 88 public Portlet getCustomized() 89 { 90 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 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 120 public void setCustomized(Portlet p) 121 { 122 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 } 148 else 149 stack.push(p); 150 } 151 else 152 stack.push(p); 153 154 155 161 162 customizationState.setAttribute ("customize-paneName", (String )p.getTitle()); 163 } 164 } 165 166 170 public Profile getCustomizedProfile() 171 { 172 SessionState customizationState = getPageSessionState(); 174 175 return (Profile) customizationState.getAttribute("customize-profile"); 176 177 } 179 183 public void setCustomizedProfile(Profile profile) 184 { 185 SessionState customizationState = getPageSessionState(); 187 188 customizationState.setAttribute("customize-profile", profile); 189 190 } 192 195 public void cleanupFromCustomization() 196 { 197 SessionState customizationState = getPageSessionState(); 199 200 customizationState.removeAttribute("customize-stack"); 201 customizationState.removeAttribute("customize-paneName"); 202 customizationState.removeAttribute("customize-profile"); 203 customizationState.removeAttribute("customize-columns"); 205 customizationState.removeAttribute("customize-mode"); 206 customizationState.removeAttribute("customize-parameters"); 207 208 setMode("default"); 209 210 } 212 217 public int getMode() 218 { 219 return this.mode; 220 } 221 222 227 public void setMode(int mode) 228 { 229 this.mode=mode; 230 } 231 232 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 257 public String getRequestedTemplate() 258 { 259 return this.template; 260 } 261 262 265 public void setRequestedTemplate(String id) 266 { 267 this.template=id; 268 } 269 270 275 public CapabilityMap getCapability() 276 { 277 if (map == null) 278 { 279 map = CapabilityMapFactory.getCapabilityMap(this); 280 } 281 282 return map; 283 } 284 285 290 public void setProfile(Profile profile) 291 { 292 this.profile = profile; 293 } 294 295 300 public Profile getProfile() 301 { 302 return this.profile; 303 } 304 305 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 323 public String getJs_peid() 324 { 325 return peid; 326 } 327 328 333 public void setJs_peid(String peid) 334 { 335 this.peid = peid; 336 } 337 338 345 public String getUserId() 346 { 347 JetspeedUser user = getJetspeedUser(); 348 if (user == null) 349 { 350 return ""; 351 } 352 return user.getUserId(); 353 } 354 355 361 public String getPageSessionId() 362 { 363 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 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 } 390 394 public SessionState getUserSessionState() 395 { 396 StateManagerService service = (StateManagerService)TurbineServices 398 .getInstance().getService(StateManagerService.SERVICE_NAME); 399 400 if (service == null) return null; 402 403 return service.getSessionState(getSession().getId()); 404 405 } 407 411 public SessionState getPageSessionState() 412 { 413 StateManagerService service = (StateManagerService)TurbineServices 415 .getInstance().getService(StateManagerService.SERVICE_NAME); 416 417 if (service == null) return null; 419 420 return service.getSessionState(getPageSessionId()); 421 422 } 424 429 public SessionState getPortletSessionState(String id) 430 { 431 StateManagerService service = (StateManagerService)TurbineServices 433 .getInstance().getService(StateManagerService.SERVICE_NAME); 434 435 if (service == null) return null; 437 438 String pageInstanceId = getPageSessionId(); 440 441 return service.getSessionState(pageInstanceId + id); 442 443 } 445 450 public JetspeedUser getJetspeedUser() 451 { 452 return (JetspeedUser)getUser(); 453 } 454 455 460 public AccessControlList getACL() 461 { 462 return null; 463 } 464 } 465 | Popular Tags |