1 18 19 package org.apache.roller.ui.authoring.struts.actions; 20 21 import java.io.IOException ; 22 import java.text.DateFormat ; 23 import java.text.ParseException ; 24 import java.util.Date ; 25 import java.util.List ; 26 27 import javax.servlet.ServletException ; 28 import javax.servlet.http.HttpServletRequest ; 29 import javax.servlet.http.HttpServletResponse ; 30 31 import org.apache.struts.action.ActionForm; 32 import org.apache.struts.action.ActionForward; 33 import org.apache.struts.action.ActionMapping; 34 import org.apache.struts.actions.DispatchAction; 35 import org.apache.roller.RollerException; 36 import org.apache.roller.model.RollerFactory; 37 import org.apache.roller.model.WeblogManager; 38 import org.apache.roller.pojos.WeblogCategoryData; 39 import org.apache.roller.pojos.WeblogEntryData; 40 import org.apache.roller.pojos.WebsiteData; 41 import org.apache.roller.ui.core.BasePageModel; 42 import org.apache.roller.ui.core.RollerRequest; 43 import org.apache.roller.ui.core.RollerSession; 44 import org.apache.roller.ui.authoring.struts.formbeans.WeblogEntryManagementForm; 45 import org.apache.roller.util.DateUtil; 46 47 48 59 public final class WeblogEntryManagementAction extends DispatchAction 60 { 61 67 public ActionForward query( 68 ActionMapping mapping, 69 ActionForm actionForm, 70 HttpServletRequest request, 71 HttpServletResponse response) 72 throws IOException , ServletException , RollerException 73 { 74 WeblogEntryManagementForm form = (WeblogEntryManagementForm)actionForm; 75 RollerRequest rreq = RollerRequest.getRollerRequest(request); 76 WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager(); 77 RollerSession rses = RollerSession.getRollerSession(request); 78 79 if (rreq.getWebsite() != null && rses.isUserAuthorized(rreq.getWebsite())) { 81 String status= form.getStatus().equals("ALL") ? null : form.getStatus(); 82 request.setAttribute("model", new PageModel( 83 request, 84 response, 85 mapping, 86 rreq.getWebsite(), 87 form)); 88 } 89 else 90 { 91 return mapping.findForward("access-denied"); 92 } 93 return mapping.findForward("weblogEntryManagement.page"); 94 } 95 96 public class PageModel extends BasePageModel { 97 private List entries = null; 98 private RollerRequest rollerRequest = null; 99 private HttpServletRequest request = null; 100 private WebsiteData website = null; 101 private String category = null; 102 private Date startDate = null; 103 private Date endDate = null; 104 private String status = WeblogEntryData.PUBLISHED; 105 private Integer maxEntries = null; 106 private boolean more = false; 107 private WeblogEntryManagementForm queryForm = null; 108 109 public PageModel( 110 HttpServletRequest request, 111 HttpServletResponse response, 112 ActionMapping mapping, 113 WebsiteData website, 114 WeblogEntryManagementForm queryForm) throws RollerException { 115 super("weblogEntryQuery.title", request, response, mapping); 116 rollerRequest = RollerRequest.getRollerRequest(request); 117 this.request = request; 118 this.queryForm = queryForm; 119 this.website = website; 120 121 if (null != queryForm.getCategoryId() && !queryForm.getCategoryId().equals("")) { 122 WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager(); 123 WeblogCategoryData cd = wmgr.getWeblogCategory(queryForm.getCategoryId()); 124 category = cd.getPath(); 125 } 126 127 final DateFormat df = 128 DateFormat.getDateInstance(DateFormat.SHORT, request.getLocale()); 129 String start = queryForm.getStartDateString(); 130 if (null != start && start.trim().length() > 0) { 131 try { 132 startDate = DateUtil.getStartOfDay(df.parse(start)); 133 } catch (ParseException e) { 134 throw new RollerException("ERROR parsing start date."); 135 } 136 } 137 138 String end = queryForm.getEndDateString(); 139 if (null != end && end.trim().length() > 0) { 140 try { 141 endDate = DateUtil.getEndOfDay(df.parse(end)); 142 } catch (ParseException e) { 143 throw new RollerException("ERROR parsing end date."); 144 } 145 } 146 147 this.status = "ALL".equals(queryForm.getStatus()) ? null: queryForm.getStatus(); 148 this.maxEntries = maxEntries; 149 150 entries = RollerFactory.getRoller().getWeblogManager().getWeblogEntries( 151 website, 152 null, 153 startDate, 154 endDate, 155 category, 156 status, 157 queryForm.getSortby(), 158 null, queryForm.getOffset(), 159 queryForm.getCount() + 1); 160 if (entries.size() > queryForm.getCount()) { 161 more = true; 162 entries.remove(entries.size()-1); 163 } 164 } 165 166 public String getBaseURL() { 167 return getRequest().getContextPath(); 168 } 169 170 176 public List getRecentWeblogEntries() throws RollerException { 177 return entries; 178 } 179 180 public int getWeblogEntryCount() { 181 return entries.size(); 182 } 183 184 public List getCategories() throws Exception { 185 RollerRequest rreq = RollerRequest.getRollerRequest(request); 186 List categories = RollerFactory.getRoller().getWeblogManager() 187 .getWeblogCategories(rreq.getWebsite()); 188 return categories; 189 } 190 191 public Date getEarliestDate() { 192 Date date = null; 193 if (entries.size() > 0) { 194 WeblogEntryData earliest = (WeblogEntryData)entries.get(entries.size()-1); 195 date = earliest.getPubTime(); 196 } 197 return date; 198 } 199 200 public Date getLatestDate() { 201 Date date = null; 202 if (entries.size() > 0) { 203 WeblogEntryData latest = (WeblogEntryData)entries.get(0); 204 date = latest.getPubTime(); 205 } 206 return date; 207 } 208 209 public String getNextLink() { 210 if (more) { 211 int offset = queryForm.getOffset() + queryForm.getCount(); 212 offset = (offset < 0) ? 0 : offset; 213 return getQueryLink() + "&offset=" + offset; 214 } else { 215 return null; 216 } 217 } 218 219 public String getPrevLink() { 220 if (queryForm.getOffset() > 0) { 221 int offset = queryForm.getOffset() - queryForm.getCount(); 222 offset = (offset < 0) ? 0 : offset; 223 return getQueryLink() + "&offset=" + offset; 224 } else { 225 return null; 226 } 227 } 228 229 private String getQueryLink() { 230 StringBuffer sb = new StringBuffer (); 231 sb.append(request.getContextPath()); 232 sb.append("/roller-ui/authoring/weblogEntryManagement.do"); sb.append("?method=query"); 234 sb.append("&weblog="); 235 sb.append(getWebsite().getHandle()); 236 sb.append("&count="); 237 sb.append(queryForm.getCount()); 238 return sb.toString(); 239 } 240 } 241 } 242 | Popular Tags |