KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > portal > portlets > AbstractVTLPortlet


1 package org.apache.jetspeed.portal.portlets;
2
3 // Turbine stuff
4
import org.apache.turbine.util.RunData;
5
6 // Jetspeed stuff
7
import org.apache.jetspeed.portal.Portlet;
8 import org.apache.jetspeed.portal.PortletException;
9 import org.apache.jetspeed.portal.portlets.AbstractPortlet;
10 import org.apache.jetspeed.portal.service.PersistenceService;
11 import org.apache.jetspeed.portal.service.ServiceFactory;
12 import org.apache.jetspeed.portal.service.ServiceException;
13
14
15 /**
16 An abstract portlet supporting min/max/restore/conf/close buttons
17
18 @author <a HREF="mailto:re_carrasco@bco011.sonda.cl">Roberto Carrasco</a>
19 */

20 public abstract class AbstractVTLPortlet extends AbstractPortlet
21 {
22
23     /**
24     By default the data is non cacheable
25     */

26     public void init( ) throws PortletException
27     {
28         setCacheable( false );
29     }
30
31     /**
32     All portlets can be minimized only if there is a user logged in
33
34     @param rundata A RunData object
35     */

36     public boolean getAllowMinimize( RunData rundata )
37     {
38         return rundata.getUser() != null && rundata.getUser().hasLoggedIn();
39     }
40
41     /**
42     All portlets can be closed only if there is a user logged in
43
44     @param rundata A RunData object
45     */

46     public boolean getAllowClose( RunData rundata )
47     {
48         return rundata.getUser() != null && rundata.getUser().hasLoggedIn();
49     }
50
51     /**
52     Retrieve a portlet attribute from persistent storage
53
54     @param attrName The attribute to retrieve
55     @parm attrDefValue The value if the attr doesn't exists
56     @param rundata A RunData object
57     @return The attribute value
58     */

59     public String JavaDoc getAttribute( String JavaDoc attrName, String JavaDoc attrDefValue, RunData rundata )
60     {
61         String JavaDoc attrValue = null ;
62
63         try
64         {
65             Object JavaDoc[] params = { this };
66             PersistenceService ps = (PersistenceService)ServiceFactory
67                                         .getService( PersistenceService.class,
68                                                      rundata, params);
69             attrValue = ps.getPage().getAttribute( attrName );
70             if( attrValue == null )
71             {
72                 attrValue = attrDefValue ;
73             }
74         }
75         catch ( ServiceException e )
76         {
77             attrValue = attrDefValue ;
78         }
79
80         return attrValue;
81     }
82
83     /**
84     A way to store a portlet attribute in persistent storage
85
86     @param attrName The attribute to retrieve
87     @parm attrValue The value to store
88     @param rundata A RunData object
89     */

90     public void setAttribute( String JavaDoc attrName, String JavaDoc attrValue, RunData rundata )
91     {
92         try
93         {
94             Object JavaDoc[] params = { this };
95             PersistenceService ps = (PersistenceService)ServiceFactory
96                                         .getService( PersistenceService.class,
97                                                      rundata, params);
98             ps.getPage().setAttribute( attrName, attrValue );
99             ps.store();
100         }
101         catch ( ServiceException e ) {}
102     }
103
104     /**
105     Change the portlet visibility state ( minimized <-> normal )
106
107     @param minimize True if the portlet change to minimized
108     @param rundata A RunData object
109     */

110     public void setMinimized( boolean minimize, RunData rundata )
111     {
112         if( this.getAllowMinimize( rundata ) )
113         {
114             this.setAttribute("minimized", minimize ? "true" : "false", rundata );
115         }
116     }
117
118     /**
119
120     @param rundata A RunData object
121     @return True if the portlet is currently minimized
122     */

123     public boolean isMinimized( RunData rundata )
124     {
125         return this.getAttribute("minimized", "false", rundata ).equals("true");
126     }
127
128     /**
129     A way to detect if the max button was clicked
130
131     @param rundata A RunData object
132     @return True if max button clicked
133     */

134     public boolean isButtonMaximize( RunData rundata )
135     {
136         String JavaDoc portlet = rundata.getParameters().getString ( "portlet", "" );
137         String JavaDoc button = rundata.getParameters().getString ( "button", "" );
138
139         return portlet.equals( this.getName() ) && button.equals("maximize");
140     }
141
142     /**
143     A way to detect if the config button was clicked
144
145     @param rundata A RunData object
146     @return True if config button clicked
147     */

148     public boolean isButtonConfigure( RunData rundata )
149     {
150         String JavaDoc portlet = rundata.getParameters().getString ( "portlet", "" );
151         String JavaDoc button = rundata.getParameters().getString ( "button", "" );
152
153         return portlet.equals( this.getName() ) && button.equals("configure");
154     }
155
156
157 }
158
Popular Tags