1 18 19 package org.apache.roller.ui.rendering.model; 20 21 import java.util.ArrayList ; 22 import java.util.Date ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 import java.util.Map ; 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 import org.apache.roller.RollerException; 29 import org.apache.roller.config.RollerRuntimeConfig; 30 import org.apache.roller.model.Roller; 31 import org.apache.roller.model.RollerFactory; 32 import org.apache.roller.model.WeblogManager; 33 import org.apache.roller.pojos.CommentData; 34 import org.apache.roller.pojos.WeblogEntryData; 35 import org.apache.roller.pojos.WebsiteData; 36 import org.apache.roller.pojos.wrapper.CommentDataWrapper; 37 import org.apache.roller.pojos.wrapper.WeblogEntryDataWrapper; 38 import org.apache.roller.pojos.wrapper.WebsiteDataWrapper; 39 import org.apache.roller.ui.rendering.util.WeblogFeedRequest; 40 import org.apache.roller.ui.rendering.util.WeblogRequest; 41 42 43 46 public class FeedModel implements Model { 47 48 private static Log log = LogFactory.getLog(FeedModel.class); 49 50 private WeblogFeedRequest feedRequest = null; 51 private WebsiteData weblog = null; 52 53 54 public void init(Map initData) throws RollerException { 55 56 WeblogRequest weblogRequest = (WeblogRequest) initData.get("weblogRequest"); 58 if(weblogRequest == null) { 59 throw new RollerException("expected weblogRequest from init data"); 60 } 61 62 if(weblogRequest instanceof WeblogFeedRequest) { 65 this.feedRequest = (WeblogFeedRequest) weblogRequest; 66 } else { 67 throw new RollerException("weblogRequest is not a WeblogFeedRequest."+ 68 " FeedModel only supports feed requests."); 69 } 70 71 weblog = feedRequest.getWeblog(); 73 } 74 75 76 77 public String getModelName() { 78 return "model"; 79 } 80 81 82 85 public String getLocale() { 86 return feedRequest.getLocale(); 87 } 88 89 90 93 public WebsiteDataWrapper getWeblog() { 94 return WebsiteDataWrapper.wrap(weblog); 95 } 96 97 98 101 public boolean getExcerpts() { 102 return feedRequest.isExcerpts(); 103 } 104 105 106 109 public String getCategoryPath() { 110 return feedRequest.getWeblogCategoryName(); 111 } 112 113 114 118 public List getWeblogEntries() { 119 120 int entryCount = 122 RollerRuntimeConfig.getIntProperty("site.newsfeeds.defaultEntries"); 123 124 List results = new ArrayList (); 125 try { 126 Roller roller = RollerFactory.getRoller(); 127 WeblogManager wmgr = roller.getWeblogManager(); 128 List entries = wmgr.getWeblogEntries( 129 weblog, 130 null, 131 null, 132 new Date (), 133 feedRequest.getWeblogCategoryName(), 134 WeblogEntryData.PUBLISHED, 135 "pubTime", 136 feedRequest.getLocale(), 137 0, 138 entryCount); 139 for (Iterator it = entries.iterator(); it.hasNext();) { 140 WeblogEntryData entry = (WeblogEntryData) it.next(); 141 results.add(WeblogEntryDataWrapper.wrap(entry)); 142 } 143 } catch (Exception e) { 144 log.error("ERROR: fetching weblog list", e); 145 } 146 return results; 147 } 148 149 150 154 public List getComments() { 155 156 int entryCount = 158 RollerRuntimeConfig.getIntProperty("site.newsfeeds.defaultEntries"); 159 160 List recentComments = new ArrayList (); 161 try { 162 WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager(); 163 List recent = wmgr.getComments( 164 RollerRuntimeConfig.isSiteWideWeblog(weblog.getHandle()) ? null : weblog, 165 null, null, null, new Date (), null, Boolean.TRUE, Boolean.FALSE, true, 0, entryCount); 176 recentComments = new ArrayList (recent.size()); 178 Iterator it = recent.iterator(); 179 while(it.hasNext()) { 180 recentComments.add(CommentDataWrapper.wrap((CommentData) it.next())); 181 } 182 } catch (RollerException e) { 183 log.error("ERROR: getting comments", e); 184 } 185 return recentComments; 186 } 187 188 } 189 | Popular Tags |