KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > deliver > portal > information > ServletRequestIG


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23 package org.infoglue.deliver.portal.information;
24
25 import java.util.Arrays JavaDoc;
26 import java.util.Collections JavaDoc;
27 import java.util.Enumeration JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.Map JavaDoc;
31 import java.util.Vector JavaDoc;
32
33 import javax.servlet.http.HttpServletRequest JavaDoc;
34 import javax.servlet.http.HttpServletRequestWrapper JavaDoc;
35
36 import org.apache.commons.logging.Log;
37 import org.apache.commons.logging.LogFactory;
38 import org.apache.pluto.om.window.PortletWindow;
39 import org.infoglue.deliver.portal.PortalControlURL;
40
41 /**
42  * @author jand
43  *
44  */

45 public class ServletRequestIG extends HttpServletRequestWrapper JavaDoc {
46     private static final Log log = LogFactory.getLog(ServletRequestIG.class);
47
48     private Map JavaDoc paramMap;
49     private Map JavaDoc attributeMap = new HashMap JavaDoc();
50
51     public ServletRequestIG(PortletWindow window, HttpServletRequest JavaDoc req) {
52         super(req);
53
54         PortalControlURL url = new PortalControlURL(req);
55         this.paramMap = url.getRenderParameterMap(window);
56         this.paramMap.putAll(url.getQueryParameterMap(window)); // in case of namespace-params.
57

58         if (log.isDebugEnabled()) {
59             StringBuffer JavaDoc str = new StringBuffer JavaDoc();
60             for (Iterator JavaDoc it = paramMap.keySet().iterator(); it.hasNext();) {
61                 String JavaDoc name = (String JavaDoc) it.next();
62                 str.append(name);
63                 str.append(": ");
64                 str.append(Arrays.asList((String JavaDoc[]) paramMap.get(name)));
65                 if (it.hasNext())
66                     str.append(", ");
67             }
68             log.debug("Available params: " + str);
69         }
70     }
71
72     /* (non-Javadoc)
73      * @see javax.servlet.ServletRequest#getParameter(java.lang.String)
74      */

75     public String JavaDoc getParameter(String JavaDoc name) {
76         String JavaDoc[] values = (String JavaDoc[]) paramMap.get(name);
77         if (values != null && values.length > 0) {
78             return values[0];
79         }
80         return null;
81     }
82
83     /* (non-Javadoc)
84      * @see javax.servlet.ServletRequest#getParameterMap()
85      */

86     public Map JavaDoc getParameterMap() {
87         return paramMap;
88     }
89
90     /* (non-Javadoc)
91      * @see javax.servlet.ServletRequest#getParameterNames()
92      */

93     public Enumeration JavaDoc getParameterNames() {
94         return Collections.enumeration(paramMap.keySet());
95     }
96
97     /* (non-Javadoc)
98      * @see javax.servlet.ServletRequest#getParameterValues(java.lang.String)
99      */

100     public String JavaDoc[] getParameterValues(String JavaDoc name) {
101         return (String JavaDoc[]) paramMap.get(name);
102     }
103
104     /* (non-Javadoc)
105      * @see javax.servlet.ServletRequest#setAttribute(java.lang.String, java.lang.Object)
106      */

107     public void setAttribute(String JavaDoc key, Object JavaDoc value) {
108         this.attributeMap.put(key, value);
109     }
110
111     /* (non-Javadoc)
112      * @see javax.servlet.ServletRequest#getAttribute(java.lang.String)
113      */

114     public Object JavaDoc getAttribute(String JavaDoc name) {
115         Object JavaDoc o = attributeMap.get(name);
116         if (o == null) {
117             o = super.getAttribute(name);
118         }
119         if (o == null) {
120             o = super.getRequest().getAttribute(name);
121         }
122         return o;
123     }
124
125     /* (non-Javadoc)
126      * @see javax.servlet.ServletRequest#getAttributeNames()
127      */

128     public Enumeration JavaDoc getAttributeNames() {
129         Vector JavaDoc v = new Vector JavaDoc();
130
131         for (Iterator JavaDoc iter = attributeMap.keySet().iterator(); iter.hasNext();) {
132             v.add(iter.next());
133         }
134         for (Enumeration JavaDoc enumeration = super.getAttributeNames(); enumeration.hasMoreElements();) {
135             v.add(enumeration.nextElement());
136         }
137         for (Enumeration JavaDoc enumeration = super.getRequest().getAttributeNames(); enumeration.hasMoreElements();) {
138             v.add(enumeration.nextElement());
139         }
140         return v.elements();
141     }
142
143 }
144
Popular Tags