001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/portal/tags/sakai_2-4-1/portal-render-impl/impl/src/java/org/sakaiproject/portal/render/portlet/servlet/SakaiServletActionRequest.java $
003: * $Id: SakaiServletActionRequest.java 29143 2007-04-19 01:10:38Z ajpoland@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.portal.render.portlet.servlet;
021:
022: import java.util.Enumeration;
023: import java.util.HashMap;
024: import java.util.Iterator;
025: import java.util.Map;
026:
027: import javax.servlet.http.HttpServletRequest;
028: import javax.servlet.http.HttpServletRequestWrapper;
029:
030: import org.sakaiproject.portal.api.PortalService;
031: import org.sakaiproject.portal.render.portlet.services.state.PortletState;
032:
033: /**
034: * @author ddwolf
035: * @author ieb
036: * @since Sakai 2.4
037: * @version $Rev: 29143 $
038: */
039: public class SakaiServletActionRequest extends
040: HttpServletRequestWrapper {
041:
042: private PortletState state;
043:
044: public SakaiServletActionRequest(HttpServletRequest servletRequest,
045: PortletState state) {
046: super (servletRequest);
047: this .state = state;
048: }
049:
050: @Override
051: public boolean isUserInRole(String string) {
052: boolean retval = SakaiServletUtil.isUserInRole(string, state);
053: return retval;
054: }
055:
056: @Override
057: public String getParameter(String string) {
058: String param = super .getParameter(string);
059: if (isEmpty(param)) {
060: return (String) state.getParameters().get(string);
061: }
062: return param;
063: }
064:
065: /**
066: * @param param
067: * @return
068: */
069: private boolean isEmpty(String param) {
070: return (param == null || param.length() == 0);
071: }
072:
073: @Override
074: @SuppressWarnings("unchecked")
075: public Map getParameterMap() {
076: Map paramMap = new HashMap(state.getParameters());
077: Map requestParamMap = super .getParameterMap();
078: for (Iterator<String> i = requestParamMap.keySet().iterator(); i
079: .hasNext();) {
080: String s = i.next();
081: paramMap.put(s, requestParamMap.get(s));
082: }
083: return paramMap;
084: }
085:
086: @Override
087: public Enumeration getParameterNames() {
088: final Iterator i = getParameterMap().keySet().iterator();
089: return new Enumeration() {
090:
091: public boolean hasMoreElements() {
092: return i.hasNext();
093: }
094:
095: public Object nextElement() {
096: return i.next();
097: }
098:
099: };
100: }
101:
102: @Override
103: public String[] getParameterValues(String string) {
104: String[] v = super .getParameterValues(string);
105: if (v == null) {
106: return (String[]) state.getParameters().get(string);
107: }
108: return v;
109: }
110:
111: /**
112: * This causes the placement ID to be retrievabl from the request
113: */
114: @Override
115: public Object getAttribute(String attributeName) {
116: if (PortalService.PLACEMENT_ATTRIBUTE.equals(attributeName)) {
117: return state.getId();
118: } else {
119: return super.getAttribute(attributeName);
120: }
121: }
122:
123: }
|