Example usage for java.util Properties Properties

List of usage examples for java.util Properties Properties

Introduction

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

Prototype

public Properties() 

Source Link

Document

Creates an empty property list with no default values.

Usage

From source file:Main.java

/**
 * Returns new properties with <code>String.trim()</code> applied to every property value.  The original properties are unchanged.
 *///from   ww w .j a  va 2 s . c  om
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.sosee.util.PropertyUtil.java

public static void writePropertiesFile(String key, String value) {
    Properties properties = new Properties();
    try {//from  w  w w .  j  av a  2  s  .  c  o  m
        OutputStream outputStream = new FileOutputStream(getFilePath());
        properties.setProperty(key, value);

        properties.store(outputStream, "user register");
        outputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

/**
 * Return XQuery XML serialization properties for pretty XML output formatting.
 * /*from  w  w w. j  a  v  a 2s.  c o  m*/
 * @return XML serialization properties for printouts
 */
public static Properties newSerializationPropertiesForPrintout() {
    final Properties serializationProps = new Properties();
    // Make sure we output in XML format
    serializationProps.setProperty("method", "xml");
    // Pretty printing
    serializationProps.setProperty("indent", "yes");
    return serializationProps;
}

From source file:com.github.ferstl.spring.jdbc.oracle.dsconfig.PoolProperties.java

public static Properties createFromEnvironment(Environment env) {
    Properties props = new Properties();
    props.setProperty("url", env.getProperty("db.url"));
    props.setProperty("username", env.getProperty("db.username"));
    props.setProperty("password", env.getProperty("db.password"));
    props.setProperty("defaultAutoCommit ", env.getProperty("db.defaultAutoCommit"));

    props.setProperty("driverClassName", env.getProperty("driverClassName"));
    props.setProperty("maxActive", env.getProperty("maxActive"));
    props.setProperty("maxIdle", env.getProperty("maxIdle"));
    props.setProperty("minIdle", env.getProperty("minIdle"));
    props.setProperty("initialSize", env.getProperty("initialSize"));

    return props;
}

From source file:Main.java

/**
 * Convert a map to a {@link Properties} object.
 *
 * @param map//from w  ww  . ja  va 2s. com
 *            map object
 * @return properties view of the map
 */
public static Properties asProperties(final Map<String, String> map) {
    final Properties properties = new Properties();
    for (final Map.Entry<String, String> entry : map.entrySet()) {
        properties.setProperty(entry.getKey(), entry.getValue());
    }
    return properties;

}

From source file:Main.java

/**
 * Converts properties from file storage format
 *///from  ww w . j a  va 2  s  .c  om
public static Properties fromFileContent(String content) {
    try {
        StringReader reader = new StringReader(content);
        Properties props = new Properties();
        props.load(reader);
        return props;
    } catch (IOException ioe) {
        throw new IllegalStateException(ioe); // shouldn't happen
    }
}

From source file:com.cyclopsgroup.tornado.utils.ConfigurationUtils.java

/**
 * Get properties from given configuration node
 *
 * @param root Configuration node root/*from  w  w  w .jav  a  2s. c om*/
 * @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:com.netpet.spools.spring.springcase.ActionFactory.java

public static Action getAction(String actionName) {
    Properties pro = new Properties();

    try {//  w ww.  ja v  a 2 s.  c  om
        pro.load(new FileInputStream(System.getProperty("user.dir") + "/springTest/" + "config.properties"));
        String actionImplName = (String) pro.get(actionName);
        String actionMessage = (String) pro.get(actionName + "_msg");
        Object obj = Class.forName(actionImplName).newInstance();
        BeanUtils.setProperty(obj, "message", actionMessage);

        return (Action) obj;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.eclipse.dirigible.cli.utils.Utils.java

public static Properties loadCLIProperties(String[] args) {
    Properties propeties = new Properties();
    for (String next : args) {
        String[] properties = next.split(SPLITTER);
        propeties.put(properties[0], properties[1]);
    }//from w ww .jav  a  2 s.co m
    return propeties;
}

From source file:Main.java

/**
 * Reads Properties from given inputStream and returns it.
 * NOTE: the given stream is closed by this method
 *///from  w w w . ja v a2s  .  c o m
public static Properties readProperties(InputStream is, Properties props) throws IOException {
    if (props == null)
        props = new Properties();
    try {
        props.load(is);
    } finally {
        is.close();
    }
    return props;
}