1 64 package com.jcorporate.expresso.core.controller; 65 66 import com.jcorporate.expresso.core.misc.ConfigManager; 67 import org.apache.commons.logging.Log; 68 import org.apache.commons.logging.LogFactory; 69 import org.apache.struts.action.Action; 70 import org.apache.struts.action.ActionForm; 71 import org.apache.struts.action.ActionMapping; 72 import org.apache.struts.action.ActionServlet; 73 import org.apache.struts.config.ActionConfig; 74 import org.apache.struts.config.ForwardConfig; 75 import org.apache.struts.config.ModuleConfig; 76 import org.apache.struts.tiles.TilesRequestProcessor; 77 import org.apache.struts.util.RequestUtils; 78 79 import javax.servlet.ServletException ; 80 import javax.servlet.http.HttpServletRequest ; 81 import javax.servlet.http.HttpServletResponse ; 82 import java.io.IOException ; 83 84 85 92 public class ExpressoRequestProcessor extends TilesRequestProcessor { 93 96 protected static Log log = LogFactory.getLog(ExpressoRequestProcessor.class); 97 98 101 public ExpressoRequestProcessor() { 102 super(); 103 } 104 105 114 public Action createAction(String className) { 115 Action instance = null; 116 117 synchronized (actions) { 118 instance = (Action) actions.get(className); 120 121 if (instance != null) { 122 if (log.isTraceEnabled()) { 123 log.trace(" Returning existing Action instance"); 124 } 125 126 return (instance); 127 } 128 129 if (log.isTraceEnabled()) { 131 log.trace(" Creating new Action instance"); 132 } 133 134 try { 135 instance = (Action) RequestUtils.applicationInstance(className); 136 instance.setServlet(this.servlet); 137 actions.put(className, instance); 138 } catch (Throwable t) { 139 log.error("Unable to create Action instance", t); 140 141 return (null); 142 } 143 } 144 145 return (instance); 146 } 147 148 155 public void init(ActionServlet servlet, ModuleConfig moduleConfig) 156 throws ServletException { 157 super.init(servlet, moduleConfig); 158 } 159 160 169 public boolean processPrepocess(HttpServletRequest request, 170 HttpServletResponse response) { 171 return true; 172 } 173 174 184 protected void processForwardConfig(HttpServletRequest request, 185 HttpServletResponse response, 186 ForwardConfig forward) 187 throws java.io.IOException , javax.servlet.ServletException { 188 189 String pageStyle = request.getParameter("pageStyle"); 191 if (pageStyle != null && pageStyle.length() > 0) { 192 ForwardConfig forwardConfig = DynamicForwarder.redeemConfig(pageStyle, request); 193 if (forwardConfig != null) { 194 if (log.isDebugEnabled()) { 195 log.debug("Redeemed page style: " + forwardConfig.getPath()); 196 } 197 forward = forwardConfig; 198 } else { 199 if (log.isDebugEnabled()) { 200 log.debug("Redeemed forward config, but forward config was null"); 201 } 202 } 203 } 204 205 206 super.processForwardConfig(request, response, forward); 207 } 208 209 225 protected String processPath(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException { 226 String path = super.processPath(httpServletRequest, httpServletResponse); 227 228 String controller = httpServletRequest.getParameter(Controller.CONTROLLER_PARAM_KEY); 229 if (controller != null) { 230 ActionConfig mapping = ConfigManager.getActionConfig(controller, 232 httpServletRequest.getParameter(Controller.STATE_PARAM_KEY)); 233 if (mapping != null) { 234 path = mapping.getPath(); 235 } 236 } 237 238 return path; 239 } 240 241 244 protected boolean processValidate(HttpServletRequest request, 245 HttpServletResponse response, 246 ActionForm form, 247 ActionMapping mapping) throws IOException , ServletException { 248 return true; 249 } 250 251 } 252 | Popular Tags |