List of usage examples for org.apache.commons.chain.web WebContext get
public Object get(Object key)
Override the default Map
behavior to return the value of a local property if the specified key matches a local property name.
From source file:org.apache.struts.chain.AbstractPerformInclude.java
/** * <p>Perform an include based on the specified * include uri (if any).</p>//from www .j a va2s .c om * * @param context The <code>Context</code> for the current request * * @return <code>true</code> so that processing completes */ public boolean execute(Context context) throws Exception { // Retrieve module config instance WebContext wcontext = (WebContext) context; ModuleConfig moduleConfig = (ModuleConfig) wcontext.get(getModuleConfigKey()); // Is there an include to be performed? String include = (String) context.get(getIncludeKey()); if (include == null) { return (false); } // Determine the currect uri String uri = moduleConfig.getPrefix() + include; // Perform the appropriate processing on this include uri perform(context, uri); return (true); }
From source file:org.apache.struts.chain.AbstractRequestNoCache.java
/** * <p>Check to see if the controller is configured to prevent caching, * and if so, request no cache flags to be set.</p> * * @param context The <code>Context</code> for the current request * * @return <code>false</code> so that processing continues *//*from w w w. j a va 2 s.com*/ public boolean execute(Context context) throws Exception { // Retrieve the ModuleConfig instance WebContext wcontext = (WebContext) context; ModuleConfig moduleConfig = (ModuleConfig) wcontext.get(getModuleConfigKey()); // If the module is configured for no caching, request no caching if (moduleConfig.getControllerConfig().getNocache()) { requestNoCache(context); } return (false); }
From source file:org.apache.struts.chain.AbstractSelectAction.java
/** * <p>Cache the <code>ActionConfig</code> instance for the * action to be used for processing this request.</p> * * @param context The <code>Context</code> for the current request * * @exception IllegalArgumentException if no valid * action can be identified for this request * * @return <code>false</code> so that processing continues *///from w w w . j a v a 2 s. com public boolean execute(Context context) throws Exception { // Identify the matching path for this request String path = getPath(context); // Cache the corresponding ActonConfig instance WebContext wcontext = (WebContext) context; ModuleConfig moduleConfig = (ModuleConfig) wcontext.get(getModuleConfigKey()); ActionConfig actionConfig = moduleConfig.findActionConfig(path); if (actionConfig == null) { // Locate the mapping for unknown paths (if any) ActionConfig configs[] = moduleConfig.findActionConfigs(); for (int i = 0; i < configs.length; i++) { if (configs[i].getUnknown()) { actionConfig = configs[i]; break; } } } if (actionConfig == null) { throw new IllegalArgumentException("No action config for '" + path + "'"); } wcontext.put(getActionConfigKey(), actionConfig); wcontext.getRequestScope().put(Globals.MAPPING_KEY, actionConfig); return (false); }
From source file:org.apache.struts.chain.AbstractSelectModule.java
/** * <p>Cache the <code>ModuleConfig</code> and <code>MessageResources</code> * instances for the sub-application module to be used for processing * this request.</p>// w w w . j a va 2 s . c o m * * @param context The <code>Context</code> for the current request * * @exception IllegalArgumentException if no valid * ModuleConfig or MessageResources can be identified for this request * * @return <code>false</code> so that processing continues */ public boolean execute(Context context) throws Exception { // Identify the module prefix for the current module String prefix = getPrefix(context); // Cache the corresponding ModuleConfig and MessageResources instances WebContext wcontext = (WebContext) context; ModuleConfig moduleConfig = (ModuleConfig) wcontext.getApplicationScope().get(Globals.MODULE_KEY + prefix); if (moduleConfig == null) { throw new IllegalArgumentException("No module config for prefix '" + prefix + "'"); } wcontext.put(getModuleConfigKey(), moduleConfig); wcontext.getRequestScope().put(Globals.MODULE_KEY, moduleConfig); MessageResources messageResources = (MessageResources) wcontext.getApplicationScope() .get(Globals.MESSAGES_KEY + prefix); if (messageResources != null) { wcontext.put(getMessageResourcesKey(), messageResources); wcontext.getRequestScope().put(Globals.MESSAGES_KEY, messageResources); } return (false); }
From source file:org.apache.struts.chain.AbstractSetContentType.java
/** * <p>Check to see if the content type is set, and if so, set it for this * response.</p>/*from w ww .j a va 2 s . c om*/ * * @param context The <code>Context</code> for the current request * * @return <code>false</code> so that processing continues */ public boolean execute(Context context) throws Exception { // Retrieve the ModuleConfig instance WebContext wcontext = (WebContext) context; ModuleConfig moduleConfig = (ModuleConfig) wcontext.get(getModuleConfigKey()); // If the content type is configured, set it for the response String contentType = moduleConfig.getControllerConfig().getContentType(); if (contentType != null) { setContentType(context, contentType); } return (false); }
From source file:org.apache.struts.chain.CreateAction.java
/** * <p>Create (if necessary) and return a <code>Map</code> containing the * <code>Action</code> instances for the current application module.</p> * * @param context The context for this request * @param moduleConfig The <code>ModuleConfig</code> for the current * application module//www . jav a 2 s . co m */ protected synchronized Map getActions(Context context, ModuleConfig moduleConfig) { WebContext wcontext = (WebContext) context; String actionsKey = Constants.ACTIONS_KEY + moduleConfig.getPrefix(); Map actions = (Map) wcontext.getApplicationScope().get(actionsKey); if (actions == null) { actions = new HashMap(); wcontext.getApplicationScope().put(actionKey, actions); } return (actions); }
From source file:org.apache.struts.chain.CreateActionForm.java
/** * <p>Create (if necessary) and cache a form bean for this request.</p> * * @param context The <code>Context</code> for the current request * * @return <code>false</code> so that processing continues *//*w ww. j a v a 2 s. co m*/ public boolean execute(Context context) throws Exception { // Is there a form bean associated with this ActionConfig? ActionConfig actionConfig = (ActionConfig) context.get(getActionConfigKey()); String name = actionConfig.getName(); if (name == null) { context.remove(getActionFormKey()); return (false); } log.trace("Look up form-bean " + name); // Look up the corresponding FormBeanConfig (if any) FormBeanConfig formBeanConfig = actionConfig.getModuleConfig().findFormBeanConfig(name); if (formBeanConfig == null) { log.warn("No FormBeanConfig found in module " + actionConfig.getModuleConfig().getPrefix() + " under name " + name); context.remove(getActionFormKey()); return (false); } // Look up the session scope ActionForm instance (if any) WebContext wcontext = (WebContext) context; ActionForm instance = null; if ("session".equals(actionConfig.getScope())) { instance = (ActionForm) wcontext.getSessionScope().get(actionConfig.getAttribute()); } // Can we recycle the existing instance (if any)? if (instance != null) { log.trace("Found an instance in the session; test for reusability"); if (formBeanConfig.getDynamic()) { String className = ((DynaBean) instance).getDynaClass().getName(); if (className.equals(formBeanConfig.getName())) { wcontext.put(getActionFormKey(), instance); /* It should already be in session scope if ("session".equals(actionConfig.getScope())) { wcontext.getSessionScope().put (actionConfig.getAttribute(), instance); } */ log.debug("Using existing instance (dynamic)"); return (false); } } else { try { Class configClass = ClassUtils.getApplicationClass(formBeanConfig.getType()); if (configClass.isAssignableFrom(instance.getClass())) { wcontext.put(getActionFormKey(), instance); /* It should already be in session scope if ("session".equals(actionConfig.getScope())) { wcontext.getSessionScope().put (actionConfig.getAttribute(), instance); } */ log.debug("Using existing instance (non-dynamic)"); return (false); } } catch (Exception e) { log.debug("Error testing existing instance for reusability; just create a new instance", e); } } } log.trace("Make a new instance of: " + formBeanConfig); // Create a new form bean instance if (formBeanConfig.getDynamic()) { ModuleConfig moduleConfig = (ModuleConfig) wcontext.get(getModuleConfigKey()); DynaActionFormClass dynaClass = DynaActionFormClass.createDynaActionFormClass(formBeanConfig); instance = (ActionForm) dynaClass.newInstance(); ((DynaActionForm) instance).initialize((ActionMapping) actionConfig); } else { instance = (ActionForm) ClassUtils.getApplicationInstance(formBeanConfig.getType()); } // Configure and cache the new instance ActionServlet servlet = (ActionServlet) wcontext.get(getActionServletKey()); instance.setServlet(servlet); wcontext.put(getActionFormKey(), instance); if ("session".equals(actionConfig.getScope())) { wcontext.getSessionScope().put(actionConfig.getAttribute(), instance); } else if ("request".equals(actionConfig.getScope())) { wcontext.getRequestScope().put(actionConfig.getAttribute(), instance); } return (false); }