KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > presentation > planet > PlanetAction


1 package org.roller.presentation.planet;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5 import java.util.ResourceBundle JavaDoc;
6
7 import javax.servlet.http.HttpServletRequest JavaDoc;
8 import javax.servlet.http.HttpServletResponse JavaDoc;
9
10 import org.apache.commons.logging.Log;
11 import org.apache.commons.logging.LogFactory;
12 import org.apache.struts.action.Action;
13 import org.apache.struts.action.ActionForm;
14 import org.apache.struts.action.ActionForward;
15 import org.apache.struts.action.ActionMapping;
16 import org.roller.RollerException;
17 import org.roller.config.RollerRuntimeConfig;
18 import org.roller.model.Roller;
19 import org.roller.pojos.PlanetConfigData;
20 import org.roller.pojos.PlanetGroupData;
21 import org.roller.presentation.RollerContext;
22 import org.roller.presentation.RollerRequest;
23
24 /**
25  * Main page action for Roller Planet.
26  * @struts.action name="main" path="/planet" scope="request"
27  * @struts.action-forward name="planet.page" path="/planet.jsp"
28  */

29 public class PlanetAction extends Action
30 {
31     private static Log mLogger =
32         LogFactory.getFactory().getInstance(PlanetAction.class);
33     private static ResourceBundle JavaDoc bundle =
34         ResourceBundle.getBundle("ApplicationResources");
35     
36     /**
37      * Loads model and forwards to planet.page.
38          */

39     public ActionForward execute(
40         ActionMapping mapping, ActionForm form,
41         HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res)
42         throws Exception JavaDoc
43     {
44         RollerContext rctx = RollerContext.getRollerContext(req);
45         req.setAttribute("version",rctx.getRollerVersion());
46         req.setAttribute("buildTime",rctx.getRollerBuildTime());
47         req.setAttribute("baseURL", rctx.getContextUrl(req));
48         req.setAttribute("data", new PlanetPageData(req));
49         
50         boolean allowNewUsers =
51            RollerRuntimeConfig.getBooleanProperty("users.registration.enabled");
52
53         java.security.Principal JavaDoc prince = req.getUserPrincipal();
54         if (prince != null)
55         {
56             req.setAttribute("loggedIn",Boolean.TRUE);
57             req.setAttribute("userName",prince.getName());
58         }
59         else if (allowNewUsers)
60         {
61             req.setAttribute("allowNewUsers",Boolean.TRUE);
62         }
63         req.setAttribute("leftPage","/theme/status.jsp");
64         
65         return mapping.findForward("planet.page");
66     }
67         
68     /**
69      * Page model.
70      */

71     public static class PlanetPageData
72     {
73         private HttpServletRequest JavaDoc mRequest = null;
74         private String JavaDoc mTitle =
75                 bundle.getString("planet.title.unconfigured");
76         private String JavaDoc mDescription =
77                 bundle.getString("planet.description.unconfigured");
78         
79         public String JavaDoc getTitle() {return mTitle;}
80         public String JavaDoc getDescription() {return mDescription;}
81         
82         public PlanetPageData(HttpServletRequest JavaDoc req) throws RollerException
83         {
84            mRequest = req;
85            Roller roller =
86            RollerRequest.getRollerRequest(mRequest).getRoller();
87            PlanetConfigData cfg = roller.getPlanetManager().getConfiguration();
88            if (cfg != null)
89            {
90                mTitle = cfg.getTitle();
91                mDescription = cfg.getDescription();
92            }
93         }
94         
95         /**
96          * Get aggregation of entries in 'all' and 'external' groups
97          */

98         public List JavaDoc getAggregation(int num) throws RollerException
99         {
100             Roller roller =
101                 RollerRequest.getRollerRequest(mRequest).getRoller();
102             return roller.getPlanetManager().getAggregation(num);
103         }
104         /**
105          * Get named group
106          */

107         public PlanetGroupData getGroup(String JavaDoc name) throws RollerException
108         {
109             PlanetGroupData group = null;
110             try
111             {
112                 Roller roller =
113                     RollerRequest.getRollerRequest(mRequest).getRoller();
114                 group = roller.getPlanetManager().getGroup(name);
115             }
116             catch (RollerException e)
117             {
118                 mLogger.error(e);
119             }
120             return group;
121         }
122         /**
123          * Get aggregation of entries in named group
124          */

125         public List JavaDoc getAggregation(String JavaDoc name, int num) throws RollerException
126         {
127             List JavaDoc ret = new ArrayList JavaDoc();
128             try
129             {
130                 Roller roller =
131                     RollerRequest.getRollerRequest(mRequest).getRoller();
132                 PlanetGroupData group= roller.getPlanetManager().getGroup(name);
133                 ret = roller.getPlanetManager().getAggregation(group, num);
134             }
135             catch (RollerException e)
136             {
137                 mLogger.error(e);
138             }
139             return ret;
140         }
141         /**
142          * Get top blogs according to Technorati
143          */

144         public List JavaDoc getTopSubscriptions(int num) throws RollerException
145         {
146             List JavaDoc ret = new ArrayList JavaDoc();
147             try
148             {
149                 Roller roller =
150                     RollerRequest.getRollerRequest(mRequest).getRoller();
151                 ret = roller.getPlanetManager().getTopSubscriptions(num);
152             }
153             catch (RollerException e)
154             {
155                 mLogger.error(e);
156             }
157             return ret;
158         }
159         /**
160          * Get top blogs in a group according to Technorati
161          */

162         public List JavaDoc getTopSubscriptions(String JavaDoc name, int num)
163         throws RollerException
164         {
165             List JavaDoc ret = new ArrayList JavaDoc();
166             try
167             {
168                 Roller roller =
169                     RollerRequest.getRollerRequest(mRequest).getRoller();
170                 PlanetGroupData group= roller.getPlanetManager().getGroup(name);
171                 ret = roller.getPlanetManager().getTopSubscriptions(group,num);
172             }
173             catch (RollerException e)
174             {
175                 mLogger.error(e);
176             }
177             return ret;
178         }
179         /**
180          * Get list of most popular websites in terms of day hits.
181          */

182         public List JavaDoc getPopularWebsites(int num) throws RollerException
183         {
184             Roller roller =
185                 RollerRequest.getRollerRequest(mRequest).getRoller();
186             return roller.getRefererManager().getDaysPopularWebsites(num);
187         }
188     }
189 }
190
191
Popular Tags