List of usage examples for java.util Properties getProperty
public String getProperty(String key)
From source file:Main.java
public static Transformer setStdTransParamsProps(final Transformer renderer, final Properties params) { if (params != null) { for (Enumeration<Object> e = params.keys(); e.hasMoreElements();) { String localkey = (String) e.nextElement(); String val = params.getProperty(localkey); renderer.setParameter(localkey, val); }/* w ww. j ava 2 s. c om*/ } return renderer; }
From source file:de.kurashigegollub.dev.gcatest.Utils.java
/** * Read a configuration value from the properties file * @param string/* www . j a v a2 s . c o m*/ * @return */ public static String readFromPropertiesAsString(String propertiesFile, String propertyName) throws IOException { InputStream is = Utils.class.getResourceAsStream(propertiesFile.replace('/', File.separatorChar)); if (is == null) { throw new IOException(String.format("Could not find %s", propertiesFile)); } Properties p = new Properties(); p.load(is); return p.getProperty(propertyName); }
From source file:io.unravelling.ferguson.configuration.FergusonConfiguration.java
/** * Validates the server URL that was supplied. * @param configuration Configuration of the server. * @return Boolean indicating if the server configuration is correct or not. *///from w ww . j a v a 2s . co m static boolean validateServerUrl(final Properties configuration) { return (configuration.containsKey(FergusonConfiguration.SERVER_URL) && !configuration.getProperty(FergusonConfiguration.SERVER_URL).isEmpty()); }
From source file:com.gistlabs.mechanize.impl.MechanizeInitializer.java
protected static void loadProperties() throws Exception { Properties properties = new Properties(); properties.load(MechanizeInitializer.class.getResourceAsStream("/mechanize.properties")); MechanizeAgent.setVersion(properties.getProperty("mechanize.version")); }
From source file:Main.java
public static Map<String, String> toMap(String properties) { try {/* w ww .j a v a2 s .c om*/ InputStream is = new ByteArrayInputStream(properties.getBytes("UTF-8")); Properties prop = new Properties(); prop.load(is); Map<String, String> ret = new HashMap<String, String>(); for (String key : prop.stringPropertyNames()) { ret.put(key, prop.getProperty(key)); } return ret; } catch (Exception ex) { ex.printStackTrace(); } return null; }
From source file:com.edmunds.etm.management.api.HostAddress.java
private static int extractPort(Properties properties) { final String portText = properties.getProperty("port"); Validate.notEmpty(portText, "port cannot be empty"); try {/*from ww w . j a v a 2s . co m*/ if (StringUtils.isNumeric(portText)) { return Integer.parseInt(portText); } else { throw new IllegalStateException("Port must be numeric: " + portText); } } catch (NumberFormatException e) { throw new IllegalStateException("Port must be numeric: " + portText, e); } }
From source file:com.netflix.config.ClasspathPropertiesConfiguration.java
/** * Get the conventional name of the configuration that comes from from the * given URL.//from w w w . j a va 2s . c o m */ private static String getConfigName(Properties props, URL propertyFile) { String name = props.getProperty(configNameProperty); if (name == null) { name = propertyFile.toExternalForm(); name = name.replace('\\', '/'); // Windows final String scheme = propertyFile.getProtocol().toLowerCase(); if ("jar".equals(scheme) || "zip".equals(scheme)) { // Use the unqualified name of the jar file. final int bang = name.lastIndexOf("!"); if (bang >= 0) { name = name.substring(0, bang); } final int slash = name.lastIndexOf("/"); if (slash >= 0) { name = name.substring(slash + 1); } } else { // Use the URL of the enclosing directory. final int slash = name.lastIndexOf("/"); if (slash >= 0) { name = name.substring(0, slash); } } } return name; }
From source file:com.splunk.shuttl.archiver.filesystem.glacier.AWSCredentialsImpl.java
/** * @param properties// w ww .jav a2s .com * file containing amazon properties for all the fields. */ public static AWSCredentialsImpl createWithPropertyFile(File amazonProperties) { try { Properties properties = new Properties(); properties.load(FileUtils.openInputStream(amazonProperties)); String id = properties.getProperty("aws.id"); String secret = properties.getProperty("aws.secret"); String bucket = properties.getProperty("s3.bucket"); String vault = properties.getProperty("glacier.vault"); String endpoint = properties.getProperty("glacier.endpoint"); return new AWSCredentialsImpl(id, secret, endpoint, bucket, vault); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.haulmont.yarg.console.ConsoleRunner.java
private static Reporting createReportingEngine(PropertiesLoader propertiesLoader) throws IOException { DefaultFormatterFactory formatterFactory = new DefaultFormatterFactory(); Reporting reporting = new Reporting(); Properties properties = propertiesLoader.load(); String openOfficePath = properties.getProperty(PropertiesLoader.CUBA_REPORTING_OPENOFFICE_PATH); String openOfficePorts = properties.getProperty(PropertiesLoader.CUBA_REPORTING_OPENOFFICE_PORTS); if (StringUtils.isNotBlank(openOfficePath) && StringUtils.isNotBlank(openOfficePorts)) { String[] portsStr = openOfficePorts.split("[,|]"); Integer[] ports = new Integer[portsStr.length]; for (int i = 0, portsStrLength = portsStr.length; i < portsStrLength; i++) { String str = portsStr[i]; ports[i] = Integer.valueOf(str); }/* w w w. j a v a 2 s. co m*/ OfficeIntegration officeIntegration = new OfficeIntegration(openOfficePath, ports); formatterFactory.setOfficeIntegration(officeIntegration); String openOfficeTimeout = properties.getProperty(PropertiesLoader.CUBA_REPORTING_OPENOFFICE_TIMEOUT); if (StringUtils.isNotBlank(openOfficeTimeout)) { officeIntegration.setTimeoutInSeconds(Integer.valueOf(openOfficeTimeout)); } String displayDeviceAvailable = properties .getProperty(PropertiesLoader.CUBA_REPORTING_OPENOFFICE_DISPLAY_DEVICE_AVAILABLE); if (StringUtils.isNotBlank(displayDeviceAvailable)) { officeIntegration.setDisplayDeviceAvailable(Boolean.valueOf(displayDeviceAvailable)); } } reporting.setFormatterFactory(formatterFactory); SqlDataLoader sqlDataLoader = new PropertiesSqlLoaderFactory(propertiesLoader).create(); GroovyDataLoader groovyDataLoader = new GroovyDataLoader(new DefaultScriptingImpl()); JsonDataLoader jsonDataLoader = new JsonDataLoader(); DefaultLoaderFactory loaderFactory = new DefaultLoaderFactory().setSqlDataLoader(sqlDataLoader) .setGroovyDataLoader(groovyDataLoader).setJsonDataLoader(jsonDataLoader); reporting.setLoaderFactory(loaderFactory); String putEmptyRowIfNoDataSelected = properties .getProperty(PropertiesLoader.CUBA_REPORTING_PUT_EMPTY_ROW_IF_NO_DATA_SELECTED); DataExtractorImpl dataExtractor = new DataExtractorImpl(loaderFactory); dataExtractor.setPutEmptyRowIfNoDataSelected(Boolean.parseBoolean(putEmptyRowIfNoDataSelected)); reporting.setDataExtractor(dataExtractor); if (sqlDataLoader != null) { DatasourceHolder.dataSource = sqlDataLoader.getDataSource(); } return reporting; }
From source file:org.zalando.stups.spring.http.client.ClientHttpRequestFactorySelector.java
public static ClientHttpRequestFactory getRequestFactory(TimeoutConfig timeoutConfig) { Properties properties = System.getProperties(); String proxyHost = properties.getProperty("http.proxyHost"); int proxyPort = properties.containsKey("http.proxyPort") ? Integer.valueOf(properties.getProperty("http.proxyPort")) : 80;/*w ww. j av a 2 s .c o m*/ if (HTTP_COMPONENTS_AVAILABLE) { HttpComponentsClientHttpRequestFactory factory = (HttpComponentsClientHttpRequestFactory) HttpComponentsClientRequestFactoryCreator .createRequestFactory(proxyHost, proxyPort); factory.setReadTimeout(timeoutConfig.getReadTimeout()); factory.setConnectTimeout(timeoutConfig.getConnectTimeout()); factory.setConnectionRequestTimeout(timeoutConfig.getConnectionRequestTimeout()); return factory; } else { SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); requestFactory.setConnectTimeout(timeoutConfig.getConnectTimeout()); requestFactory.setReadTimeout(timeoutConfig.getReadTimeout()); if (proxyHost != null) { requestFactory.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort))); } return requestFactory; } }