Search in sources :

Example 61 with ModuleConfig

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

the class ModuleUtils method getModuleConfig.

/**
 * Return the ModuleConfig object is it exists, null otherwise.
 *
 * @param request The servlet request we are processing
 * @param context The ServletContext for this web application
 * @return the ModuleConfig object
 */
public ModuleConfig getModuleConfig(HttpServletRequest request, ServletContext context) {
    ModuleConfig moduleConfig = this.getModuleConfig(request);
    if (moduleConfig == null) {
        moduleConfig = this.getModuleConfig("", context);
        request.setAttribute(Globals.MODULE_KEY, moduleConfig);
    }
    return moduleConfig;
}
Also used : ModuleConfig(org.apache.struts.config.ModuleConfig)

Example 62 with ModuleConfig

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

the class ModuleUtils method selectModule.

/**
 * Select the module to which the specified request belongs, and add
 * corresponding request attributes to this request.
 *
 * @param prefix  The module prefix of the desired module
 * @param request The servlet request we are processing
 * @param context The ServletContext for this web application
 */
public void selectModule(String prefix, HttpServletRequest request, ServletContext context) {
    // Expose the resources for this module
    ModuleConfig config = getModuleConfig(prefix, context);
    if (config != null) {
        request.setAttribute(Globals.MODULE_KEY, config);
        MessageResourcesConfig[] mrConfig = config.findMessageResourcesConfigs();
        for (int i = 0; i < mrConfig.length; i++) {
            String key = mrConfig[i].getKey();
            MessageResources resources = (MessageResources) context.getAttribute(key + prefix);
            if (resources != null) {
                request.setAttribute(key, resources);
            } else {
                request.removeAttribute(key);
            }
        }
    } else {
        request.removeAttribute(Globals.MODULE_KEY);
    }
}
Also used : ModuleConfig(org.apache.struts.config.ModuleConfig) MessageResourcesConfig(org.apache.struts.config.MessageResourcesConfig)

Example 63 with ModuleConfig

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

the class RequestUtils method getMultipartHandler.

/**
 * <p>Try to locate a multipart request handler for this request. First,
 * look for a mapping-specific handler stored for us under an attribute.
 * If one is not present, use the global multipart handler, if there is
 * one.</p>
 *
 * @param request The HTTP request for which the multipart handler should
 *                be found.
 * @return the multipart handler to use, or null if none is found.
 * @throws ServletException if any exception is thrown while attempting to
 *                          locate the multipart handler.
 */
private static MultipartRequestHandler getMultipartHandler(HttpServletRequest request) throws ServletException {
    MultipartRequestHandler multipartHandler = null;
    String multipartClass = (String) request.getAttribute(Globals.MULTIPART_KEY);
    request.removeAttribute(Globals.MULTIPART_KEY);
    // Try to initialize the mapping specific request handler
    if (multipartClass != null) {
        try {
            multipartHandler = (MultipartRequestHandler) applicationInstance(multipartClass);
        } catch (ClassNotFoundException cnfe) {
            log.error("MultipartRequestHandler class \"" + multipartClass + "\" in mapping class not found, " + "defaulting to global multipart class");
        } catch (InstantiationException ie) {
            log.error("InstantiationException when instantiating " + "MultipartRequestHandler \"" + multipartClass + "\", " + "defaulting to global multipart class, exception: " + ie.getMessage());
        } catch (IllegalAccessException iae) {
            log.error("IllegalAccessException when instantiating " + "MultipartRequestHandler \"" + multipartClass + "\", " + "defaulting to global multipart class, exception: " + iae.getMessage());
        }
        if (multipartHandler != null) {
            return multipartHandler;
        }
    }
    ModuleConfig moduleConfig = ModuleUtils.getInstance().getModuleConfig(request);
    multipartClass = moduleConfig.getControllerConfig().getMultipartClass();
    // Try to initialize the global request handler
    if (multipartClass != null) {
        try {
            multipartHandler = (MultipartRequestHandler) applicationInstance(multipartClass);
        } catch (ClassNotFoundException cnfe) {
            throw new ServletException("Cannot find multipart class \"" + multipartClass + "\"" + ", exception: " + cnfe.getMessage());
        } catch (InstantiationException ie) {
            throw new ServletException("InstantiationException when instantiating " + "multipart class \"" + multipartClass + "\", exception: " + ie.getMessage());
        } catch (IllegalAccessException iae) {
            throw new ServletException("IllegalAccessException when instantiating " + "multipart class \"" + multipartClass + "\", exception: " + iae.getMessage());
        }
        if (multipartHandler != null) {
            return multipartHandler;
        }
    }
    return multipartHandler;
}
Also used : ServletException(javax.servlet.ServletException) ModuleConfig(org.apache.struts.config.ModuleConfig) MultipartRequestHandler(org.apache.struts.upload.MultipartRequestHandler)

Example 64 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonar-java 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 65 with ModuleConfig

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

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