Example usage for java.util Properties getProperty

List of usage examples for java.util Properties getProperty

Introduction

In this page you can find the example usage for java.util Properties getProperty.

Prototype

public String getProperty(String key) 

Source Link

Document

Searches for the property with the specified key in this property list.

Usage

From source file:com.chiralbehaviors.seurat.service.DemoScenarioTest.java

@BeforeClass
public static void createEMF() throws IOException, SQLException {
    if (emf == null) {
        InputStream is = ModelTest.class.getResourceAsStream("/jpa.properties");
        assertNotNull("jpa properties missing", is);
        Properties properties = new Properties();
        properties.load(is);/*from  w ww  .  j  ava2s.  co  m*/
        System.out.println(
                String.format("Database URL: %s", properties.getProperty("javax.persistence.jdbc.url")));
        emf = Persistence.createEntityManagerFactory(WellKnownObject.CORE, properties);
    }
}

From source file:com.tacitknowledge.util.migration.jdbc.util.ConfigurationUtil.java

/**
 * Returns the value of the specified configuration parameter.
 *
 * @param props the properties file containing the values
 * @param param the parameter to return//from ww w.  ja  v  a 2s.  co  m
 * @return the value of the specified configuration parameter
 * @throws IllegalArgumentException if the parameter does not exist
 */
public static String getRequiredParam(Properties props, String param) throws IllegalArgumentException {
    String value = props.getProperty(param);
    if (value == null) {
        log.warn("Parameter named: " + param + " was not found.");
        log.warn("-----Parameters found-----");
        Iterator propNameIterator = props.keySet().iterator();
        while (propNameIterator.hasNext()) {
            String name = (String) propNameIterator.next();
            String val = props.getProperty(name);
            log.warn(name + " = " + val);
        }
        log.warn("--------------------------");
        throw new IllegalArgumentException(
                "'" + param + "' is a required " + "initialization parameter.  Aborting.");
    }
    return value;
}

From source file:com.axiomine.largecollections.utilities.KryoUtils.java

public static void registerKryoClasses(Kryo kryo, String propFile) throws Exception {
    FileReader fReader = new FileReader(new File(propFile));
    Properties props = new Properties();
    props.load(fReader);/*from   w w  w.j a  v a  2  s .c o  m*/
    Set ks = props.keySet();
    for (Object k : ks) {
        Class c = Class.forName((String) k);
        Class s = Class.forName(props.getProperty((String) k));
        Serializer ss = (Serializer) s.newInstance();
        kryo.register(c, ss);
    }

}

From source file:net.ontopia.utils.PropertyUtils.java

public static Map<String, String> toMap(Properties properties) {
    Map<String, String> result = new HashMap<String, String>(properties.size());
    for (String key : properties.stringPropertyNames()) {
        result.put(key, properties.getProperty(key));
    }// w w w.  jav a  2s.  co m
    return result;
}

From source file:Main.java

/**
 * Converts a Properties object into a Map.
 * /*w w w.  j  a  v a  2s .  c  om*/
 * @param properties
 *            set of string key-value pairs
 * @returns map of key-value pairs (never null)
 */
public static Map<String, String> getMapFromProperties(Properties props) {
    Map<String, String> map = new HashMap<String, String>();

    if (props != null) {
        Enumeration<Object> e = props.keys();
        while (e.hasMoreElements()) {
            String s = (String) e.nextElement();
            map.put(s, props.getProperty(s));
        }
    }

    return map;
}

From source file:it.infn.ct.futuregateway.apiserver.inframanager.JobDescriptionFactory.java

/**
 * Sets an optional parameter in the job description.
 *
 * @param desc The job description to modify
 * @param prop The set of properties for the job
 * @param name The name of the properties to add
 * @param multi True if the properties has multiple values, false otherwise.
 * If there are multiple values these are separated by ',' or ';'
 *///from   w  ww  . j  a  v  a  2 s . c o m
private static void setOptionalParam(final JobDescription desc, final Properties prop, final String name,
        final boolean multi) {
    String value = prop.getProperty(name);
    if (value != null) {
        try {
            if (multi) {
                desc.setVectorAttribute(name, value.split(",|;"));
            } else {
                desc.setAttribute(name, value);
            }
        } catch (NotImplementedException | AuthenticationFailedException | AuthorizationFailedException
                | PermissionDeniedException | IncorrectStateException | BadParameterException
                | DoesNotExistException | TimeoutException | NoSuccessException ex) {
            LOG.warn("Problem with the attribute '" + name + "': " + ex.getMessage());
        }
    }
}

From source file:com.stratelia.silverpeas.silvertrace.MsgTrace.java

/**
 * Reads a boolean property and return it's boolean value
 * @param theProps the Properties object
 * @param propertyName the name of the property to test
 * @param defaultValue the default value to set to the property if it doesn't exist
 * @return true/false// ww w. j  a v  a  2  s  . c o m
 * @see
 */
static public boolean getBooleanProperty(Properties theProps, String propertyName, boolean defaultValue) {
    boolean valret = defaultValue;
    String value = theProps.getProperty(propertyName);
    if (value != null) {
        valret = "true".equalsIgnoreCase(value);
    }
    return valret;
}

From source file:io.apiman.servers.gateway_es.Starter.java

/**
 * Loads properties from a file and puts them into system properties.
 *//*from  w ww .  j a  va  2 s.  co m*/
@SuppressWarnings({ "nls", "unchecked" })
protected static void loadProperties() {
    URL configUrl = Starter.class.getClassLoader().getResource("gateway_es-apiman.properties");
    if (configUrl == null) {
        throw new RuntimeException(
                "Failed to find properties file (see README.md): gateway_es-apiman.properties");
    }
    InputStream is = null;
    try {
        is = configUrl.openStream();
        Properties props = new Properties();
        props.load(is);
        Enumeration<String> names = (Enumeration<String>) props.propertyNames();
        while (names.hasMoreElements()) {
            String name = names.nextElement();
            String value = props.getProperty(name);
            System.setProperty(name, value);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:io.hawkcd.agent.AgentConfiguration.java

private static void getUserEnteredSettings() {
    Properties configFileProperties = fetchConfigFileProperties();

    String agentId = configFileProperties.getProperty("agentId");
    agentInfo.setId((agentId != null && !agentId.isEmpty()) ? agentId : generateAgentId(configFileProperties));

    String agentName = configFileProperties.getProperty("agentName");
    agentInfo.setName((agentName != null && !agentName.isEmpty()) ? agentName : ConfigConstants.AGENT_NAME);
    agentInfo.setConnected(true);/*from  ww  w  .  j a va  2s.  com*/
    agentInfo.setEnabled(false);
    agentInfo.setRootPath(ConfigConstants.AGENT_SANDBOX);
    agentInfo.setLastReportedTime(null);
    try {
        agentInfo.setHostName(InetAddress.getLocalHost().getHostName());
        agentInfo.setIpAddress(InetAddress.getLocalHost().getHostAddress());
        agentInfo.setOperatingSystem(System.getProperty("os.name"));

    } catch (UnknownHostException e) {
        agentInfo.setHostName("unknown");
        agentInfo.setIpAddress("unknown");
        agentInfo.setOperatingSystem("not available");
    }

    String agentPipelinesDir = configFileProperties.getProperty("agentPipelinesDir");
    installInfo.setAgentPipelinesDir(
            (agentPipelinesDir != null && !agentPipelinesDir.isEmpty()) ? agentPipelinesDir
                    : ConfigConstants.AGENT_PIPELINES_DIR);

    String serverName = configFileProperties.getProperty("serverName");
    installInfo.setServerName(
            (serverName != null && !serverName.isEmpty()) ? serverName : ConfigConstants.SERVER_NAME);

    String serverPort = configFileProperties.getProperty("serverPort");
    installInfo.setServerPort((serverPort != null && !serverPort.isEmpty()) ? Integer.parseInt(serverPort)
            : ConfigConstants.SERVER_PORT);

    installInfo.setServerAddress(
            String.format("http://%s:%s", installInfo.getServerName(), installInfo.getServerPort()));

    installInfo.setReportJobApiAddress(String.format("%s/%s", installInfo.getServerAddress(),
            String.format(ConfigConstants.SERVER_REPORT_JOB_API_ADDRESS, getAgentInfo().getId())));

    installInfo.setReportAgentApiAddress(String.format("%s/%s/%s/%s", installInfo.getServerAddress(),
            ConfigConstants.SERVER_REPORT_AGENT_API_ADDRESS, getAgentInfo().getId(), "report"));

    installInfo.setCheckForWorkApiAddress(String.format("%s/%s", installInfo.getServerAddress(),
            String.format(ConfigConstants.SERVER_CHECK_FOR_WORK_API_ADDRESS, getAgentInfo().getId())));

    installInfo.setCreateArtifactApiAddress(String.format("%s/%s", installInfo.getServerAddress(),
            ConfigConstants.SERVER_CREATE_ARTIFACT_API_ADDRESS));

    installInfo.setFetchArtifactApiAddress(String.format("%s/%s", installInfo.getServerAddress(),
            ConfigConstants.SERVER_FETCH_ARTIFACT_API_ADDRESS));

    installInfo.setAgentSandbox(Paths.get(ConfigConstants.AGENT_SANDBOX).toString());

    installInfo.setAgentTempDirectoryPath(
            Paths.get(ConfigConstants.AGENT_SANDBOX, ConfigConstants.AGENT_TEMP_DIR).toString());

    installInfo.setAgentArtifactsDirectoryPath(
            Paths.get(ConfigConstants.AGENT_SANDBOX, ConfigConstants.ARTIFACTS_DIRECTORY).toString());
}

From source file:com.groupdocs.ui.Utils.java

public static String getProjectProperty(String name) {
    Properties p = new Properties();
    try (InputStream i = Utils.class.getResourceAsStream("/project.properties")) {
        p.load(i);//w  w  w  .j a v  a  2s .c  o m
    } catch (IOException e) {
        // Ignore
    }
    return p.getProperty(name);
}