KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > pojos > WeblogEntryData


1
2 package org.roller.pojos;
3
4 import java.io.UnsupportedEncodingException JavaDoc;
5 import java.net.URLEncoder JavaDoc;
6 import java.sql.Timestamp JavaDoc;
7 import java.text.SimpleDateFormat JavaDoc;
8 import java.util.ArrayList JavaDoc;
9 import java.util.Arrays JavaDoc;
10 import java.util.Calendar JavaDoc;
11 import java.util.Date JavaDoc;
12 import java.util.HashMap JavaDoc;
13 import java.util.Iterator JavaDoc;
14 import java.util.List JavaDoc;
15 import java.util.Map JavaDoc;
16 import java.util.Set JavaDoc;
17 import java.util.StringTokenizer JavaDoc;
18 import java.util.TreeSet JavaDoc;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.roller.RollerException;
24 import org.roller.model.Roller;
25 import org.roller.model.RollerFactory;
26 import org.roller.model.WeblogManager;
27 import org.roller.util.DateUtil;
28 import org.roller.util.Utilities;
29
30 /**
31  * Represents a Weblog Entry.
32  *
33  * @author David M Johnson
34  *
35  * @ejb:bean name="WeblogEntryData"
36  * @struts.form include-all="true"
37  * @hibernate.class table="weblogentry"
38  * hibernate.jcs-cache usage="read-write"
39  */

40 public class WeblogEntryData extends org.roller.pojos.PersistentObject
41     implements java.io.Serializable JavaDoc
42 {
43     private static Log mLogger = LogFactory.getFactory()
44                                            .getInstance(WeblogEntryData.class);
45                                            
46     static final long serialVersionUID = 2341505386843044125L;
47     
48     protected String JavaDoc id=null;
49     protected org.roller.pojos.WeblogCategoryData category=null;
50     protected String JavaDoc title=null;
51     protected String JavaDoc link=null;
52     protected String JavaDoc text=null;
53     protected String JavaDoc anchor=null;
54     protected Timestamp JavaDoc pubTime=null;
55     protected Timestamp JavaDoc updateTime=null;
56     protected Boolean JavaDoc publishEntry=null;
57     protected WebsiteData mWebsite=null;
58     protected String JavaDoc mPlugins;
59     protected Boolean JavaDoc allowComments = Boolean.TRUE;
60     protected Integer JavaDoc commentDays = new Integer JavaDoc(7);
61     protected Boolean JavaDoc rightToLeft = Boolean.FALSE;
62     protected Boolean JavaDoc pinnedToMain = Boolean.FALSE;
63     
64     private Map JavaDoc attMap = new HashMap JavaDoc();
65     private Set JavaDoc attSet = new TreeSet JavaDoc();
66     
67     //----------------------------------------------------------- Construction
68

69     public WeblogEntryData()
70     {
71     }
72
73     public WeblogEntryData(
74        java.lang.String JavaDoc id,
75        org.roller.pojos.WeblogCategoryData category,
76        WebsiteData website,
77        java.lang.String JavaDoc title,
78        java.lang.String JavaDoc link,
79        java.lang.String JavaDoc text,
80        java.lang.String JavaDoc anchor,
81        java.sql.Timestamp JavaDoc pubTime,
82        java.sql.Timestamp JavaDoc updateTime,
83        java.lang.Boolean JavaDoc publishEntry)
84     {
85         this.id = id;
86         this.category = category;
87         this.mWebsite = website;
88         this.title = title;
89         this.link = link;
90         this.text = text;
91         this.anchor = anchor;
92         this.pubTime = pubTime;
93         this.updateTime = updateTime;
94         this.publishEntry = publishEntry;
95     }
96
97     public WeblogEntryData(WeblogEntryData otherData)
98     {
99         setData(otherData);
100     }
101
102     //---------------------------------------------------------- Initializaion
103

104     /**
105      * Setter is needed in RollerImpl.storePersistentObject()
106      */

107     public void setData(org.roller.pojos.PersistentObject otherData)
108     {
109         WeblogEntryData other = (WeblogEntryData)otherData;
110         this.id = other.id;
111         this.category = other.category;
112         this.mWebsite = other.mWebsite;
113         this.title = other.title;
114         this.link = other.link;
115         this.text = other.text;
116         this.anchor = other.anchor;
117         this.pubTime = other.pubTime;
118         this.updateTime = other.updateTime;
119         this.publishEntry = other.publishEntry;
120         this.mPlugins = other.mPlugins;
121         this.allowComments = other.allowComments;
122         this.commentDays = other.commentDays;
123         this.rightToLeft = other.rightToLeft;
124         this.pinnedToMain = other.pinnedToMain;
125     }
126
127     //------------------------------------------------------ Simple properties
128

129     /**
130      * @ejb:persistent-field
131      * @hibernate.id column="id" type="string"
132      * generator-class="uuid.hex" unsaved-value="null"
133      */

134     public java.lang.String JavaDoc getId()
135     {
136         return this.id;
137     }
138
139     /** @ejb:persistent-field */
140     public void setId(java.lang.String JavaDoc id)
141     {
142         this.id = id;
143     }
144
145     /**
146      * @ejb:persistent-field
147      * @hibernate.many-to-one column="categoryid" cascade="none" not-null="true"
148      */

149     public org.roller.pojos.WeblogCategoryData getCategory()
150     {
151         return this.category;
152     }
153
154     /** @ejb:persistent-field */
155     public void setCategory(org.roller.pojos.WeblogCategoryData category)
156     {
157         this.category = category;
158     }
159
160     /**
161      * Set weblog category via weblog category ID.
162      * @param id Weblog category ID.
163      */

164     public void setCategoryId(String JavaDoc id) throws RollerException
165     {
166         WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager();
167         setCategory(wmgr.retrieveWeblogCategory(id));
168     }
169
170     /**
171      * @ejb:persistent-field
172      * @hibernate.many-to-one column="websiteid" cascade="none" not-null="true"
173      */

174     public WebsiteData getWebsite()
175     {
176         return this.mWebsite;
177     }
178
179     /** @ejb:persistent-field */
180     public void setWebsite(WebsiteData website)
181     {
182         this.mWebsite = website;
183     }
184
185     /**
186      * @ejb:persistent-field
187      * @hibernate.property column="title" non-null="true" unique="false"
188      */

189     public java.lang.String JavaDoc getTitle()
190     {
191         return this.title;
192     }
193
194     /** @ejb:persistent-field */
195     public void setTitle(java.lang.String JavaDoc title)
196     {
197         this.title = title;
198     }
199
200     /**
201      * @ejb:persistent-field
202      * @hibernate.property column="text" non-null="true" unique="false"
203      */

204     public java.lang.String JavaDoc getText()
205     {
206         return this.text;
207     }
208
209     /** @ejb:persistent-field */
210     public void setText(java.lang.String JavaDoc text)
211     {
212         this.text = text;
213     }
214
215     /**
216      * @ejb:persistent-field
217      * @hibernate.property column="anchor" non-null="true" unique="false"
218      */

219     public java.lang.String JavaDoc getAnchor()
220     {
221         return this.anchor;
222     }
223
224     /** @ejb:persistent-field */
225     public void setAnchor(java.lang.String JavaDoc anchor)
226     {
227         this.anchor = anchor;
228     }
229
230     //-------------------------------------------------------------------------
231
/**
232      * Map attributes as set because XDoclet 1.2b4 map support is broken.
233      * @ejb:persistent-field
234      * @hibernate.set lazy="true" order-by="name" inverse="true" cascade="all"
235      * @hibernate.collection-key column="entryid" type="String"
236      * @hibernate.collection-one-to-many class="org.roller.pojos.EntryAttributeData"
237      */

238     public Set JavaDoc getEntryAttributes()
239     {
240         return attSet;
241     }
242     /** @ejb:persistent-field */
243     public void setEntryAttributes(Set JavaDoc attSet)
244     {
245         this.attSet = attSet;
246         
247         // copy set to map
248
if (attSet != null)
249         {
250             this.attSet = attSet;
251             this.attMap = new HashMap JavaDoc();
252             Iterator JavaDoc iter = this.attSet.iterator();
253             while (iter.hasNext())
254             {
255                 EntryAttributeData att = (EntryAttributeData)iter.next();
256                 attMap.put(att.getName(), att);
257             }
258         }
259         else
260         {
261             this.attSet = new TreeSet JavaDoc();
262             this.attMap = new HashMap JavaDoc();
263         }
264     }
265     /** Would be named getEntryAttribute, but that would set off XDoclet */
266     public String JavaDoc findEntryAttribute(String JavaDoc name)
267     {
268         EntryAttributeData att = ((EntryAttributeData)attMap.get(name));
269         return (att != null) ? att.getValue() : null;
270     }
271     public void putEntryAttribute(String JavaDoc name, String JavaDoc value) throws Exception JavaDoc
272     {
273         EntryAttributeData att = (EntryAttributeData)attMap.get(name);
274         if (att == null)
275         {
276             att = new EntryAttributeData();
277             att.setEntry(this);
278             att.setName(name);
279             att.setValue(value);
280             attMap.put(name, att);
281             attSet.add(att);
282         }
283         else
284         {
285             att.setValue(value);
286         }
287     }
288     public void removeEntryAttribute(String JavaDoc name) throws RollerException
289     {
290         EntryAttributeData att = (EntryAttributeData)attMap.get(name);
291         if (att != null)
292         {
293             attMap.remove(att);
294             attSet.remove(att);
295             att.remove();
296         }
297     }
298     //-------------------------------------------------------------------------
299

300     /**
301      * <p>Publish time is the time that an entry is to be (or was) made available
302      * for viewing by newsfeed readers and visitors to the Roller site.</p>
303      *
304      * <p>Roller stores time in universal time. When times are displayed in a
305      * user's weblog they must be translated to the user's timezone.</p>
306      *
307      * <p>NOTE: Times are stored using the SQL TIMESTAMP datatype, which on
308      * MySQL has only a one-second resolution.</p>
309      *
310      * @ejb:persistent-field
311      * @hibernate.property column="pubtime" non-null="true" unique="false"
312      */

313     public java.sql.Timestamp JavaDoc getPubTime()
314     {
315         return this.pubTime;
316     }
317
318     /** @ejb:persistent-field */
319     public void setPubTime(java.sql.Timestamp JavaDoc pubTime)
320     {
321         this.pubTime = pubTime;
322     }
323
324     /**
325      * <p>Update time is the last time that an weblog entry was saved in the
326      * Roller weblog editor or via web services API (XML-RPC or Atom).</p>
327      *
328      * <p>Roller stores time using the timezone of the server itself. When
329      * times are displayed in a user's weblog they must be translated
330      * to the user's timezone.</p>
331      *
332      * <p>NOTE: Times are stored using the SQL TIMESTAMP datatype, which on
333      * MySQL has only a one-second resolution.</p>
334      *
335      * @ejb:persistent-field
336      * @hibernate.property column="updatetime" non-null="true" unique="false"
337      */

338     public java.sql.Timestamp JavaDoc getUpdateTime()
339     {
340         return this.updateTime;
341     }
342
343     /** @ejb:persistent-field */
344     public void setUpdateTime(java.sql.Timestamp JavaDoc updateTime)
345     {
346         this.updateTime = updateTime;
347     }
348
349     /**
350      * @ejb:persistent-field
351      * @hibernate.property column="publishentry" non-null="true" unique="false"
352      */

353     public java.lang.Boolean JavaDoc getPublishEntry()
354     {
355         return this.publishEntry;
356     }
357
358     /** @ejb:persistent-field */
359     public void setPublishEntry(java.lang.Boolean JavaDoc publishEntry)
360     {
361         this.publishEntry = publishEntry;
362     }
363
364     /**
365      * Some weblog entries are about one specific link.
366      * @return Returns the link.
367      *
368      * @ejb:persistent-field
369      * @hibernate.property column="link" non-null="false" unique="false"
370      */

371     public java.lang.String JavaDoc getLink()
372     {
373         return link;
374     }
375
376     /**
377      * @ejb:persistent-field
378      * @param link The link to set.
379      */

380     public void setLink(java.lang.String JavaDoc link)
381     {
382         this.link = link;
383     }
384
385     /**
386      * Comma-delimited list of this entry's Plugins.
387      * @ejb:persistent-field
388      * @hibernate.property column="plugins" non-null="false" unique="false"
389      */

390     public java.lang.String JavaDoc getPlugins()
391     {
392         return mPlugins;
393     }
394
395     /** @ejb:persistent-field */
396     public void setPlugins(java.lang.String JavaDoc string)
397     {
398         mPlugins = string;
399     }
400
401     
402     /**
403      * True if comments are allowed on this weblog entry.
404      * @ejb:persistent-field
405      * @hibernate.property column="allowcomments" non-null="true" unique="false"
406      */

407     public Boolean JavaDoc getAllowComments() {
408         return allowComments;
409     }
410     /**
411      * True if comments are allowed on this weblog entry.
412      * @ejb:persistent-field
413      */

414     public void setAllowComments(Boolean JavaDoc allowComments) {
415         this.allowComments = allowComments;
416     }
417     
418     /**
419      * Number of days after pubTime that comments should be allowed, or 0 for no limit.
420      * @ejb:persistent-field
421      * @hibernate.property column="commentdays" non-null="true" unique="false"
422      */

423     public Integer JavaDoc getCommentDays() {
424         return commentDays;
425     }
426     /**
427      * Number of days after pubTime that comments should be allowed, or 0 for no limit.
428      * @ejb:persistent-field
429      */

430     public void setCommentDays(Integer JavaDoc commentDays) {
431         this.commentDays = commentDays;
432     }
433     
434     /**
435      * True if this entry should be rendered right to left.
436      * @ejb:persistent-field
437      * @hibernate.property column="righttoleft" non-null="true" unique="false"
438      */

439     public Boolean JavaDoc getRightToLeft() {
440         return rightToLeft;
441     }
442     /**
443      * True if this entry should be rendered right to left.
444      * @ejb:persistent-field
445      */

446     public void setRightToLeft(Boolean JavaDoc rightToLeft) {
447         this.rightToLeft = rightToLeft;
448     }
449
450     /**
451      * True if story should be pinned to the top of the Roller site main blog.
452      * @return Returns the pinned.
453      *
454      * @ejb:persistent-field
455      * @hibernate.property column="pinnedtomain" non-null="true" unique="false"
456      */

457     public Boolean JavaDoc getPinnedToMain()
458     {
459         return pinnedToMain;
460     }
461     /**
462      * True if story should be pinned to the top of the Roller site main blog.
463      * @param pinnedToMain The pinned to set.
464      *
465      * @ejb:persistent-field
466      */

467     public void setPinnedToMain(Boolean JavaDoc pinnedToMain)
468     {
469         this.pinnedToMain = pinnedToMain;
470     }
471
472     //------------------------------------------------------------------------
473

474     /**
475      * Save the entry and queue applicable web log update pings if the entry is published.
476      * @see org.roller.pojos.PersistentObject#save()
477      */

478     public void save() throws RollerException
479     {
480         // If no anchor then create one
481
if (getAnchor()==null || getAnchor().trim().equals(""))
482         {
483             setAnchor(createAnchor());
484         }
485         if (getPublishEntry() != null && getPublishEntry().booleanValue()) {
486             // Queue applicable pings for this update.
487
RollerFactory.getRoller().getAutopingManager().queueApplicableAutoPings(this);
488         }
489         super.save();
490     }
491     
492     //------------------------------------------------------------------------
493

494     /**
495      * True if comments are still allowed on this entry considering the
496      * allowComments and commentDays fields.
497      */

498     public boolean getCommentsStillAllowed()
499     {
500             boolean ret = false;
501             if (getAllowComments() == null || getAllowComments().booleanValue())
502             {
503                 if (getCommentDays() == null || getCommentDays().intValue() == 0)
504                 {
505                     ret = true;
506                 }
507                 else
508                 {
509                     Calendar JavaDoc expireCal = Calendar.getInstance(getWebsite().getLocaleInstance());
510                     expireCal.setTime(getPubTime());
511                     expireCal.add(Calendar.DATE, getCommentDays().intValue());
512                     Date JavaDoc expireDay = expireCal.getTime();
513                     Date JavaDoc today = new Date JavaDoc();
514                     if (today.before(expireDay))
515                     {
516                         ret = true;
517                     }
518                 }
519             }
520             return ret;
521     }
522     public void setCommentsStillAllowed(boolean ignored) {
523         // no-op
524
}
525
526     
527     //------------------------------------------------------------------------
528

529     /**
530      * Format the publish time of this weblog entry using the specified pattern.
531      * See java.text.SimpleDateFormat for more information on this format.
532      * @see java.text.SimpleDateFormat
533      * @return Publish time formatted according to pattern.
534      */

535     public String JavaDoc formatPubTime(String JavaDoc pattern)
536     {
537         try
538         {
539             SimpleDateFormat JavaDoc format = new SimpleDateFormat JavaDoc(pattern,
540                     this.getWebsite().getLocaleInstance());
541
542             return format.format(getPubTime());
543         }
544         catch (RuntimeException JavaDoc e)
545         {
546             mLogger.error("Unexpected exception", e);
547         }
548
549         return "ERROR: formatting date";
550     }
551
552     //------------------------------------------------------------------------
553

554     /**
555      * Format the update time of this weblog entry using the specified pattern.
556      * See java.text.SimpleDateFormat for more information on this format.
557      * @see java.text.SimpleDateFormat
558      * @return Update time formatted according to pattern.
559      */

560     public String JavaDoc formatUpdateTime(String JavaDoc pattern)
561     {
562         try
563         {
564             SimpleDateFormat JavaDoc format = new SimpleDateFormat JavaDoc(pattern);
565
566             return format.format(getUpdateTime());
567         }
568         catch (RuntimeException JavaDoc e)
569         {
570             mLogger.error("Unexpected exception", e);
571         }
572
573         return "ERROR: formatting date";
574     }
575
576     //------------------------------------------------------------------------
577

578     public List JavaDoc getComments()
579     {
580         return getComments(true);
581     }
582     
583     public List JavaDoc getComments(boolean ignoreSpam)
584     {
585         List JavaDoc list = new ArrayList JavaDoc();
586         try
587         {
588             return RollerFactory.getRoller().getWeblogManager().getComments(getId(), ignoreSpam);
589         }
590         catch (RollerException alreadyLogged) {}
591         return list;
592     }
593
594     //------------------------------------------------------------------------
595

596     public List JavaDoc getReferers()
597     {
598         List JavaDoc referers = null;
599         try {
600             referers = RollerFactory.getRoller().getRefererManager().getReferersToEntry(getId());
601         } catch (RollerException e) {
602             mLogger.error("Unexpected exception", e);
603         }
604         return referers;
605     }
606
607     //------------------------------------------------------------------------
608

609     /**
610      * @param entry
611      * @param url
612      * @param title
613      * @param excerpt
614      * @param blogName
615      */

616     public void addTrackback(
617         String JavaDoc url, String JavaDoc title, String JavaDoc excerpt, String JavaDoc blogName)
618         throws RollerException
619     {
620         String JavaDoc modTitle = blogName + ": " + title;
621         if (modTitle.length() >= 250)
622         {
623             modTitle = modTitle.substring(0, 257);
624             modTitle += "...";
625         }
626         
627         // Track trackbacks as comments
628
CommentData comment = new CommentData();
629         comment.setContent("[Trackback] "+excerpt);
630         comment.setName(blogName);
631         comment.setUrl(url);
632         comment.setWeblogEntry(this);
633         comment.setNotify(Boolean.FALSE);
634         comment.setPostTime(new Timestamp JavaDoc(new Date JavaDoc().getTime()));
635         comment.save();
636          
637         // Alternative: treat trackbacks as referers
638
//RefererData ref = new RefererData();
639
//ref.setWebsite(getWebsite());
640
//ref.setWeblogEntry(this);
641
//ref.setRequestUrl("(trackback)");
642
//ref.setRefererUrl(url);
643
//ref.setTitle(modTitle);
644
//ref.setExcerpt(excerpt);
645
//ref.setVisible(Boolean.TRUE);
646
//ref.setDayHits(new Integer(0));
647
//ref.setTotalHits(new Integer(0));
648
//ref.setDuplicate(Boolean.FALSE);
649
//ref.setDateString(formatPubTime("yyyyMMdd"));
650
//mRoller.getRefererManager().storeReferer(ref);
651
}
652     
653     /**
654      * Convenience method for getPermalink(category)
655      * where no category is necessary.
656      * @return
657      */

658     public String JavaDoc getPermaLink()
659     {
660         String JavaDoc lAnchor = this.getAnchor();
661         
662         try
663         {
664             lAnchor = URLEncoder.encode(anchor, "UTF-8");
665         }
666         catch (UnsupportedEncodingException JavaDoc e)
667         {
668             // go with the "no encoding" version
669
}
670         
671         WebsiteData website = this.getWebsite();
672         String JavaDoc plink = "/page/" + website.getUser().getUserName() +
673                 "?entry=" + lAnchor;
674         
675         return plink;
676     }
677     
678     /**
679      * Get the "relative" URL to this entry. Proper use of this will
680      * require prepending the baseURL (either the full root
681      * [http://server.com/context] or at least the context
682      * [/context]) in order to generate a functional link.
683      * @param category The category name to insert into the permalink.
684      * @return String
685      */

686     public String JavaDoc getPermaLink(String JavaDoc categoryPath)
687     {
688         // i don't really understand the purpose of this method since
689
// WeblogEntryData.getPermaLink() is only meant to point to this entry
690

691         return this.getPermaLink();
692     }
693         
694     public String JavaDoc getCommentsLink()
695     {
696         String JavaDoc dayString = DateUtil.format8chars(this.getPubTime());
697         String JavaDoc lAnchor = this.getAnchor();
698         try
699         {
700             lAnchor = URLEncoder.encode(anchor, "UTF-8");
701         }
702         catch (UnsupportedEncodingException JavaDoc e)
703         {
704             // go with the "no encoding" version
705
}
706         String JavaDoc clink = "/page/" + this.getWebsite().getUser().getUserName() + "?anchor=" + lAnchor;
707         return clink;
708     }
709     /** to please XDoclet */
710     public void setCommentsLink(String JavaDoc ignored) {}
711     
712     /**
713      * Return the Title of this post, or the first 255 characters of the
714      * entry's text.
715      *
716      * @return String
717      */

718     public String JavaDoc getDisplayTitle()
719     {
720         if ( getTitle()==null || getTitle().trim().equals("") )
721         {
722             return StringUtils.left(Utilities.removeHTML(text),255);
723         }
724         return Utilities.removeHTML(getTitle());
725     }
726     
727     //------------------------------------------------------------------------
728

729     public String JavaDoc toString()
730     {
731         StringBuffer JavaDoc str = new StringBuffer JavaDoc("{");
732
733         str.append("id=" + id + " " +
734                    "category=" + category + " " +
735                    "title=" + title + " " +
736                     "text=" + text + " " +
737                     "anchor=" + anchor + " " +
738                     "pubTime=" + pubTime + " " +
739                     "updateTime=" + updateTime + " " +
740                     "publishEntry=" + publishEntry + " " +
741                     "plugins=" + mPlugins);
742         str.append('}');
743
744         return (str.toString());
745     }
746
747     //------------------------------------------------------------------------
748

749     public boolean equals(Object JavaDoc pOther)
750     {
751         if (pOther instanceof WeblogEntryData)
752         {
753             WeblogEntryData lTest = (WeblogEntryData) pOther;
754             boolean lEquals = true;
755
756             if (this.id == null)
757             {
758                 lEquals = lEquals && (lTest.id == null);
759             }
760             else
761             {
762                 lEquals = lEquals && this.id.equals(lTest.id);
763             }
764
765             if (this.category == null)
766             {
767                 lEquals = lEquals && (lTest.category == null);
768             }
769             else
770             {
771                 lEquals = lEquals && this.category.equals(lTest.category);
772             }
773
774             if (this.mWebsite == null)
775             {
776                 lEquals = lEquals && (lTest.mWebsite == null);
777             }
778             else
779             {
780                 lEquals = lEquals && this.mWebsite.equals(lTest.mWebsite);
781             }
782
783             if (this.title == null)
784             {
785                 lEquals = lEquals && (lTest.title == null);
786             }
787             else
788             {
789                 lEquals = lEquals && this.title.equals(lTest.title);
790             }
791
792             if (this.text == null)
793             {
794                 lEquals = lEquals && (lTest.text == null);
795             }
796             else
797             {
798                 lEquals = lEquals && this.text.equals(lTest.text);
799             }
800
801             if (this.anchor == null)
802             {
803                 lEquals = lEquals && (lTest.anchor == null);
804             }
805             else
806             {
807                 lEquals = lEquals && this.anchor.equals(lTest.anchor);
808             }
809
810             if (this.pubTime == null)
811             {
812                 lEquals = lEquals && (lTest.pubTime == null);
813             }
814             else
815             {
816                 lEquals = lEquals && this.pubTime.equals(lTest.pubTime);
817             }
818
819             if (this.updateTime == null)
820             {
821                 lEquals = lEquals && (lTest.updateTime == null);
822             }
823             else
824             {
825                 lEquals = lEquals &&
826                           this.updateTime.equals(lTest.updateTime);
827             }
828
829             if (this.publishEntry == null)
830             {
831                 lEquals = lEquals && (lTest.publishEntry == null);
832             }
833             else
834             {
835                 lEquals = lEquals &&
836                           this.publishEntry.equals(lTest.publishEntry);
837             }
838
839             if (this.mPlugins == null)
840             {
841                 lEquals = lEquals && (lTest.mPlugins == null);
842             }
843             else
844             {
845                 lEquals = lEquals &&
846                           this.mPlugins.equals(lTest.mPlugins);
847             }
848
849
850             return lEquals;
851         }
852         else
853         {
854             return false;
855         }
856     }
857
858     //------------------------------------------------------------------------
859

860     public int hashCode()
861     {
862         int result = 17;
863         result = (37 * result) +
864                  ((this.id != null) ? this.id.hashCode() : 0);
865         result = (37 * result) +
866                  ((this.category != null) ? this.category.hashCode() : 0);
867         result = (37 * result) +
868                  ((this.mWebsite != null) ? this.mWebsite.hashCode() : 0);
869         result = (37 * result) +
870                  ((this.title != null) ? this.title.hashCode() : 0);
871         result = (37 * result) +
872                  ((this.text != null) ? this.text.hashCode() : 0);
873         result = (37 * result) +
874                  ((this.anchor != null) ? this.anchor.hashCode() : 0);
875         result = (37 * result) +
876                  ((this.pubTime != null) ? this.pubTime.hashCode() : 0);
877         result = (37 * result) +
878                  ((this.updateTime != null) ? this.updateTime.hashCode() : 0);
879         result = (37 * result) +
880                  ((this.publishEntry != null) ? this.publishEntry.hashCode() : 0);
881         result = (37 * result) +
882                  ((this.mPlugins != null) ? this.mPlugins.hashCode() : 0);
883
884         return result;
885     }
886     
887     /** Return RSS 09x style description (escaped HTML version of entry text) */
888     public String JavaDoc getRss09xDescription()
889     {
890         return getRss09xDescription(-1);
891     }
892     
893     /** Return RSS 09x style description (escaped HTML version of entry text) */
894     public String JavaDoc getRss09xDescription(int maxLength)
895     {
896         String JavaDoc ret = Utilities.escapeHTML(text);
897         if (maxLength != -1 && ret.length() > maxLength)
898         {
899             ret = ret.substring(0,maxLength-3)+"...";
900         }
901         return ret;
902     }
903
904     /** Create anchor for weblog entry, based on title or text */
905     protected String JavaDoc createAnchor() throws RollerException
906     {
907         return RollerFactory.getRoller().getWeblogManager().createAnchor(this);
908     }
909
910     /** Create anchor for weblog entry, based on title or text */
911     public String JavaDoc createAnchorBase()
912     {
913         // Use title or text for base anchor
914
String JavaDoc base = getTitle();
915         if (base == null || base.trim().equals(""))
916         {
917             base = getText();
918         }
919         if (base != null && !base.trim().equals(""))
920         {
921             base = Utilities.replaceNonAlphanumeric(base, ' ');
922
923             // Use only the first 4 words
924
StringTokenizer JavaDoc toker = new StringTokenizer JavaDoc(base);
925             String JavaDoc tmp = null;
926             int count = 0;
927             while (toker.hasMoreTokens() && count < 5)
928             {
929                 String JavaDoc s = toker.nextToken();
930                 s = s.toLowerCase();
931                 tmp = (tmp == null) ? s : tmp + "_" + s;
932                 count++;
933             }
934             base = tmp;
935         }
936         // No title or text, so instead we will use the items date
937
// in YYYYMMDD format as the base anchor
938
else
939         {
940             base = DateUtil.format8chars(getPubTime());
941         }
942
943         return base;
944     }
945
946     /**
947      * A no-op.
948      * TODO: fix formbean generation so this is not needed.
949      * @param string
950      */

951     public void setPermaLink(String JavaDoc string)
952     {
953     }
954
955     /**
956      * A no-op.
957      * TODO: fix formbean generation so this is not needed.
958      * @param string
959      */

960     public void setDisplayTitle(String JavaDoc string)
961     {
962     }
963
964     /**
965      * A no-op.
966      * TODO: fix formbean generation so this is not needed.
967      * @param string
968      */

969     public void setRss09xDescription(String JavaDoc string)
970     {
971     }
972     
973     /**
974      * @see org.roller.pojos.PersistentObject#remove()
975      */

976     public void remove() throws RollerException
977     {
978         RollerFactory.getRoller().getWeblogManager().removeWeblogEntryContents(this);
979         super.remove();
980     }
981     
982     /**
983      * Convenience method to transform mPlugins to a List
984      * @return
985      */

986     public List JavaDoc getPluginsList()
987     {
988         if (mPlugins != null)
989         {
990             return Arrays.asList( StringUtils.split(mPlugins, ",") );
991         }
992         return new ArrayList JavaDoc();
993     }
994
995     public boolean canSave() throws RollerException
996     {
997         Roller roller = RollerFactory.getRoller();
998         if (roller.getUser().equals(UserData.SYSTEM_USER))
999         {
1000            return true;
1001        }
1002        if (roller.getUser().equals(getWebsite().getUser()))
1003        {
1004            return true;
1005        }
1006        return false;
1007    }
1008}
1009
Popular Tags