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 |
|
|
37 |
|
|
38 |
0 |
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 |
0 |
fields.add(ID); |
46 |
0 |
fields.add(PORTLET_APPLICATION); |
47 |
0 |
} |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
public ParsedObject parseObject(Object o) |
53 |
|
{ |
54 |
0 |
BaseParsedObject result = null; |
55 |
0 |
if(o instanceof PortletDefinitionComposite) |
56 |
|
{ |
57 |
0 |
result = new BaseParsedObject(); |
58 |
0 |
PortletDefinitionComposite pd = (PortletDefinitionComposite)o; |
59 |
|
|
60 |
|
|
61 |
0 |
String displayNameText = pd.getDisplayNameText(JetspeedLocale.getDefaultLocale()); |
62 |
0 |
result.setTitle(displayNameText); |
63 |
|
|
64 |
0 |
String description = pd.getDescriptionText(JetspeedLocale.getDefaultLocale()); |
65 |
0 |
result.setDescription(description); |
66 |
|
|
67 |
0 |
result.setClassName(pd.getClass().getName()); |
68 |
0 |
result.setKey(KEY_PREFIX + pd.getUniqueName()); |
69 |
0 |
result.setType(ParsedObject.OBJECT_TYPE_PORTLET); |
70 |
|
|
71 |
|
|
72 |
0 |
MultiHashMap fieldMap = new MultiHashMap(); |
73 |
0 |
fieldMap.put(ID, pd.getName()); |
74 |
|
|
75 |
0 |
PortletApplication pa = (PortletApplication)pd.getPortletApplicationDefinition(); |
76 |
0 |
fieldMap.put(PORTLET_APPLICATION, pa.getName()); |
77 |
|
|
78 |
0 |
Collection mdFields = pd.getMetadata().getFields(); |
79 |
0 |
for (Iterator fieldIter = mdFields.iterator(); fieldIter.hasNext();) |
80 |
|
{ |
81 |
0 |
LocalizedField field = (LocalizedField) fieldIter.next(); |
82 |
0 |
fieldMap.put(field.getName(), field.getValue()); |
83 |
0 |
} |
84 |
|
|
85 |
|
|
86 |
0 |
Iterator descIter = pd.getDescriptionSet().iterator(); |
87 |
0 |
while (descIter.hasNext()) |
88 |
|
{ |
89 |
0 |
Description desc = (Description) descIter.next(); |
90 |
0 |
fieldMap.put(ParsedObject.FIELDNAME_DESCRIPTION, desc.getDescription()); |
91 |
0 |
} |
92 |
|
|
93 |
|
|
94 |
0 |
Iterator displayNameIter = pd.getDisplayNameSet().iterator(); |
95 |
0 |
while (displayNameIter.hasNext()) |
96 |
|
{ |
97 |
0 |
DisplayName displayName = (DisplayName) displayNameIter.next(); |
98 |
0 |
fieldMap.put(ParsedObject.FIELDNAME_TITLE, displayName.getDisplayName()); |
99 |
0 |
} |
100 |
|
|
101 |
0 |
HashSet keywordSet = new HashSet(); |
102 |
|
|
103 |
0 |
Iterator langIter = pd.getLanguageSet().iterator(); |
104 |
0 |
while (langIter.hasNext()) |
105 |
|
{ |
106 |
0 |
Language lang = (Language) langIter.next(); |
107 |
0 |
fieldMap.put(ParsedObject.FIELDNAME_TITLE, lang.getTitle()); |
108 |
0 |
fieldMap.put(ParsedObject.FIELDNAME_TITLE, lang.getShortTitle()); |
109 |
|
|
110 |
0 |
Iterator keywordIter = lang.getKeywords(); |
111 |
0 |
if (keywordIter != null) |
112 |
|
{ |
113 |
0 |
while (keywordIter.hasNext()) |
114 |
|
{ |
115 |
0 |
String keyword = (String) keywordIter.next(); |
116 |
0 |
keywordSet.add(keyword); |
117 |
0 |
} |
118 |
|
} |
119 |
0 |
} |
120 |
|
|
121 |
0 |
String[] temp = new String[keywordSet.size()]; |
122 |
0 |
result.setKeywords((String[])keywordSet.toArray(temp)); |
123 |
0 |
result.setFields(fieldMap); |
124 |
|
} |
125 |
0 |
return result; |
126 |
|
} |
127 |
|
} |