Example usage for java.util ResourceBundle getBundle

List of usage examples for java.util ResourceBundle getBundle

Introduction

In this page you can find the example usage for java.util ResourceBundle getBundle.

Prototype

@CallerSensitive
public static ResourceBundle getBundle(String baseName, Locale locale, ClassLoader loader) 

Source Link

Document

Gets a resource bundle using the specified base name, locale, and class loader.

Usage

From source file:mondrian.gui.Workbench.java

public static I18n getGlobalResourceConverter() {
    if (resourceConverter == null) {
        ClassLoader currentClassLoader;

        ResourceBundle localGuiResourceBundle;
        ResourceBundle localTextResourceBundle;

        currentClassLoader = Workbench.class.getClassLoader();

        localGuiResourceBundle = ResourceBundle.getBundle(GUIResourceName, Locale.getDefault(),
                currentClassLoader);/*from  www  .ja  v a2 s .  c o m*/
        localTextResourceBundle = ResourceBundle.getBundle(TextResourceName, Locale.getDefault(),
                currentClassLoader);

        resourceConverter = new I18n(localGuiResourceBundle, localTextResourceBundle);
    }
    return resourceConverter;
}

From source file:com.projity.menu.MenuManager.java

private MenuManager(ActionMap rootActionMap) {
    this.rootActionMap = rootActionMap;
    if (bundle == null) {
        try {//from  w w  w .  j  a v a  2s .c  om
            DirectoryClassLoader dir = new DirectoryClassLoader();
            if (dir.isValid()) {
                log.info("Loading menu bundle from file: " + MENU_BUNDLE_CONF_DIR + "," + Locale.getDefault()
                        + "," + dir);
                bundle = ResourceBundle.getBundle(MENU_BUNDLE_CONF_DIR, Locale.getDefault(), dir);

            }
        } catch (Exception e) {
        }
        if (bundle == null) {
            log.info("Loading menu bundle from classloader: " + MENU_BUNDLE + "," + Locale.getDefault() + ","
                    + ClassLoaderUtils.getLocalClassLoader());
            bundle = ResourceBundle.getBundle(MENU_BUNDLE, Locale.getDefault(),
                    ClassLoaderUtils.getLocalClassLoader());
        }
    }
    menuFactory = new ExtMenuFactory(bundle, rootActionMap);
    toolBarFactory = new ExtToolBarFactory(bundle, rootActionMap);
}

From source file:com.liferay.portal.servlet.PortletContextListener.java

public void contextInitialized(ServletContextEvent sce) {
    try {/*from w  w w  .j  a  v  a 2 s.com*/

        // Servlet context

        ServletContext ctx = sce.getServletContext();

        _servletContextName = StringUtil.replace(ctx.getServletContextName(), StringPool.SPACE,
                StringPool.UNDERLINE);

        // Company ids

        _companyIds = StringUtil.split(ctx.getInitParameter("company_id"));

        // Class loader

        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();

        // Initialize portlets

        String[] xmls = new String[] { Http.URLtoString(ctx.getResource("/WEB-INF/portlet.xml")),
                Http.URLtoString(ctx.getResource("/WEB-INF/liferay-portlet.xml")) };

        _portlets = PortletManagerUtil.initWAR(_servletContextName, xmls);

        // Portlet context wrapper

        Iterator itr1 = _portlets.iterator();

        while (itr1.hasNext()) {
            Portlet portlet = (Portlet) itr1.next();

            javax.portlet.Portlet portletInstance = (javax.portlet.Portlet) contextClassLoader
                    .loadClass(portlet.getPortletClass()).newInstance();

            Indexer indexerInstance = null;
            if (Validator.isNotNull(portlet.getIndexerClass())) {
                indexerInstance = (Indexer) contextClassLoader.loadClass(portlet.getIndexerClass())
                        .newInstance();
            }

            Scheduler schedulerInstance = null;
            if (Validator.isNotNull(portlet.getSchedulerClass())) {
                schedulerInstance = (Scheduler) contextClassLoader.loadClass(portlet.getSchedulerClass())
                        .newInstance();
            }

            PreferencesValidator prefsValidator = null;
            if (Validator.isNotNull(portlet.getPreferencesValidator())) {
                prefsValidator = (PreferencesValidator) contextClassLoader
                        .loadClass(portlet.getPreferencesValidator()).newInstance();

                try {
                    if (GetterUtil.getBoolean(PropsUtil.get(PropsUtil.PREFERENCE_VALIDATE_ON_STARTUP))) {

                        prefsValidator.validate(
                                PortletPreferencesSerializer.fromDefaultXML(portlet.getDefaultPreferences()));
                    }
                } catch (Exception e1) {
                    _log.warn("Portlet with the name " + portlet.getPortletId()
                            + " does not have valid default preferences");
                }
            }

            Map resourceBundles = null;

            if (Validator.isNotNull(portlet.getResourceBundle())) {
                resourceBundles = CollectionFactory.getHashMap();

                Iterator itr2 = portlet.getSupportedLocales().iterator();

                while (itr2.hasNext()) {
                    String supportedLocale = (String) itr2.next();

                    Locale locale = new Locale(supportedLocale);

                    try {
                        ResourceBundle resourceBundle = ResourceBundle.getBundle(portlet.getResourceBundle(),
                                locale, contextClassLoader);

                        resourceBundles.put(locale.getLanguage(), resourceBundle);
                    } catch (MissingResourceException mre) {
                        _log.warn(mre.getMessage());
                    }
                }
            }

            Map customUserAttributes = CollectionFactory.getHashMap();

            Iterator itr2 = portlet.getCustomUserAttributes().entrySet().iterator();

            while (itr2.hasNext()) {
                Map.Entry entry = (Map.Entry) itr2.next();

                String attrName = (String) entry.getKey();
                String attrCustomClass = (String) entry.getValue();

                customUserAttributes.put(attrCustomClass,
                        contextClassLoader.loadClass(attrCustomClass).newInstance());
            }

            PortletContextWrapper pcw = new PortletContextWrapper(portlet.getPortletId(), ctx, portletInstance,
                    indexerInstance, schedulerInstance, prefsValidator, resourceBundles, customUserAttributes);

            PortletContextPool.put(portlet.getPortletId(), pcw);
        }

        // Portlet class loader

        String servletPath = ctx.getRealPath("/");
        if (!servletPath.endsWith("/") && !servletPath.endsWith("\\")) {
            servletPath += "/";
        }

        File servletClasses = new File(servletPath + "WEB-INF/classes");
        File servletLib = new File(servletPath + "WEB-INF/lib");

        List urls = new ArrayList();

        if (servletClasses.exists()) {
            urls.add(new URL("file:" + servletClasses + "/"));
        }

        if (servletLib.exists()) {
            String[] jars = FileUtil.listFiles(servletLib);

            for (int i = 0; i < jars.length; i++) {
                urls.add(new URL("file:" + servletLib + "/" + jars[i]));
            }
        }

        URLClassLoader portletClassLoader = new URLClassLoader((URL[]) urls.toArray(new URL[0]),
                contextClassLoader);

        ctx.setAttribute(WebKeys.PORTLET_CLASS_LOADER, portletClassLoader);

        // Portlet display

        String xml = Http.URLtoString(ctx.getResource("/WEB-INF/liferay-display.xml"));

        Map newCategories = PortletManagerUtil.getWARDisplay(_servletContextName, xml);

        for (int i = 0; i < _companyIds.length; i++) {
            String companyId = _companyIds[i];

            Map oldCategories = (Map) WebAppPool.get(companyId, WebKeys.PORTLET_DISPLAY);

            Map mergedCategories = PortalUtil.mergeCategories(oldCategories, newCategories);

            WebAppPool.put(companyId, WebKeys.PORTLET_DISPLAY, mergedCategories);
        }

        // Reinitialize portal properties

        PropsUtil.init();
    } catch (Exception e2) {
        Logger.error(this, e2.getMessage(), e2);
    }
}