KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > portal > controllers > AbstractPortletController


1 /*
2  * Copyright 2000-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 package org.apache.jetspeed.portal.controllers;
18
19 //jetspeed support
20
import org.apache.jetspeed.portal.BasePortletSetConstraints;
21 import org.apache.jetspeed.portal.PortletConfig;
22 import org.apache.jetspeed.portal.PortletController;
23 import org.apache.jetspeed.portal.PortletControllerConfig;
24 import org.apache.jetspeed.portal.PortletSet;
25
26 import org.apache.jetspeed.capability.CapabilityMap;
27 import org.apache.jetspeed.services.rundata.JetspeedRunData;
28 import org.apache.jetspeed.services.Registry;
29 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
30 import org.apache.jetspeed.services.logging.JetspeedLogger;
31 import org.apache.jetspeed.om.registry.PortletControllerEntry;
32 import org.apache.jetspeed.om.registry.MediaTypeEntry;
33 import org.apache.jetspeed.util.MimeType;
34
35 //turbine support
36
import org.apache.turbine.util.RunData;
37
38 //ecs stuff
39
import org.apache.ecs.ConcreteElement;
40 import org.apache.ecs.ElementContainer;
41
42 import java.util.Map JavaDoc;
43 import java.util.Iterator JavaDoc;
44
45 /**
46  @author <a HREF="mailto:burton@apache.org">Kevin A. Burton</a>
47  @version $Id: AbstractPortletController.java,v 1.26 2004/02/23 03:25:06 jford Exp $
48 */

49 public abstract class AbstractPortletController implements PortletController
50 {
51
52     /**
53      * Static initialization of the logger for this class
54      */

55     private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(AbstractPortletController.class.getName());
56     
57     /**
58      * Default padding to be displayed between portlets
59      */

60     public int DEFAULT_PADDING = 3;
61
62     private String JavaDoc width="100%";
63     private PortletSet portlets = null;
64     private PortletControllerConfig conf = null;
65
66
67     /**
68     Allows the user to override the default set of portlets...
69     */

70     public final void setConfig(PortletControllerConfig conf)
71     {
72         this.conf = conf;
73     }
74
75
76     /**
77     */

78     public final PortletControllerConfig getConfig()
79     {
80         return this.conf;
81     }
82
83     /**
84     Allows the user to override the default set of portlets...
85     */

86     public final void setPortlets(PortletSet portlets)
87     {
88       this.portlets = portlets;
89     }
90
91
92     /**
93     */

94     public final PortletSet getPortlets()
95     {
96         return this.portlets;
97     }
98
99     /**
100     */

101     public String JavaDoc getWidth() {
102         return this.width;
103     }
104
105     /**
106     */

107     public void setWidth(String JavaDoc width) {
108         this.width = width;
109     }
110
111     /**
112     Returns the padding value between the displayed portlets
113     */

114     public int getPadding() {
115         int padding = 0;
116
117         try {
118             PortletConfig conf = getPortlets().getPortletConfig();
119             padding = Integer.parseInt( conf.getSkin( "padding" , String.valueOf( DEFAULT_PADDING ) ) );
120         } catch ( RuntimeException JavaDoc e ) {
121             logger.error("Exception getting padding value", e);
122             padding = DEFAULT_PADDING;
123         }
124
125         return padding;
126     }
127
128     /**
129     Sets the padding space to be put between portlets
130     */

131     public void setPadding(int padding) {
132         try {
133             PortletConfig conf = getPortlets().getPortletConfig();
134             conf.setSkin( "padding" , String.valueOf( padding ) );
135         } catch ( RuntimeException JavaDoc e ) {
136             logger.error("Exception setting padding value", e);
137             // FIXME: What should we do if there's no portlets, config or skin defined ?
138
}
139
140     }
141
142     /**
143     Sets the padding space to be put between portlets
144     */

145     public void setPadding(String JavaDoc padding) {
146         try {
147             PortletConfig conf = getPortlets().getPortletConfig();
148             conf.setSkin( "padding" , padding );
149         } catch ( RuntimeException JavaDoc e ) {
150             logger.error("Exception setting padding value", e);
151             // FIXME: What should we do if there's no portlets, config or skin defined ?
152
}
153     }
154
155     /**
156     */

157     public void init()
158     {
159         // no specific init
160
}
161
162
163     /**
164     @see Portlet#supportsType
165     */

166     public boolean supportsType( MimeType mimeType )
167     {
168         // we now need to check that the control also supports the type...
169
PortletControllerEntry entry =
170                 (PortletControllerEntry)Registry.getEntry(Registry.PORTLET_CONTROLLER,
171                                                    getConfig().getName() );
172         String JavaDoc baseType = mimeType.toString();
173
174         if (entry!=null)
175         {
176             Iterator JavaDoc i = entry.listMediaTypes();
177
178             while(i.hasNext())
179             {
180                 String JavaDoc name = (String JavaDoc)i.next();
181                 MediaTypeEntry media = (MediaTypeEntry)Registry.getEntry(Registry.MEDIA_TYPE, name);
182
183                 if (media != null)
184                 {
185                     if (baseType.equals(media.getMimeType()))
186                     {
187                         return true;
188                     }
189                 }
190             }
191         }
192
193         return false;
194     }
195
196     /**
197     */

198     public ConcreteElement getContent( RunData rundata )
199     {
200
201         CapabilityMap map = ((JetspeedRunData)rundata).getCapability();
202         ConcreteElement content = null;
203
204         if ( MimeType.WML.equals( map.getPreferredType() ) )
205         {
206             content = getWMLContent( portlets, rundata );
207         }
208         else if ( MimeType.HTML.equals( map.getPreferredType() ) )
209         {
210             content = getHTMLContent( portlets, rundata );
211         }
212         else
213         {
214             // we don't know how to handle this type, maybe a subclass knows
215
content = getContent( portlets, rundata );
216         }
217
218         return content;
219     }
220
221     /**
222     */

223     protected ConcreteElement getContent( PortletSet set, RunData data )
224     {
225         return new ElementContainer();
226     }
227
228     /**
229     */

230     protected ConcreteElement getWMLContent( PortletSet set, RunData data )
231     {
232         return new ElementContainer();
233     }
234
235     /**
236     */

237     protected ConcreteElement getHTMLContent( PortletSet set, RunData data )
238     {
239         return new ElementContainer();
240     }
241
242     /**
243      * Creates a constraint object based on an original map source.
244      *
245      * @param original the source for this constraint object
246      * @return a new Constraints object appropriate for this controller
247      */

248     public PortletSet.Constraints getConstraints( Map original )
249     {
250         PortletSet.Constraints constraints = new BasePortletSetConstraints();
251         if (original != null) constraints.putAll(original);
252         return constraints;
253     }
254
255 }
256
Popular Tags