1 16 17 package org.apache.jetspeed.portal.portlets.admin; 18 19 import org.apache.ecs.html.Table; 21 import org.apache.ecs.html.TD; 22 import org.apache.ecs.html.TH; 23 import org.apache.ecs.html.TR; 24 import org.apache.ecs.ConcreteElement; 25 26 import org.apache.jetspeed.portal.portlets.AbstractPortlet; 28 import org.apache.jetspeed.portal.PortletException; 29 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 30 import org.apache.jetspeed.services.logging.JetspeedLogger; 31 32 import org.apache.turbine.util.RunData; 34 import org.apache.turbine.services.servlet.TurbineServlet; 35 36 import java.util.Enumeration ; 38 import javax.servlet.ServletContext ; 39 40 48 public class ServletContextPortlet extends AbstractPortlet 49 { 50 51 54 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(ServletContextPortlet.class.getName()); 55 56 public ConcreteElement getContent( RunData rundata ) { 57 58 Table table = new Table().setWidth("100%"); 59 60 try { 61 62 ServletContext context = TurbineServlet.getServletContext(); 63 64 table.addElement( new TR() 65 .addElement( new TH( "Key" ) ) 66 .addElement( new TH( "String Value" ) ) ); 67 68 table.addElement( new TR() 69 .addElement( new TD( "Server Info" ) ) 70 .addElement( new TD( context.getServerInfo() ) ) ); 71 72 table.addElement( new TR() 73 .addElement( new TH( "Attribute" ) ) 74 .addElement( new TH( "String Value" ) ) ); 75 76 Enumeration names = context.getAttributeNames(); 77 78 while ( names.hasMoreElements() ) { 79 String name = (String ) names.nextElement(); 80 table.addElement( new TR() 81 .addElement( new TD( name ) ) 82 .addElement( new TD( context.getAttribute( name ).toString() ) ) ); 83 } 84 85 table.addElement( new TR() 86 .addElement( new TH( "InitParameter" ) ) 87 .addElement( new TH( "String Value" ) ) ); 88 89 90 Enumeration ipnames = context.getInitParameterNames(); 91 while ( ipnames.hasMoreElements() ) { 92 String ipname = (String ) ipnames.nextElement(); 93 table.addElement( new TR() 94 .addElement( new TD( ipname ) ) 95 .addElement( new TD( context.getInitParameter( ipname ).toString() ) ) ); 96 } 97 98 } catch (Throwable t) { 99 logger.error("Throwable", t); 100 table.addElement( new TR() 101 .addElement( new TD( "Error" ) ) 102 .addElement( new TD( "Could not read servlet context" ) ) ); 103 } 104 105 return table; 106 } 107 108 112 public void init() throws PortletException { 113 114 this.setTitle("Java Servlet Context"); 115 this.setDescription("Attributes of your Servlet Context"); 116 117 } 118 119 public boolean getAllowEdit(RunData rundata) { 120 return false; 121 } 122 123 public boolean getAllowMaximize(RunData rundata) { 124 return false; 125 } 126 127 128 } 129 | Popular Tags |