File Source: response.java
/*
P/P * Method: net.sourceforge.pebble.domain.Response__static_init
*/
1 /*
2 * Copyright (c) 2003-2006, Simon Brown
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * - Neither the name of Pebble nor the names of its contributors may
17 * be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32 package net.sourceforge.pebble.domain;
33
34 import java.util.Calendar;
35 import java.util.Date;
36
37 import net.sourceforge.pebble.util.StringUtils;
38
39 /**
40 * Represents a response to a blog entry - either a comment or a TrackBack.
41 *
42 * @author Simon Brown
43 */
44 public abstract class Response extends Content {
45
46 /** the title */
47 protected String title;
48
49 /** the ip address of the author */
50 protected String ipAddress;
51
52 /** the date that the trackback was received */
53 protected Date date;
54
55 /** the parent blog entry */
56 protected BlogEntry blogEntry;
57
58 /** a score used to help identify spam when repsonses are added */
59 private int spamScore = 0;
60
61 /**
62 * Default, no args constructor.
63 */
/*
P/P * Method: void net.sourceforge.pebble.domain.Response()
*
* Postconditions:
* this.events == &new ArrayList(Content#1)
* init'ed(this.eventsEnabled)
* this.propertyChangeEvents == &new ArrayList(Content#3)
* this.propertyChangeSupport == &new PropertyChangeSupport(Content#2)
* this.spamScore == 0
* new ArrayList(Content#1) num objects == 1
* new ArrayList(Content#3) num objects == 1
* new PropertyChangeSupport(Content#2) num objects == 1
*/
64 public Response() {
65 }
66
67 /**
68 * Creates a new instance with the specified properties.
69 *
70 * @param title the title of the entry
71 * @param ipAddress the IP address of the author
72 * @param date the date that this comment was left
73 * @param state the state of the comment
74 * @param blogEntry the owning blog entry
75 */
/*
P/P * Method: void net.sourceforge.pebble.domain.Response(String, String, Date, State, BlogEntry)
*
* Preconditions:
* blogEntry != null
*
* Postconditions:
* this.blogEntry == blogEntry
* this.blogEntry != null
* init'ed(this.date)
* this.events == &new ArrayList(Content#1)
* init'ed(this.eventsEnabled)
* this.ipAddress == One-of{null, ipAddress}
* init'ed(this.ipAddress)
* this.propertyChangeEvents == &new ArrayList(Content#3)
* this.propertyChangeSupport == &new PropertyChangeSupport(Content#2)
* init'ed(this.spamScore)
* ...
*/
76 Response(String title, String ipAddress, Date date, State state, BlogEntry blogEntry) {
77 this.blogEntry = blogEntry;
78
79 setTitle(title);
80 setIpAddress(ipAddress);
81 setDate(date);
82 setState(state);
83 }
84
85 /**
86 * Gets the id of this comment.
87 *
88 * @return the id as a primitive long
89 */
90 public long getId() {
/*
P/P * Method: long getId()
*
* Preconditions:
* this.date != null
*
* Postconditions:
* init'ed(return_value)
*/
91 return date.getTime();
92 }
93
94 /**
95 * Gets the globally unique id of this response.
96 *
97 * @return a String of the form type/blogEntryId/responseId
98 */
99 public String getGuid() {
/*
P/P * Method: String getGuid()
*
* Preconditions:
* this.blogEntry != null
* this.date != null
*
* Postconditions:
* return_value != null
*/
100 String s = "";
101 if (this instanceof Comment) {
102 s = "c/";
103 } else if (this instanceof TrackBack) {
104 s = "t/";
105 }
106
107 s+= getBlogEntry().getId() + "/" + getId();
108
109 return s;
110 }
111
112 /**
113 * Gets the title.
114 *
115 * @return the title as a String
116 */
117 public String getTitle() {
/*
P/P * Method: String getTitle()
*
* Preconditions:
* init'ed(this.title)
*
* Postconditions:
* return_value == this.title
* init'ed(return_value)
*/
118 return this.title;
119 }
120
121 /**
122 * Sets the title of the blog entry for this trackback.
123 *
124 * @param title the title as a String
125 */
126 public void setTitle(String title) {
/*
P/P * Method: void setTitle(String)
*
* Postconditions:
* init'ed(this.title)
*/
127 this.title = StringUtils.transformHTML(title);
128 }
129
130 /**
131 * Gets the name of the source of this response.
132 *
133 * @return a String
134 */
135 public abstract String getSourceName();
136
137 /**
138 * Gets the link to the source of this response.
139 *
140 * @return a String
141 */
142 public abstract String getSourceLink();
143
144 /**
145 * Gets the IP address.
146 *
147 * @return the IP address as a String
148 */
149 public String getIpAddress() {
/*
P/P * Method: String getIpAddress()
*
* Preconditions:
* init'ed(this.ipAddress)
*
* Postconditions:
* return_value == this.ipAddress
* init'ed(return_value)
*/
150 return ipAddress;
151 }
152
153 /**
154 * Sets the IP address.
155 *
156 * @param ipAddress the IP address of the responder
157 */
158 public void setIpAddress(String ipAddress) {
/*
P/P * Method: void setIpAddress(String)
*
* Postconditions:
* this.ipAddress == One-of{null, ipAddress}
* init'ed(this.ipAddress)
*
* Test Vectors:
* ipAddress: Addr_Set{null}, Inverse{null}
* java.lang.String:length(...)@159: {1..232-1}, {0}
*/
159 if (ipAddress == null || ipAddress.length() == 0) {
160 this.ipAddress = null;
161 } else {
162 this.ipAddress = ipAddress;
163 }
164 }
165
166 /**
167 * Gets the date that this response was received.
168 *
169 * @return the date as a java.util.Date instance.
170 */
171 public Date getDate() {
/*
P/P * Method: Date getDate()
*
* Preconditions:
* init'ed(this.date)
*
* Postconditions:
* return_value == this.date
* init'ed(return_value)
*/
172 return date;
173 }
174
175 /**
176 * Sets the date that this response was received.
177 *
178 * @param date the date as a java.util.Date instance.
179 */
180 public void setDate(Date date) {
/*
P/P * Method: void setDate(Date)
*
* Preconditions:
* this.blogEntry != null
*
* Presumptions:
* net.sourceforge.pebble.domain.Blog:getCalendar(...)@185 != null
* net.sourceforge.pebble.domain.BlogEntry:getBlog(...)@185 != null
*
* Postconditions:
* init'ed(this.date)
*
* Test Vectors:
* date: Inverse{null}, Addr_Set{null}
*/
181 if (date == null) {
182 date = new Date();
183 }
184
185 Calendar cal = blogEntry.getBlog().getCalendar();
186 cal.setTime(date);
187 this.date = cal.getTime();
188 }
189
190 /**
191 * Gets the owning blog entry.
192 *
193 * @return the owning BlogEntry instance
194 */
195 public BlogEntry getBlogEntry() {
/*
P/P * Method: BlogEntry getBlogEntry()
*
* Preconditions:
* init'ed(this.blogEntry)
*
* Postconditions:
* return_value == this.blogEntry
* init'ed(return_value)
*/
196 return blogEntry;
197 }
198
199 /**
200 * Sets the owning blog entry.
201 *
202 * @param blogEntry the owning BlogEntry instance
203 */
204 void setBlogEntry(BlogEntry blogEntry) {
/*
P/P * Method: void setBlogEntry(BlogEntry)
*
* Postconditions:
* this.blogEntry == blogEntry
* init'ed(this.blogEntry)
*/
205 this.blogEntry = blogEntry;
206 }
207
208 /**
209 * Gets the spam score.
210 *
211 * @return an int
212 */
213 public int getSpamScore() {
/*
P/P * Method: int getSpamScore()
*
* Preconditions:
* init'ed(this.spamScore)
*
* Postconditions:
* return_value == this.spamScore
* init'ed(return_value)
*/
214 return this.spamScore;
215 }
216
217 /**
218 * Increments the spam score by 1.
219 */
220 public void incrementSpamScore() {
/*
P/P * Method: void incrementSpamScore()
*
* Preconditions:
* this.spamScore <= 232-2
*
* Postconditions:
* this.spamScore == old this.spamScore + 1
* this.spamScore >= -231+1
*/
221 this.spamScore++;
222 }
223
224 /**
225 * Sets the state of this response to rejected.
226 */
227 public void setRejected() {
/*
P/P * Method: void setRejected()
*
* Postconditions:
* this.state == One-of{&net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#2), old this.state}
*/
228 setState(State.REJECTED);
229 }
230
231 /**
232 * Determines whether this response is rejected.
233 *
234 * @return true if the state is rejected, false otherwise
235 */
236 public boolean isRejected() {
/*
P/P * Method: bool isRejected()
*
* Preconditions:
* this.state != null
* (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#2).name != null
* (soft) init'ed(this.state.name)
*
* Postconditions:
* init'ed(return_value)
*/
237 return getState().equals(State.REJECTED);
238 }
239
240 /**
241 * Sets the state of this response to approved.
242 */
243 public void setApproved() {
/*
P/P * Method: void setApproved()
*
* Postconditions:
* this.state == One-of{&net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#1), old this.state}
*/
244 setState(State.APPROVED);
245 }
246
247 /**
248 * Determines whether this response is approved.
249 *
250 * @return true if the state is approved, false otherwise
251 */
252 public boolean isApproved() {
/*
P/P * Method: bool isApproved()
*
* Preconditions:
* this.state != null
* (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#1).name != null
* (soft) init'ed(this.state.name)
*
* Postconditions:
* init'ed(return_value)
*/
253 return getState().equals(State.APPROVED);
254 }
255
256 /**
257 * Sets the state of this response to pending.
258 */
259 public void setPending() {
/*
P/P * Method: void setPending()
*
* Postconditions:
* this.state == One-of{&net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#3), old this.state}
*/
260 setState(State.PENDING);
261 }
262
263 /**
264 * Determines whether this response is pending.
265 *
266 * @return true if the state is pending, false otherwise
267 */
268 public boolean isPending() {
/*
P/P * Method: bool isPending()
*
* Preconditions:
* this.state != null
* (soft) net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#3).name != null
* (soft) init'ed(this.state.name)
*
* Postconditions:
* init'ed(return_value)
*/
269 return getState().equals(State.PENDING);
270 }
271
272 }
SofCheck Inspector Build Version : 2.22510
| response.java |
2010-Jun-25 19:40:32 |
| response.class |
2010-Jul-19 20:23:40 |