KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > portalImpl > om > portlet > impl > ContentTypeSetImpl


1 /*
2  * Copyright 2003,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17
18  */

19
20 package org.apache.pluto.portalImpl.om.portlet.impl;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Iterator JavaDoc;
25
26 import org.apache.pluto.om.portlet.ContentType;
27 import org.apache.pluto.om.portlet.ContentTypeSet;
28 import org.apache.pluto.portalImpl.om.common.AbstractSupportSet;
29 import org.apache.pluto.util.StringUtils;
30
31 public class ContentTypeSetImpl extends AbstractSupportSet
32 implements ContentTypeSet, java.io.Serializable JavaDoc {
33
34
35     // ContentTypeSet implementation.
36

37     // special content type that represents the union of all supported markups
38
private ContentType anyContentType;
39     
40     public ContentType get(String JavaDoc contentType)
41     {
42         Iterator JavaDoc iterator = this.iterator();
43         while (iterator.hasNext()) {
44             ContentType _contentType = (ContentType)iterator.next();
45             if (_contentType.getContentType().equals(contentType)) {
46                 return _contentType;
47             }
48         }
49         return null;
50     }
51
52     // support implemenation
53
public void postLoad(Object JavaDoc parameter) throws Exception JavaDoc
54     {
55         super.postLoad(parameter);
56         
57         Collection JavaDoc allPortletModes = new ArrayList JavaDoc();
58
59         Iterator JavaDoc contentTypes = this.iterator();
60         while (contentTypes.hasNext()){
61             ContentType aContentType = (ContentType)contentTypes.next();
62             Iterator JavaDoc portletModes = aContentType.getPortletModes();
63             
64             while(portletModes.hasNext()) {
65                 Object JavaDoc portletMode = portletModes.next();
66                 if(!allPortletModes.contains(portletMode)) {
67                     allPortletModes.add(portletMode);
68                 }
69             }
70         }
71         
72         ContentTypeImpl _anyContentType = new ContentTypeImpl();
73         _anyContentType.setPortletModes(allPortletModes);
74         anyContentType = _anyContentType;
75     }
76
77
78     // additional methods.
79

80     public String JavaDoc toString()
81     {
82         return toString(0);
83     }
84
85     public String JavaDoc toString(int indent)
86     {
87         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(50);
88         StringUtils.newLine(buffer,indent);
89         buffer.append(getClass().toString());
90         buffer.append(": ");
91         Iterator JavaDoc iterator = this.iterator();
92         while (iterator.hasNext()) {
93             buffer.append(((ContentTypeImpl)iterator.next()).toString(indent+2));
94         }
95         return buffer.toString();
96     }
97
98     public boolean supportsPortletMode(javax.portlet.PortletMode portletMode) {
99         return anyContentType.supportsPortletMode(portletMode);
100     }
101 }
102
Popular Tags