2 * Copyright (C) 2001, 2002 The Mir-coders group
\r
4 * This file is part of Mir.
\r
6 * Mir is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 2 of the License, or
\r
9 * (at your option) any later version.
\r
11 * Mir is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with Mir; if not, write to the Free Software
\r
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 * In addition, as a special exception, The Mir-coders gives permission to link
\r
21 * the code of this program with any library licensed under the Apache Software License,
\r
22 * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
\r
23 * (or with modified versions of the above that use the same license as the above),
\r
24 * and distribute linked combinations including the two. You must obey the
\r
25 * GNU General Public License in all respects for all of the code used other than
\r
26 * the above mentioned libraries. If you modify this file, you may extend this
\r
27 * exception to your version of the file, but you are not obligated to do so.
\r
28 * If you do not wish to do so, delete this exception statement from your version.
\r
30 package mir.session;
\r
32 import java.util.Arrays;
\r
33 import java.util.List;
\r
34 import java.util.Vector;
\r
35 import javax.servlet.http.HttpServletRequest;
\r
36 import javax.servlet.http.HttpSession;
\r
38 import org.apache.commons.fileupload.FileItem;
\r
40 import mir.util.HTTPParsedRequest;
\r
42 public class HTTPAdapters {
\r
43 public static class HTTPRequestAdapter implements Request {
\r
44 private HttpServletRequest request;
\r
46 public HTTPRequestAdapter(HttpServletRequest aRequest) {
\r
50 public String getHeader(String aHeaderName) {
\r
51 if (aHeaderName.equals("ip"))
\r
52 return request.getRemoteAddr();
\r
54 return request.getHeader(aHeaderName);
\r
57 public String getParameter(String aName) {
\r
58 return request.getParameter(aName);
\r
61 public List getUploadedFiles() {
\r
62 return new Vector();
\r
65 public List getParameters(String aName) {
\r
66 return Arrays.asList(request.getParameterValues(aName));
\r
69 public HttpServletRequest getRequest() {
\r
74 public static class HTTPParsedRequestAdapter implements Request {
\r
75 private HTTPParsedRequest request;
\r
77 public HTTPParsedRequestAdapter(HTTPParsedRequest aRequest) {
\r
81 public String getHeader(String aHeaderName) {
\r
82 if (aHeaderName.equals("ip"))
\r
83 return request.getRequest().getRemoteAddr();
\r
85 return request.getHeader(aHeaderName);
\r
88 public String getParameter(String aName) {
\r
89 return request.getParameter(aName);
\r
92 public List getParameters(String aName) {
\r
93 return request.getParameterList(aName);
\r
96 public List getUploadedFiles() {
\r
97 List result = new Vector();
\r
98 List files = request.getFiles();
\r
100 for (int i=0; i<files.size(); i++) {
\r
101 result.add(new CommonsUploadedFileAdapter((FileItem) files.get(i)));
\r
107 public HttpServletRequest getRequest() {
\r
108 return request.getRequest();
\r
112 public static class HTTPSessionAdapter implements Session {
\r
113 private HttpSession session;
\r
115 public HTTPSessionAdapter(HttpSession aSession) {
\r
116 session = aSession;
\r
118 public Object getAttribute(String aName) {
\r
119 return session.getAttribute(aName);
\r
122 public void deleteAttribute(String aName) {
\r
123 session.removeAttribute(aName);
\r
126 public void setAttribute(String aName, Object aNewValue) {
\r
127 if (aName.equals("$httpsessiontimeout")) {
\r
128 if (aNewValue instanceof Number) {
\r
130 session.setMaxInactiveInterval( ( (Number) aNewValue).intValue());
\r
132 catch (Throwable t) {
\r
137 if (aNewValue == null)
\r
138 deleteAttribute(aName);
\r
140 session.setAttribute(aName, aNewValue);
\r
144 public void terminate() {
\r
145 session.invalidate();
\r