use of org.apache.struts.util.MessageResources in project sonarqube by SonarSource.
the class ActionServlet method initModuleMessageResources.
/**
* <p>Initialize the application <code>MessageResources</code> for the
* specified module.</p>
*
* @param config ModuleConfig information for this module
* @throws ServletException if initialization cannot be performed
* @since Struts 1.1
*/
protected void initModuleMessageResources(ModuleConfig config) throws ServletException {
MessageResourcesConfig[] mrcs = config.findMessageResourcesConfigs();
for (int i = 0; i < mrcs.length; i++) {
if ((mrcs[i].getFactory() == null) || (mrcs[i].getParameter() == null)) {
continue;
}
if (log.isDebugEnabled()) {
log.debug("Initializing module path '" + config.getPrefix() + "' message resources from '" + mrcs[i].getParameter() + "'");
}
String factory = mrcs[i].getFactory();
MessageResourcesFactory.setFactoryClass(factory);
MessageResourcesFactory factoryObject = MessageResourcesFactory.createFactory();
factoryObject.setConfig(mrcs[i]);
MessageResources resources = factoryObject.createResources(mrcs[i].getParameter());
resources.setReturnNull(mrcs[i].getNull());
resources.setEscape(mrcs[i].isEscape());
getServletContext().setAttribute(mrcs[i].getKey() + config.getPrefix(), resources);
}
}
use of org.apache.struts.util.MessageResources 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.util.MessageResources 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.util.MessageResources in project sonarqube by SonarSource.
the class AuthorizeAction method getErrorMessage.
protected String getErrorMessage(ActionContext context, ActionConfig actionConfig) {
ServletActionContext servletActionContext = (ServletActionContext) context;
// Retrieve internal message resources
ActionServlet servlet = servletActionContext.getActionServlet();
MessageResources resources = servlet.getInternal();
return resources.getMessage("notAuthorized", actionConfig.getPath());
}
use of org.apache.struts.util.MessageResources 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