Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
../../../../img/srcFileCovDistChart9.png 23% of files have more coverage
58   411   40   1,81
10   166   0,69   32
32     1,25  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  PageBasedContent       Line # 19 58 0% 40 14 86% 0.86
 
  (484)
 
1    package net.sourceforge.pebble.domain;
2   
3    import net.sourceforge.pebble.PebbleContext;
4    import net.sourceforge.pebble.security.PebbleUserDetails;
5    import net.sourceforge.pebble.security.SecurityRealm;
6    import net.sourceforge.pebble.security.SecurityRealmException;
7    import net.sourceforge.pebble.util.StringUtils;
8   
9    import org.apache.commons.logging.Log;
10    import org.apache.commons.logging.LogFactory;
11   
12    import java.util.*;
13   
14    /**
15    * The superclass for blog entries and pages.
16    *
17    * @author Simon Brown
18    */
 
19    public abstract class PageBasedContent extends Content {
20   
21    private static final Log log = LogFactory.getLog(PageBasedContent.class);
22   
23    public static final String TITLE_PROPERTY = "title";
24    public static final String SUBTITLE_PROPERTY = "subtitle";
25    public static final String BODY_PROPERTY = "body";
26    public static final String AUTHOR_PROPERTY = "author";
27    public static final String DATE_PROPERTY = "date";
28    public static final String ORIGINAL_PERMALINK_PROPERTY = "originalPermalink";
29    public static final String TAGS_PROPERTY = "tags";
30   
31    /**
32    * the id
33    */
34    private String id;
35   
36    /**
37    * the title
38    */
39    private String title = "";
40   
41    /**
42    * the subtitle
43    */
44    private String subtitle = "";
45   
46    /**
47    * the body
48    */
49    private String body = "";
50   
51    /**
52    * the date that the content was created
53    */
54    private Date date;
55   
56    /**
57    * the author of the blog entry
58    */
59    private String author = "";
60   
61    /** the enriched user details */
62    private PebbleUserDetails user;
63   
64    /**
65    * the alternative permalink for this blog entry
66    */
67    private String originalPermalink;
68   
69    /** the list of tags for this blog entry */
70    private String tags = "";
71   
72    /** the List of tags for this blog entry */
73    private List<Tag> tagsAsList = new LinkedList<Tag>();
74   
75    /** the tags, comma separated */
76    private String tagsAsCommaSeparated = "";
77   
78    /** the owning blog */
79    private Blog blog;
80   
81    private boolean persistent = false;
82    private String lockedBy = null;
83   
84    /**
85    * Creates a new blog entry.
86    *
87    * @param blog the owning Blog
88    */
 
89  1284 toggle public PageBasedContent(Blog blog) {
90  1284 this.blog = blog;
91  1284 setDate(new Date());
92    }
93   
94    /**
95    * Gets the unique id of this blog entry.
96    *
97    * @return the id as a String
98    */
 
99  4768 toggle public String getId() {
100  4768 return id;
101    }
102   
103    /**
104    * Gets the title of this blog entry.
105    *
106    * @return the title as a String
107    */
 
108  1728 toggle public String getTitle() {
109  1728 return title;
110    }
111   
112    /**
113    * Sets the title of this blog entry.
114    *
115    * @param newTitle the title as a String
116    */
 
117  934 toggle public void setTitle(String newTitle) {
118  934 newTitle = newTitle;
119  934 propertyChangeSupport.firePropertyChange(TITLE_PROPERTY, title, newTitle);
120  934 this.title = newTitle;
121    }
122   
123    /**
124    * Gets the subtitle of this blog entry.
125    *
126    * @return the subtitle as a String
127    */
 
128  580 toggle public String getSubtitle() {
129  580 return subtitle;
130    }
131   
132    /**
133    * Sets the subtitle of this blog entry.
134    *
135    * @param newSubtitle the subtitle as a String
136    */
 
137  564 toggle public void setSubtitle(String newSubtitle) {
138    //newSubtitle = StringUtils.transformHTML(newSubtitle);
139  564 propertyChangeSupport.firePropertyChange(SUBTITLE_PROPERTY, subtitle, newSubtitle);
140  564 this.subtitle = newSubtitle;
141    }
142   
143    /**
144    * Gets the body of this blog entry.
145    *
146    * @return the body as a String
147    */
 
148  1054 toggle public String getBody() {
149  1054 return body;
150    }
151   
152    /**
153    * Gets the content of this response.
154    *
155    * @return a String
156    */
 
157  0 toggle public String getContent() {
158  0 return body;
159    }
160   
161    /**
162    * Sets the body of this blog entry.
163    *
164    * @param newBody the body as a String
165    */
 
166  1078 toggle public void setBody(String newBody) {
167  1078 propertyChangeSupport.firePropertyChange(BODY_PROPERTY, body, newBody);
168  1078 this.body = newBody;
169    }
170   
171    /**
172    * Gets the date that this blog entry was created.
173    *
174    * @return a java.util.Date instance
175    */
 
176  1496 toggle public Date getDate() {
177  1496 return date;
178    }
179   
180    /**
181    * Gets the date that this blog entry was last updated.
182    *
183    * @return a Date instance representing the time of the last comment/TrackBack
184    */
 
185  0 toggle public Date getLastModified() {
186  0 return date;
187    }
188   
189    /**
190    * Sets the date that this blog entry was created.
191    *
192    * @param newDate a java.util.Date instance
193    */
 
194  2178 toggle public void setDate(Date newDate) {
195  2178 propertyChangeSupport.firePropertyChange(DATE_PROPERTY, date, newDate);
196  2178 this.date = newDate;
197  2178 this.id = "" + this.date.getTime();
198    }
199   
200    /**
201    * Gets the author of this blog entry.
202    *
203    * @return the author as a String
204    */
 
205  974 toggle public String getAuthor() {
206  974 return author;
207    }
208   
209    /**
210    * Gets full user details about the author including name, email-address, etc.
211    *
212    * @return a PebbleUserDetails instance
213    */
 
214  14 toggle public PebbleUserDetails getUser() {
215  14 if (this.user == null) {
216  14 SecurityRealm realm = PebbleContext.getInstance().getConfiguration().getSecurityRealm();
217  14 try {
218  14 this.user = realm.getUser(getAuthor());
219    } catch (SecurityRealmException e) {
220  0 log.error(e);
221    }
222    }
223   
224  14 return this.user;
225    }
226   
227    /**
228    * Sets the author of this blog entry.
229    *
230    * @param newAuthor the author as a String
231    */
 
232  764 toggle public void setAuthor(String newAuthor) {
233  764 this.author = StringUtils.transformHTML(newAuthor);
234    }
235   
236    /**
237    * Gets the tags associated with this category.
238    *
239    * @return a list of tags
240    */
 
241  646 toggle public String getTags() {
242  646 return this.tags;
243    }
244   
245    /**
246    * Gets the tags associated with this category, as a List.
247    *
248    * @return a List of tags
249    */
 
250  856 toggle public List<Tag> getTagsAsList() {
251  856 return this.tagsAsList;
252    }
253   
254    /**
255    * Gets a list of all tags, as a comma separated string.
256    *
257    * @return a comma separated String of tags
258    */
 
259  0 toggle public String getTagsAsCommaSeparated() {
260  0 return this.tagsAsCommaSeparated;
261    }
262   
263    /**
264    * Gets a list of all tags.
265    *
266    * @return a List of tags
267    */
268    public abstract List<Tag> getAllTags();
269   
270    /**
271    * Sets the set of tags associated with this category.
272    *
273    * @param newTags a set of tags
274    */
 
275  632 toggle public void setTags(String newTags) {
276  632 if (newTags != null && newTags.indexOf(",") > -1) {
277    // if the tags have been comma separated, convert them to
278    // whitespace separated by
279    // - remove whitespace
280    // - convert commas to whitespace
281  30 newTags = newTags.replaceAll(" ", "").replaceAll(",", " ");
282    }
283  632 propertyChangeSupport.firePropertyChange(TAGS_PROPERTY, tags, newTags);
284  632 this.tags = newTags;
285  632 this.tagsAsList = Tag.parse(getBlog(), tags);
286  632 this.tagsAsCommaSeparated = Tag.format(getAllTags());
287    }
288   
289    /**
290    * Determines whether this blog entry has been aggregated from another
291    * source. An aggregated blog entry will have a specified permalink.
292    *
293    * @return true if this blog entry has been aggegrated, false otherwise
294    */
 
295  172 toggle public boolean isAggregated() {
296  172 return (originalPermalink != null);
297    }
298   
299    /**
300    * Gets the alternative permalink for this blog entry.
301    *
302    * @return an absolute URL as a String
303    */
 
304  512 toggle public String getOriginalPermalink() {
305  512 return this.originalPermalink;
306    }
307   
308    /**
309    * Sets the alternative permalink for this blog entry.
310    *
311    * @param newPermalink an absolute URL as a String
312    */
 
313  522 toggle public void setOriginalPermalink(String newPermalink) {
314  522 newPermalink = StringUtils.transformHTML(newPermalink);
315  522 if (newPermalink == null || newPermalink.length() == 0) {
316  506 propertyChangeSupport.firePropertyChange(ORIGINAL_PERMALINK_PROPERTY, originalPermalink, null);
317  506 this.originalPermalink = null;
318    } else {
319  16 propertyChangeSupport.firePropertyChange(ORIGINAL_PERMALINK_PROPERTY, originalPermalink, newPermalink);
320  16 this.originalPermalink = newPermalink;
321    }
322    }
323   
324    /**
325    * Gets a permalink for this blog entry.
326    *
327    * @return an absolute URL as a String
328    */
 
329  86 toggle public String getPermalink() {
330  86 if (isAggregated()) {
331  0 return getOriginalPermalink();
332    } else {
333  86 return getLocalPermalink();
334    }
335    }
336   
337    /**
338    * Gets a permalink for this blog entry that is local to the blog. In other
339    * words, it doesn't take into account the original permalink for
340    * aggregated content.
341    *
342    * @return an absolute URL as a String
343    */
344    public abstract String getLocalPermalink();
345   
346    /**
347    * Helper method to get the owning Blog instance.
348    *
349    * @return the overall owning Blog instance
350    */
 
351  8180 toggle public Blog getBlog() {
352  8180 return this.blog;
353    }
354   
355    /**
356    * Gets a string representation of this object.
357    *
358    * @return a String
359    */
 
360  0 toggle public String toString() {
361  0 return getBlog().getId() + "/" + getTitle();
362    }
363   
 
364  1350 toggle public boolean isPersistent() {
365  1350 return persistent;
366    }
367   
 
368  1484 toggle public void setPersistent(boolean persistent) {
369  1484 this.persistent = persistent;
370    }
371   
372    /**
373    * Determines whether this content is published.
374    *
375    * @return true if the state is published, false otherwise
376    */
 
377  2600 toggle public boolean isPublished() {
378  2600 return getState().equals(State.PUBLISHED);
379    }
380   
381    /**
382    * Determines whether this content is unpublished.
383    *
384    * @return true if the state is unpublished, false otherwise
385    */
 
386  26 toggle public boolean isUnpublished() {
387  26 return getState().equals(State.UNPUBLISHED);
388    }
389   
390    /**
391    * Sets the state of this content.
392    *
393    * @param published true if this content is published, false if unpublished
394    */
 
395  1994 toggle public void setPublished(boolean published) {
396  1994 if (published) {
397  364 setState(State.PUBLISHED);
398    } else {
399  1630 setState(State.UNPUBLISHED);
400    }
401    }
402   
 
403  0 toggle public String getLockedBy() {
404  0 return lockedBy;
405    }
406   
 
407  2 toggle public void setLockedBy(String lockedBy) {
408  2 this.lockedBy = lockedBy;
409    }
410   
411    }