1 24 25 package com.j2biz.blogunity.pojo; 26 27 import java.io.Serializable ; 28 import java.util.Date ; 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 47 public class Trackback implements Validatable, Serializable { 48 51 private static final long serialVersionUID = 3257003259070854967L; 52 53 56 private static final Log log = LogFactory.getLog(Trackback.class); 57 58 private String _tbUrl; 59 60 private Long _tbId; 61 62 private String _tbDirection; 63 64 private String _tbTitle; 65 66 private Long _tbReferencedEntryId; 67 68 private Long _tbReferencedBlogId; 69 70 private Date _tbDate; 71 72 private String _tbContent; 73 74 private String _tbLoggedIp; 75 76 public static String DIRECTION_OUTGOING = "OUT"; 77 78 public static String DIRECTION_INCOMING = "IN"; 79 80 86 public String getLoggedIp() { 87 return _tbLoggedIp; 88 } 89 94 public void setLoggedIp(String loggedIp) { 95 _tbLoggedIp = loggedIp; 96 } 97 103 public String getTitle() { 104 return _tbTitle; 105 } 106 107 112 public void setTitle(String title) { 113 if (title != null){ 114 _tbTitle = title.replaceAll("\\<.*?\\>", ""); } 116 } 117 118 124 public String getTrackbackContent() { 125 if(_tbContent == null){ 126 return null; 127 } 128 if (_tbContent.length() > 255) { 129 return _tbContent.substring(0, 255) + "..."; 131 } 132 return _tbContent; 133 } 134 135 140 public void setTrackbackContent(String content) { 141 if(content != null) 142 _tbContent = content.replaceAll("\\<.*?\\>", ""); 144 } 145 146 152 public Date getDate() { 153 return _tbDate; 154 } 155 156 160 public void setDate(Date date) { 161 this._tbDate = date; 162 } 163 164 169 public String getDirection() { 170 return _tbDirection; 171 } 172 173 177 public void setDirection(String direction) { 178 this._tbDirection = direction; 179 } 180 181 186 public Long getId() { 187 return _tbId; 188 } 189 190 194 public void setId(Long id) { 195 this._tbId = id; 196 } 197 198 215 221 public Long getReferencedEntryId() { 222 return _tbReferencedEntryId; 223 } 224 225 229 public void setReferencedEntryId(Long referencedEntryId) { 230 this._tbReferencedEntryId = referencedEntryId; 231 } 232 233 238 public String getUrl() { 239 return _tbUrl; 240 } 241 242 246 public void setUrl(String url) { 247 if (url != null) 248 this._tbUrl = url.replaceAll("\\<.*?\\>", ""); } 250 251 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 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 } 276 } 277 | Popular Tags |