001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.demo.simple;
018:
019: import java.io.IOException;
020:
021: import javax.portlet.ActionRequest;
022: import javax.portlet.ActionResponse;
023: import javax.portlet.PortletException;
024: import javax.portlet.PortletSession;
025:
026: import org.apache.portals.bridges.common.GenericServletPortlet;
027:
028: /**
029: * This class only exists to maintain the Help and View page names. As soon
030: * as the container/engine will retain the preferences this class can be
031: * replaced by configuring portlet preferences.
032: *
033: * @version $Id: AttributeScopeServlet.java 553014 2007-07-03 23:10:53Z ate $
034: * @task Remove this class when the container/engine retain preferences
035: */
036: public class AttributeScopeServlet extends GenericServletPortlet {
037: /**
038: * Default action page when preference does not exist
039: *
040: * @see org.apache.portals.bridges.common.GenericServletPortlet#processAction
041: */
042: private static final String DEFAULT_ACTION_PAGE = null;
043:
044: /**
045: * Default custom page when preference does not exist
046: *
047: * @see org.apache.portals.bridges.common.GenericServletPortlet#doCustom
048: */
049: private static final String DEFAULT_CUSTOM_PAGE = null;
050:
051: /**
052: * Default edit page when preference does not exist
053: *
054: * @see org.apache.portals.bridges.common.GenericServletPortlet#doEdit
055: */
056: private static final String DEFAULT_EDIT_PAGE = null;
057:
058: /**
059: * Default help page when preference does not exist
060: *
061: * @see org.apache.portals.bridges.common.GenericServletPortlet#doHelp
062: */
063: private static final String DEFAULT_HELP_PAGE = "/WEB-INF/demo/simple/AttributeScopeHelp.jsp";
064:
065: /**
066: * Default help page when preference does not exist
067: *
068: * @see org.apache.portals.bridges.common.GenericServletPortlet#doView
069: */
070:
071: private static final String DEFAULT_VIEW_PAGE = "/WEB-INF/demo/simple/AttributeScope.jsp";
072:
073: private static final String APPLICATION_SCOPE_NAME = "ApplicationScope";
074: private static final String PORTLET_SCOPE_NAME = "PortletScope";
075: private static final String REQUEST_SCOPE_NAME = "RequestScope";
076: private static final String SESSION_SCOPE_NAME = "SessionScope";
077:
078: /**
079: * Set default page values when class is created
080: */
081: public AttributeScopeServlet() {
082: setDefaultActionPage(DEFAULT_ACTION_PAGE);
083: setDefaultCustomPage(DEFAULT_CUSTOM_PAGE);
084: setDefaultEditPage(DEFAULT_EDIT_PAGE);
085: setDefaultHelpPage(DEFAULT_HELP_PAGE);
086: setDefaultViewPage(DEFAULT_VIEW_PAGE);
087: }
088:
089: /**
090: * Increment attributes in different scopes
091: *
092: * @see javax.portlet.GenericPortlet#processAction
093: *
094: */
095: public void processAction(ActionRequest request,
096: ActionResponse actionResponse) throws PortletException,
097: IOException {
098: PortletSession session = request.getPortletSession();
099:
100: // Get attribute values, set to 0 if they do not exist
101: Long applicationScopeAttribute = (Long) session.getAttribute(
102: APPLICATION_SCOPE_NAME, PortletSession.PORTLET_SCOPE);
103: if (applicationScopeAttribute == null) {
104: applicationScopeAttribute = new Long(0);
105: }
106: Long portletScopeAttribute = (Long) session.getAttribute(
107: PORTLET_SCOPE_NAME, PortletSession.PORTLET_SCOPE);
108: if (portletScopeAttribute == null) {
109: portletScopeAttribute = new Long(0);
110: }
111: Long requestScopeAttribute = (Long) request
112: .getAttribute(REQUEST_SCOPE_NAME);
113: if (requestScopeAttribute == null) {
114: requestScopeAttribute = new Long(0);
115: }
116:
117: // Increment the values
118: applicationScopeAttribute = new Long(applicationScopeAttribute
119: .longValue() + 1);
120: portletScopeAttribute = new Long(portletScopeAttribute
121: .longValue() + 1);
122: requestScopeAttribute = new Long(requestScopeAttribute
123: .longValue() + 1);
124:
125: // Update the attribute values
126: session.setAttribute(APPLICATION_SCOPE_NAME,
127: applicationScopeAttribute,
128: PortletSession.APPLICATION_SCOPE);
129: session.setAttribute(PORTLET_SCOPE_NAME, portletScopeAttribute,
130: PortletSession.PORTLET_SCOPE);
131: request.setAttribute(REQUEST_SCOPE_NAME, requestScopeAttribute);
132:
133: return;
134: }
135:
136: }
|