1 4 package org.roller.presentation.weblog.actions; 5 6 import org.apache.struts.action.ActionMapping; 7 import org.roller.RollerException; 8 import org.roller.model.WeblogManager; 9 import org.roller.pojos.WeblogCategoryData; 10 import org.roller.pojos.WebsiteData; 11 import org.roller.presentation.BasePageModel; 12 import org.roller.presentation.RollerRequest; 13 import org.roller.util.DateUtil; 14 15 import java.text.DateFormat ; 16 import java.text.ParseException ; 17 import java.util.Date ; 18 import java.util.List ; 19 20 import javax.servlet.http.HttpServletRequest ; 21 import javax.servlet.http.HttpServletResponse ; 22 23 27 public class WeblogQueryPageModel extends BasePageModel 28 { 29 private RollerRequest rollerRequest = null; 30 private WebsiteData website = null; 31 private String category = null; 32 private Date startDate = null; 33 private Date endDate = null; 34 private String status = WeblogManager.PUB_ONLY; 35 private Integer maxEntries = null; 36 37 public WeblogQueryPageModel( 38 HttpServletRequest request, 39 HttpServletResponse response, 40 ActionMapping mapping, 41 WebsiteData website, 42 String categoryId, 43 String start, 44 String end, 45 String status, 46 Integer maxEntries) throws RollerException 47 { 48 super(request, response, mapping); 49 rollerRequest = RollerRequest.getRollerRequest(request); 50 51 this.website = website; 52 53 if (null != categoryId && !categoryId.equals("")) 54 { 55 WeblogManager wmgr = rollerRequest.getRoller().getWeblogManager(); 56 WeblogCategoryData cd = wmgr.retrieveWeblogCategory(categoryId); 57 category = cd.getPath(); 58 } 59 60 final DateFormat df = 61 DateFormat.getDateInstance(DateFormat.SHORT, request.getLocale()); 62 if (null != start && start.trim().length() > 0) 63 { 64 try 65 { 66 startDate = DateUtil.getStartOfDay(df.parse(start)); 67 } 68 catch (ParseException e) 69 { 70 throw new RollerException("ERROR parsing start date."); 71 } 72 } 73 74 if (null != end && end.trim().length() > 0) 75 { 76 try 77 { 78 endDate = DateUtil.getEndOfDay(df.parse(end)); 79 } 80 catch (ParseException e) 81 { 82 throw new RollerException("ERROR parsing end date."); 83 } 84 } 85 86 this.status = status; 87 this.maxEntries = maxEntries; 88 } 89 90 public String getBaseURL() 91 { 92 return getRequest().getContextPath(); 93 } 94 95 101 public List getRecentWeblogEntries() throws RollerException 102 { 103 return rollerRequest.getRoller().getWeblogManager().getWeblogEntries( 104 website, 105 startDate, 106 endDate, 107 category, 108 status, 109 maxEntries); 110 } 111 112 public List getCategories() throws Exception 113 { 114 List categories = rollerRequest.getRoller().getWeblogManager() 115 .getWeblogCategories(rollerRequest.getWebsite()); 116 return categories; 117 } 118 119 } 187 | Popular Tags |