Search in sources :

Example 1 with MessageResources

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);
    }
}
Also used : MessageResources(org.apache.struts.util.MessageResources) MessageResourcesFactory(org.apache.struts.util.MessageResourcesFactory) MessageResourcesConfig(org.apache.struts.config.MessageResourcesConfig)

Example 2 with MessageResources

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);
}
Also used : MessageResources(org.apache.struts.util.MessageResources) ModuleConfig(org.apache.struts.config.ModuleConfig)

Example 3 with MessageResources

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());
}
Also used : MessageResources(org.apache.struts.util.MessageResources) ServletContext(javax.servlet.ServletContext) ModuleConfig(org.apache.struts.config.ModuleConfig)

Example 4 with MessageResources

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());
}
Also used : MessageResources(org.apache.struts.util.MessageResources) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) ActionServlet(org.apache.struts.action.ActionServlet)

Example 5 with MessageResources

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;
}
Also used : JspException(javax.servlet.jsp.JspException) MessageResources(org.apache.struts.util.MessageResources) ModuleConfig(org.apache.struts.config.ModuleConfig)

Aggregations

MessageResources (org.apache.struts.util.MessageResources)17 Locale (java.util.Locale)4 ServletContext (javax.servlet.ServletContext)4 ModuleConfig (org.apache.struts.config.ModuleConfig)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 JspException (javax.servlet.jsp.JspException)2 Arg (org.apache.commons.validator.Arg)2 Msg (org.apache.commons.validator.Msg)2 ActionServlet (org.apache.struts.action.ActionServlet)2 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)2 MessageResourcesFactory (org.apache.struts.util.MessageResourcesFactory)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Field (org.apache.commons.validator.Field)1 ValidatorAction (org.apache.commons.validator.ValidatorAction)1 Var (org.apache.commons.validator.Var)1 ActionMapping (org.apache.struts.action.ActionMapping)1