KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openejb > webadmin > main > PropertiesBean


1 /**
2  * Redistribution and use of this software and associated documentation
3  * ("Software"), with or without modification, are permitted provided
4  * that the following conditions are met:
5  *
6  * 1. Redistributions of source code must retain copyright
7  * statements and notices. Redistributions must also contain a
8  * copy of this document.
9  *
10  * 2. Redistributions in binary form must reproduce the
11  * above copyright notice, this list of conditions and the
12  * following disclaimer in the documentation and/or other
13  * materials provided with the distribution.
14  *
15  * 3. The name "OpenEJB" must not be used to endorse or promote
16  * products derived from this Software without prior written
17  * permission of The OpenEJB Group. For written permission,
18  * please contact dev@openejb.org.
19  *
20  * 4. Products derived from this Software may not be called "OpenEJB"
21  * nor may "OpenEJB" appear in their names without prior written
22  * permission of The OpenEJB Group. OpenEJB is a registered
23  * trademark of The OpenEJB Group.
24  *
25  * 5. Due credit should be given to the OpenEJB Project
26  * (http://www.openejb.org/).
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE OPENEJB GROUP AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32  * THE OPENEJB GROUP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  *
41  * Copyright 2001 (C) The OpenEJB Group. All Rights Reserved.
42  *
43  * $Id: PropertiesBean.java 1912 2005-06-16 22:29:56Z jlaskowski $
44  */

45 package org.openejb.webadmin.main;
46
47 import java.io.File JavaDoc;
48 import java.io.IOException JavaDoc;
49 import java.io.PrintWriter JavaDoc;
50 import java.util.Arrays JavaDoc;
51 import java.util.Enumeration JavaDoc;
52 import java.util.Properties JavaDoc;
53 import java.util.StringTokenizer JavaDoc;
54
55 import org.openejb.webadmin.HttpRequest;
56 import org.openejb.webadmin.HttpResponse;
57 import org.openejb.webadmin.WebAdminBean;
58
59 /** Prints out a list of system properties for the server.
60  * @author <a HREF="mailto:tim_urberg@yahoo.com">Tim Urberg</a>
61  */

62 public class PropertiesBean extends WebAdminBean {
63
64     /**
65      * Called after a new instance of PropertiesBean is created
66      */

67     public void ejbCreate() {
68         // The section variable must match
69
// the deployment id name
70
section = "Properties";
71     }
72
73     /** called after all content is written to the browser
74      * @param request the http request
75      * @param response the http response
76      * @throws IOException if an exception is thrown
77      */

78     public void postProcess(HttpRequest request, HttpResponse response) throws IOException JavaDoc {
79     }
80
81     /** called before any content is written to the browser
82      * @param request the http request
83      * @param response the http response
84      * @throws IOException if an exception is thrown
85      */

86     public void preProcess(HttpRequest request, HttpResponse response) throws IOException JavaDoc {
87     }
88
89     /** writes the main body content to the broswer. This content is inside a <code>&lt;p&gt;</code> block
90      *
91      *
92      * @param body the output to write to
93      * @exception IOException if an exception is thrown
94      */

95     public void writeBody(PrintWriter JavaDoc body) throws IOException JavaDoc {
96         Properties JavaDoc p = System.getProperties();
97         Enumeration JavaDoc e = p.keys();
98         String JavaDoc[] propertyList = new String JavaDoc[p.size()];
99
100         body.println("<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\">");
101         String JavaDoc currentProperty = null;
102         body.println("<tr><th align=\"left\">Property Name</th><th align=\"left\">Property Value</th></tr>");
103         int j = 0;
104         while ( e.hasMoreElements() ) {
105             propertyList[j++] = (String JavaDoc) e.nextElement();
106         }
107         Arrays.sort(propertyList);
108
109         String JavaDoc[] color = new String JavaDoc[]{"c9c5fe", "FFFFFF"};
110         for ( int i=0; i<propertyList.length; i++ ) {
111             String JavaDoc name = propertyList[i];
112             String JavaDoc value = System.getProperty(propertyList[i]);
113
114             body.println("<tr bgcolor=\"#"+ color[i%2] +"\" >");
115             body.println("<td valign=\"top\">" + name + "</td>");
116             body.println("<td>");
117             if (propertyList[i].endsWith(".path")) {
118                 StringTokenizer JavaDoc path = new StringTokenizer JavaDoc(value,File.pathSeparator);
119                 while (path.hasMoreTokens()) {
120                     body.print(path.nextToken());
121                     body.println("<br>");
122                 }
123             } else {
124                 body.println(value);
125             }
126             body.println("&nbsp;</td>");
127             body.println("</tr>");
128         }
129         body.println("</table>");
130     }
131
132     /** Write the TITLE of the HTML document. This is the part
133      * that goes into the <code>&lt;head&gt;&lt;title&gt;
134      * &lt;/title&gt;&lt;/head&gt;</code> tags
135      *
136      * @param body the output to write to
137      * @exception IOException of an exception is thrown
138      *
139      */

140     public void writeHtmlTitle(PrintWriter JavaDoc body) throws IOException JavaDoc {
141         body.print(HTML_TITLE);
142     }
143
144     /** Write the title of the page. This is displayed right
145      * above the main block of content.
146      *
147      * @param body the output to write to
148      * @exception IOException if an exception is thrown
149      */

150     public void writePageTitle(PrintWriter JavaDoc body) throws IOException JavaDoc {
151         body.print("System Properties");
152     }
153
154     /** Write the sub items for this bean in the left navigation bar of
155      * the page. This should look somthing like the one below:
156      *
157      * <code>
158      * &lt;tr&gt;
159      * &lt;td valign="top" align="left"&gt;
160      * &lt;a HREF="system?show=deployments"&gt;&lt;span class="subMenuOff"&gt;
161      * &nbsp;&nbsp;&nbsp;Deployments
162      * &lt;/span&gt;
163      * &lt;/a&gt;&lt;/td&gt;
164      * &lt;/tr&gt;
165      * </code>
166      *
167      * Alternately, the bean can use the method formatSubMenuItem(..) which
168      * will create HTML like the one above
169      *
170      * @param body the output to write to
171      * @exception IOException if an exception is thrown
172      *
173      */

174     public void writeSubMenuItems(PrintWriter JavaDoc body) throws IOException JavaDoc {
175     }
176 }
177
Popular Tags