KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > roller > pojos > BookmarkData


1 package org.roller.pojos;
2
3 import org.roller.RollerException;
4 import org.roller.model.BookmarkManager;
5 import org.roller.model.Roller;
6 import org.roller.model.RollerFactory;
7
8 import java.io.Serializable JavaDoc;
9
10 /**
11  * <p>Represents a single URL in a user's favorite web-bookmarks collection.
12  * Don't construct one of these yourself, instead use the create method in
13  * the your BookmarkManager implementation.</p>
14  *
15  * @ejb:bean name="BookmarkData"
16  *
17  * @struts.form include-all="true"
18  * extends="org.apache.struts.validator.ValidatorForm"
19  *
20  * @hibernate.class table="bookmark"
21  * hibernate.jcs-cache usage="read-write"
22  */

23 public class BookmarkData extends org.roller.pojos.PersistentObject
24     implements Serializable JavaDoc, Comparable JavaDoc
25 {
26     static final long serialVersionUID = 2315131256728236003L;
27     
28     protected FolderData folder;
29
30     protected String JavaDoc id = null;
31     protected String JavaDoc name;
32     protected String JavaDoc description;
33     protected String JavaDoc url;
34     protected Integer JavaDoc weight;
35     protected Integer JavaDoc priority;
36     protected String JavaDoc image;
37     protected String JavaDoc feedUrl;
38     
39     protected BookmarkManager bookmarkManager = null;
40
41     //----------------------------------------------------------- Constructors
42

43     /** Default constructor, for use in form beans only. */
44     public BookmarkData()
45     {
46     }
47     
48     public BookmarkData(
49         FolderData parent,
50         String JavaDoc name,
51         String JavaDoc desc,
52         String JavaDoc url,
53         String JavaDoc feedUrl,
54         Integer JavaDoc weight,
55         Integer JavaDoc priority,
56         String JavaDoc image)
57     {
58         this.folder = parent;
59         this.name = name;
60         this.description = desc;
61         this.url = url;
62         this.feedUrl = feedUrl;
63         this.weight = weight;
64         this.priority = priority;
65         this.image = image;
66     }
67
68     /** For use by BookmarkManager implementations only. */
69     public BookmarkData(BookmarkManager bmgr)
70     {
71         bookmarkManager = bmgr;
72     }
73
74     //------------------------------------------------------------- Attributes
75

76     /**
77      * @ejb:persistent-field
78      *
79      * @hibernate.id column="id" type="string"
80      * generator-class="uuid.hex" unsaved-value="null"
81      */

82     public String JavaDoc getId()
83     {
84         return this.id;
85     }
86
87     /** @ejb:persistent-field */
88     public void setId(String JavaDoc id)
89     {
90         this.id = id;
91     }
92
93     /**
94      * Name of bookmark.
95      *
96      * @struts.validator type="required" msgkey="errors.required"
97      * @struts.validator-args arg0resource="bookmarkForm.name"
98      *
99      * @ejb:persistent-field
100      *
101      * @hibernate.property column="name" non-null="true" unique="false"
102      */

103     public String JavaDoc getName()
104     {
105         return this.name;
106     }
107
108     /** @ejb:persistent-field */
109     public void setName(String JavaDoc name)
110     {
111         this.name = name;
112     }
113
114     /**
115      * Description of bookmark.
116      *
117      * @ejb:persistent-field
118      *
119      * @hibernate.property column="description" non-null="true" unique="false"
120      */

121     public String JavaDoc getDescription()
122     {
123         return this.description;
124     }
125
126     /** @ejb:persistent-field */
127     public void setDescription(String JavaDoc description)
128     {
129         this.description = description;
130     }
131
132     /**
133      * URL of bookmark.
134      *
135      * @ejb:persistent-field
136      *
137      * @hibernate.property column="url" non-null="true" unique="false"
138      */

139     public String JavaDoc getUrl()
140     {
141         return this.url;
142     }
143
144     /** @ejb:persistent-field */
145     public void setUrl(String JavaDoc url)
146     {
147         this.url = url;
148     }
149
150     /**
151      * Weight indicates prominence of link
152      *
153      * @struts.validator type="required" msgkey="errors.required"
154      * @struts.validator type="integer" msgkey="errors.integer"
155      * @struts.validator-args arg0resource="bookmarkForm.weight"
156      *
157      * @ejb:persistent-field
158      *
159      * @hibernate.property column="weight" non-null="true" unique="false"
160      */

161     public java.lang.Integer JavaDoc getWeight()
162     {
163         return this.weight;
164     }
165
166     /** @ejb:persistent-field */
167     public void setWeight(java.lang.Integer JavaDoc weight)
168     {
169         this.weight = weight;
170     }
171
172     /**
173      * Priority determines order of display
174      *
175      * @struts.validator type="required" msgkey="errors.required"
176      * @struts.validator type="integer" msgkey="errors.integer"
177      * @struts.validator-args arg0resource="bookmarkForm.priority"
178      *
179      * @ejb:persistent-field
180      *
181      * @hibernate.property column="priority" non-null="true" unique="false"
182      */

183     public java.lang.Integer JavaDoc getPriority()
184     {
185         return this.priority;
186     }
187
188     /** @ejb:persistent-field */
189     public void setPriority(java.lang.Integer JavaDoc priority)
190     {
191         this.priority = priority;
192     }
193
194     /**
195      * @ejb:persistent-field
196      *
197      * @hibernate.property column="image" non-null="true" unique="false"
198      */

199     public String JavaDoc getImage()
200     {
201         return this.image;
202     }
203
204     /** @ejb:persistent-field */
205     public void setImage(String JavaDoc image)
206     {
207         this.image = image;
208     }
209
210     /**
211      * @ejb:persistent-field
212      *
213      * @hibernate.property column="feedurl" non-null="true" unique="false"
214      */

215     public String JavaDoc getFeedUrl()
216     {
217         return this.feedUrl;
218     }
219
220     /** @ejb:persistent-field */
221     public void setFeedUrl(String JavaDoc feedUrl)
222     {
223         this.feedUrl = feedUrl;
224     }
225
226     //---------------------------------------------------------- Relationships
227

228     /**
229      * @ejb:persistent-field
230      * @hibernate.many-to-one column="folderid" cascade="none" not-null="true"
231      */

232     public org.roller.pojos.FolderData getFolder()
233     {
234         return this.folder;
235     }
236
237     /** @ejb:persistent-field */
238     public void setFolder(org.roller.pojos.FolderData folder)
239     {
240         this.folder = folder;
241     }
242
243     //------------------------------------------------------- Good citizenship
244

245     public String JavaDoc toString()
246     {
247         StringBuffer JavaDoc str = new StringBuffer JavaDoc("{");
248
249         str.append("id=" + id + " " + "name=" + name + " " + "description=" +
250                    description + " " + "url=" + url + " " + "weight=" +
251                    weight + " " + "priority=" + priority + " " + "folderId=" +
252                    "image=" + image + " " + "feedUrl=" +
253                    feedUrl);
254         str.append('}');
255
256         return (str.toString());
257     }
258
259     public boolean equals(Object JavaDoc pOther)
260     {
261         if (pOther instanceof BookmarkData)
262         {
263             BookmarkData lTest = (BookmarkData) pOther;
264             boolean lEquals = true;
265
266             if (this.id == null)
267             {
268                 lEquals = lEquals && (lTest.id == null);
269             }
270             else
271             {
272                 lEquals = lEquals && this.id.equals(lTest.id);
273             }
274
275             if (this.name == null)
276             {
277                 lEquals = lEquals && (lTest.name == null);
278             }
279             else
280             {
281                 lEquals = lEquals && this.name.equals(lTest.name);
282             }
283
284             if (this.description == null)
285             {
286                 lEquals = lEquals && (lTest.description == null);
287             }
288             else
289             {
290                 lEquals = lEquals &&
291                           this.description.equals(lTest.description);
292             }
293
294             if (this.url == null)
295             {
296                 lEquals = lEquals && (lTest.url == null);
297             }
298             else
299             {
300                 lEquals = lEquals && this.url.equals(lTest.url);
301             }
302
303             if (this.weight == null)
304             {
305                 lEquals = lEquals && (lTest.weight == null);
306             }
307             else
308             {
309                 lEquals = lEquals && this.weight.equals(lTest.weight);
310             }
311
312             if (this.priority == null)
313             {
314                 lEquals = lEquals && (lTest.priority == null);
315             }
316             else
317             {
318                 lEquals = lEquals && this.priority.equals(lTest.priority);
319             }
320
321 // if (this.mFolder == null)
322
// {
323
// lEquals = lEquals && (lTest.mFolder == null);
324
// }
325
// else
326
// {
327
// lEquals = lEquals && this.mFolder.equals(lTest.mFolder);
328
// }
329
//
330
if (this.image == null)
331             {
332                 lEquals = lEquals && (lTest.image == null);
333             }
334             else
335             {
336                 lEquals = lEquals && this.image.equals(lTest.image);
337             }
338
339             if (this.feedUrl == null)
340             {
341                 lEquals = lEquals && (lTest.feedUrl == null);
342             }
343             else
344             {
345                 lEquals = lEquals && this.feedUrl.equals(lTest.feedUrl);
346             }
347
348             return lEquals;
349         }
350         else
351         {
352             return false;
353         }
354     }
355
356     public int hashCode()
357     {
358         int result = 17;
359         result = (37 * result) +
360                  ((this.id != null) ? this.id.hashCode() : 0);
361         result = (37 * result) +
362                  ((this.name != null) ? this.name.hashCode() : 0);
363         result = (37 * result) +
364                  ((this.description != null) ? this.description.hashCode() : 0);
365         result = (37 * result) +
366                  ((this.url != null) ? this.url.hashCode() : 0);
367         result = (37 * result) +
368                  ((this.weight != null) ? this.weight.hashCode() : 0);
369         result = (37 * result) +
370                  ((this.priority != null) ? this.priority.hashCode() : 0);
371         result = (37 * result) +
372                  ((this.folder != null) ? this.folder.hashCode() : 0);
373         result = (37 * result) +
374                  ((this.image != null) ? this.image.hashCode() : 0);
375         result = (37 * result) +
376                  ((this.feedUrl != null) ? this.feedUrl.hashCode() : 0);
377
378         return result;
379     }
380
381     /**
382      * Setter is needed in RollerImpl.storePersistentObject()
383      */

384     public void setData(org.roller.pojos.PersistentObject otherData)
385     {
386         this.id = ((BookmarkData) otherData).id;
387         this.name = ((BookmarkData) otherData).name;
388         this.description = ((BookmarkData) otherData).description;
389         this.url = ((BookmarkData) otherData).url;
390         this.weight = ((BookmarkData) otherData).weight;
391         this.priority = ((BookmarkData) otherData).priority;
392         this.folder = ((BookmarkData) otherData).folder;
393         this.image = ((BookmarkData) otherData).image;
394         this.feedUrl = ((BookmarkData) otherData).feedUrl;
395     }
396
397     /**
398      * @see java.lang.Comparable#compareTo(java.lang.Object)
399      */

400     public int compareTo(Object JavaDoc o)
401     {
402         return bookmarkComparator.compare(this, o);
403     }
404     
405     private BookmarkComparator bookmarkComparator = new BookmarkComparator();
406
407     /**
408      * @param impl
409      */

410     public void setBookmarkManager(BookmarkManager bmgr)
411     {
412         bookmarkManager = bmgr;
413     }
414
415     public boolean canSave() throws RollerException
416     {
417         Roller roller = RollerFactory.getRoller();
418         if (roller.getUser().equals(UserData.SYSTEM_USER))
419         {
420             return true;
421         }
422         if (roller.getUser().equals(getFolder().getWebsite().getUser()))
423         {
424             return true;
425         }
426         return false;
427     }
428 }
Popular Tags