KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > presentation > weblog > actions > WeblogQueryPageModel


1 /*
2  * Created on Mar 10, 2004
3  */

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 JavaDoc;
16 import java.text.ParseException JavaDoc;
17 import java.util.Date JavaDoc;
18 import java.util.List JavaDoc;
19
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21 import javax.servlet.http.HttpServletResponse JavaDoc;
22
23 /**
24  * All data needed to render the edit-weblog page.
25  * @author David M Johnson
26  */

27 public class WeblogQueryPageModel extends BasePageModel
28 {
29     private RollerRequest rollerRequest = null;
30     private WebsiteData website = null;
31     private String JavaDoc category = null;
32     private Date JavaDoc startDate = null;
33     private Date JavaDoc endDate = null;
34     private String JavaDoc status = WeblogManager.PUB_ONLY;
35     private Integer JavaDoc maxEntries = null;
36
37     public WeblogQueryPageModel(
38             HttpServletRequest JavaDoc request,
39             HttpServletResponse JavaDoc response,
40             ActionMapping mapping,
41             WebsiteData website,
42             String JavaDoc categoryId,
43             String JavaDoc start,
44             String JavaDoc end,
45             String JavaDoc status,
46             Integer JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc getBaseURL()
91     {
92         return getRequest().getContextPath();
93     }
94
95     /**
96      * Get recent weblog entries using request parameters to determine
97      * username, date, and category name parameters.
98      * @return List of WeblogEntryData objects.
99      * @throws RollerException
100      */

101     public List JavaDoc 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 JavaDoc getCategories() throws Exception JavaDoc
113     {
114         List JavaDoc categories = rollerRequest.getRoller().getWeblogManager()
115             .getWeblogCategories(rollerRequest.getWebsite());
116         return categories;
117     }
118
119 // public List getHoursList()
120
// {
121
// List ret = new LinkedList();
122
// for (int i=0; i<24; i++)
123
// {
124
// ret.add(new Integer(i));
125
// }
126
// return ret;
127
// }
128
//
129
// public List getMinutesList()
130
// {
131
// List ret = new LinkedList();
132
// for (int i=0; i<60; i++)
133
// {
134
// ret.add(new Integer(i));
135
// }
136
// return ret;
137
// }
138
//
139
// public List getSecondsList()
140
// {
141
// return getMinutesList();
142
// }
143
//
144
// public boolean getHasPagePlugins()
145
// {
146
// return ContextLoader.hasPlugins();
147
// }
148
//
149
// public String getEditorPage()
150
// {
151
// // Select editor page selected by user (simple text editor,
152
// // DHTML editor, Ekit Java applet, etc.
153
// String editorPage = rollerRequest.getWebsite().getEditorPage();
154
// if (StringUtils.isEmpty( editorPage ))
155
// {
156
// editorPage = "editor-text.jsp";
157
// }
158
// return editorPage;
159
// }
160
//
161
// public CalendarModel getCalendarModel() throws Exception
162
// {
163
// // Determine URL to self
164
// ActionForward selfForward = getMapping().findForward("editWeblog");
165
// String selfUrl= getRequest().getContextPath()+selfForward.getPath();
166
//
167
// // Setup weblog calendar model
168
// CalendarModel model = new EditWeblogCalendarModel(
169
// rollerRequest.getRequest(), getResponse(), selfUrl );
170
// model.setDay( rollerRequest.getDate(true) );
171
// return model;
172
// }
173
//
174
// public UserData getUser()
175
// {
176
// return rollerRequest.getUser();
177
// }
178
//
179
// public int getCommentCount(WeblogEntryData entry) throws Exception
180
// {
181
// // include Spam in comments count
182
// List comments = rollerRequest.getRoller().getWeblogManager().getComments(entry.getId(), false);
183
// if (comments == null) return 0;
184
// return comments.size();
185
// }
186
}
187
Popular Tags