1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.pluto.portalImpl.om.portlet.impl;
21
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.Iterator;
25 import java.util.Locale;
26 import java.util.StringTokenizer;
27
28 import org.apache.pluto.om.common.Description;
29 import org.apache.pluto.om.common.DescriptionSet;
30 import org.apache.pluto.om.common.DisplayName;
31 import org.apache.pluto.om.common.DisplayNameSet;
32 import org.apache.pluto.om.common.LanguageSet;
33 import org.apache.pluto.om.common.ObjectID;
34 import org.apache.pluto.om.common.ParameterSet;
35 import org.apache.pluto.om.common.PreferenceSet;
36 import org.apache.pluto.om.common.SecurityRoleRefSet;
37 import org.apache.pluto.om.portlet.ContentTypeSet;
38 import org.apache.pluto.om.portlet.PortletApplicationDefinition;
39 import org.apache.pluto.om.portlet.PortletDefinition;
40 import org.apache.pluto.om.portlet.PortletDefinitionCtrl;
41 import org.apache.pluto.om.servlet.ServletDefinition;
42 import org.apache.pluto.portalImpl.om.common.Support;
43 import org.apache.pluto.portalImpl.om.common.impl.DescriptionSetImpl;
44 import org.apache.pluto.portalImpl.om.common.impl.DisplayNameSetImpl;
45 import org.apache.pluto.portalImpl.om.common.impl.LanguageSetImpl;
46 import org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl;
47 import org.apache.pluto.util.StringUtils;
48
49 public class PortletDefinitionImpl
50 implements PortletDefinition, PortletDefinitionCtrl, java.io.Serializable,
51 org.apache.pluto.portalImpl.om.common.Support {
52
53
54 private PortletApplicationDefinition application;
55 private LanguageSet castorResources;
56
57
58 private ArrayList castorSupportedLocales = new ArrayList();
59 private ClassLoader classLoader;
60 private String className;
61 private ContentTypeSet contentTypes = new ContentTypeSetImpl();
62 private DescriptionSet descriptions = new org.apache.pluto.portalImpl.om.common.impl.DescriptionSetImpl();
63
64 private DisplayNameSet displayNames = new org.apache.pluto.portalImpl.om.common.impl.DisplayNameSetImpl();
65 private String expirationCache;
66 public String id = "";
67 private ParameterSet initParams = new org.apache.pluto.portalImpl.om.common.impl.ParameterSetImpl();
68 private SecurityRoleRefSet initSecurityRoleRefs = new org.apache.pluto.portalImpl.om.common.impl.SecurityRoleRefSetImpl();
69 private String name;
70
71 private ObjectID objectId;
72 private PreferenceSet preferences = new org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl();
73
74
75 private String resourceBundle;
76 private ServletDefinition servlet;
77
78
79 private ArrayList supportedLocales = new ArrayList();
80
81
82
83 public ObjectID getId()
84 {
85 if (objectId==null) {
86 objectId = org.apache.pluto.portalImpl.util.ObjectID.createFromString(getGUID());
87 }
88
89 return objectId;
90 }
91
92 public String getClassName()
93 {
94 return className;
95 }
96
97 public String getName()
98 {
99 return name;
100 }
101
102
103
104
105 public Description getDescription(Locale locale) {
106 return descriptions.get(locale);
107 }
108
109 public LanguageSet getLanguageSet()
110 {
111 ((LanguageSetImpl)castorResources).setClassLoader(this.getPortletClassLoader());
112 return castorResources;
113 }
114
115 public ParameterSet getInitParameterSet()
116 {
117 return initParams;
118 }
119
120 public SecurityRoleRefSet getInitSecurityRoleRefSet()
121 {
122 return initSecurityRoleRefs;
123 }
124
125 public PreferenceSet getPreferenceSet()
126 {
127 ((PreferenceSetImpl)preferences).setClassLoader(this.getPortletClassLoader());
128 return preferences;
129 }
130
131 public ContentTypeSet getContentTypeSet()
132 {
133 return contentTypes;
134 }
135
136 public PortletApplicationDefinition getPortletApplicationDefinition()
137 {
138 return application;
139 }
140
141 public ServletDefinition getServletDefinition()
142 {
143 return servlet;
144 }
145
146 public DisplayName getDisplayName(Locale locale)
147 {
148 return displayNames.get(locale);
149 }
150
151 public String getExpirationCache()
152 {
153 return expirationCache;
154 }
155
156
157
158 public void setId(String id)
159 {
160
161 }
162
163 public void setClassName(String className)
164 {
165 this.className = className;
166 }
167
168 public void setName(String name)
169 {
170 this.name = name;
171 }
172
173
174
175
176 public void setDescriptions(DescriptionSet descriptions) {
177 this.descriptions = descriptions;
178 }
179
180 public void setDisplayNames(DisplayNameSet displayNames)
181 {
182 this.displayNames = displayNames;
183 }
184
185 public void setPortletClassLoader(ClassLoader loader)
186 {
187 this.classLoader = loader;
188 }
189
190 public void store() throws java.io.IOException
191 {
192
193 }
194
195
196
197 public void postBuild(Object parameter) throws Exception
198 {
199 setServletDefinition((ServletDefinition)parameter);
200 ((Support)contentTypes).postBuild(this);
201 if (castorResources!=null) {
202 ((Support)castorResources).postBuild(this);
203 }
204 }
205
206 public void postLoad(Object parameter) throws Exception
207 {
208 ((Support)contentTypes).postLoad(this);
209
210
211 Iterator iterator = castorSupportedLocales.iterator();
212 while (iterator.hasNext()) {
213
214 String locale = (String)iterator.next();
215
216
217 StringTokenizer tokenizer = new StringTokenizer(locale,"_");
218 String[] localeDef = new String[3];
219 for (int i=0; i<3 ;i++) {
220 if (tokenizer.hasMoreTokens()) {
221 localeDef[i] = tokenizer.nextToken();
222 } else {
223 localeDef[i] = "";
224 }
225 }
226 supportedLocales.add(new java.util.Locale(localeDef[0], localeDef[1], localeDef[2]));
227
228 }
229
230 if (castorResources==null) {
231 castorResources = new LanguageSetImpl();
232 }
233 if (resourceBundle!=null) {
234 ((LanguageSetImpl)castorResources).setResources(resourceBundle);
235 }
236 ((Support)castorResources).postLoad(this.supportedLocales);
237 ((Support)descriptions).postLoad(parameter);
238 ((Support)displayNames).postLoad(parameter);
239
240 }
241 public void postStore(Object parameter) throws Exception
242 {
243 ((Support)contentTypes).postStore(this);
244 if (castorResources!=null) {
245 ((Support)castorResources).postStore(this);
246 }
247 }
248 public void preBuild(Object parameter) throws Exception
249 {
250 setPortletApplicationDefinition((PortletApplicationDefinition)parameter);
251 ((Support)contentTypes).preBuild(this);
252 if (castorResources!=null) {
253 ((Support)castorResources).preBuild(this);
254 }
255 }
256 public void preStore(Object parameter) throws Exception
257 {
258 ((Support)contentTypes).preStore(this);
259 if (castorResources!=null) {
260 ((Support)castorResources).preStore(this);
261 }
262 }
263
264
265
266 public Collection getCastorContentTypes()
267 {
268 return(ContentTypeSetImpl)contentTypes;
269 }
270
271 public Collection getCastorDisplayNames()
272 {
273 return(DisplayNameSetImpl)displayNames;
274 }
275
276 public Collection getCastorDescriptions()
277 {
278 return(DescriptionSetImpl)descriptions;
279 }
280
281 public Collection getDescriptions()
282 {
283 return(DescriptionSetImpl)descriptions;
284 }
285
286 public Collection getCastorInitParams()
287 {
288 return(org.apache.pluto.portalImpl.om.common.impl.ParameterSetImpl)initParams;
289 }
290
291 public SecurityRoleRefSet getCastorInitSecurityRoleRefs()
292 {
293 return initSecurityRoleRefs;
294 }
295
296 public PreferenceSet getCastorPreferences()
297 {
298 return preferences;
299 }
300
301 public LanguageSet getCastorResources()
302 {
303 return castorResources;
304 }
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319 public Collection getCastorSupportedLocales()
320 {
321 return castorSupportedLocales;
322 }
323
324
325 private String getGUID()
326 {
327 String portletID = "";
328 if (getName()!=null) portletID += getName();
329
330 portletID = application.getId().toString() + "."+portletID;
331 return portletID;
332 }
333
334 public ClassLoader getPortletClassLoader()
335 {
336 return classLoader;
337 }
338
339 public String getResourceBundle()
340 {
341 return this.resourceBundle;
342 }
343
344 public Collection getSupportedLocales()
345 {
346 return supportedLocales;
347 }
348
349 public void setCastorContentTypes(ContentTypeSet castorContentTypes)
350 {
351 this.contentTypes = castorContentTypes;
352 }
353
354 public void setCastorInitParams(ParameterSet castorInitParams)
355 {
356 this.initParams = castorInitParams;
357 }
358
359 public void setCastorInitSecurityRoleRefs(SecurityRoleRefSet castorInitSecurityRoleRefs)
360 {
361 this.initSecurityRoleRefs = castorInitSecurityRoleRefs;
362 }
363
364 public void setCastorDisplayNames(DisplayNameSet castorDisplayNames)
365 {
366 this.displayNames = castorDisplayNames;
367 }
368
369 public void setCastorDescriptions(DescriptionSet castorDescriptions)
370 {
371 this.descriptions = castorDescriptions;
372 }
373
374 public void setCastorPreferences(PreferenceSet castorPreferences)
375 {
376 this.preferences = castorPreferences;
377 }
378
379 public void setCastorResources(LanguageSet resources)
380 {
381 this.castorResources = resources;
382 }
383
384 public void setCastorSupportedLocales(Collection castorSupportedLocales)
385 {
386 this.castorSupportedLocales = (ArrayList)castorSupportedLocales;
387 }
388
389 public void setExpirationCache(String expirationCache)
390 {
391 this.expirationCache = expirationCache;
392 }
393
394 protected void setPortletApplicationDefinition(PortletApplicationDefinition application)
395 {
396 this.application = application;
397 }
398
399 public void setResourceBundle(String resourceBundle)
400 {
401 this.resourceBundle = resourceBundle;
402 }
403
404 protected void setServletDefinition(ServletDefinition servlet)
405 {
406 this.servlet = servlet;
407 }
408
409
410
411
412 public String toString()
413 {
414 return toString(0);
415 }
416
417 public String toString(int indent)
418 {
419 StringBuffer buffer = new StringBuffer(50);
420 StringUtils.newLine(buffer,indent);
421 buffer.append(getClass().toString()); buffer.append(":");
422 StringUtils.newLine(buffer,indent);
423 buffer.append("{");
424 StringUtils.newLine(buffer,indent);
425 buffer.append("objectID='"); buffer.append(getId()); buffer.append("'");
426 StringUtils.newLine(buffer,indent);
427 buffer.append("guid='"); buffer.append(getGUID()); buffer.append("'");
428 StringUtils.newLine(buffer,indent);
429 buffer.append("id='"); buffer.append(id); buffer.append("'");
430 StringUtils.newLine(buffer,indent);
431 buffer.append("name='"); buffer.append(name); buffer.append("'");
432
433 StringUtils.newLine(buffer,indent);
434 buffer.append(((org.apache.pluto.portalImpl.om.common.impl.LanguageSetImpl)castorResources).toString(indent));
435
436 StringUtils.newLine(buffer,indent);
437 buffer.append(((org.apache.pluto.portalImpl.om.common.impl.ParameterSetImpl)initParams).toString(indent));
438
439 StringUtils.newLine(buffer,indent);
440 buffer.append(((org.apache.pluto.portalImpl.om.common.impl.PreferenceSetImpl)preferences).toString(indent));
441
442 StringUtils.newLine(buffer,indent);
443 buffer.append(((org.apache.pluto.portalImpl.om.common.impl.SecurityRoleRefSetImpl)initSecurityRoleRefs).toString(indent));
444
445 StringUtils.newLine(buffer,indent);
446 buffer.append(((ContentTypeSetImpl)contentTypes).toString(indent));
447
448 StringUtils.newLine(buffer,indent);
449 buffer.append(((DescriptionSetImpl)descriptions).toString(indent));
450
451 StringUtils.newLine(buffer,indent);
452 buffer.append(((DisplayNameSetImpl)displayNames).toString(indent));
453
454
455 if (servlet!=null) {
456 StringUtils.newLine(buffer,indent);
457 buffer.append("servlet:");
458 buffer.append(((org.apache.pluto.portalImpl.om.servlet.impl.ServletDefinitionImpl)servlet).toString(indent+2));
459 }
460 StringUtils.newLine(buffer,indent);
461 buffer.append("}");
462 return buffer.toString();
463 }
464
465
466 }