1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.demo.simple;
18
19 import java.io.IOException;
20
21 import javax.portlet.ActionRequest;
22 import javax.portlet.ActionResponse;
23 import javax.portlet.PortletException;
24 import javax.portlet.PortletSession;
25
26 import org.apache.portals.bridges.common.GenericServletPortlet;
27
28 /***
29 * This class only exists to maintain the Help and View page names. As soon
30 * as the container/engine will retain the preferences this class can be
31 * replaced by configuring portlet preferences.
32 *
33 * @version $Id: AttributeScopeServlet.java 553014 2007-07-03 23:10:53Z ate $
34 * @task Remove this class when the container/engine retain preferences
35 */
36 public class AttributeScopeServlet extends GenericServletPortlet
37 {
38 /***
39 * Default action page when preference does not exist
40 *
41 * @see org.apache.portals.bridges.common.GenericServletPortlet#processAction
42 */
43 private static final String DEFAULT_ACTION_PAGE = null;
44
45 /***
46 * Default custom page when preference does not exist
47 *
48 * @see org.apache.portals.bridges.common.GenericServletPortlet#doCustom
49 */
50 private static final String DEFAULT_CUSTOM_PAGE = null;
51
52 /***
53 * Default edit page when preference does not exist
54 *
55 * @see org.apache.portals.bridges.common.GenericServletPortlet#doEdit
56 */
57 private static final String DEFAULT_EDIT_PAGE = null;
58
59 /***
60 * Default help page when preference does not exist
61 *
62 * @see org.apache.portals.bridges.common.GenericServletPortlet#doHelp
63 */
64 private static final String DEFAULT_HELP_PAGE = "/WEB-INF/demo/simple/AttributeScopeHelp.jsp";
65
66 /***
67 * Default help page when preference does not exist
68 *
69 * @see org.apache.portals.bridges.common.GenericServletPortlet#doView
70 */
71
72 private static final String DEFAULT_VIEW_PAGE = "/WEB-INF/demo/simple/AttributeScope.jsp";
73
74 private static final String APPLICATION_SCOPE_NAME = "ApplicationScope";
75 private static final String PORTLET_SCOPE_NAME = "PortletScope";
76 private static final String REQUEST_SCOPE_NAME = "RequestScope";
77 private static final String SESSION_SCOPE_NAME = "SessionScope";
78
79 /***
80 * Set default page values when class is created
81 */
82 public AttributeScopeServlet ()
83 {
84 setDefaultActionPage(DEFAULT_ACTION_PAGE);
85 setDefaultCustomPage(DEFAULT_CUSTOM_PAGE);
86 setDefaultEditPage(DEFAULT_EDIT_PAGE);
87 setDefaultHelpPage(DEFAULT_HELP_PAGE);
88 setDefaultViewPage(DEFAULT_VIEW_PAGE);
89 }
90
91 /***
92 * Increment attributes in different scopes
93 *
94 * @see javax.portlet.GenericPortlet#processAction
95 *
96 */
97 public void processAction(ActionRequest request, ActionResponse actionResponse)
98 throws PortletException, IOException
99 {
100 PortletSession session = request.getPortletSession();
101
102
103 Long applicationScopeAttribute = (Long)session.getAttribute(APPLICATION_SCOPE_NAME, PortletSession.PORTLET_SCOPE);
104 if (applicationScopeAttribute == null)
105 {
106 applicationScopeAttribute = new Long(0);
107 }
108 Long portletScopeAttribute = (Long)session.getAttribute(PORTLET_SCOPE_NAME, PortletSession.PORTLET_SCOPE);
109 if (portletScopeAttribute == null)
110 {
111 portletScopeAttribute = new Long(0);
112 }
113 Long requestScopeAttribute = (Long)request.getAttribute(REQUEST_SCOPE_NAME);
114 if (requestScopeAttribute == null)
115 {
116 requestScopeAttribute = new Long(0);
117 }
118
119
120 applicationScopeAttribute = new Long(applicationScopeAttribute.longValue() + 1);
121 portletScopeAttribute = new Long(portletScopeAttribute.longValue() + 1);
122 requestScopeAttribute = new Long(requestScopeAttribute.longValue() + 1);
123
124
125 session.setAttribute( APPLICATION_SCOPE_NAME, applicationScopeAttribute, PortletSession.APPLICATION_SCOPE);
126 session.setAttribute( PORTLET_SCOPE_NAME, portletScopeAttribute, PortletSession.PORTLET_SCOPE);
127 request.setAttribute( REQUEST_SCOPE_NAME, requestScopeAttribute);
128
129 return;
130 }
131
132 }
133