KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > j2biz > blogunity > pojo > Trackback


1 /*
2  * $Id: Trackback.java,v 1.9 2005/01/17 21:36:23 michelson Exp $
3  * Created on 23.12.2004
4  * Copyright (c) 2005 j2biz Group, http://www.j2biz.com
5  * Koeln / Duesseldorf , Germany
6  *
7  * @author Juan Antonio Agudo
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  *
23  */

24
25 package com.j2biz.blogunity.pojo;
26
27 import java.io.Serializable JavaDoc;
28 import java.util.Date JavaDoc;
29
30 import net.sf.hibernate.Validatable;
31 import net.sf.hibernate.ValidationFailure;
32
33 import org.apache.commons.logging.Log;
34 import org.apache.commons.logging.LogFactory;
35
36 import com.j2biz.blogunity.dao.EntryDAO;
37 import com.j2biz.blogunity.exception.BlogunityException;
38
39 /**
40  * @hibernate.class table="TRACKBACKS" dynamic-insert="true"
41  * dynamic-update="true"
42  *
43  * @author tag
44  * @version $version$
45  * @since 0.3
46  */

47 public class Trackback implements Validatable, Serializable JavaDoc {
48     /**
49      * Comment for <code>serialVersionUID</code>
50      */

51     private static final long serialVersionUID = 3257003259070854967L;
52
53     /**
54      * Logger for this class
55      */

56     private static final Log log = LogFactory.getLog(Trackback.class);
57
58     private String JavaDoc _tbUrl;
59
60     private Long JavaDoc _tbId;
61
62     private String JavaDoc _tbDirection;
63
64     private String JavaDoc _tbTitle;
65
66     private Long JavaDoc _tbReferencedEntryId;
67
68     private Long JavaDoc _tbReferencedBlogId;
69
70     private Date JavaDoc _tbDate;
71
72     private String JavaDoc _tbContent;
73
74     private String JavaDoc _tbLoggedIp;
75     
76     public static String JavaDoc DIRECTION_OUTGOING = "OUT";
77
78     public static String JavaDoc DIRECTION_INCOMING = "IN";
79     
80     /**
81      * @hibernate.property name="_tbLoggedIp" column="LOGGED_IP" type="text"
82      * not-null="false" unique="false"
83      *
84      * @return Returns the Title of a trackback.
85      */

86     public String JavaDoc getLoggedIp() {
87         return _tbLoggedIp;
88     }
89     /**
90      * Sets the Logged ip
91      *
92      * @param content
93      */

94     public void setLoggedIp(String JavaDoc loggedIp) {
95         _tbLoggedIp = loggedIp;
96     }
97     /**
98      * @hibernate.property name="_tbTitle" column="TITLE" type="text"
99      * not-null="false" unique="false"
100      *
101      * @return Returns the Title of a trackback.
102      */

103     public String JavaDoc getTitle() {
104         return _tbTitle;
105     }
106
107     /**
108      * Sets the Title
109      *
110      * @param content
111      */

112     public void setTitle(String JavaDoc title) {
113         if (title != null){
114             _tbTitle = title.replaceAll("\\<.*?\\>", ""); // strip html tags;
115
}
116     }
117
118     /**
119      * @hibernate.property name="_tbContent" column="CONTENT" type="text"
120      * not-null="false" unique="false"
121      *
122      * @return Returns the Content of a trackback.
123      */

124     public String JavaDoc getTrackbackContent() {
125         if(_tbContent == null){
126             return null;
127         }
128         if (_tbContent.length() > 255) {
129             // TODO: insert maximum trackback length property
130
return _tbContent.substring(0, 255) + "...";
131         }
132         return _tbContent;
133     }
134
135     /**
136      * Sets the Trackback content
137      *
138      * @param content
139      */

140     public void setTrackbackContent(String JavaDoc content) {
141         if(content != null)
142             _tbContent = content.replaceAll("\\<.*?\\>", ""); // strip html tags
143

144     }
145
146     /**
147      * @hibernate.property name="_tbDate" column="DATE_OF_TB" type="timestamp"
148      * not-null="true" unique="false"
149      *
150      * @return Returns the date.
151      */

152     public Date JavaDoc getDate() {
153         return _tbDate;
154     }
155
156     /**
157      * @param date
158      * The date to set.
159      */

160     public void setDate(Date JavaDoc date) {
161         this._tbDate = date;
162     }
163
164     /**
165      * @hibernate.property name="_tbDirection" column="DIRECTION" type="string"
166      * not-null="true" unique="false" length="3"
167      * @return Returns the direction.
168      */

169     public String JavaDoc getDirection() {
170         return _tbDirection;
171     }
172
173     /**
174      * @param direction
175      * The direction to set.
176      */

177     public void setDirection(String JavaDoc direction) {
178         this._tbDirection = direction;
179     }
180
181     /**
182      * @hibernate.id generator-class="increment" type="long" column="ID"
183      * unsaved-value="null"
184      * @return Returns the id.
185      */

186     public Long JavaDoc getId() {
187         return _tbId;
188     }
189
190     /**
191      * @param id
192      * The id to set.
193      */

194     public void setId(Long JavaDoc id) {
195         this._tbId = id;
196     }
197
198 // /**
199
// * @hibernate.property name="_tbReferencedBlogId" column="REF_BLOG_ID"
200
// * type="long" not-null="true" unique="false"
201
// * @return Returns the referencedBlogId.
202
// */
203
// public Long getReferencedBlogId() {
204
// return _tbReferencedBlogId;
205
// }
206
//
207
// /**
208
// * @param referencedBlogId
209
// * The referencedBlogId to set.
210
// */
211
// public void setReferencedBlogId(Long referencedBlogId) {
212
// this._tbReferencedBlogId = referencedBlogId;
213
// }
214

215     /**
216      *
217      * @hibernate.property name="_tbReferencedEntryId" column="REF_ENTRY_ID"
218      * type="long" not-null="true" unique="false"
219      * @return Returns the referencedEntryId.
220      */

221     public Long JavaDoc getReferencedEntryId() {
222         return _tbReferencedEntryId;
223     }
224
225     /**
226      * @param referencedEntryId
227      * The referencedEntryId to set.
228      */

229     public void setReferencedEntryId(Long JavaDoc referencedEntryId) {
230         this._tbReferencedEntryId = referencedEntryId;
231     }
232
233     /**
234      * @hibernate.property name="_tbUrl" column="TB_URL" type="string"
235      * not-null="true" unique="false"
236      * @return Returns the url.
237      */

238     public String JavaDoc getUrl() {
239         return _tbUrl;
240     }
241
242     /**
243      * @param url
244      * The url to set.
245      */

246     public void setUrl(String JavaDoc url) {
247         if (url != null)
248             this._tbUrl = url.replaceAll("\\<.*?\\>", ""); // strip html tags
249
}
250
251     /*
252      * (non-Javadoc)
253      *
254      * @see net.sf.hibernate.Validatable#validate()
255      */

256     public void validate() throws ValidationFailure {
257         if (!(DIRECTION_INCOMING.equals(getDirection()) || DIRECTION_OUTGOING.equals(getDirection()))) {
258             throw new ValidationFailure("Internal failure: Trackback direction can be either OUT or IN, not '" + getDirection() + "'");
259         }
260         try {
261             
262             //FIXME validate trackback entry within TrackbackDAO, not here!!!
263
EntryDAO entryDAO = new EntryDAO();
264             Entry entry = entryDAO.getEntryByID(getReferencedEntryId());
265             if(!entry.isTrackbackAllowed()){
266                 log.info("Trackbacks are not allowed for this article");
267                 throw new ValidationFailure("Trackbacks are not allowed for this article");
268             }
269         } catch (BlogunityException e) {
270             log.error("Error while fetching entry to trackback.",e);
271             throw new ValidationFailure("Error while fetching entry to trackback.",e);
272             
273         }
274         // TODO: add more validation rules
275
}
276 }
277
Popular Tags