1 15 package org.apache.tapestry.html; 16 17 import java.util.Collections ; 18 import java.util.Iterator ; 19 import java.util.List ; 20 import java.util.Properties ; 21 import java.util.StringTokenizer ; 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 36 public abstract class RequestDisplay extends BaseComponent 37 { 38 39 public void renderSystemProperties(IMarkupWriter writer) 40 { 41 42 Properties p = System.getProperties(); 43 44 String 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 i = WebUtils.toSortedList(p.keys()).iterator(); 56 57 while (i.hasNext()) 58 { 59 String key = (String ) i.next(); 60 String 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 key, String value, 69 String pathSeparator) 70 { 71 String [] 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 [] split(String key, String value, String pathSeparator) 90 { 91 if (!key.endsWith(".path")) 92 return new String [] 93 { value }; 94 95 StringTokenizer tokenizer = new StringTokenizer (value, pathSeparator); 96 List values = Collections.list(tokenizer); 97 98 return (String []) values.toArray(new String [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 |