KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > pluto > om > common > ContentTypeSetImpl


1 /*
2  * Copyright 2004,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 package org.apache.cocoon.portal.pluto.om.common;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.Collection JavaDoc;
20 import java.util.Iterator JavaDoc;
21
22 import org.apache.pluto.om.portlet.ContentType;
23 import org.apache.pluto.om.portlet.ContentTypeSet;
24 import org.apache.pluto.util.StringUtils;
25
26 /**
27  *
28  *
29  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
30  *
31  * @version CVS $Id: ContentTypeSetImpl.java 123407 2004-12-27 13:51:59Z cziegeler $
32  */

33 public class ContentTypeSetImpl extends AbstractSupportSet
34 implements ContentTypeSet, java.io.Serializable JavaDoc {
35
36     // special content type that represents the union of all supported markups
37
private ContentType anyContentType;
38     
39     /* (non-Javadoc)
40      * @see org.apache.pluto.om.portlet.ContentTypeSet#get(java.lang.String)
41      */

42     public ContentType get(String JavaDoc contentType) {
43         Iterator JavaDoc iterator = this.iterator();
44         while (iterator.hasNext()) {
45             ContentType _contentType = (ContentType)iterator.next();
46             if (_contentType.getContentType().equals(contentType)) {
47                 return _contentType;
48             }
49         }
50         return null;
51     }
52
53     /* (non-Javadoc)
54      * @see org.apache.cocoon.portal.pluto.om.common.Support#postLoad(java.lang.Object)
55      */

56     public void postLoad(Object JavaDoc parameter) throws Exception JavaDoc {
57         super.postLoad(parameter);
58         
59         Collection JavaDoc allPortletModes = new ArrayList JavaDoc();
60
61         Iterator JavaDoc contentTypes = this.iterator();
62         while (contentTypes.hasNext()){
63             ContentType aContentType = (ContentType)contentTypes.next();
64             Iterator JavaDoc portletModes = aContentType.getPortletModes();
65             
66             while(portletModes.hasNext()) {
67                 Object JavaDoc portletMode = portletModes.next();
68                 if(!allPortletModes.contains(portletMode)) {
69                     allPortletModes.add(portletMode);
70                 }
71             }
72         }
73         
74         ContentTypeImpl _anyContentType = new ContentTypeImpl();
75         _anyContentType.setPortletModes(allPortletModes);
76         anyContentType = _anyContentType;
77     }
78
79
80     /* (non-Javadoc)
81      * @see java.lang.Object#toString()
82      */

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