001: /**********************************************************************************
002: *
003: * Copyright (c) 2003, 2004 The Regents of the University of Michigan, Trustees of Indiana University,
004: * Board of Trustees of the Leland Stanford, Jr., University, and The MIT Corporation
005: *
006: * Licensed under the Educational Community License Version 1.0 (the "License");
007: * By obtaining, using and/or copying this Original Work, you agree that you have read,
008: * understand, and will comply with the terms and conditions of the Educational Community License.
009: * You may obtain a copy of the License at:
010: *
011: * http://cvs.sakaiproject.org/licenses/license_1_0.html
012: *
013: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
014: * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
015: * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
016: * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
017: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
018: *
019: **********************************************************************************/package edu.indiana.lib.twinpeaks.search;
020:
021: import edu.indiana.lib.twinpeaks.util.*;
022:
023: import java.io.*;
024: import java.util.*;
025:
026: import org.osid.repository.Asset;
027: import org.osid.repository.AssetIterator;
028: import org.osid.repository.Record;
029: import org.osid.repository.Part;
030: import org.osid.repository.PartStructure;
031:
032: /**
033: * Encapsulate one matching search item
034: */
035: public class MatchItem {
036:
037: private static org.apache.commons.logging.Log _log = LogUtils
038: .getLog(MatchItem.class);
039:
040: private String _displayName;
041: private String _description;
042: private String _id;
043: private String _openUrl;
044: private List _partStructureList;
045:
046: private String _previewUrl;
047: private String _previewImage;
048: private String _previewText;
049: private String _persistentUrl;
050: private String _persistentParameters;
051: private String _persistentParametersForEncoding;
052: private String _persistentText;
053:
054: /**
055: * Constructor
056: */
057: public MatchItem() {
058: super ();
059:
060: _partStructureList = new ArrayList();
061: }
062:
063: /**
064: * Fetch the Asset "display name"
065: * @return Display name text
066: */
067: public String getDisplayName() {
068: return _displayName;
069: }
070:
071: /**
072: * Set the Asset "display name"
073: * @param displayName Display name text
074: */
075: public void setDisplayName(String displayName) {
076: _displayName = displayName;
077: }
078:
079: /**
080: * Fetch additional descriptive text
081: * @return Additional text
082: */
083: public String getDescription() {
084: return _description;
085: }
086:
087: /**
088: * Set description text
089: * @param text Description text
090: */
091: public void setDescription(String text) {
092: _description = normalizeDescription(text);
093: }
094:
095: /**
096: * Fetch the Asset ID
097: * @return ID text
098: */
099: public String getId() {
100: return _id;
101: }
102:
103: /**
104: * Set the ID
105: * @param id ID text
106: */
107: public void setId(String id) {
108: _id = normalizeDescription(id);
109: }
110:
111: /**
112: * Add an additional PartStructure too the list
113: * @param partStructureId The PartStructure Id to add
114: * @param value PartStructure value
115: */
116: public void addPartStructure(org.osid.shared.Id partStructureId,
117: Serializable value) {
118: _partStructureList.add(new PartPair(partStructureId, value));
119: }
120:
121: /**
122: * Get an interator for the PartStructureId list (PartPair objects)
123: * @return PartStructure list Iterator
124: */
125: public Iterator partPairIterator() {
126: return _partStructureList.iterator();
127: }
128:
129: /**
130: * Fetch the OpenURL generated at search time
131: * @return The generated OpenURL
132: */
133: public String getOpenUrl() {
134: return _openUrl;
135: }
136:
137: /**
138: * Save the OpenUrl discovered at search time
139: * @param url URL string
140: */
141: public void setOpenUrl(String url) {
142: _openUrl = url;
143: }
144:
145: /**
146: * Fetch the URL of the "preview" view of the matching item
147: * @return A fully qualified URL value
148: */
149: public String getPreviewUrl() {
150: return _previewUrl;
151: }
152:
153: /**
154: * Set the "preview" URL
155: * @param url Preview URL string
156: */
157: public void setPreviewUrl(String url) {
158: _previewUrl = url;
159: }
160:
161: /**
162: * Fetch the image associated with the "preview" URL
163: * @return Image source specification
164: */
165: public String getPreviewImage() {
166: return _previewImage;
167: }
168:
169: /**
170: * Set "preview" URL image
171: * @param source Image source specification
172: */
173: public void setPreviewImage(String source) {
174: _previewImage = source;
175: }
176:
177: /**
178: * Fetch the text associated with the "preview" URL
179: * @return Text
180: */
181: public String getPreviewText() {
182: return _previewText;
183: }
184:
185: /**
186: * Set "preview" URL text
187: * @param text Preview text
188: */
189: public void setPreviewText(String text) {
190: _previewText = text;
191: }
192:
193: /**
194: * Fetch the URL for the persistent reference
195: * @return A fully qualified URL value (minus any arguments)
196: */
197: public String getPersistentUrl() {
198: return _persistentUrl;
199: }
200:
201: /**
202: * Set the persistent URL
203: * @param url Persistent URL
204: */
205: public void setPersistentUrl(String url) {
206: _persistentUrl = url;
207: }
208:
209: /**
210: * Set the persistent URL and simple parameters
211: * @param persistentHref Persistent URL
212: */
213: public void setPersistentUrlAndParameters(String persistentHref) {
214: String url = persistentHref;
215:
216: if (!StringUtils.isNull(url)) {
217: int index;
218:
219: if ((index = url.indexOf('?')) != -1) {
220: if (++index < url.length()) {
221: _persistentParameters = url.substring(index);
222: }
223: url = url.substring(0, index);
224: }
225: }
226: _persistentUrl = url;
227: }
228:
229: /**
230: * Fetch simple parameters for the persistent reference
231: * @return Parameters (<code>?name1=value1&name2=value2</code>)
232: */
233: public String getPersistentUrlParameters() {
234: return (_persistentParameters == null) ? ""
235: : _persistentParameters;
236: }
237:
238: /**
239: * Set persistent URL parameter values
240: * @param parameters Parameter text (name=value pairs)
241: */
242: public void setPersistentUrlParameters(String parameters) {
243: _persistentParameters = parameters;
244: }
245:
246: /**
247: * Fetch any persistent reference parameters that <i>must be</i> URL encoded.
248: *<p>
249: * Note: When used with IE, the HTML editor parses encoded text, replacing
250: * entity sequences and the like with "real" characters - in rare cases, this
251: * will cause the resultant URL to fail. As a work around, the query handler
252: * can specifiy parameters that need to be wrapped in a JavaScript escape()
253: * at URL "click time".
254: *
255: * @return Parameters (<code>?name3=value3&name4=value4</code>)
256: */
257: public String getPersistentUrlParametersForEncoding() {
258: return _persistentParametersForEncoding;
259: }
260:
261: /**
262: * Set any persistent URL parameter values that require JavaScript encoding
263: * @param parameters Parameter text (name=value pairs)
264: */
265: public void setPersistentUrlParametersForEncoding(String parameters) {
266: _persistentParametersForEncoding = parameters;
267: }
268:
269: /**
270: * Fetch the link text associated with the persistent reference
271: * @return Anchor text
272: */
273: public String getPersistentText() {
274: return _persistentText;
275: }
276:
277: /**
278: * Set persistent URL text
279: * @param text Anchor text
280: */
281: public void setPersistentText(String text) {
282: _persistentText = normalizePersistentText(text);
283: }
284:
285: /*
286: * Helpers
287: */
288:
289: /**
290: * Normalize persistent text:
291: * <ul>
292: * <li> Remove trailing dots (.)
293: * </ul>
294: * @param text Persistent text
295: * @return Normalized text
296: */
297: private String normalizePersistentText(String text) {
298: return StringUtils.trimEnd(text, '.');
299: }
300:
301: /**
302: * Normalize description text:
303: * <ul>
304: * <li> Remove leading dots (.)
305: * </ul>
306: * @param text Description text
307: * @return Normalized description
308: */
309: private String normalizeDescription(String text) {
310: String result = StringUtils.trimFront(text, '.');
311:
312: result = StringUtils.trimFront(result, ',');
313: result = StringUtils.trimFront(result, ';');
314:
315: return result;
316: }
317:
318: /**
319: * Container class for Part ID and Value
320: */
321: public static class PartPair {
322: private org.osid.shared.Id __id;
323: private Serializable __value;
324:
325: /**
326: * Simple constructor (unused)
327: */
328: private PartPair() {
329: }
330:
331: /**
332: * Constructor (save ID and Value)
333: */
334: private PartPair(org.osid.shared.Id id, Serializable value) {
335: __id = id;
336: __value = value;
337: }
338:
339: /**
340: * Return ID
341: */
342: public org.osid.shared.Id getId() {
343: return __id;
344: }
345:
346: /**
347: * Return Value
348: */
349: public Serializable getValue() {
350: return __value;
351: }
352: }
353: }
|