KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > blog > data > Entry


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenChronicle
5  *
6  * $Id: Entry.java,v 1.4 2007/01/07 06:05:11 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21
22 package org.opensubsystems.blog.data;
23
24 import java.sql.Timestamp JavaDoc;
25
26 import org.opensubsystems.core.data.DataConstant;
27 import org.opensubsystems.core.data.DataObject;
28 import org.opensubsystems.core.data.ModifiableDataObject;
29
30 /**
31  * Entry within a blog. Entry has caption, text and can have an image associated
32  * with it. Entry can also contain separate URL associated with the image.
33  *
34  * @version $Id: Entry.java,v 1.4 2007/01/07 06:05:11 bastafidli Exp $
35  * @author Miro Halas
36  * @code.reviewer Miro Halas
37  * @code.reviewed Initial revision
38  */

39 public class Entry extends ModifiableDataObject
40 {
41    // Cached values ////////////////////////////////////////////////////////////
42

43    /**
44     * Maximal length of the caption field. The value depends on the underlying
45     * persistance mechanism and it is set once the persistance is initialized.
46     */

47    protected static int s_iCaptionMaxLength;
48
49    /**
50     * Maximal length of the comments field. The value depends on the underlying
51     * persistance mechanism and it is set once the persistance is initialized.
52     */

53    protected static int s_iCommentsMaxLength;
54
55    /**
56     * Maximal length of the image URL field. The value depends on the underlying
57     * persistance mechanism and it is set once the persistance is initialized.
58     */

59    protected static int s_iImageURLMaxLength;
60
61    /**
62     * Maximal length of the target URL field. The value depends on the underlying
63     * persistance mechanism and it is set once the persistance is initialized.
64     */

65    protected static int s_iTargetURLMaxLength;
66
67    /**
68     * Flag signaling if the text contains formatting or not. Example of such
69     * formatting is a newline character.
70     */

71    protected Boolean JavaDoc m_bIsPreformated = null;
72
73    // Attributes ///////////////////////////////////////////////////////////////
74

75    /**
76     * Generated serial version id for this class.
77     */

78    private static final long serialVersionUID = -2560701905097962342L;
79
80    /**
81     * Parent ID is the ID of the blog this entry belongs to.
82     */

83    protected int m_iParentId;
84
85    /**
86     * Caption is more descriptive name of the entry.
87     */

88    protected String JavaDoc m_strCaption;
89
90    /**
91     * Comments is any additional text for the entry.
92     */

93    protected String JavaDoc m_strComments;
94
95    /**
96     * Image URL of image associated with the entry.
97     */

98    protected String JavaDoc m_strImageURL;
99
100    /**
101     * Target URL for the image when user clicks on the image.
102     */

103    protected String JavaDoc m_strTargetURL;
104
105    // Constructors /////////////////////////////////////////////////////////////
106

107    static
108    {
109       DataConstant.setDataTypeName(DataConstant.BLOGENTRY_DATA_TYPE_OBJ,
110                                    "Chronicle entry");
111    }
112    
113    /**
114     * Empty entry initialized to default parameters
115     */

116    public Entry(
117    )
118    {
119       this(DataObject.NEW_ID, DataObject.NEW_ID, DataObject.NEW_ID, "", "", "",
120            "", null, null);
121    }
122
123    /**
124     * Empty entry for a specified domain initialized to default parameters
125     *
126     * @param iDomainId - Id of the domain this domain belongs to
127     */

128    public Entry(
129       int iDomainId
130    )
131    {
132       this(DataObject.NEW_ID, iDomainId, DataObject.NEW_ID, "", "", "", "", null, null);
133    }
134
135    /**
136     * Empty entry for a specified domain and parent initialized to default parameters
137     *
138     * @param iDomainId - Id of the domain this domain belongs to
139     * @param iParentId - Id of the parent this entry belongs to
140     */

141    public Entry(
142       int iDomainId,
143       int iParentId
144    )
145    {
146       this(DataObject.NEW_ID, iDomainId, iParentId, "", "", "", "", null, null);
147    }
148
149    /**
150     * Create entry from a given parameters.
151     *
152     * @param iId - Id of the entry
153     * @param iDomainId - Id of the domain this domain belongs to
154     * @param iParentId - Id of the parent this entry belongs to
155     * @param strCaption - More descriptive name of the entry
156     * @param strComments - Any additional text of the entry
157     * @param strImageURL - Image URL of image associated with the entry
158     * @param strTargetURL - Target URL for the image when user clicks on the image
159     * @param creationTimestamp - Timestamp when the entry was created
160     * @param modificationTimestamp - Timestamp when the entry was last time modified
161     */

162    public Entry(
163       int iId,
164       int iDomainId,
165       int iParentId,
166       String JavaDoc strCaption,
167       String JavaDoc strComments,
168       String JavaDoc strImageURL,
169       String JavaDoc strTargetURL,
170       Timestamp JavaDoc creationTimestamp,
171       Timestamp JavaDoc modificationTimestamp
172    )
173    {
174       super(iId, iDomainId, creationTimestamp, modificationTimestamp);
175
176       m_iParentId = iParentId;
177       m_strCaption = strCaption;
178       m_strComments = strComments;
179       m_strImageURL = strImageURL;
180       m_strTargetURL = strTargetURL;
181    }
182
183    // Accessors ////////////////////////////////////////////////////////////////
184

185    /**
186     * Id of the parent this entry belongs to.
187     *
188     * @return int
189     */

190    public int getParentId(
191    )
192    {
193       return m_iParentId;
194    }
195
196    /**
197     * Id of the parent this entry belongs to.
198     *
199     * @param iParentId - if of the parent this entry belongs to
200     */

201    public void setParentId(
202       int iParentId
203    )
204    {
205       m_iParentId = iParentId;
206    }
207
208    /**
209     * Caption is more descriptive name of the entry.
210     *
211     * @return String
212     */

213    public String JavaDoc getCaption(
214    )
215    {
216       return m_strCaption;
217    }
218
219    /**
220     * Comments is any additional description of the entry.
221     *
222     * @return String
223     */

224    public String JavaDoc getComments(
225    )
226    {
227       return m_strComments;
228    }
229
230    /**
231     * Image URL of image associated with the entry.
232     *
233     * @return String
234     */

235    public String JavaDoc getImageURL(
236    )
237    {
238       return m_strImageURL;
239    }
240
241    /**
242     * Target URL to display when user clicks on the image associated with this
243     * entry.
244     *
245     * @return String
246     */

247    public String JavaDoc getTargetURL(
248    )
249    {
250       return m_strTargetURL;
251    }
252
253    /**
254     * @return int
255     */

256    public static int getCaptionMaxLengthStatic(
257    )
258    {
259       return s_iCaptionMaxLength;
260    }
261
262    /**
263     * @return int
264     */

265    public int getCaptionMaxLength(
266    )
267    {
268       return s_iCaptionMaxLength;
269    }
270
271    /**
272     * @return int
273     */

274    public static int getCommentsMaxLengthStatic(
275    )
276    {
277       return s_iCommentsMaxLength;
278    }
279
280    /**
281     * @return int
282     */

283    public int getCommentsMaxLength(
284    )
285    {
286       return s_iCommentsMaxLength;
287    }
288
289    /**
290     * @param iCaptionMaxLength - maximal length for caption
291     */

292    public static void setCaptionMaxLength(
293       int iCaptionMaxLength
294    )
295    {
296       s_iCaptionMaxLength = iCaptionMaxLength;
297    }
298
299    /**
300     * @param iCommentsMaxLength - maximal length for comments
301     */

302    public static void setCommentsMaxLength(
303       int iCommentsMaxLength
304    )
305    {
306       s_iCommentsMaxLength = iCommentsMaxLength;
307    }
308
309    /**
310     * @return int - maximal length for image URL
311     */

312    public static int getImageURLMaxLengthStatic(
313    )
314    {
315       return s_iImageURLMaxLength;
316    }
317
318    /**
319     * @return int - maximal length for image URL
320     */

321    public int getImageURLMaxLength(
322    )
323    {
324       return s_iImageURLMaxLength;
325    }
326
327    /**
328     * @return int - maximal length for target URL
329     */

330    public static int getTargetURLMaxLengthStatic()
331    {
332       return s_iTargetURLMaxLength;
333    }
334
335    /**
336     * @return int - maximal length for target URL
337     */

338    public int getTargetURLMaxLength()
339    {
340       return s_iTargetURLMaxLength;
341    }
342
343    /**
344     * @param iImageURLMaxLength - maximal length for image URL
345     */

346    public static void setImageURLMaxLength(
347       int iImageURLMaxLength
348    )
349    {
350       s_iImageURLMaxLength = iImageURLMaxLength;
351    }
352
353    /**
354     * @param iTargetURLMaxLength - maximal length for target URL
355     */

356    public static void setTargetURLMaxLength(
357       int iTargetURLMaxLength
358    )
359    {
360       s_iTargetURLMaxLength = iTargetURLMaxLength;
361    }
362    
363    /**
364     * Flag signaling if the text contains formatting or not. Example of such
365     * formatting is a newline character.
366     *
367     * @return boolean
368     */

369    public boolean getIsPreformated()
370    {
371       if (m_bIsPreformated == null)
372       {
373          if (m_strComments == null)
374          {
375             m_bIsPreformated = Boolean.FALSE;
376          }
377          else
378          {
379             m_bIsPreformated = ((m_strComments.indexOf('\n') != -1) ? Boolean.TRUE
380                                                                     : Boolean.FALSE);
381          }
382       }
383       
384       return (m_bIsPreformated == Boolean.TRUE);
385    }
386    
387    /**
388     * {@inheritDoc}
389     */

390    public boolean isSame(
391       Object JavaDoc oObject
392    )
393    {
394       boolean bReturn = false;
395       Entry data;
396
397       if (oObject == this)
398       {
399          bReturn = true;
400       }
401       else
402       {
403          if (oObject != null && oObject instanceof Entry)
404          {
405             data = (Entry) oObject;
406             bReturn = data.getParentId() == m_iParentId
407                      && ((data.getCaption() == null && m_strCaption == null)
408                            || data.getCaption().equals(m_strCaption))
409                      && ((data.getComments() == null && m_strComments == null)
410                            || data.getComments().equals(m_strComments))
411                      && ((data.getImageURL() == null && m_strImageURL == null)
412                            || data.getImageURL().equals(m_strImageURL))
413                      && ((data.getTargetURL() == null && m_strTargetURL == null)
414                            || data.getTargetURL().equals(m_strTargetURL));
415          }
416       }
417       return bReturn;
418    }
419 }
420
Popular Tags