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:com.cyclopsgroup.tornado.utils.ConfigurationUtils.java

/**
 * Get properties from given configuration node
 *
 * @param root Configuration node root/*w w w.jav a 2s .  c o  m*/
 * @return Properties object
 * @throws ConfigurationException Illegal format of configuration
 */
public static Properties getProperties(Configuration root) throws ConfigurationException {
    Properties p = new Properties();
    Configuration[] confs = root.getChildren("property");
    for (int i = 0; i < confs.length; i++) {
        Configuration conf = confs[i];
        String name = conf.getAttribute("name");
        String value = conf.getValue(StringUtils.EMPTY);
        if (StringUtils.isNotEmpty(name)) {
            p.setProperty(name, value);
        }
    }
    return p;
}

From source file:Main.java

/**
 * Converts XML {@code <property name=""></property>} tags to Properties
 * object./* ww w  .  j a  v  a 2s.c o  m*/
 * 
 * @see java.util.XmlUtils.importProperties()
 * 
 * @param entries
 *            List of property nodes in the DOM
 */
public static Properties importProperties(NodeList entries) {
    Properties props = new Properties();
    int numEntries = entries.getLength();
    for (int i = 0; i < numEntries; i++) {
        Element entry = (Element) entries.item(i);
        if (entry.hasAttribute("name")) {
            Node n = entry.getFirstChild();
            String val = (n == null) ? "" : n.getNodeValue();
            props.setProperty(entry.getAttribute("name"), val);
        }
    }
    return props;
}

From source file:com.hangum.tadpole.commons.libs.core.define.PublicTadpoleDefine.java

/**
 * Setting SQL Client Info/*ww w.  j a  v a2  s. c om*/
 * @return
 */
public static Properties getSQLClientInfo() {
    Properties prop = new Properties();
    prop.setProperty("ApplicationName", String.format("%s %s %s", SystemDefine.NAME, SystemDefine.MAJOR_VERSION,
            SystemDefine.RELEASE_DATE));
    prop.setProperty("ClientUser", RWT.getRequest().getRemoteHost());
    prop.setProperty("ClientHostname", RWT.getRequest().getLocalAddr());

    return prop;
}

From source file:Main.java

/**
 * Fix properties keys./* www . j  a v a  2s .  c om*/
 *
 * @param prop
 *            the prop
 */
public static void fixPropertiesKeys(final Properties prop) {
    final Enumeration<Object> keys = prop.keys();
    while (keys.hasMoreElements()) {
        final String currentKey = (String) keys.nextElement();
        final String fixedKey = fixPropertyKey(currentKey);
        final String value = prop.getProperty(currentKey);
        prop.remove(currentKey);
        prop.setProperty(fixedKey, value);
    }
}

From source file:org.keycloak.testsuite.adapter.federation.AbstractKerberosAdapterTest.java

protected static LDAPEmbeddedServer createServer() {
    Properties defaultProperties = new Properties();
    defaultProperties.setProperty(LDAPEmbeddedServer.PROPERTY_DSF, LDAPEmbeddedServer.DSF_INMEMORY);
    defaultProperties.setProperty(LDAPEmbeddedServer.PROPERTY_LDIF_FILE,
            "classpath:kerberos/users-kerberos.ldif");
    return new KerberosEmbeddedServer(defaultProperties);
}

From source file:com.github.robozonky.installer.RoboZonkyInstallerListener.java

static CommandLinePart prepareJmx() {
    final boolean isJmxEnabled = Boolean.parseBoolean(Variables.IS_JMX_ENABLED.getValue(DATA));
    final CommandLinePart clp = new CommandLinePart()
            .setProperty("com.sun.management.jmxremote", isJmxEnabled ? "true" : "false")
            // the buffer is effectively a memory leak; we'll reduce its size from 1000 to 10
            .setProperty("jmx.remote.x.notification.buffer.size", "10");
    if (!isJmxEnabled) { // ignore JMX
        return clp;
    }//from ww w.j  a  v a  2 s .c om
    // write JMX properties file
    final Properties props = new Properties();
    props.setProperty("com.sun.management.jmxremote.authenticate",
            Variables.IS_JMX_SECURITY_ENABLED.getValue(DATA));
    props.setProperty("com.sun.management.jmxremote.ssl", "false");
    final String port = Variables.JMX_PORT.getValue(DATA);
    props.setProperty("com.sun.management.jmxremote.rmi.port", port);
    props.setProperty("com.sun.management.jmxremote.port", port);
    try {
        Util.writeOutProperties(props, JMX_PROPERTIES_FILE);
    } catch (final Exception ex) {
        throw new IllegalStateException("Failed writing JMX configuration.", ex);
    }
    // configure JMX to read the props file
    return clp.setProperty("com.sun.management.config.file", JMX_PROPERTIES_FILE.getAbsolutePath())
            .setProperty("java.rmi.server.hostname", Variables.JMX_HOSTNAME.getValue(DATA));
}

From source file:com.wavemaker.common.util.SystemUtils.java

/**
 * Add all properties from p that are not set in org.
 *///from  www . jav a 2  s . c om
public static void addAllUnlessSet(Properties org, Properties p) {
    for (String s : CastUtils.<String>cast(p.keySet())) {
        if (!org.containsKey(s)) {
            org.setProperty(s, p.getProperty(s));
        }
    }
}

From source file:com.uber.hoodie.common.model.HoodieTestUtils.java

public static HoodieTableMetaClient initTableType(Configuration hadoopConf, String basePath,
        HoodieTableType tableType) throws IOException {
    Properties properties = new Properties();
    properties.setProperty(HoodieTableConfig.HOODIE_TABLE_NAME_PROP_NAME, RAW_TRIPS_TEST_NAME);
    properties.setProperty(HoodieTableConfig.HOODIE_TABLE_TYPE_PROP_NAME, tableType.name());
    properties.setProperty(HoodieTableConfig.HOODIE_PAYLOAD_CLASS_PROP_NAME, HoodieAvroPayload.class.getName());
    return HoodieTableMetaClient.initializePathAsHoodieDataset(hadoopConf, basePath, properties);
}

From source file:gobblin.kafka.writer.KafkaDataWriter.java

private static Properties stripPrefix(Properties props, String prefix) {
    Properties strippedProps = new Properties();
    int prefixLength = prefix.length();
    for (String key : props.stringPropertyNames()) {
        if (key.startsWith(prefix)) {
            strippedProps.setProperty(key.substring(prefixLength), props.getProperty(key));
        }/*from w  ww . j av  a  2s .c om*/
    }
    return strippedProps;
}

From source file:com.cisco.dbds.utils.report.CustomReport.java

/**
 * Sendmail./*  w ww  .  j  a  va2  s.  c o m*/
 *
 * @param msg the msg
 * @throws AddressException the address exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static void sendmail(String msg) throws AddressException, IOException {
    //Properties CustomReport_CONFIG = new Properties();
    //FileInputStream fn = new FileInputStream(System.getProperty("user.dir")+ "/src/it/resources/config.properties");
    //CustomReport_CONFIG.load(fn);
    String from = "automationreportmailer@cisco.com";
    // String from = "sitaut@cisco.com";
    //String host = System.getProperty("MAIL.SMTP.HOST");
    String host = "outbound.cisco.com";
    // Mail to details
    Properties properties = System.getProperties();
    properties.setProperty("mail.smtp.host", host);
    // String ecsip = CustomReport_CONFIG.getProperty("ecsip");
    javax.mail.Session session = javax.mail.Session.getDefaultInstance(properties);

    // compose the message
    try {
        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress(from
        // ));
                , "Automation Report Mailer"));
        //message.addRecipients(Message.RecipientType.TO, System.getProperty("MAIL.TO"));
        //message.setSubject(System.getProperty("mail.subject"));

        message.addRecipients(Message.RecipientType.TO, "maparame@cisco.com");
        message.setSubject("VCS consle report");
        Multipart mp = new MimeMultipart();
        MimeBodyPart htmlPart = new MimeBodyPart();
        htmlPart.setContent(msg, "text/html");
        mp.addBodyPart(htmlPart);
        message.setContent(mp);
        Transport.send(message);
        System.out.println(msg);
        System.out.println("message sent successfully....");

    } catch (MessagingException mex) {
        mex.printStackTrace();
    } catch (Exception e) {
        System.out.println("\tException in sending mail to configured mailers list");
    }
}