1 17 18 package org.apache.commons.digester.plugins.strategies; 19 20 import java.io.InputStream ; 21 import java.io.ByteArrayInputStream ; 22 import java.io.ByteArrayOutputStream ; 23 import java.io.IOException ; 24 import org.xml.sax.InputSource ; 25 26 import org.apache.commons.digester.Digester; 27 import org.apache.commons.digester.plugins.RuleLoader; 28 import org.apache.commons.digester.plugins.PluginException; 29 import org.apache.commons.digester.xmlrules.FromXmlRuleSet; 30 import org.apache.commons.logging.Log; 31 32 39 40 public class LoaderFromStream extends RuleLoader { 41 42 private byte[] input; 43 private FromXmlRuleSet ruleSet; 44 45 46 public LoaderFromStream(InputStream s) throws Exception { 47 load(s); 48 } 49 50 57 private void load(InputStream s) throws IOException { 58 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 59 byte[] buf = new byte[256]; 60 for(;;) { 61 int i = s.read(buf); 62 if (i == -1) 63 break; 64 baos.write(buf, 0, i); 65 } 66 input = baos.toByteArray(); 67 } 68 69 73 public void addRules(Digester d, String path) throws PluginException { 74 Log log = d.getLogger(); 75 boolean debug = log.isDebugEnabled(); 76 if (debug) { 77 log.debug( 78 "LoaderFromStream: loading rules for plugin at path [" 79 + path + "]"); 80 } 81 82 88 InputSource source = new InputSource (new ByteArrayInputStream (input)); 89 FromXmlRuleSet ruleSet = new FromXmlRuleSet(source); 90 ruleSet.addRuleInstances(d, path); 91 } 92 } 93 94 | Popular Tags |