View Javadoc

1   /*
2    * Copyright 2000-2001,2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.jetspeed.portal.portlets.admin;
18  
19  //Element Construction Set
20  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  //Jetspeed stuff
27  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  //turbine
33  import org.apache.turbine.util.RunData;
34  import org.apache.turbine.services.servlet.TurbineServlet;
35  
36  //standard java stuff
37  import java.util.Enumeration;
38  import javax.servlet.ServletContext;
39  
40  /***
41  
42  @author <a href="mailto:tkuebler@cisco.com">Todd Kuebler</a>
43  @version $Id: ServletContextPortlet.java,v 1.4 2004/02/23 03:26:19 jford Exp $ 
44  
45  Based on the Java Runtime Portlet.
46  
47  */
48  public class ServletContextPortlet extends AbstractPortlet 
49  {
50  
51      /***
52       * Static initialization of the logger for this class
53       */    
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     /***
109     @author <a href="mailto:tkuebler@cisco.com">Todd Kuebler</a>
110     @version $Id: ServletContextPortlet.java,v 1.4 2004/02/23 03:26:19 jford Exp $ 
111     */
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 }