List of usage examples for org.apache.commons.chain Context get
V get(Object key);
From source file:org.apache.struts.chain.AbstractExceptionHandler.java
/** * <p>Invoke the appropriate <code>Action</code> for this request, and cache * the returned <code>ActionForward</code>.</p> * * @param context The <code>Context</code> for the current request * * @exception InvalidPathException if no valid * action can be identified for this request * * @return <code>false</code> if a <code>ForwardConfig</code> is returned, * else <code>true</code> to complete processing *///from w ww. ja va 2 s . c om public boolean execute(Context context) throws Exception { // Look up the exception that was thrown Exception exception = (Exception) context.get(getExceptionKey()); if (exception == null) { log.warn("No Exception found under key '" + getExceptionKey() + "'"); return (true); } // Look up the local or global exception handler configuration ExceptionConfig exceptionConfig = null; ActionConfig actionConfig = (ActionConfig) context.get(getActionConfigKey()); ModuleConfig moduleConfig = (ModuleConfig) context.get(getModuleConfigKey()); if (actionConfig != null) { log.debug("See if actionConfig " + actionConfig + " has an exceptionConfig for " + exception.getClass().getName()); exceptionConfig = actionConfig.findException(exception.getClass()); } // Handle the exception in the configured manner if (exceptionConfig == null) { log.warn("Unhandled exception", exception); throw exception; } ForwardConfig forwardConfig = handle(context, exception, exceptionConfig, actionConfig, moduleConfig); if (forwardConfig != null) { context.put(getForwardConfigKey(), forwardConfig); return (false); } else { return (true); } }
From source file:org.apache.struts.chain.AbstractExecuteAction.java
/** * <p>Invoke the appropriate <code>Action</code> for this request, and cache * the returned <code>ActionForward</code>.</p> * * @param context The <code>Context</code> for the current request * * @exception InvalidPathException if no valid * action can be identified for this request * * @return <code>false</code> so that processing continues *///w w w . j a v a 2s . c om public boolean execute(Context context) throws Exception { // Skip processing if the current request is not valid Boolean valid = (Boolean) context.get(getValidKey()); if ((valid == null) || !valid.booleanValue()) { return (false); } // Acquire the resources we will need to send to the Action Action action = (Action) context.get(getActionKey()); if (action == null) { return (false); } ActionConfig actionConfig = (ActionConfig) context.get(getActionConfigKey()); ActionForm actionForm = (ActionForm) context.get(getActionFormKey()); // Execute the Action for this request, caching returned ActionForward ForwardConfig forwardConfig = execute(context, action, actionConfig, actionForm); context.put(getForwardConfigKey(), forwardConfig); return (false); }
From source file:org.apache.struts.chain.AbstractPerformForward.java
/** * <p>Perform forwarding or redirection based on the specified * <code>ActionForward</code> (if any).</p> * * @param context The <code>Context</code> for the current request * * @return <code>true</code> so that processing completes *//* ww w . j a v a 2s .c om*/ public boolean execute(Context context) throws Exception { // Is there a ForwardConfig to be performed? ForwardConfig forwardConfig = (ForwardConfig) context.get(getForwardConfigKey()); if (forwardConfig == null) { return (false); } // Perform the appropriate processing on this ActionForward perform(context, forwardConfig); return (true); }
From source file:org.apache.struts.chain.AbstractPerformInclude.java
/** * <p>Perform an include based on the specified * include uri (if any).</p>// ww w . j a va 2s. c o m * * @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.AbstractPopulateActionForm.java
/** * <p>Populate the form bean (if any) for this request.</p> * * @param context The <code>Context</code> for the current request * * @return <code>false</code> so that processing continues *///from w ww .j a v a 2 s. c o m public boolean execute(Context context) throws Exception { // Is there a form bean for this request? ActionForm actionForm = (ActionForm) context.get(getActionFormKey()); if (actionForm == null) { return (false); } // Reset the form bean property values ActionConfig actionConfig = (ActionConfig) context.get(getActionConfigKey()); reset(context, actionConfig, actionForm); populate(context, actionConfig, actionForm); handleCancel(context, actionConfig, actionForm); return (false); }
From source file:org.apache.struts.chain.AbstractSelectForward.java
/** * <p>Select and cache the <code>ActionForward</code> for this * <code>ActionConfig</code> if specified.</p> * * @param context The <code>Context</code> for the current request * * @return <code>false</code> so that processing continues *//*from www . j a v a 2 s . com*/ public boolean execute(Context context) throws Exception { // Skip processing if the current request is not valid Boolean valid = (Boolean) context.get(getValidKey()); if ((valid == null) || !valid.booleanValue()) { return (false); } // Acquire configuration objects that we need ActionConfig actionConfig = (ActionConfig) context.get(getActionConfigKey()); ModuleConfig moduleConfig = actionConfig.getModuleConfig(); ForwardConfig forwardConfig = null; String forward = actionConfig.getForward(); if (forward != null) { forwardConfig = forward(context, moduleConfig, forward); if (log.isDebugEnabled()) { log.debug("Forwarding to " + forwardConfig); } context.put(getForwardConfigKey(), forwardConfig); } return (false); }
From source file:org.apache.struts.chain.AbstractSelectInput.java
/** * <p>Select and cache a <code>ForwardConfig</code> for the input page * for the current request.</p>//from w ww. jav a 2 s. co m * * @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 { // Skip processing if the current request is valid Boolean valid = (Boolean) context.get(getValidKey()); if ((valid != null) && valid.booleanValue()) { return (false); } // Acquire configuration objects that we need ActionConfig actionConfig = (ActionConfig) context.get(getActionConfigKey()); ModuleConfig moduleConfig = actionConfig.getModuleConfig(); // Cache an ForwardConfig back to our input page ForwardConfig forwardConfig = null; String input = actionConfig.getInput(); if (moduleConfig.getControllerConfig().getInputForward()) { if (log.isTraceEnabled()) { log.trace("Finding ForwardConfig for '" + input + "'"); } forwardConfig = actionConfig.findForwardConfig(input); if (forwardConfig == null) { forwardConfig = moduleConfig.findForwardConfig(input); } } else { if (log.isTraceEnabled()) { log.trace("Delegating to forward() for '" + input + "'"); } forwardConfig = forward(context, moduleConfig, input); } if (log.isDebugEnabled()) { log.debug("Forwarding back to " + forwardConfig); } context.put(getForwardConfigKey(), forwardConfig); return (false); }
From source file:org.apache.struts.chain.AbstractSelectLocale.java
/** * <p>Select the <code>Locale</code> to be used for this request.</p> * * @param context The <code>Context</code> for the current request * * @return <code>false</code> so that processing continues *//*from w w w.jav a2s . c o m*/ public boolean execute(Context context) throws Exception { // Are we configured to select Locale automatically? ModuleConfig moduleConfig = (ModuleConfig) context.get(getModuleConfigKey()); if (!moduleConfig.getControllerConfig().getLocale()) { return (false); } // Retrieve and cache appropriate Locale for this request Locale locale = getLocale(context); context.put(getLocaleKey(), locale); return (false); }
From source file:org.apache.struts.chain.AbstractValidateActionForm.java
/** * <p>Validate the properties of the form bean for this request. If * there are any validation errors, execute the child commands in our * chain; otherwise, proceed normally.</p> * * @param context The <code>Context</code> for the current request * * @return <code>false</code> so that processing continues, if there are * no validation errors; otherwise <code>true</code> *//* w w w .j av a 2 s. c om*/ public boolean execute(Context context) throws Exception { // Is there a form bean for this request? ActionForm actionForm = (ActionForm) context.get(getActionFormKey()); if (actionForm == null) { context.put(getValidKey(), Boolean.TRUE); return (false); } // Was this request cancelled? Boolean cancel = (Boolean) context.get(getCancelKey()); if ((cancel != null) && cancel.booleanValue()) { context.put(getValidKey(), Boolean.TRUE); return (false); } // Is validation disabled on this request? ActionConfig actionConfig = (ActionConfig) context.get(getActionConfigKey()); if (!actionConfig.getValidate()) { context.put(getValidKey(), Boolean.TRUE); return (false); } // Call the validate() method of this form bean ActionErrors errors = validate(context, actionConfig, actionForm); // If there were no errors, proceed normally if ((errors == null) || (errors.isEmpty())) { context.put(getValidKey(), Boolean.TRUE); return (false); } // Flag the validation failure and proceed context.put(getValidKey(), Boolean.FALSE); return (false); }
From source file:org.apache.struts.chain.commands.generic.WrappingLookupCommand.java
/** * <p>Return the Command to process for this Context.</p> * * @param context The Context we are processing * @return The Command to process for this Context *///from w w w . j av a 2 s . c o m protected Command getCommand(Context context) { CatalogFactory catalogFactory = CatalogFactory.getInstance(); String catalogName = getCatalogName(); Catalog catalog; if (catalogName == null) { catalog = catalogFactory.getCatalog(); catalogName = "{default}"; // for debugging purposes } else { catalog = catalogFactory.getCatalog(catalogName); } if (catalog == null) { throw new IllegalArgumentException("Cannot find catalog '" + catalogName + "'"); } Command command; String name = getName(); if (name == null) { name = (String) context.get(getNameKey()); } if (name != null) { if (LOG.isDebugEnabled()) { LOG.debug("Lookup command " + name + " in catalog " + catalogName); } command = catalog.getCommand(name); if (LOG.isDebugEnabled()) { LOG.debug("Found command " + command + ";" + " optional: " + isOptional()); } if ((command == null) && !isOptional()) { throw new IllegalArgumentException( "Cannot find command " + "'" + name + "' in catalog '" + catalogName + "'"); } else { return command; } } else { throw new IllegalArgumentException("No command name"); } }