1 package org.roller.presentation.planet; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 import java.util.ResourceBundle ; 6 7 import javax.servlet.http.HttpServletRequest ; 8 import javax.servlet.http.HttpServletResponse ; 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 29 public class PlanetAction extends Action 30 { 31 private static Log mLogger = 32 LogFactory.getFactory().getInstance(PlanetAction.class); 33 private static ResourceBundle bundle = 34 ResourceBundle.getBundle("ApplicationResources"); 35 36 39 public ActionForward execute( 40 ActionMapping mapping, ActionForm form, 41 HttpServletRequest req, HttpServletResponse res) 42 throws Exception 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 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 71 public static class PlanetPageData 72 { 73 private HttpServletRequest mRequest = null; 74 private String mTitle = 75 bundle.getString("planet.title.unconfigured"); 76 private String mDescription = 77 bundle.getString("planet.description.unconfigured"); 78 79 public String getTitle() {return mTitle;} 80 public String getDescription() {return mDescription;} 81 82 public PlanetPageData(HttpServletRequest 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 98 public List getAggregation(int num) throws RollerException 99 { 100 Roller roller = 101 RollerRequest.getRollerRequest(mRequest).getRoller(); 102 return roller.getPlanetManager().getAggregation(num); 103 } 104 107 public PlanetGroupData getGroup(String 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 125 public List getAggregation(String name, int num) throws RollerException 126 { 127 List ret = new ArrayList (); 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 144 public List getTopSubscriptions(int num) throws RollerException 145 { 146 List ret = new ArrayList (); 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 162 public List getTopSubscriptions(String name, int num) 163 throws RollerException 164 { 165 List ret = new ArrayList (); 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 182 public List 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 |