001 // Copyright 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 015 package org.apache.tapestry.describe; 016 017 import java.util.Iterator; 018 import java.util.List; 019 020 import javax.servlet.http.HttpServletRequest; 021 022 import org.apache.tapestry.web.WebUtils; 023 024 /** 025 * Strategy for describing an {@link javax.servlet.http.HttpServletRequest}. 026 * 027 * @author Howard M. Lewis Ship 028 * @since 4.0 029 */ 030 public class HttpServletRequestStrategy implements DescribableStrategy 031 { 032 033 public void describeObject(Object object, DescriptionReceiver receiver) 034 { 035 HttpServletRequest request = (HttpServletRequest) object; 036 037 receiver.title("HttpServletRequest"); 038 receiver.property("authType", request.getAuthType()); 039 receiver.property("characterEncoding", request.getCharacterEncoding()); 040 receiver.property("contentLength", request.getContentLength()); 041 receiver.property("contextPath", request.getContextPath()); 042 receiver.property("contentType", request.getContentType()); 043 receiver.array("cookies", request.getCookies()); 044 receiver.property("locale", request.getLocale()); 045 receiver.property("method", request.getMethod()); 046 receiver.property("pathInfo", request.getPathInfo()); 047 receiver.property("pathTranslated", request.getPathTranslated()); 048 receiver.property("protocol", request.getProtocol()); 049 receiver.property("queryString", request.getQueryString()); 050 receiver.property("requestURI", request.getRequestURI()); 051 receiver.property("scheme", request.getScheme()); 052 receiver.property("secure", request.isSecure()); 053 receiver.property("serverName", request.getServerName()); 054 receiver.property("serverPort", request.getServerPort()); 055 receiver.property("servletPath", request.getServletPath()); 056 receiver.property("userPrincipal", request.getUserPrincipal()); 057 058 receiver.section("Parameters"); 059 060 List keys = WebUtils.toSortedList(request.getParameterNames()); 061 Iterator i = keys.iterator(); 062 while(i.hasNext()) 063 { 064 String key = (String) i.next(); 065 String[] values = request.getParameterValues(key); 066 067 receiver.array(key, values); 068 } 069 070 receiver.section("Headers"); 071 keys = WebUtils.toSortedList(request.getHeaderNames()); 072 i = keys.iterator(); 073 while(i.hasNext()) 074 { 075 String key = (String) i.next(); 076 String value = request.getHeader(key); 077 078 receiver.property(key, value); 079 } 080 081 receiver.section("Attributes"); 082 keys = WebUtils.toSortedList(request.getAttributeNames()); 083 i = keys.iterator(); 084 while(i.hasNext()) 085 { 086 String key = (String) i.next(); 087 Object value = request.getAttribute(key); 088 089 receiver.property(key, value); 090 } 091 } 092 093 }