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.portal.portlets;
1819import org.apache.jetspeed.portal.Portlet;
20import org.apache.jetspeed.portal.PortletException;
21import org.apache.jetspeed.portal.PortletConfig;
22import org.apache.jetspeed.om.profile.ProfileLocator;
23import org.apache.jetspeed.services.Profiler;
24import org.apache.jetspeed.om.profile.Profile;
25import org.apache.jetspeed.om.profile.PSMLDocument;
26import org.apache.jetspeed.om.profile.Portlets;
27import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
28import org.apache.jetspeed.services.logging.JetspeedLogger;
29import org.apache.jetspeed.services.rundata.JetspeedRunData;
30import org.apache.jetspeed.services.persistence.PersistenceManager;
31import org.apache.jetspeed.services.persistence.PortalPersistenceException;
32import org.apache.jetspeed.portal.PortletInstance;
3334import org.apache.jetspeed.util.MimeType;
3536import org.apache.jetspeed.util.JetspeedClearElement;
37import org.apache.ecs.ConcreteElement;
3839import org.apache.turbine.util.RunData;
4041/***42 Aggregate Portlet aggregates the content of other portlets.4344 This portlet is a test for an alternate aggregation algorithm4546 UNDER CONSTRUCTION4748 @author <A HREF="mailto:taylor@apache.org">David Sean Taylor</A>49 @version $Id: ContainerTestPortlet.java,v 1.9 2004/03/29 21:38:42 taylor Exp $50*/5152publicclassContainerTestPortlet implements Portlet/* , PortletState, Cacheable, Refreshable */53 {
5455/***56 * Static initialization of the logger for this class57 */58privatestaticfinalJetspeedLogger logger = JetspeedLogFactoryService.getLogger(ContainerTestPortlet.class.getName());
5960private String image = null;
6162private String name = "not set";
6364private String title = "la title";
6566private String description = "description";
6768private String id = null;
6970private String handle = "";
7172privatePortletConfig pc = null;
737475/***76 Holds instances of ConcreteElements (Portlet output/content)77 based on its current CapabilityMap.78 */79// protected Hashtable content = new Hashtable();8081/***82 The time this portlet was created.83 */84privatelong creationTime;
8586/***87 Returns a name for this portlet. This is used by PSML to identify a Portlet88 within the PortletRegistry89 */90public String getName()
91 {
92return name;
93 }
9495/***96 Sets the name on this Portlet.9798 @see #getName()99 */100publicvoid setName(String name)
101 {
102 System.out.println("setting name = " + name);
103this.name = name;
104 }
105106/***107 <p>108 Allows a Portlet to define its title. This can be used by a PortletControl109 for rendering its content.110 </p>111112 <p>113 In order to define a default title you should not override this but should114 call setTitle() within your init() method115 </p>116117 <p>118 This should return null if not specified.119 </p>120 */121public String getTitle()
122 {
123returnthis.title;
124 }
125126/***127 * t a title for this instance of the portlet. This method is called128 * from the context variable portlet_instance and from PortletInstance129 *130 * If you wish to append to the title, then you code should look like131 * getTitle( String instanceTitle)132 * {133 * return super.getTitle( instanceTitle) + " - Appened title text";134 * }135 *136 * @param instanceTitle Title from PSML137 */138public String getTitle(String instanceTitle)
139 {
140if (instanceTitle != null)
141return instanceTitle;
142return getTitle();
143 }
144145146/***147 Set the title for this Portlet148 */149publicvoid setTitle( String title )
150 {
151this.title = title;
152 }
153154/***155 <p>156 Returns a description of this portlet. This should describe what the157 capabilities of the portlet and how it can help the user.158 </p>159160 <p>161 In order to define a default title you should not override (in the162 AbstractPortlet implementation) this but should call setDescription()163 within your init() method164 </p>165166 <p>167 This should return null if not specified.168 </p>169 */170public String getDescription()
171 {
172return description;
173 }
174175/***176 * Provide a Description within PML if the user has specified one.177 *178 * @return a null entry if the user hasn't defined anything179 */180public String getDescription(String instanceDescription)
181 {
182if (instanceDescription != null)
183return instanceDescription;
184return getDescription();
185 }
186187/***188 Set the description for this Portlet189 */190publicvoid setDescription( String description )
191 {
192this.description = description;
193 }
194195/***196 * Getter for property image.197 * @return Name of portlet image, icon. The name is expected to be in the form of a URL.198 */199public String getImage()
200 {
201return image;
202 }
203204/***205 * Getter for property image.206 * @return Name of portlet image, icon. The name is expected to be in the form of a URL.207 */208public String getImage(String instanceImage)
209 {
210if (instanceImage != null)
211return instanceImage;
212return getImage();
213 }
214215publicvoid setImage( String image )
216 {
217this.image = image;
218 }
219220/***221 Returns an HTML representation of this portlet. Usually a Portlet would222 initialized itself within init() and then when getContent is called it223 would return its presentation.224 */225public ConcreteElement getContent(RunData rundata)
226 {
227 String key = ((JetspeedRunData)rundata).getProfile().getId()
228 + "." + this.getID();
229230 String path = (String)rundata.getUser().getTemp(key);
231if (path == null)
232 {
233 path = this.getPortletConfig().getInitParameter("path");
234 }
235236if (null == path)
237 {
238returnnewJetspeedClearElement("Path parameter not set");
239 }
240241ProfileLocator locator = Profiler.createLocator();
242 locator.createFromPath(path);
243 String id = locator.getId();
244245try246 {
247Profile profile = Profiler.getProfile(locator);
248PSMLDocument doc = profile.getDocument();
249if (doc == null)
250 {
251returnnull;
252 }
253Portlets portlets = doc.getPortlets();
254//PortletContainer.aggregate(portlets);255returnnewJetspeedClearElement("XXX Under Construction :)");
256 }
257catch (Exception e)
258 {
259 logger.error("Exception", e);
260returnnewJetspeedClearElement("Error in aggregation portlet: " + e.toString());
261 }
262 }
263264/***265 All initialization should be performed here. If your Portlet wants to266 do any work it should be done here. You are not guaranteed that any267 particular order of method call will happen just that init() will happen268 first. Therefore if you have to calculate things like a title, a269 description, etc it should happen here.270 */271publicvoid init() throws PortletException
272 {
273 String path = this.pc.getInitParameter("path");
274 }
275276277/***278 Set's the configuration of this servlet.279 */280publicvoid setPortletConfig(PortletConfig pc)
281 {
282this.pc = pc;
283 }
284285286/***287 Get the config of this servlet.288 */289publicPortletConfig getPortletConfig()
290 {
291return pc;
292 }
293294/***295 <p>Return true if this portlet is allowed to be edited in the rundata's context .</p>296297 <p>Note: PortletControl implementations should pay attention to this so298 that they don't allow this option if it returns false.</p>299 */300publicboolean getAllowEdit( RunData rundata )
301 {
302return false;
303 }
304305/***306 <p>Return true if this portlets is allowed to be maximized.</p>307308 <p>Note: PortletControl implementations should pay attention to this so309 that they don't allow this option if it returns false.</p>310 */311publicboolean getAllowMaximize( RunData rundata )
312 {
313returntrue;
314 }
315316/***317 Get the creation time for this Portlet318 */319publiclong getCreationTime()
320 {
321322returnthis.creationTime;
323 }
324325/***326 Set the creation time for this Portlet327 */328publicvoid setCreationTime( long creationTime )
329 {
330 System.out.println("setting creating time");
331this.creationTime = creationTime;
332 }
333334/***335 Returns true portlet is able to output content for given mimetype336 */337publicboolean supportsType( MimeType mimeType )
338 {
339returntrue;
340 }
341342/***343 * Retrieve a portlet attribute from persistent storage344 *345 * @param attrName The attribute to retrieve346 * @param attrDefValue The value if the attr doesn't exists347 * @param rundata The RunData object for the current request348 * @return The attribute value349 */350public String getAttribute( String attrName, String attrDefValue, RunData rundata )
351 {
352 String attrValue = null ;
353354PortletInstance instance = PersistenceManager.getInstance(this, rundata);
355 attrValue = instance.getAttribute(attrName, attrDefValue);
356357return attrValue;
358 }
359360/***361 * Stores a portlet attribute in persistent storage362 *363 * @param attrName The attribute to retrieve364 * @paarm attrValue The value to store365 * @param rundata The RunData object for the current request366 */367publicvoid setAttribute( String attrName, String attrValue, RunData rundata )
368 {
369try370 {
371PortletInstance instance = PersistenceManager.getInstance(this, rundata);
372 instance.setAttribute(attrName, attrValue);
373 PersistenceManager.store(instance);
374 }
375catch (PortalPersistenceException e)
376 {
377 logger.error("Exception while setting attribute "+attrName+" for portlet "+getName(),e);
378 }
379 }
380381/***382 * Gets the portlet instance associated with this portlet.383 *384 * @return PortletInstance385 */386publicPortletInstance getInstance(RunData rundata)
387 {
388return PersistenceManager.getInstance(this, rundata);
389 }
390391392393394/***395 Retrieve a unique portlet id396 */397public String getID()
398 {
399return"9";
400 }
401402publicvoid setID(String id)
403 {
404this.id = id;
405 }
406407/***408 * @return true if the portlet does its own customization409 */410publicboolean providesCustomization()
411 {
412return false;
413 }
414415/*** Returns TRUE if the title bar in should be displayed. The title bar includes416 * the portlet title and action buttons. This417 *418 * @param rundata The RunData object for the current request419 */420publicboolean isShowTitleBar(RunData rundata)
421 {
422returntrue;
423 }
424425/***426 * Is the portled viewable.427 * @param rundata The RunData object for the current request428 * @return <CODE>true</CODE> Viewing is allow429 * <CODE>false</CODE> Viewing is NOT alowed430 * 431 * Override this method to control your own View behavior432 */433publicboolean getAllowView( RunData rundata )
434 {
435returntrue;
436 }
437438439 }