Search in sources :

Example 1 with ModuleConfig

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

the class ActionServlet method process.

/**
     * <p>Perform the standard request processing for this request, and create
     * the corresponding response.</p>
     *
     * @param request  The servlet request we are processing
     * @param response The servlet response we are creating
     * @throws IOException      if an input/output error occurs
     * @throws ServletException if a servlet exception is thrown
     */
protected void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    ModuleUtils.getInstance().selectModule(request, getServletContext());
    ModuleConfig config = getModuleConfig(request);
    RequestProcessor processor = getProcessorForModule(config);
    if (processor == null) {
        processor = getRequestProcessor(config);
    }
    processor.process(request, response);
}
Also used : ModuleConfig(org.apache.struts.config.ModuleConfig)

Example 2 with ModuleConfig

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

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

the class ActionServlet method initModuleConfig.

/**
     * <p>Initialize the module configuration information for the specified
     * module.</p>
     *
     * @param prefix Module prefix for this module
     * @param paths  Comma-separated list of context-relative resource path(s)
     *               for this modules's configuration resource(s)
     * @return The new module configuration instance.
     * @throws ServletException if initialization cannot be performed
     * @since Struts 1.1
     */
protected ModuleConfig initModuleConfig(String prefix, String paths) throws ServletException {
    if (log.isDebugEnabled()) {
        log.debug("Initializing module path '" + prefix + "' configuration from '" + paths + "'");
    }
    // Parse the configuration for this module
    ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();
    ModuleConfig config = factoryObject.createModuleConfig(prefix);
    // Configure the Digester instance we will use
    Digester digester = initConfigDigester();
    List urls = splitAndResolvePaths(paths);
    URL url;
    for (Iterator i = urls.iterator(); i.hasNext(); ) {
        url = (URL) i.next();
        digester.push(config);
        this.parseModuleConfigFile(digester, url);
    }
    getServletContext().setAttribute(Globals.MODULE_KEY + config.getPrefix(), config);
    return config;
}
Also used : ModuleConfigFactory(org.apache.struts.config.ModuleConfigFactory) Digester(org.apache.commons.digester.Digester) Iterator(java.util.Iterator) ModuleConfig(org.apache.struts.config.ModuleConfig) List(java.util.List) ArrayList(java.util.ArrayList) URL(java.net.URL)

Example 4 with ModuleConfig

use of org.apache.struts.config.ModuleConfig 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 5 with ModuleConfig

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

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