File Source: WeblogEntry.java
/*
P/P * Method: void readObject(ObjectInputStream)
*
* Preconditions:
* Param_1 != null
*
* Presumptions:
* init'ed(org.apache.openjpa.enhance.PersistenceCapable.DESERIALIZED)
*
* Postconditions:
* Param_0.pcDetachedState == org.apache.openjpa.enhance.PersistenceCapable.DESERIALIZED
* (soft) init'ed(Param_0.pcDetachedState)
*/
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.pojos;
20
21 import java.io.Serializable;
22 import java.io.UnsupportedEncodingException;
23 import java.net.URLEncoder;
24 import java.sql.Timestamp;
25 import java.text.SimpleDateFormat;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.Calendar;
29 import java.util.Date;
30 import java.util.HashMap;
31 import java.util.HashSet;
32 import java.util.Iterator;
33 import java.util.List;
34 import java.util.Locale;
35 import java.util.Map;
36 import java.util.Set;
37 import java.util.StringTokenizer;
38 import java.util.TreeSet;
39
40 import org.apache.commons.lang.StringEscapeUtils;
41
42 import org.apache.commons.lang.StringUtils;
43 import org.apache.commons.lang.builder.EqualsBuilder;
44 import org.apache.commons.lang.builder.HashCodeBuilder;
45 import org.apache.commons.logging.Log;
46 import org.apache.commons.logging.LogFactory;
47 import org.apache.roller.weblogger.WebloggerException;
48 import org.apache.roller.weblogger.config.WebloggerRuntimeConfig;
49 import org.apache.roller.weblogger.business.WebloggerFactory;
50 import org.apache.roller.weblogger.business.plugins.entry.WeblogEntryPlugin;
51 import org.apache.roller.weblogger.business.WeblogManager;
52 import org.apache.roller.util.DateUtil;
53 import org.apache.roller.weblogger.util.I18nMessages;
54 import org.apache.roller.util.UUIDGenerator;
55 import org.apache.roller.weblogger.util.Utilities;
56
57 /**
58 * Represents a Weblog Entry.
59 *
60 * @ejb:bean name="WeblogEntry"
61 * @struts.form include-all="true"
62 * @hibernate.class lazy="true" table="weblogentry"
63 * @hibernate.cache usage="read-write"
64 */
65 public class WeblogEntry implements Serializable {
/*
P/P * Method: org.apache.roller.weblogger.pojos.WeblogEntry__static_init
*
* Presumptions:
* org.apache.commons.logging.LogFactory:getFactory(...)@66 != null
*
* Postconditions:
* init'ed(mLogger)
* pcFieldFlags == &new byte[](WeblogEntry__static_init#3)
* pcFieldNames == &new String[](WeblogEntry__static_init#1)
* pcFieldTypes == &new Class[](WeblogEntry__static_init#2)
* new Class[](WeblogEntry__static_init#2) num objects == 1
* new String[](WeblogEntry__static_init#1) num objects == 1
* new byte[](WeblogEntry__static_init#3) num objects == 1
* pcFieldTypes.length == 22
* pcFieldNames.length == 22
* pcFieldFlags.length == 22
* ...
*/
66 private static Log mLogger =
67 LogFactory.getFactory().getInstance(WeblogEntry.class);
68
69 public static final long serialVersionUID = 2341505386843044125L;
70
71 public static final String DRAFT = "DRAFT";
72 public static final String PUBLISHED = "PUBLISHED";
73 public static final String PENDING = "PENDING";
74 public static final String SCHEDULED = "SCHEDULED";
75
76 // Simple properies
77 private String id = UUIDGenerator.generateUUID();
78 private String title = null;
79 private String link = null;
80 private String summary = null;
81 private String text = null;
82 private String contentType = null;
83 private String contentSrc = null;
84 private String anchor = null;
85 private Timestamp pubTime = null;
86 private Timestamp updateTime = null;
87 private String plugins = null;
88 private Boolean allowComments = Boolean.TRUE;
89 private Integer commentDays = new Integer(7);
90 private Boolean rightToLeft = Boolean.FALSE;
91 private Boolean pinnedToMain = Boolean.FALSE;
92 private String status = DRAFT;
93 private String locale = null;
94
95 // Associated objects
96 private User creator = null;
97 private Weblog website = null;
98 private WeblogCategory category = null;
99
100 // Collection of name/value entry attributes
101 private Set attSet = new TreeSet();
102
103 private Set tagSet = new HashSet();
104 private Set removedTags = new HashSet();
105 private Set addedTags = new HashSet();
106
107 //----------------------------------------------------------- Construction
108
/*
P/P * Method: void org.apache.roller.weblogger.pojos.WeblogEntry()
*
* Presumptions:
* init'ed(java.lang.Boolean.FALSE)
* init'ed(java.lang.Boolean.TRUE)
*
* Postconditions:
* this.addedTags == &new HashSet(WeblogEntry#5)
* this.allowComments == java.lang.Boolean.TRUE
* (soft) init'ed(this.allowComments)
* this.anchor == null
* this.category == null
* this.contentSrc == null
* this.contentType == null
* this.creator == null
* this.link == null
* this.locale == null
* ...
*/
109 public WeblogEntry() {
110 }
111
112 public WeblogEntry(
113 String id,
114 WeblogCategory category,
115 Weblog website,
116 User creator,
117 String title,
118 String link,
119 String text,
120 String anchor,
121 Timestamp pubTime,
122 Timestamp updateTime,
/*
P/P * Method: void org.apache.roller.weblogger.pojos.WeblogEntry(String, WeblogCategory, Weblog, User, String, String, String, String, Timestamp, Timestamp, String)
*
* Presumptions:
* init'ed(java.lang.Boolean.FALSE)
* init'ed(java.lang.Boolean.TRUE)
*
* Postconditions:
* this.addedTags == &new HashSet(WeblogEntry#5)
* this.allowComments == java.lang.Boolean.TRUE
* (soft) init'ed(this.allowComments)
* this.anchor == anchor
* init'ed(this.anchor)
* this.attSet == &new TreeSet(WeblogEntry#2)
* this.category == category
* init'ed(this.category)
* this.commentDays == &new Integer(WeblogEntry#1)
* this.contentSrc == null
* ...
*/
123 String status) {
124 //this.id = id;
125 this.category = category;
126 this.website = website;
127 this.creator = creator;
128 this.title = title;
129 this.link = link;
130 this.text = text;
131 this.anchor = anchor;
132 this.pubTime = pubTime;
133 this.updateTime = updateTime;
134 this.status = status;
135 }
136
/*
P/P * Method: void org.apache.roller.weblogger.pojos.WeblogEntry(WeblogEntry)
*
* Preconditions:
* otherData != null
* init'ed(otherData.allowComments)
* init'ed(otherData.anchor)
* init'ed(otherData.category)
* init'ed(otherData.commentDays)
* init'ed(otherData.creator)
* init'ed(otherData.id)
* init'ed(otherData.link)
* init'ed(otherData.locale)
* init'ed(otherData.pcStateManager)
* ...
*
* Presumptions:
* init'ed(java.lang.Boolean.FALSE)
* init'ed(java.lang.Boolean.TRUE)
*
* Postconditions:
* this.addedTags == &new HashSet(WeblogEntry#5)
* this.allowComments == otherData.allowComments
* init'ed(this.allowComments)
* this.anchor == otherData.anchor
* init'ed(this.anchor)
* this.attSet == &new TreeSet(WeblogEntry#2)
* this.category == otherData.category
* init'ed(this.category)
* this.commentDays == otherData.commentDays
* init'ed(this.commentDays)
* ...
*/
137 public WeblogEntry(WeblogEntry otherData) {
138 this.setData(otherData);
139 }
140
141 //---------------------------------------------------------- Initializaion
142
143 /**
144 * Set bean properties based on other bean.
145 */
146 public void setData(WeblogEntry other) {
147
/*
P/P * Method: void setData(WeblogEntry)
*
* Preconditions:
* other != null
* init'ed(other.allowComments)
* init'ed(other.anchor)
* init'ed(other.category)
* init'ed(other.commentDays)
* init'ed(other.creator)
* init'ed(other.id)
* init'ed(other.link)
* init'ed(other.locale)
* init'ed(other.pcStateManager)
* ...
*
* Postconditions:
* this.allowComments == other.allowComments
* init'ed(this.allowComments)
* this.anchor == other.anchor
* init'ed(this.anchor)
* this.category == other.category
* init'ed(this.category)
* this.commentDays == other.commentDays
* init'ed(this.commentDays)
* this.creator == other.creator
* init'ed(this.creator)
* ...
*/
148 this.id = other.getId();
149 this.category = other.getCategory();
150 this.website = other.getWebsite();
151 this.creator = other.getCreator();
152 this.title = other.getTitle();
153 this.link = other.getLink();
154 this.text = other.getText();
155 this.anchor = other.getAnchor();
156 this.pubTime = other.getPubTime();
157 this.updateTime = other.getUpdateTime();
158 this.status = other.getStatus();
159 this.plugins = other.getPlugins();
160 this.allowComments = other.getAllowComments();
161 this.commentDays = other.getCommentDays();
162 this.rightToLeft = other.getRightToLeft();
163 this.pinnedToMain = other.getPinnedToMain();
164 this.locale = other.getLocale();
165 }
166
167 //------------------------------------------------------- Good citizenship
168
169 public String toString() {
/*
P/P * Method: String toString()
*
* Preconditions:
* init'ed(this.anchor)
* init'ed(this.id)
* init'ed(this.pubTime)
* init'ed(this.title)
*
* Postconditions:
* java.lang.StringBuffer:toString(...)._tainted == this.title._tainted | this.id._tainted | this.anchor._tainted
* init'ed(java.lang.StringBuffer:toString(...)._tainted)
* return_value == &java.lang.StringBuffer:toString(...)
*/
170 StringBuffer buf = new StringBuffer();
171 buf.append("{");
172 buf.append(this.id);
173 buf.append(", ").append(this.anchor);
174 buf.append(", ").append(this.title);
175 buf.append(", ").append(this.pubTime);
176 buf.append("}");
177 return buf.toString();
178 }
179
180 public boolean equals(Object other) {
/*
P/P * Method: bool equals(Object)
*
* Preconditions:
* (soft) init'ed(other.anchor)
* (soft) init'ed(other.pcStateManager)
* (soft) init'ed(other.website)
* (soft) pcInheritedFieldCount <= 232-22
* (soft) init'ed(this.anchor)
* (soft) init'ed(this.pcStateManager)
* (soft) init'ed(this.website)
*
* Presumptions:
* org.apache.commons.lang.builder.EqualsBuilder:append(...)@184 != null
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* other == this: {0}, {1}
*/
181 if (other == this) return true;
182 if (other instanceof WeblogEntry != true) return false;
183 WeblogEntry o = (WeblogEntry)other;
184 return new EqualsBuilder()
185 .append(getAnchor(), o.getAnchor())
186 .append(getWebsite(), o.getWebsite())
187 .isEquals();
188 }
189
190 public int hashCode() {
/*
P/P * Method: int hashCode()
*
* Preconditions:
* init'ed(this.anchor)
* init'ed(this.pcStateManager)
* init'ed(this.website)
* (soft) pcInheritedFieldCount <= 232-22
*
* Presumptions:
* org.apache.commons.lang.builder.HashCodeBuilder:append(...)@191 != null
*
* Postconditions:
* init'ed(return_value)
*/
191 return new HashCodeBuilder()
192 .append(getAnchor())
193 .append(getWebsite())
194 .toHashCode();
195 }
196
197 //------------------------------------------------------ Simple properties
198
199 /**
200 * @roller.wrapPojoMethod type="simple"
201 * @ejb:persistent-field
202 * @hibernate.id column="id" generator-class="assigned"
203 */
204 public String getId() {
/*
P/P * Method: String pcgetId()
*
* Preconditions:
* init'ed(this.id)
*
* Postconditions:
* return_value == this.id
* init'ed(return_value)
*/
205 return this.id;
206 }
207
208 /** @ejb:persistent-field */
209 public void setId(String id) {
210 // Form bean workaround: empty string is never a valid id
/*
P/P * Method: void pcsetId(String)
*
* Postconditions:
* this.id == One-of{old this.id, Param_1}
*
* Test Vectors:
* Param_1: Addr_Set{null}, Inverse{null}
* java.lang.String:length(...)@211: {1..232-1}, {0}
*/
211 if (id != null && id.trim().length() == 0) return;
212 this.id = id;
213 }
214
215 /**
216 * @roller.wrapPojoMethod type="pojo"
217 * @ejb:persistent-field
218 * @hibernate.many-to-one column="categoryid" cascade="none" not-null="true"
219 */
220 public WeblogCategory getCategory() {
/*
P/P * Method: WeblogCategory pcgetCategory()
*
* Preconditions:
* init'ed(this.category)
*
* Postconditions:
* return_value == this.category
* init'ed(return_value)
*/
221 return this.category;
222 }
223
224 /** @ejb:persistent-field */
225 public void setCategory(WeblogCategory category) {
/*
P/P * Method: void pcsetCategory(WeblogCategory)
*
* Postconditions:
* this.category == Param_1
* init'ed(this.category)
*/
226 this.category = category;
227 }
228
229 /**
230 * Return collection of WeblogCategory objects of this entry.
231 * Added for symetry with PlanetEntryData object.
232 *
233 * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.weblogger.pojos.WeblogCategory"
234 */
235 public List getCategories() {
/*
P/P * Method: List getCategories()
*
* Preconditions:
* init'ed(this.category)
* init'ed(this.pcStateManager)
* (soft) pcInheritedFieldCount <= 232-3
*
* Postconditions:
* return_value == &new ArrayList(getCategories#1)
* new ArrayList(getCategories#1) num objects == 1
*/
236 List cats = new ArrayList();
237 cats.add(getCategory());
238 return cats;
239 }
240
241 /** No-op method to please XDoclet */
242 public void setCategories(List cats) {
243 // no-op
/*
P/P * Method: void setCategories(List)
*/
244 }
245
246 /**
247 * @roller.wrapPojoMethod type="pojo"
248 * @ejb:persistent-field
249 * @hibernate.many-to-one column="websiteid" cascade="none" not-null="true"
250 */
251 public Weblog getWebsite() {
/*
P/P * Method: Weblog pcgetWebsite()
*
* Preconditions:
* init'ed(this.website)
*
* Postconditions:
* return_value == this.website
* init'ed(return_value)
*/
252 return this.website;
253 }
254
255 /** @ejb:persistent-field */
256 public void setWebsite(Weblog website) {
/*
P/P * Method: void pcsetWebsite(Weblog)
*
* Postconditions:
* this.website == Param_1
* init'ed(this.website)
*/
257 this.website = website;
258 }
259
260 /**
261 * @roller.wrapPojoMethod type="simple"
262 * @ejb:persistent-field
263 * @hibernate.many-to-one column="userid" cascade="none" not-null="true"
264 */
265 public User getCreator() {
/*
P/P * Method: User pcgetCreator()
*
* Preconditions:
* init'ed(this.creator)
*
* Postconditions:
* return_value == this.creator
* init'ed(return_value)
*/
266 return this.creator;
267 }
268
269 /** @ejb:persistent-field */
270 public void setCreator(User creator) {
/*
P/P * Method: void pcsetCreator(User)
*
* Postconditions:
* this.creator == Param_1
* init'ed(this.creator)
*/
271 this.creator = creator;
272 }
273
274 /**
275 * @roller.wrapPojoMethod type="simple"
276 * @ejb:persistent-field
277 * @hibernate.property column="title" non-null="true" unique="false"
278 */
279 public String getTitle() {
/*
P/P * Method: String pcgetTitle()
*
* Preconditions:
* init'ed(this.title)
*
* Postconditions:
* return_value == this.title
* init'ed(return_value)
*/
280 return this.title;
281 }
282
283 /** @ejb:persistent-field */
284 public void setTitle(String title) {
/*
P/P * Method: void pcsetTitle(String)
*
* Postconditions:
* this.title == Param_1
* init'ed(this.title)
*/
285 this.title = title;
286 }
287
288 /**
289 * Get summary for weblog entry (maps to RSS description and Atom summary).
290 * @roller.wrapPojoMethod type="simple"
291 * @ejb:persistent-field
292 * @hibernate.property column="summary" non-null="false" unique="false"
293 */
294 public String getSummary() {
/*
P/P * Method: String pcgetSummary()
*
* Preconditions:
* init'ed(this.summary)
*
* Postconditions:
* return_value == this.summary
* init'ed(return_value)
*/
295 return summary;
296 }
297
298 /**
299 * Set summary for weblog entry (maps to RSS description and Atom summary).
300 * @ejb:persistent-field
301 */
302 public void setSummary(String summary) {
/*
P/P * Method: void pcsetSummary(String)
*
* Postconditions:
* this.summary == Param_1
* init'ed(this.summary)
*/
303 this.summary = summary;
304 }
305
306 /**
307 * Get content text for weblog entry (maps to RSS content:encoded and Atom content).
308 * @roller.wrapPojoMethod type="simple"
309 * @ejb:persistent-field
310 * @hibernate.property column="text" non-null="true" unique="false"
311 */
312 public String getText() {
/*
P/P * Method: String pcgetText()
*
* Preconditions:
* init'ed(this.text)
*
* Postconditions:
* return_value == this.text
* init'ed(return_value)
*/
313 return this.text;
314 }
315
316 /**
317 * Set content text for weblog entry (maps to RSS content:encoded and Atom content).
318 * @ejb:persistent-field
319 */
320 public void setText(String text) {
/*
P/P * Method: void pcsetText(String)
*
* Postconditions:
* this.text == Param_1
* init'ed(this.text)
*/
321 this.text = text;
322 }
323
324 /**
325 * Get content type (text, html, xhtml or a MIME content type)
326 * @roller.wrapPojoMethod type="simple"
327 * @ejb:persistent-field
328 * @hibernate.property column="content_type" non-null="false" unique="false"
329 */
330 public String getContentType() {
/*
P/P * Method: String pcgetContentType()
*
* Preconditions:
* init'ed(this.contentType)
*
* Postconditions:
* return_value == this.contentType
* init'ed(return_value)
*/
331 return contentType;
332 }
333
334 /**
335 * Set content type (text, html, xhtml or a MIME content type)
336 * @ejb:persistent-field
337 */
338 public void setContentType(String contentType) {
/*
P/P * Method: void pcsetContentType(String)
*
* Postconditions:
* this.contentType == Param_1
* init'ed(this.contentType)
*/
339 this.contentType = contentType;
340 }
341
342 /**
343 * Get URL for out-of-line content.
344 * @roller.wrapPojoMethod type="simple"
345 * @ejb:persistent-field
346 * @hibernate.property column="content_src" non-null="false" unique="false"
347 */
348 public String getContentSrc() {
/*
P/P * Method: String pcgetContentSrc()
*
* Preconditions:
* init'ed(this.contentSrc)
*
* Postconditions:
* return_value == this.contentSrc
* init'ed(return_value)
*/
349 return contentSrc;
350 }
351
352 /**
353 * Set URL for out-of-line content.
354 * @ejb:persistent-field
355 */
356 public void setContentSrc(String contentSrc) {
/*
P/P * Method: void pcsetContentSrc(String)
*
* Postconditions:
* this.contentSrc == Param_1
* init'ed(this.contentSrc)
*/
357 this.contentSrc = contentSrc;
358 }
359
360 /**
361 * @roller.wrapPojoMethod type="simple"
362 * @ejb:persistent-field
363 * @hibernate.property column="anchor" non-null="true" unique="false"
364 */
365 public String getAnchor() {
/*
P/P * Method: String pcgetAnchor()
*
* Preconditions:
* init'ed(this.anchor)
*
* Postconditions:
* return_value == this.anchor
* init'ed(return_value)
*/
366 return this.anchor;
367 }
368
369 /** @ejb:persistent-field */
370 public void setAnchor(String anchor) {
/*
P/P * Method: void pcsetAnchor(String)
*
* Postconditions:
* this.anchor == Param_1
* init'ed(this.anchor)
*/
371 this.anchor = anchor;
372 }
373
374 //-------------------------------------------------------------------------
375 /**
376 * Map attributes as set because XDoclet 1.2b4 map support is broken.
377 *
378 * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.weblogger.pojos.WeblogEntryAttribute"
379 * @ejb:persistent-field
380 * @hibernate.set lazy="true" order-by="name" inverse="true" cascade="all"
381 * @hibernate.collection-key column="entryid" type="String"
382 * @hibernate.collection-one-to-many class="org.apache.roller.weblogger.pojos.WeblogEntryAttribute"
383 */
384 public Set getEntryAttributes() {
/*
P/P * Method: Set pcgetEntryAttributes()
*
* Preconditions:
* init'ed(this.attSet)
*
* Postconditions:
* return_value == this.attSet
* init'ed(return_value)
*/
385 return attSet;
386 }
387 /** @ejb:persistent-field */
388 public void setEntryAttributes(Set atts) {
/*
P/P * Method: void pcsetEntryAttributes(Set)
*
* Postconditions:
* this.attSet == Param_1
* init'ed(this.attSet)
*/
389 this.attSet = atts;
390 }
391
392
393 /**
394 * Would be named getEntryAttribute, but that would set off XDoclet
395 *
396 * @roller.wrapPojoMethod type="simple"
397 */
398 public String findEntryAttribute(String name) {
/*
P/P * Method: String findEntryAttribute(String)
*
* Preconditions:
* init'ed(this.attSet)
* init'ed(this.pcStateManager)
* (soft) name != null
* (soft) org/apache/roller/weblogger/pojos/WeblogEntryAttribute.pcInheritedFieldCount <= 232-4
* (soft) pcInheritedFieldCount <= 232-8
*
* Presumptions:
* java.util.Iterator:next(...)@401 != null
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* this.attSet: Addr_Set{null}, Inverse{null}
* java.lang.String:equals(...)@402: {0}, {1}
* java.util.Iterator:hasNext(...)@400: {0}, {1}
*/
399 if (getEntryAttributes() != null) {
400 for (Iterator it = getEntryAttributes().iterator(); it.hasNext(); ) {
401 WeblogEntryAttribute att = (WeblogEntryAttribute) it.next();
402 if (name.equals(att.getName())) return att.getValue();
403 }
404 }
405 return null;
406 }
407
408 public void putEntryAttribute(String name, String value) throws Exception {
/*
P/P * Method: void putEntryAttribute(String, String)
*
* Preconditions:
* this.attSet != null
* init'ed(this.pcStateManager)
* (soft) name != null
* (soft) org/apache/roller/weblogger/pojos/WeblogEntryAttribute.pcInheritedFieldCount <= 232-4
* (soft) pcInheritedFieldCount <= 232-8
*
* Presumptions:
* java.util.Iterator:next(...)@411 != null
*
* Test Vectors:
* java.lang.String:equals(...)@412: {0}, {1}
* java.util.Iterator:hasNext(...)@410: {0}, {1}
*/
409 WeblogEntryAttribute att = null;
410 for (Iterator it = getEntryAttributes().iterator(); it.hasNext(); ) {
411 WeblogEntryAttribute o = (WeblogEntryAttribute) it.next();
412 if (name.equals(o.getName())) {
413 att = o;
414 break;
415 }
416 }
417 if (att == null) {
418 att = new WeblogEntryAttribute();
419 att.setEntry(this);
420 att.setName(name);
421 att.setValue(value);
422 getEntryAttributes().add(att);
423 } else {
424 att.setValue(value);
425 }
426 }
427
428 //-------------------------------------------------------------------------
429
430 /**
431 * <p>Publish time is the time that an entry is to be (or was) made available
432 * for viewing by newsfeed readers and visitors to the Roller site.</p>
433 *
434 * <p>Roller stores time using the timeZone of the server itself. When
435 * times are displayed in a user's weblog they must be translated
436 * to the user's timeZone.</p>
437 *
438 * <p>NOTE: Times are stored using the SQL TIMESTAMP datatype, which on
439 * MySQL has only a one-second resolution.</p>
440 *
441 * @roller.wrapPojoMethod type="simple"
442 * @ejb:persistent-field
443 * @hibernate.property column="pubtime" non-null="true" unique="false"
444 */
445 public Timestamp getPubTime() {
/*
P/P * Method: Timestamp pcgetPubTime()
*
* Preconditions:
* init'ed(this.pubTime)
*
* Postconditions:
* return_value == this.pubTime
* init'ed(return_value)
*/
446 return this.pubTime;
447 }
448
449 /** @ejb:persistent-field */
450 public void setPubTime(Timestamp pubTime) {
/*
P/P * Method: void pcsetPubTime(Timestamp)
*
* Postconditions:
* this.pubTime == Param_1
* init'ed(this.pubTime)
*/
451 this.pubTime = pubTime;
452 }
453
454 /**
455 * <p>Update time is the last time that an weblog entry was saved in the
456 * Roller weblog editor or via web services API (XML-RPC or Atom).</p>
457 *
458 * <p>Roller stores time using the timeZone of the server itself. When
459 * times are displayed in a user's weblog they must be translated
460 * to the user's timeZone.</p>
461 *
462 * <p>NOTE: Times are stored using the SQL TIMESTAMP datatype, which on
463 * MySQL has only a one-second resolution.</p>
464 *
465 * @roller.wrapPojoMethod type="simple"
466 * @ejb:persistent-field
467 * @hibernate.property column="updatetime" non-null="true" unique="false"
468 */
469 public Timestamp getUpdateTime() {
/*
P/P * Method: Timestamp pcgetUpdateTime()
*
* Preconditions:
* init'ed(this.updateTime)
*
* Postconditions:
* return_value == this.updateTime
* init'ed(return_value)
*/
470 return this.updateTime;
471 }
472
473 /** @ejb:persistent-field */
474 public void setUpdateTime(Timestamp updateTime) {
/*
P/P * Method: void pcsetUpdateTime(Timestamp)
*
* Postconditions:
* this.updateTime == Param_1
* init'ed(this.updateTime)
*/
475 this.updateTime = updateTime;
476 }
477
478 /**
479 * @roller.wrapPojoMethod type="simple"
480 * @ejb:persistent-field
481 * @hibernate.property column="status" non-null="true" unique="false"
482 */
483 public String getStatus() {
/*
P/P * Method: String pcgetStatus()
*
* Preconditions:
* init'ed(this.status)
*
* Postconditions:
* return_value == this.status
* init'ed(return_value)
*/
484 return this.status;
485 }
486
487 /** @ejb:persistent-field */
488 public void setStatus(String status) {
/*
P/P * Method: void pcsetStatus(String)
*
* Postconditions:
* this.status == Param_1
* init'ed(this.status)
*/
489 this.status = status;
490 }
491
492 /**
493 * Some weblog entries are about one specific link.
494 * @return Returns the link.
495 *
496 * @roller.wrapPojoMethod type="simple"
497 * @ejb:persistent-field
498 * @hibernate.property column="link" non-null="false" unique="false"
499 */
500 public String getLink() {
/*
P/P * Method: String pcgetLink()
*
* Preconditions:
* init'ed(this.link)
*
* Postconditions:
* return_value == this.link
* init'ed(return_value)
*/
501 return link;
502 }
503
504 /**
505 * @ejb:persistent-field
506 * @param link The link to set.
507 */
508 public void setLink(String link) {
/*
P/P * Method: void pcsetLink(String)
*
* Postconditions:
* this.link == Param_1
* init'ed(this.link)
*/
509 this.link = link;
510 }
511
512 /**
513 * Comma-delimited list of this entry's Plugins.
514 *
515 * @roller.wrapPojoMethod type="simple"
516 * @ejb:persistent-field
517 * @hibernate.property column="plugins" non-null="false" unique="false"
518 */
519 public String getPlugins() {
/*
P/P * Method: String pcgetPlugins()
*
* Preconditions:
* init'ed(this.plugins)
*
* Postconditions:
* return_value == this.plugins
* init'ed(return_value)
*/
520 return plugins;
521 }
522
523 /** @ejb:persistent-field */
524 public void setPlugins(String string) {
/*
P/P * Method: void pcsetPlugins(String)
*
* Postconditions:
* this.plugins == Param_1
* init'ed(this.plugins)
*/
525 plugins = string;
526 }
527
528
529 /**
530 * True if comments are allowed on this weblog entry.
531 *
532 * @roller.wrapPojoMethod type="simple"
533 * @ejb:persistent-field
534 * @hibernate.property column="allowcomments" non-null="true" unique="false"
535 */
536 public Boolean getAllowComments() {
/*
P/P * Method: Boolean pcgetAllowComments()
*
* Preconditions:
* init'ed(this.allowComments)
*
* Postconditions:
* return_value == this.allowComments
* init'ed(return_value)
*/
537 return allowComments;
538 }
539 /**
540 * True if comments are allowed on this weblog entry.
541 * @ejb:persistent-field
542 */
543 public void setAllowComments(Boolean allowComments) {
/*
P/P * Method: void pcsetAllowComments(Boolean)
*
* Postconditions:
* this.allowComments == Param_1
* init'ed(this.allowComments)
*/
544 this.allowComments = allowComments;
545 }
546
547 /**
548 * Number of days after pubTime that comments should be allowed, or 0 for no limit.
549 *
550 * @roller.wrapPojoMethod type="simple"
551 * @ejb:persistent-field
552 * @hibernate.property column="commentdays" non-null="true" unique="false"
553 */
554 public Integer getCommentDays() {
/*
P/P * Method: Integer pcgetCommentDays()
*
* Preconditions:
* init'ed(this.commentDays)
*
* Postconditions:
* return_value == this.commentDays
* init'ed(return_value)
*/
555 return commentDays;
556 }
557 /**
558 * Number of days after pubTime that comments should be allowed, or 0 for no limit.
559 * @ejb:persistent-field
560 */
561 public void setCommentDays(Integer commentDays) {
/*
P/P * Method: void pcsetCommentDays(Integer)
*
* Postconditions:
* this.commentDays == Param_1
* init'ed(this.commentDays)
*/
562 this.commentDays = commentDays;
563 }
564
565 /**
566 * True if this entry should be rendered right to left.
567 *
568 * @roller.wrapPojoMethod type="simple"
569 * @ejb:persistent-field
570 * @hibernate.property column="righttoleft" non-null="true" unique="false"
571 */
572 public Boolean getRightToLeft() {
/*
P/P * Method: Boolean pcgetRightToLeft()
*
* Preconditions:
* init'ed(this.rightToLeft)
*
* Postconditions:
* return_value == this.rightToLeft
* init'ed(return_value)
*/
573 return rightToLeft;
574 }
575 /**
576 * True if this entry should be rendered right to left.
577 * @ejb:persistent-field
578 */
579 public void setRightToLeft(Boolean rightToLeft) {
/*
P/P * Method: void pcsetRightToLeft(Boolean)
*
* Postconditions:
* this.rightToLeft == Param_1
* init'ed(this.rightToLeft)
*/
580 this.rightToLeft = rightToLeft;
581 }
582
583 /**
584 * True if story should be pinned to the top of the Roller site main blog.
585 * @return Returns the pinned.
586 *
587 * @roller.wrapPojoMethod type="simple"
588 * @ejb:persistent-field
589 * @hibernate.property column="pinnedtomain" non-null="true" unique="false"
590 */
591 public Boolean getPinnedToMain() {
/*
P/P * Method: Boolean pcgetPinnedToMain()
*
* Preconditions:
* init'ed(this.pinnedToMain)
*
* Postconditions:
* return_value == this.pinnedToMain
* init'ed(return_value)
*/
592 return pinnedToMain;
593 }
594 /**
595 * True if story should be pinned to the top of the Roller site main blog.
596 * @param pinnedToMain The pinned to set.
597 *
598 * @ejb:persistent-field
599 */
600 public void setPinnedToMain(Boolean pinnedToMain) {
/*
P/P * Method: void pcsetPinnedToMain(Boolean)
*
* Postconditions:
* this.pinnedToMain == Param_1
* init'ed(this.pinnedToMain)
*/
601 this.pinnedToMain = pinnedToMain;
602 }
603
604
605 /**
606 * The locale string that defines the i18n approach for this entry.
607 *
608 * @roller.wrapPojoMethod type="simple"
609 * @ejb:persistent-field
610 * @hibernate.property column="locale" non-null="false" unique="false"
611 */
612 public String getLocale() {
/*
P/P * Method: String pcgetLocale()
*
* Preconditions:
* init'ed(this.locale)
*
* Postconditions:
* return_value == this.locale
* init'ed(return_value)
*/
613 return locale;
614 }
615
616
617 public void setLocale(String locale) {
/*
P/P * Method: void pcsetLocale(String)
*
* Postconditions:
* this.locale == Param_1
* init'ed(this.locale)
*/
618 this.locale = locale;
619 }
620
621 /**
622 * @ejb:persistent-field
623 *
624 * @hibernate.set lazy="true" order-by="name" inverse="true" cascade="all"
625 * @hibernate.collection-key column="entryid"
626 * @hibernate.collection-one-to-many class="org.apache.roller.weblogger.pojos.WeblogEntryTag"
627 */
628 public Set getTags()
629 {
/*
P/P * Method: Set pcgetTags()
*
* Preconditions:
* init'ed(this.tagSet)
*
* Postconditions:
* return_value == this.tagSet
* init'ed(return_value)
*/
630 return tagSet;
631 }
632
633 private void setTags(Set tagSet) throws WebloggerException
634 {
/*
P/P * Method: void pcsetTags(Set)
*
* Postconditions:
* this.addedTags == &new HashSet(pcsetTags#2)
* this.removedTags == &new HashSet(pcsetTags#1)
* this.tagSet == Param_1
* init'ed(this.tagSet)
* new HashSet(pcsetTags#1) num objects == 1
* new HashSet(pcsetTags#2) num objects == 1
*/
635 this.tagSet = tagSet;
636 this.removedTags = new HashSet();
637 this.addedTags = new HashSet();
638 }
639
640 /**
641 * Roller lowercases all tags based on locale because there's not a 1:1 mapping
642 * between uppercase/lowercase characters across all languages.
643 * @param name
644 * @throws WebloggerException
645 */
646 public void addTag(String name) throws WebloggerException {
/*
P/P * Method: void addTag(String)
*
* Preconditions:
* init'ed(this.pcStateManager)
* init'ed(this.website)
* (soft) org/apache/roller/weblogger/pojos/WeblogEntryTag.pcInheritedFieldCount <= 232-6
* (soft) pcInheritedFieldCount <= 232-22
* (soft) this.addedTags != null
* (soft) init'ed(this.creator)
* (soft) this.tagSet != null
* (soft) init'ed(this.updateTime)
*
* Presumptions:
* java.util.Iterator:next(...)@653 != null
* org.apache.roller.weblogger.util.Utilities:normalizeTag(...)@648 != null
* tag.name@653 != null
*
* Test Vectors:
* this.website: Addr_Set{null}, Inverse{null}
* java.lang.String:equals(...)@654: {0}, {1}
* java.lang.String:length(...)@649: {1..232-1}, {0}
* java.util.Iterator:hasNext(...)@652: {0}, {1}
*/
647 Locale locale = getWebsite() != null ? getWebsite().getLocaleInstance() : Locale.getDefault();
648 name = Utilities.normalizeTag(name, locale);
649 if(name.length() == 0)
650 return;
651
652 for (Iterator it = getTags().iterator(); it.hasNext();) {
653 WeblogEntryTag tag = (WeblogEntryTag) it.next();
654 if (tag.getName().equals(name))
655 return;
656 }
657
658 WeblogEntryTag tag = new WeblogEntryTag();
659 tag.setName(name);
660 tag.setUser(getCreator());
661 tag.setWeblog(getWebsite());
662 tag.setWeblogEntry(this);
663 tag.setTime(getUpdateTime());
664 tagSet.add(tag);
665
666 addedTags.add(name);
667 }
668
669 public void onRemoveTag(String name) throws WebloggerException {
/*
P/P * Method: void onRemoveTag(String)
*
* Preconditions:
* this.removedTags != null
*/
670 removedTags.add(name);
671 }
672
673 public Set getAddedTags() {
/*
P/P * Method: Set getAddedTags()
*
* Preconditions:
* init'ed(this.addedTags)
*
* Postconditions:
* return_value == this.addedTags
* init'ed(return_value)
*/
674 return addedTags;
675 }
676
677 public Set getRemovedTags() {
/*
P/P * Method: Set getRemovedTags()
*
* Preconditions:
* init'ed(this.removedTags)
*
* Postconditions:
* return_value == this.removedTags
* init'ed(return_value)
*/
678 return removedTags;
679 }
680
681 public void updateTags(List tags) throws WebloggerException {
682
/*
P/P * Method: void updateTags(List)
*
* Preconditions:
* (soft) org/apache/roller/weblogger/pojos/WeblogEntryTag.pcInheritedFieldCount <= 232-6
* (soft) pcInheritedFieldCount <= 232-22
* (soft) this.addedTags != null
* (soft) init'ed(this.creator)
* (soft) init'ed(this.pcStateManager)
* (soft) this.tagSet != null
* (soft) init'ed(this.updateTime)
* (soft) init'ed(this.website)
*
* Presumptions:
* java.util.Iterator:next(...)@698 != null
* org.apache.roller.weblogger.business.Weblogger:getWeblogManager(...)@706 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@706 != null
*
* Test Vectors:
* tags: Inverse{null}, Addr_Set{null}
* this.website: Addr_Set{null}, Inverse{null}
* java.util.HashSet:contains(...)@699: {1}, {0}
* java.util.Iterator:hasNext(...)@689: {0}, {1}
* java.util.Iterator:hasNext(...)@697: {0}, {1}
* java.util.Iterator:hasNext(...)@707: {0}, {1}
* java.util.Iterator:hasNext(...)@711: {0}, {1}
*/
683 if(tags == null)
684 return;
685
686 HashSet newTags = new HashSet(tags.size());
687 Locale locale = getWebsite() != null ? getWebsite().getLocaleInstance() : Locale.getDefault();
688
689 for(Iterator it = tags.iterator(); it.hasNext();) {
690 String name = (String) it.next();
691 newTags.add(Utilities.normalizeTag(name, locale));
692 }
693
694 HashSet removeTags = new HashSet();
695
696 // remove old ones no longer passed.
697 for (Iterator it = getTags().iterator(); it.hasNext();) {
698 WeblogEntryTag tag = (WeblogEntryTag) it.next();
699 if (!newTags.contains(tag.getName())) {
700 removeTags.add(tag.getName());
701 } else {
702 newTags.remove(tag.getName());
703 }
704 }
705
706 WeblogManager weblogManager = WebloggerFactory.getWeblogger().getWeblogManager();
707 for (Iterator it = removeTags.iterator(); it.hasNext();) {
708 weblogManager.removeWeblogEntryTag((String) it.next(), this);
709 }
710
711 for (Iterator it = newTags.iterator(); it.hasNext();) {
712 addTag((String) it.next());
713 }
714 }
715
716 /**
717 * @roller.wrapPojoMethod type="simple"
718 */
719 public String getTagsAsString() {
/*
P/P * Method: String getTagsAsString()
*
* Preconditions:
* init'ed(this.pcStateManager)
* this.tagSet != null
* (soft) org/apache/roller/weblogger/pojos/WeblogEntryTag.pcInheritedFieldCount <= 232-2
* (soft) pcInheritedFieldCount <= 232-18
*
* Presumptions:
* java.lang.StringBuffer:length(...)@725 >= -231+1
* java.util.Iterator:next(...)@722 != null
*
* Postconditions:
* java.lang.StringBuffer:toString(...)._tainted == 0
* return_value == &java.lang.StringBuffer:toString(...)
*
* Test Vectors:
* java.lang.StringBuffer:length(...)@724: {-231..0}, {1..232-1}
* java.util.Iterator:hasNext(...)@721: {0}, {1}
*/
720 StringBuffer sb = new StringBuffer();
721 for (Iterator it = getTags().iterator(); it.hasNext();) {
722 sb.append(((WeblogEntryTag) it.next()).getName()).append(" ");
723 }
724 if (sb.length() > 0) {
725 sb.deleteCharAt(sb.length() - 1);
726 }
727
728 return sb.toString();
729 }
730
731 public void setTagsAsString(String tags) throws WebloggerException {
/*
P/P * Method: void setTagsAsString(String)
*
* Preconditions:
* (soft) org/apache/roller/weblogger/pojos/WeblogEntryTag.pcInheritedFieldCount <= 232-6
* (soft) pcInheritedFieldCount <= 232-22
* (soft) this.addedTags != null
* (soft) init'ed(this.creator)
* (soft) init'ed(this.pcStateManager)
* (soft) this.tagSet != null
* (soft) init'ed(this.updateTime)
* (soft) init'ed(this.website)
*
* Test Vectors:
* tags: Inverse{null}, Addr_Set{null}
*/
732 if (tags == null) {
733 tagSet.clear();
734 return;
735 }
736
737 updateTags(Utilities.splitStringAsTags(tags));
738 }
739
740 // ------------------------------------------------------------------------
741
742 /**
743 * True if comments are still allowed on this entry considering the
744 * allowComments and commentDays fields as well as the website and
745 * site-wide configs.
746 *
747 * @roller.wrapPojoMethod type="simple"
748 */
749 public boolean getCommentsStillAllowed() {
/*
P/P * Method: bool getCommentsStillAllowed()
*
* Preconditions:
* (soft) pcInheritedFieldCount <= 232-22
* (soft) init'ed(this.allowComments)
* (soft) init'ed(this.commentDays)
* (soft) init'ed(this.pcStateManager)
* (soft) init'ed(this.pubTime)
* (soft) init'ed(this.updateTime)
* (soft) this.website != null
*
* Presumptions:
* getAllowComments(...)@753 != null
* java.util.Calendar:getInstance(...)@770 != null
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* this.allowComments: Addr_Set{null}, Inverse{null}
* this.commentDays: Addr_Set{null}, Inverse{null}
* this.pubTime: Inverse{null}, Addr_Set{null}
* getAllowComments(...)@753: Addr_Set{null}, Inverse{null}
* java.lang.Boolean:booleanValue(...)@753: {1}, {0}
* java.lang.Boolean:booleanValue(...)@756: {1}, {0}
* java.lang.Integer:intValue(...)@760: {-231..-1, 1..232-1}, {0}
* java.util.Date:before(...)@776: {0}, {1}
* org.apache.roller.weblogger.config.WebloggerRuntimeConfig:getBooleanProperty(...)@750: {1}, {0}
*/
750 if (!WebloggerRuntimeConfig.getBooleanProperty("users.comments.enabled")) {
751 return false;
752 }
753 if (website.getAllowComments() != null && !website.getAllowComments().booleanValue()) {
754 return false;
755 }
756 if (getAllowComments() != null && !getAllowComments().booleanValue()) {
757 return false;
758 }
759 boolean ret = false;
760 if (getCommentDays() == null || getCommentDays().intValue() == 0) {
761 ret = true;
762 } else {
763 // we want to use pubtime for calculating when comments expire, but
764 // if pubtime isn't set (like for drafts) then just use updatetime
765 Date pubTime = getPubTime();
766 if(pubTime == null) {
767 pubTime = getUpdateTime();
768 }
769
770 Calendar expireCal = Calendar.getInstance(
771 getWebsite().getLocaleInstance());
772 expireCal.setTime(pubTime);
773 expireCal.add(Calendar.DATE, getCommentDays().intValue());
774 Date expireDay = expireCal.getTime();
775 Date today = new Date();
776 if (today.before(expireDay)) {
777 ret = true;
778 }
779 }
780 return ret;
781 }
782 public void setCommentsStillAllowed(boolean ignored) {
783 // no-op
/*
P/P * Method: void setCommentsStillAllowed(bool)
*/
784 }
785
786
787 //------------------------------------------------------------------------
788
789 /**
790 * Format the publish time of this weblog entry using the specified pattern.
791 * See java.text.SimpleDateFormat for more information on this format.
792 *
793 * @roller.wrapPojoMethod type="simple"
794 * @see java.text.SimpleDateFormat
795 * @return Publish time formatted according to pattern.
796 */
797 public String formatPubTime(String pattern) {
798 try {
/*
P/P * Method: String formatPubTime(String)
*
* Preconditions:
* (soft) mLogger != null
* (soft) pcInheritedFieldCount <= 232-22
* (soft) init'ed(this.pcStateManager)
* (soft) init'ed(this.pubTime)
* (soft) this.website != null
*
* Postconditions:
* init'ed(return_value)
*/
799 SimpleDateFormat format = new SimpleDateFormat(pattern,
800 this.getWebsite().getLocaleInstance());
801
802 return format.format(getPubTime());
803 } catch (RuntimeException e) {
804 mLogger.error("Unexpected exception", e);
805 }
806
807 return "ERROR: formatting date";
808 }
809
810 //------------------------------------------------------------------------
811
812 /**
813 * Format the update time of this weblog entry using the specified pattern.
814 * See java.text.SimpleDateFormat for more information on this format.
815 *
816 * @roller.wrapPojoMethod type="simple"
817 * @see java.text.SimpleDateFormat
818 * @return Update time formatted according to pattern.
819 */
820 public String formatUpdateTime(String pattern) {
821 try {
/*
P/P * Method: String formatUpdateTime(String)
*
* Preconditions:
* (soft) mLogger != null
* (soft) pcInheritedFieldCount <= 232-21
* (soft) init'ed(this.pcStateManager)
* (soft) init'ed(this.updateTime)
*
* Postconditions:
* init'ed(return_value)
*/
822 SimpleDateFormat format = new SimpleDateFormat(pattern);
823
824 return format.format(getUpdateTime());
825 } catch (RuntimeException e) {
826 mLogger.error("Unexpected exception", e);
827 }
828
829 return "ERROR: formatting date";
830 }
831
832 //------------------------------------------------------------------------
833
834 /**
835 * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.weblogger.pojos.WeblogEntryComment"
836 */
837 public List getComments() {
/*
P/P * Method: List getComments()
*
* Preconditions:
* (soft) pcInheritedFieldCount <= 232-22
* (soft) init'ed(this.pcStateManager)
* (soft) init'ed(this.website)
*
* Postconditions:
* init'ed(return_value)
* new ArrayList(getComments#1*) num objects == 1
*/
838 return getComments(true, true);
839 }
840
841 /**
842 * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.weblogger.pojos.WeblogEntryComment"
843 *
844 * TODO: why is this method exposed to users with ability to get spam/non-approved comments?
845 */
846 public List getComments(boolean ignoreSpam, boolean approvedOnly) {
/*
P/P * Method: List getComments(bool, bool)
*
* Preconditions:
* (soft) pcInheritedFieldCount <= 232-22
* (soft) init'ed(this.pcStateManager)
* (soft) init'ed(this.website)
*
* Presumptions:
* org.apache.roller.weblogger.business.Weblogger:getWeblogManager(...)@849 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@849 != null
*
* Postconditions:
* init'ed(return_value)
* new ArrayList(getComments#1) num objects == 1
*/
847 List list = new ArrayList();
848 try {
849 WeblogManager wmgr = WebloggerFactory.getWeblogger().getWeblogManager();
850 return wmgr.getComments(
851 getWebsite(),
852 this,
853 null, // search String
854 null, // startDate
855 null,
856 approvedOnly ? WeblogEntryComment.APPROVED : null,
857 false, // we want chrono order
858 0, // offset
859 -1); // no limit
860 } catch (WebloggerException alreadyLogged) {}
861 return list;
862 }
863
864 /**
865 * @roller.wrapPojoMethod type="simple"
866 */
867 public int getCommentCount() {
/*
P/P * Method: int getCommentCount()
*
* Preconditions:
* (soft) pcInheritedFieldCount <= 232-22
* (soft) init'ed(this.pcStateManager)
* (soft) init'ed(this.website)
*
* Postconditions:
* init'ed(return_value)
*/
868 List comments = getComments(true, true);
+ 869 return comments.size();
870 }
871
872 /** No-op to please XDoclet */
873 public void setCommentCount(int ignored) {
874 // no-op
/*
P/P * Method: void setCommentCount(int)
*/
875 }
876
877 //------------------------------------------------------------------------
878
879 /**
880 * @roller.wrapPojoMethod type="pojo-collection" class="org.apache.roller.weblogger.pojos.RefererData"
881 */
882 public List getReferers() {
/*
P/P * Method: List getReferers()
*
* Preconditions:
* (soft) mLogger != null
* (soft) pcInheritedFieldCount <= 232-9
* (soft) init'ed(this.id)
* (soft) init'ed(this.pcStateManager)
*
* Presumptions:
* org.apache.roller.weblogger.business.Weblogger:getRefererManager(...)@885 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@885 != null
*
* Postconditions:
* init'ed(return_value)
*/
883 List referers = null;
884 try {
885 referers = WebloggerFactory.getWeblogger().getRefererManager().getReferersToEntry(getId());
886 } catch (WebloggerException e) {
887 mLogger.error("Unexpected exception", e);
888 }
889 return referers;
890 }
891
892 //------------------------------------------------------------------------
893
894 /**
895 * Returns absolute entry permalink.
896 */
897 public String getPermalink() {
/*
P/P * Method: String getPermalink()
*
* Preconditions:
* init'ed(this.anchor)
* init'ed(this.pcStateManager)
* init'ed(this.website)
* (soft) pcInheritedFieldCount <= 232-22
*
* Presumptions:
* org.apache.roller.weblogger.business.Weblogger:getUrlStrategy(...)@898 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@898 != null
*
* Postconditions:
* init'ed(return_value)
*/
898 return WebloggerFactory.getWeblogger().getUrlStrategy().getWeblogEntryURL(getWebsite(), null, anchor, true);
899 }
900
901 /**
902 * Returns entry permalink, relative to Roller context.
903 * @deprecated Use getPermalink() instead.
904 * @roller.wrapPojoMethod type="simple"
905 */
906 public String getPermaLink() {
/*
P/P * Method: String getPermaLink()
*
* Preconditions:
* init'ed(this.anchor)
* init'ed(this.pcStateManager)
* this.website != null
* (soft) pcInheritedFieldCount <= 232-22
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* return_value == &java.lang.StringBuilder:toString(...)
*/
907 String lAnchor = this.getAnchor();
908 try {
909 lAnchor = URLEncoder.encode(anchor, "UTF-8");
910 } catch (UnsupportedEncodingException e) {
911 // go with the "no encoding" version
912 }
+ 913 Weblog website = this.getWebsite();
914 return "/" + getWebsite().getHandle() + "/entry/" + lAnchor;
915 }
916
917 /**
918 * Get relative URL to comments page.
919 * @roller.wrapPojoMethod type="simple"
920 * @deprecated Use commentLink() instead
921 */
922 public String getCommentsLink() {
/*
P/P * Method: String getCommentsLink()
*
* Preconditions:
* init'ed(this.anchor)
* init'ed(this.pcStateManager)
* this.website != null
* (soft) pcInheritedFieldCount <= 232-22
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* return_value == &java.lang.StringBuilder:toString(...)
*/
923 return getPermaLink() + "#comments";
924 }
925
926 /**
927 * to please XDoclet
928 * @deprecated Use commentLink() instead
929 */
/*
P/P * Method: void setCommentsLink(String)
*/
930 public void setCommentsLink(String ignored) {}
931
932
933 /**
934 * Return the Title of this post, or the first 255 characters of the
935 * entry's text.
936 *
937 * @roller.wrapPojoMethod type="simple"
938 * @return String
939 */
940 public String getDisplayTitle() {
/*
P/P * Method: String getDisplayTitle()
*
* Preconditions:
* init'ed(this.pcStateManager)
* init'ed(this.title)
* (soft) pcInheritedFieldCount <= 232-20
* (soft) init'ed(this.text)
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* this.title: Addr_Set{null}, Inverse{null}
* java.lang.String:equals(...)@941: {0}, {1}
*/
941 if ( getTitle()==null || getTitle().trim().equals("") ) {
942 return StringUtils.left(Utilities.removeHTML(text),255);
943 }
944 return Utilities.removeHTML(getTitle());
945 }
946
947 /**
948 * Return RSS 09x style description (escaped HTML version of entry text)
949 *
950 * @roller.wrapPojoMethod type="simple"
951 */
952 public String getRss09xDescription() {
/*
P/P * Method: String getRss09xDescription()
*
* Preconditions:
* init'ed(this.text)
*
* Postconditions:
* java.lang.StringBuilder:toString(...)._tainted == 0
* return_value != null
*/
953 return getRss09xDescription(-1);
954 }
955
956 /**
957 * Return RSS 09x style description (escaped HTML version of entry text)
958 *
959 * @roller.wrapPojoMethod type="simple"
960 */
961 public String getRss09xDescription(int maxLength) {
/*
P/P * Method: String getRss09xDescription(int)
*
* Preconditions:
* maxLength >= -231+3
* init'ed(this.text)
*
* Presumptions:
* org.apache.commons.lang.StringEscapeUtils:escapeHtml(...)@962 != null
*
* Postconditions:
* java.lang.StringBuilder:toString(...)._tainted == 0
* (soft) return_value != null
*
* Test Vectors:
* maxLength: {-1}, {0..232-2}
*/
962 String ret = StringEscapeUtils.escapeHtml(text);
963 if (maxLength != -1 && ret.length() > maxLength) {
964 ret = ret.substring(0,maxLength-3)+"...";
965 }
966 return ret;
967 }
968
969 /** Create anchor for weblog entry, based on title or text */
970 protected String createAnchor() throws WebloggerException {
/*
P/P * Method: String createAnchor()
*
* Presumptions:
* org.apache.roller.weblogger.business.Weblogger:getWeblogManager(...)@971 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@971 != null
*
* Postconditions:
* init'ed(return_value)
*/
971 return WebloggerFactory.getWeblogger().getWeblogManager().createAnchor(this);
972 }
973
974 /** Create anchor for weblog entry, based on title or text */
975 public String createAnchorBase() {
976
977 // Use title (minus non-alphanumeric characters)
/*
P/P * Method: String createAnchorBase()
*
* Preconditions:
* init'ed(this.pcStateManager)
* init'ed(this.title)
* (soft) pcInheritedFieldCount <= 232-20
* (soft) init'ed(this.pubTime)
* (soft) init'ed(this.text)
*
* Presumptions:
* org.apache.roller.weblogger.util.Utilities:replaceNonAlphanumeric(...)@980 != null
* org.apache.roller.weblogger.util.Utilities:replaceNonAlphanumeric(...)@984 != null
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* java.util.StringTokenizer:nextToken(...)._tainted == 0
* init'ed(return_value)
*
* Test Vectors:
* java.util.StringTokenizer:hasMoreTokens(...)@993: {0}, {1}
* org.apache.commons.lang.StringUtils:isEmpty(...)@979: {1}, {0}
* org.apache.commons.lang.StringUtils:isEmpty(...)@983: {0}, {1}
* org.apache.commons.lang.StringUtils:isEmpty(...)@983: {1}, {0}
* org.apache.commons.lang.StringUtils:isEmpty(...)@987: {1}, {0}
*/
978 String base = null;
979 if (!StringUtils.isEmpty(getTitle())) {
980 base = Utilities.replaceNonAlphanumeric(getTitle(), ' ').trim();
981 }
982 // If we still have no base, then try text (minus non-alphanumerics)
983 if (StringUtils.isEmpty(base) && !StringUtils.isEmpty(getText())) {
984 base = Utilities.replaceNonAlphanumeric(getText(), ' ').trim();
985 }
986
987 if (!StringUtils.isEmpty(base)) {
988
989 // Use only the first 4 words
990 StringTokenizer toker = new StringTokenizer(base);
991 String tmp = null;
992 int count = 0;
993 while (toker.hasMoreTokens() && count < 5) {
994 String s = toker.nextToken();
995 s = s.toLowerCase();
996 tmp = (tmp == null) ? s : tmp + "_" + s;
997 count++;
998 }
999 base = tmp;
1000 }
1001 // No title or text, so instead we will use the items date
1002 // in YYYYMMDD format as the base anchor
1003 else {
1004 base = DateUtil.format8chars(getPubTime());
1005 }
1006
1007 return base;
1008 }
1009
1010 /**
1011 * A no-op. TODO: fix formbean generation so this is not needed.
1012 */
/*
P/P * Method: void setPermalink(String)
*/
1013 public void setPermalink(String string) {}
1014
1015 /**
1016 * A no-op. TODO: fix formbean generation so this is not needed.
1017 */
/*
P/P * Method: void setPermaLink(String)
*/
1018 public void setPermaLink(String string) {}
1019
1020 /**
1021 * A no-op.
1022 * TODO: fix formbean generation so this is not needed.
1023 * @param string
1024 */
1025 public void setDisplayTitle(String string) {
/*
P/P * Method: void setDisplayTitle(String)
*/
1026 }
1027
1028 /**
1029 * A no-op.
1030 * TODO: fix formbean generation so this is not needed.
1031 * @param string
1032 */
1033 public void setRss09xDescription(String string) {
/*
P/P * Method: void setRss09xDescription(String)
*/
1034 }
1035
1036
1037 /**
1038 * Convenience method to transform mPlugins to a List
1039 *
1040 * @roller.wrapPojoMethod type="simple"
1041 * @return
1042 */
1043 public List getPluginsList() {
/*
P/P * Method: List getPluginsList()
*
* Preconditions:
* init'ed(this.plugins)
*
* Postconditions:
* init'ed(return_value)
* new ArrayList(getPluginsList#1) num objects <= 1
*
* Test Vectors:
* this.plugins: Addr_Set{null}, Inverse{null}
*/
1044 if (plugins != null) {
1045 return Arrays.asList( StringUtils.split(plugins, ",") );
1046 }
1047 return new ArrayList();
1048 }
1049
1050 /** Convenience method for checking status */
1051 public boolean isDraft() {
/*
P/P * Method: bool isDraft()
*
* Preconditions:
* this.status != null
*
* Postconditions:
* init'ed(return_value)
*/
1052 return status.equals(DRAFT);
1053 }
1054 /** no-op: needed only to satisfy XDoclet, use setStatus() instead */
1055 public void setDraft(boolean value) {
/*
P/P * Method: void setDraft(bool)
*/
1056 }
1057
1058 /** Convenience method for checking status */
1059 public boolean isPending() {
/*
P/P * Method: bool isPending()
*
* Preconditions:
* this.status != null
*
* Postconditions:
* init'ed(return_value)
*/
1060 return status.equals(PENDING);
1061 }
1062 /** no-op: needed only to satisfy XDoclet, use setStatus() instead */
1063 public void setPending(boolean value) {
/*
P/P * Method: void setPending(bool)
*/
1064 }
1065
1066 /** Convenience method for checking status */
1067 public boolean isPublished() {
/*
P/P * Method: bool isPublished()
*
* Preconditions:
* this.status != null
*
* Postconditions:
* init'ed(return_value)
*/
1068 return status.equals(PUBLISHED);
1069 }
1070 /** no-op: needed only to satisfy XDoclet, use setStatus() instead */
1071 public void setPublished(boolean value) {
/*
P/P * Method: void setPublished(bool)
*/
1072 }
1073
1074 /**
1075 * Get entry text, transformed by plugins enabled for entry.
1076 * @roller.wrapPojoMethod type="simple"
1077 */
1078 public String getTransformedText() {
/*
P/P * Method: String getTransformedText()
*
* Preconditions:
* mLogger != null
* init'ed(this.text)
* this.website != null
* (soft) init'ed(this.plugins)
*
* Postconditions:
* init'ed(return_value)
*/
1079 return render(text);
1080 }
1081 /**
1082 * No-op to please XDoclet.
1083 */
1084 public void setTransformedText(String t) {
1085 // no-op
/*
P/P * Method: void setTransformedText(String)
*/
1086 }
1087
1088 /**
1089 * Get entry summary, transformed by plugins enabled for entry.
1090 * @roller.wrapPojoMethod type="simple"
1091 */
1092 public String getTransformedSummary() {
/*
P/P * Method: String getTransformedSummary()
*
* Preconditions:
* mLogger != null
* init'ed(this.summary)
* this.website != null
* (soft) init'ed(this.plugins)
*
* Postconditions:
* init'ed(return_value)
*/
1093 return render(summary);
1094 }
1095 /**
1096 * No-op to please XDoclet.
1097 */
1098 public void setTransformedSummary(String t) {
1099 // no-op
/*
P/P * Method: void setTransformedSummary(String)
*/
1100 }
1101
1102 /**
1103 * Determine if the specified user has permissions to edit this entry.
1104 */
1105 public boolean hasWritePermissions(User user) throws WebloggerException {
1106
1107 // global admins can hack whatever they want
/*
P/P * Method: bool hasWritePermissions(User)
*
* Preconditions:
* user != null
* init'ed(user.pcStateManager)
* user.roles != null
* (soft) org/apache/roller/weblogger/pojos/User.pcInheritedFieldCount <= 232-10
* (soft) org/apache/roller/weblogger/pojos/UserRole.pcInheritedFieldCount <= 232-2
* (soft) init'ed(org/apache/roller/weblogger/pojos/WeblogPermission.AUTHOR)
* (soft) init'ed(org/apache/roller/weblogger/pojos/WeblogPermission.LIMITED)
* (soft) pcInheritedFieldCount <= 232-22
* (soft) init'ed(this.pcStateManager)
* (soft) this.status != null
* ...
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* hasUserPermissions(...)@1112: {1}, {0}
* hasUserPermissions(...)@1115: {0}, {1}
* java.lang.String:equals(...)@1052: {1}, {0}
* java.lang.String:equals(...)@1060: {0}, {1}
*/
1108 if(user.hasRole("admin")) {
1109 return true;
1110 }
1111
1112 boolean author = getWebsite().hasUserPermissions(
1113
1114 user,(short)(WeblogPermission.AUTHOR));
1115 boolean limited = getWebsite().hasUserPermissions(
1116
1117 user,(short)(WeblogPermission.LIMITED));
1118
1119 if (author || (limited && isDraft()) || (limited && isPending())) {
1120 return true;
1121 }
1122
1123 return false;
1124 }
1125
1126 /**
1127 * Transform string based on plugins enabled for this weblog entry.
1128 */
1129 private String render(String str) {
/*
P/P * Method: String render(String)
*
* Preconditions:
* mLogger != null
* this.website != null
* (soft) init'ed(this.plugins)
*
* Presumptions:
* java.util.Map:get(...)@1146 != null
* java.util.Map:keySet(...)@1142 != null
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* str: Addr_Set{null}, Inverse{null}
* getInitializedPlugins(...)@1132: Addr_Set{null}, Inverse{null}
* java.util.Iterator:hasNext(...)@1143: {0}, {1}
* java.util.List:contains(...)@1145: {0}, {1}
* java.util.List:isEmpty(...)@1137: {1}, {0}
*/
1130 String ret = str;
1131 mLogger.debug("Applying page plugins to string");
1132 Map plugins = this.website.getInitializedPlugins();
1133 if (str != null && plugins != null) {
1134 List entryPlugins = getPluginsList();
1135
1136 // if no Entry plugins, don't bother looping.
1137 if (entryPlugins != null && !entryPlugins.isEmpty()) {
1138
1139 // now loop over mPagePlugins, matching
1140 // against Entry plugins (by name):
1141 // where a match is found render Plugin.
1142 Iterator iter = plugins.keySet().iterator();
1143 while (iter.hasNext()) {
1144 String key = (String)iter.next();
1145 if (entryPlugins.contains(key)) {
1146 WeblogEntryPlugin pagePlugin = (WeblogEntryPlugin)plugins.get(key);
1147 try {
1148 ret = pagePlugin.render(this, ret);
1149 } catch (Throwable t) {
1150 mLogger.error("ERROR from plugin: " + pagePlugin.getName(), t);
1151 }
1152 }
1153 }
1154 }
1155 }
1156 return ret;
1157 }
1158
1159
1160 /**
1161 * Get the right transformed display content depending on the situation.
1162 *
1163 * If the readMoreLink is specified then we assume the caller wants to
1164 * prefer summary over content and we include a "Read More" link at the
1165 * end of the summary if it exists. Otherwise, if the readMoreLink is
1166 * empty or null then we assume the caller prefers content over summary.
1167 *
1168 * @roller.wrapPojoMethod type="simple"
1169 */
1170 public String displayContent(String readMoreLink) {
1171
/*
P/P * Method: String displayContent(String)
*
* Preconditions:
* mLogger != null
* init'ed(this.pcStateManager)
* (soft) pcInheritedFieldCount <= 232-22
* (soft) init'ed(this.plugins)
* (soft) init'ed(this.summary)
* (soft) init'ed(this.text)
* (soft) this.website != null
*
* Presumptions:
* org.apache.roller.weblogger.util.I18nMessages:getMessages(...)@1194 != null
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* init'ed(return_value)
*
* Test Vectors:
* readMoreLink: Addr_Set{null}, Inverse{null}
* java.lang.String:equals(...)@1174: {0}, {1}
* java.lang.String:length(...)@1174: {0}, {1..232-1}
* org.apache.commons.lang.StringUtils:isNotEmpty(...)@1178: {0}, {1}
* org.apache.commons.lang.StringUtils:isNotEmpty(...)@1186: {0}, {1}
* org.apache.commons.lang.StringUtils:isNotEmpty(...)@1188: {0}, {1}
*/
1172 String displayContent = null;
1173
1174 if(readMoreLink == null || readMoreLink.trim().length() < 1 ||
1175 "nil".equals(readMoreLink)) {
1176
1177 // no readMore link means permalink, so prefer text over summary
1178 if(StringUtils.isNotEmpty(this.getText())) {
1179 displayContent = this.getTransformedText();
1180 } else {
1181 displayContent = this.getTransformedSummary();
1182 }
1183 } else {
1184 // not a permalink, so prefer summary over text
1185 // include a "read more" link if needed
1186 if(StringUtils.isNotEmpty(this.getSummary())) {
1187 displayContent = this.getTransformedSummary();
1188 if(StringUtils.isNotEmpty(this.getText())) {
1189 // add read more
1190 List args = new ArrayList();
1191 args.add(readMoreLink);
1192
1193 // TODO: we need a more appropriate way to get the view locale here
1194 String readMore = I18nMessages.getMessages(getWebsite().getLocaleInstance()).getString("macro.weblog.readMoreLink", args);
1195
1196 displayContent += readMore;
1197 }
1198 } else {
1199 displayContent = this.getTransformedText();
1200 }
1201 }
1202
1203 return displayContent;
1204 }
1205
1206
1207 /**
1208 * Get the right transformed display content.
1209 *
1210 * @roller.wrapPojoMethod type="simple"
1211 */
1212 public String getDisplayContent() {
/*
P/P * Method: String getDisplayContent()
*
* Preconditions:
* mLogger != null
* init'ed(this.pcStateManager)
* (soft) pcInheritedFieldCount <= 232-22
* (soft) init'ed(this.plugins)
* (soft) init'ed(this.summary)
* (soft) init'ed(this.text)
* (soft) this.website != null
*
* Postconditions:
* init'ed(java.lang.StringBuilder:toString(...)._tainted)
* init'ed(return_value)
*/
1213 return displayContent(null);
1214 }
1215
1216
1217 /** No-op method to please XDoclet */
/*
P/P * Method: void setDisplayContent(String)
*/
1218 public void setDisplayContent(String ignored) {}
1219
1220 }
+ 1221 Other Messages
SofCheck Inspector Build Version : 2.18479
| WeblogEntry.java |
2009-Jan-02 14:25:32 |
| WeblogEntry.class |
2009-Sep-04 03:12:37 |