001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.webadmin.main;
017:
018: import java.io.File;
019: import java.io.IOException;
020: import java.io.PrintWriter;
021: import java.util.Arrays;
022: import java.util.Enumeration;
023: import java.util.Properties;
024: import java.util.StringTokenizer;
025:
026: import org.apache.openejb.webadmin.HttpRequest;
027: import org.apache.openejb.webadmin.HttpResponse;
028: import org.apache.openejb.webadmin.WebAdminBean;
029: import org.apache.openejb.webadmin.HttpHome;
030:
031: import javax.ejb.Stateless;
032: import javax.ejb.RemoteHome;
033:
034: /** Prints out a list of system properties for the server.
035: * @author <a href="mailto:tim_urberg@yahoo.com">Tim Urberg</a>
036: */
037: @Stateless(name="Webadmin/Properties")
038: @RemoteHome(HttpHome.class)
039: public class PropertiesBean extends WebAdminBean {
040:
041: /**
042: * Called after a new instance of PropertiesBean is created
043: */
044: public void ejbCreate() {
045: // The section variable must match
046: // the deployment id name
047: section = "Properties";
048: }
049:
050: /** called after all content is written to the browser
051: * @param request the http request
052: * @param response the http response
053: * @throws IOException if an exception is thrown
054: */
055: public void postProcess(HttpRequest request, HttpResponse response)
056: throws IOException {
057: }
058:
059: /** called before any content is written to the browser
060: * @param request the http request
061: * @param response the http response
062: * @throws IOException if an exception is thrown
063: */
064: public void preProcess(HttpRequest request, HttpResponse response)
065: throws IOException {
066: }
067:
068: /** writes the main body content to the broswer. This content is inside a <code><p></code> block
069: *
070: *
071: * @param body the output to write to
072: * @exception IOException if an exception is thrown
073: */
074: public void writeBody(PrintWriter body) throws IOException {
075: Properties p = System.getProperties();
076: Enumeration e = p.keys();
077: String[] propertyList = new String[p.size()];
078:
079: body
080: .println("<table border=\"0\" cellspacing=\"0\" cellpadding=\"2\">");
081: String currentProperty = null;
082: body
083: .println("<tr><th align=\"left\">Property Name</th><th align=\"left\">Property Value</th></tr>");
084: int j = 0;
085: while (e.hasMoreElements()) {
086: propertyList[j++] = (String) e.nextElement();
087: }
088: Arrays.sort(propertyList);
089:
090: String[] color = new String[] { "c9c5fe", "FFFFFF" };
091: for (int i = 0; i < propertyList.length; i++) {
092: String name = propertyList[i];
093: String value = System.getProperty(propertyList[i]);
094:
095: body.println("<tr bgcolor=\"#" + color[i % 2] + "\" >");
096: body.println("<td valign=\"top\">" + name + "</td>");
097: body.println("<td>");
098: if (propertyList[i].endsWith(".path")) {
099: StringTokenizer path = new StringTokenizer(value,
100: File.pathSeparator);
101: while (path.hasMoreTokens()) {
102: body.print(path.nextToken());
103: body.println("<br>");
104: }
105: } else {
106: body.println(value);
107: }
108: body.println(" </td>");
109: body.println("</tr>");
110: }
111: body.println("</table>");
112: }
113:
114: /** Write the TITLE of the HTML document. This is the part
115: * that goes into the <code><head><title>
116: * </title></head></code> tags
117: *
118: * @param body the output to write to
119: * @exception IOException of an exception is thrown
120: *
121: */
122: public void writeHtmlTitle(PrintWriter body) throws IOException {
123: body.print(HTML_TITLE);
124: }
125:
126: /** Write the title of the page. This is displayed right
127: * above the main block of content.
128: *
129: * @param body the output to write to
130: * @exception IOException if an exception is thrown
131: */
132: public void writePageTitle(PrintWriter body) throws IOException {
133: body.print("System Properties");
134: }
135:
136: /** Write the sub items for this bean in the left navigation bar of
137: * the page. This should look somthing like the one below:
138: *
139: * <code>
140: * <tr>
141: * <td valign="top" align="left">
142: * <a href="system?show=deployments"><span class="subMenuOff">
143: * Deployments
144: * </span>
145: * </a></td>
146: * </tr>
147: * </code>
148: *
149: * Alternately, the bean can use the method formatSubMenuItem(..) which
150: * will create HTML like the one above
151: *
152: * @param body the output to write to
153: * @exception IOException if an exception is thrown
154: *
155: */
156: public void writeSubMenuItems(PrintWriter body) throws IOException {
157: }
158: }
|