KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > blojsom > blog > database > DatabaseTrackback


1 /**
2  * Copyright (c) 2003-2006, David A. Czarnecki
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and the
9  * following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
11  * following disclaimer in the documentation and/or other materials provided with the distribution.
12  * Neither the name of "David A. Czarnecki" and "blojsom" nor the names of its contributors may be used to
13  * endorse or promote products derived from this software without specific prior written permission.
14  * Products derived from this software may not be called "blojsom", nor may "blojsom" appear in their name,
15  * without prior written permission of David A. Czarnecki.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
18  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
19  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
21  * EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */

31 package org.blojsom.blog.database;
32
33 import org.blojsom.blog.Entry;
34 import org.blojsom.blog.Trackback;
35 import org.blojsom.util.BlojsomUtils;
36
37 import java.io.Serializable JavaDoc;
38 import java.text.SimpleDateFormat JavaDoc;
39 import java.util.Date JavaDoc;
40 import java.util.HashMap JavaDoc;
41 import java.util.Locale JavaDoc;
42 import java.util.Map JavaDoc;
43
44 /**
45  * DatabaseTrackback
46  *
47  * @author David Czarnecki
48  * @version $Id: DatabaseTrackback.java,v 1.6 2006/09/26 02:55:21 czarneckid Exp $
49  * @since blojsom 3.0
50  */

51 public class DatabaseTrackback implements Trackback, Serializable JavaDoc {
52
53     protected Integer JavaDoc _id;
54     protected Integer JavaDoc _blogId;
55     protected Integer JavaDoc _blogEntryId;
56     protected Entry _entry;
57
58     protected String JavaDoc _title;
59     protected String JavaDoc _excerpt;
60     protected String JavaDoc _url;
61     protected String JavaDoc _blogName;
62     protected Date JavaDoc _trackbackDate;
63     protected long _trackbackDateLong;
64     protected Map JavaDoc _metaData;
65     protected String JavaDoc _status;
66     protected String JavaDoc _ip;
67
68     /**
69      * Create a new instance of the database trackback
70      */

71     public DatabaseTrackback() {
72     }
73
74     /**
75      * Set the trackback ID
76      *
77      * @param id Trackback ID
78      */

79     public void setId(Integer JavaDoc id) {
80         _id = id;
81     }
82
83     /**
84      * Get the trackback ID
85      *
86      * @return Trackback ID
87      */

88     public Integer JavaDoc getId() {
89         return _id;
90     }
91
92     /**
93      * Set the blog ID
94      *
95      * @param blogId Blog ID
96      */

97     public void setBlogId(Integer JavaDoc blogId) {
98         _blogId = blogId;
99     }
100
101     /**
102      * Get the blog ID
103      *
104      * @return Blog ID
105      */

106     public Integer JavaDoc getBlogId() {
107         return _blogId;
108     }
109
110     /**
111      * Get the blog entry ID
112      *
113      * @return Blog entry ID
114      */

115     public Integer JavaDoc getBlogEntryId() {
116         return _blogEntryId;
117     }
118
119     /**
120      * Set the blog entry ID
121      *
122      * @param blogEntryId Blog entry ID
123      */

124     public void setBlogEntryId(Integer JavaDoc blogEntryId) {
125         _blogEntryId = blogEntryId;
126     }
127
128     /**
129      * Retrieve the {@link BlogEntry} associated with this trackback
130      *
131      * @return {@link BlogEntry}
132      */

133     public Entry getEntry() {
134         return _entry;
135     }
136
137     /**
138      * Set the {@link BlogEntry} associated with this trackback
139      *
140      * @param blogEntry {@link BlogEntry}
141      */

142     public void setEntry(Entry entry) {
143         _entry = entry;
144     }
145
146     /**
147      * Get the title of the trackback
148      *
149      * @return Trackback title
150      */

151     public String JavaDoc getTitle() {
152         return _title;
153     }
154
155     /**
156      * Get the escaped title of the trackback
157      *
158      * @return Escaped title
159      */

160     public String JavaDoc getEscapedTitle() {
161         return BlojsomUtils.escapeString(_title);
162     }
163
164     /**
165      * Set the title of the trackback
166      *
167      * @param title Trackback title
168      */

169     public void setTitle(String JavaDoc title) {
170         _title = title;
171     }
172
173     /**
174      * Get the excerpt of the trackback
175      *
176      * @return Trackback excerpt
177      */

178     public String JavaDoc getExcerpt() {
179         return _excerpt;
180     }
181
182     /**
183      * Get the excerpt as an escaped string
184      *
185      * @return Escaped excerpt
186      */

187     public String JavaDoc getEscapedExcerpt() {
188         return BlojsomUtils.escapeString(_excerpt);
189     }
190
191     /**
192      * Set the excerpt of the trackback
193      *
194      * @param excerpt Trackback excerpt
195      */

196     public void setExcerpt(String JavaDoc excerpt) {
197         _excerpt = excerpt;
198     }
199
200     /**
201      * Get the url of the trackback
202      *
203      * @return Trackback url
204      */

205     public String JavaDoc getUrl() {
206         return _url;
207     }
208
209     /**
210      * Get the escaped url of the trackback
211      *
212      * @return Escaped url
213      */

214     public String JavaDoc getEscapedUrl() {
215         return BlojsomUtils.escapeString(_url);
216     }
217
218     /**
219      * Set the url of the trackback
220      *
221      * @param url Trackback url
222      */

223     public void setUrl(String JavaDoc url) {
224         _url = url;
225     }
226
227     /**
228      * Get the blog name of the trackback
229      *
230      * @return Trackback blog name
231      */

232     public String JavaDoc getBlogName() {
233         return _blogName;
234     }
235
236     /**
237      * Get the escaped blog name of the trackback
238      *
239      * @return Escaped blog name
240      */

241     public String JavaDoc getEscapedBlogName() {
242         return BlojsomUtils.escapeString(_blogName);
243     }
244
245     /**
246      * Get the trackback meta-data
247      *
248      * @return Meta-data as a {@link Map}
249      */

250     public Map JavaDoc getMetaData() {
251         if (_metaData == null) {
252             return new HashMap JavaDoc();
253         }
254
255         return _metaData;
256     }
257
258     /**
259      * Set the blog name of the trackback
260      *
261      * @param blogName Trackback blog name
262      */

263     public void setBlogName(String JavaDoc blogName) {
264         _blogName = blogName;
265     }
266
267     /**
268      * Set the date for the trackback
269      *
270      * @param trackbackDateLong Trackback date as a <code>long</code> value
271      */

272     public void setTrackbackDateLong(long trackbackDateLong) {
273         _trackbackDateLong = trackbackDateLong;
274         _trackbackDate = new Date JavaDoc(_trackbackDateLong);
275     }
276
277     /**
278      * Get the date of the trackback
279      *
280      * @return Date of the trackback as a <code>long</code>
281      */

282     public long getTrackbackDateLong() {
283         return _trackbackDateLong;
284     }
285
286     /**
287      * Set the trackback meta-data
288      *
289      * @param metaData {@link Map} containing meta-data for this trackback
290      */

291     public void setMetaData(Map JavaDoc metaData) {
292         _metaData = metaData;
293     }
294
295     /**
296      * Return the trackback date formatted with a specified date format
297      *
298      * @param format Date format
299      * @return <code>null</code> if the format is null, otherwise returns the trackback date formatted to
300      * the specified format. If the format is invalid, returns <tt>trackbackDate.toString()</tt>
301      */

302     public String JavaDoc getDateAsFormat(String JavaDoc format) {
303         return getDateAsFormat(format, null);
304     }
305
306     /**
307      * Return the trackback date formatted with a specified date format
308      *
309      * @param format Date format
310      * @param locale Locale for date formatting
311      * @return <code>null</code> if the entry date or format is null, otherwise returns the entry date formatted to the specified format. If the format is invalid, returns <tt>trackbackDate.toString()</tt>
312      */

313     public String JavaDoc getDateAsFormat(String JavaDoc format, Locale JavaDoc locale) {
314         if (_trackbackDate == null || format == null) {
315             return null;
316         }
317
318         SimpleDateFormat JavaDoc sdf;
319         try {
320             if (locale == null) {
321                 sdf = new SimpleDateFormat JavaDoc(format);
322             } else {
323                 sdf = new SimpleDateFormat JavaDoc(format, locale);
324             }
325
326             return sdf.format(_trackbackDate);
327         } catch (IllegalArgumentException JavaDoc e) {
328             return _trackbackDate.toString();
329         }
330     }
331
332     /**
333      * Retrieve the date this trackback was created
334      *
335      * @return Date trackback was created
336      */

337     public Date JavaDoc getTrackbackDate() {
338         return _trackbackDate;
339     }
340
341     /**
342      * Set the trackback date
343      *
344      * @param trackbackDate Trackback date
345      */

346     public void setTrackbackDate(Date JavaDoc trackbackDate) {
347         _trackbackDate = trackbackDate;
348         _trackbackDateLong = _trackbackDate.getTime();
349     }
350
351     /**
352      * Get the IP
353      *
354      * @return IP
355      */

356     public String JavaDoc getIp() {
357         return _ip;
358     }
359
360     /**
361      * Get the IP
362      *
363      * @return IP
364      */

365     public void setIp(String JavaDoc ip) {
366         _ip = ip;
367     }
368
369     /**
370      * Get the status
371      *
372      * @return Status
373      */

374     public String JavaDoc getStatus() {
375         return _status;
376     }
377
378     /**
379      * Set the status
380      *
381      * @param status Status
382      */

383     public void setStatus(String JavaDoc status) {
384         _status = status;
385     }
386
387     /**
388      * Retrieve the date for this object
389      *
390      * @return Date
391      */

392     public Date JavaDoc getDate() {
393         return _trackbackDate;
394     }
395
396     /**
397      * Get the response type
398      *
399      * @return Response type
400      */

401     public String JavaDoc getType() {
402         return TRACKBACK_TYPE;
403     }
404 }
405
Popular Tags