KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > web > MultiMapJacRequest


1 /*
2   Copyright (C) 2002 Laurent Martelli <laurent@aopsys.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.aspects.gui.web;
19
20 import java.util.Iterator JavaDoc;
21 import java.util.Map JavaDoc;
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23 import org.mortbay.util.MultiMap;
24
25 /**
26  * This class represents a multi-part HttpRequest.
27  */

28 public class MultiMapJacRequest extends AbstractJacRequest implements JacRequest {
29     MultiMap parameters;
30
31     /**
32      * Parameters are initialized from the given map.
33      */

34     public MultiMapJacRequest(MultiMap map, HttpServletRequest JavaDoc servletRequest) {
35         super(servletRequest);
36         this.parameters = map;
37         readParamsFromRequest(servletRequest);
38     }
39
40     public MultiMapJacRequest(MultiMap map, HttpServletRequest JavaDoc servletRequest,
41                               JacRequest parent) {
42         this(map,servletRequest);
43         this.parent = parent;
44     }
45
46     /**
47      * Parameters are copied from the HttpServletRequest.
48      */

49     public MultiMapJacRequest(HttpServletRequest JavaDoc servletRequest) {
50         super(servletRequest);
51         parameters = new MultiMap();
52         readParamsFromRequest(servletRequest);
53     }
54
55     protected void readParamsFromRequest(HttpServletRequest JavaDoc servletRequest) {
56         // We must copy the parameters because HttpServletRequest
57
// objects are recycled by Jetty
58
Map JavaDoc servletParameters = servletRequest.getParameterMap();
59         Iterator JavaDoc it = servletParameters.keySet().iterator();
60         while(it.hasNext()) {
61             String JavaDoc name = (String JavaDoc)it.next();
62             String JavaDoc[] values = (String JavaDoc[])servletParameters.get(name);
63             parameters.putValues(name,values);
64         }
65     }
66
67     public boolean contains(String JavaDoc name) {
68         if (parameters.containsKey(name))
69             return true;
70         else if (parent!=null)
71             return parent.contains(name);
72         else
73             return false;
74     }
75
76     public Object JavaDoc getParameter(String JavaDoc name) {
77         if (parameters.containsKey(name))
78             return parameters.getString(name);
79         else if (parent!=null)
80             return parent.getParameter(name);
81         else
82             return null;
83     }
84
85     public Object JavaDoc[] getParameters(String JavaDoc name) {
86         if (parameters.containsKey(name))
87             return parameters.getValues(name).toArray(new String JavaDoc [0]);
88         else if (parent!=null)
89             return parent.getParameters(name);
90         else
91             return null;
92     }
93
94     public String JavaDoc toString() {
95         return parameters.toString();
96     }
97     
98 }
99
Popular Tags