List of usage examples for java.util Properties getProperty
public String getProperty(String key)
From source file:mitm.common.properties.PropertyUtils.java
/** * Returns the property as a boolean. If propery is not found, or the property is not something that can * be represented a boolean, defaultValue will be returned. *//*from w w w. j a v a2s . c om*/ public static boolean getBooleanProperty(Properties properties, String name, boolean defaultValue) { boolean result = defaultValue; Object value = properties.get(name); if (value == null) { value = properties.getProperty(name); } if (value instanceof String) { result = BooleanUtils.toBoolean((String) value); } else if (value instanceof Boolean) { result = (Boolean) value; } return result; }
From source file:org.edgexfoundry.EdgeXConfigWatcherApplication.java
private static boolean loadProperties() { Properties properties = new Properties(); try (final InputStream inputStream = new FileInputStream(APP_PROPERTIES)) { properties.load(inputStream);//from ww w . jav a 2s .c o m serviceName = properties.getProperty("service.name"); globalPrefix = properties.getProperty("global.prefix"); servicePrefix = properties.getProperty("service.prefix"); consulProtocol = properties.getProperty("consul.protocol"); consulHost = properties.getProperty("consul.host"); consulPort = Integer.parseInt(properties.getProperty("consul.port", "8500")); notificationPathKey = properties.getProperty("notification.path.key"); notificationProtocol = properties.getProperty("notification.protocol"); if (serviceName == null || globalPrefix == null || servicePrefix == null || consulProtocol == null || consulHost == null || consulPort == 0 || notificationPathKey == null || notificationProtocol == null) { LOGGER.error( "Application configuration did not load properly or is missing elements. Cannot create watcher."); System.exit(1); return false; } } catch (IOException ex) { LOGGER.error("IO Exception getting application properties: " + ex.getMessage()); System.exit(1); return false; } return true; }
From source file:com.dattack.naming.loader.NamingLoader.java
private static void createAndBind(final Properties properties, final Context context, final String name, final Collection<File> extraClasspath) throws NamingException { final String type = properties.getProperty(TYPE_KEY); final ResourceFactory<?> factory = ResourceFactoryRegistry.getFactory(type); if (factory == null) { LOGGER.warn("Unable to get a factory for type ''{0}''", type); return;/*from w w w . j av a 2 s . c o m*/ } final Object value = factory.getObjectInstance(properties, extraClasspath); if (value != null) { LOGGER.info("Binding object to '{}/{}' (type: '{}')", context.getNameInNamespace(), name, type); execBind(context, name, value); } }
From source file:org.openbaton.vnfm.utils.Utils.java
public static void loadExternalProperties(Properties properties) { if (properties.getProperty("external-properties-file") != null) { File externalPropertiesFile = new File(properties.getProperty("external-properties-file")); if (externalPropertiesFile.exists()) { log.debug("Loading properties from external-properties-file: " + properties.getProperty("external-properties-file")); InputStream is = null; try { is = new FileInputStream(externalPropertiesFile); properties.load(is);/*from ww w. j av a 2s . c o m*/ } catch (FileNotFoundException e) { log.error(e.getMessage(), e); } catch (IOException e) { log.error(e.getMessage(), e); } } else { log.debug("external-properties-file: " + properties.getProperty("external-properties-file") + " doesn't exist"); } } }
From source file:com.bmwcarit.barefoot.roadmap.Loader.java
/** * Loads {@link RoadMap} object from database (or file buffer, if set to true) using database * connection parameters provided with the following properties: * <ul>//from w w w . j a v a2s . c o m * <li>database.host (e.g. localhost)</li> * <li>database.port (e.g. 5432)</li> * <li>database.name (e.g. barefoot-oberbayern)</li> * <li>database.table (e.g. bfmap_ways)</li> * <li>database.user (e.g. osmuser)</li> * <li>database.password</li> * <li>database.road-types (e.g. /path/to/road-types.json)</li> * </ul> * * @param properties {@link Properties} object with database connection parameters. * @param buffer Indicates if map shall be read from file buffer and written to file buffer. * @return {@link RoadMap} read from source. (Note: It is not yet constructed!) * @throws SourceException thrown if reading properties, road types or road map data fails. */ public static RoadMap roadmap(Properties properties, boolean buffer) throws SourceException { String database = properties.getProperty("database.name"); if (database == null) { throw new SourceException("could not read database properties"); } File file = new File(database + ".bfmap"); RoadMap map = null; if (!file.exists() || !buffer) { logger.info("load map from database {}", database); RoadReader reader = reader(properties); map = RoadMap.Load(reader); if (buffer) { reader = map.reader(); RoadWriter writer = new BfmapWriter(file.getAbsolutePath()); BaseRoad road = null; reader.open(); writer.open(); while ((road = reader.next()) != null) { writer.write(road); } writer.close(); reader.close(); } } else { logger.info("load map from file {}", file.getAbsolutePath()); map = RoadMap.Load(new BfmapReader(file.getAbsolutePath())); } return map; }
From source file:uk.dsxt.voting.common.utils.PropertiesHelper.java
public static <T> T loadResource(Properties properties, String subdirectory, String propertyName, Class<T> clazz) throws InternalLogicException { String path = properties.getProperty(propertyName); if (subdirectory != null) path = String.format(path, subdirectory); String resourceJson = PropertiesHelper.getResourceString(path); if (resourceJson.isEmpty()) throw new InternalLogicException( String.format("Couldn't find file for %s property with value '%s'.", propertyName, path)); try {// w w w. j a v a 2 s . c o m return mapper.readValue(resourceJson, clazz); } catch (Exception ex) { throw new InternalLogicException( String.format("Couldn't parse '%s' file for type %s due to %s", path, clazz, ex.getMessage())); } }
From source file:com.navercorp.pinpoint.collector.config.CollectorConfiguration.java
protected static boolean readBoolean(Properties properties, String propertyName) { final String value = properties.getProperty(propertyName); // if a default value will be needed afterwards, may match string value instead of Utils. // for now stay unmodified because of no need. final boolean result = Boolean.valueOf(value); if (LOGGER.isInfoEnabled()) { LOGGER.info("{}={}", propertyName, result); }/*ww w . java 2 s. co m*/ return result; }
From source file:Main.java
/** * All the standard parameters must be set in the properties file * /*w w w . jav a 2s . c o m*/ * @param renderer * @param params * @return */ public static Transformer setStdTransParamsProps(Transformer renderer, Properties params) { // log.severe("setStdTransParamsProps params = "+params); if (params != null) { for (Enumeration e = params.keys(); e.hasMoreElements();) { String localkey = (String) e.nextElement(); String val = params.getProperty(localkey); renderer.setParameter(localkey, val); } } return renderer; }
From source file:com.joliciel.talismane.utils.StringUtils.java
/** * Get a map of strings from Properties. *//*from ww w . j a v a2s . c o m*/ public static Map<String, String> getArgMap(Properties props) { Map<String, String> argMap = new HashMap<String, String>(); for (String propertyName : props.stringPropertyNames()) { argMap.put(propertyName, props.getProperty(propertyName)); } return argMap; }
From source file:com.taobao.tddl.jdbc.atom.common.TAtomConfParser.java
public static String parserPasswd(String passwdStr) { String passwd = null;/*from w w w. j a v a2s .com*/ Properties passwdProp = TAtomConfParser.parserConfStr2Properties(passwdStr); String encPasswd = passwdProp.getProperty(TAtomConfParser.PASSWD_ENC_PASSWD_KEY); if (TStringUtil.isNotBlank(encPasswd)) { String encKey = passwdProp.getProperty(TAtomConfParser.PASSWD_ENC_KEY_KEY); try { passwd = SecureIdentityLoginModule.decode(encKey, encPasswd); } catch (Exception e) { logger.error("[parserPasswd Error] decode dbPasswdError !", e); } } return passwd; }