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;
}
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);
}
}
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;
}
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);
}
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);
}
Aggregations