1 17 18 package org.apache.commons.digester.plugins.strategies; 19 20 import java.util.Properties ; 21 import java.io.InputStream ; 22 import java.io.FileInputStream ; 23 import java.io.IOException ; 24 25 import org.apache.commons.digester.Digester; 26 import org.apache.commons.digester.plugins.RuleFinder; 27 import org.apache.commons.digester.plugins.RuleLoader; 28 import org.apache.commons.digester.plugins.PluginException; 29 30 38 39 public class FinderFromFile extends RuleFinder { 40 44 public static String DFLT_FILENAME_ATTR = "file"; 45 46 47 private String filenameAttr; 48 49 50 public FinderFromFile() { 51 this(DFLT_FILENAME_ATTR); 52 } 53 54 55 public FinderFromFile(String filenameAttr) { 56 this.filenameAttr = filenameAttr; 57 } 58 59 69 public RuleLoader findLoader(Digester d, Class pluginClass, Properties p) 70 throws PluginException { 71 72 String rulesFileName = p.getProperty(filenameAttr); 73 if (rulesFileName == null) { 74 return null; 77 } 78 79 InputStream is = null; 80 try { 81 is = new FileInputStream (rulesFileName); 82 } catch(IOException ioe) { 83 throw new PluginException( 84 "Unable to process file [" + rulesFileName + "]", ioe); 85 } 86 87 try { 88 RuleLoader loader = new LoaderFromStream(is); 89 return loader; 90 } catch(Exception e) { 91 throw new PluginException( 92 "Unable to load xmlrules from file [" + 93 rulesFileName + "]", e); 94 } finally { 95 try { 96 is.close(); 97 } catch(java.io.IOException ioe) { 98 throw new PluginException( 99 "Unable to close stream for file [" + 100 rulesFileName + "]", ioe); 101 } 102 } 103 } 104 } 105 106 | Popular Tags |