1 16 17 package org.apache.jetspeed.portal.portlets; 18 19 import org.apache.jetspeed.portal.Portlet; 20 import org.apache.jetspeed.portal.PortletException; 21 import org.apache.jetspeed.portal.PortletConfig; 22 import org.apache.jetspeed.om.profile.ProfileLocator; 23 import org.apache.jetspeed.services.Profiler; 24 import org.apache.jetspeed.om.profile.Profile; 25 import org.apache.jetspeed.om.profile.PSMLDocument; 26 import org.apache.jetspeed.om.profile.Portlets; 27 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 28 import org.apache.jetspeed.services.logging.JetspeedLogger; 29 import org.apache.jetspeed.services.rundata.JetspeedRunData; 30 import org.apache.jetspeed.services.persistence.PersistenceManager; 31 import org.apache.jetspeed.services.persistence.PortalPersistenceException; 32 import org.apache.jetspeed.portal.PortletInstance; 33 34 import org.apache.jetspeed.util.MimeType; 35 36 import org.apache.jetspeed.util.JetspeedClearElement; 37 import org.apache.ecs.ConcreteElement; 38 39 import org.apache.turbine.util.RunData; 40 41 51 52 public class ContainerTestPortlet implements Portlet 53 { 54 55 58 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(ContainerTestPortlet.class.getName()); 59 60 private String image = null; 61 62 private String name = "not set"; 63 64 private String title = "la title"; 65 66 private String description = "description"; 67 68 private String id = null; 69 70 private String handle = ""; 71 72 private PortletConfig pc = null; 73 74 75 79 81 84 private long creationTime; 85 86 90 public String getName() 91 { 92 return name; 93 } 94 95 100 public void setName(String name) 101 { 102 System.out.println("setting name = " + name); 103 this.name = name; 104 } 105 106 121 public String getTitle() 122 { 123 return this.title; 124 } 125 126 138 public String getTitle(String instanceTitle) 139 { 140 if (instanceTitle != null) 141 return instanceTitle; 142 return getTitle(); 143 } 144 145 146 149 public void setTitle( String title ) 150 { 151 this.title = title; 152 } 153 154 170 public String getDescription() 171 { 172 return description; 173 } 174 175 180 public String getDescription(String instanceDescription) 181 { 182 if (instanceDescription != null) 183 return instanceDescription; 184 return getDescription(); 185 } 186 187 190 public void setDescription( String description ) 191 { 192 this.description = description; 193 } 194 195 199 public String getImage() 200 { 201 return image; 202 } 203 204 208 public String getImage(String instanceImage) 209 { 210 if (instanceImage != null) 211 return instanceImage; 212 return getImage(); 213 } 214 215 public void setImage( String image ) 216 { 217 this.image = image; 218 } 219 220 225 public ConcreteElement getContent(RunData rundata) 226 { 227 String key = ((JetspeedRunData)rundata).getProfile().getId() 228 + "." + this.getID(); 229 230 String path = (String )rundata.getUser().getTemp(key); 231 if (path == null) 232 { 233 path = this.getPortletConfig().getInitParameter("path"); 234 } 235 236 if (null == path) 237 { 238 return new JetspeedClearElement("Path parameter not set"); 239 } 240 241 ProfileLocator locator = Profiler.createLocator(); 242 locator.createFromPath(path); 243 String id = locator.getId(); 244 245 try 246 { 247 Profile profile = Profiler.getProfile(locator); 248 PSMLDocument doc = profile.getDocument(); 249 if (doc == null) 250 { 251 return null; 252 } 253 Portlets portlets = doc.getPortlets(); 254 return new JetspeedClearElement("XXX Under Construction :)"); 256 } 257 catch (Exception e) 258 { 259 logger.error("Exception", e); 260 return new JetspeedClearElement("Error in aggregation portlet: " + e.toString()); 261 } 262 } 263 264 271 public void init() throws PortletException 272 { 273 String path = this.pc.getInitParameter("path"); 274 } 275 276 277 280 public void setPortletConfig(PortletConfig pc) 281 { 282 this.pc = pc; 283 } 284 285 286 289 public PortletConfig getPortletConfig() 290 { 291 return pc; 292 } 293 294 300 public boolean getAllowEdit( RunData rundata ) 301 { 302 return false; 303 } 304 305 311 public boolean getAllowMaximize( RunData rundata ) 312 { 313 return true; 314 } 315 316 319 public long getCreationTime() 320 { 321 322 return this.creationTime; 323 } 324 325 328 public void setCreationTime( long creationTime ) 329 { 330 System.out.println("setting creating time"); 331 this.creationTime = creationTime; 332 } 333 334 337 public boolean supportsType( MimeType mimeType ) 338 { 339 return true; 340 } 341 342 350 public String getAttribute( String attrName, String attrDefValue, RunData rundata ) 351 { 352 String attrValue = null ; 353 354 PortletInstance instance = PersistenceManager.getInstance(this, rundata); 355 attrValue = instance.getAttribute(attrName, attrDefValue); 356 357 return attrValue; 358 } 359 360 367 public void setAttribute( String attrName, String attrValue, RunData rundata ) 368 { 369 try 370 { 371 PortletInstance instance = PersistenceManager.getInstance(this, rundata); 372 instance.setAttribute(attrName, attrValue); 373 PersistenceManager.store(instance); 374 } 375 catch (PortalPersistenceException e) 376 { 377 logger.error("Exception while setting attribute "+attrName+" for portlet "+getName(),e); 378 } 379 } 380 381 386 public PortletInstance getInstance(RunData rundata) 387 { 388 return PersistenceManager.getInstance(this, rundata); 389 } 390 391 392 393 394 397 public String getID() 398 { 399 return "9"; 400 } 401 402 public void setID(String id) 403 { 404 this.id = id; 405 } 406 407 410 public boolean providesCustomization() 411 { 412 return false; 413 } 414 415 420 public boolean isShowTitleBar(RunData rundata) 421 { 422 return true; 423 } 424 425 433 public boolean getAllowView( RunData rundata ) 434 { 435 return true; 436 } 437 438 439 } 440 | Popular Tags |