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 019 import javax.servlet.ServletContext; 020 021 import 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 */ 029 public 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() + "." 040 + context.getMinorVersion()); 041 042 receiver.section("Attributes"); 043 044 Iterator i = WebUtils.toSortedList(context.getAttributeNames()) 045 .iterator(); 046 while(i.hasNext()) 047 { 048 String key = (String) i.next(); 049 050 receiver.property(key, context.getAttribute(key)); 051 } 052 053 receiver.section("Initialization Parameters"); 054 i = WebUtils.toSortedList(context.getInitParameterNames()).iterator(); 055 while(i.hasNext()) 056 { 057 String key = (String) i.next(); 058 059 receiver.property(key, context.getInitParameter(key)); 060 } 061 062 } 063 064 }