1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.jetspeed.om.portlet.impl;
19
20 import java.io.Serializable;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.HashMap;
25 import java.util.Iterator;
26 import java.util.List;
27 import java.util.Map;
28
29 import javax.portlet.PortletMode;
30 import javax.portlet.WindowState;
31
32 import org.apache.jetspeed.JetspeedActions;
33 import org.apache.jetspeed.om.common.GenericMetadata;
34 import org.apache.jetspeed.om.common.JetspeedServiceReference;
35 import org.apache.jetspeed.om.common.Support;
36 import org.apache.jetspeed.om.common.UserAttribute;
37 import org.apache.jetspeed.om.common.UserAttributeRef;
38 import org.apache.jetspeed.om.common.portlet.CustomPortletMode;
39 import org.apache.jetspeed.om.common.portlet.CustomWindowState;
40 import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
41 import org.apache.jetspeed.om.common.portlet.PortletDefinitionComposite;
42 import org.apache.jetspeed.om.impl.UserAttributeImpl;
43 import org.apache.jetspeed.util.JetspeedLongObjectID;
44 import org.apache.pluto.om.common.ObjectID;
45 import org.apache.pluto.om.portlet.PortletDefinition;
46 import org.apache.pluto.om.portlet.PortletDefinitionList;
47 import org.apache.pluto.om.servlet.WebApplicationDefinition;
48
49 /***
50 *
51 * @author <a href="mailto:paulsp@apache.org">Paul Spencer</a>
52 * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
53 * @version $Id: PortletApplicationDefinitionImpl.java 553014 2007-07-03 23:10:53Z ate $
54 * @since 1.0
55 */
56 public class PortletApplicationDefinitionImpl implements MutablePortletApplication, Serializable, Support
57 {
58 /***
59 * Unique id of the application. This serves as the primary key in database
60 * and in any caching of this object.
61 */
62 private Long id;
63
64 private JetspeedLongObjectID oid;
65
66 /*** Holds value of property name. */
67 private String name;
68
69 /*** Holds value of property version. */
70 private String version;
71
72 /*** Holds the optional application identifier from the portlet.xml */
73 private String applicationIdentifier;
74
75 /*** WebApplication property */
76 private transient WebApplicationDefinition webApplication;
77 /*** PK of this Portlet Application's Web Application */
78 protected long webApplicationId;
79
80 /*** Metadata property */
81 private Collection metadataFields = null;
82
83 /*** Metadata property */
84 private Collection services = new ArrayList();
85
86 /*** Description */
87 private String description;
88
89 private Collection portlets;
90
91 /*** User attribute refs collection. */
92 private Collection userAttributeRefs;
93
94 /*** User attributes collection. */
95 private Collection userAttributes;
96
97 private PortletDefinitionListImpl listWrapper = new PortletDefinitionListImpl();
98
99 private int applicationType = MutablePortletApplication.WEBAPP;
100
101 private String checksum = "0";
102 private long checksumLong = -1;
103
104 private List customPortletModes;
105 private List customWindowStates;
106
107 private String jetspeedSecurityConstraint = null;
108
109 private transient Map supportedCustomModes;
110 private transient Map supportedCustomStates;
111 private transient Map mappedCustomModes;
112 private transient Map mappedCustomStates;
113 private transient Collection supportedPortletModes;
114 private transient Collection supportedWindowStates;
115
116 /*** Creates a new instance of BaseApplication */
117 public PortletApplicationDefinitionImpl()
118 {
119 portlets = new ArrayList();
120 userAttributes = new ArrayList();
121 userAttributeRefs = new ArrayList();
122 customPortletModes = new ArrayList();
123 customWindowStates = new ArrayList();
124 }
125
126 /***
127 * @see org.apache.pluto.om.portlet.PortletApplicationDefinition#getId()
128 */
129 public ObjectID getId()
130 {
131 if ( oid == null && id != null )
132 {
133 oid = new JetspeedLongObjectID(id);
134 }
135 return oid;
136 }
137
138 /***
139 * @see org.apache.jetspeed.om.common.Application#getName()
140 */
141 public String getName()
142 {
143 return this.name;
144 }
145
146 /***
147 * @see org.apache.jetspeed.om.common.Application#setName(String)
148 */
149 public void setName(String name)
150 {
151 this.name = name;
152 }
153
154 /***
155 * @see org.apache.jetspeed.om.common.Application#getVersion()
156 */
157 public String getVersion()
158 {
159 return this.version;
160 }
161
162 /***
163 * @see org.apache.jetspeed.om.common.Application#setVersion(String)
164 */
165 public void setVersion(String version)
166 {
167 this.version = version;
168 }
169
170 /***
171 * @return
172 */
173 public WebApplicationDefinition getWebApplicationDefinition()
174 {
175 return webApplication;
176 }
177
178 /***
179 * @see org.apache.pluto.om.portlet.PortletApplicationDefinition#getPortletDefinitionList()
180 */
181 public PortletDefinitionList getPortletDefinitionList()
182 {
183 return new PortletDefinitionListImpl(portlets);
184 }
185
186 /***
187 * @return
188 */
189 public String getDescription()
190 {
191 return description;
192 }
193
194 /***
195 * @param string
196 */
197 public void setDescription(String string)
198 {
199 description = string;
200 }
201
202 /***
203 * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#setWebApplicationDefinition(org.apache.pluto.om.servlet.WebApplicationDefinition)
204 */
205 public void setWebApplicationDefinition(WebApplicationDefinition wad)
206 {
207 this.webApplication = wad;
208
209 }
210
211 /***
212 * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#addPortletDefinition(org.apache.pluto.om.portlet.PortletDefinition)
213 */
214 public void addPortletDefinition(PortletDefinition pd)
215 {
216 ((PortletDefinitionComposite) pd).setPortletApplicationDefinition(this);
217 portlets.add(pd);
218 }
219
220 /***
221 * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#getPortletDefinitions()
222 */
223 public Collection getPortletDefinitions()
224 {
225 return portlets;
226 }
227
228 /***
229 * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#getPortletDefinitionByName(java.lang.String)
230 */
231 public PortletDefinition getPortletDefinitionByName(String name)
232 {
233 listWrapper.setInnerCollection(portlets);
234 return listWrapper.get(name);
235 }
236
237 /***
238 * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#setPortletDefinitionList(org.apache.pluto.om.portlet.PortletDefinitionList)
239 */
240 public void setPortletDefinitionList(PortletDefinitionList portlets)
241 {
242 this.portlets = ((PortletDefinitionListImpl) portlets).getInnerCollection();
243 }
244
245 /***
246 * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#setUserAttributeRefs(java.util.Collection)
247 */
248 public void setUserAttributeRefs(Collection userAttributeRefs)
249 {
250 this.userAttributeRefs = userAttributeRefs;
251 }
252
253 /***
254 * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#getUserAttributeRefs()
255 */
256 public Collection getUserAttributeRefs()
257 {
258 return this.userAttributeRefs;
259 }
260
261 /***
262 * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#addUserAttributeRef(org.apache.jetspeed.om.common.UserAttributeRef)
263 */
264 public void addUserAttributeRef(UserAttributeRef userAttributeRef)
265 {
266 userAttributeRefs.add(userAttributeRef);
267 }
268
269 /***
270 * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#addUserAttribute(org.apache.jetspeed.om.common.UserAttribute)
271 */
272 public void addUserAttribute(UserAttribute userAttribute)
273 {
274 userAttributes.add(userAttribute);
275 }
276
277 /***
278 * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#addUserAttribute(java.lang.String, java.lang.String)
279 */
280 public void addUserAttribute(String userName, String description)
281 {
282 UserAttributeImpl userAttribute = new UserAttributeImpl();
283 userAttribute.setName(userName);
284 userAttribute.setDescription(description);
285 userAttributes.add(userAttribute);
286 }
287
288 /***
289 * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#setUserAttributes(java.util.Collection)
290 */
291 public void setUserAttributes(Collection userAttributes)
292 {
293 this.userAttributes = userAttributes;
294 }
295
296 /***
297 * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#getUserAttributes()
298 */
299 public Collection getUserAttributes()
300 {
301 return this.userAttributes;
302 }
303
304 /***
305 * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#setApplicationIdentifier(java.lang.String)
306 */
307 public void setApplicationIdentifier(String applicationIdentifier)
308 {
309 this.applicationIdentifier = applicationIdentifier;
310 }
311
312 /***
313 * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#getApplicationIdentifier()
314 */
315 public String getApplicationIdentifier()
316 {
317 return this.applicationIdentifier;
318 }
319
320 /***
321 * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#setApplicationType(int)
322 */
323 public void setApplicationType(int type)
324 {
325 this.applicationType = type;
326 }
327
328 /***
329 * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#getApplicationType()
330 */
331 public int getApplicationType()
332 {
333 return applicationType;
334 }
335
336 /***
337 * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#getMetadata()
338 */
339 public GenericMetadata getMetadata()
340 {
341 if(metadataFields == null)
342 {
343 metadataFields = new ArrayList();
344 }
345
346 GenericMetadata metadata = new PortletApplicationMetadataImpl();
347 metadata.setFields(metadataFields);
348
349 return metadata;
350 }
351
352 /***
353 * @see org.apache.jetspeed.om.common.portlet.MutablePortletApplication#setMetadata(org.apache.jetspeed.om.common.GenericMetadata)
354 */
355 public void setMetadata(GenericMetadata metadata)
356 {
357 this.metadataFields = metadata.getFields();
358 }
359
360 /***
361 * @return
362 */
363 protected Collection getMetadataFields()
364 {
365 return metadataFields;
366 }
367
368 /***
369 * @param collection
370 */
371 protected void setMetadataFields(Collection metadataFields)
372 {
373 this.metadataFields = metadataFields;
374 }
375
376
377
378
379 public Collection getJetspeedServices()
380 {
381 return services;
382 }
383
384
385
386
387 public void addJetspeedService(JetspeedServiceReference service)
388 {
389 services.add(service);
390 }
391
392 public long getChecksum()
393 {
394 if(checksumLong == -1)
395 {
396 checksumLong = Long.parseLong(checksum);
397 }
398 return checksumLong;
399 }
400
401 public void setChecksum(long checksum)
402 {
403 this.checksumLong = checksum;
404 this.checksum = Long.toString(checksum);
405 }
406
407
408
409
410 public void postLoad(Object parameter) throws Exception
411 {
412 Iterator portletDefinitions = getPortletDefinitions().iterator();
413 while (portletDefinitions.hasNext())
414 {
415 ((Support) portletDefinitions.next()).postLoad(this);
416 }
417 }
418
419 public Collection getCustomPortletModes()
420 {
421 return customPortletModes;
422 }
423
424 public void addCustomPortletMode(CustomPortletMode customPortletMode)
425 {
426
427 supportedPortletModes = null;
428 supportedCustomModes = null;
429 mappedCustomModes = null;
430
431 if ( !customPortletModes.contains(customPortletMode) )
432 {
433 customPortletModes.add(customPortletMode);
434 }
435 }
436
437 public void setCustomPortletModes(Collection customPortletModes)
438 {
439
440 supportedPortletModes = null;
441 supportedCustomModes = null;
442 mappedCustomModes = null;
443
444 this.customPortletModes.clear();
445
446 if ( customPortletModes != null )
447 {
448 this.customPortletModes.addAll(customPortletModes);
449 }
450 }
451
452 public PortletMode getMappedPortletMode(PortletMode mode)
453 {
454 if ( JetspeedActions.getStandardPortletModes().contains(mode) )
455 {
456 return mode;
457 }
458 else if ( getSupportedPortletModes().contains(mode) )
459 {
460 return (PortletMode)mappedCustomModes.get(mode);
461 }
462 return null;
463 }
464
465 public PortletMode getCustomPortletMode(PortletMode mode)
466 {
467 if (JetspeedActions.getStandardPortletModes().contains(mode))
468 {
469 return mode;
470 }
471 else if (JetspeedActions.getExtendedPortletModes().contains(mode))
472 {
473
474 getSupportedPortletModes();
475 return (PortletMode)supportedCustomModes.get(mode);
476 }
477 return null;
478 }
479
480 public Collection getSupportedPortletModes()
481 {
482 if ( supportedPortletModes == null )
483 {
484 ArrayList list = new ArrayList(JetspeedActions.getStandardPortletModes());
485 supportedCustomModes = new HashMap();
486 mappedCustomModes = new HashMap();
487
488 if ( customPortletModes.size() > 0 )
489 {
490 Iterator iter = customPortletModes.iterator();
491 while ( iter.hasNext() )
492 {
493 CustomPortletMode customMode = (CustomPortletMode)iter.next();
494 if ( !list.contains(customMode.getCustomMode()) && JetspeedActions.getExtendedPortletModes().contains(customMode.getMappedMode()) )
495 {
496 list.add(customMode.getCustomMode());
497 supportedCustomModes.put(customMode.getMappedMode(), customMode.getCustomMode());
498 mappedCustomModes.put(customMode.getCustomMode(), customMode.getMappedMode());
499 }
500 }
501 }
502 supportedPortletModes = Collections.unmodifiableCollection(list);
503 }
504 return supportedPortletModes;
505 }
506
507 public Collection getCustomWindowStates()
508 {
509 return customWindowStates;
510 }
511
512 public void addCustomWindowState(CustomWindowState customWindowState)
513 {
514
515 supportedWindowStates = null;
516 supportedCustomStates = null;
517 mappedCustomStates = null;
518
519 if ( !customWindowStates.contains(customWindowState) )
520 {
521 customWindowStates.add(customWindowState);
522 }
523 }
524
525 public void setCustomWindowStates(Collection customWindowStates)
526 {
527
528 supportedWindowStates = null;
529 supportedCustomStates = null;
530 mappedCustomStates = null;
531
532 this.customWindowStates.clear();
533
534 if ( customWindowStates != null )
535 {
536 this.customWindowStates.addAll(customWindowStates);
537 }
538 }
539
540 public WindowState getMappedWindowState(WindowState state)
541 {
542 if (JetspeedActions.getStandardWindowStates().contains(state) )
543 {
544 return state;
545 }
546 else if ( getSupportedWindowStates().contains(state) )
547 {
548 return (WindowState)mappedCustomStates.get(state);
549 }
550 return null;
551 }
552
553 public WindowState getCustomWindowState(WindowState state)
554 {
555 if (JetspeedActions.getStandardWindowStates().contains(state))
556 {
557 return state;
558 }
559 else if (JetspeedActions.getExtendedWindowStates().contains(state))
560 {
561
562 getSupportedWindowStates();
563 return (WindowState)supportedCustomStates.get(state);
564 }
565 return null;
566 }
567
568 public Collection getSupportedWindowStates()
569 {
570 if ( supportedWindowStates == null )
571 {
572 ArrayList list = new ArrayList(JetspeedActions.getStandardWindowStates());
573 supportedCustomStates = new HashMap();
574 mappedCustomStates = new HashMap();
575
576 if ( customWindowStates.size() > 0 )
577 {
578 Iterator iter = customWindowStates.iterator();
579 while ( iter.hasNext() )
580 {
581 CustomWindowState customState = (CustomWindowState)iter.next();
582 if ( !list.contains(customState.getCustomState()) && JetspeedActions.getExtendedWindowStates().contains(customState.getMappedState()) )
583 {
584 list.add(customState.getCustomState());
585 supportedCustomStates.put(customState.getMappedState(),customState.getCustomState());
586 mappedCustomStates.put(customState.getCustomState(),customState.getMappedState());
587 }
588 }
589 }
590 supportedWindowStates = Collections.unmodifiableCollection(list);
591 }
592 return supportedWindowStates;
593 }
594
595
596
597
598 public String getJetspeedSecurityConstraint()
599 {
600 return this.jetspeedSecurityConstraint;
601 }
602
603
604
605
606 public void setJetspeedSecurityConstraint(String constraint)
607 {
608 this.jetspeedSecurityConstraint = constraint;
609 }
610
611 public boolean isLayoutApplication()
612 {
613 if (this.getMetadata() != null)
614 {
615 Collection c = this.getMetadata().getFields("layout-app");
616 if (c != null)
617 {
618 if (!c.isEmpty())
619 {
620 return true;
621 }
622 }
623 }
624 return false;
625 }
626 }