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.rhino.data.db.DataSourceFactory.java

public static DataSource getDataSource() {
    if (source != null) {
        return source;
    }/* w  ww. j a va2s .c om*/
    Properties props = new Properties();
    FileInputStream fis = null;

    BasicDataSource dataSource = new BasicDataSource();
    try {

        props.load(ClassLoader.getSystemResourceAsStream("mysql.properties"));
        dataSource.setDriverClassName(props.getProperty("MYSQL_DB_DRIVER_CLASS"));
        dataSource.setUrl(props.getProperty("MYSQL_DB_URL"));
        dataSource.setUsername(props.getProperty("MYSQL_DB_USERNAME"));
        dataSource.setPassword(props.getProperty("MYSQL_DB_PASSWORD"));

    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return source = dataSource;
}

From source file:com.taksmind.karma.functions.scheduled.Log.java

public static void uploadFile() throws IOException {
    try {//from w  w  w . j  a v a2 s .c  om
        logDirectory = new File("logs");
        if (!logDirectory.isDirectory()) {
            logDirectory.mkdir();
        }
        date = sdf.parse(sdf.format(new Date())).toString().replaceAll(" ", "")
                .replaceAll("[0-9]+:[0-9]+:[0-9]+CDT", "");

        Properties properties = new Properties(); //creates configuration object
        properties.load(new FileInputStream(Main.configuration));
        ftpServer = properties.getProperty("ftpServer");
        ftpUser = properties.getProperty("ftpUser");
        ftpPassword = properties.getProperty("ftpPassword");

        client = new FTPClient();

        client.connect(ftpServer);
        int reply = client.getReplyCode();

        if (!FTPReply.isPositiveCompletion(reply)) {
            client.disconnect();
            System.err.println("FTP server refused connection.");
        }

        if (client.login(ftpUser, ftpPassword)) {
            client.enterLocalPassiveMode();
            String localFile = logDirectory.getAbsolutePath() + "/" + date + ".log";
            String remoteFile = "/downloads/logs/" + date + ".log";
            if (Main.debug) {
                System.out.println(localFile);
                System.out.println(remoteFile);
            }
            FileInputStream fis = new FileInputStream(new File(localFile));
            if (client.storeFile(remoteFile, fis)) {
                System.out.println("File uploaded successfully.");
            } else {
                System.err.println("Uploading file failed..");
            }
            fis.close();
            client.logout();
            client.disconnect();
        } else {
            System.out.println("Could not authenticate with FTP server..");
            client.logout();
        }

    } catch (ParseException e) {
        System.err.println("Error parsing log file");
        e.printStackTrace();
    } catch (SocketException e) {
        System.err.println("some exception happened.");
        e.printStackTrace();
    } catch (IOException e) {
        System.err.println("can not open or upload file.");
        e.printStackTrace();
    } finally {
        if (client.isConnected()) {
            client.disconnect();
        }
    }
}

From source file:com.xinlv.test.PortalTestUtil.java

public static String[] getMessage(String key, Class<?> clazz) {
    Properties prop = new Properties();
    try {/*from w  ww.j  a v a 2s.co  m*/
        prop.load(clazz.getResourceAsStream(clazz.getSimpleName() + ".properties"));
    } catch (IOException e) {
        // do nothing
    }
    return new String[] { prop.getProperty(key) };
}

From source file:com.nts.alphamale.data.Settings.java

public static void loadSettings() {
    if (new File(SETTINGS).exists()) {
        Properties prop = new Properties();
        try {//from  w ww  .j  a va2  s  .c om
            prop.load(new FileReader(SETTINGS));
            if (prop.getProperty("command_timeout") != null)
                EXECUTOR_TIMEOUT = Long.parseLong(prop.getProperty("command_timeout"));
            if (prop.getProperty("double_tap_threshold") != null)
                DOUBLE_TAP_THRESHOLD = Double.parseDouble(prop.getProperty("double_tap_threshold"));
            if (prop.getProperty("long_tap_threshold") != null)
                LONG_TAP_THRESHOLD = Double.parseDouble(prop.getProperty("long_tap_threshold"));
            if (prop.getProperty("swipe_area_threshold") != null)
                SWIPE_AREA_THRESHOLD = Integer.parseInt(prop.getProperty("swipe_area_threshold"));
            if (prop.getProperty("swipe_angle_threshold") != null)
                SWIPE_ANGLE_THRESHOLD = Integer.parseInt(prop.getProperty("swipe_angle_threshold"));
            if (prop.getProperty("find_timeout") != null)
                FIND_ELEMENT_TIMEOUT = Long.parseLong(prop.getProperty("find_timeout"));
            if (prop.getProperty("idle_timeout") != null)
                WAIT_FOR_IDLE_TIMEOUT = Integer.parseInt(prop.getProperty("idle_timeout"));
            if (prop.getProperty("orientation_schedule") != null)
                ORIENTATION_SCHEDULE = Long.parseLong(prop.getProperty("orientation_schedule"));
            if (prop.getProperty("keypad_schedule") != null)
                KEYPAD_SCHEDULE = Long.parseLong(prop.getProperty("keypad_schedule"));
            if (prop.getProperty("event_interval") != null)
                EVENT_INTERVAL = Integer.parseInt(prop.getProperty("event_interval"));
            if (prop.getProperty("touchscreen_device") != null)
                TOUCH_DEVICE = prop.getProperty("touchscreen_device");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        FileWriterWithEncoding fw = null;
        String lineSeparator = System.getProperty("line.separator");
        try {
            fw = new FileWriterWithEncoding(SETTINGS, "UTF-8");
            fw.write("# command timeout(ms)" + lineSeparator);
            fw.write("command_timeout = 5000" + lineSeparator);
            fw.write(lineSeparator);
            fw.write("# double tap threshold(sec)" + lineSeparator);
            fw.write("double_tap_threshold = 0.7" + lineSeparator);
            fw.write(lineSeparator);
            fw.write("# long tap threshold(sec)" + lineSeparator);
            fw.write("long_tap_threshold = 0.7" + lineSeparator);
            fw.write(lineSeparator);
            fw.write("# swipe area threshold(px)" + lineSeparator);
            fw.write("swipe_area_threshold = 100" + lineSeparator);
            fw.write(lineSeparator);
            fw.write("# swipe angle threshold" + lineSeparator);
            fw.write("swipe_angle_threshold = 45" + lineSeparator);
            fw.write(lineSeparator);
            fw.write("# find element threshold(ms)" + lineSeparator);
            fw.write("find_timeout = 2000" + lineSeparator);
            fw.write(lineSeparator);
            fw.write("# idle threshold(ms)" + lineSeparator);
            fw.write("idle_timeout = 2000" + lineSeparator);
            fw.write(lineSeparator);
            fw.write("# orientation recognition schedule" + lineSeparator);
            fw.write("orientation_schedule = 500" + lineSeparator);
            fw.write(lineSeparator);
            fw.write("# keypad recognition schedule" + lineSeparator);
            fw.write("keypad_schedule = 500" + lineSeparator);
            fw.write(lineSeparator);
            fw.write("# follower event injection interval(ms)" + lineSeparator);
            fw.write("event_interval = 500" + lineSeparator);
            fw.write(lineSeparator);
            fw.write("# touch screen device" + lineSeparator);
            fw.write(
                    "touchscreen_device = _touchscreen,touch_dev,clearpad,sensor00,atmel_mxt_540s,synaptics_rmi,mtk-tpd");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fw.close();
            } catch (IOException e) {
            }
        }
    }
}

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

/**
 * Gets the value of the supplied property name. First it searches in system properties. If
 * not found then it examines the supplied array of command line arguments.
 *
 * @param propertyName   the property naem to get
 * @param properties     the <code>Properties</code> for the Java system
 * @param arguments      the array of command line arguments
 * @param index          the index of the property in the command line arguments
 * @param throwException if <code>true</code> then the method will throw an exception; if
 *                       <code>false</code> is supplied then it will return <code>null</code>
 * @return the property value if found; <code>null</code> otherwise
 */// w  w  w.ja  v a 2s .c om
private static String getPropertyValue(String propertyName, Properties properties, String[] arguments,
        int index, boolean throwException) {
    String value = properties.getProperty(propertyName);

    if (value == null) {
        if ((arguments != null) && (arguments.length > 0) && (index < arguments.length)) {
            value = arguments[index].trim();
        } else if (throwException) {
            throw new IllegalArgumentException("The " + propertyName + " system property is required");
        } else {
            value = null;
        }
    }

    return value;
}

From source file:Main.java

public static void xmlProps(final StringBuilder sb, final Properties props) {
    if (props != null) {
        int i = 0;
        for (Object key : props.keySet()) {
            if (i > 0)
                sb.append(';');
            sb.append(key.toString());/*from   w w  w .ja v  a 2  s  .  c  o  m*/
            sb.append("="); //$NON-NLS-1$
            sb.append(props.getProperty(key.toString()));
            i++;
        }
    }
}

From source file:com.cisco.dbds.utils.configfilehandler.ConfigFileHandler.java

/**
 * Sets the systemvariable.//from   w ww .j  ava 2  s.co  m
 *
 * @param input the new systemvariable
 */
public static void setSystemvariable(InputStream input) {
    Properties tmp1 = new Properties();
    try {
        tmp1.load(input);

        for (Object element : tmp1.keySet()) {
            System.setProperty(element.toString().trim(), tmp1.getProperty(element.toString().trim()).trim());
        }
    } catch (IOException e) {
        System.out.println("setSystemvariable method failure");
    }
}

From source file:com.github.brandtg.switchboard.JdbcBasedLogIndex.java

private static String getAndCheck(Properties config, String name) {
    String value = config.getProperty(name);
    if (value == null) {
        throw new IllegalArgumentException(name + " is required");
    }/*from   w  ww  .  j a  v a2s.  c om*/
    return value;
}

From source file:edu.pitt.dbmi.ipm.service.EnterpriseAnalytics.java

/**
 * Initializes parameters from *.conf file based on selected storage
 * parameter 'useVitOrPostgre' in jQueryPostgres.conf file
 *//*  ww w.  j a v  a 2 s.c o m*/
private static void initParams() {
    if (!hasParams) {
        hasParams = true;
        try {
            StorageFactory.getStorage().initParameters();
            hasParams = true;
            Properties params = new Properties();
            params.load(new FileInputStream(System.getProperty("user.dir") + File.separator + "resources"
                    + File.separator + StorageFactory.getStorage().getConfFileName()));

            String prefix_name = params.getProperty("prefix_name");
            String prefix = params.getProperty("prefix");

            count_patients_by_tss_Q = DataSelection
                    .queryInitReplace(params.getProperty("count_patients_by_tss"), prefix_name, prefix);
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
        }
    }
}

From source file:Main.java

public static String replaceSystemProps(String xml) {
    Properties properties = System.getProperties();
    Enumeration e = properties.propertyNames();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        String s = "${" + key + "}";
        if (xml.contains(s)) {
            xml = xml.replace(s, properties.getProperty(key));
        }// ww w.  j a  v a 2 s  .c  o m

    }
    return xml;
}