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 015package org.apache.tapestry.describe; 016 017import java.util.Iterator; 018 019import javax.servlet.ServletContext; 020 021import org.apache.tapestry.web.WebUtils; 022 023/** 024 * Describes a {@link javax.servlet.ServletContext}. 025 * 026 * @author Howard M. Lewis Ship 027 * @since 4.0 028 */ 029public class ServletContextStrategy implements DescribableStrategy 030{ 031 032 public void describeObject(Object object, DescriptionReceiver receiver) 033 { 034 ServletContext context = (ServletContext) object; 035 036 receiver.title("ServletContext"); 037 038 receiver.property("serverInfo", context.getServerInfo()); 039 receiver.property("version", context.getMajorVersion() + "." + context.getMinorVersion()); 040 041 receiver.section("Attributes"); 042 043 Iterator i = WebUtils.toSortedList(context.getAttributeNames()).iterator(); 044 while (i.hasNext()) 045 { 046 String key = (String) i.next(); 047 048 receiver.property(key, context.getAttribute(key)); 049 } 050 051 receiver.section("Initialization Parameters"); 052 i = WebUtils.toSortedList(context.getInitParameterNames()).iterator(); 053 while (i.hasNext()) 054 { 055 String key = (String) i.next(); 056 057 receiver.property(key, context.getInitParameter(key)); 058 } 059 060 } 061 062}