1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.search.handlers.pam;
18
19 import java.util.Collection;
20 import java.util.HashSet;
21 import java.util.Iterator;
22
23 import org.apache.commons.collections.MultiHashMap;
24 import org.apache.jetspeed.om.common.LocalizedField;
25 import org.apache.jetspeed.om.common.portlet.PortletApplication;
26 import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
27 import org.apache.jetspeed.search.AbstractObjectHandler;
28 import org.apache.jetspeed.search.BaseParsedObject;
29 import org.apache.jetspeed.search.ParsedObject;
30 import org.apache.jetspeed.util.JetspeedLocale;
31 import org.apache.pluto.om.common.Description;
32 import org.apache.pluto.om.common.DisplayName;
33 import org.apache.pluto.om.common.Language;
34
35 /***
36 * @author <a href="mailto: jford@apache.org">Jeremy Ford</a>
37 */
38 public class PortletDefinitionHandler extends AbstractObjectHandler
39 {
40 private static final String KEY_PREFIX = "PortletDefinition::";
41 private static final String ID = "ID";
42 private static final String PORTLET_APPLICATION = "portlet_application";
43
44 {
45 fields.add(ID);
46 fields.add(PORTLET_APPLICATION);
47 }
48
49
50
51
52 public ParsedObject parseObject(Object o)
53 {
54 BaseParsedObject result = null;
55 if(o instanceof PortletDefinitionComposite)
56 {
57 result = new BaseParsedObject();
58 PortletDefinitionComposite pd = (PortletDefinitionComposite)o;
59
60
61 String displayNameText = pd.getDisplayNameText(JetspeedLocale.getDefaultLocale());
62 result.setTitle(displayNameText);
63
64 String description = pd.getDescriptionText(JetspeedLocale.getDefaultLocale());
65 result.setDescription(description);
66
67 result.setClassName(pd.getClass().getName());
68 result.setKey(KEY_PREFIX + pd.getUniqueName());
69 result.setType(ParsedObject.OBJECT_TYPE_PORTLET);
70
71
72 MultiHashMap fieldMap = new MultiHashMap();
73 fieldMap.put(ID, pd.getName());
74
75 PortletApplication pa = (PortletApplication)pd.getPortletApplicationDefinition();
76 fieldMap.put(PORTLET_APPLICATION, pa.getName());
77
78 Collection mdFields = pd.getMetadata().getFields();
79 for (Iterator fieldIter = mdFields.iterator(); fieldIter.hasNext();)
80 {
81 LocalizedField field = (LocalizedField) fieldIter.next();
82 fieldMap.put(field.getName(), field.getValue());
83 }
84
85
86 Iterator descIter = pd.getDescriptionSet().iterator();
87 while (descIter.hasNext())
88 {
89 Description desc = (Description) descIter.next();
90 fieldMap.put(ParsedObject.FIELDNAME_DESCRIPTION, desc.getDescription());
91 }
92
93
94 Iterator displayNameIter = pd.getDisplayNameSet().iterator();
95 while (displayNameIter.hasNext())
96 {
97 DisplayName displayName = (DisplayName) displayNameIter.next();
98 fieldMap.put(ParsedObject.FIELDNAME_TITLE, displayName.getDisplayName());
99 }
100
101 HashSet keywordSet = new HashSet();
102
103 Iterator langIter = pd.getLanguageSet().iterator();
104 while (langIter.hasNext())
105 {
106 Language lang = (Language) langIter.next();
107 fieldMap.put(ParsedObject.FIELDNAME_TITLE, lang.getTitle());
108 fieldMap.put(ParsedObject.FIELDNAME_TITLE, lang.getShortTitle());
109
110 Iterator keywordIter = lang.getKeywords();
111 if (keywordIter != null)
112 {
113 while (keywordIter.hasNext())
114 {
115 String keyword = (String) keywordIter.next();
116 keywordSet.add(keyword);
117 }
118 }
119 }
120
121 String[] temp = new String[keywordSet.size()];
122 result.setKeywords((String[])keywordSet.toArray(temp));
123 result.setFields(fieldMap);
124 }
125 return result;
126 }
127 }