1 17 18 19 package org.apache.catalina.core; 20 21 22 import java.util.Enumeration ; 23 import java.util.HashMap ; 24 25 import javax.servlet.ServletRequest ; 26 import javax.servlet.ServletRequestWrapper ; 27 28 import org.apache.catalina.Globals; 29 import org.apache.catalina.util.Enumerator; 30 import org.apache.catalina.util.StringManager; 31 32 33 48 49 class ApplicationRequest extends ServletRequestWrapper { 50 51 52 54 55 58 protected static final String specials[] = 59 { Globals.INCLUDE_REQUEST_URI_ATTR, Globals.INCLUDE_CONTEXT_PATH_ATTR, 60 Globals.INCLUDE_SERVLET_PATH_ATTR, Globals.INCLUDE_PATH_INFO_ATTR, 61 Globals.INCLUDE_QUERY_STRING_ATTR, Globals.FORWARD_REQUEST_URI_ATTR, 62 Globals.FORWARD_CONTEXT_PATH_ATTR, Globals.FORWARD_SERVLET_PATH_ATTR, 63 Globals.FORWARD_PATH_INFO_ATTR, Globals.FORWARD_QUERY_STRING_ATTR }; 64 65 66 68 69 74 public ApplicationRequest(ServletRequest request) { 75 76 super(request); 77 setRequest(request); 78 79 } 80 81 82 84 85 89 protected HashMap attributes = new HashMap (); 90 91 92 95 protected static StringManager sm = 96 StringManager.getManager(Constants.Package); 97 98 99 101 102 107 public Object getAttribute(String name) { 108 109 synchronized (attributes) { 110 return (attributes.get(name)); 111 } 112 113 } 114 115 116 120 public Enumeration getAttributeNames() { 121 122 synchronized (attributes) { 123 return (new Enumerator(attributes.keySet())); 124 } 125 126 } 127 128 129 135 public void removeAttribute(String name) { 136 137 synchronized (attributes) { 138 attributes.remove(name); 139 if (!isSpecial(name)) 140 getRequest().removeAttribute(name); 141 } 142 143 } 144 145 146 153 public void setAttribute(String name, Object value) { 154 155 synchronized (attributes) { 156 attributes.put(name, value); 157 if (!isSpecial(name)) 158 getRequest().setAttribute(name, value); 159 } 160 161 } 162 163 164 166 167 172 public void setRequest(ServletRequest request) { 173 174 super.setRequest(request); 175 176 synchronized (attributes) { 178 attributes.clear(); 179 Enumeration names = request.getAttributeNames(); 180 while (names.hasMoreElements()) { 181 String name = (String ) names.nextElement(); 182 Object value = request.getAttribute(name); 183 attributes.put(name, value); 184 } 185 } 186 187 } 188 189 190 192 193 199 protected boolean isSpecial(String name) { 200 201 for (int i = 0; i < specials.length; i++) { 202 if (specials[i].equals(name)) 203 return (true); 204 } 205 return (false); 206 207 } 208 209 210 } 211 | Popular Tags |