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
25   212   23   1,56
6   80   0,92   16
16     1,44  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  Content       Line # 49 25 0% 23 2 95,7% 0.9574468
 
  (498)
 
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 net.sourceforge.pebble.api.event.PebbleEvent;
35    import net.sourceforge.pebble.util.StringUtils;
36   
37    import java.beans.PropertyChangeEvent;
38    import java.beans.PropertyChangeListener;
39    import java.beans.PropertyChangeSupport;
40    import java.io.Serializable;
41    import java.util.ArrayList;
42    import java.util.List;
43   
44    /**
45    * Superclass for blog entries, comments and TrackBacks.
46    *
47    * @author Simon Brown
48    */
 
49    public abstract class Content implements Permalinkable, Cloneable, Serializable {
50   
51    /** the state of the object */
52    private State state;
53   
54    /** flag to indicate whether events are enabled */
55    private boolean eventsEnabled = false;
56   
57    /** the class responsible for managing property change events */
58    protected transient PropertyChangeSupport propertyChangeSupport;
59   
60    /** the collection of properties that have changed since the last store */
61    private transient ArrayList propertyChangeEvents;
62   
63    /** the collection of PebbleEvent instances that have been initiated */
64    private transient List<PebbleEvent> events = new ArrayList<PebbleEvent>();
65   
66    /**
67    * Default, no args constructor.
68    */
 
69  1882 toggle public Content() {
70  1882 this.propertyChangeSupport = new PropertyChangeSupport(this);
71  1882 this.propertyChangeEvents = new ArrayList();
72  1882 this.propertyChangeSupport.addPropertyChangeListener(new PropertyChangeListener() {
 
73  5011 toggle public void propertyChange(PropertyChangeEvent event) {
74  5011 if (areEventsEnabled()) {
75  166 Object oldValue = event.getOldValue();
76  166 Object newValue = event.getNewValue();
77  166 if ((oldValue == null && newValue == null) ||
78    (oldValue != null && newValue != null && oldValue.equals(newValue))) {
79  6 return;
80    } else {
81  160 Content.this.propertyChangeEvents.add(event);
82    }
83    }
84    }
85    });
86    }
87   
88    /**
89    * Gets the content of this response.
90    *
91    * @return a String
92    */
93    public abstract String getContent();
94   
95    /**
96    * Gets the content of this response, truncated and without HTML tags.
97    *
98    * @return the content of this response as a String
99    */
 
100  84 toggle public String getTruncatedContent() {
101  84 return StringUtils.truncate(getContent());
102    }
103   
104    /**
105    * Gets the state of this comment.
106    *
107    * @return a State instance (APPROVED, REJECTED or PENDING)
108    */
 
109  7346 toggle public State getState() {
110  7346 return this.state;
111    }
112   
113    /**
114    * Sets the state of this comment.
115    */
 
116  3352 toggle void setState(State state) {
117  3352 this.state = state;
118    }
119   
120    /**
121    * Sets whether events are enabled.
122    *
123    * @param b true to enable events, false otherwise
124    */
 
125  2002 toggle void setEventsEnabled(boolean b) {
126  2002 this.eventsEnabled = b;
127    }
128   
129    /**
130    * Determines whether events are enabled.
131    *
132    * @return true if events are enabled, false otherwise
133    */
 
134  8701 toggle boolean areEventsEnabled() {
135  8701 return this.eventsEnabled;
136    }
137   
138    /**
139    * Clears existing property change events.
140    */
 
141  496 toggle public void clearPropertyChangeEvents() {
142  496 this.propertyChangeEvents = new ArrayList();
143    }
144   
145    /**
146    * Determines whether this class has had properties changed since it
147    * was last persisted.
148    *
149    * @return true if properties have changed, false otherwise
150    */
 
151  152 toggle public boolean isDirty() {
152  152 return !propertyChangeEvents.isEmpty();
153    }
154   
155    /**
156    * Gets the list of property change events.
157    *
158    * @return a List of PropertyChangeEvent instances
159    */
 
160  36 toggle public List getPropertyChangeEvents() {
161  36 return (List)propertyChangeEvents.clone();
162    }
163   
164    /**
165    * Adds an event to the list.
166    *
167    * @param event a PebbleEvent instance
168    */
 
169  252 toggle synchronized void addEvent(PebbleEvent event) {
170  252 events.add(event);
171    }
172   
173    /**
174    * Inserts an event to the list into the front of the list.
175    *
176    * @param event a PebbleEvent instance
177    */
 
178  306 toggle synchronized void insertEvent(PebbleEvent event) {
179  306 events.add(0, event);
180    }
181   
182    /**
183    * Determines whether this object has outstanding events.
184    *
185    * @return true if events are outstanding, false otherwise
186    */
 
187  1356 toggle public synchronized boolean hasEvents() {
188  1356 return !events.isEmpty();
189    }
190   
191    /**
192    * Gets the next event to be handled.
193    *
194    * @return a PebbleEvent instance, or null if no more events
195    */
 
196  492 toggle public synchronized PebbleEvent nextEvent() {
197  492 if (hasEvents()) {
198  492 return events.remove(0);
199    } else {
200  0 return null;
201    }
202    }
203   
 
204  636 toggle synchronized void clearEvents() {
205  636 events = new ArrayList<PebbleEvent>();
206    }
207   
 
208  4 toggle public synchronized List<PebbleEvent> getEvents() {
209  4 return new ArrayList<PebbleEvent>(events);
210    }
211   
212    }