1 29 30 package com.caucho.server.webapp; 31 32 import com.caucho.log.Log; 33 import com.caucho.util.FreeList; 34 35 import javax.servlet.ServletException ; 36 import javax.servlet.http.HttpServletRequest ; 37 import javax.servlet.http.HttpServletResponse ; 38 import java.util.Enumeration ; 39 import java.util.Hashtable ; 40 import java.util.Iterator ; 41 import java.util.logging.Logger ; 42 45 class IncludeDispatchRequest extends DispatchRequest { 46 protected static final Logger log 47 = Logger.getLogger(IncludeDispatchRequest.class.getName()); 48 49 private static final FreeList<IncludeDispatchRequest> _freeList 50 = new FreeList<IncludeDispatchRequest>(32); 51 52 private Hashtable <String ,String > _headers; 53 54 protected IncludeDispatchRequest() 55 { 56 } 57 58 61 public static IncludeDispatchRequest createDispatch() 62 { 63 IncludeDispatchRequest req = _freeList.allocate(); 64 if (req == null) 65 req = new IncludeDispatchRequest(); 66 67 return req; 68 } 69 70 void init(WebApp webApp, 71 WebApp oldWebApp, 72 HttpServletRequest request, 73 HttpServletResponse response, 74 String method, String uri, 75 String servletPath, String pathInfo, 76 String queryString, String addedQuery) 77 throws ServletException 78 { 79 super.init(webApp, oldWebApp, request, response, 80 method, uri, servletPath, pathInfo, queryString, addedQuery); 81 82 _headers = null; 83 } 84 85 88 public Enumeration getHeaderNames() 89 { 90 return new HeaderEnumeration(super.getHeaderNames(), _headers); 91 } 92 93 public String getHeader(String key) 94 { 95 String value = null; 96 if (_headers != null) 97 value = (String ) _headers.get(key); 98 99 if (value != null) 100 return value; 101 102 if (key.equalsIgnoreCase("If-Modified-Since") || 105 key.equalsIgnoreCase("If-None-Match")) 106 return null; 107 else { 108 return super.getHeader(key); 109 } 110 } 111 112 public void setHeader(String key, String value) 113 { 114 if (_headers == null) 115 _headers = new Hashtable <String ,String >(); 116 _headers.put(key, value); 117 } 118 119 122 public static void free(IncludeDispatchRequest req) 123 { 124 req.free(); 125 126 _freeList.free(req); 127 } 128 129 public static class HeaderEnumeration implements Enumeration { 130 private Enumeration _parent; 131 132 private Hashtable <String ,String > _headers; 133 private Iterator <String > _headerIter; 134 135 private String _nextHeader; 136 137 HeaderEnumeration(Enumeration parent, Hashtable <String ,String > headers) 138 { 139 _parent = parent; 140 _headers = headers; 141 142 if (headers != null) 143 _headerIter = headers.keySet().iterator(); 144 } 145 146 149 public boolean hasMoreElements() 150 { 151 if (_nextHeader != null) 152 return true; 153 154 if (_parent == null && _headerIter == null) 155 return false; 156 157 if (_parent != null) { 158 while (_parent.hasMoreElements() && _nextHeader == null) { 159 _nextHeader = (String ) _parent.nextElement(); 160 161 if (_nextHeader == null) { 162 } 163 else if (_nextHeader.equalsIgnoreCase("If-Modified-Since") || 164 _nextHeader.equalsIgnoreCase("If-None-Match") || 165 _headers != null && _headers.get(_nextHeader) != null) { 166 _nextHeader = null; 167 } 168 } 169 170 if (_nextHeader == null) 171 _parent = null; 172 else 173 return true; 174 } 175 176 if (_headerIter != null) { 177 _nextHeader = _headerIter.next(); 178 } 179 180 return _nextHeader != null; 181 } 182 183 public Object nextElement() 184 { 185 if (! hasMoreElements()) 186 return null; 187 188 Object value = _nextHeader; 189 _nextHeader = null; 190 191 return value; 192 } 193 } 194 } 195 | Popular Tags |