001: /**
002: * Copyright (c) 2003-2007, David A. Czarnecki
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * Redistributions of source code must retain the above copyright notice, this list of conditions and the
009: * following disclaimer.
010: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
011: * following disclaimer in the documentation and/or other materials provided with the distribution.
012: * Neither the name of "David A. Czarnecki" and "blojsom" nor the names of its contributors may be used to
013: * endorse or promote products derived from this software without specific prior written permission.
014: * Products derived from this software may not be called "blojsom", nor may "blojsom" appear in their name,
015: * without prior written permission of David A. Czarnecki.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
018: * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
019: * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
020: * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
021: * EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
022: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
025: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
026: * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
027: * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
028: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
029: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
030: */package org.blojsom.blog.database;
031:
032: import org.blojsom.blog.Entry;
033: import org.blojsom.blog.Trackback;
034: import org.blojsom.util.BlojsomUtils;
035:
036: import java.io.Serializable;
037: import java.text.SimpleDateFormat;
038: import java.util.Date;
039: import java.util.HashMap;
040: import java.util.Locale;
041: import java.util.Map;
042:
043: /**
044: * DatabaseTrackback
045: *
046: * @author David Czarnecki
047: * @version $Id: DatabaseTrackback.java,v 1.7 2007/01/17 02:35:16 czarneckid Exp $
048: * @since blojsom 3.0
049: */
050: public class DatabaseTrackback implements Trackback, Serializable {
051:
052: protected Integer _id;
053: protected Integer _blogId;
054: protected Integer _blogEntryId;
055: protected Entry _entry;
056:
057: protected String _title;
058: protected String _excerpt;
059: protected String _url;
060: protected String _blogName;
061: protected Date _trackbackDate;
062: protected long _trackbackDateLong;
063: protected Map _metaData;
064: protected String _status;
065: protected String _ip;
066:
067: /**
068: * Create a new instance of the database trackback
069: */
070: public DatabaseTrackback() {
071: }
072:
073: /**
074: * Set the trackback ID
075: *
076: * @param id Trackback ID
077: */
078: public void setId(Integer id) {
079: _id = id;
080: }
081:
082: /**
083: * Get the trackback ID
084: *
085: * @return Trackback ID
086: */
087: public Integer getId() {
088: return _id;
089: }
090:
091: /**
092: * Set the blog ID
093: *
094: * @param blogId Blog ID
095: */
096: public void setBlogId(Integer blogId) {
097: _blogId = blogId;
098: }
099:
100: /**
101: * Get the blog ID
102: *
103: * @return Blog ID
104: */
105: public Integer getBlogId() {
106: return _blogId;
107: }
108:
109: /**
110: * Get the blog entry ID
111: *
112: * @return Blog entry ID
113: */
114: public Integer getBlogEntryId() {
115: return _blogEntryId;
116: }
117:
118: /**
119: * Set the blog entry ID
120: *
121: * @param blogEntryId Blog entry ID
122: */
123: public void setBlogEntryId(Integer blogEntryId) {
124: _blogEntryId = blogEntryId;
125: }
126:
127: /**
128: * Retrieve the {@link BlogEntry} associated with this trackback
129: *
130: * @return {@link BlogEntry}
131: */
132: public Entry getEntry() {
133: return _entry;
134: }
135:
136: /**
137: * Set the {@link BlogEntry} associated with this trackback
138: *
139: * @param blogEntry {@link BlogEntry}
140: */
141: public void setEntry(Entry entry) {
142: _entry = entry;
143: }
144:
145: /**
146: * Get the title of the trackback
147: *
148: * @return Trackback title
149: */
150: public String getTitle() {
151: return _title;
152: }
153:
154: /**
155: * Get the escaped title of the trackback
156: *
157: * @return Escaped title
158: */
159: public String getEscapedTitle() {
160: return BlojsomUtils.escapeString(_title);
161: }
162:
163: /**
164: * Set the title of the trackback
165: *
166: * @param title Trackback title
167: */
168: public void setTitle(String title) {
169: _title = title;
170: }
171:
172: /**
173: * Get the excerpt of the trackback
174: *
175: * @return Trackback excerpt
176: */
177: public String getExcerpt() {
178: return _excerpt;
179: }
180:
181: /**
182: * Get the excerpt as an escaped string
183: *
184: * @return Escaped excerpt
185: */
186: public String getEscapedExcerpt() {
187: return BlojsomUtils.escapeString(_excerpt);
188: }
189:
190: /**
191: * Set the excerpt of the trackback
192: *
193: * @param excerpt Trackback excerpt
194: */
195: public void setExcerpt(String excerpt) {
196: _excerpt = excerpt;
197: }
198:
199: /**
200: * Get the url of the trackback
201: *
202: * @return Trackback url
203: */
204: public String getUrl() {
205: return _url;
206: }
207:
208: /**
209: * Get the escaped url of the trackback
210: *
211: * @return Escaped url
212: */
213: public String getEscapedUrl() {
214: return BlojsomUtils.escapeString(_url);
215: }
216:
217: /**
218: * Set the url of the trackback
219: *
220: * @param url Trackback url
221: */
222: public void setUrl(String url) {
223: _url = url;
224: }
225:
226: /**
227: * Get the blog name of the trackback
228: *
229: * @return Trackback blog name
230: */
231: public String getBlogName() {
232: return _blogName;
233: }
234:
235: /**
236: * Get the escaped blog name of the trackback
237: *
238: * @return Escaped blog name
239: */
240: public String getEscapedBlogName() {
241: return BlojsomUtils.escapeString(_blogName);
242: }
243:
244: /**
245: * Get the trackback meta-data
246: *
247: * @return Meta-data as a {@link Map}
248: */
249: public Map getMetaData() {
250: if (_metaData == null) {
251: return new HashMap();
252: }
253:
254: return _metaData;
255: }
256:
257: /**
258: * Set the blog name of the trackback
259: *
260: * @param blogName Trackback blog name
261: */
262: public void setBlogName(String blogName) {
263: _blogName = blogName;
264: }
265:
266: /**
267: * Set the date for the trackback
268: *
269: * @param trackbackDateLong Trackback date as a <code>long</code> value
270: */
271: public void setTrackbackDateLong(long trackbackDateLong) {
272: _trackbackDateLong = trackbackDateLong;
273: _trackbackDate = new Date(_trackbackDateLong);
274: }
275:
276: /**
277: * Get the date of the trackback
278: *
279: * @return Date of the trackback as a <code>long</code>
280: */
281: public long getTrackbackDateLong() {
282: return _trackbackDateLong;
283: }
284:
285: /**
286: * Set the trackback meta-data
287: *
288: * @param metaData {@link Map} containing meta-data for this trackback
289: */
290: public void setMetaData(Map metaData) {
291: _metaData = metaData;
292: }
293:
294: /**
295: * Return the trackback date formatted with a specified date format
296: *
297: * @param format Date format
298: * @return <code>null</code> if the format is null, otherwise returns the trackback date formatted to
299: * the specified format. If the format is invalid, returns <tt>trackbackDate.toString()</tt>
300: */
301: public String getDateAsFormat(String format) {
302: return getDateAsFormat(format, null);
303: }
304:
305: /**
306: * Return the trackback date formatted with a specified date format
307: *
308: * @param format Date format
309: * @param locale Locale for date formatting
310: * @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>
311: */
312: public String getDateAsFormat(String format, Locale locale) {
313: if (_trackbackDate == null || format == null) {
314: return null;
315: }
316:
317: SimpleDateFormat sdf;
318: try {
319: if (locale == null) {
320: sdf = new SimpleDateFormat(format);
321: } else {
322: sdf = new SimpleDateFormat(format, locale);
323: }
324:
325: return sdf.format(_trackbackDate);
326: } catch (IllegalArgumentException e) {
327: return _trackbackDate.toString();
328: }
329: }
330:
331: /**
332: * Retrieve the date this trackback was created
333: *
334: * @return Date trackback was created
335: */
336: public Date getTrackbackDate() {
337: return _trackbackDate;
338: }
339:
340: /**
341: * Set the trackback date
342: *
343: * @param trackbackDate Trackback date
344: */
345: public void setTrackbackDate(Date trackbackDate) {
346: _trackbackDate = trackbackDate;
347: _trackbackDateLong = _trackbackDate.getTime();
348: }
349:
350: /**
351: * Get the IP
352: *
353: * @return IP
354: */
355: public String getIp() {
356: return _ip;
357: }
358:
359: /**
360: * Get the IP
361: *
362: * @return IP
363: */
364: public void setIp(String ip) {
365: _ip = ip;
366: }
367:
368: /**
369: * Get the status
370: *
371: * @return Status
372: */
373: public String getStatus() {
374: return _status;
375: }
376:
377: /**
378: * Set the status
379: *
380: * @param status Status
381: */
382: public void setStatus(String status) {
383: _status = status;
384: }
385:
386: /**
387: * Retrieve the date for this object
388: *
389: * @return Date
390: */
391: public Date getDate() {
392: return _trackbackDate;
393: }
394:
395: /**
396: * Get the response type
397: *
398: * @return Response type
399: */
400: public String getType() {
401: return TRACKBACK_TYPE;
402: }
403: }
|