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.TR;
23  import org.apache.ecs.ConcreteElement;
24  
25  //Jetspeed stuff
26  import org.apache.jetspeed.portal.portlets.AbstractPortlet;
27  import org.apache.jetspeed.portal.PortletException;
28  import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
29  import org.apache.jetspeed.services.logging.JetspeedLogger;
30  
31  //turbine
32  import org.apache.turbine.util.RunData;
33  
34  //standard java stuff
35  import java.util.Enumeration;
36  import java.util.Properties;
37  
38  /***
39  Handles enumerating Portlets that are also applications
40  
41  @author <a href="mailto:burton@apache.org">Kevin A. Burton</a>
42  @version $Id: JavaRuntimePortlet.java,v 1.18 2004/02/23 03:26:19 jford Exp $ 
43  */
44  public class JavaRuntimePortlet extends AbstractPortlet 
45  {
46  
47      /***
48       * Static initialization of the logger for this class
49       */    
50      private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(JavaRuntimePortlet.class.getName());
51      
52      public ConcreteElement getContent( RunData rundata ) {
53  
54          Table table = new Table().setWidth("100%");
55  
56          try {
57              //get Runtime status
58              Runtime jvm = Runtime.getRuntime();
59          
60              table.addElement( new TR()
61                  .addElement( new TD("Free Memory (in bytes)") )
62                  .addElement( new TD( Long.toString( jvm.freeMemory() ) ) ) );
63          
64              table.addElement( new TR()
65                  .addElement( new TD("Total Memory (in bytes)") )
66                  .addElement( new TD( Long.toString( jvm.totalMemory() ) ) ) );
67  
68              //get the system properties (It can throw a SecurityException)
69              Properties props = System.getProperties();
70          
71              Enumeration enum = props.propertyNames();
72              while( enum.hasMoreElements() ) {
73                  Object key = enum.nextElement();
74                  if ( ! ( key instanceof String ) ) {
75                      continue;
76                  }
77  
78                  Object value = props.getProperty( key.toString() );
79                  table.addElement( new TR()
80                      .addElement( new TD( key.toString() ) )
81                      .addElement( new TD( value.toString() ) ) );
82              
83              }
84          } catch (Throwable t) {
85              logger.error("Throwable",  t);
86              table.addElement( new TR()
87                  .addElement( new TD( "Error" ) )
88                  .addElement( new TD( "Could not read system properties" ) ) );
89          }
90  
91          return table;
92      }
93      
94      /***
95      @author <a href="mailto:burton@apache.org">Kevin A. Burton</a>
96      @version $Id: JavaRuntimePortlet.java,v 1.18 2004/02/23 03:26:19 jford Exp $ 
97      */
98      public void init() throws PortletException {
99  
100         this.setTitle("Java Runtime");
101         this.setDescription("Information about your Java Runtime");
102 
103     }
104 
105     public boolean getAllowEdit(RunData rundata) {
106         return false;
107     }
108 
109     public boolean getAllowMaximize(RunData rundata) {
110         return false;
111     }
112     
113     
114 }