KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > portal > portlets > AggregatePortlet


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.portal.portlets;
18
19 import org.apache.jetspeed.om.profile.ProfileLocator;
20 import org.apache.jetspeed.services.Profiler;
21 import org.apache.jetspeed.om.profile.Profile;
22 import org.apache.jetspeed.om.profile.PSMLDocument;
23 import org.apache.jetspeed.om.profile.Portlets;
24 import org.apache.jetspeed.services.PortalToolkit;
25 import org.apache.jetspeed.portal.PortletSet;
26 import org.apache.jetspeed.services.rundata.JetspeedRunData;
27 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
28 import org.apache.jetspeed.services.logging.JetspeedLogger;
29 import org.apache.jetspeed.util.JetspeedClearElement;
30
31 import org.apache.ecs.ConcreteElement;
32
33 import org.apache.turbine.util.RunData;
34
35 /**
36     Aggregate Portlet aggregates the content of other portlets.
37
38     This portlet is a test for an alternate aggregation algorithm (from getSet)
39
40     @author <A HREF="mailto:taylor@apache.org">David Sean Taylor</A>
41     @version $Id: AggregatePortlet.java,v 1.8 2004/02/23 04:03:34 jford Exp $
42 */

43
44 public class AggregatePortlet extends AbstractPortlet
45 {
46
47     /**
48      * Static initialization of the logger for this class
49      */

50     private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(AggregatePortlet.class.getName());
51     
52     /**
53     Returns an HTML representation of this portlet. Usually a Portlet would
54     initialized itself within init() and then when getContent is called it
55     would return its presentation.
56     */

57     public ConcreteElement getContent(RunData rundata)
58     {
59         String JavaDoc key = ((JetspeedRunData)rundata).getProfile().getId()
60                     + "." + this.getID();
61
62         String JavaDoc path = (String JavaDoc)rundata.getUser().getTemp(key);
63         if (path == null)
64         {
65             path = this.getPortletConfig().getInitParameter("path");
66         }
67
68         if (null == path)
69         {
70             return new JetspeedClearElement("Path parameter not set");
71         }
72         ProfileLocator locator = Profiler.createLocator();
73         locator.createFromPath(path);
74         String JavaDoc id = locator.getId();
75
76         try
77         {
78             Profile profile = Profiler.getProfile(locator);
79             PSMLDocument doc = profile.getDocument();
80
81             if (doc == null)
82             {
83                 return null;
84             }
85             Portlets portlets = doc.getPortlets();
86             PortletSet ps = PortalToolkit.getSet(portlets);
87             return ps.getContent(rundata);
88         }
89         catch (Exception JavaDoc e)
90         {
91             logger.error("Exception", e);
92             return new JetspeedClearElement("Error in aggregation portlet: " + e.toString());
93         }
94     }
95
96
97
98 }
99
Popular Tags