KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenChronicle
5  *
6  * $Id: Blog.java,v 1.5 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  * Blog is a list of entries. Simples blog has name, description and set of
32  * entries added over the time.
33  *
34  * @version $Id: Blog.java,v 1.5 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 Blog extends ModifiableDataObject
40 {
41    // Constants ////////////////////////////////////////////////////////////////
42

43    // Cached values ////////////////////////////////////////////////////////////
44

45    /**
46     * Maximal length of the folder field. The value depends on the underlying
47     * persistance mechanism and it is set once the persistance is initialized.
48     */

49    protected static int s_iFolderMaxLength;
50    
51    /**
52     * Maximal length of the caption field. The value depends on the underlying
53     * persistance mechanism and it is set once the persistance is initialized.
54     */

55    protected static int s_iCaptionMaxLength;
56
57    /**
58     * Maximal length of the comments field. The value depends on the underlying
59     * persistance mechanism and it is set once the persistance is initialized.
60     */

61    protected static int s_iCommentsMaxLength;
62    
63    /**
64     * Flag signaling if the text contains formatting or not. Example of such
65     * formatting is a newline character.
66     */

67    protected Boolean JavaDoc m_bIsPreformated = null;
68
69    // Attributes ///////////////////////////////////////////////////////////////
70

71    /**
72     * Generated serial version id for this class.
73     */

74    private static final long serialVersionUID = -6839950852321644561L;
75
76    /**
77     * Folder allows to organize blogs within folders.
78     */

79    protected String JavaDoc m_strFolder;
80    
81    /**
82     * Caption is more descriptive name of the blog.
83     */

84    protected String JavaDoc m_strCaption;
85    
86    /**
87     * Comments is any additional description of the blog.
88     */

89    protected String JavaDoc m_strComments;
90    
91    // Constructors /////////////////////////////////////////////////////////////
92

93    static
94    {
95       DataConstant.setDataTypeName(DataConstant.BLOG_DATA_TYPE_OBJ,
96                                    "Chronicle");
97    }
98    
99    /**
100     * Empty blog initialized to default parameters
101     */

102    public Blog(
103    )
104    {
105       this(DataObject.NEW_ID, DataObject.NEW_ID, "", "", "", null, null);
106    }
107    
108    /**
109     * Empty blog for a specified domain initialized to default parameters
110     *
111     * @param iDomainId - Id of the domain this blog belongs to
112     */

113    public Blog(
114       int iDomainId
115    )
116    {
117       this(DataObject.NEW_ID, iDomainId, "", "", "", null, null);
118    }
119    
120    /**
121     * Create blog from a given parameters.
122     *
123     * @param iId - Unique ID identifying this Blog
124     * @param iDomainId - Id of the domain this blog belongs to
125     * @param strBlogFolder - Folder allows to categorize Blogs to groups
126     * @param strCaption - More descriptive name of the Blog
127     * @param strComments - Any additional description of the Blog
128     * @param creationTimestamp - Timestamp when the Blog was created
129     * @param modificationTimestamp - Timestamp when the Blog was last time modified
130     */

131    public Blog(
132       int iId,
133       int iDomainId,
134       String JavaDoc strBlogFolder,
135       String JavaDoc strCaption,
136       String JavaDoc strComments,
137       Timestamp JavaDoc creationTimestamp,
138       Timestamp JavaDoc modificationTimestamp
139    )
140    {
141       super(iId, iDomainId, creationTimestamp, modificationTimestamp);
142       
143       m_strFolder = strBlogFolder.trim();
144       m_strCaption = strCaption;
145       m_strComments = strComments;
146    }
147    
148    // Public methods ///////////////////////////////////////////////////////////
149

150    /**
151     * Folder allows to organize blogs within folders.
152     *
153     * @return String
154     */

155    public String JavaDoc getFolder(
156    )
157    {
158       return m_strFolder;
159    }
160    
161    /**
162     * Caption is more descriptive name of the blog.
163     *
164     * @return String
165     */

166    public String JavaDoc getCaption(
167    )
168    {
169       return m_strCaption;
170    }
171    
172    /**
173     * Comments is any additional description of the blog.
174     *
175     * @return String
176     */

177    public String JavaDoc getComments(
178    )
179    {
180       return m_strComments;
181    }
182    
183    /**
184     * @return int
185     */

186    public static int getCaptionMaxLengthStatic(
187    )
188    {
189       return s_iCaptionMaxLength;
190    }
191
192    /**
193     * @return int
194     */

195    public int getCaptionMaxLength(
196    )
197    {
198       return s_iCaptionMaxLength;
199    }
200
201    /**
202     * @return int
203     */

204    public static int getCommentsMaxLengthStatic(
205    )
206    {
207       return s_iCommentsMaxLength;
208    }
209
210    /**
211     * @return int
212     */

213    public int getCommentsMaxLength(
214    )
215    {
216       return s_iCommentsMaxLength;
217    }
218
219    /**
220     * @return int
221     */

222    public static int getFolderMaxLengthStatic(
223    )
224    {
225       return s_iFolderMaxLength;
226    }
227
228    /**
229     * @return int
230     */

231    public int getFolderMaxLength(
232    )
233    {
234       return s_iFolderMaxLength;
235    }
236
237    /**
238     * @param iCaptionMaxLength - maximal length for caption
239     */

240    public static void setCaptionMaxLength(
241       int iCaptionMaxLength
242    )
243    {
244       s_iCaptionMaxLength = iCaptionMaxLength;
245    }
246
247    /**
248     * @param iCommentsMaxLength - maximal length for comments
249     */

250    public static void setCommentsMaxLength(
251       int iCommentsMaxLength
252    )
253    {
254       s_iCommentsMaxLength = iCommentsMaxLength;
255    }
256
257    /**
258     * @param iFolderMaxLength - maximal length for folder
259     */

260    public static void setFolderMaxLength(
261       int iFolderMaxLength
262    )
263    {
264       s_iFolderMaxLength = iFolderMaxLength;
265    }
266    
267    /**
268     * Flag signaling if the text contains formatting or not. Example of such
269     * formatting is a newline character.
270     *
271     * @return boolean
272     */

273    public boolean getIsPreformated()
274    {
275       if (m_bIsPreformated == null)
276       {
277          if (m_strComments == null)
278          {
279             m_bIsPreformated = Boolean.FALSE;
280          }
281          else
282          {
283             m_bIsPreformated = ((m_strComments.indexOf('\n') != -1) ? Boolean.TRUE
284                                                                     : Boolean.FALSE);
285          }
286       }
287       
288       return (m_bIsPreformated == Boolean.TRUE);
289    }
290
291    /**
292     * {@inheritDoc}
293     */

294    public boolean isSame(
295       Object JavaDoc oObject
296    )
297    {
298       boolean bReturn = false;
299       Blog data;
300
301       if (oObject == this)
302       {
303          bReturn = true;
304       }
305       else
306       {
307          if (oObject != null && oObject instanceof Blog)
308          {
309             data = (Blog) oObject;
310             bReturn = ((data.getFolder() == null && m_strFolder == null)
311                            || data.getFolder().equals(m_strFolder))
312                      && ((data.getCaption() == null && m_strCaption == null)
313                            || data.getCaption().equals(m_strCaption))
314                      && ((data.getComments() == null && m_strComments == null)
315                            || data.getComments().equals(m_strComments));
316          }
317       }
318       return bReturn;
319    }
320 }
321
Popular Tags