1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.demo.preferences;
18
19 import java.io.IOException;
20 import java.text.MessageFormat;
21 import java.util.ResourceBundle;
22
23 import javax.portlet.ActionRequest;
24 import javax.portlet.ActionResponse;
25 import javax.portlet.GenericPortlet;
26 import javax.portlet.PortletConfig;
27 import javax.portlet.PortletContext;
28 import javax.portlet.PortletException;
29 import javax.portlet.PortletRequestDispatcher;
30 import javax.portlet.PortletSession;
31 import javax.portlet.RenderRequest;
32 import javax.portlet.RenderResponse;
33
34 /***
35 * <p>
36 * PreferencePortlet
37 * </p>
38 *
39 * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
40 * @version $Id: PreferencePortlet.java 516448 2007-03-09 16:25:47Z ate $
41 *
42 */
43 public class PreferencePortlet extends GenericPortlet
44 {
45
46 /***
47 * @see javax.portlet.GenericPortlet#doView(javax.portlet.RenderRequest, javax.portlet.RenderResponse)
48 */
49 protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException
50 {
51 PortletContext context = getPortletContext();
52 ResourceBundle resource = getPortletConfig().getResourceBundle(request.getLocale());
53
54 request.setAttribute("viewMessage", resource.getString("preference.label.MyModeIsView"));
55
56 PortletRequestDispatcher rd = context.getRequestDispatcher("/WEB-INF/demo/preference/pref-view.jsp");
57 rd.include(request, response);
58 }
59
60 /***
61 * @see javax.portlet.GenericPortlet#init()
62 */
63 public void init(PortletConfig config) throws PortletException
64 {
65
66 super.init(config);
67 }
68
69 /***
70 * @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
71 */
72 public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException
73 {
74 ResourceBundle resource = getPortletConfig().getResourceBundle(request.getLocale());
75
76 Integer iCount = (Integer) request.getPortletSession().getAttribute("org.apache.jetspeed.invocationCount");
77 if (iCount == null)
78 {
79 iCount = new Integer(0);
80 }
81
82 int count = iCount.intValue();
83 count++;
84
85 response.setRenderParameter("invocationCount", String.valueOf(count));
86
87 MessageFormat format = new MessageFormat(resource.getString("preference.label.processActionIWasInvoked"));
88 String[] patterns = { Integer.toString(count)};
89 response.setRenderParameter("invokeMessage", format.format(patterns));
90 request.getPortletSession().setAttribute("org.apache.jetspeed.invocationCount", new Integer(count), PortletSession.PORTLET_SCOPE);
91
92 }
93
94 }