KickJava   Java API By Example, From Geeks To Geeks.

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


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.portalImpl.om.common.Support;
28 import org.apache.pluto.util.StringUtils;
29
30 public class ContentTypeImpl
31 implements ContentType, java.io.Serializable JavaDoc, Support {
32
33     private String JavaDoc contentType = null;
34     private Collection JavaDoc portletModes = new ArrayList JavaDoc();
35
36     private Collection JavaDoc castorPortletModes = new ArrayList JavaDoc();
37
38     public ContentTypeImpl()
39     {
40     }
41
42     // ContentType implementation.
43

44     public String JavaDoc getContentType()
45     {
46         return contentType;
47     }
48
49     public Iterator JavaDoc getPortletModes()
50     {
51         return portletModes.iterator();
52     }
53     
54     // Support implementation.
55
public void postLoad(Object JavaDoc parameter) throws Exception JavaDoc
56     {
57         portletModes.clear();
58         Iterator JavaDoc iterator = castorPortletModes.iterator();
59         while (iterator.hasNext()) {
60             String JavaDoc name = (String JavaDoc)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 JavaDoc parameter) throws Exception JavaDoc
69     {
70     }
71
72     public void postBuild(Object JavaDoc parameter) throws Exception JavaDoc
73     {
74     }
75
76     public void preStore(Object JavaDoc parameter) throws Exception JavaDoc
77     {
78         castorPortletModes.clear();
79         Iterator JavaDoc 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 JavaDoc parameter) throws Exception JavaDoc
87     {
88     }
89
90     // additional methods.
91

92     public void setContentType(String JavaDoc contentType)
93     {
94         this.contentType = contentType;
95     }
96
97     public void setPortletModes(Collection JavaDoc 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 JavaDoc toString()
108     {
109         return toString(0);
110     }
111
112     public String JavaDoc toString(int indent)
113     {
114         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(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 JavaDoc 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 JavaDoc getCastorPortletModes()
137     {
138         return castorPortletModes;
139     }
140
141 }
142
Popular Tags