List of usage examples for java.util PropertyResourceBundle PropertyResourceBundle
@SuppressWarnings({ "unchecked", "rawtypes" }) public PropertyResourceBundle(Reader reader) throws IOException
From source file:net.sf.eclipsecs.core.config.configtypes.ConfigurationType.java
/** * Gets the property resolver for this configuration type used to expand * property values within the checkstyle configuration. * //from w ww. j a v a 2s . c om * @param checkConfiguration * the actual check configuration * @return the property resolver * @throws IOException * error creating the property resolver */ protected PropertyResolver getPropertyResolver(ICheckConfiguration config, CheckstyleConfigurationFile configFile) throws IOException { MultiPropertyResolver multiResolver = new MultiPropertyResolver(); multiResolver.addPropertyResolver(new ResolvablePropertyResolver(config)); File f = FileUtils.toFile(configFile.getResolvedConfigFileURL()); if (f != null) { multiResolver.addPropertyResolver(new StandardPropertyResolver(f.toString())); } else { multiResolver.addPropertyResolver( new StandardPropertyResolver(configFile.getResolvedConfigFileURL().toString())); } multiResolver.addPropertyResolver(new ClasspathVariableResolver()); multiResolver.addPropertyResolver(new SystemPropertyResolver()); if (configFile.getAdditionalPropertiesBundleStream() != null) { ResourceBundle bundle = new PropertyResourceBundle(configFile.getAdditionalPropertiesBundleStream()); multiResolver.addPropertyResolver(new ResourceBundlePropertyResolver(bundle)); } return multiResolver; }
From source file:org.echocat.jomon.runtime.i18n.RecursiveResourceBundleFactory.java
@Nullable protected ResourceBundle loadBundles(@Nonnull String withName, @Nonnull ClassLoader from) { final List<ResourceBundle> bundles = new ArrayList<>(); final Enumeration<URL> i; try {// www. java2s .c o m i = from.getResources(withName); } catch (final IOException e) { throw new RuntimeException( "Could not find all resourceBundles with name '" + withName + "' in " + from + ".", e); } while (i.hasMoreElements()) { final URL propertiesUrl = i.nextElement(); try (final InputStream is = propertiesUrl.openStream()) { try (final Reader reader = new InputStreamReader(is, _charset)) { bundles.add(new PropertyResourceBundle(reader)); } } catch (final IOException e) { throw new RuntimeException("Could not load resourceBundle from '" + propertiesUrl + "'.", e); } } return bundles.isEmpty() ? null : new CombinedResourceBundle(bundles); }
From source file:org.nuxeo.apidoc.introspection.ServerInfo.java
protected static BundleInfoImpl computeBundleInfo(Bundle bundle) { RuntimeService runtime = Framework.getRuntime(); BundleInfoImpl binfo = new BundleInfoImpl(bundle.getSymbolicName()); binfo.setFileName(runtime.getBundleFile(bundle).getName()); binfo.setLocation(bundle.getLocation()); if (!(bundle instanceof BundleImpl)) { return binfo; }// w ww. j a v a 2 s . c o m BundleImpl nxBundle = (BundleImpl) bundle; File jarFile = nxBundle.getBundleFile().getFile(); if (jarFile == null) { return binfo; } try { if (jarFile.isDirectory()) { // directory: run from Eclipse in unit tests // .../nuxeo-runtime/nuxeo-runtime/bin // or sometimes // .../nuxeo-runtime/nuxeo-runtime/bin/main File manifest = new File(jarFile, META_INF_MANIFEST_MF); if (manifest.exists()) { InputStream is = new FileInputStream(manifest); String mf = IOUtils.toString(is, Charsets.UTF_8); binfo.setManifest(mf); } // find and parse pom.xml File up = new File(jarFile, ".."); File pom = new File(up, POM_XML); if (!pom.exists()) { pom = new File(new File(up, ".."), POM_XML); if (!pom.exists()) { pom = null; } } if (pom != null) { DocumentBuilder b = documentBuilderFactory.newDocumentBuilder(); Document doc = b.parse(new FileInputStream(pom)); XPath xpath = xpathFactory.newXPath(); String groupId = (String) xpath.evaluate("//project/groupId", doc, XPathConstants.STRING); if ("".equals(groupId)) { groupId = (String) xpath.evaluate("//project/parent/groupId", doc, XPathConstants.STRING); } String artifactId = (String) xpath.evaluate("//project/artifactId", doc, XPathConstants.STRING); if ("".equals(artifactId)) { artifactId = (String) xpath.evaluate("//project/parent/artifactId", doc, XPathConstants.STRING); } String version = (String) xpath.evaluate("//project/version", doc, XPathConstants.STRING); if ("".equals(version)) { version = (String) xpath.evaluate("//project/parent/version", doc, XPathConstants.STRING); } binfo.setArtifactId(artifactId); binfo.setGroupId(groupId); binfo.setArtifactVersion(version); } } else { try (ZipFile zFile = new ZipFile(jarFile)) { ZipEntry mfEntry = zFile.getEntry(META_INF_MANIFEST_MF); if (mfEntry != null) { try (InputStream mfStream = zFile.getInputStream(mfEntry)) { String mf = IOUtils.toString(mfStream, Charsets.UTF_8); binfo.setManifest(mf); } } Enumeration<? extends ZipEntry> entries = zFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.getName().endsWith(POM_PROPERTIES)) { try (InputStream is = zFile.getInputStream(entry)) { PropertyResourceBundle prb = new PropertyResourceBundle(is); String groupId = prb.getString("groupId"); String artifactId = prb.getString("artifactId"); String version = prb.getString("version"); binfo.setArtifactId(artifactId); binfo.setGroupId(groupId); binfo.setArtifactVersion(version); } break; } } } try (ZipFile zFile = new ZipFile(jarFile)) { EmbeddedDocExtractor.extractEmbeddedDoc(zFile, binfo); } } } catch (IOException | ParserConfigurationException | SAXException | XPathException | NuxeoException e) { log.error(e, e); } return binfo; }
From source file:com.twinsoft.convertigo.beans.core.MySimpleBeanInfo.java
protected ResourceBundle getResourceBundle(String path) throws IOException { return new PropertyResourceBundle(beanClass.getResourceAsStream(path + ".properties")); }
From source file:org.sakaiproject.search.component.test.LoaderComponentIntegrationTest.java
/** * Fetches the "maven.tomcat.home" property from the maven build.properties * file located in the user's $HOME directory. * /* w ww . j a v a 2 s .co m*/ * @return * @throws Exception */ private static String getTomcatHome() throws Exception { String testTomcatHome = System.getProperty("test.tomcat.home"); if (testTomcatHome != null && testTomcatHome.length() > 0) { return testTomcatHome; } else { String homeDir = System.getProperty("user.home"); File file = new File(homeDir + File.separatorChar + "build.properties"); FileInputStream fis = new FileInputStream(file); PropertyResourceBundle rb = new PropertyResourceBundle(fis); return rb.getString("maven.tomcat.home"); } }
From source file:org.gitana.platform.client.Gitana.java
public static ResourceBundle readBundle(String bundleId) { ResourceBundle bundle = null; // check current file path File file = new File(bundleId + ".properties"); if (file != null && file.exists()) { try {// w ww .j ava 2s . c o m FileInputStream fis = new FileInputStream(file); bundle = new PropertyResourceBundle(fis); System.out.println("Found local " + bundleId + ".properties, loading..."); } catch (Exception ex) { throw new RuntimeException(ex); } } if (bundle == null) { bundle = ResourceBundle.getBundle(bundleId); } return bundle; }
From source file:org.artifactory.bintray.BintrayServiceImpl.java
private void sendBuildPushNotification(BasicStatusHolder statusHolder, String buildNameAndNumber) throws IOException { log.info("Sending logs for push build '{}' by mail.", buildNameAndNumber); InputStream stream = null;/*ww w .j a va2 s. com*/ try { //Get message body from properties and substitute variables stream = getClass().getResourceAsStream("/org/artifactory/email/messages/bintrayPushBuild.properties"); ResourceBundle resourceBundle = new PropertyResourceBundle(stream); String body = resourceBundle.getString("body"); String logBlock = getLogBlock(statusHolder); UserInfo currentUser = getCurrentUser(); if (currentUser != null) { String userEmail = currentUser.getEmail(); if (StringUtils.isBlank(userEmail)) { log.warn( "Couldn't find valid email address. Skipping push build to bintray email notification"); } else { log.debug("Sending push build to Bintray notification to '{}'.", userEmail); String message = MessageFormat.format(body, logBlock); mailService.sendMail(new String[] { userEmail }, "Push Build to Bintray Report", message); } } } catch (EmailException e) { log.error("Error while notification of: '" + buildNameAndNumber + "' messages.", e); throw e; } finally { IOUtils.closeQuietly(stream); } }
From source file:org.artifactory.backup.BackupServiceImpl.java
@Override public void sendBackupErrorNotification(String backupName, BasicStatusHolder statusHolder) throws Exception { InputStream stream = null;/*from w w w . j av a 2 s . c o m*/ try { //Get message body from properties and substitute variables stream = getClass().getResourceAsStream("/org/artifactory/email/messages/backupError.properties"); ResourceBundle resourceBundle = new PropertyResourceBundle(stream); String body = resourceBundle.getString("body"); String errorListBlock = getErrorListBlock(statusHolder); CoreAddons coreAddons = addonsManager.addonByType(CoreAddons.class); List<String> adminEmails = coreAddons.getUsersForBackupNotifications(); if (CollectionUtils.isNullOrEmpty(adminEmails)) { log.warn("Couldn't find admin account with valid email address. " + "Skipping backup failure email notification"); } for (String adminEmail : adminEmails) { if (StringUtils.isNotBlank(adminEmail)) { log.debug("Sending backup error notification to '{}'.", adminEmail); StringBuilder artifactoryUrlMessage = new StringBuilder(); String artifactoryUrl = centralConfig.getDescriptor().getServerUrlForEmail(); if (StringUtils.isNotBlank(artifactoryUrl)) { String artifactoryLink = createArtifactoryLinkFromUrl(artifactoryUrl); artifactoryUrlMessage.append("Your Artifactory base URL is: ").append(artifactoryLink); } else { artifactoryUrlMessage.append("No Artifactory base URL is configured"); } String message = MessageFormat.format(body, backupName, artifactoryUrlMessage, errorListBlock); mailService.sendMail(new String[] { adminEmail }, "Backup Error Notification", message); } } } catch (EmailException e) { log.error("Error while notification of: '" + backupName + "' errors.", e); throw e; } finally { IOUtils.closeQuietly(stream); } log.info("Error notification for backup '{}' was sent by mail.", backupName); }
From source file:org.ebayopensource.turmeric.eclipse.utils.plugin.JDTUtil.java
/** * Gets the plugin properties.//from w ww.j a v a 2s . c o m * * @param bundle the bundle * @param fileName the file name * @return the plugin properties * @throws IOException Signals that an I/O exception has occurred. */ public static PropertyResourceBundle getPluginProperties(final Bundle bundle, String fileName) throws IOException { PropertyResourceBundle pluginProperties; if (StringUtils.isBlank(fileName)) { final Object object = bundle.getHeaders().get(Constants.BUNDLE_LOCALIZATION); fileName = object != null ? object.toString() + ".properties" : "plugin.properties"; } pluginProperties = new PropertyResourceBundle(FileLocator.openStream(bundle, new Path(fileName), false)); return pluginProperties; }
From source file:com.feilong.commons.core.configure.ResourceBundleUtil.java
/** * resource bundle({@link PropertyResourceBundle}),????(file). * * @param reader//from w w w. j a v a 2s .co m * the reader * @return the resource bundle * @throws UncheckedIOException * the unchecked io exception * @see java.util.PropertyResourceBundle#PropertyResourceBundle(Reader) * @since 1.0.9 */ public static ResourceBundle getResourceBundle(Reader reader) throws UncheckedIOException { if (Validator.isNullOrEmpty(reader)) { throw new IllegalArgumentException("reader can't be null/empty!"); } try { ResourceBundle resourceBundle = new PropertyResourceBundle(reader); return resourceBundle; } catch (IOException e) { throw new UncheckedIOException(e); } }