KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > authoring > struts > formbeans > CommentManagementForm


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */

18 package org.apache.roller.ui.authoring.struts.formbeans;
19
20 import java.text.DateFormat JavaDoc;
21 import java.text.ParseException JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Calendar JavaDoc;
24 import java.util.Date JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Locale JavaDoc;
28
29 import javax.servlet.ServletRequest JavaDoc;
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32
33 import org.apache.struts.action.ActionMapping;
34 import org.apache.roller.pojos.CommentData;
35 import org.apache.roller.util.DateUtil;
36 import org.apache.roller.util.Utilities;
37
38 /**
39  * @struts.form name="commentManagementForm"
40  * @author Dave Johnson
41  */

42 public class CommentManagementForm
43     extends org.apache.struts.action.ActionForm
44     implements java.io.Serializable JavaDoc {
45     
46     private static Log logger =
47         LogFactory.getFactory().getInstance(CommentManagementForm.class);
48     
49     private String JavaDoc entryid = null;
50     private String JavaDoc handle = null;
51     
52     private String JavaDoc searchString = null;
53     private String JavaDoc startDateString;
54     private String JavaDoc endDateString;
55     
56     /** ALL, NO_SPAM or ONLY_SPAM */
57     private String JavaDoc spamString = "ALL";
58     
59     /** ALL, NO_APPROVED or ONLY_APPROVED */
60     private String JavaDoc approvedString = "ALL";
61    
62     /** max comments displayed per page */
63     private int count = 30;
64     
65      /** offset into current query results */
66     private int offset = 0;
67
68     /** IDs of comments to mark as spam */
69     private String JavaDoc[] spamComments = new String JavaDoc[0];
70     
71     /** IDs of comments to mark as approved */
72     private String JavaDoc[] approvedComments = new String JavaDoc[0];
73     
74     /** IDs of comments to delete */
75     private String JavaDoc[] deleteComments = new String JavaDoc[0];
76     
77     /** Limit updates to just this set of comma-separated IDs */
78     private String JavaDoc ids = null;
79     
80     
81     public void reset(ActionMapping mapping, ServletRequest JavaDoc request) {
82         // reset time fields to current time
83
Calendar JavaDoc cal = Calendar.getInstance(request.getLocale());
84         Date JavaDoc now = new Date JavaDoc();
85         cal.setTime(now);
86     
87         DateFormat JavaDoc df = DateFormat.getDateInstance(DateFormat.SHORT, request.getLocale());
88         setEndDateString(df.format(now));
89         
90         cal.set(Calendar.DAY_OF_MONTH, 1);
91         setStartDateString(df.format(cal.getTime()));
92     }
93
94     public void loadCheckboxes(List JavaDoc comments) {
95         ArrayList JavaDoc all = new ArrayList JavaDoc();
96         ArrayList JavaDoc approvedList = new ArrayList JavaDoc();
97         ArrayList JavaDoc spamList = new ArrayList JavaDoc();
98         Iterator JavaDoc it = comments.iterator();
99         while (it.hasNext()) {
100             CommentData comment = (CommentData)it.next();
101             all.add(comment.getId());
102             if (comment.getApproved().booleanValue()) {
103                 approvedList.add(comment.getId());
104             }
105             if (comment.getSpam().booleanValue()) {
106                 spamList.add(comment.getId());
107             }
108         }
109         String JavaDoc[] idArray = (String JavaDoc[])all.toArray(
110             new String JavaDoc[all.size()]);
111         ids = Utilities.stringArrayToString(idArray,",");
112         
113         approvedComments = (String JavaDoc[])approvedList.toArray(
114             new String JavaDoc[approvedList.size()]);
115         spamComments = (String JavaDoc[])spamList.toArray(
116             new String JavaDoc[spamList.size()]);
117     }
118         
119     public Date JavaDoc getStartDate(Locale JavaDoc locale) {
120         Date JavaDoc startDate = null;
121         final DateFormat JavaDoc df =
122             DateFormat.getDateInstance(DateFormat.SHORT, locale);
123         if (null != getStartDateString() && getStartDateString().trim().length() > 0) {
124             try {
125                 startDate = DateUtil.getStartOfDay(df.parse(getStartDateString()));
126             } catch (ParseException JavaDoc e) {
127                 // what!?! calendar widget handed us a bad date?
128
logger.debug("Parsing startDate", e);
129             }
130         }
131         return startDate;
132     }
133
134     public Date JavaDoc getEndDate(Locale JavaDoc locale) {
135         Date JavaDoc endDate = null;
136         final DateFormat JavaDoc df =
137             DateFormat.getDateInstance(DateFormat.SHORT, locale);
138         if (null != getEndDateString() && getEndDateString().trim().length() > 0) {
139             try {
140                 endDate = DateUtil.getEndOfDay(df.parse(getEndDateString()));
141             } catch (ParseException JavaDoc e) {
142                 // what!?! calendar widget handed us a bad date?
143
logger.debug("Parsing endDate", e);
144             }
145         }
146         return endDate;
147     }
148
149     public Boolean JavaDoc getSpam() {
150         if (spamString.equals("ONLY_SPAM")) {
151             return Boolean.TRUE;
152         } else if (spamString.equals("NO_SPAM")) {
153             return Boolean.FALSE;
154         }
155         return null;
156     }
157
158     public Boolean JavaDoc getPending() {
159         if (approvedString.equals("ONLY_PENDING")) {
160             return Boolean.TRUE;
161         }
162         return null;
163     }
164     
165     public Boolean JavaDoc getApproved() {
166         if (approvedString.equals("ONLY_APPROVED")) {
167             return Boolean.TRUE;
168         } else if (approvedString.equals("ONLY_DISAPPROVED")) {
169             return Boolean.FALSE;
170         }
171         return null;
172     }
173
174     public int getCount() {
175         return count;
176     }
177
178     public void setCount(int count) {
179         this.count = count;
180     }
181
182     public int getOffset() {
183         return offset;
184     }
185
186     public void setOffset(int offset) {
187         this.offset = offset;
188     }
189
190     public String JavaDoc getStartDateString() {
191         return startDateString;
192     }
193
194     public void setStartDateString(String JavaDoc startDateString) {
195         this.startDateString = startDateString;
196     }
197
198     public String JavaDoc getEndDateString() {
199         return endDateString;
200     }
201
202     public void setEndDateString(String JavaDoc endDateString) {
203         this.endDateString = endDateString;
204     }
205
206     public String JavaDoc getSpamString() {
207         return spamString;
208     }
209
210     public void setSpamString(String JavaDoc spamString) {
211         this.spamString = spamString;
212     }
213
214     public String JavaDoc getPendingString() {
215         return approvedString;
216     }
217
218     public void setPendingString(String JavaDoc pendingString) {
219         this.approvedString = pendingString;
220     }
221
222     public String JavaDoc getIds() {
223         return ids;
224     }
225
226     public void setIds(String JavaDoc ids) {
227         this.ids = ids;
228     }
229
230     public String JavaDoc getSearchString() {
231         return searchString;
232     }
233
234     public void setSearchString(String JavaDoc searchString) {
235         this.searchString = searchString;
236     }
237
238     public String JavaDoc getEntryid() {
239         return entryid;
240     }
241
242     public void setEntryid(String JavaDoc entryid) {
243         this.entryid = entryid;
244     }
245
246     public String JavaDoc getWeblog() {
247         return handle;
248     }
249
250     public void setWeblog(String JavaDoc handle) {
251         this.handle = handle;
252     }
253     
254     public String JavaDoc[] getDeleteComments() {
255         return deleteComments;
256     }
257     
258     public void setDeleteComments(String JavaDoc[] deleteComments) {
259         this.deleteComments = deleteComments;
260     }
261     
262     public String JavaDoc[] getSpamComments() {
263         return spamComments;
264     }
265     
266     public void setSpamComments(String JavaDoc[] commentsToMarkAsSpam) {
267         this.spamComments = commentsToMarkAsSpam;
268     }
269     
270     public String JavaDoc[] getApprovedComments() {
271         return approvedComments;
272     }
273     
274     public void setApprovedComments(String JavaDoc[] approvedComments) {
275         this.approvedComments = approvedComments;
276     }
277
278 }
279
Popular Tags