001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/help/tags/sakai_2-4-1/help-component-shared/src/java/org/sakaiproject/component/app/help/model/ResourceBean.java $
003: * $Id: ResourceBean.java 7653 2006-04-12 12:10:02Z marquard@ched.uct.ac.za $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.component.app.help.model;
021:
022: import java.net.MalformedURLException;
023: import java.net.URL;
024: import java.util.HashSet;
025: import java.util.Set;
026:
027: import org.sakaiproject.api.app.help.Category;
028: import org.sakaiproject.api.app.help.Resource;
029:
030: /**
031: * resource bean
032: * @version $Id: ResourceBean.java 7653 2006-04-12 12:10:02Z marquard@ched.uct.ac.za $
033: */
034: public class ResourceBean implements Resource, Comparable {
035: private Long id;
036: private String docId;
037: private String name;
038: private Set contexts = new HashSet();
039: private String location;
040: private String source;
041: private Long tstamp;
042: private float score;
043: private String formattedScore;
044: private String defaultForTool;
045: private String welcomePage;
046: private Category category;
047:
048: /**
049: * get id
050: * @return Returns the id.
051: */
052: public Long getId() {
053: return id;
054: }
055:
056: /**
057: * set id
058: * @param id The id to set.
059: */
060: public void setId(Long id) {
061: this .id = id;
062: }
063:
064: /**
065: * @see org.sakaiproject.api.app.help.Resource#getDocId()
066: */
067: public String getDocId() {
068: return docId;
069: }
070:
071: /**
072: * @see org.sakaiproject.api.app.help.Resource#setDocId(java.lang.String)
073: */
074: public void setDocId(String docId) {
075: this .docId = docId;
076: }
077:
078: /**
079: * @see org.sakaiproject.api.app.help.Resource#getLocation()
080: */
081: public String getLocation() {
082: return location;
083: }
084:
085: /**
086: * @see org.sakaiproject.api.app.help.Resource#setLocation(java.lang.String)
087: */
088: public void setLocation(String location) {
089: this .location = location;
090: }
091:
092: /**
093: * @see org.sakaiproject.api.app.help.Resource#getContexts()
094: */
095: public Set getContexts() {
096: return contexts;
097: }
098:
099: /**
100: * @see org.sakaiproject.api.app.help.Resource#setContexts(java.util.Set)
101: */
102: public void setContexts(Set contexts) {
103: this .contexts = contexts;
104: }
105:
106: /**
107: * @see org.sakaiproject.api.app.help.Resource#getUrl()
108: */
109: public URL getUrl() throws MalformedURLException {
110: return new URL(getLocation());
111: }
112:
113: /**
114: * @see org.sakaiproject.api.app.help.Resource#getName()
115: */
116: public String getName() {
117: return name;
118: }
119:
120: /**
121: * @see org.sakaiproject.api.app.help.Resource#setName(java.lang.String)
122: */
123: public void setName(String name) {
124: this .name = name;
125: }
126:
127: /**
128: * @see org.sakaiproject.api.app.help.Resource#getSource()
129: */
130: public String getSource() {
131: return source;
132: }
133:
134: /**
135: * @see org.sakaiproject.api.app.help.Resource#setSource(java.lang.String)
136: */
137: public void setSource(String source) {
138: this .source = source;
139: }
140:
141: /**
142: * @see org.sakaiproject.api.app.help.Resource#getTstamp()
143: */
144: public Long getTstamp() {
145: return tstamp;
146: }
147:
148: /**
149: * @see org.sakaiproject.api.app.help.Resource#setTstamp(java.lang.Long)
150: */
151: public void setTstamp(Long tstamp) {
152: this .tstamp = tstamp;
153: }
154:
155: /**
156: * @see org.sakaiproject.api.app.help.Resource#getScore()
157: */
158: public float getScore() {
159: return score;
160: }
161:
162: /**
163: * @see org.sakaiproject.api.app.help.Resource#setScore(float)
164: */
165: public void setScore(float score) {
166: this .score = score;
167: }
168:
169: /**
170: * @see org.sakaiproject.api.app.help.Resource#getDefaultForTool()
171: */
172: public String getDefaultForTool() {
173: return defaultForTool;
174: }
175:
176: /**
177: * @see org.sakaiproject.api.app.help.Resource#setDefaultForTool(java.lang.String)
178: */
179: public void setDefaultForTool(String defaultForTool) {
180: this .defaultForTool = defaultForTool;
181: }
182:
183: /**
184: * @see org.sakaiproject.api.app.help.Resource#getFormattedScore()
185: */
186: public String getFormattedScore() {
187: formattedScore = String.valueOf(score);
188: int index = formattedScore.indexOf(".");
189: formattedScore = formattedScore.substring(0, index + 2);
190: return formattedScore + "%";
191: }
192:
193: /**
194: * @see java.lang.Comparable#compareTo(java.lang.Object)
195: */
196: public int compareTo(Object object) {
197: ResourceBean resourceBean = (ResourceBean) object;
198: if (resourceBean.score != 0) {
199: return Float.compare(resourceBean.score, score);
200: } else {
201: return (id.compareTo(resourceBean.id));
202: }
203: }
204:
205: /**
206: * business key
207: * @return businessKey
208: */
209: private String businessKey() {
210: StringBuffer sb = new StringBuffer();
211: sb.append(docId);
212: return sb.toString();
213: }
214:
215: /**
216: * @see java.lang.Object#equals(java.lang.Object)
217: */
218: public boolean equals(Object obj) {
219: if (this == obj)
220: return true;
221: if (!(obj instanceof ResourceBean))
222: return false;
223: ResourceBean other = (ResourceBean) obj;
224: return this .businessKey().equals(other.businessKey());
225: }
226:
227: /**
228: * @see java.lang.Object#hashCode()
229: */
230: public int hashCode() {
231: return businessKey().hashCode();
232: }
233:
234: /**
235: * @see java.lang.Object#toString()
236: */
237: public String toString() {
238: StringBuffer sb = new StringBuffer();
239: sb.append("docId=");
240: sb.append(docId);
241: sb.append(", name=");
242: sb.append(name);
243: sb.append(", location=");
244: sb.append(location);
245: sb.append(", defaultForTool=");
246: sb.append(defaultForTool);
247: sb.append(", welcomePage=");
248: sb.append(welcomePage);
249: sb.append(", source=");
250: sb.append(source);
251: return sb.toString();
252: }
253:
254: /**
255: * get category
256: * @return Returns the category.
257: */
258: public Category getCategory() {
259: return category;
260: }
261:
262: /**
263: * set category
264: * @param category The category to set.
265: */
266: public void setCategory(Category category) {
267: this .category = category;
268: }
269:
270: public String getWelcomePage() {
271: return welcomePage;
272: }
273:
274: public void setWelcomePage(String welcomePage) {
275: this.welcomePage = welcomePage;
276: }
277: }
|