View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.jetspeed.om.portlet.impl;
18  
19  import java.io.Serializable;
20  import java.util.ArrayList;
21  import java.util.Collection;
22  import java.util.Iterator;
23  
24  import javax.portlet.PortletMode;
25  
26  import org.apache.jetspeed.om.common.portlet.ContentTypeSetComposite;
27  import org.apache.pluto.om.portlet.ContentType;
28  
29  /***
30   * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a> 
31   */
32  public class ContentTypeSetImpl implements ContentTypeSetComposite, Serializable
33  {
34  
35      protected Collection innerCollection;
36  
37      public ContentTypeSetImpl()
38      {
39          innerCollection = new ArrayList();
40      }
41  
42      public ContentTypeSetImpl(Collection collection)
43      {
44          innerCollection = collection;
45      }
46  
47      public boolean supportsPortletMode(PortletMode mode)
48      {
49          // Always support "VIEW".  Some portlet vendors do not indicate view
50          // in the deployment descriptor.
51          if(mode.equals(PortletMode.VIEW))
52          {
53              return true;
54          }
55          
56          Iterator itr = innerCollection.iterator();
57          while (itr.hasNext())
58          {
59              ContentType p = (ContentType) itr.next();
60              if (p.supportsPortletMode(mode))
61              {
62                  return true;
63              }
64          }
65          
66          return false;
67      }
68      
69      /***
70       * @see org.apache.pluto.om.portlet.ContentTypeSet#get(java.lang.String)
71       */
72      public ContentType get(String contentType)
73      {
74          Iterator itr = innerCollection.iterator();
75          while (itr.hasNext())
76          {
77              ContentType p = (ContentType) itr.next();
78              if (p.getContentType().equals(contentType))
79              {
80                  return p;
81              }
82          }
83  
84          return null;
85      }
86  
87      /***
88       * @see java.util.Collection#add(java.lang.Object)
89       */
90      public boolean add(Object o)
91      {
92          ContentType cType = (ContentType) o;
93          
94          return innerCollection.add(cType);
95      }
96  
97      /***
98       * @see java.util.Collection#remove(java.lang.Object)
99       */
100     public boolean remove(Object o)
101     {
102         ContentType cType = (ContentType) o;
103         
104         return innerCollection.remove(cType);
105     }
106 
107     /***
108      * @see org.apache.jetspeed.om.common.portlet.ContentTypeSetComposite#addContentType(org.apache.pluto.om.portlet.ContentType)
109      */
110     public void addContentType(ContentType contentType)
111     {
112         add(contentType);
113     }
114 
115     /***
116      * @see org.apache.pluto.om.portlet.ContentTypeSet#iterator()
117      */
118     public Iterator iterator()
119     {        
120         return innerCollection.iterator();
121     }
122 
123     /***
124      * @return
125      */
126     public Collection getInnerCollection()
127     {
128         return innerCollection;
129     }
130 
131     /***
132      * @param collection
133      */
134     public void setInnerCollection(Collection collection)
135     {
136         innerCollection = collection;
137     }
138 
139 }