1 18 19 package org.apache.roller.ui.rendering.model; 20 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 import java.util.Map ; 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 import org.apache.roller.RollerException; 28 import org.apache.roller.model.PlanetManager; 29 import org.apache.roller.model.Roller; 30 import org.apache.roller.model.RollerFactory; 31 import org.apache.roller.pojos.PlanetSubscriptionData; 32 import org.apache.roller.pojos.Template; 33 import org.apache.roller.pojos.WebsiteData; 34 import org.apache.roller.pojos.wrapper.PlanetSubscriptionDataWrapper; 35 import org.apache.roller.ui.rendering.pagers.Pager; 36 import org.apache.roller.ui.rendering.pagers.PlanetEntriesPager; 37 import org.apache.roller.ui.rendering.util.WeblogPageRequest; 38 import org.apache.roller.ui.rendering.util.WeblogRequest; 39 import org.apache.roller.util.URLUtilities; 40 41 42 45 public class PlanetModel implements Model { 46 47 private static Log log = LogFactory.getLog(PlanetModel.class); 48 49 private WeblogRequest weblogRequest = null; 50 private String pageLink = null; 51 private int pageNum = 0; 52 private WebsiteData weblog = null; 53 54 55 public String getModelName() { 56 return "planet"; 57 } 58 59 public void init(Map initData) throws RollerException { 60 61 this.weblogRequest = (WeblogRequest) initData.get("weblogRequest"); 63 if(this.weblogRequest == null) { 64 throw new RollerException("expected weblogRequest from init data"); 65 } 66 67 if (weblogRequest instanceof WeblogPageRequest) { 68 Template weblogPage = ((WeblogPageRequest)weblogRequest).getWeblogPage(); 69 pageLink = (weblogPage != null) ? weblogPage.getLink() : null; 70 pageNum = ((WeblogPageRequest)weblogRequest).getPageNum(); 71 } 72 73 weblog = weblogRequest.getWeblog(); 75 } 76 77 78 84 public Pager getAggregationPager(int sinceDays, int length) { 85 86 String pagerUrl = URLUtilities.getWeblogPageURL(weblog, 87 weblogRequest.getLocale(), pageLink, 88 null, null, null, 0, false); 89 90 return new PlanetEntriesPager( 91 null, 92 null, 93 pagerUrl, 94 weblogRequest.getLocale(), 95 sinceDays, 96 pageNum, 97 length); 98 } 99 100 101 107 public Pager getAggregationPager(String groupHandle, int sinceDays, int length) { 108 109 String pagerUrl = URLUtilities.getWeblogPageURL(weblog, 110 weblogRequest.getLocale(), pageLink, 111 null, null, null, 0, false); 112 113 return new PlanetEntriesPager( 114 null, 115 groupHandle, 116 pagerUrl, 117 weblogRequest.getLocale(), 118 sinceDays, 119 pageNum, 120 length); 121 } 122 123 124 130 public Pager getFeedPager(String feedURL, int length) { 131 132 String pagerUrl = URLUtilities.getWeblogPageURL(weblog, 133 weblogRequest.getLocale(), pageLink, 134 null, null, null, 0, false); 135 136 return new PlanetEntriesPager( 137 feedURL, 138 null, 139 pagerUrl, 140 weblogRequest.getLocale(), 141 -1, 142 pageNum, 143 length); 144 } 145 146 147 153 public List getRankedSubscriptions(int sinceDays, int length) { 154 return getRankedSubscriptions(null, sinceDays, length); 155 } 156 157 158 165 public List getRankedSubscriptions(String groupHandle, int sinceDays, int length) { 166 List list = new ArrayList (); 167 try { 168 Roller roller = RollerFactory.getRoller(); 169 PlanetManager planetManager = roller.getPlanetManager(); 170 List subs = planetManager.getTopSubscriptions(groupHandle, 0, length); 171 for (Iterator it = subs.iterator(); it.hasNext();) { 172 PlanetSubscriptionData sub = (PlanetSubscriptionData) it.next(); 173 list.add(PlanetSubscriptionDataWrapper.wrap(sub)); 174 } 175 } catch (Exception e) { 176 log.error("ERROR: get ranked blogs", e); 177 } 178 return list; 179 } 180 181 } 182 | Popular Tags |