Search in sources :

Example 56 with ForwardConfig

use of org.apache.struts.config.ForwardConfig in project sonar-java by SonarSource.

the class ModuleConfigImpl method freeze.

/**
 * <p> Freeze the configuration of this module.  After this method
 * returns, any attempt to modify the configuration will return an
 * IllegalStateException. </p>
 */
public void freeze() {
    super.freeze();
    ActionConfig[] aconfigs = findActionConfigs();
    for (int i = 0; i < aconfigs.length; i++) {
        aconfigs[i].freeze();
    }
    matcher = new ActionConfigMatcher(aconfigs);
    getControllerConfig().freeze();
    ExceptionConfig[] econfigs = findExceptionConfigs();
    for (int i = 0; i < econfigs.length; i++) {
        econfigs[i].freeze();
    }
    FormBeanConfig[] fbconfigs = findFormBeanConfigs();
    for (int i = 0; i < fbconfigs.length; i++) {
        fbconfigs[i].freeze();
    }
    ForwardConfig[] fconfigs = findForwardConfigs();
    for (int i = 0; i < fconfigs.length; i++) {
        fconfigs[i].freeze();
    }
    MessageResourcesConfig[] mrconfigs = findMessageResourcesConfigs();
    for (int i = 0; i < mrconfigs.length; i++) {
        mrconfigs[i].freeze();
    }
    PlugInConfig[] piconfigs = findPlugInConfigs();
    for (int i = 0; i < piconfigs.length; i++) {
        piconfigs[i].freeze();
    }
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ExceptionConfig(org.apache.struts.config.ExceptionConfig) FormBeanConfig(org.apache.struts.config.FormBeanConfig) PlugInConfig(org.apache.struts.config.PlugInConfig) ForwardConfig(org.apache.struts.config.ForwardConfig) ActionConfigMatcher(org.apache.struts.config.ActionConfigMatcher) MessageResourcesConfig(org.apache.struts.config.MessageResourcesConfig)

Example 57 with ForwardConfig

use of org.apache.struts.config.ForwardConfig in project sonar-java by SonarSource.

the class ActionMapping method findForwards.

/**
 * <p>Return the logical names of all locally defined forwards for this
 * mapping. If there are no such forwards, a zero-length array is
 * returned.</p>
 *
 * @return The forward names for this action mapping.
 */
public String[] findForwards() {
    ArrayList results = new ArrayList();
    ForwardConfig[] fcs = findForwardConfigs();
    for (int i = 0; i < fcs.length; i++) {
        results.add(fcs[i].getName());
    }
    return ((String[]) results.toArray(new String[results.size()]));
}
Also used : ArrayList(java.util.ArrayList) ForwardConfig(org.apache.struts.config.ForwardConfig)

Example 58 with ForwardConfig

use of org.apache.struts.config.ForwardConfig in project sonar-java by SonarSource.

the class ActionServlet method processActionConfigClass.

/**
 * <p>Checks if the current actionConfig is using the correct class based
 * on the class of its ancestor ActionConfig.</p>
 *
 * @param actionConfig The action config to check.
 * @param moduleConfig The config for the current module.
 * @return The config object using the correct class as determined by the
 *         config's ancestor and its own overridden value.
 * @throws ServletException if an instance of the action config class
 *                          cannot be created.
 */
protected ActionConfig processActionConfigClass(ActionConfig actionConfig, ModuleConfig moduleConfig) throws ServletException {
    String ancestor = actionConfig.getExtends();
    if (ancestor == null) {
        // Nothing to do, then
        return actionConfig;
    }
    // Make sure that this config is of the right class
    ActionConfig baseConfig = moduleConfig.findActionConfig(ancestor);
    if (baseConfig == null) {
        throw new UnavailableException("Unable to find " + "action config for '" + ancestor + "' to extend.");
    }
    // Was our actionConfig's class overridden already?
    if (actionConfig.getClass().equals(ActionMapping.class)) {
        // Ensure that our config is using the correct class
        if (!baseConfig.getClass().equals(actionConfig.getClass())) {
            // Replace the config with an instance of the correct class
            ActionConfig newActionConfig = null;
            String baseConfigClassName = baseConfig.getClass().getName();
            try {
                newActionConfig = (ActionConfig) RequestUtils.applicationInstance(baseConfigClassName);
                // copy the values
                BeanUtils.copyProperties(newActionConfig, actionConfig);
                // copy the forward and exception configs, too
                ForwardConfig[] forwards = actionConfig.findForwardConfigs();
                for (int i = 0; i < forwards.length; i++) {
                    newActionConfig.addForwardConfig(forwards[i]);
                }
                ExceptionConfig[] exceptions = actionConfig.findExceptionConfigs();
                for (int i = 0; i < exceptions.length; i++) {
                    newActionConfig.addExceptionConfig(exceptions[i]);
                }
            } catch (Exception e) {
                handleCreationException(baseConfigClassName, e);
            }
            // replace actionConfig with newActionConfig
            moduleConfig.removeActionConfig(actionConfig);
            moduleConfig.addActionConfig(newActionConfig);
            actionConfig = newActionConfig;
        }
    }
    return actionConfig;
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ExceptionConfig(org.apache.struts.config.ExceptionConfig) UnavailableException(javax.servlet.UnavailableException) ForwardConfig(org.apache.struts.config.ForwardConfig) ServletException(javax.servlet.ServletException) MissingResourceException(java.util.MissingResourceException) SAXException(org.xml.sax.SAXException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UnavailableException(javax.servlet.UnavailableException)

Example 59 with ForwardConfig

use of org.apache.struts.config.ForwardConfig in project sonar-java by SonarSource.

the class AbstractExceptionHandler method execute.

// ---------------------------------------------------------- Public Methods
/**
 * <p>Invoke the appropriate <code>Action</code> for this request, and
 * cache the returned <code>ActionForward</code>.</p>
 *
 * @param actionCtx The <code>Context</code> for the current request
 * @return <code>false</code> if a <code>ForwardConfig</code> is returned,
 *         else <code>true</code> to complete processing
 * @throws Exception if thrown by the Action class and not declared by an
 *                   Exception Handler
 */
public boolean execute(ActionContext actionCtx) throws Exception {
    // Look up the exception that was thrown
    Exception exception = actionCtx.getException();
    if (exception == null) {
        LOG.warn("No Exception found in ActionContext");
        return (true);
    }
    // Look up the local or global exception handler configuration
    ExceptionConfig exceptionConfig = null;
    ActionConfig actionConfig = actionCtx.getActionConfig();
    ModuleConfig moduleConfig = actionCtx.getModuleConfig();
    if (actionConfig != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("See if actionConfig " + actionConfig + " has an exceptionConfig for " + exception.getClass().getName());
        }
        exceptionConfig = actionConfig.findException(exception.getClass());
    } else if (moduleConfig != null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("No action yet, see if moduleConfig " + moduleConfig + " has an exceptionConfig " + exception.getClass().getName());
        }
        exceptionConfig = moduleConfig.findException(exception.getClass());
    }
    // Handle the exception in the configured manner
    if (exceptionConfig == null) {
        LOG.warn("Unhandled exception", exception);
        throw exception;
    }
    ForwardConfig forwardConfig = handle(actionCtx, exception, exceptionConfig, actionConfig, moduleConfig);
    if (forwardConfig != null) {
        actionCtx.setForwardConfig(forwardConfig);
        return (false);
    } else {
        return (true);
    }
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ExceptionConfig(org.apache.struts.config.ExceptionConfig) ModuleConfig(org.apache.struts.config.ModuleConfig) ForwardConfig(org.apache.struts.config.ForwardConfig)

Example 60 with ForwardConfig

use of org.apache.struts.config.ForwardConfig in project sonar-java by SonarSource.

the class AbstractExecuteAction method execute.

// ---------------------------------------------------------- Public Methods
/**
 * <p>Invoke the appropriate <code>Action</code> for this request, and
 * cache the returned <code>ActionForward</code>.</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 the resources we will need to send to the Action
    Action action = actionCtx.getAction();
    if (action == null) {
        return (false);
    }
    ActionConfig actionConfig = actionCtx.getActionConfig();
    ActionForm actionForm = actionCtx.getActionForm();
    // Execute the Action for this request, caching returned ActionForward
    ForwardConfig forwardConfig = execute(actionCtx, action, actionConfig, actionForm);
    actionCtx.setForwardConfig(forwardConfig);
    return (false);
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) Action(org.apache.struts.action.Action) ActionForm(org.apache.struts.action.ActionForm) ForwardConfig(org.apache.struts.config.ForwardConfig)

Aggregations

ForwardConfig (org.apache.struts.config.ForwardConfig)63 ActionConfig (org.apache.struts.config.ActionConfig)14 UnavailableException (javax.servlet.UnavailableException)12 ServletException (javax.servlet.ServletException)10 ExceptionConfig (org.apache.struts.config.ExceptionConfig)10 MalformedURLException (java.net.MalformedURLException)8 ModuleConfig (org.apache.struts.config.ModuleConfig)8 IOException (java.io.IOException)6 MissingResourceException (java.util.MissingResourceException)6 ModuleConfigFactory (org.apache.struts.config.ModuleConfigFactory)6 SAXException (org.xml.sax.SAXException)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 ActionFormBean (org.apache.struts.action.ActionFormBean)4 ActionForward (org.apache.struts.action.ActionForward)4 ActionMapping (org.apache.struts.action.ActionMapping)4 ActionServlet (org.apache.struts.action.ActionServlet)4 FormPropertyConfig (org.apache.struts.config.FormPropertyConfig)4 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)3 ArrayList (java.util.ArrayList)2