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.portalImpl.om.common.Support;
28  import org.apache.pluto.util.StringUtils;
29  
30  public class ContentTypeImpl
31  implements ContentType, java.io.Serializable, Support {
32  
33      private String contentType = null;
34      private Collection portletModes = new ArrayList();
35  
36      private Collection castorPortletModes = new ArrayList();
37  
38      public ContentTypeImpl()
39      {
40      }
41  
42      // ContentType implementation.
43  
44      public String getContentType()
45      {
46          return contentType;
47      }
48  
49      public Iterator getPortletModes()
50      {
51          return portletModes.iterator();
52      }
53      
54      // Support implementation.
55      public void postLoad(Object parameter) throws Exception
56      {
57          portletModes.clear();
58          Iterator iterator = castorPortletModes.iterator();
59          while (iterator.hasNext()) {
60              String name = (String)iterator.next();
61              portletModes.add(new javax.portlet.PortletMode(name));
62          }
63          if (!portletModes.contains(javax.portlet.PortletMode.VIEW)) {
64              portletModes.add(javax.portlet.PortletMode.VIEW);
65          }
66      }
67  
68      public void preBuild(Object parameter) throws Exception
69      {
70      }
71  
72      public void postBuild(Object parameter) throws Exception
73      {
74      }
75  
76      public void preStore(Object parameter) throws Exception
77      {
78          castorPortletModes.clear();
79          Iterator iterator = portletModes.iterator();
80          while (iterator.hasNext()) {
81              javax.portlet.PortletMode mode = (javax.portlet.PortletMode)iterator.next();
82              castorPortletModes.add(mode.toString());
83          }
84      }
85  
86      public void postStore(Object parameter) throws Exception
87      {
88      }
89  
90      // additional methods.
91  
92      public void setContentType(String contentType)
93      {
94          this.contentType = contentType;
95      }
96  
97      public void setPortletModes(Collection portletModes)
98      {
99          this.portletModes = portletModes;
100     }
101 
102     public boolean supportsPortletMode(javax.portlet.PortletMode portletMode)
103     {
104     	return portletModes.contains(portletMode);
105     }	
106     
107     public String toString()
108     {
109         return toString(0);
110     }
111 
112     public String toString(int indent)
113     {
114         StringBuffer buffer = new StringBuffer(50);
115         StringUtils.newLine(buffer,indent);
116         buffer.append(getClass().toString()); buffer.append(":");
117         StringUtils.newLine(buffer,indent);
118         buffer.append("{");
119         StringUtils.newLine(buffer,indent);
120         buffer.append("contentType='"); buffer.append(contentType); buffer.append("'");
121         int i = 0;
122         Iterator iterator = portletModes.iterator();
123         while (iterator.hasNext()) {
124             StringUtils.newLine(buffer,indent);
125             buffer.append("portletMode["); 
126             buffer.append(i++); 
127             buffer.append("]='");
128             buffer.append(iterator.next());
129             buffer.append("'");
130         }
131         StringUtils.newLine(buffer,indent);
132         buffer.append("}");
133         return buffer.toString();
134     }
135 
136     public Collection getCastorPortletModes()
137     {
138         return castorPortletModes;
139     }
140 
141 }