KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.StringUtils;
24
25 /**
26  *
27  *
28  * @author <a HREF="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
29  *
30  * @version CVS $Id: ContentTypeImpl.java 123407 2004-12-27 13:51:59Z cziegeler $
31  */

32 public class ContentTypeImpl
33 implements ContentType, java.io.Serializable JavaDoc, Support {
34
35     private String JavaDoc contentType;
36     private Collection JavaDoc portletModes = new ArrayList JavaDoc();
37
38     private Collection JavaDoc castorPortletModes = new ArrayList JavaDoc();
39
40     public ContentTypeImpl() {
41         // nothing to do
42
}
43
44     /* (non-Javadoc)
45      * @see org.apache.pluto.om.portlet.ContentType#getContentType()
46      */

47     public String JavaDoc getContentType() {
48         return contentType;
49     }
50
51     /* (non-Javadoc)
52      * @see org.apache.pluto.om.portlet.ContentType#getPortletModes()
53      */

54     public Iterator JavaDoc getPortletModes() {
55         return portletModes.iterator();
56     }
57     
58     /* (non-Javadoc)
59      * @see org.apache.cocoon.portal.pluto.om.common.Support#postLoad(java.lang.Object)
60      */

61     public void postLoad(Object JavaDoc parameter) throws Exception JavaDoc {
62         portletModes.clear();
63         Iterator JavaDoc iterator = castorPortletModes.iterator();
64         while (iterator.hasNext()) {
65             String JavaDoc name = (String JavaDoc)iterator.next();
66             portletModes.add(new javax.portlet.PortletMode(name));
67         }
68         if (!portletModes.contains(javax.portlet.PortletMode.VIEW)) {
69             portletModes.add(javax.portlet.PortletMode.VIEW);
70         }
71     }
72
73     /* (non-Javadoc)
74      * @see org.apache.cocoon.portal.pluto.om.common.Support#preBuild(java.lang.Object)
75      */

76     public void preBuild(Object JavaDoc parameter) throws Exception JavaDoc {
77         // nothing to do
78
}
79
80     /* (non-Javadoc)
81      * @see org.apache.cocoon.portal.pluto.om.common.Support#postBuild(java.lang.Object)
82      */

83     public void postBuild(Object JavaDoc parameter) throws Exception JavaDoc {
84         // nothing to do
85
}
86
87     /* (non-Javadoc)
88      * @see org.apache.cocoon.portal.pluto.om.common.Support#preStore(java.lang.Object)
89      */

90     public void preStore(Object JavaDoc parameter) throws Exception JavaDoc {
91         castorPortletModes.clear();
92         Iterator JavaDoc iterator = portletModes.iterator();
93         while (iterator.hasNext()) {
94             javax.portlet.PortletMode mode = (javax.portlet.PortletMode)iterator.next();
95             castorPortletModes.add(mode.toString());
96         }
97     }
98
99     /* (non-Javadoc)
100      * @see org.apache.cocoon.portal.pluto.om.common.Support#postStore(java.lang.Object)
101      */

102     public void postStore(Object JavaDoc parameter) throws Exception JavaDoc {
103         // nothing to do
104
}
105
106     // additional methods.
107

108     public void setContentType(String JavaDoc contentType) {
109         this.contentType = contentType;
110     }
111
112     public void setPortletModes(Collection JavaDoc portletModes) {
113         this.portletModes = portletModes;
114     }
115
116     public boolean supportsPortletMode(javax.portlet.PortletMode portletMode) {
117         return portletModes.contains(portletMode);
118     }
119     
120     /* (non-Javadoc)
121      * @see java.lang.Object#toString()
122      */

123     public String JavaDoc toString() {
124         return toString(0);
125     }
126
127     public String JavaDoc toString(int indent) {
128         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(50);
129         StringUtils.newLine(buffer,indent);
130         buffer.append(getClass().toString()); buffer.append(":");
131         StringUtils.newLine(buffer,indent);
132         buffer.append("{");
133         StringUtils.newLine(buffer,indent);
134         buffer.append("contentType='"); buffer.append(contentType); buffer.append("'");
135         int i = 0;
136         Iterator JavaDoc iterator = portletModes.iterator();
137         while (iterator.hasNext()) {
138             StringUtils.newLine(buffer,indent);
139             buffer.append("portletMode[");
140             buffer.append(i++);
141             buffer.append("]='");
142             buffer.append(iterator.next());
143             buffer.append("'");
144         }
145         StringUtils.newLine(buffer,indent);
146         buffer.append("}");
147         return buffer.toString();
148     }
149
150     public Collection JavaDoc getCastorPortletModes() {
151         return castorPortletModes;
152     }
153
154 }
155
Popular Tags