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:net.erdfelt.android.sdkfido.Build.java

public static String getVersion() {
    if (version == null) {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        String resource = String.format("META-INF/maven/%s/%s/pom.properties", GROUP_ID, ARTIFACT_ID);
        URL url = cl.getResource(resource);
        if (url == null) {
            version = "[DEV]";
        } else {//from   w ww . ja va  2 s. c  o  m
            InputStream in = null;
            try {
                in = url.openStream();
                Properties props = new Properties();
                props.load(in);
                version = props.getProperty("version");
            } catch (IOException e) {
                LOG.log(Level.WARNING, "Unable to read: " + url, e);
                version = "[UNKNOWN]";
            } finally {
                IOUtils.closeQuietly(in);
            }
        }
    }
    return version;
}

From source file:com.dragoniade.encrypt.EncryptionHelper.java

public static void encrypt(Properties p, String seedKey, String key) {
    String value = p.getProperty(key);
    String seed = p.getProperty(seedKey, seedKey);

    String encrypted;/*from   www  .j  av  a 2 s  .  com*/
    try {
        Cipher cipher = getEncrypter(seed);
        byte[] result = cipher.doFinal(value.getBytes("UTF-16"));
        encrypted = cipher.getAlgorithm() + "{" + Base64.encode(result) + "}";
    } catch (Exception e) {
        try {
            encrypted = "{" + Base64.encode(value.getBytes("UTF-16")) + "}";
        } catch (Exception e2) {
            encrypted = "{" + Base64.encode(value.getBytes()) + "}";
        }
    }

    p.setProperty(key, encrypted);
}

From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.home.page.SettingsUtil.java

public static String getVersionString() {
    Properties props = getVersionProperties();
    if ("unknown".equals(props.getProperty(PROP_VERSION))) {
        return "Version information not available";
    } else {
        return props.getProperty(SettingsUtil.PROP_VERSION) + " ("
                + props.getProperty(SettingsUtil.PROP_TIMESTAMP) + ", build "
                + props.getProperty(SettingsUtil.PROP_BUILD_NUMBER) + ")";
    }/*from   w  w  w . j  ava 2  s.c o  m*/
}

From source file:com.jdom.util.properties.PropertiesUtil.java

public static long getLong(Properties properties, String key) {
    return Long.parseLong(properties.getProperty(key));
}

From source file:com.feedeo.shopify.web.client.rest.ShopifyOAuth2RestClient.java

private static String getClientIdFromProperties(Properties properties) {
    String clientId = properties.getProperty("jopify.client_id");

    checkArgument(!isNullOrEmpty(clientId), "Client ID is not set in properties file");

    return clientId;
}

From source file:com.opengamma.examples.simulated.DBTestUtils.java

public static String getJettyPort(String configResourceLocation) throws IOException {
    Properties props = loadProperties(configResourceLocation);
    return props.getProperty("jetty.port");
}

From source file:com.jdom.util.properties.PropertiesUtil.java

public static int getInteger(Properties properties, String key) {
    return Integer.parseInt(properties.getProperty(key));
}

From source file:Main.java

/**
 * Returns new properties with <code>String.trim()</code> applied to every property value.  The original properties are unchanged.
 *///w ww .  ja  v  a  2s .  c o m
public static Properties toTrimmedProperties(Properties props) {
    Properties trimmed = new Properties();
    for (String name : props.stringPropertyNames()) {
        String val = props.getProperty(name);
        val = val == null ? val : val.trim();
        trimmed.setProperty(name, val);
    }
    return trimmed;
}

From source file:com.feedeo.shopify.web.client.rest.ShopifyOAuth2RestClient.java

private static String getClientSecretFromProperties(Properties properties) {
    String clientSecret = properties.getProperty("jopify.client_secret");

    checkArgument(!isNullOrEmpty(clientSecret), "Client secret is not set in properties file");

    return properties.getProperty("jopify.client_secret");
}

From source file:il.ac.tau.yoavram.pes.SpringRunner.java

public static void run(String[] args) throws IOException {
    System.out.println("Starting " + SpringRunner.class.getSimpleName());
    SimulationConfigurer configurer = new SimulationConfigurer(args);
    if (configurer.getSpringXmlConfig() == null) {
        System.err.println("Spring XML config file not defined");
        System.err.println();//from w  w  w .  j  a  va2 s  .c o  m
        System.exit(1);
    }
    if (configurer.getProperties() == null) {
        System.err.println("Properties not defined");
        System.err.println();
        System.exit(1);
    }

    // get the properties
    Properties properties = configurer.getProperties();
    String jobName = properties.getProperty(SimulationConfigurer.JOB_NAME_KEY);

    // create context
    AbstractXmlApplicationContext context = new ClassPathXmlApplicationContext();

    // add properties to context
    logger.info("Adding properties to context: " + properties.toString());
    PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer();
    propertyPlaceholderConfigurer.setProperties(properties);
    context.addBeanFactoryPostProcessor(propertyPlaceholderConfigurer);

    // set config location
    String configLocation = configurer.getSpringXmlConfig().toString();
    logger.info("Loading context from file " + configLocation);
    context.setConfigLocation(configLocation);

    // make sure destroy methods will be called and refresh the context
    context.registerShutdownHook();
    context.refresh();

    // persist properties
    try {
        PropertiesPersister persister = context.getBean(PropertiesPersister.class);
        if (persister != null) {
            persister.persist(properties);
        }
    } catch (NoSuchBeanDefinitionException e) {
        // nothing to do
    }

    // get the simulation bean and run it
    Simulation simulation = context.getBean("simulation", Simulation.class);

    logger.debug("Starting simulation " + jobName);
    simulation.start();
}