1 4 5 9 10 package org.openlaszlo.test.xmlrpc; 11 12 import java.io.IOException; 13 import java.io.InputStream; 14 import java.io.OutputStream; 15 import java.net.MalformedURLException; 16 import javax.servlet.http.HttpServletRequest; 17 import javax.servlet.http.HttpServletResponse; 18 import java.util.Date; 19 import java.util.Enumeration; 20 import java.util.HashMap; 21 import java.util.Properties; 22 import org.xml.sax.helpers.AttributesImpl; 23 24 import org.openlaszlo.xml.DataEncoder; 25 26 27 public class SystemProperties 28 { 29 public static DataEncoder getProperties() { 30 DataEncoder encoder = new DataEncoder(); 31 encoder.startDocument(); 32 33 encoder.startElement("system", new AttributesImpl()); 34 35 Properties prop = System.getProperties(); 36 Enumeration enum = prop.propertyNames(); 37 while (enum.hasMoreElements()) { 38 String key = (String)enum.nextElement(); 39 String val = xmlEscape(prop.getProperty(key)); 40 AttributesImpl attrs = new AttributesImpl(); 41 attrs.addAttribute("", "key", "", "CDATA", key); 42 attrs.addAttribute("", "val", "", "CDATA", val); 43 44 encoder.startElement("property", attrs); 45 encoder.endElement(); 46 } 47 48 encoder.endElement(); 49 encoder.endDocument(); 50 return encoder; 51 } 52 53 public static DataEncoder getProperty(String key) { 54 DataEncoder encoder = new DataEncoder(); 55 encoder.startDocument(); 56 57 encoder.startElement("system", new AttributesImpl()); 58 59 String val = xmlEscape(System.getProperty(key)); 60 AttributesImpl attrs = new AttributesImpl(); 61 attrs.addAttribute("", "key", "", "CDATA", key); 62 attrs.addAttribute("", "val", "", "CDATA", val); 63 encoder.startElement("property", attrs); 64 encoder.endElement(); 65 66 encoder.endElement(); 67 68 encoder.endDocument(); 69 return encoder; 70 } 71 72 79 static String xmlEscape(String s) { 80 if (s == null) return null; 81 StringBuffer sb = new StringBuffer(); 82 for(int i=0; i<s.length(); i++) { 83 char c = s.charAt(i); 84 if (c == '<') { 85 sb.append("<"); 86 } else if (c == '>') { 87 sb.append(">"); 88 } else if (c == '\'') { 89 sb.append("'"); 90 } else if (c == '&') { 91 sb.append("&"); 92 } else if (c == '"') { 93 sb.append("""); 94 } else { 95 sb.append(c); 96 } 97 } 98 return sb.toString(); 99 } 100 } 101 102 | Popular Tags |