KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > html > RequestDisplay


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.html;
16
17 import java.util.Collections JavaDoc;
18 import java.util.Iterator JavaDoc;
19 import java.util.List JavaDoc;
20 import java.util.Properties JavaDoc;
21 import java.util.StringTokenizer JavaDoc;
22
23 import org.apache.tapestry.BaseComponent;
24 import org.apache.tapestry.IMarkupWriter;
25 import org.apache.tapestry.IRender;
26 import org.apache.tapestry.IRequestCycle;
27 import org.apache.tapestry.web.WebUtils;
28
29 /**
30  * Supports the {@link org.apache.tapestry.pages.Exception} page by displaying the request,
31  * session, servlet context and servlet object for the current request.
32  *
33  * @author Howard M. Lewis Ship
34  * @since 4.0
35  */

36 public abstract class RequestDisplay extends BaseComponent
37 {
38
39     public void renderSystemProperties(IMarkupWriter writer)
40     {
41
42         Properties JavaDoc p = System.getProperties();
43
44         String JavaDoc pathSeparator = p.getProperty("path.separator");
45
46         writer.begin("div");
47         writer.attribute("class", "described-object-title");
48         writer.print("JVM System Properties");
49         writer.end();
50         writer.println();
51
52         writer.begin("table");
53         writer.attribute("class", "described-object");
54
55         Iterator JavaDoc i = WebUtils.toSortedList(p.keys()).iterator();
56
57         while (i.hasNext())
58         {
59             String JavaDoc key = (String JavaDoc) i.next();
60             String JavaDoc value = p.getProperty(key);
61
62             renderKeyAndValue(writer, key, value, pathSeparator);
63         }
64
65         writer.end();
66     }
67
68     private void renderKeyAndValue(IMarkupWriter writer, String JavaDoc key, String JavaDoc value,
69             String JavaDoc pathSeparator)
70     {
71         String JavaDoc[] values = split(key, value, pathSeparator);
72
73         for (int i = 0; i < values.length; i++)
74         {
75             writer.begin("tr");
76             writer.begin("th");
77
78             if (i == 0)
79                 writer.print(key);
80
81             writer.end();
82             writer.begin("td");
83             writer.print(values[i]);
84             writer.end("tr");
85             writer.println();
86         }
87     }
88
89     private String JavaDoc[] split(String JavaDoc key, String JavaDoc value, String JavaDoc pathSeparator)
90     {
91         if (!key.endsWith(".path"))
92             return new String JavaDoc[]
93             { value };
94
95         StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(value, pathSeparator);
96         List JavaDoc values = Collections.list(tokenizer);
97
98         return (String JavaDoc[]) values.toArray(new String JavaDoc[values.size()]);
99     }
100
101     public IRender getSystemPropertiesRenderer()
102     {
103         return new IRender()
104         {
105             public void render(IMarkupWriter writer, IRequestCycle cycle)
106             {
107                 renderSystemProperties(writer);
108             }
109         };
110     }
111 }
Popular Tags