Search in sources :

Example 66 with ModuleConfig

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

the class AbstractSelectInput method execute.

// ---------------------------------------------------------- Public Methods
/**
 * <p>Select and cache a <code>ForwardConfig</code> for the input page for
 * the current request.</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 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();
    // Cache an ForwardConfig back to our input page
    ForwardConfig forwardConfig;
    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(actionCtx, moduleConfig, input);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Forwarding back 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 67 with ModuleConfig

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

the class AbstractSelectModule method execute.

// ------------------------------------------------------ Instance Variables
// ---------------------------------------------------------- Public Methods
/**
 * <p>Cache the <code>ModuleConfig</code> and <code>MessageResources</code>
 * instances for the sub-application module 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 IllegalArgumentException if no valid ModuleConfig or
 *                                  MessageResources can be identified for
 *                                  this request
 * @throws Exception                if thrown by the Action class
 */
public boolean execute(ActionContext actionCtx) throws Exception {
    String prefix = getPrefix(actionCtx);
    // Cache the corresponding ModuleConfig and MessageResources instances
    ModuleConfig moduleConfig = (ModuleConfig) actionCtx.getApplicationScope().get(Globals.MODULE_KEY + prefix);
    if (moduleConfig == null) {
        throw new IllegalArgumentException("No module config for prefix '" + prefix + "'");
    }
    actionCtx.setModuleConfig(moduleConfig);
    String key = Globals.MESSAGES_KEY + prefix;
    MessageResources messageResources = (MessageResources) actionCtx.getApplicationScope().get(key);
    if (messageResources == null) {
        throw new IllegalArgumentException("No message resources found in application scope under " + key);
    }
    actionCtx.setMessageResources(messageResources);
    return (false);
}
Also used : MessageResources(org.apache.struts.util.MessageResources) ModuleConfig(org.apache.struts.config.ModuleConfig)

Example 68 with ModuleConfig

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

the class AbstractSetContentType method execute.

// ---------------------------------------------------------- Public Methods
/**
 * <p>Check to see if the content type is set, and if so, set it for this
 * response.</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 {
    // Retrieve the ModuleConfig instance
    ModuleConfig moduleConfig = actionCtx.getModuleConfig();
    // If the content type is configured, set it for the response
    String contentType = moduleConfig.getControllerConfig().getContentType();
    if (contentType != null) {
        setContentType(actionCtx, contentType);
    }
    return (false);
}
Also used : ModuleConfig(org.apache.struts.config.ModuleConfig)

Example 69 with ModuleConfig

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

the class ActionServlet method destroyModules.

// ------------------------------------------------------ Protected Methods
/**
 * <p>Gracefully terminate use of any modules associated with this
 * application (if any).</p>
 *
 * @since Struts 1.1
 */
protected void destroyModules() {
    ArrayList values = new ArrayList();
    Enumeration names = getServletContext().getAttributeNames();
    while (names.hasMoreElements()) {
        values.add(names.nextElement());
    }
    Iterator keys = values.iterator();
    while (keys.hasNext()) {
        String name = (String) keys.next();
        Object value = getServletContext().getAttribute(name);
        if (!(value instanceof ModuleConfig)) {
            continue;
        }
        ModuleConfig config = (ModuleConfig) value;
        if (this.getProcessorForModule(config) != null) {
            this.getProcessorForModule(config).destroy();
        }
        getServletContext().removeAttribute(name);
        PlugIn[] plugIns = (PlugIn[]) getServletContext().getAttribute(Globals.PLUG_INS_KEY + config.getPrefix());
        if (plugIns != null) {
            for (int i = 0; i < plugIns.length; i++) {
                int j = plugIns.length - (i + 1);
                plugIns[j].destroy();
            }
            getServletContext().removeAttribute(Globals.PLUG_INS_KEY + config.getPrefix());
        }
    }
}
Also used : Enumeration(java.util.Enumeration) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ModuleConfig(org.apache.struts.config.ModuleConfig)

Example 70 with ModuleConfig

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

the class ActionServlet method init.

/**
 * <p>Initialize this servlet.  Most of the processing has been factored
 * into support methods so that you can override particular functionality
 * at a fairly granular level.</p>
 *
 * @throws ServletException if we cannot configure ourselves correctly
 */
public void init() throws ServletException {
    final String configPrefix = "config/";
    final int configPrefixLength = configPrefix.length() - 1;
    // to the developer
    try {
        initInternal();
        initOther();
        initServlet();
        initChain();
        getServletContext().setAttribute(Globals.ACTION_SERVLET_KEY, this);
        initModuleConfigFactory();
        // Initialize modules as needed
        ModuleConfig moduleConfig = initModuleConfig("", config);
        initModuleMessageResources(moduleConfig);
        initModulePlugIns(moduleConfig);
        initModuleFormBeans(moduleConfig);
        initModuleForwards(moduleConfig);
        initModuleExceptionConfigs(moduleConfig);
        initModuleActions(moduleConfig);
        moduleConfig.freeze();
        Enumeration names = getServletConfig().getInitParameterNames();
        while (names.hasMoreElements()) {
            String name = (String) names.nextElement();
            if (!name.startsWith(configPrefix)) {
                continue;
            }
            String prefix = name.substring(configPrefixLength);
            moduleConfig = initModuleConfig(prefix, getServletConfig().getInitParameter(name));
            initModuleMessageResources(moduleConfig);
            initModulePlugIns(moduleConfig);
            initModuleFormBeans(moduleConfig);
            initModuleForwards(moduleConfig);
            initModuleExceptionConfigs(moduleConfig);
            initModuleActions(moduleConfig);
            moduleConfig.freeze();
        }
        this.initModulePrefixes(this.getServletContext());
        this.destroyConfigDigester();
    } catch (UnavailableException ex) {
        throw ex;
    } catch (Throwable t) {
        // The follow error message is not retrieved from internal message
        // resources as they may not have been able to have been
        // initialized
        log.error("Unable to initialize Struts ActionServlet due to an " + "unexpected exception or error thrown, so marking the " + "servlet as unavailable.  Most likely, this is due to an " + "incorrect or missing library dependency.", t);
        throw new UnavailableException(t.getMessage());
    }
}
Also used : Enumeration(java.util.Enumeration) UnavailableException(javax.servlet.UnavailableException) ModuleConfig(org.apache.struts.config.ModuleConfig)

Aggregations

ModuleConfig (org.apache.struts.config.ModuleConfig)73 HttpServletRequest (javax.servlet.http.HttpServletRequest)10 JspException (javax.servlet.jsp.JspException)10 Iterator (java.util.Iterator)8 ActionConfig (org.apache.struts.config.ActionConfig)8 ForwardConfig (org.apache.struts.config.ForwardConfig)8 MessageResources (org.apache.struts.util.MessageResources)8 ArrayList (java.util.ArrayList)6 ServletException (javax.servlet.ServletException)6 Enumeration (java.util.Enumeration)4 List (java.util.List)4 Locale (java.util.Locale)4 ActionServlet (org.apache.struts.action.ActionServlet)4 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)4 UnavailableException (javax.servlet.UnavailableException)3 Digester (org.apache.commons.digester.Digester)3 ModuleConfigFactory (org.apache.struts.config.ModuleConfigFactory)3 MultipartRequestHandler (org.apache.struts.upload.MultipartRequestHandler)3 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2