1 25 26 package com.j2biz.blogunity.web.actions.blog; 27 28 import java.util.Calendar ; 29 import java.util.List ; 30 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.servlet.http.HttpServletResponse ; 33 34 import com.j2biz.blogunity.dao.EntryDAO; 35 import com.j2biz.blogunity.exception.BlogunityException; 36 import com.j2biz.blogunity.i18n.I18N; 37 import com.j2biz.blogunity.i18n.I18NStatusFactory; 38 import com.j2biz.blogunity.pojo.Blog; 39 import com.j2biz.blogunity.web.ActionResultFactory; 40 import com.j2biz.blogunity.web.IActionResult; 41 import com.j2biz.blogunity.web.actions.AbstractAction; 42 43 public class MonthAction extends AbstractAction { 44 45 private static final IActionResult BLOG_MONTHLY_FORWARD = ActionResultFactory 46 .buildForward("/monthlyView.vm"); 47 48 private Blog blog; 49 50 private String year; 51 52 private String month; 53 54 public MonthAction(Blog blog, String year, String month) { 55 this.blog = blog; 56 this.year = year; 57 this.month = month; 58 } 59 60 66 public IActionResult execute(HttpServletRequest request, HttpServletResponse response) 67 throws BlogunityException { 68 69 int _year; 70 int _month; 71 72 try { 73 _year = Integer.parseInt(year); 74 if (_year < 2000) 75 throw new BlogunityException(I18NStatusFactory 76 .create(I18N.ERRORS.ENTRY_BY_YEAR)); 77 } catch (NumberFormatException e) { 78 throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.ENTRY_BY_YEAR)); 79 } 80 81 try { 82 _month = Integer.parseInt(month); 83 if (_month < 1 || _month > 12) 84 throw new BlogunityException(I18NStatusFactory 85 .create(I18N.ERRORS.ENTRY_BY_MONTH)); 86 } catch (NumberFormatException e) { 87 throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.ENTRY_BY_MONTH)); 88 } 89 90 Calendar monthObj = Calendar.getInstance(); 91 monthObj.set(_year, _month - 1, 1, 0, 0, 0); 92 93 List entries = ( new EntryDAO()).getEntriesForMonth(blog.getUrlName(), monthObj); 94 95 request.setAttribute("entries", entries); 96 request.setAttribute("requestedMonth", monthObj); 97 98 return BLOG_MONTHLY_FORWARD; 99 100 } 101 102 } | Popular Tags |