Search in sources :

Example 16 with ModuleConfig

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

the class CreateAction method getAction.

/* :TODO The Action class' dependency on having its "servlet" property set
     * requires this API-dependent subclass of AbstractCreateAction.
     */
protected synchronized Action getAction(ActionContext context, String type, ActionConfig actionConfig) throws Exception {
    ModuleConfig moduleConfig = actionConfig.getModuleConfig();
    String actionsKey = Constants.ACTIONS_KEY + moduleConfig.getPrefix();
    Map actions = (Map) context.getApplicationScope().get(actionsKey);
    if (actions == null) {
        actions = new HashMap();
        context.getApplicationScope().put(actionsKey, actions);
    }
    Action action = null;
    synchronized (actions) {
        action = (Action) actions.get(type);
        if (action == null) {
            action = createAction(context, type);
            actions.put(type, action);
        }
    }
    if (action.getServlet() == null) {
        ServletActionContext saContext = (ServletActionContext) context;
        ActionServlet actionServlet = saContext.getActionServlet();
        action.setServlet(actionServlet);
    }
    return (action);
}
Also used : Action(org.apache.struts.action.Action) HashMap(java.util.HashMap) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) ModuleConfig(org.apache.struts.config.ModuleConfig) Map(java.util.Map) HashMap(java.util.HashMap) ActionServlet(org.apache.struts.action.ActionServlet)

Example 17 with ModuleConfig

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

the class PerformForward method resolveModuleRelativePath.

private String resolveModuleRelativePath(ForwardConfig forwardConfig, ServletContext servletContext, HttpServletRequest request) {
    String prefix = forwardConfig.getModule();
    ModuleConfig moduleConfig = ModuleUtils.getInstance().getModuleConfig(prefix, request, servletContext);
    return RequestUtils.forwardURL(request, forwardConfig, moduleConfig);
}
Also used : ModuleConfig(org.apache.struts.config.ModuleConfig)

Example 18 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonarqube 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)

Example 19 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonarqube 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 20 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonarqube 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)

Aggregations

ModuleConfig (org.apache.struts.config.ModuleConfig)34 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 JspException (javax.servlet.jsp.JspException)5 Iterator (java.util.Iterator)4 ActionConfig (org.apache.struts.config.ActionConfig)4 ForwardConfig (org.apache.struts.config.ForwardConfig)4 MessageResources (org.apache.struts.util.MessageResources)4 ArrayList (java.util.ArrayList)3 Enumeration (java.util.Enumeration)2 List (java.util.List)2 Locale (java.util.Locale)2 ServletException (javax.servlet.ServletException)2 ActionServlet (org.apache.struts.action.ActionServlet)2 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Map (java.util.Map)1 ServletContext (javax.servlet.ServletContext)1