001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.apache.bridges.struts;
022:
023: import com.liferay.portal.struts.StrutsUtil;
024: import com.liferay.portal.util.PortalUtil;
025: import com.liferay.portal.util.WebKeys;
026: import com.liferay.portlet.ActionRequestImpl;
027: import com.liferay.portlet.RenderRequestImpl;
028: import com.liferay.util.CollectionFactory;
029: import com.liferay.util.servlet.UploadServletRequest;
030:
031: import java.util.Collections;
032: import java.util.Enumeration;
033: import java.util.Iterator;
034: import java.util.List;
035: import java.util.Map;
036: import java.util.Vector;
037:
038: import javax.servlet.http.HttpServletRequest;
039: import javax.servlet.http.HttpServletRequestWrapper;
040:
041: /**
042: * <a href="LiferayStrutsRequestImpl.java.html"><b><i>View Source</i></b></a>
043: *
044: * @author Michael Young
045: *
046: */
047: public class LiferayStrutsRequestImpl extends HttpServletRequestWrapper {
048:
049: public LiferayStrutsRequestImpl(ActionRequestImpl req) {
050: this (req.getHttpServletRequest());
051: }
052:
053: public LiferayStrutsRequestImpl(RenderRequestImpl req) {
054: this (req.getHttpServletRequest());
055: }
056:
057: public Object getAttribute(String name) {
058: Object value = null;
059:
060: if (name.startsWith(StrutsUtil.STRUTS_PACKAGE)) {
061: value = _strutsAttributes.get(name);
062: } else {
063: value = super .getAttribute(name);
064: }
065:
066: return value;
067: }
068:
069: public void setAttribute(String name, Object value) {
070: if (name.startsWith(StrutsUtil.STRUTS_PACKAGE)) {
071: _strutsAttributes.put(name, value);
072: } else {
073: super .setAttribute(name, value);
074: }
075: }
076:
077: public Enumeration getAttributeNames() {
078: List attributeNames = new Vector();
079:
080: Enumeration enu = super .getAttributeNames();
081:
082: while (enu.hasMoreElements()) {
083: String name = (String) enu.nextElement();
084:
085: if (!name.startsWith(StrutsUtil.STRUTS_PACKAGE)) {
086: attributeNames.add(name);
087: }
088: }
089:
090: Iterator itr = _strutsAttributes.keySet().iterator();
091:
092: while (itr.hasNext()) {
093: String name = (String) itr.next();
094:
095: attributeNames.add(name);
096: }
097:
098: return Collections.enumeration(attributeNames);
099: }
100:
101: public String getParameter(String name) {
102: if (_multipartParams.get(name) != null) {
103: return null;
104: } else {
105: return super .getParameter(name);
106: }
107: }
108:
109: public Map getParameterMap() {
110: Map params = CollectionFactory.getHashMap();
111:
112: Enumeration enu = getParameterNames();
113:
114: while (enu.hasMoreElements()) {
115: String name = (String) enu.nextElement();
116:
117: String[] values = super .getParameterValues(name);
118:
119: params.put(name, values);
120: }
121:
122: return params;
123: }
124:
125: public Enumeration getParameterNames() {
126: List parameterNames = new Vector();
127:
128: Enumeration enu = super .getParameterNames();
129:
130: while (enu.hasMoreElements()) {
131: String name = (String) enu.nextElement();
132:
133: if (!_multipartParams.containsKey(name)) {
134: parameterNames.add(name);
135: }
136: }
137:
138: return Collections.enumeration(parameterNames);
139: }
140:
141: public String[] getParameterValues(String name) {
142: if (_multipartParams.get(name) != null) {
143: return null;
144: } else {
145: return super .getParameterValues(name);
146: }
147: }
148:
149: protected LiferayStrutsRequestImpl(HttpServletRequest req) {
150: super (req);
151:
152: _strutsAttributes = (Map) req
153: .getAttribute(WebKeys.STRUTS_BRIDGES_ATTRIBUTES);
154:
155: if (_strutsAttributes == null) {
156: _strutsAttributes = CollectionFactory.getHashMap();
157:
158: req.setAttribute(WebKeys.STRUTS_BRIDGES_ATTRIBUTES,
159: _strutsAttributes);
160: }
161:
162: UploadServletRequest uploadReq = PortalUtil
163: .getUploadServletRequest(req);
164:
165: if (uploadReq != null) {
166: _multipartParams = uploadReq.getMultipartParameterMap();
167: }
168: }
169:
170: private Map _strutsAttributes;
171: private Map _multipartParams = CollectionFactory.getHashMap();
172:
173: }
|