Example usage for java.util Properties setProperty

List of usage examples for java.util Properties setProperty

Introduction

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

Prototype

public synchronized Object setProperty(String key, String value) 

Source Link

Document

Calls the Hashtable method put .

Usage

From source file:Main.java

public static boolean clearProperty(String filePath, String fileName, String propertyName) {
    try {//  ww  w  .  j a va2  s  .c  o  m
        Properties p = loadPropertyInstance(filePath, fileName);
        p.setProperty(propertyName, "");
        String comment = propertyName;
        return storePropertyInstance(filePath, fileName, p, comment);
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:Main.java

public static boolean setProperty(String filePath, String fileName, String propertyName, String propertyValue) {
    try {/*from  w w w .j  a  v  a2 s  . c o m*/
        Properties p = loadPropertyInstance(filePath, fileName);
        p.setProperty(propertyName, propertyValue);
        String comment = "Update '" + propertyName + "' value";
        return storePropertyInstance(filePath, fileName, p, comment);
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:eu.learnpad.simulator.mon.utils.Manager.java

public static Properties createConsumerSettingsPropertiesObject(String javaNamingFactoryInitial,
        String javaNamingProviderUrl, String javaNamingSecurityPrincipal, String javaNamingSecurityCredential,
        String connectionFactoryNames, String topicServiceTopic, boolean debug, String consumerName) {
    if (debug)/*from w w  w. ja v  a 2s.  c  o m*/
        DebugMessages.print(TimeStamp.getCurrentTime(), "Consumer", "Creating Properties object ");
    Properties settings = new Properties();
    settings.setProperty("java.naming.factory.initial", javaNamingFactoryInitial);
    settings.setProperty("java.naming.provider.url", javaNamingProviderUrl);
    settings.setProperty("java.naming.security.principal", javaNamingSecurityPrincipal);
    settings.setProperty("java.naming.security.credential", javaNamingSecurityCredential);
    settings.setProperty("connectionFactoryNames", connectionFactoryNames);
    settings.setProperty("topic.serviceTopic", topicServiceTopic);
    settings.setProperty("consumerName", consumerName);
    if (debug) {
        DebugMessages.ok();
        DebugMessages.line();
    }
    return settings;
}

From source file:com.nokia.dempsy.mpcluster.zookeeper.ZookeeperTestServer.java

private static Properties genZookeeperConfig(File zkDir) throws IOException {
    Properties props = new Properties();
    props.setProperty("timeTick", "2000");
    props.setProperty("initLimit", "10");
    props.setProperty("syncLimit", "5");
    try {//from   ww w . j  a  v  a  2  s  . com
        props.setProperty("dataDir", zkDir.getCanonicalPath());
    } catch (IOException e) {
        fail("Can't create zkConfig, zkDir has no path");
    }

    props.setProperty("clientPort", String.valueOf(port));
    return props;
}

From source file:eu.learnpad.simulator.mon.utils.Manager.java

public static Properties createProbeSettingsPropertiesObject(String javaNamingFactoryInitial,
        String javaNamingProviderUrl, String javaNamingSecurityPrincipal, String javaNamingSecurityCredential,
        String connectionFactoryNames, String topicProbeTopic, boolean debug, String probeName,
        String probeChannel) {//from w  w  w  . j  ava 2 s.c  o  m
    if (debug)
        DebugMessages.print(TimeStamp.getCurrentTime(), GlimpseAbstractProbe.class.getSimpleName(),
                "Creating Properties object ");
    Properties settings = new Properties();
    settings.setProperty("java.naming.factory.initial", javaNamingFactoryInitial);
    settings.setProperty("java.naming.provider.url", javaNamingProviderUrl);
    settings.setProperty("java.naming.security.principal", javaNamingSecurityPrincipal);
    settings.setProperty("java.naming.security.credential", javaNamingSecurityCredential);
    settings.setProperty("connectionFactoryNames", connectionFactoryNames);
    settings.setProperty("topic.probeTopic", topicProbeTopic);
    settings.setProperty("probeName", probeName);
    settings.setProperty("probeChannel", probeChannel);
    if (debug) {
        DebugMessages.ok();
        DebugMessages.line();
    }
    return settings;
}

From source file:de.ingrid.interfaces.csw.admin.command.AdminManager.java

/**
 * Read the override configuration and convert the clear text password to a bcrypt-hash,
 * which is used and needed by the base-webapp v3.6.1 
 *//*  ww w  .ja  v a2 s  . c  om*/
private static void migratePassword() {
    try {
        InputStream is = new FileInputStream("conf/config.properties");
        Properties props = new Properties();
        props.load(is);
        String oldPassword = props.getProperty("ingrid.admin.password");
        is.close();

        props.setProperty("ingrid.admin.password", BCrypt.hashpw(oldPassword, BCrypt.gensalt()));

        OutputStream os = new FileOutputStream("conf/config.override.properties");
        props.store(os, "Override configuration written by the application");
        os.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.netflix.iep.config.TestResourceConfiguration.java

public static void load(String propFile, Map<String, String> subs, Map<String, String> overrides)
        throws IOException {
    URL propUrl = Resources.getResource(propFile);
    String propData = Resources.toString(propUrl, Charsets.UTF_8);
    for (Map.Entry e : subs.entrySet()) {
        propData = propData.replaceAll("\\{" + e.getKey() + "\\}", (String) e.getValue());
    }/*from   w  ww. java 2  s.  co m*/
    final Properties props = new Properties();
    props.load(new ByteArrayInputStream(propData.getBytes()));
    for (Map.Entry e : overrides.entrySet()) {
        props.setProperty((String) e.getKey(), (String) e.getValue());
    }

    ConfigurationManager.getConfigInstance().clear();
    ConfigurationManager.loadProperties(props);
}

From source file:de.ee.hezel.PDFCompareMain.java

public static Properties getLog4jProperties(boolean output, File logPath) {
    Properties props = new Properties();

    if (output) {
        props.setProperty("log4j.rootLogger", "debug, stdout, errorfile, resultfile");

        props.setProperty("log4j.appender.stdout", "org.apache.log4j.ConsoleAppender");
        props.setProperty("log4j.appender.stdout.layout", "org.apache.log4j.PatternLayout");
        props.setProperty("log4j.appender.stdout.layout.ConversionPattern", "%5p [%t] (%F:%L) - %m%n");
    } else//from  www .ja  v a 2 s . co m
        props.setProperty("log4j.rootLogger", "debug, errorfile, resultfile");

    File logfile = new File(logPath, "_error.log");
    props.setProperty("log4j.appender.errorfile", "org.apache.log4j.FileAppender");
    props.setProperty("log4j.appender.errorfile.File", logfile.getAbsolutePath());
    props.setProperty("log4j.appender.errorfile.Append", "false");
    props.setProperty("log4j.appender.errorfile.Threshold", "ERROR");
    props.setProperty("log4j.appender.errorfile.layout", "org.apache.log4j.PatternLayout");
    props.setProperty("log4j.appender.errorfile.layout.ConversionPattern", "%d %p %F - %m%n");

    File logfile1 = new File(logPath, "_results.log");
    props.setProperty("log4j.appender.resultfile", "org.apache.log4j.FileAppender");
    props.setProperty("log4j.appender.resultfile.File", logfile1.getAbsolutePath());
    props.setProperty("log4j.appender.resultfile.Append", "false");

    // filters in property files are supported from 1.2.16 and above 
    // http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PropertyConfigurator.html
    props.setProperty("log4j.appender.resultfile.filter.ID", "org.apache.log4j.varia.LevelRangeFilter");
    props.setProperty("log4j.appender.resultfile.filter.ID.LevelMin", "INFO");
    props.setProperty("log4j.appender.resultfile.filter.ID.LevelMax", "INFO");
    props.setProperty("log4j.appender.resultfile.layout", "org.apache.log4j.PatternLayout");
    props.setProperty("log4j.appender.resultfile.layout.ConversionPattern", "%d %p %F - %m%n");

    return props;
}

From source file:Main.java

/**
 * Returns new properties with <code>String.trim()</code> applied to every property value.  The original properties are unchanged.
 *///from w  w  w  .  j av a  2s.  co  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:Log4jPropertyHelper.java

public static void updateLog4jConfiguration(Class<?> targetClass, String log4jPath) throws Exception {
    Properties customProperties = new Properties();
    FileInputStream fs = null;//from w  w w  . j av a2 s . co  m
    InputStream is = null;
    try {
        fs = new FileInputStream(log4jPath);
        is = targetClass.getResourceAsStream("/log4j.properties");
        customProperties.load(fs);
        Properties originalProperties = new Properties();
        originalProperties.load(is);
        for (Entry<Object, Object> entry : customProperties.entrySet()) {
            originalProperties.setProperty(entry.getKey().toString(), entry.getValue().toString());
        }
        LogManager.resetConfiguration();
        PropertyConfigurator.configure(originalProperties);
    } finally {
        IOUtils.closeQuietly(is);
        IOUtils.closeQuietly(fs);
    }
}