Search in sources :

Example 6 with ModuleConfig

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

Example 7 with ModuleConfig

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

Example 8 with ModuleConfig

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

Example 9 with ModuleConfig

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

Example 10 with ModuleConfig

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

Aggregations

ModuleConfig (org.apache.struts.config.ModuleConfig)34 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 JspException (javax.servlet.jsp.JspException)5 Iterator (java.util.Iterator)4 ActionConfig (org.apache.struts.config.ActionConfig)4 ForwardConfig (org.apache.struts.config.ForwardConfig)4 MessageResources (org.apache.struts.util.MessageResources)4 ArrayList (java.util.ArrayList)3 Enumeration (java.util.Enumeration)2 List (java.util.List)2 Locale (java.util.Locale)2 ServletException (javax.servlet.ServletException)2 ActionServlet (org.apache.struts.action.ActionServlet)2 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Map (java.util.Map)1 ServletContext (javax.servlet.ServletContext)1