View Javadoc

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;
23  import java.util.Collection;
24  import java.util.Iterator;
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 {
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 contentType)
41      {
42          Iterator 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 parameter) throws Exception
54      {
55      	super.postLoad(parameter);
56      	
57      	Collection allPortletModes = new ArrayList();
58  
59      	Iterator contentTypes = this.iterator();
60  		while (contentTypes.hasNext()){
61  			ContentType aContentType = (ContentType)contentTypes.next();
62  			Iterator portletModes = aContentType.getPortletModes();
63  			
64  			while(portletModes.hasNext()) {
65  				Object 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 toString()
81      {
82          return toString(0);
83      }
84  
85      public String toString(int indent)
86      {
87          StringBuffer buffer = new StringBuffer(50);
88          StringUtils.newLine(buffer,indent);
89          buffer.append(getClass().toString());
90          buffer.append(": ");
91          Iterator 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 }