Example usage for java.util PropertyResourceBundle PropertyResourceBundle

List of usage examples for java.util PropertyResourceBundle PropertyResourceBundle

Introduction

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

Prototype

@SuppressWarnings({ "unchecked", "rawtypes" })
public PropertyResourceBundle(Reader reader) throws IOException 

Source Link

Document

Creates a property resource bundle from a java.io.Reader Reader .

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    // Prepare content for simulating property files
    String fileContent = "s1=1\n" + "s2=Main\n" + "s3=Fri Jan 31";
    InputStream propStream = new StringBufferInputStream(fileContent);

    PropertyResourceBundle bundle = new PropertyResourceBundle(propStream);

    // Get resource keys
    Enumeration keys = bundle.getKeys();
    while (keys.hasMoreElements()) {
        System.out.println("Bundle key: " + keys.nextElement());
    }//w  ww.  j av  a  2  s .  c o m
}

From source file:cz.lbenda.dataman.rc.DatamanApp.java

public static void main(String[] args) {
    CommandLine cmd = commandLine(args);
    ConfigurationRW.createInstance("dataman", null);
    PropertyResourceBundle prb = null;
    try {/*from w  w  w.j a  v a 2 s.c  o  m*/
        prb = new PropertyResourceBundle(DatamanApp.class.getResourceAsStream("messages.properties"));
    } catch (IOException e) {
        LOG.error("The messages wasn't loaded", e);
    }
    MessageFactory.createInstance(prb);
    MessageFactory.getInstance().initializePackage("cz.lbenda");

    if (cz.lbenda.dataman.Constants.HEADLESS) {
        DatamanHeadless headless = new DatamanHeadless();
        headless.launch(cmd);
    } else {
        launch(args);
    }
}

From source file:com.diversityarrays.kdxplore.trials.TrialSelectionDialog.java

static public void main(String[] args) {

    Transformer<BackgroundRunner, TrialSearchOptionsPanel> factory = new Transformer<BackgroundRunner, TrialSearchOptionsPanel>() {
        @Override//from www.  ja  v  a 2s .c  o m
        public TrialSearchOptionsPanel transform(BackgroundRunner backgroundRunner) {
            return TrialSelectionSearchOptionsPanel.create(backgroundRunner);
        }
    };

    boolean test = false;
    if (test) {
        @SuppressWarnings("unchecked")
        TrialSelectionDialog tsd = new TrialSelectionDialog(null, "Test Tree", null, Collections.EMPTY_LIST, //$NON-NLS-1$
                factory);
        //         tsd.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        tsd.setVisible(true);
    } else {

        File propertiesFile = new File(System.getProperty("user.home"), //$NON-NLS-1$
                "LoginDialog.properties"); //$NON-NLS-1$
        //.getBundle("LoginDialog"); //, Locale.getDefault());

        ResourceBundle bundle = null;

        if (propertiesFile.exists()) {
            try {
                bundle = new PropertyResourceBundle(new FileReader(propertiesFile));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                System.exit(1);
            } catch (IOException e) {
                e.printStackTrace();
                System.exit(1);
            }
        }

        Preferences loginPreferences = KdxplorePreferences.getInstance().getPreferences();
        //         Preferences loginPreferences = Preferences.userNodeForPackage(KdxConstants.class);

        LoginDialog ld = new LoginDialog(null, "Login Please", loginPreferences, bundle); //$NON-NLS-1$
        ld.setVisible(true);
        DALClient client = ld.getDALClient();
        if (client != null) {
            @SuppressWarnings("unchecked")
            TrialSelectionDialog tsd = new TrialSelectionDialog(null, "Test Tree", client, //$NON-NLS-1$
                    Collections.EMPTY_LIST, factory);
            //            tsd.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            tsd.setVisible(true);
            if (tsd.trialRecords == null) {
                System.out.println("Cancelled !"); //$NON-NLS-1$
            } else {
                System.out.println(tsd.trialRecords.length + " chosen: "); //$NON-NLS-1$
                for (TrialPlus tr : tsd.trialRecords) {
                    System.out.println("\t" + tr.getTrialId() + ": " + tr.getTrialName()); //$NON-NLS-1$ //$NON-NLS-2$
                }
                System.out.println("- - -"); //$NON-NLS-1$
            }
        }
    }
    System.exit(0);
}

From source file:com.github.jankrause.javadoctools.connectors.DbConnector.java

private static ResourceBundle createResourceBundle() {
    InputStream resourcesFileAsStream = null;

    try {/*from   w  w  w  . j a  v a  2  s .c o  m*/
        resourcesFileAsStream = new FileInputStream(DB_PROPERTY_FILE);
        return new PropertyResourceBundle(resourcesFileAsStream);
    } catch (IOException ioEx) {
        throw new RuntimeException("Could not read the expected resource-file " + DB_PROPERTY_FILE, ioEx);
    } finally {
        IOUtils.closeQuietly(resourcesFileAsStream);
    }
}

From source file:pt.webdetails.cda.Messages.java

private static ResourceBundle getBundle() {
    Locale locale = LocaleHelper.getLocale();
    ResourceBundle bundle = Messages.locales.get(locale);
    if (bundle == null) {
        //      IPentahoSession session = new StandaloneSession("dashboards messages"); //$NON-NLS-1$
        InputStream in = null;//from   w  ww  .  j  av a2s .  c  o  m
        try {
            in = CdaEngine.getRepo().getPluginSystemReader(null).getFileInputStream("messages.properties"); //$NON-NLS-1$
            bundle = new PropertyResourceBundle(in);
            Messages.locales.put(locale, bundle);
        } catch (Exception e) {
            Logger.error(Messages.class.getName(), "Could not get localization bundle", e); //$NON-NLS-1$
        } finally {
            IOUtils.closeQuietly(in);
        }
    }
    return bundle;
}

From source file:ru.mystamps.web.tests.TranslationUtils.java

private static ResourceBundle getResourceBundleForFile(String filename) {
    FileInputStream stream = null;
    try {//from  w w w .ja v  a  2  s .  c o  m
        File file = new File(TranslationUtils.class.getClassLoader().getResource(filename).toURI());
        stream = new FileInputStream(file);
        return new PropertyResourceBundle(stream);

    } catch (IOException | URISyntaxException ex) {
        throw new RuntimeException(ex);

    } finally {
        IOUtils.closeQuietly(stream);
    }
}

From source file:org.pentaho.cdf.Messages.java

private static ResourceBundle getBundle() {

    Locale locale = CdfEngine.getEnvironment().getLocale();
    ResourceBundle bundle = Messages.locales.get(locale);
    if (bundle == null) {

        try {/*from   w ww .j a v  a2s .  com*/
            IReadAccess access = CdfEngine.getPluginSystemReader(null);

            if (access.fileExists(CdfConstants.GLOBAL_MESSAGES_PROPERTIES_FILE)) {
                InputStream in = access.getFileInputStream(CdfConstants.GLOBAL_MESSAGES_PROPERTIES_FILE);
                bundle = new PropertyResourceBundle(in);
                Messages.locales.put(locale, bundle);
            }
        } catch (Exception e) {
            logger.error("Could not get localization bundle", e); //$NON-NLS-1$
        }
    }
    return bundle;
}

From source file:pt.webdetails.cdf.dd.Messages.java

private static ResourceBundle getBundle() {
    Locale locale = CdeEngine.getInstance().getEnvironment().getLocale();
    ResourceBundle bundle = Messages.locales.get(locale);
    if (bundle == null) {
        InputStream in = null;/*  w ww .jav a2 s  .c o m*/
        try {
            String messagesPath = CdeEnvironment.getPluginResourceLocationManager()
                    .getMessagePropertiesResourceLocation();
            in = CdeEnvironment.getPluginSystemReader().getFileInputStream(messagesPath);
            bundle = new PropertyResourceBundle(in);
            Messages.locales.put(locale, bundle);
        } catch (Exception e) {
            logger.error("Could not get localization bundle", e); //$NON-NLS-1$
        } finally {
            IOUtils.closeQuietly(in);
        }
    }
    return bundle;
}

From source file:org.apache.jsp.mantle.launch.launch_jsp.java

private static ResourceBundle getBundle(String messageUri) {
       Locale locale = LocaleHelper.getLocale();
       IPentahoSession session = new StandaloneSession("dashboards messages"); //$NON-NLS-1$
       try {/*from   w w  w . j  ava2  s .  co  m*/
           if (messageUri.startsWith("content/")) {
               messageUri = "system/" + messageUri.substring(8); //$NON-NLS-1$
           }
           InputStream in = PentahoSystem.get(ISolutionRepository.class, session)
                   .getResourceInputStream(messageUri, true, ISolutionRepository.ACTION_EXECUTE);
           return new PropertyResourceBundle(in);
       } catch (Exception e) {
           Logger.error(Messages.class.getName(), "Could not get localization bundle", e); //$NON-NLS-1$
       }
       return null;
   }

From source file:org.openo.msb.wrapper.util.JedisUtil.java

private static void initialPool() {
    try {/*  ww w .  j  ava2  s  .c  o  m*/
        JedisPoolConfig config = new JedisPoolConfig();

        //         String pathtest=JedisUtil.class.getResource("").getPath();
        //         String path ="/"+ pathtest.substring(0, pathtest.indexOf("assembly")).replace("file:/", "") +"assembly/"+defaultWorkspace;

        File propertiesFile = new File(propertiesPath);

        if (propertiesFile.exists()) {

            BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(propertiesPath));
            ResourceBundle bundle = new PropertyResourceBundle(inputStream);

            if (bundle == null) {
                throw new IllegalArgumentException("[redis.properties] is not found!");
            }

            String strHost = bundle.getString("redis.host");
            if (StringUtils.isNotEmpty(strHost)) {
                host = strHost;
            }
            String strPort = bundle.getString("redis.port");
            if (StringUtils.isNotEmpty(strPort)) {
                port = Integer.valueOf(strPort);
            }

            String strTimeout = bundle.getString("redis.connectionTimeout");
            if (StringUtils.isNotEmpty(strTimeout)) {
                connectionTimeout = Integer.valueOf(strTimeout);
            }

            //               serverIp=bundle.getString("server.ip");
            serverPort = Integer.valueOf(bundle.getString("server.port"));

            String strDbIndex = bundle.getString("redis.db_index");
            if (StringUtils.isNotEmpty(strDbIndex)) {
                DEFAULT_DB_INDEX = Integer.valueOf(strDbIndex);
            }

            String strMaxTotal = bundle.getString("redis.pool.maxTotal");
            if (StringUtils.isNotEmpty(strMaxTotal)) {
                config.setMaxTotal(Integer.valueOf(strMaxTotal));
            }

            String strMaxIdle = bundle.getString("redis.pool.maxIdle");
            if (StringUtils.isNotEmpty(strMaxIdle)) {
                config.setMaxIdle(Integer.valueOf(strMaxIdle));
            }

            String strMaxWaitMillis = bundle.getString("redis.pool.maxWaitMillis");
            if (StringUtils.isNotEmpty(strMaxWaitMillis)) {
                config.setMaxWaitMillis(Long.valueOf(strMaxWaitMillis));
            }

            String strTestOnBorrow = bundle.getString("redis.pool.testOnBorrow");
            if (StringUtils.isNotEmpty(strTestOnBorrow)) {
                config.setTestOnBorrow(Boolean.valueOf(strTestOnBorrow));
            }

            String strTestOnReturn = bundle.getString("redis.pool.testOnReturn");
            if (StringUtils.isNotEmpty(strTestOnReturn)) {
                config.setTestOnReturn(Boolean.valueOf(strTestOnReturn));
            }

        }

        LOGGER.info("Redis server info: " + host + ":" + port);
        LOGGER.info("nginx server info: " + serverIp + ":" + serverPort);

        //         ResourceBundle bundle = ResourceBundle.getBundle("conf.redis");

        jedisPool = new JedisPool(config, host, port, connectionTimeout);
    } catch (Exception e) {
        LOGGER.error("Initiate Jedis pool failed!", e);
    }
}