Example usage for java.util ResourceBundle keySet

List of usage examples for java.util ResourceBundle keySet

Introduction

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

Prototype

Set keySet

To view the source code for java.util ResourceBundle keySet.

Click Source Link

Document

A Set of the keys contained only in this ResourceBundle.

Usage

From source file:org.hoteia.qalingo.core.service.ReferentialDataService.java

private Map<String, String> buildMap(final ResourceBundle bundleByLocale) {
    Map<String, String> mapByLocale = new HashMap<String, String>();
    Set<String> keyList = bundleByLocale.keySet();
    for (Iterator<String> iterator = keyList.iterator(); iterator.hasNext();) {
        final String key = (String) iterator.next();
        try {/*from w ww  .j  a v  a2 s.  co  m*/
            mapByLocale.put(key, new String(bundleByLocale.getString(key).getBytes("ISO-8859-1"), "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            logger.error("", e);
        }
    }
    return mapByLocale;
}

From source file:org.mili.core.resource.ResourceUtilImpl.java

private void copyResourceBundleInResMap(ResourceBundle bundle, String baseName, Locale locale) {
    Map<String, String> resMap = getResourceMap(baseName, locale);
    for (String key : bundle.keySet()) {
        resMap.put(key, bundle.getString(key));
    }/*from   w w w .ja v  a 2 s . c  o  m*/
}

From source file:org.kuali.rice.core.impl.services.ConfigurationServiceImpl.java

/**
 * Default constructor// w w w  .  ja va  2s  .co  m
 */
public ConfigurationServiceImpl() {
    this.propertyHolder.getHeldProperties().putAll(ConfigContext.getCurrentContextConfig().getProperties());

    // TODO: remove loading of property files once KNS legacy code is removed
    String propertyConfig = (String) ConfigContext.getCurrentContextConfig().getProperties()
            .get(MESSAGE_RESOURCES);
    propertyConfig = removeSpacesAround(propertyConfig);

    String[] bundleNames = StringUtils.split(propertyConfig, ",");
    for (String bundleName : bundleNames) {
        ResourceBundle bundle = ResourceBundle.getBundle(bundleName);

        for (String key : bundle.keySet()) {
            String message = bundle.getString(key);
            this.propertyHolder.getHeldProperties().put(key, message);
        }
    }
}

From source file:org.mypsycho.util.PropertiesLoader.java

protected Bundle createBundle(Class<?> type, Locale locale) {
    Bundle props = new Bundle(type.getName(), locale, type.getClassLoader());

    Class<?> until = until(type);
    if (until == null) {
        until = Object.class;
    }/*w  w w. j  ava  2 s. c  om*/

    List<ResourceBundle> bundles = new LinkedList<ResourceBundle>();
    for (Class<?> c = type; (c != null) && !c.equals(until); c = c.getSuperclass()) {
        String basename = c.getName();

        try {
            bundles.add(0, ResourceBundle.getBundle(basename, locale, getClassLoader(c), RES_CONTROL));
        } catch (MissingResourceException e) {
            handle("noBundle", basename);
        }
    }

    for (ResourceBundle bundle : bundles) {
        for (String key : bundle.keySet()) {
            props.putDefinition(key, bundle.getString(key));
        }
    }

    return props;
}

From source file:org.mypsycho.util.PropertiesLoader.java

protected Bundle createBundle(String basename, Locale locale, ClassLoader loader) {
    Bundle props = new Bundle(basename, locale, loader);

    try {//from  w w w  .  ja  v  a 2  s . c  o m
        ResourceBundle bundle = ResourceBundle.getBundle(basename, locale, loader, RES_CONTROL);
        for (String key : bundle.keySet()) {
            props.putDefinition(key, bundle.getString(key));
        }
    } catch (MissingResourceException e) {
        handle("noBundle", basename);
    }

    return props;
}

From source file:com.opengamma.language.object.ObjectFunctionProvider.java

@Override
protected final void loadDefinitions(final Collection<MetaFunction> definitions) {
    s_logger.info("Starting loadDefinitions with {} in collection", definitions.size());
    final Map<String, ObjectInfo> functions = new HashMap<String, ObjectInfo>();
    final ResourceBundle mapping = getResourceBundle();
    for (final String key : mapping.keySet()) {
        int dot = key.lastIndexOf('.');
        final String clazz = key.substring(0, dot);
        final String attribute = key.substring(dot + 1);
        final String value = mapping.getString(key);
        ObjectInfo func = functions.get(clazz);
        if (func == null) {
            try {
                func = new ObjectInfo(Class.forName(clazz));
            } catch (Throwable t) {
                throw new OpenGammaRuntimeException(
                        "Class '" + clazz + "' not available for function definition", t);
            }/*  w w  w.j  ava2s  .  c o m*/
            functions.put(clazz, func);
        }
        if ("_abstract".equals(attribute)) {
            func.setAbstract("true".equalsIgnoreCase(value));
        } else if ("_description".equals(attribute)) {
            func.setConstructorDescription(value);
        } else if ("_label".equals(attribute)) {
            func.setLabel(value);
        } else if ("_name".equals(attribute)) {
            func.setName(value);
        } else if ("_category".equals(attribute)) {
            func.setCategory(value);
        } else if ("_parameters".equals(attribute)) {
            func.setConstructorParameters(value.split(",\\s*"));
        } else {
            func.setAttributeLabel(attribute, value);
        }
    }
    final Collection<ObjectInfo> objects = functions.values();
    for (ObjectInfo object : objects) {
        Class<?> superClazz = object.getObjectClass().getSuperclass();
        while ((superClazz != null) && !Object.class.equals(superClazz)) {
            final ObjectInfo superclass = functions.get(superClazz.getName());
            if (superclass != null) {
                object.setSuperclass(superclass);
                break;
            }
            superClazz = superClazz.getSuperclass();
        }
    }
    loadDefinitions(objects, definitions);
    s_logger.debug("Finished loadDefinitions with {} definitions in collection", definitions.size());
}

From source file:se.streamsource.streamflow.web.application.pdf.CasePdfGenerator.java

private void generateCaselog(Input<CaseLogEntryValue, RuntimeException> caselog) throws IOException {
    // TODO This needs to be cleaned up. Translations should be in a better place!
    ResourceBundle bnd = ResourceBundle.getBundle(MessagesContext.class.getName(), locale);
    final Map<String, String> translations = new HashMap<String, String>();
    for (String key : bnd.keySet()) {
        translations.put(key, bnd.getString(key));
    }//from   www . j ava 2  s . c o m

    caselog.transferTo(new Output<CaseLogEntryValue, IOException>() {
        public <SenderThrowableType extends Throwable> void receiveFrom(
                Sender<? extends CaseLogEntryValue, SenderThrowableType> sender)
                throws IOException, SenderThrowableType {
            document.changeColor(headingColor).println(bundle.getString("caselog"), valueFontBold)
                    .changeColor(Color.BLACK);

            sender.sendTo(new Receiver<CaseLogEntryValue, IOException>() {
                public void receive(CaseLogEntryValue entry) throws IOException {
                    UnitOfWork uow = module.unitOfWorkFactory().currentUnitOfWork();
                    String label = uow.get(Describable.class, entry.createdBy().get().identity())
                            .getDescription() + ", "
                            + DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, locale)
                                    .format(entry.createdOn().get())
                            + ": ";

                    document.print(label, valueFontBold)
                            .print(Translator.translate(entry.message().get(), translations), valueFont)
                            .print("", valueFont);
                }
            });
        }
    });
}

From source file:org.itracker.services.implementations.ConfigurationServiceImpl.java

public void initializeConfiguration() {

    // TODO when current version is outdated?
    long current = SystemConfigurationUtilities.getVersionAsLong(getItrackerVersion());

    long initialized = SystemConfigurationUtilities.getVersionAsLong(getInitializedVersionString());

    if (0 == initialized) {

        logger.info("System does not appear to be initialized, initializing system configuration.");

        ResourceBundle baseLanguage = ITrackerResources
                .getBundle(ITrackerResources.getLocale(ITrackerResources.BASE_LOCALE));
        getLanguage(ITrackerResources.getLocale(ITrackerResources.BASE_LOCALE));

        if (baseLanguage == null) {

            throw new IllegalStateException(
                    "Languages must be initialized before the system configuration can be loaded.");

        }/*from  w ww .ja  v a  2s  . com*/

        // Remove any previous configuration information, possibly left
        // over from previous failed initialization

        logger.debug("Removing previous incomplete initialization information.");

        removeConfigurationItems(Configuration.Type.status);

        removeConfigurationItems(Configuration.Type.severity);

        removeConfigurationItems(Configuration.Type.resolution);

        Set<String> keys = baseLanguage.keySet();
        for (final String key : keys) {
            if (key.startsWith(ITrackerResources.KEY_BASE_RESOLUTION)) {

                try {

                    String resolutionString = key.substring(20);
                    if (logger.isDebugEnabled()) {
                        logger.debug("Adding new configuration resolution value: " + resolutionString);
                    }
                    int resolutionNumber = Integer.parseInt(resolutionString);

                    createConfigurationItem(new Configuration(Configuration.Type.resolution, resolutionString,
                            getItrackerVersion(), resolutionNumber));

                } catch (RuntimeException e) {

                    logger.error("Unable to load resolution value: " + key, e);
                    throw e;

                }

            }

            if (key.startsWith(ITrackerResources.KEY_BASE_SEVERITY)) {

                try {

                    String severityString = key.substring(18);

                    logger.debug("Adding new configuration severity value: " + severityString);

                    int severityNumber = Integer.parseInt(severityString);

                    createConfigurationItem(new Configuration(Configuration.Type.severity, severityString,
                            getItrackerVersion(), severityNumber));

                } catch (RuntimeException e) {

                    logger.error("Unable to load severity value: " + key, e);
                    throw e;
                }

            }

            if (key.startsWith(ITrackerResources.KEY_BASE_STATUS)) {

                try {

                    String statusString = key.substring(16);

                    logger.debug("Adding new configuration status value: " + statusString);

                    int statusNumber = Integer.parseInt(statusString);

                    createConfigurationItem(new Configuration(Configuration.Type.status, statusString,
                            getItrackerVersion(), statusNumber));
                } catch (RuntimeException e) {
                    logger.error("Unable to load status value: " + key, e);
                    throw e;
                }
            }
        }

        createConfigurationItem(new Configuration(Configuration.Type.initialized, "1", getItrackerVersion()));
    }

}