Search in sources :

Example 1 with MessageResourcesConfig

use of org.apache.struts.config.MessageResourcesConfig 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 MessageResourcesConfig

use of org.apache.struts.config.MessageResourcesConfig in project sonarqube 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);
    }
}
Also used : ModuleConfig(org.apache.struts.config.ModuleConfig) MessageResourcesConfig(org.apache.struts.config.MessageResourcesConfig)

Example 3 with MessageResourcesConfig

use of org.apache.struts.config.MessageResourcesConfig in project sonarqube by SonarSource.

the class ModuleConfigImpl method freeze.

/**
     * <p> Freeze the configuration of this module.  After this method
     * returns, any attempt to modify the configuration will return an
     * IllegalStateException. </p>
     */
public void freeze() {
    super.freeze();
    ActionConfig[] aconfigs = findActionConfigs();
    for (int i = 0; i < aconfigs.length; i++) {
        aconfigs[i].freeze();
    }
    matcher = new ActionConfigMatcher(aconfigs);
    getControllerConfig().freeze();
    ExceptionConfig[] econfigs = findExceptionConfigs();
    for (int i = 0; i < econfigs.length; i++) {
        econfigs[i].freeze();
    }
    FormBeanConfig[] fbconfigs = findFormBeanConfigs();
    for (int i = 0; i < fbconfigs.length; i++) {
        fbconfigs[i].freeze();
    }
    ForwardConfig[] fconfigs = findForwardConfigs();
    for (int i = 0; i < fconfigs.length; i++) {
        fconfigs[i].freeze();
    }
    MessageResourcesConfig[] mrconfigs = findMessageResourcesConfigs();
    for (int i = 0; i < mrconfigs.length; i++) {
        mrconfigs[i].freeze();
    }
    PlugInConfig[] piconfigs = findPlugInConfigs();
    for (int i = 0; i < piconfigs.length; i++) {
        piconfigs[i].freeze();
    }
}
Also used : ActionConfig(org.apache.struts.config.ActionConfig) ExceptionConfig(org.apache.struts.config.ExceptionConfig) FormBeanConfig(org.apache.struts.config.FormBeanConfig) PlugInConfig(org.apache.struts.config.PlugInConfig) ForwardConfig(org.apache.struts.config.ForwardConfig) ActionConfigMatcher(org.apache.struts.config.ActionConfigMatcher) MessageResourcesConfig(org.apache.struts.config.MessageResourcesConfig)

Example 4 with MessageResourcesConfig

use of org.apache.struts.config.MessageResourcesConfig in project sonarqube by SonarSource.

the class TestPropertyMessageResources method createMessageResources.

/**
     * Create the PropertyMessageResources.
     */
private MessageResources createMessageResources(String file, boolean returnNull, String mode) {
    MessageResourcesConfig config = new MessageResourcesConfig();
    config.setNull(returnNull);
    if (mode != null) {
        config.setProperty("mode", mode);
    }
    PropertyMessageResourcesFactory factory = new PropertyMessageResourcesFactory();
    factory.setConfig(config);
    factory.setReturnNull(returnNull);
    return factory.createResources(file);
}
Also used : MessageResourcesConfig(org.apache.struts.config.MessageResourcesConfig)

Aggregations

MessageResourcesConfig (org.apache.struts.config.MessageResourcesConfig)4 ActionConfig (org.apache.struts.config.ActionConfig)1 ActionConfigMatcher (org.apache.struts.config.ActionConfigMatcher)1 ExceptionConfig (org.apache.struts.config.ExceptionConfig)1 FormBeanConfig (org.apache.struts.config.FormBeanConfig)1 ForwardConfig (org.apache.struts.config.ForwardConfig)1 ModuleConfig (org.apache.struts.config.ModuleConfig)1 PlugInConfig (org.apache.struts.config.PlugInConfig)1 MessageResources (org.apache.struts.util.MessageResources)1 MessageResourcesFactory (org.apache.struts.util.MessageResourcesFactory)1