File Source: CommentsBean.java
/*
P/P * Method: org.apache.roller.weblogger.ui.struts2.editor.CommentsBean__static_init
*/
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
19 package org.apache.roller.weblogger.ui.struts2.editor;
20
21 import java.text.DateFormat;
22 import java.text.SimpleDateFormat;
23 import java.util.ArrayList;
24 import java.util.Date;
25 import java.util.Iterator;
26 import java.util.List;
27 import org.apache.commons.lang.StringUtils;
28 import org.apache.roller.weblogger.pojos.WeblogEntryComment;
29 import org.apache.roller.weblogger.util.Utilities;
30
31
32 /**
33 * A bean for managing comments.
34 */
/*
P/P * Method: void org.apache.roller.weblogger.ui.struts2.editor.CommentsBean()
*
* Postconditions:
* this.approvedComments == &new String[](CommentsBean#1)
* this.approvedString == &"ALL"
* this.spamString == &"ALL"
* this.deleteComments == &new String[](CommentsBean#3)
* this.endDateString == null
* this.entryId == null
* this.ids == null
* this.searchString == null
* this.startDateString == null
* this.page == 0
* ...
*/
35 public class CommentsBean {
36
37 private String entryId = null;
38 private String searchString = null;
39 private String startDateString = null;
40 private String endDateString = null;
41 private String spamString = "ALL";
42 private String approvedString = "ALL";
43 private int page = 0;
44
45 private String[] approvedComments = new String[0];
46 private String[] spamComments = new String[0];
47 private String[] deleteComments = new String[0];
48
49 // Limit updates to just this set of comma-separated IDs
50 private String ids = null;
51
52
53 public void loadCheckboxes(List comments) {
54
/*
P/P * Method: void loadCheckboxes(List)
*
* Preconditions:
* comments != null
*
* Presumptions:
* java.util.Iterator:next(...)@61 != null
* java.util.List:size(...)@72 >= 0
* java.util.List:size(...)@76 >= 0
* java.util.List:size(...)@79 >= 0
*
* Postconditions:
* init'ed(this.approvedComments)
* init'ed(this.ids)
* init'ed(this.spamComments)
*
* Test Vectors:
* java.lang.String:equals(...)@64: {0}, {1}
* java.lang.String:equals(...)@66: {0}, {1}
* java.util.Iterator:hasNext(...)@60: {0}, {1}
*/
55 List<String> allComments = new ArrayList();
56 List<String> approvedList = new ArrayList();
57 List<String> spamList = new ArrayList();
58
59 Iterator it = comments.iterator();
60 while (it.hasNext()) {
61 WeblogEntryComment comment = (WeblogEntryComment)it.next();
62 allComments.add(comment.getId());
63
64 if(WeblogEntryComment.APPROVED.equals(comment.getStatus())) {
65 approvedList.add(comment.getId());
66 } else if(WeblogEntryComment.SPAM.equals(comment.getStatus())) {
67 spamList.add(comment.getId());
68 }
69 }
70
71 // list of ids we are working on
72 String[] idArray = (String[]) allComments.toArray(new String[allComments.size()]);
73 setIds(Utilities.stringArrayToString(idArray,","));
74
75 // approved ids list
76 setApprovedComments((String[])approvedList.toArray(new String[approvedList.size()]));
77
78 // spam ids list
79 setSpamComments((String[])spamList.toArray(new String[spamList.size()]));
80 }
81
82
83 public String getStatus() {
/*
P/P * Method: String getStatus()
*
* Preconditions:
* this.approvedString != null
* (soft) this.spamString != null
*
* Postconditions:
* return_value in Addr_Set{null,&"ALL_IGNORE_SPAM",&"SPAM",&"PENDING",&"DISAPPROVED",&"APPROVED"}
*
* Test Vectors:
* java.lang.String:equals(...)@84: {0}, {1}
* java.lang.String:equals(...)@86: {0}, {1}
* java.lang.String:equals(...)@88: {0}, {1}
* java.lang.String:equals(...)@90: {0}, {1}
* java.lang.String:equals(...)@92: {0}, {1}
*/
84 if (approvedString.equals("ONLY_APPROVED")) {
85 return WeblogEntryComment.APPROVED;
86 } else if (approvedString.equals("ONLY_DISAPPROVED")) {
87 return WeblogEntryComment.DISAPPROVED;
88 } else if (approvedString.equals("ONLY_PENDING")) {
89 return WeblogEntryComment.PENDING;
90 } else if (spamString.equals("ONLY_SPAM")) {
91 return WeblogEntryComment.SPAM;
92 } else if (spamString.equals("NO_SPAM")) {
93 // all status' except spam
94 // special situation, so this doesn't map to a persisted comment status
95 return "ALL_IGNORE_SPAM";
96 } else {
97 // shows *all* comments, regardless of status
98 return null;
99 }
100 }
101
102 public Date getStartDate() {
/*
P/P * Method: Date getStartDate()
*
* Preconditions:
* init'ed(this.startDateString)
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* org.apache.commons.lang.StringUtils:isEmpty(...)@103: {1}, {0}
*/
103 if(!StringUtils.isEmpty(getStartDateString())) try {
104 DateFormat df = new SimpleDateFormat("MM/dd/yy");
105 return df.parse(getStartDateString());
106 } catch(Exception e) { }
107 return null;
108 }
109
110 public Date getEndDate() {
/*
P/P * Method: Date getEndDate()
*
* Preconditions:
* init'ed(this.endDateString)
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* org.apache.commons.lang.StringUtils:isEmpty(...)@111: {1}, {0}
*/
111 if(!StringUtils.isEmpty(getEndDateString())) try {
112 DateFormat df = new SimpleDateFormat("MM/dd/yy");
113 return df.parse(getEndDateString());
114 } catch(Exception e) { }
115 return null;
116 }
117
118
119 public String getSpamString() {
/*
P/P * Method: String getSpamString()
*
* Preconditions:
* init'ed(this.spamString)
*
* Postconditions:
* return_value == this.spamString
* init'ed(return_value)
*/
120 return spamString;
121 }
122
123 public void setSpamString(String spamString) {
/*
P/P * Method: void setSpamString(String)
*
* Postconditions:
* this.spamString == spamString
* init'ed(this.spamString)
*/
124 this.spamString = spamString;
125 }
126
127 public String getIds() {
/*
P/P * Method: String getIds()
*
* Preconditions:
* init'ed(this.ids)
*
* Postconditions:
* return_value == this.ids
* init'ed(return_value)
*/
128 return ids;
129 }
130
131 public void setIds(String ids) {
/*
P/P * Method: void setIds(String)
*
* Postconditions:
* this.ids == ids
* init'ed(this.ids)
*/
132 this.ids = ids;
133 }
134
135 public String getSearchString() {
/*
P/P * Method: String getSearchString()
*
* Preconditions:
* init'ed(this.searchString)
*
* Postconditions:
* return_value == this.searchString
* init'ed(return_value)
*/
136 return searchString;
137 }
138
139 public void setSearchString(String searchString) {
/*
P/P * Method: void setSearchString(String)
*
* Postconditions:
* this.searchString == searchString
* init'ed(this.searchString)
*/
140 this.searchString = searchString;
141 }
142
143 public String[] getApprovedComments() {
/*
P/P * Method: String[] getApprovedComments()
*
* Preconditions:
* init'ed(this.approvedComments)
*
* Postconditions:
* return_value == this.approvedComments
* init'ed(return_value)
*/
144 return approvedComments;
145 }
146
147 public void setApprovedComments(String[] approvedComments) {
/*
P/P * Method: void setApprovedComments(String[])
*
* Postconditions:
* this.approvedComments == approvedComments
* init'ed(this.approvedComments)
*/
148 this.approvedComments = approvedComments;
149 }
150
151 public String[] getSpamComments() {
/*
P/P * Method: String[] getSpamComments()
*
* Preconditions:
* init'ed(this.spamComments)
*
* Postconditions:
* return_value == this.spamComments
* init'ed(return_value)
*/
152 return spamComments;
153 }
154
155 public void setSpamComments(String[] spamComments) {
/*
P/P * Method: void setSpamComments(String[])
*
* Postconditions:
* this.spamComments == spamComments
* init'ed(this.spamComments)
*/
156 this.spamComments = spamComments;
157 }
158
159 public String[] getDeleteComments() {
/*
P/P * Method: String[] getDeleteComments()
*
* Preconditions:
* init'ed(this.deleteComments)
*
* Postconditions:
* return_value == this.deleteComments
* init'ed(return_value)
*/
160 return deleteComments;
161 }
162
163 public void setDeleteComments(String[] deleteComments) {
/*
P/P * Method: void setDeleteComments(String[])
*
* Postconditions:
* this.deleteComments == deleteComments
* init'ed(this.deleteComments)
*/
164 this.deleteComments = deleteComments;
165 }
166
167 public String getApprovedString() {
/*
P/P * Method: String getApprovedString()
*
* Preconditions:
* init'ed(this.approvedString)
*
* Postconditions:
* return_value == this.approvedString
* init'ed(return_value)
*/
168 return approvedString;
169 }
170
171 public void setApprovedString(String approvedString) {
/*
P/P * Method: void setApprovedString(String)
*
* Postconditions:
* this.approvedString == approvedString
* init'ed(this.approvedString)
*/
172 this.approvedString = approvedString;
173 }
174
175 public int getPage() {
/*
P/P * Method: int getPage()
*
* Preconditions:
* init'ed(this.page)
*
* Postconditions:
* return_value == this.page
* init'ed(return_value)
*/
176 return page;
177 }
178
179 public void setPage(int page) {
/*
P/P * Method: void setPage(int)
*
* Postconditions:
* this.page == page
* init'ed(this.page)
*/
180 this.page = page;
181 }
182
183 public String getStartDateString() {
/*
P/P * Method: String getStartDateString()
*
* Preconditions:
* init'ed(this.startDateString)
*
* Postconditions:
* return_value == this.startDateString
* init'ed(return_value)
*/
184 return startDateString;
185 }
186
187 public void setStartDateString(String startDateString) {
/*
P/P * Method: void setStartDateString(String)
*
* Postconditions:
* this.startDateString == startDateString
* init'ed(this.startDateString)
*/
188 this.startDateString = startDateString;
189 }
190
191 public String getEndDateString() {
/*
P/P * Method: String getEndDateString()
*
* Preconditions:
* init'ed(this.endDateString)
*
* Postconditions:
* return_value == this.endDateString
* init'ed(return_value)
*/
192 return endDateString;
193 }
194
195 public void setEndDateString(String endDateString) {
/*
P/P * Method: void setEndDateString(String)
*
* Postconditions:
* this.endDateString == endDateString
* init'ed(this.endDateString)
*/
196 this.endDateString = endDateString;
197 }
198
199 public String getEntryId() {
/*
P/P * Method: String getEntryId()
*
* Preconditions:
* init'ed(this.entryId)
*
* Postconditions:
* return_value == this.entryId
* init'ed(return_value)
*/
200 return entryId;
201 }
202
203 public void setEntryId(String entryId) {
/*
P/P * Method: void setEntryId(String)
*
* Postconditions:
* this.entryId == entryId
* init'ed(this.entryId)
*/
204 this.entryId = entryId;
205 }
206
207 }
SofCheck Inspector Build Version : 2.18479
| CommentsBean.java |
2009-Jan-02 14:25:34 |
| CommentsBean.class |
2009-Sep-04 03:12:45 |