List of usage examples for java.util PropertyResourceBundle PropertyResourceBundle
@SuppressWarnings({ "unchecked", "rawtypes" }) public PropertyResourceBundle(Reader reader) throws IOException
From source file:org.gcaldaemon.gui.Messages.java
public static final boolean setUserLocale(Locale locale) { try {/*ww w. jav a 2s . c o m*/ userResourceBundle = null; String programDir = System.getProperty("gcaldaemon.program.dir", "/Progra~1/GCALDaemon"); File langDir = new File(programDir, "lang"); if (!langDir.isDirectory()) { langDir.mkdir(); return false; } File msgFile = new File(langDir, "messages-" + locale.getLanguage().toLowerCase() + ".txt"); if (!msgFile.isFile()) { return false; } InputStream in = new BufferedInputStream(new FileInputStream(msgFile)); userResourceBundle = new PropertyResourceBundle(in); in.close(); userLocale = locale; Locale.setDefault(locale); return true; } catch (Exception ignored) { log.error("Unable to load messages!", ignored); } return false; }
From source file:org.kramerius.convert.input.ParametrizedConvertInputTemplateTest.java
@Test public void testInputTemplateTest() throws IOException { Provider<Locale> localeProvider = EasyMock.createMock(_TestLocaleProvider.class); EasyMock.expect(localeProvider.get()).andReturn(Locale.getDefault()).anyTimes(); ResourceBundleService resb = EasyMock.createMock(ResourceBundleService.class); PropertyResourceBundle resourceBundle = new PropertyResourceBundle(new StringReader(BUNDLES)); EasyMock.expect(resb.getResourceBundle("labels", Locale.getDefault())).andReturn(resourceBundle).anyTimes(); KConfiguration conf = EasyMock.createMock(KConfiguration.class); EasyMock.expect(conf.getProperty("import.directory")).andReturn(System.getProperty("user.dir")).anyTimes(); EasyMock.expect(conf.getProperty("convert.target.directory")).andReturn(System.getProperty("user.dir")) .anyTimes();/*from www. jav a2 s. c om*/ EasyMock.expect(conf.getProperty("convert.directory")).andReturn(System.getProperty("user.dir")).anyTimes(); Configuration subConfObject = EasyMock.createMock(Configuration.class); EasyMock.expect(conf.getConfiguration()).andReturn(subConfObject).anyTimes(); EasyMock.expect(subConfObject.getBoolean("ingest.skip")).andReturn(true).anyTimes(); EasyMock.expect(subConfObject.getBoolean("ingest.startIndexer")).andReturn(true).anyTimes(); EasyMock.expect(subConfObject.getBoolean("convert.defaultRights")).andReturn(true).anyTimes(); EasyMock.replay(localeProvider, resb, conf, subConfObject); ParametrizedConvertInputTemplate temp = new ParametrizedConvertInputTemplate(); temp.configuration = conf; temp.localesProvider = localeProvider; temp.resourceBundleService = resb; StringWriter nstr = new StringWriter(); temp.renderInput(null, nstr, new Properties()); Assert.assertNotNull(nstr.toString()); }
From source file:org.kramerius.k3replications.input.InputTemplateTest.java
@Test public void testInputTemplateTest() throws IOException { Provider<Locale> localeProvider = EasyMock.createMock(_TestLocaleProvider.class); EasyMock.expect(localeProvider.get()).andReturn(Locale.getDefault()).anyTimes(); ResourceBundleService resb = EasyMock.createMock(ResourceBundleService.class); PropertyResourceBundle resourceBundle = new PropertyResourceBundle(new StringReader(BUNDLES)); EasyMock.expect(resb.getResourceBundle("labels", Locale.getDefault())).andReturn(resourceBundle).anyTimes(); KConfiguration conf = EasyMock.createMock(KConfiguration.class); EasyMock.expect(conf.getProperty("migration.target.directory")).andReturn(System.getProperty("user.dir")) .anyTimes();/*from w w w . ja va2 s. c o m*/ EasyMock.expect(conf.getProperty("migration.directory")).andReturn(System.getProperty("user.dir")) .anyTimes(); Configuration subConfObject = EasyMock.createMock(Configuration.class); EasyMock.expect(conf.getConfiguration()).andReturn(subConfObject).anyTimes(); EasyMock.expect(subConfObject.getBoolean("ingest.skip")).andReturn(true).anyTimes(); EasyMock.expect(subConfObject.getBoolean("ingest.startIndexer")).andReturn(true).anyTimes(); EasyMock.expect(subConfObject.getBoolean("convert.defaultRights")).andReturn(true).anyTimes(); EasyMock.replay(localeProvider, resb, conf, subConfObject); InputTemplate temp = new InputTemplate(); temp.configuration = conf; temp.localesProvider = localeProvider; temp.resourceBundleService = resb; StringWriter nstr = new StringWriter(); temp.renderInput(null, nstr, new Properties()); Assert.assertNotNull(nstr.toString()); }
From source file:de.tbuchloh.kiskis.util.CheckUpdate.java
/** * checks the version file and says false, if the version does not match. *//*from w w w .java 2s .c o m*/ public boolean check() throws IOException { LOG.info("Calling " + VERSION_FILE); final URL url = new URL(VERSION_FILE); final InputStream os = url.openStream(); if (os == null) { return true; } final PropertyResourceBundle p = new PropertyResourceBundle(os); os.close(); _version = AboutDialog.createBuildInfo(p); LOG.info("Found version=" + _version); return _version.getVersion().equals(BuildProperties.getVersion()); }
From source file:csiro.pidsvc.core.Settings.java
private Settings(HttpServlet servlet) throws NullPointerException, IOException { // Retrieve manifest. if ((_servlet = servlet) != null) { ServletConfig config = _servlet.getServletConfig(); if (config != null) { ServletContext application = config.getServletContext(); _manifest = new Manifest(application.getResourceAsStream("/META-INF/MANIFEST.MF")); }/* w ww. j a v a 2 s .c o m*/ } // Retrieve settings. FileInputStream fis = null; try { InitialContext context = new InitialContext(); String settingsFile = (String) context.lookup("java:comp/env/" + SETTINGS_OPT); fis = new FileInputStream(settingsFile); _properties = new PropertyResourceBundle(fis); } catch (NamingException ex) { _logger.debug("Using default pidsvc.properties file."); _properties = ResourceBundle.getBundle("pidsvc"); } finally { if (fis != null) fis.close(); } // Get additional system properties. _serverProperties.put("serverJavaVersion", System.getProperty("java.version")); _serverProperties.put("serverJavaVendor", System.getProperty("java.vendor")); _serverProperties.put("javaHome", System.getProperty("java.home")); _serverProperties.put("serverOsArch", System.getProperty("os.arch")); _serverProperties.put("serverOsName", System.getProperty("os.name")); _serverProperties.put("serverOsVersion", System.getProperty("os.version")); }
From source file:org.ebayopensource.turmeric.eclipse.core.TurmericCoreActivator.java
/** * Gets the plugin properties./* w w w . ja v a 2 s . c o m*/ * * @return the plugin properties */ public PropertyResourceBundle getPluginProperties() { if (pluginProperties == null) { try { pluginProperties = new PropertyResourceBundle(FileLocator.openStream( getBundle() == null ? context.getBundle() : getBundle(), new Path(MY_PROPERTIES), false)); } catch (IOException e) { soaLogger.error(e); } } return pluginProperties; }
From source file:griffon.plugins.i18n.ExtendedResourceBundleMessageSource.java
private List<ResourceBundle> loadBundleForFilename(String filename) { List<ResourceBundle> bundles = new ArrayList<ResourceBundle>(); try {/*w w w. java 2 s .co m*/ Resource[] resources = resolver.getResources("classpath*:/" + filename + ".properties"); if (LOG.isTraceEnabled()) { LOG.trace("Found " + resources.length + " matches for classpath *:/" + filename + ".properties"); } for (Resource resource : resources) { if (LOG.isTraceEnabled()) LOG.trace("Initializing bundle with " + resource.getURI()); bundles.add(new PropertyResourceBundle(resource.getInputStream())); } } catch (IOException e) { // ignore } return bundles; }
From source file:info.magnolia.cms.i18n.DefaultMessagesImpl.java
/** * @return Returns the bundle for the current basename *///w w w . ja v a 2 s . c om protected ResourceBundle getBundle() { if (bundle == null) { try { InputStream stream = ClasspathResourcesUtil.getStream("/" + StringUtils.replace(basename, ".", "/") + "_" + getLocale().getLanguage() + "_" + getLocale().getCountry() + ".properties", false); if (stream == null) { stream = ClasspathResourcesUtil.getStream("/" + StringUtils.replace(basename, ".", "/") + "_" + getLocale().getLanguage() + ".properties", false); } if (stream == null) { stream = ClasspathResourcesUtil.getStream("/" + StringUtils.replace(basename, ".", "/") + "_" + MessagesManager.getDefaultLocale().getLanguage() + ".properties", false); } if (stream == null) { stream = ClasspathResourcesUtil .getStream("/" + StringUtils.replace(basename, ".", "/") + ".properties", false); } if (stream != null) { bundle = new PropertyResourceBundle(stream); } else { bundle = ResourceBundle.getBundle(getBasename(), getLocale()); } } catch (IOException e) { log.error("can't load messages for " + basename); } } return bundle; }
From source file:com.swtxml.i18n.ResourceBundleLabelTranslator.java
public ResourceBundleLabelTranslator(IDocumentResource document, Locale locale) { Assert.isNotNull(document, "document"); String documentName = FilenameUtils.getBaseName(document.getDocumentName()); List<String> resourceBundleNames = getResourceBundleNames(documentName, locale); resourceBundleNames.addAll(getResourceBundleNames("messages", locale)); resourceBundleNames.addAll(getResourceBundleNames("bundle:messages", locale)); resourceBundleNames.addAll(getResourceBundleNames("bundle:plugin", locale)); this.resourceBundles = new ArrayList<ResourceBundle>(); for (String name : resourceBundleNames) { try {//from ww w . j ava2 s . co m InputStream resource = document.resolve(name + ".properties"); if (resource != null) { resourceBundles.add(new PropertyResourceBundle(resource)); } } catch (MissingResourceException e) { // ignore missing resources } catch (IOException e) { // ignore invalid resource bundles } } }
From source file:com.github.cc007.headsinventory.locale.Translator.java
public Translator(String bundleName, Locale locale, ClassLoader classLoader) { this.locale = locale; this.bundleName = bundleName; this.classLoader = classLoader; ResourceBundle translations = null; ResourceBundle fallbackTranslations = null; try {// w w w . j a v a 2 s. co m InputStream translationsStream = getTranslationsFileStream( "locale/" + bundleName + "_" + locale.toString() + ".properties", classLoader); translations = new PropertyResourceBundle(translationsStream); InputStream fallbackTranslationsStream = getTranslationsFileStream( "locale/" + bundleName + ".properties", classLoader); fallbackTranslations = new PropertyResourceBundle(fallbackTranslationsStream); } catch (IOException ex) { HeadsInventory.getPlugin().getLogger().log(Level.SEVERE, null, ex); } this.translations = translations; this.fallbackTranslations = fallbackTranslations; }