1 16 package org.apache.commons.chain.config; 17 18 19 import java.net.URL ; 20 import org.apache.commons.chain.Catalog; 21 import org.apache.commons.digester.Digester; 22 import org.apache.commons.digester.RuleSet; 23 import org.xml.sax.InputSource ; 24 25 26 38 public class ConfigParser { 39 40 41 43 44 47 private Digester digester = null; 48 49 50 54 private RuleSet ruleSet = null; 55 56 57 60 private boolean useContextClassLoader = true; 61 62 63 65 66 70 public Digester getDigester() { 71 72 if (digester == null) { 73 digester = new Digester(); 74 RuleSet ruleSet = getRuleSet(); 75 digester.setNamespaceAware(ruleSet.getNamespaceURI() != null); 76 digester.setUseContextClassLoader(getUseContextClassLoader()); 77 digester.setValidating(false); 78 digester.addRuleSet(ruleSet); 79 } 80 return (digester); 81 82 } 83 84 85 89 public RuleSet getRuleSet() { 90 91 if (ruleSet == null) { 92 ruleSet = new ConfigRuleSet(); 93 } 94 return (ruleSet); 95 96 } 97 98 99 105 public void setRuleSet(RuleSet ruleSet) { 106 107 this.digester = null; 108 this.ruleSet = ruleSet; 109 110 } 111 112 113 118 public boolean getUseContextClassLoader() { 119 120 return (this.useContextClassLoader); 121 122 } 123 124 125 130 public void setUseContextClassLoader(boolean useContextClassLoader) { 131 132 this.useContextClassLoader = useContextClassLoader; 133 134 } 135 136 137 139 140 156 public void parse(Catalog catalog, URL url) throws Exception { 157 158 Digester digester = getDigester(); 160 digester.clear(); 161 digester.push(catalog); 162 163 InputSource source = new InputSource (url.toExternalForm()); 165 source.setByteStream(url.openStream()); 166 167 digester.parse(source); 169 170 } 171 172 173 184 public void parse(URL url) throws Exception { 185 186 Digester digester = getDigester(); 188 digester.clear(); 189 190 InputSource source = new InputSource (url.toExternalForm()); 192 source.setByteStream(url.openStream()); 193 194 digester.parse(source); 196 197 } 198 199 200 } 201 | Popular Tags |