1 64 65 package com.jcorporate.expresso.core.controller; 66 67 import com.jcorporate.expresso.core.misc.ConfigManager; 68 import org.apache.commons.logging.Log; 69 import org.apache.commons.logging.LogFactory; 70 import org.apache.struts.action.ActionServlet; 71 import org.apache.struts.action.RequestProcessor; 72 import org.apache.struts.config.ControllerConfig; 73 import org.apache.struts.config.ModuleConfig; 74 import org.apache.struts.tiles.TilesPlugin; 75 import org.apache.struts.util.RequestUtils; 76 77 import javax.servlet.ServletException ; 78 79 80 96 public class ExpressoPlugin extends TilesPlugin { 97 98 99 102 protected static Log log = LogFactory.getLog(ExpressoPlugin.class); 103 104 105 108 public ExpressoPlugin() { 109 super(); 110 } 111 112 113 121 public void initModuleConfiguration(ActionServlet servlet, ModuleConfig moduleConfig) { 122 ConfigManager.storeModuleActionConfig(moduleConfig); 123 } 124 125 136 public void init(ActionServlet servlet, ModuleConfig moduleConfig) throws ServletException { 137 super.init(servlet, moduleConfig); 139 log.info("Expresso Plugin loaded for module`" + moduleConfig.getPrefix() + "'."); 140 initModuleConfiguration(servlet, moduleConfig); 141 } 142 143 146 public void destroy() { 147 log.info("Expresso Plugin unloading for module."); 148 ConfigManager.setControllerFactory(null); 149 150 super.destroy(); } 152 153 171 protected void initRequestProcessorClass(ModuleConfig config) throws ServletException { 172 System.out.println("initRequestProcessorClass(" + config + ")"); 173 174 String expressoProcessorClassname = ExpressoRequestProcessor.class.getName(); 175 ControllerConfig ctrlConfig = config.getControllerConfig(); 176 String configProcessorClassname = ctrlConfig.getProcessorClass(); 177 178 Class configProcessorClass; 180 try { 181 configProcessorClass = RequestUtils.applicationClass(configProcessorClassname); 182 } catch (java.lang.ClassNotFoundException ex) { 183 log.fatal("Can't set ExpressoRequestProcessor: bad class name '" 184 + configProcessorClassname 185 + "'."); 186 throw new ServletException (ex); 187 } 188 189 if (configProcessorClassname.equals(RequestProcessor.class.getName()) || 192 configProcessorClassname.endsWith(expressoProcessorClassname)) { 193 ctrlConfig.setProcessorClass(expressoProcessorClassname); 194 return; 195 } 196 197 Class expressoProcessorClass = ExpressoRequestProcessor.class; 199 if (!expressoProcessorClass.isAssignableFrom(configProcessorClass)) { 200 String msg = "ExpressoPlugin : Specified RequestProcessor not compatible with ExpressoRequestProcessor"; 202 if (log.isFatalEnabled()) { 203 log.fatal(msg); 204 } 205 throw new ServletException (msg); 206 } 207 } 208 209 } 210 | Popular Tags |