001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018: package org.apache.roller.pojos;
019:
020: import org.apache.roller.RollerException;
021: import org.apache.roller.business.BookmarkManager;
022: import org.apache.roller.business.Roller;
023: import org.apache.roller.business.RollerFactory;
024:
025: import java.io.Serializable;
026:
027: /**
028: * <p>Represents a single URL in a user's favorite web-bookmarks collection.
029: * Don't construct one of these yourself, instead use the create method in
030: * the your BookmarkManager implementation.</p>
031: *
032: * @ejb:bean name="BookmarkData"
033: *
034: * @struts.form include-all="true"
035: * extends="org.apache.struts.validator.ValidatorForm"
036: *
037: * @hibernate.class lazy="false" table="bookmark"
038: * @hibernate.cache usage="read-write"
039: */
040: public class BookmarkData extends PersistentObject implements
041: Serializable, Comparable {
042: static final long serialVersionUID = 2315131256728236003L;
043:
044: private FolderData folder;
045:
046: private String id = null;
047: private String name;
048: private String description;
049: private String url;
050: private Integer weight;
051: private Integer priority;
052: private String image;
053: private String feedUrl;
054:
055: private BookmarkManager bookmarkManager = null;
056:
057: //----------------------------------------------------------- Constructors
058:
059: /** Default constructor, for use in form beans only. */
060: public BookmarkData() {
061: }
062:
063: public BookmarkData(FolderData parent, String name, String desc,
064: String url, String feedUrl, Integer weight,
065: Integer priority, String image) {
066: this .folder = parent;
067: this .name = name;
068: this .description = desc;
069: this .url = url;
070: this .feedUrl = feedUrl;
071: this .weight = weight;
072: this .priority = priority;
073: this .image = image;
074: }
075:
076: /** For use by BookmarkManager implementations only. */
077: public BookmarkData(BookmarkManager bmgr) {
078: bookmarkManager = bmgr;
079: }
080:
081: //------------------------------------------------------------- Attributes
082:
083: /**
084: * @roller.wrapPojoMethod type="simple"
085: *
086: * @ejb:persistent-field
087: *
088: * @hibernate.id column="id"
089: * generator-class="uuid.hex" unsaved-value="null"
090: */
091: public String getId() {
092: return this .id;
093: }
094:
095: /** @ejb:persistent-field */
096: public void setId(String id) {
097: this .id = id;
098: }
099:
100: /**
101: * Name of bookmark.
102: *
103: * @roller.wrapPojoMethod type="simple"
104: *
105: * @struts.validator type="required" msgkey="errors.required"
106: * @struts.validator-args arg0resource="bookmarkForm.name"
107: *
108: * @ejb:persistent-field
109: *
110: * @hibernate.property column="name" non-null="true" unique="false"
111: */
112: public String getName() {
113: return this .name;
114: }
115:
116: /** @ejb:persistent-field */
117: public void setName(String name) {
118: this .name = name;
119: }
120:
121: /**
122: * Description of bookmark.
123: *
124: * @roller.wrapPojoMethod type="simple"
125: *
126: * @ejb:persistent-field
127: *
128: * @hibernate.property column="description" non-null="true" unique="false"
129: */
130: public String getDescription() {
131: return this .description;
132: }
133:
134: /** @ejb:persistent-field */
135: public void setDescription(String description) {
136: this .description = description;
137: }
138:
139: /**
140: * URL of bookmark.
141: *
142: * @roller.wrapPojoMethod type="simple"
143: *
144: * @ejb:persistent-field
145: *
146: * @hibernate.property column="url" non-null="true" unique="false"
147: */
148: public String getUrl() {
149: return this .url;
150: }
151:
152: /** @ejb:persistent-field */
153: public void setUrl(String url) {
154: this .url = url;
155: }
156:
157: /**
158: * Weight indicates prominence of link
159: *
160: * @roller.wrapPojoMethod type="simple"
161: *
162: * @struts.validator type="required" msgkey="errors.required"
163: * @struts.validator type="integer" msgkey="errors.integer"
164: * @struts.validator-args arg0resource="bookmarkForm.weight"
165: *
166: * @ejb:persistent-field
167: *
168: * @hibernate.property column="weight" non-null="true" unique="false"
169: */
170: public java.lang.Integer getWeight() {
171: return this .weight;
172: }
173:
174: /** @ejb:persistent-field */
175: public void setWeight(java.lang.Integer weight) {
176: this .weight = weight;
177: }
178:
179: /**
180: * Priority determines order of display
181: *
182: * @roller.wrapPojoMethod type="simple"
183: *
184: * @struts.validator type="required" msgkey="errors.required"
185: * @struts.validator type="integer" msgkey="errors.integer"
186: * @struts.validator-args arg0resource="bookmarkForm.priority"
187: *
188: * @ejb:persistent-field
189: *
190: * @hibernate.property column="priority" non-null="true" unique="false"
191: */
192: public java.lang.Integer getPriority() {
193: return this .priority;
194: }
195:
196: /** @ejb:persistent-field */
197: public void setPriority(java.lang.Integer priority) {
198: this .priority = priority;
199: }
200:
201: /**
202: * @ejb:persistent-field
203: *
204: * @roller.wrapPojoMethod type="simple"
205: *
206: * @hibernate.property column="image" non-null="true" unique="false"
207: */
208: public String getImage() {
209: return this .image;
210: }
211:
212: /** @ejb:persistent-field */
213: public void setImage(String image) {
214: this .image = image;
215: }
216:
217: /**
218: * @ejb:persistent-field
219: *
220: * @roller.wrapPojoMethod type="simple"
221: *
222: * @hibernate.property column="feedurl" non-null="true" unique="false"
223: */
224: public String getFeedUrl() {
225: return this .feedUrl;
226: }
227:
228: /** @ejb:persistent-field */
229: public void setFeedUrl(String feedUrl) {
230: this .feedUrl = feedUrl;
231: }
232:
233: //---------------------------------------------------------- Relationships
234:
235: /**
236: * @roller.wrapPojoMethod type="pojo"
237: * @ejb:persistent-field
238: * @hibernate.many-to-one column="folderid" cascade="none" not-null="true"
239: */
240: public org.apache.roller.pojos.FolderData getFolder() {
241: return this .folder;
242: }
243:
244: /** @ejb:persistent-field */
245: public void setFolder(org.apache.roller.pojos.FolderData folder) {
246: this .folder = folder;
247: }
248:
249: //------------------------------------------------------- Good citizenship
250:
251: public String toString() {
252: StringBuffer str = new StringBuffer("{");
253:
254: str.append("id=" + id + " " + "name=" + name + " "
255: + "description=" + description + " " + "url=" + url
256: + " " + "weight=" + weight + " " + "priority="
257: + priority + " " + "folderId=" + "image=" + image + " "
258: + "feedUrl=" + feedUrl);
259: str.append('}');
260:
261: return (str.toString());
262: }
263:
264: public boolean equals(Object pOther) {
265: if (pOther instanceof BookmarkData) {
266: BookmarkData lTest = (BookmarkData) pOther;
267: boolean lEquals = true;
268:
269: if (this .id == null) {
270: lEquals = lEquals && (lTest.getId() == null);
271: } else {
272: lEquals = lEquals && this .id.equals(lTest.getId());
273: }
274:
275: if (this .name == null) {
276: lEquals = lEquals && (lTest.getName() == null);
277: } else {
278: lEquals = lEquals && this .name.equals(lTest.getName());
279: }
280:
281: if (this .description == null) {
282: lEquals = lEquals && (lTest.getDescription() == null);
283: } else {
284: lEquals = lEquals
285: && this .description.equals(lTest
286: .getDescription());
287: }
288:
289: if (this .url == null) {
290: lEquals = lEquals && (lTest.getUrl() == null);
291: } else {
292: lEquals = lEquals && this .url.equals(lTest.getUrl());
293: }
294:
295: if (this .weight == null) {
296: lEquals = lEquals && (lTest.getWeight() == null);
297: } else {
298: lEquals = lEquals
299: && this .weight.equals(lTest.getWeight());
300: }
301:
302: if (this .priority == null) {
303: lEquals = lEquals && (lTest.getPriority() == null);
304: } else {
305: lEquals = lEquals
306: && this .priority.equals(lTest.getPriority());
307: }
308:
309: // if (this.mFolder == null)
310: // {
311: // lEquals = lEquals && (lTest.mFolder == null);
312: // }
313: // else
314: // {
315: // lEquals = lEquals && this.mFolder.equals(lTest.mFolder);
316: // }
317: //
318: if (this .image == null) {
319: lEquals = lEquals && (lTest.getImage() == null);
320: } else {
321: lEquals = lEquals
322: && this .image.equals(lTest.getImage());
323: }
324:
325: if (this .feedUrl == null) {
326: lEquals = lEquals && (lTest.getFeedUrl() == null);
327: } else {
328: lEquals = lEquals
329: && this .feedUrl.equals(lTest.getFeedUrl());
330: }
331:
332: return lEquals;
333: } else {
334: return false;
335: }
336: }
337:
338: public int hashCode() {
339: int result = 17;
340: result = (37 * result)
341: + ((this .id != null) ? this .id.hashCode() : 0);
342: result = (37 * result)
343: + ((this .name != null) ? this .name.hashCode() : 0);
344: result = (37 * result)
345: + ((this .description != null) ? this .description
346: .hashCode() : 0);
347: result = (37 * result)
348: + ((this .url != null) ? this .url.hashCode() : 0);
349: result = (37 * result)
350: + ((this .weight != null) ? this .weight.hashCode() : 0);
351: result = (37 * result)
352: + ((this .priority != null) ? this .priority.hashCode()
353: : 0);
354: result = (37 * result)
355: + ((this .folder != null) ? this .folder.hashCode() : 0);
356: result = (37 * result)
357: + ((this .image != null) ? this .image.hashCode() : 0);
358: result = (37 * result)
359: + ((this .feedUrl != null) ? this .feedUrl.hashCode() : 0);
360:
361: return result;
362: }
363:
364: /**
365: * Setter is needed in RollerImpl.storePersistentObject()
366: */
367: public void setData(
368: org.apache.roller.pojos.PersistentObject otherData) {
369: BookmarkData other = (BookmarkData) otherData;
370: this .id = other.getId();
371: this .name = other.getName();
372: this .description = other.getDescription();
373: this .url = other.getUrl();
374: this .weight = other.getWeight();
375: this .priority = other.getPriority();
376: this .folder = other.getFolder();
377: this .image = other.getImage();
378: this .feedUrl = other.getUrl();
379: }
380:
381: /**
382: * @see java.lang.Comparable#compareTo(java.lang.Object)
383: */
384: public int compareTo(Object o) {
385: return bookmarkComparator.compare(this , o);
386: }
387:
388: private BookmarkComparator bookmarkComparator = new BookmarkComparator();
389:
390: /**
391: * @param impl
392: */
393: public void setBookmarkManager(BookmarkManager bmgr) {
394: bookmarkManager = bmgr;
395: }
396:
397: public WebsiteData getWebsite() {
398: return this.folder.getWebsite();
399: }
400:
401: }
|