1 2 3 27 28 29 package org.apache.catalina.util; 30 31 32 import com.sun.org.apache.commons.digester.Digester; 33 34 import org.xml.sax.Attributes ; 35 import org.xml.sax.helpers.AttributesImpl ; 36 import org.xml.sax.SAXException ; 37 38 import org.apache.tomcat.util.IntrospectionUtils; 39 40 47 public class CatalinaDigester extends Digester { 48 49 50 52 53 private static class SystemPropertySource 54 implements IntrospectionUtils.PropertySource { 55 public String getProperty( String key ) { 56 return System.getProperty(key); 57 } 58 } 59 60 protected static IntrospectionUtils.PropertySource source[] = 61 new IntrospectionUtils.PropertySource[] { new SystemPropertySource() }; 62 63 64 66 67 72 public void startElement(String namespaceURI, String localName, 73 String qName, Attributes list) 74 throws SAXException { 75 list = updateAttributes(list); 76 super.startElement(namespaceURI, localName, qName, list); 77 } 78 79 80 84 public void endElement(String namespaceURI, String localName, String qName) 85 throws SAXException { 86 bodyText = updateBodyText(bodyText); 87 super.endElement(namespaceURI, localName, qName); 88 } 89 90 91 96 private Attributes updateAttributes(Attributes list) { 97 98 if (list.getLength() == 0) { 99 return list; 100 } 101 102 AttributesImpl newAttrs = new AttributesImpl (list); 103 int nAttributes = newAttrs.getLength(); 104 for (int i = 0; i < nAttributes; ++i) { 105 String value = newAttrs.getValue(i); 106 try { 107 String newValue = 108 IntrospectionUtils.replaceProperties(value, null, source); 109 if (value != newValue) { 110 newAttrs.setValue(i, newValue); 111 } 112 } 113 catch (Exception e) { 114 } 116 } 117 118 return newAttrs; 119 120 } 121 122 123 128 private StringBuffer updateBodyText(StringBuffer bodyText) { 129 String in = bodyText.toString(); 130 String out; 131 try { 132 out = IntrospectionUtils.replaceProperties(in, null, source); 133 } catch(Exception e) { 134 return bodyText; } 136 137 if (out == in) { 138 return bodyText; 141 } else { 142 return new StringBuffer (out); 143 } 144 } 145 146 147 } 148 149 | Popular Tags |