Search in sources :

Example 6 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonarqube by SonarSource.

the class AbstractPopulateActionForm method execute.

// ---------------------------------------------------------- Public Methods
/**
     * <p>Populate the form bean (if any) for this request.</p>
     *
     * @param actionCtx The <code>Context</code> for the current request
     * @return <code>false</code> so that processing continues
     * @throws Exception On an unexpected error
     */
public boolean execute(ActionContext actionCtx) throws Exception {
    // Is there a form bean for this request?
    ActionForm actionForm = actionCtx.getActionForm();
    if (actionForm == null) {
        return (false);
    }
    // Reset the form bean property values
    ActionConfig actionConfig = actionCtx.getActionConfig();
    reset(actionCtx, actionConfig, actionForm);
    populate(actionCtx, actionConfig, actionForm);
    handleCancel(actionCtx, actionConfig, actionForm);
    return (false);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ActionForm(org.apache.struts.action.ActionForm)

Example 7 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonarqube by SonarSource.

the class AbstractSelectAction method execute.

// ---------------------------------------------------------- Public Methods
/**
     * <p>Cache the <code>ActionConfig</code> instance for the action to be
     * used for processing this request.</p>
     *
     * @param actionCtx The <code>Context</code> for the current request
     * @return <code>false</code> so that processing continues
     * @throws InvalidPathException if no valid action can be identified for
     *                              this request
     * @throws Exception            if thrown by the Action class
     */
public boolean execute(ActionContext actionCtx) throws Exception {
    // Identify the matching path for this request
    String path = getPath(actionCtx);
    // Cache the corresponding ActonConfig instance
    ModuleConfig moduleConfig = actionCtx.getModuleConfig();
    ActionConfig actionConfig = moduleConfig.findActionConfig(path);
    if (actionConfig == null) {
        // NOTE Shouldn't this be the responsibility of ModuleConfig?
        // 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 InvalidPathException("No action config found for the specified url.", path);
    }
    actionCtx.setActionConfig(actionConfig);
    return (false);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ModuleConfig(org.apache.struts.config.ModuleConfig)

Example 8 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonarqube by SonarSource.

the class AbstractSelectForward method execute.

// ---------------------------------------------------------- Public Methods
/**
     * <p>Select and cache the <code>ActionForward</code> for this
     * <code>ActionConfig</code> if specified.</p>
     *
     * @param actionCtx The <code>Context</code> for the current request
     * @return <code>false</code> so that processing continues
     * @throws Exception if thrown by the Action class
     */
public boolean execute(ActionContext actionCtx) throws Exception {
    // Skip processing if the current request is not valid
    Boolean valid = actionCtx.getFormValid();
    if ((valid == null) || !valid.booleanValue()) {
        return (false);
    }
    // Acquire configuration objects that we need
    ActionConfig actionConfig = actionCtx.getActionConfig();
    ModuleConfig moduleConfig = actionConfig.getModuleConfig();
    ForwardConfig forwardConfig = null;
    String forward = actionConfig.getForward();
    if (forward != null) {
        forwardConfig = forward(actionCtx, moduleConfig, forward);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Forwarding to " + forwardConfig);
        }
        actionCtx.setForwardConfig(forwardConfig);
    }
    return (false);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ModuleConfig(org.apache.struts.config.ModuleConfig) ForwardConfig(org.apache.struts.config.ForwardConfig)

Example 9 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonarqube by SonarSource.

the class AbstractValidateActionForm method execute.

// ---------------------------------------------------------- Public Methods
/**
     * <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 actionCtx 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>
     * @throws Exception if thrown by the Action class
     */
public boolean execute(ActionContext actionCtx) throws Exception {
    // Set form valid until found otherwise
    actionCtx.setFormValid(Boolean.TRUE);
    // Is there a form bean for this request?
    ActionForm actionForm = actionCtx.getActionForm();
    if (actionForm == null) {
        return false;
    }
    // Is validation disabled on this request?
    ActionConfig actionConfig = actionCtx.getActionConfig();
    if (!actionConfig.getValidate()) {
        return false;
    }
    // Was this request cancelled?
    if (isCancelled(actionCtx, actionConfig)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug(" Cancelled transaction, skipping validation");
        }
        return false;
    }
    // Call the validate() method of this form bean
    ActionErrors errors = validate(actionCtx, actionConfig, actionForm);
    // If there were no errors, proceed normally
    if ((errors == null) || (errors.isEmpty())) {
        return false;
    }
    // Flag the validation failure and proceed
    /* NOTE: Is there any concern that there might have already
         * been errors, or that other errors might be coming?
         */
    actionCtx.saveErrors(errors);
    actionCtx.setFormValid(Boolean.FALSE);
    return false;
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ActionForm(org.apache.struts.action.ActionForm) ActionErrors(org.apache.struts.action.ActionErrors)

Example 10 with ActionConfig

use of org.apache.struts.config.ActionConfig in project sonarqube by SonarSource.

the class CreateActionForm method execute.

// ---------------------------------------------------------- Public Methods
/**
     * <p>Create (if necessary) and cache a form bean for this request.</p>
     *
     * @param actionCtx The <code>Context</code> for the current request
     * @return <code>false</code> so that processing continues
     * @throws Exception on any error
     */
public boolean execute(ActionContext actionCtx) throws Exception {
    // Is there a form bean associated with this ActionConfig?
    ActionConfig actionConfig = actionCtx.getActionConfig();
    String name = actionConfig.getName();
    if (name == null) {
        actionCtx.setActionForm(null);
        return (false);
    }
    if (LOG.isTraceEnabled()) {
        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);
        actionCtx.setActionForm(null);
        return (false);
    }
    Map scope = actionCtx.getScope(actionConfig.getScope());
    ActionForm instance;
    instance = (ActionForm) scope.get(actionConfig.getAttribute());
    // Can we recycle the existing instance (if any)?
    if (!formBeanConfig.canReuse(instance)) {
        instance = formBeanConfig.createActionForm(actionCtx);
    }
    //  directly depends on ActionServlet
    if (actionCtx instanceof ServletActionContext) {
        // The servlet property of ActionForm is transient, so
        // ActionForms which are restored from a serialized state
        // need to have their servlet restored.
        ServletActionContext sac = (ServletActionContext) actionCtx;
        instance.setServlet(sac.getActionServlet());
    }
    actionCtx.setActionForm(instance);
    scope.put(actionConfig.getAttribute(), instance);
    return (false);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) FormBeanConfig(org.apache.struts.config.FormBeanConfig) ActionForm(org.apache.struts.action.ActionForm) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) Map(java.util.Map)

Aggregations

ActionConfig (org.apache.struts.config.ActionConfig)76 ForwardConfig (org.apache.struts.config.ForwardConfig)14 UnavailableException (javax.servlet.UnavailableException)8 ActionForm (org.apache.struts.action.ActionForm)8 ExceptionConfig (org.apache.struts.config.ExceptionConfig)8 FormBeanConfig (org.apache.struts.config.FormBeanConfig)8 ModuleConfig (org.apache.struts.config.ModuleConfig)8 ServletException (javax.servlet.ServletException)6 MalformedURLException (java.net.MalformedURLException)4 Map (java.util.Map)4 Action (org.apache.struts.action.Action)4 UnauthorizedActionException (org.apache.struts.chain.commands.UnauthorizedActionException)4 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 MissingResourceException (java.util.MissingResourceException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 JspException (javax.servlet.jsp.JspException)2 ActionErrors (org.apache.struts.action.ActionErrors)2 MockActionContext (org.apache.struts.chain.contexts.MockActionContext)2 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)2