1 16 17 package org.apache.struts.chain.legacy; 18 19 20 import java.net.URL ; 21 22 import javax.servlet.ServletException ; 23 24 import org.apache.struts.action.ActionServlet; 25 import org.apache.struts.action.PlugIn; 26 import org.apache.struts.chain.Constants; 27 import org.apache.struts.config.ModuleConfig; 28 29 import org.apache.commons.chain.Catalog; 30 import org.apache.commons.chain.CatalogFactory; 31 import org.apache.commons.chain.config.ConfigParser; 32 import org.apache.commons.chain.impl.CatalogBase; 33 import org.apache.commons.logging.Log; 34 import org.apache.commons.logging.LogFactory; 35 36 37 38 52 53 public class CatalogConfiguratorPlugIn implements PlugIn { 54 55 56 58 59 private static Log log = LogFactory.getLog(CatalogConfiguratorPlugIn.class); 60 private String path = null; 61 private String resource = null; 62 63 64 66 67 70 public String getPath() { 71 return (this.path); 72 } 73 74 75 80 public void setPath(String path) { 81 this.path = path; 82 } 83 84 85 88 public String getResource() { 89 return (this.resource); 90 } 91 92 93 98 public void setResource(String resource) { 99 this.resource = resource; 100 } 101 102 103 105 106 109 public void destroy() { 110 111 CatalogFactory.clear(); 112 113 } 114 115 116 122 public void init(ActionServlet servlet, ModuleConfig config) 123 throws ServletException { 124 125 try { 127 ConfigParser parser = new ConfigParser(); 128 URL configResource = null; 129 if (path != null) { 130 log.info("Loading context relative resources from '" + 131 path + "'"); 132 configResource = 133 servlet.getServletContext().getResource(path); 134 } else if (resource != null) { 135 log.info("Loading classloader resources from '" + 136 resource + "'"); 137 ClassLoader loader = 138 Thread.currentThread().getContextClassLoader(); 139 if (loader == null) { 140 loader = this.getClass().getClassLoader(); 141 } 142 configResource = loader.getResource(resource); 143 } 144 parser.parse(configResource); 145 } catch (Exception e) { 146 log.error("Exception loading resources", e); 147 throw new ServletException (e); 148 } 149 150 } 151 152 153 154 } 155 | Popular Tags |