1 17 18 19 package org.apache.commons.digester.xmlrules; 20 21 22 import java.io.IOException ; 23 import java.io.InputStream ; 24 import java.io.Reader ; 25 import java.net.URL ; 26 27 import org.apache.commons.digester.Digester; 28 import org.apache.commons.digester.RuleSet; 29 30 import org.xml.sax.SAXException ; 31 import org.xml.sax.InputSource ; 32 33 34 40 41 public class DigesterLoader { 42 43 48 public static Digester createDigester(InputSource rulesSource) { 49 RuleSet ruleSet = new FromXmlRuleSet(rulesSource); 50 Digester digester = new Digester(); 51 digester.addRuleSet(ruleSet); 52 return digester; 53 } 54 55 64 public static Digester createDigester(InputSource rulesSource, Digester rulesDigester) { 65 RuleSet ruleSet = new FromXmlRuleSet(rulesSource, rulesDigester); 66 Digester digester = new Digester(); 67 digester.addRuleSet(ruleSet); 68 return digester; 69 } 70 71 76 public static Digester createDigester(URL rulesXml) { 77 RuleSet ruleSet = new FromXmlRuleSet(rulesXml); 78 Digester digester = new Digester(); 79 digester.addRuleSet(ruleSet); 80 return digester; 81 } 82 83 94 public static Digester createDigester(URL rulesXml, Digester rulesDigester) { 95 RuleSet ruleSet = new FromXmlRuleSet(rulesXml, rulesDigester); 96 Digester digester = new Digester(); 97 digester.addRuleSet(ruleSet); 98 return digester; 99 } 100 101 111 public static Object load(URL digesterRules, ClassLoader classLoader, 112 URL fileURL) throws IOException , SAXException , DigesterLoadingException { 113 return load(digesterRules, classLoader, fileURL.openStream()); 114 } 115 116 126 public static Object load(URL digesterRules, ClassLoader classLoader, 127 InputStream input) throws IOException , SAXException , DigesterLoadingException { 128 Digester digester = createDigester(digesterRules); 129 digester.setClassLoader(classLoader); 130 try { 131 return digester.parse(input); 132 } catch (XmlLoadException ex) { 133 throw new DigesterLoadingException(ex.getMessage(), ex); 137 } 138 } 139 140 150 public static Object load( 151 URL digesterRules, 152 ClassLoader classLoader, 153 Reader reader) 154 throws 155 IOException , 156 SAXException , 157 DigesterLoadingException { 158 Digester digester = createDigester(digesterRules); 159 digester.setClassLoader(classLoader); 160 try { 161 return digester.parse(reader); 162 } catch (XmlLoadException ex) { 163 throw new DigesterLoadingException(ex.getMessage(), ex); 167 } 168 } 169 170 171 184 public static Object load(URL digesterRules, ClassLoader classLoader, 185 URL fileURL, Object rootObject) throws IOException , SAXException , 186 DigesterLoadingException { 187 return load(digesterRules, classLoader, fileURL.openStream(), rootObject); 188 } 189 190 202 public static Object load(URL digesterRules, ClassLoader classLoader, 203 InputStream input, Object rootObject) throws IOException , SAXException , 204 DigesterLoadingException { 205 Digester digester = createDigester(digesterRules); 206 digester.setClassLoader(classLoader); 207 digester.push(rootObject); 208 try { 209 return digester.parse(input); 210 } catch (XmlLoadException ex) { 211 throw new DigesterLoadingException(ex.getMessage(), ex); 215 } 216 } 217 218 230 public static Object load( 231 URL digesterRules, 232 ClassLoader classLoader, 233 Reader input, 234 Object rootObject) 235 throws 236 IOException , 237 SAXException , 238 DigesterLoadingException { 239 Digester digester = createDigester(digesterRules); 240 digester.setClassLoader(classLoader); 241 digester.push(rootObject); 242 try { 243 return digester.parse(input); 244 } catch (XmlLoadException ex) { 245 throw new DigesterLoadingException(ex.getMessage(), ex); 249 } 250 } 251 } 252 | Popular Tags |