KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > j2biz > blogunity > web > actions > blog > DayAction


1 /*
2  * $Id: DayAction.java,v 1.3 2005/01/17 21:36:04 michelson Exp $
3  *
4  * Copyright (c) 2005 j2biz Group, http://www.j2biz.com Koeln / Duesseldorf ,
5  * Germany
6  *
7  * @author Max Kalina
8  *
9  *
10  * This program is free software; you can redistribute it and/or modify it under
11  * the terms of the GNU General Public License as published by the Free Software
12  * Foundation; either version 2 of the License, or (at your option) any later
13  * version.
14  *
15  * This program is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License along with
21  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  * Place, Suite 330, Boston, MA 02111-1307 USA
23  *
24  */

25
26 package com.j2biz.blogunity.web.actions.blog;
27
28 import java.util.Calendar JavaDoc;
29 import java.util.List JavaDoc;
30
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32 import javax.servlet.http.HttpServletResponse JavaDoc;
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 DayAction extends AbstractAction {
44
45     private static final IActionResult BLOG_DAILY_FORWARD = ActionResultFactory
46             .buildForward("/dailyView.vm");
47
48     private Blog blog;
49
50     private String JavaDoc year;
51
52     private String JavaDoc month;
53
54     private String JavaDoc day;
55
56     public DayAction(Blog blog, String JavaDoc year, String JavaDoc month, String JavaDoc day) {
57         this.blog = blog;
58         this.year = year;
59         this.month = month;
60         this.day = day;
61     }
62
63     /*
64      * (non-Javadoc)
65      *
66      * @see com.j2biz.blogunity.web.actions.AbstractAction#execute(javax.servlet.http.HttpServletRequest,
67      * javax.servlet.http.HttpServletResponse)
68      */

69     public IActionResult execute(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
70             throws BlogunityException {
71
72         int _year;
73         int _month;
74         int _day;
75
76         try {
77             _year = Integer.parseInt(year);
78             if (_year < 2000)
79                     throw new BlogunityException(I18NStatusFactory
80                             .create(I18N.ERRORS.ENTRY_BY_YEAR));
81         } catch (NumberFormatException JavaDoc e) {
82             throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.ENTRY_BY_YEAR));
83         }
84
85         try {
86             _month = Integer.parseInt(month);
87             if (_month < 1 || _month > 12)
88                     throw new BlogunityException(I18NStatusFactory
89                             .create(I18N.ERRORS.ENTRY_BY_MONTH));
90         } catch (NumberFormatException JavaDoc e) {
91             throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.ENTRY_BY_MONTH));
92         }
93
94         try {
95             _day = Integer.parseInt(day);
96             if (_day < 1 || _day > 31) { throw new BlogunityException(I18NStatusFactory
97                     .create(I18N.ERRORS.ENTRY_BY_DAY)); }
98         } catch (NumberFormatException JavaDoc e) {
99             throw new BlogunityException(I18NStatusFactory.create(I18N.ERRORS.ENTRY_BY_DAY));
100         }
101
102         Calendar JavaDoc dayObj = Calendar.getInstance();
103         dayObj.set(_year, _month - 1, _day, 0, 0, 0);
104
105         List JavaDoc entries = ( new EntryDAO()).geEntriesForDay(blog.getUrlName(), dayObj);
106
107         request.setAttribute("entries", entries);
108         request.setAttribute("requestedDay", dayObj);
109
110         return BLOG_DAILY_FORWARD;
111     }
112
113 }
Popular Tags