use of org.apache.struts.config.ModuleConfig in project sonarqube by SonarSource.
the class AbstractSelectLocale method execute.
// ---------------------------------------------------------- Public Methods
/**
* <p>Select the <code>Locale</code> to be used for this 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 {
// Are we configured to select Locale automatically?
LOG.trace("retrieve config...");
ModuleConfig moduleConfig = actionCtx.getModuleConfig();
if (!moduleConfig.getControllerConfig().getLocale()) {
if (LOG.isDebugEnabled()) {
LOG.debug("module is not configured for a specific locale; " + "nothing to do");
}
return (false);
}
// Retrieve and cache appropriate Locale for this request
Locale locale = getLocale(actionCtx);
if (LOG.isDebugEnabled()) {
LOG.debug("set context locale to " + locale);
}
actionCtx.setLocale(locale);
return (false);
}
use of org.apache.struts.config.ModuleConfig in project sonarqube 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);
}
use of org.apache.struts.config.ModuleConfig in project sonarqube by SonarSource.
the class Action method getResources.
/**
* <p>Return the specified message resources for the current module.</p>
*
* @param request The servlet request we are processing
* @param key The key specified in the message-resources element for
* the requested bundle.
* @return The specified message resource for the current module.
* @since Struts 1.1
*/
protected MessageResources getResources(HttpServletRequest request, String key) {
// Identify the current module
ServletContext context = getServlet().getServletContext();
ModuleConfig moduleConfig = ModuleUtils.getInstance().getModuleConfig(request, context);
// Return the requested message resources instance
return (MessageResources) context.getAttribute(key + moduleConfig.getPrefix());
}
use of org.apache.struts.config.ModuleConfig in project sonarqube by SonarSource.
the class TestRequestUtils method testSelectApplication2b.
// Map to the second module -- include
public void testSelectApplication2b() {
String[] prefixes = { "/1", "/2" };
context.setAttribute(Globals.MODULE_PREFIXES_KEY, prefixes);
request.setPathElements("/myapp", "/noform.do", null, null);
request.setAttribute(RequestProcessor.INCLUDE_SERVLET_PATH, "/2/noform.do");
ModuleUtils.getInstance().selectModule(request, context);
ModuleConfig moduleConfig = (ModuleConfig) request.getAttribute(Globals.MODULE_KEY);
assertNotNull("Selected a module", moduleConfig);
assertEquals("Selected correct module", "/2", moduleConfig.getPrefix());
// FIXME - check application resources?
}
use of org.apache.struts.config.ModuleConfig in project sonarqube by SonarSource.
the class TagUtils method retrieveMessageResources.
/**
* Returns the appropriate MessageResources object for the current module
* and the given bundle.
*
* @param pageContext Search the context's scopes for the resources.
* @param bundle The bundle name to look for. If this is
* <code>null</code>, the default bundle name is
* used.
* @param checkPageScope Whether to check page scope
* @return MessageResources The bundle's resources stored in some scope.
* @throws JspException if the MessageResources object could not be
* found.
*/
public MessageResources retrieveMessageResources(PageContext pageContext, String bundle, boolean checkPageScope) throws JspException {
MessageResources resources = null;
if (bundle == null) {
bundle = Globals.MESSAGES_KEY;
}
if (checkPageScope) {
resources = (MessageResources) pageContext.getAttribute(bundle, PageContext.PAGE_SCOPE);
}
if (resources == null) {
resources = (MessageResources) pageContext.getAttribute(bundle, PageContext.REQUEST_SCOPE);
}
if (resources == null) {
ModuleConfig moduleConfig = getModuleConfig(pageContext);
resources = (MessageResources) pageContext.getAttribute(bundle + moduleConfig.getPrefix(), PageContext.APPLICATION_SCOPE);
}
if (resources == null) {
resources = (MessageResources) pageContext.getAttribute(bundle, PageContext.APPLICATION_SCOPE);
}
if (resources == null) {
JspException e = new JspException(messages.getMessage("message.bundle", bundle));
saveException(pageContext, e);
throw e;
}
return resources;
}
Aggregations