Example usage for java.util ResourceBundle getObject

List of usage examples for java.util ResourceBundle getObject

Introduction

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

Prototype

public final Object getObject(String key) 

Source Link

Document

Gets an object for the given key from this resource bundle or one of its parents.

Usage

From source file:Configuration.java

public static void main(String[] args) {
    ResourceBundle resource = ResourceBundle.getBundle("your.ConfigFile");
    System.out.println(resource.getObject("port"));
    System.out.println(resource.getString("host"));
}

From source file:net.openkoncept.vroom.VroomUtilities.java

public static JSONObject convertObjectToJSONObject(Object object) throws JSONException {
    JSONObject jo = new JSONObject();
    if (object instanceof Character || object instanceof String || object instanceof Boolean
            || object instanceof Short || object instanceof Integer || object instanceof Long
            || object instanceof Float || object instanceof Double || object instanceof java.util.Date
            || object instanceof java.math.BigDecimal || object instanceof java.math.BigInteger) {
        jo.put("value", getValueForJSONObject(object));
    } else if (object instanceof java.util.Map) {
        Map m = (Map) object;
        Iterator iter = m.keySet().iterator();
        while (iter.hasNext()) {
            String key = (String) iter.next();
            jo.put(key, getValueForJSONObject(m.get(key)));
        }/*from   w  w  w.  j  a  v  a2s . c om*/
    } else if (object instanceof Collection) {
        Collection c = (Collection) object;
        Iterator iter = c.iterator();
        JSONArray ja = new JSONArray();
        while (iter.hasNext()) {
            ja.put(getValueForJSONObject(iter.next()));
        }
        jo.put("array", ja);
    } else if (object != null && object.getClass().isArray()) {
        Object[] oa = (Object[]) object;
        JSONArray ja = new JSONArray();
        for (int i = 0; i < oa.length; i++) {
            ja.put(getValueForJSONObject(oa[i]));
        }
        jo.put("array", ja);
    } else if (object instanceof ResourceBundle) {
        ResourceBundle rb = (ResourceBundle) object;
        Enumeration e = rb.getKeys();
        while (e.hasMoreElements()) {
            String key = (String) e.nextElement();
            Object value = getValueForJSONObject(rb.getObject(key));
            jo.put(key, value);
        }
    } else if (object != null) {
        Class clazz = object.getClass();
        PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors(object);
        for (int i = 0; i < pds.length; i++) {
            PropertyDescriptor pd = pds[i];
            String name = pd.getName();
            if (!"class".equals(name) && PropertyUtils.isReadable(object, pd.getName())) {
                try {
                    Object value = PropertyUtils.getProperty(object, name);
                    jo.put(name, getValueForJSONObject(value));
                } catch (Exception e) {
                    // Useless...
                }
            }
        }
    } else {
        jo.put("value", "");
    }
    return jo;
}

From source file:de.micromata.genome.util.i18n.ChainedResourceBundleTranslationResolver.java

@Override
public I18NTranslationProvider getTranslationFor(Locale locale) {
    Map<String, Object> entries = new HashMap<>();
    for (String resId : resIds) {
        ResourceBundle resbundle = ResourceBundle.getBundle(resId, locale);
        for (String key : resbundle.keySet()) {
            entries.putIfAbsent(key, resbundle.getObject(key));
        }/*from ww w . j av a  2s  .  c om*/
    }
    return new MapTranslationProvider(StringUtils.join(resIds, "_"), entries);
}

From source file:dataprocessing.elasticsearch.ElasticSearchClient.java

/** ***************************************************************
 * Constructor//from w w w  .j  a v  a  2s.c  o  m
 */
public ElasticSearchClient() {

    ResourceBundle resourceBundle = ResourceBundle.getBundle("elasticsearch");
    index = resourceBundle.getObject("index").toString();
    type = resourceBundle.getObject("type").toString();
    header = new BasicHeader("CloudMinds", "empty");

    client = RestClient.builder(new HttpHost(resourceBundle.getObject("host").toString(),
            Integer.parseInt(resourceBundle.getObject("port").toString()),
            resourceBundle.getObject("protocol").toString())).build();
}

From source file:cn.edu.zjnu.acm.judge.config.JudgeConfiguration.java

@PostConstruct
public void init() {
    {/*from  ww w.j a  va  2  s  .c om*/
        ResourceBundle bundle = ResourceBundle.getBundle(WEB_PROPERTIES, Locale.US);
        bundle.keySet().forEach(key -> servletContext.setAttribute(key, bundle.getObject(key)));
    }

    contextPath = fixContextPath(servletContext.getContextPath());
    dataFilesPath = Paths.get(getValue("DataFilesPath"));
    workingPath = Paths.get(getValue("WorkingPath"));
    uploadDirectory = Paths.get(getValue("UploadPath"));
    deleteTempFile = Boolean.parseBoolean(getValue("DeleteTempFile"));
}

From source file:de.unentscheidbar.validation.swing.DefaultMessageTextGetter.java

private String getFormatString(ValidationMessage.Id messageId, Locale locale) throws MissingResourceException {

    ResourceBundle bundle = ResourceBundle.getBundle(getBundleName(messageId), locale,
            messageId.getClass().getClassLoader());
    return String.valueOf(bundle.getObject(messageId.name()));
}

From source file:de.unentscheidbar.validation.swing.DefaultMessageTextGetter.java

@Override
public boolean hasText(Id messageId, Locale locale) {

    try {/*from   w  w  w . j  av  a2s.  c om*/
        String bundleName = getBundleName(messageId);
        ResourceBundle bundle = ResourceBundle.getBundle(bundleName, locale,
                messageId.getClass().getClassLoader(), STRICT_CONTROL);
        Object resource = bundle.getObject(messageId.name());
        return resource != null;
    } catch (MissingResourceException e) {
        return false;
    }
}

From source file:fr.hoteia.qalingo.core.service.impl.ReferentialDataServiceImpl.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();
        mapByLocale.put(key, (String) bundleByLocale.getObject(key));
    }/*ww  w. j  a v  a  2  s .  co m*/
    return mapByLocale;
}

From source file:org.jfree.chart.demo.JFreeChartDemo.java

/**
 * Creates a menubar.//from  w  w w . jav a2 s. c o  m
 *
 * @param resources  localised resources.
 *
 * @return the menu bar.
 */
private JMenuBar createMenuBar(final ResourceBundle resources) {

    // create the menus
    final JMenuBar menuBar = new JMenuBar();

    String label;
    Character mnemonic;

    // first the file menu
    label = resources.getString("menu.file");
    mnemonic = (Character) resources.getObject("menu.file.mnemonic");
    final JMenu fileMenu = new JMenu(label, true);
    fileMenu.setMnemonic(mnemonic.charValue());

    label = resources.getString("menu.file.exit");
    mnemonic = (Character) resources.getObject("menu.file.exit.mnemonic");
    final JMenuItem exitItem = new JMenuItem(label, mnemonic.charValue());
    exitItem.setActionCommand(EXIT_COMMAND);
    exitItem.addActionListener(this);
    fileMenu.add(exitItem);

    // then the help menu
    label = resources.getString("menu.help");
    mnemonic = (Character) resources.getObject("menu.help.mnemonic");
    final JMenu helpMenu = new JMenu(label);
    helpMenu.setMnemonic(mnemonic.charValue());

    label = resources.getString("menu.help.about");
    mnemonic = (Character) resources.getObject("menu.help.about.mnemonic");
    final JMenuItem aboutItem = new JMenuItem(label, mnemonic.charValue());
    aboutItem.setActionCommand(ABOUT_COMMAND);
    aboutItem.addActionListener(this);
    helpMenu.add(aboutItem);

    // finally, glue together the menu and return it
    menuBar.add(fileMenu);
    menuBar.add(helpMenu);

    return menuBar;

}

From source file:kg.apc.jmeter.config.redis.RedisDataSet.java

/**
 * Override the setProperty method in order to convert
 * the original String calcMode property.
 * This used the locale-dependent display value, so caused
 * problems when the language was changed.
 * Note that the calcMode StringProperty is replaced with an IntegerProperty
 * so the conversion only needs to happen once.
 *//*from   w  w  w  . j a v a 2s  .c  o  m*/
@Override
public void setProperty(JMeterProperty property) {
    if (property instanceof StringProperty) {
        final String pn = property.getName();
        if (pn.equals("getMode")) {
            final Object objectValue = property.getObjectValue();
            try {
                final BeanInfo beanInfo = Introspector.getBeanInfo(this.getClass());
                final ResourceBundle rb = (ResourceBundle) beanInfo.getBeanDescriptor()
                        .getValue(GenericTestBeanCustomizer.RESOURCE_BUNDLE);
                for (Enum<GetMode> e : GetMode.values()) {
                    final String propName = e.toString();
                    if (objectValue.equals(rb.getObject(propName))) {
                        final int tmpMode = e.ordinal();
                        if (log.isDebugEnabled()) {
                            log.debug("Converted " + pn + "=" + objectValue + " to mode=" + tmpMode
                                    + " using Locale: " + rb.getLocale());
                        }
                        super.setProperty(pn, tmpMode);
                        return;
                    }
                }
                log.warn("Could not convert " + pn + "=" + objectValue + " using Locale: " + rb.getLocale());
            } catch (IntrospectionException e) {
                log.error("Could not find BeanInfo", e);
            }
        } else if (pn.equals("whenExhaustedAction")) {
            final Object objectValue = property.getObjectValue();
            try {
                final BeanInfo beanInfo = Introspector.getBeanInfo(this.getClass());
                final ResourceBundle rb = (ResourceBundle) beanInfo.getBeanDescriptor()
                        .getValue(GenericTestBeanCustomizer.RESOURCE_BUNDLE);
                for (Enum<WhenExhaustedAction> e : WhenExhaustedAction.values()) {
                    final String propName = e.toString();
                    if (objectValue.equals(rb.getObject(propName))) {
                        final int tmpMode = e.ordinal();
                        if (log.isDebugEnabled()) {
                            log.debug("Converted " + pn + "=" + objectValue + " to mode=" + tmpMode
                                    + " using Locale: " + rb.getLocale());
                        }
                        super.setProperty(pn, tmpMode);
                        return;
                    }
                }
                log.warn("Could not convert " + pn + "=" + objectValue + " using Locale: " + rb.getLocale());
            } catch (IntrospectionException e) {
                log.error("Could not find BeanInfo", e);
            }
        }
    }
    super.setProperty(property);
}