KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > notes > Note


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2003 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.applications.notes;
20
21 import java.io.Serializable JavaDoc;
22 import java.text.DateFormat JavaDoc;
23 import java.util.*;
24
25 import org.lucane.client.Client;
26
27 public class Note implements Serializable JavaDoc
28 {
29   //-- attributes
30
private String JavaDoc id;
31
32   private String JavaDoc author;
33   private String JavaDoc title;
34   private String JavaDoc content;
35
36   private Date creationDate;
37   private Date editionDate;
38
39   private boolean published;
40   private boolean commentable;
41
42   /**
43    * Public constructor
44    * Used for new notes
45    */

46   public Note(String JavaDoc author, String JavaDoc title, String JavaDoc content, boolean published, boolean commentable)
47   {
48     this.id = null;
49
50     this.author = author;
51     this.title = title;
52     this.content = content.replaceAll(" \\/\\>", ">");
53
54
55     this.creationDate = new Date();
56     this.editionDate = null;
57
58     this.published = published;
59     this.commentable = commentable;
60   }
61
62   /**
63    * Protected constructor
64    * Used when loading notes from the database
65    */

66   protected Note(String JavaDoc id, String JavaDoc author, String JavaDoc title, String JavaDoc content, String JavaDoc creationDate, String JavaDoc editionDate, String JavaDoc published, String JavaDoc commentable)
67   {
68     this.id = id;
69     
70     this.author = author;
71     this.title = title;
72     this.content = content.replaceAll(" \\/\\>", ">");
73
74
75     this.creationDate = new Date(Long.parseLong(creationDate));
76     if(editionDate.length() > 0 && !editionDate.equals("0"))
77       this.editionDate = new Date(Long.parseLong(editionDate));
78     else
79       this.editionDate = null;
80
81     this.published = Integer.parseInt(published) > 0;
82     this.commentable = Integer.parseInt(commentable) > 0;
83   }
84
85
86   /**
87    * Edit the note content
88    */

89   public void editContent(String JavaDoc title, String JavaDoc content, boolean isPublic, boolean isCommentable)
90   {
91       this.title = title;
92     this.content = content;
93     this.editionDate = new Date();
94     this.published = isPublic;
95     this.commentable = isCommentable;
96   }
97
98   //-- getters
99

100   public void setId(String JavaDoc id)
101   {
102     this.id = id;
103   }
104   
105   public String JavaDoc getId()
106   {
107     return this.id;
108   }
109
110   public String JavaDoc getAuthor()
111   {
112     return this.author;
113   }
114   
115   public String JavaDoc getTitle()
116   {
117     return this.title;
118   }
119
120   public String JavaDoc getContent()
121   {
122     return this.content;
123   }
124
125   public Date getCreationDate()
126   {
127     return this.creationDate;
128   }
129   
130   public Date getEditionDate()
131   {
132     return this.editionDate;
133   }
134
135   public boolean isPublic()
136   {
137     return this.published;
138   }
139   
140   public boolean isCommentable()
141   {
142     return this.commentable;
143   }
144
145   public String JavaDoc toString()
146   {
147     Locale locale = new Locale(Client.getInstance().getConfig().getLanguage());
148     DateFormat JavaDoc df = DateFormat.getDateInstance(DateFormat.LONG, locale);
149     return this.title + " - " + df.format(this.creationDate);
150   }
151 }
152
Popular Tags