1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
package org.apache.jetspeed.util.descriptor; |
18 |
|
|
19 |
|
import java.io.Reader; |
20 |
|
import java.util.Collection; |
21 |
|
import java.util.Iterator; |
22 |
|
|
23 |
|
import org.apache.commons.digester.Digester; |
24 |
|
import org.apache.commons.logging.Log; |
25 |
|
import org.apache.commons.logging.LogFactory; |
26 |
|
import org.apache.jetspeed.om.common.Support; |
27 |
|
import org.apache.jetspeed.om.common.portlet.MutablePortletApplication; |
28 |
|
import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite; |
29 |
|
import org.apache.jetspeed.om.impl.LanguageImpl; |
30 |
|
import org.apache.jetspeed.om.impl.ParameterDescriptionImpl; |
31 |
|
import org.apache.jetspeed.om.impl.PortletDescriptionImpl; |
32 |
|
import org.apache.jetspeed.om.impl.PortletDisplayNameImpl; |
33 |
|
import org.apache.jetspeed.om.impl.PortletInitParameterImpl; |
34 |
|
import org.apache.jetspeed.om.impl.SecurityRoleRefDescriptionImpl; |
35 |
|
import org.apache.jetspeed.om.impl.SecurityRoleRefImpl; |
36 |
|
import org.apache.jetspeed.om.impl.UserAttributeImpl; |
37 |
|
import org.apache.jetspeed.om.portlet.impl.ContentTypeImpl; |
38 |
|
import org.apache.jetspeed.om.portlet.impl.CustomPortletModeImpl; |
39 |
|
import org.apache.jetspeed.om.portlet.impl.CustomWindowStateImpl; |
40 |
|
import org.apache.jetspeed.om.portlet.impl.PortletApplicationDefinitionImpl; |
41 |
|
import org.apache.jetspeed.tools.pamanager.PortletApplicationException; |
42 |
|
import org.apache.pluto.om.common.SecurityRoleRef; |
43 |
|
import org.apache.pluto.om.common.SecurityRoleRefSet; |
44 |
|
import org.apache.pluto.om.common.SecurityRoleSet; |
45 |
|
import org.apache.pluto.om.portlet.PortletDefinition; |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
public class PortletApplicationDescriptor |
59 |
|
{ |
60 |
0 |
protected final static Log log = LogFactory.getLog(PortletApplicationDescriptor.class); |
61 |
|
protected Reader portletXmlReader; |
62 |
|
private String appName; |
63 |
|
|
64 |
|
|
65 |
|
public PortletApplicationDescriptor(Reader portletXmlReader, String appName) |
66 |
0 |
{ |
67 |
0 |
this.portletXmlReader = portletXmlReader; |
68 |
0 |
this.appName = appName; |
69 |
0 |
} |
70 |
|
|
71 |
|
public MutablePortletApplication createPortletApplication() |
72 |
|
throws PortletApplicationException |
73 |
|
{ |
74 |
0 |
return createPortletApplication(this.getClass().getClassLoader()); |
75 |
|
} |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
public MutablePortletApplication createPortletApplication(ClassLoader classLoader) |
85 |
|
throws PortletApplicationException |
86 |
|
{ |
87 |
|
try |
88 |
|
{ |
89 |
|
|
90 |
0 |
Digester digester = new Digester(); |
91 |
0 |
digester.setValidating(false); |
92 |
0 |
digester.setClassLoader(this.getClass().getClassLoader()); |
93 |
|
|
94 |
|
|
95 |
|
|
96 |
0 |
digester.addRule("portlet-app", new PortletApplicationRule(appName)); |
97 |
0 |
digester.addSetProperties("portlet-app", "id", "applicationIdentifier"); |
98 |
|
|
99 |
|
|
100 |
0 |
digester.addRule("portlet-app/portlet", new PortletRule()); |
101 |
|
|
102 |
0 |
digester.addSetProperties("portlet-app/portlet", "id", "portletIdentifier"); |
103 |
0 |
digester.addBeanPropertySetter("portlet-app/portlet/portlet-name", "name"); |
104 |
0 |
digester.addBeanPropertySetter("portlet-app/portlet/portlet-class", "className"); |
105 |
0 |
digester.addBeanPropertySetter("portlet-app/portlet/expiration-cache", "expirationCache"); |
106 |
0 |
digester.addBeanPropertySetter("portlet-app/portlet/resource-bundle", "resourceBundle"); |
107 |
0 |
digester.addCallMethod("portlet-app/portlet/supported-locale", "addSupportedLocale", 0); |
108 |
|
|
109 |
0 |
digester.addObjectCreate("portlet-app/portlet/display-name", PortletDisplayNameImpl.class); |
110 |
0 |
digester.addSetProperties("portlet-app/portlet/display-name", "xml:lang", "language"); |
111 |
0 |
digester.addBeanPropertySetter("portlet-app/portlet/display-name", "displayName"); |
112 |
0 |
digester.addSetNext("portlet-app/portlet/display-name", "addDisplayName"); |
113 |
|
|
114 |
0 |
digester.addObjectCreate("portlet-app/portlet/description", PortletDescriptionImpl.class); |
115 |
0 |
digester.addSetProperties("portlet-app/portlet/description", "xml:lang", "language"); |
116 |
0 |
digester.addBeanPropertySetter("portlet-app/portlet/description", "description"); |
117 |
0 |
digester.addSetNext("portlet-app/portlet/description", "addDescription"); |
118 |
|
|
119 |
0 |
digester.addObjectCreate("portlet-app/portlet/init-param", PortletInitParameterImpl.class); |
120 |
0 |
digester.addBeanPropertySetter("portlet-app/portlet/init-param/name", "name"); |
121 |
0 |
digester.addBeanPropertySetter("portlet-app/portlet/init-param/value", "value"); |
122 |
0 |
digester.addSetNext("portlet-app/portlet/init-param", "addInitParameter"); |
123 |
|
|
124 |
0 |
digester.addObjectCreate("portlet-app/portlet/init-param/description", ParameterDescriptionImpl.class); |
125 |
0 |
digester.addSetProperties("portlet-app/portlet/init-param/description", "xml:lang", "language"); |
126 |
0 |
digester.addBeanPropertySetter("portlet-app/portlet/init-param/description", "description"); |
127 |
0 |
digester.addSetNext("portlet-app/portlet/init-param/description", "addDescription"); |
128 |
|
|
129 |
0 |
digester.addObjectCreate("portlet-app/portlet/supports", ContentTypeImpl.class); |
130 |
0 |
digester.addBeanPropertySetter("portlet-app/portlet/supports/mime-type", "contentType"); |
131 |
0 |
digester.addCallMethod("portlet-app/portlet/supports/portlet-mode", "addPortletMode", 0); |
132 |
0 |
digester.addSetNext("portlet-app/portlet/supports", "addContentType"); |
133 |
|
|
134 |
0 |
digester.addObjectCreate("portlet-app/portlet/portlet-info", LanguageImpl.class); |
135 |
0 |
digester.addBeanPropertySetter("portlet-app/portlet/portlet-info/title", "title"); |
136 |
0 |
digester.addBeanPropertySetter("portlet-app/portlet/portlet-info/short-title", "shortTitle"); |
137 |
0 |
digester.addCallMethod("portlet-app/portlet/portlet-info/keywords", "setKeywords", 0, new Class[]{String.class}); |
138 |
0 |
digester.addSetNext("portlet-app/portlet/portlet-info", "addLanguage"); |
139 |
|
|
140 |
0 |
digester.addRuleSet(new PortletPreferenceRuleSet()); |
141 |
|
|
142 |
|
|
143 |
0 |
digester.addObjectCreate("portlet-app/user-attribute", UserAttributeImpl.class); |
144 |
0 |
digester.addBeanPropertySetter("portlet-app/user-attribute/description", "description"); |
145 |
0 |
digester.addBeanPropertySetter("portlet-app/user-attribute/name", "name"); |
146 |
0 |
digester.addSetNext("portlet-app/user-attribute", "addUserAttribute"); |
147 |
|
|
148 |
0 |
digester.addObjectCreate("portlet-app/custom-portlet-mode", CustomPortletModeImpl.class); |
149 |
0 |
digester.addBeanPropertySetter("portlet-app/custom-portlet-mode/description", "description"); |
150 |
|
|
151 |
|
|
152 |
|
|
153 |
0 |
digester.addBeanPropertySetter("portlet-app/custom-portlet-mode/portlet-mode", "customName"); |
154 |
0 |
digester.addBeanPropertySetter("portlet-app/custom-portlet-mode/name", "customName"); |
155 |
0 |
digester.addSetNext("portlet-app/custom-portlet-mode", "addCustomPortletMode"); |
156 |
|
|
157 |
0 |
digester.addObjectCreate("portlet-app/custom-window-state", CustomWindowStateImpl.class); |
158 |
0 |
digester.addBeanPropertySetter("portlet-app/custom-window-state/description", "description"); |
159 |
|
|
160 |
|
|
161 |
|
|
162 |
0 |
digester.addBeanPropertySetter("portlet-app/custom-window-state/window-state", "customName"); |
163 |
0 |
digester.addBeanPropertySetter("portlet-app/custom-window-state/name", "customName"); |
164 |
0 |
digester.addSetNext("portlet-app/custom-window-state", "addCustomWindowState"); |
165 |
|
|
166 |
0 |
digester.addObjectCreate("portlet-app/portlet/security-role-ref", SecurityRoleRefImpl.class); |
167 |
0 |
digester.addBeanPropertySetter("portlet-app/portlet/security-role-ref/role-name", "roleName"); |
168 |
0 |
digester.addBeanPropertySetter("portlet-app/portlet/security-role-ref/role-link", "roleLink"); |
169 |
0 |
digester.addSetNext("portlet-app/portlet/security-role-ref", "addSecurityRoleRef"); |
170 |
|
|
171 |
0 |
digester.addObjectCreate("portlet-app/portlet/security-role-ref/description", SecurityRoleRefDescriptionImpl.class); |
172 |
0 |
digester.addSetProperties("portlet-app/portlet/security-role-ref/description", "xml:lang", "language"); |
173 |
0 |
digester.addBeanPropertySetter("portlet-app/portlet/security-role-ref/description", "description"); |
174 |
0 |
digester.addSetNext("portlet-app/portlet/security-role-ref/description", "addDescription"); |
175 |
|
|
176 |
0 |
PortletApplicationDefinitionImpl pd = (PortletApplicationDefinitionImpl) digester.parse(portletXmlReader); |
177 |
|
|
178 |
|
|
179 |
0 |
if(pd.getApplicationIdentclass="keyword">ifier() == null) |
180 |
|
{ |
181 |
0 |
pd.setApplicationIdentifier(appName); |
182 |
|
} |
183 |
|
|
184 |
0 |
Iterator portletDefs = pd.getPortletDefinitions().iterator(); |
185 |
0 |
while(portletDefs.hasNext()) |
186 |
|
{ |
187 |
0 |
Object obj = portletDefs.next(); |
188 |
0 |
PortletDefinitionComposite portletDef = (PortletDefinitionComposite) obj; |
189 |
0 |
if(portletDef.getPortletIdentclass="keyword">ifier() == null) |
190 |
|
{ |
191 |
0 |
portletDef.setPortletIdentifier(portletDef.getName()); |
192 |
|
} |
193 |
|
|
194 |
0 |
((Support)obj).postLoad(classLoader); |
195 |
0 |
} |
196 |
|
|
197 |
0 |
return pd; |
198 |
|
|
199 |
|
} |
200 |
0 |
catch (Throwable t) |
201 |
|
{ |
202 |
0 |
String msg = "Could not unmarshal portlet.xml. " + t.toString(); |
203 |
0 |
throw new PortletApplicationException(msg, t); |
204 |
|
} |
205 |
|
} |
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
public void validate(MutablePortletApplication app) |
226 |
|
throws PortletApplicationException |
227 |
|
{ |
228 |
0 |
SecurityRoleSet roles = app.getWebApplicationDefinition() |
229 |
|
.getSecurityRoles(); |
230 |
0 |
Collection portlets = app.getPortletDefinitions(); |
231 |
0 |
Iterator portletIterator = portlets.iterator(); |
232 |
0 |
while (portletIterator.hasNext()) |
233 |
|
{ |
234 |
0 |
PortletDefinition portlet = (PortletDefinition) portletIterator |
235 |
|
.next(); |
236 |
0 |
SecurityRoleRefSet securityRoleRefs = portlet |
237 |
|
.getInitSecurityRoleRefSet(); |
238 |
0 |
Iterator roleRefsIterator = securityRoleRefs.iterator(); |
239 |
0 |
while (roleRefsIterator.hasNext()) |
240 |
|
{ |
241 |
0 |
SecurityRoleRef roleRef = (SecurityRoleRef) roleRefsIterator |
242 |
|
.next(); |
243 |
0 |
String roleName = roleRef.getRoleLink(); |
244 |
0 |
if (roleName == null || roleName.length() == 0) |
245 |
|
{ |
246 |
0 |
roleName = roleRef.getRoleName(); |
247 |
|
} |
248 |
0 |
if (roles.get(roleName) == null) |
249 |
|
{ |
250 |
0 |
String errorMsg = "Undefined security role " + roleName |
251 |
|
+ " referenced from portlet " + portlet.getName(); |
252 |
0 |
log.error(errorMsg); |
253 |
0 |
throw new PortletApplicationException(errorMsg); |
254 |
|
} |
255 |
0 |
} |
256 |
0 |
} |
257 |
0 |
} |
258 |
|
} |