KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > portal > controls > VTLTitlePortletControl


1 package org.apache.jetspeed.portal.controls;
2
3 import org.apache.jetspeed.portal.portlets.AbstractVTLPortlet;
4
5 // Turbine stuff
6
import org.apache.turbine.services.velocity.TurbineVelocity;
7 import org.apache.turbine.util.RunData;
8 import org.apache.turbine.util.DynamicURI;
9
10 // Jetspeed stuff
11
import org.apache.jetspeed.portal.Portlet;
12 import org.apache.jetspeed.portal.PortletControl;
13 import org.apache.jetspeed.util.MimeType;
14 import org.apache.jetspeed.util.URILookup;
15 import org.apache.jetspeed.util.JetspeedException;
16
17 // Ecs stuff
18
import org.apache.ecs.ConcreteElement;
19 import org.apache.ecs.StringElement;
20
21 // Velocity Stuff
22
import org.apache.velocity.context.Context;
23
24 /**
25 A Velocity based portlet control with added funtionalities
26 like min/max/conf/restore/close buttons.
27
28 you need this lines in jetspeed-config.jcfg:
29
30     <portlet-control-registry>
31
32        <portlet-control-entry name="VTLTitlePortletControl">
33            <classname>org.apache.jetspeed.portal.controls.VTLTitlePortletControl</classname>
34            <meta-info>
35                <title>VTLPortletControl</title>
36            </meta-info>
37            <media-type ref="html"/>
38        </portlet-control-entry>
39
40     </portlet-control-registry>
41
42
43 and (optional) in JetspeedResources.properties:
44
45     portletcontrol.default.classname=org.apache.jetspeed.portal.controls.VTLTitlePortletControl
46
47 @author <a HREF="mailto:re_carrasco@bco011.sonda.cl">Roberto Carrasco</a>
48 */

49 public class VTLTitlePortletControl extends PortletControl
50 {
51     /**
52     Only HTML ...
53     */

54     public boolean supportsType( MimeType mimeType )
55     {
56         return mimeType == MimeType.HTML;
57     }
58
59
60     /**
61     */

62     public ConcreteElement getContent( RunData rundata )
63     {
64         // Get the data here to allow the portlet to change some internal state
65
Portlet portlet = getPortlet();
66         String JavaDoc portletName = portlet.getName();
67         ConcreteElement portletContent = portlet.getContent( rundata );
68
69         // default links for buttons (means non visible)
70
String JavaDoc hrefConfigure = "";
71         String JavaDoc hrefMinimize = "";
72         String JavaDoc hrefRestore = "";
73         String JavaDoc hrefMaximize = "";
74         String JavaDoc hrefClose = "";
75
76         // i don't like this, but ...
77
if( portlet instanceof AbstractVTLPortlet)
78         {
79             // only AbstractVTLPortlet gives me this functionality
80
AbstractVTLPortlet xPortlet = (AbstractVTLPortlet)portlet;
81     
82             // configure button
83
if( xPortlet.getAllowEdit( rundata ) )
84             {
85                 hrefConfigure=new DynamicURI( rundata )
86                                     .addPathInfo("portlet", portletName)
87                                     .addPathInfo("button","configure")
88                                     .toString();
89             }
90     
91             // minimize/restore button
92
if( xPortlet.getAllowMinimize( rundata ) )
93             {
94                 if( xPortlet.isMinimized( rundata ) )
95                 {
96                     hrefRestore=new DynamicURI( rundata )
97                                     .addPathInfo("action", "portlets.RestorePortlet")
98                                     .addPathInfo("portletName", portletName)
99                                     .toString();
100                 }
101                 else
102                 {
103                     hrefMinimize=new DynamicURI( rundata )
104                                     .addPathInfo("action", "portlets.MinimizePortlet")
105                                     .addPathInfo("portletName", portletName)
106                                     .toString();
107                 }
108             }
109     
110             // maximize button
111
if( xPortlet.getAllowMaximize( rundata ) )
112             {
113                 hrefMaximize=new DynamicURI( rundata )
114                                     .addPathInfo("portlet", portletName)
115                                     .addPathInfo("button","maximize")
116                                     .toString();
117             }
118     
119             // close button
120
if( xPortlet.getAllowClose( rundata ) )
121             {
122                 hrefClose=new DynamicURI( rundata )
123                                     .addPathInfo("action", "portlets.ClosePortlet")
124                                     .addPathInfo("portletName", portletName)
125                                     .toString();
126             }
127         }
128
129         // Hmmm, let's works like TitlePortletControl
130
else
131         {
132             if ( portlet.getAllowEdit( rundata ) )
133             {
134                 try
135                 {
136                       hrefConfigure = URILookup.getURI( URILookup.TYPE_INFO,
137                                                         URILookup.SUBTYPE_MARK,
138                                                         portlet, rundata );
139                 }
140                 catch (JetspeedException e) {}
141             }
142
143             if ( portlet.getAllowMaximize( rundata ) )
144             {
145                 try
146                 {
147                       hrefMaximize = URILookup.getURI( URILookup.TYPE_HOME,
148                                                        URILookup.SUBTYPE_MAXIMIZE,
149                                                        portlet, rundata );
150                 }
151                 catch (JetspeedException je) {}
152             }
153         }
154
155         // to render we need just a blank context object
156
Context context = TurbineVelocity.getContext();
157
158         // put buttons in the context
159
context.put( "hrefConfigure", hrefConfigure );
160         context.put( "hrefMinimize", hrefMinimize );
161         context.put( "hrefRestore", hrefRestore );
162         context.put( "hrefMaximize", hrefMaximize );
163         context.put( "hrefClose", hrefClose );
164
165         // the whole area used by portlet + borders + title
166
context.put( "panelColor", this.getColor() );
167         context.put( "panelWidth", this.getWidth() );
168
169         // the title area
170
context.put( "titleText", getPortlet().getTitle() );
171         context.put( "titleBgColor", this.getTitleColor() );
172
173         // the portlet area
174
context.put( "portletBgColor", this.getBackgroundColor() );
175
176         // the portlet content
177
context.put( "portletContent", portletContent );
178
179         // let velocity handle look&feel
180
// TODO: get theme from user's preferences
181
String JavaDoc theme = "VTLDefaultTheme.vm";
182         String JavaDoc s = null;
183         try
184         {
185             s = TurbineVelocity.handleRequest(context, "controls/" + theme);
186         }
187         catch( Exception JavaDoc e )
188         {
189             s = e.toString();
190         }
191
192         return new StringElement( s );
193     }
194
195 }
196
197
Popular Tags