Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
35   272   25   1,75
8   92   0,71   20
20     1,25  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  Response       Line # 44 35 0% 25 2 96,8% 0.96825397
 
  (228)
 
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    */
 
64  0 toggle 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    */
 
76  598 toggle Response(String title, String ipAddress, Date date, State state, BlogEntry blogEntry) {
77  598 this.blogEntry = blogEntry;
78   
79  598 setTitle(title);
80  598 setIpAddress(ipAddress);
81  598 setDate(date);
82  598 setState(state);
83    }
84   
85    /**
86    * Gets the id of this comment.
87    *
88    * @return the id as a primitive long
89    */
 
90  3296 toggle public long getId() {
91  3296 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  560 toggle public String getGuid() {
100  560 String s = "";
101  560 if (this instanceof Comment) {
102  478 s = "c/";
103  82 } else if (this instanceof TrackBack) {
104  82 s = "t/";
105    }
106   
107  560 s+= getBlogEntry().getId() + "/" + getId();
108   
109  560 return s;
110    }
111   
112    /**
113    * Gets the title.
114    *
115    * @return the title as a String
116    */
 
117  414 toggle public String getTitle() {
118  414 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  162 toggle public void setTitle(String title) {
127  162 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  760 toggle public String getIpAddress() {
150  760 return ipAddress;
151    }
152   
153    /**
154    * Sets the IP address.
155    *
156    * @param ipAddress the IP address of the responder
157    */
 
158  598 toggle public void setIpAddress(String ipAddress) {
159  598 if (ipAddress == null || ipAddress.length() == 0) {
160  48 this.ipAddress = null;
161    } else {
162  550 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  1560 toggle public Date getDate() {
172  1560 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  774 toggle public void setDate(Date date) {
181  774 if (date == null) {
182  2 date = new Date();
183    }
184   
185  774 Calendar cal = blogEntry.getBlog().getCalendar();
186  774 cal.setTime(date);
187  774 this.date = cal.getTime();
188    }
189   
190    /**
191    * Gets the owning blog entry.
192    *
193    * @return the owning BlogEntry instance
194    */
 
195  1538 toggle public BlogEntry getBlogEntry() {
196  1538 return blogEntry;
197    }
198   
199    /**
200    * Sets the owning blog entry.
201    *
202    * @param blogEntry the owning BlogEntry instance
203    */
 
204  280 toggle void setBlogEntry(BlogEntry blogEntry) {
205  280 this.blogEntry = blogEntry;
206    }
207   
208    /**
209    * Gets the spam score.
210    *
211    * @return an int
212    */
 
213  194 toggle public int getSpamScore() {
214  194 return this.spamScore;
215    }
216   
217    /**
218    * Increments the spam score by 1.
219    */
 
220  74 toggle public void incrementSpamScore() {
221  74 this.spamScore++;
222    }
223   
224    /**
225    * Sets the state of this response to rejected.
226    */
 
227  14 toggle public void setRejected() {
228  14 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  98 toggle public boolean isRejected() {
237  98 return getState().equals(State.REJECTED);
238    }
239   
240    /**
241    * Sets the state of this response to approved.
242    */
 
243  62 toggle public void setApproved() {
244  62 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  404 toggle public boolean isApproved() {
253  404 return getState().equals(State.APPROVED);
254    }
255   
256    /**
257    * Sets the state of this response to pending.
258    */
 
259  180 toggle public void setPending() {
260  180 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  146 toggle public boolean isPending() {
269  146 return getState().equals(State.PENDING);
270    }
271   
272    }