List of usage examples for java.util PropertyResourceBundle PropertyResourceBundle
@SuppressWarnings({ "unchecked", "rawtypes" }) public PropertyResourceBundle(Reader reader) throws IOException
From source file:com.feilong.core.util.ResourceBundleUtil.java
/** * resource bundle({@link PropertyResourceBundle}),????(file). * * @param reader/*from ww w . j a v a 2 s . com*/ * the reader * @return <code>reader</code> null, {@link NullPointerException}<br> * ? {@link java.util.PropertyResourceBundle#PropertyResourceBundle(Reader)} * @see java.util.PropertyResourceBundle#PropertyResourceBundle(Reader) * @since 1.0.9 */ public static ResourceBundle getResourceBundle(Reader reader) { Validate.notNull(reader, "reader can't be null!"); try { return new PropertyResourceBundle(reader); } catch (IOException e) { throw new UncheckedIOException(e); } }
From source file:org.jpos.q2.Q2.java
private void initConfigDecorator() { InputStream in = Q2.class.getClassLoader() .getResourceAsStream("META-INF/org/jpos/config/Q2-decorator.properties"); try {/* www . ja v a 2s . c o m*/ if (in != null) { PropertyResourceBundle bundle = new PropertyResourceBundle(in); String ccdClass = bundle.getString("config-decorator-class"); if (log != null) log.info("Initializing config decoration provider: " + ccdClass); decorator = (ConfigDecorationProvider) Q2.class.getClassLoader().loadClass(ccdClass).newInstance(); decorator.initialize(getDeployDir()); } } catch (IOException ignored) { } catch (Exception e) { if (log != null) log.error(e); else { e.printStackTrace(); } } finally { if (in != null) { try { in.close(); } catch (IOException ignored) { } } } }
From source file:org.artifactory.security.SecurityServiceImpl.java
/** * Generates a password recovery key for the specified user and send it by mail * * @param username User to rest his password * @param remoteAddress The IP of the client that sent the request * @param resetPageUrl The URL to the password reset page * @throws Exception/*w w w. j a va 2 s .com*/ */ @Override public void generatePasswordResetKey(String username, String remoteAddress, String resetPageUrl) throws Exception { UserInfo userInfo; try { userInfo = findUser(username); } catch (UsernameNotFoundException e) { //If can't find user throw new IllegalArgumentException("Could not find specified username.", e); } //If user has valid email if (!StringUtils.isEmpty(userInfo.getEmail())) { if (!userInfo.isUpdatableProfile()) { //If user is not allowed to update his profile throw new AuthorizationException("User is not permitted to reset his password."); } //Build key by UUID + current time millis + client ip -> encoded in B64 UUID uuid = UUID.randomUUID(); String passwordKey = uuid.toString() + ":" + System.currentTimeMillis() + ":" + remoteAddress; byte[] encodedKey = Base64.encodeBase64URLSafe(passwordKey.getBytes(Charsets.UTF_8)); String encodedKeyString = new String(encodedKey, Charsets.UTF_8); MutableUserInfo mutableUser = InfoFactoryHolder.get().copyUser(userInfo); mutableUser.setGenPasswordKey(encodedKeyString); updateUser(mutableUser, false); //Add encoded key to page url String resetPage = resetPageUrl + "?key=" + encodedKeyString; //If there are any admins with valid email addresses, add them to the list that the message will contain String adminList = getAdminListBlock(userInfo); InputStream stream = null; try { //Get message body from properties and substitute variables stream = getClass().getResourceAsStream("/org/artifactory/email/messages/resetPassword.properties"); ResourceBundle resourceBundle = new PropertyResourceBundle(stream); String body = resourceBundle.getString("body"); body = MessageFormat.format(body, username, remoteAddress, resetPage, adminList); mailService.sendMail(new String[] { userInfo.getEmail() }, "Reset password request", body); } catch (EmailException e) { log.error("Error while resetting password for user: '" + username + "'.", e); throw e; } finally { IOUtils.closeQuietly(stream); } log.info("The user: '{}' has been sent a password reset message by mail.", username); } }
From source file:org.schemaspy.Config.java
/** * Determines the database properties associated with the specified type. * A call to {@link #setDbProperties(Properties)} is expected after determining * the complete set of properties.// w w w.j a v a 2 s. c o m * * @param type * @return * @throws IOException * @throws InvalidConfigurationException if db properties are incorrectly formed */ public Properties determineDbProperties(String type) throws IOException, InvalidConfigurationException { ResourceBundle bundle = null; try { File propertiesFile = new File(type); bundle = new PropertyResourceBundle(new FileInputStream(propertiesFile)); dbPropertiesLoadedFrom = propertiesFile.getAbsolutePath(); } catch (FileNotFoundException notFoundOnFilesystemWithoutExtension) { try { File propertiesFile = new File(type + ".properties"); bundle = new PropertyResourceBundle(new FileInputStream(propertiesFile)); dbPropertiesLoadedFrom = propertiesFile.getAbsolutePath(); } catch (FileNotFoundException notFoundOnFilesystemWithExtensionTackedOn) { try { bundle = ResourceBundle.getBundle(type); dbPropertiesLoadedFrom = "[" + getLoadedFromJar() + "]" + File.separator + type + ".properties"; } catch (Exception notInJarWithoutPath) { try { String path = TableOrderer.class.getPackage().getName() + ".types." + type; path = path.replace('.', '/'); bundle = ResourceBundle.getBundle(path); dbPropertiesLoadedFrom = "[" + getLoadedFromJar() + "]/" + path + ".properties"; } catch (Exception notInJar) { notInJar.printStackTrace(); notFoundOnFilesystemWithExtensionTackedOn.printStackTrace(); throw notFoundOnFilesystemWithoutExtension; } } } } Properties props = asProperties(bundle); bundle = null; String saveLoadedFrom = dbPropertiesLoadedFrom; // keep original thru recursion // bring in key/values pointed to by the include directive // example: include.1=mysql::selectRowCountSql for (int i = 1; true; ++i) { String include = (String) props.remove("include." + i); if (include == null) break; int separator = include.indexOf("::"); if (separator == -1) throw new InvalidConfigurationException("include directive in " + dbPropertiesLoadedFrom + " must have '::' between dbType and key"); String refdType = include.substring(0, separator).trim(); String refdKey = include.substring(separator + 2).trim(); // recursively resolve the ref'd properties file and the ref'd key Properties refdProps = determineDbProperties(refdType); props.put(refdKey, refdProps.getProperty(refdKey)); } // bring in base properties files pointed to by the extends directive String baseDbType = (String) props.remove("extends"); if (baseDbType != null) { baseDbType = baseDbType.trim(); Properties baseProps = determineDbProperties(baseDbType); // overlay our properties on top of the base's baseProps.putAll(props); props = baseProps; } // done with this level of recursion...restore original dbPropertiesLoadedFrom = saveLoadedFrom; // this won't be correct until the final recursion exits dbProperties = props; return props; }
From source file:org.eclipse.birt.report.utility.ParameterAccessor.java
/** * Returns the application properties/* ww w . j ava 2s . c om*/ * * @param context * @param props * @return */ public synchronized static Map initViewerProps(ServletContext context, Map props) { // initialize map if (props == null) props = new HashMap(); // get config file String file = context.getInitParameter(INIT_PARAM_CONFIG_FILE); if (file == null || file.trim().length() <= 0) file = IBirtConstants.DEFAULT_VIEWER_CONFIG_FILE; try { InputStream is = null; if (isRelativePath(file)) { // realtive path if (!file.startsWith("/")) //$NON-NLS-1$ file = "/" + file; //$NON-NLS-1$ is = context.getResourceAsStream(file); } else { // absolute path is = new FileInputStream(file); } // parse the properties file PropertyResourceBundle bundle = new PropertyResourceBundle(is); if (bundle != null) { Enumeration<String> keys = bundle.getKeys(); while (keys != null && keys.hasMoreElements()) { String key = keys.nextElement(); String value = (String) bundle.getObject(key); if (key != null && value != null) props.put(key, value); } } } catch (Exception e) { } return props; }
From source file:com.amalto.workbench.utils.Util.java
public static String checkOnVersionCompatibility(String url, String username, String password) { IProduct product = Platform.getProduct(); String versionComp = "";//$NON-NLS-1$ try {/*from w w w .j av a 2s .c o m*/ URL resourceURL = product.getDefiningBundle().getResource("/about.mappings");//$NON-NLS-1$ PropertyResourceBundle bundle = new PropertyResourceBundle(resourceURL.openStream()); String studioVersion = bundle.getString("1").trim();//$NON-NLS-1$ Pattern vsnPtn = Pattern.compile("^(\\d+)\\.(\\d+)(\\.)*(\\d*)$");//$NON-NLS-1$ Matcher match = vsnPtn.matcher(studioVersion); if (!match.find()) { return null; } versionComp = Messages.Util_45 + studioVersion + Messages.Util_46; int major = Integer.parseInt(match.group(1)); int minor = Integer.parseInt(match.group(2)); int rev = match.group(4) != null && !match.group(4).equals("") ? Integer.parseInt(match.group(4)) : 0;//$NON-NLS-1$ TMDMService service = Util.getMDMService(new URL(url), username, password); WSVersion wsVersion = service .getComponentVersion(new WSGetComponentVersion(WSComponent.DATA_MANAGER, null)); versionComp += Messages.Util_47 + wsVersion.getMajor() + Messages.Util_48 + wsVersion.getMinor() + Messages.Util_49 + wsVersion.getRevision(); if (major != wsVersion.getMajor() || minor != wsVersion.getMinor()) { return versionComp; } if (rev == 0) { // major version compare if (wsVersion.getRevision() != 0) { return versionComp; } } } catch (Exception e) { } return null; }
From source file:org.regenstrief.util.Util.java
/** * Retrieves the ResourceBundle/*w ww . ja va 2 s . c om*/ * * @param location the ResourceBundle source location * @return the ResourceBundle **/ public final static ResourceBundle getResourceBundle(final String location) { FileInputStream propin = null; try { propin = new FileInputStream(location); return new PropertyResourceBundle(propin); } catch (final Exception e) { IoUtil.close(propin); return ResourceBundle.getBundle(location); } finally { IoUtil.close(propin); } }