KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > exchange > items > note > model > Note


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

18
19 package sync4j.exchange.items.note.model;
20
21
22 import java.text.MessageFormat JavaDoc;
23 import java.text.ParseException JavaDoc;
24 import java.text.SimpleDateFormat JavaDoc;
25
26 import java.util.Date JavaDoc;
27 import java.util.StringTokenizer JavaDoc;
28
29 import sync4j.exchange.items.note.NoteParseException;
30 import sync4j.exchange.xml.XmlParser;
31 import sync4j.exchange.xml.XmlParseException;
32
33 /**
34  *
35  * @version $Id: Note.java,v 1.16 2005/07/05 10:07:29 luigiafassina Exp $
36  **/

37
38 public class Note {
39
40     //--------------------------------------------------------------------- Constants
41

42     private static final String JavaDoc TAG_PP_DATE = "Date" ;
43     private static final String JavaDoc TAG_PP_SUBJECT = "Subject" ;
44     private static final String JavaDoc TAG_PP_NOTE
45         = "Body" ;
46
47     private static final String JavaDoc MSG_PP =
48           "<note>\r\n" +
49           "<Subject>{0}</Subject>\r\n" +
50           "<Body>{1}</Body>\r\n" +
51           "<Date>{2}</Date>\r\n" +
52           "</note>" ;
53
54     //--------------------------------------------------------------------- Private data
55

56     private String JavaDoc id = null ;
57
58     private String JavaDoc username = null ;
59
60     private String JavaDoc subject = null ;
61
62     private String JavaDoc textDescription = null ;
63
64     private Date JavaDoc date = null ;
65
66     private String JavaDoc href = null ;
67
68     private Date JavaDoc lastModified = null ;
69     private char state = ' ' ;
70
71     //--------------------------------------------------------------------- Constructors
72

73     /**
74      * Creates a Note
75      *
76      */

77     public Note () {
78
79     }
80
81     /**
82      * Creates a Note
83      *
84      *
85      * @param id client item id
86      *
87      */

88     public Note (String JavaDoc id) {
89
90         this.id = id ;
91
92     }
93
94     /**
95      * Creates a Note
96      *
97      *
98      * @param id client item key
99      * @param t client item timestamp
100      *
101      */

102     public Note (String JavaDoc id, Date JavaDoc t)
103     throws NoteParseException {
104
105         this.id = id ;
106         this.lastModified = t ;
107
108     }
109
110     /**
111      * Creates a Note
112      *
113      *
114      * @param id client item id
115      * @param state client item state
116      *
117      */

118     public Note (String JavaDoc id, char state) {
119
120         this.id = id ;
121         this.state = state ;
122
123     }
124
125     /**
126      * Creates a Note
127      *
128      *
129      * @param id
130      * @param href
131      * @param state
132      * @param lastModified
133      *
134      */

135     public Note (String JavaDoc id ,
136                  String JavaDoc href ,
137                  char state ,
138                  Date JavaDoc lastModified) {
139
140         this.id = id ;
141         this.href = href ;
142         this.state = state ;
143         this.lastModified = lastModified ;
144
145     }
146
147     /**
148      * Creates a Note
149      *
150      *
151      * @param id client item id
152      * @param content client item content
153      * @param t client item timestamp
154      *
155      */

156     public Note (String JavaDoc id, String JavaDoc content, Date JavaDoc t)
157     throws NoteParseException {
158
159         getPPNote (id, content, t);
160
161     }
162
163     //----------------------------------------------------------------------- Public methods
164

165
166     public String JavaDoc getId() {
167         return this.id;
168     }
169
170     public String JavaDoc getUsername() {
171             return this.username;
172     }
173
174     public String JavaDoc getSubject() {
175         return this.subject;
176     }
177
178     public String JavaDoc getTextDescription() {
179         return this.textDescription;
180     }
181
182     public Date JavaDoc getDate() {
183         return this.date;
184     }
185
186
187     public Date JavaDoc getLastModified() {
188         return this.lastModified;
189     }
190
191     public String JavaDoc getHref() {
192         return this.href;
193     }
194
195     public char getState() {
196         return this.state;
197     }
198
199     public void setId(String JavaDoc id) {
200         this.id = id;
201     }
202
203     public void setUsername(String JavaDoc username) {
204         this.username = username;
205     }
206
207     public void setSubject(String JavaDoc subject) {
208         this.subject = subject;
209     }
210
211     public void setTextDescription(String JavaDoc textDescription) {
212         this.textDescription = textDescription;
213     }
214
215     public void setDate(Date JavaDoc date) {
216         this.date = date;
217     }
218
219     public void setLastModified(Date JavaDoc lastModified) {
220         this.lastModified = lastModified;
221     }
222
223     public void setHref(String JavaDoc href) {
224             this.href = href;
225     }
226
227     public void setState(char state) {
228         this.state = state;
229     }
230
231     /**
232      * Set a Note properties from Client format content
233      *
234      *
235      * @param id client item id
236      * @param content client item content
237      * @param t client item timestamp
238      *
239      */

240     public void getPPNote (String JavaDoc id, String JavaDoc content, Date JavaDoc t)
241     throws NoteParseException {
242
243         String JavaDoc dt = null ;
244
245         this.id = id ;
246         this.lastModified = t ;
247
248         try {
249
250             XmlParser p = new XmlParser();
251
252             dt = p.getXMLInitTagValue(content, TAG_PP_DATE );
253
254             this.date = p.clientDateToDate (dt);
255
256             this.subject = p.getXMLInitTagValue (content, TAG_PP_SUBJECT );
257
258             this.textDescription
259                 = p.getXMLInitTagValue (content, TAG_PP_NOTE);
260
261         } catch (NumberFormatException JavaDoc e) {
262             throw new NoteParseException(e.getMessage());
263         } catch (XmlParseException e) {
264             throw new NoteParseException(e.getMessage());
265         }
266
267     }
268
269     /**
270      * Set a Note properties to Client format content
271      *
272      * @return content in client format
273      *
274      */

275     public String JavaDoc toXML()
276     throws NoteParseException {
277
278          String JavaDoc ppMsg = null ;
279          String JavaDoc date = null ;
280
281          XmlParser p = new XmlParser();
282
283          try {
284
285              date = p.toClientDate (this.date) ;
286
287              ppMsg = MessageFormat.format(MSG_PP,
288                 new Object JavaDoc[] {
289                                 p.getString(subject ) ,
290                                 p.getString(textDescription ) ,
291                                 p.getString(date )
292
293                               }
294              );
295
296          } catch (Exception JavaDoc e) {
297              throw new NoteParseException ("Error composing calendar Device: " +
298                                            e.getMessage());
299          }
300
301          return ppMsg;
302
303      }
304
305 }
306
Popular Tags