1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.jetspeed.services.search.handlers;
17
18
19 import java.util.HashMap;
20 import java.util.Iterator;
21
22
23 import org.apache.jetspeed.om.registry.PortletEntry;
24 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
25 import org.apache.jetspeed.services.logging.JetspeedLogger;
26 import org.apache.jetspeed.services.search.ParsedObject;
27 import org.apache.jetspeed.om.registry.Category;
28
29 /***
30 * This object handler deals with portlet registry entries
31 *
32 * @author <a href="mailto:caius1440@hotmail.com">Jeremy Ford</a>
33 * @version $Id: PortletEntryToDocHandler.java,v 1.5 2004/02/23 03:47:46 jford Exp $
34 */
35 public class PortletEntryToDocHandler extends RegistryEntryToDocHandler
36 {
37 private static final String PARENT = "parent";
38 private static final String TYPE = "type";
39
40 {
41 fields.add(PARENT);
42 fields.add(TYPE);
43 }
44
45 /***
46 * Static initialization of the logger for this class
47 */
48 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(PortletEntryToDocHandler.class.getName());
49
50 /***
51 * Parses portlet entry object
52 *
53 * @param o
54 * @return
55 */
56 public ParsedObject parseObject(Object o)
57 {
58 ParsedObject result = super.parseObject(o);
59
60 if ((o instanceof PortletEntry) == false)
61 {
62 logger.error("PortletEntryToDocHandler: invalid object type: " + o);
63 return null;
64 }
65
66 PortletEntry portletEntry = (PortletEntry) o;
67
68 HashMap fields = new HashMap();
69 fields.put(PARENT, portletEntry.getParent());
70 fields.put(TYPE, portletEntry.getType());
71
72 result.setFields(fields);
73
74 StringBuffer content = new StringBuffer();
75 String title = portletEntry.getTitle();
76 content.append(title == null ? portletEntry.getName() : title);
77 content.append(" ");
78 content.append(portletEntry.getDescription());
79 content.append(" ");
80 Iterator it = portletEntry.listCategories();
81 while (it.hasNext())
82 {
83 Category cat = (Category) it.next();
84 content.append(cat.getName());
85 content.append(" ");
86 }
87
88 result.setContent(content.toString());
89
90 result.setType(ParsedObject.OBJECT_TYPE_PORTLET);
91
92
93
94
95 return result;
96 }
97 }