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.commonsware.android.gcm.cmd.GCM.java

private static void sendMessage(String apiKey, List<String> devices, Properties data) throws Exception {
    Sender sender = new Sender(apiKey);
    Message.Builder builder = new Message.Builder();

    for (Object o : data.keySet()) {
        String key = o.toString();

        builder.addData(key, data.getProperty(key));
    }//from  w  w  w .j  a v a 2  s  .co  m

    MulticastResult mcResult = sender.send(builder.build(), devices, 5);

    for (int i = 0; i < mcResult.getTotal(); i++) {
        Result result = mcResult.getResults().get(i);

        if (result.getMessageId() != null) {
            String canonicalRegId = result.getCanonicalRegistrationId();

            if (canonicalRegId != null) {
                System.err.println(String.format("%s canonical ID = %s", devices.get(i), canonicalRegId));
            } else {
                System.out.println(String.format("%s success", devices.get(i)));
            }
        } else {
            String error = result.getErrorCodeName();

            if (Constants.ERROR_NOT_REGISTERED.equals(error)) {
                System.err.println(String.format("%s is unregistered", devices.get(i)));
            } else if (error != null) {
                System.err.println(String.format("%s error = %s", devices.get(i), error));
            }
        }
    }
}

From source file:com.mirth.connect.server.launcher.MirthLauncher.java

private static void createAppdataDir(Properties mirthProperties) {
    File appDataDirFile = null;/*  ww  w. j  a va  2  s  .c o  m*/

    if (mirthProperties.getProperty(PROPERTY_APP_DATA_DIR) != null) {
        appDataDirFile = new File(mirthProperties.getProperty(PROPERTY_APP_DATA_DIR));

        if (!appDataDirFile.exists()) {
            if (appDataDirFile.mkdir()) {
                logger.debug("created app data dir: " + appDataDirFile.getAbsolutePath());
            } else {
                logger.error("error creating app data dir: " + appDataDirFile.getAbsolutePath());
            }
        }
    } else {
        appDataDirFile = new File(".");
    }

    appDataDir = appDataDirFile.getAbsolutePath();
    logger.debug("set app data dir: " + appDataDir);
}

From source file:io.cloudslang.lang.tools.build.ArgumentProcessorUtils.java

/**
 * Returns a property value as boolean value, with a default in case of null.
 *
 * @param propertyKey         the key inside the properties entries.
 * @param defaultBooleanValue the default boolean value to use in case it is not present
 *                            inside the properties entries.
 * @param properties          the properties entries.
 * @return get the property or default/*from   w  w w  .  j  av  a  2s  . c o m*/
 */
public static boolean getBooleanFromPropertiesWithDefault(String propertyKey, boolean defaultBooleanValue,
        Properties properties) {
    validateArguments(propertyKey, properties);
    String valueBoolean = properties.getProperty(propertyKey);
    return (equalsIgnoreCase(valueBoolean, TRUE.toString()) || equalsIgnoreCase(valueBoolean, FALSE.toString()))
            ? parseBoolean(valueBoolean)
            : defaultBooleanValue;
}

From source file:de.mfo.jsurf.grid.RotationGrid.java

public static void loadFromProperties(Properties props) throws Exception {
    asr.setSurfaceFamily(props.getProperty("surface_equation"));

    Set<Map.Entry<Object, Object>> entries = props.entrySet();
    String parameter_prefix = "surface_parameter_";
    for (Map.Entry<Object, Object> entry : entries) {
        String name = (String) entry.getKey();
        if (name.startsWith(parameter_prefix)) {
            String parameterName = name.substring(parameter_prefix.length());
            asr.setParameterValue(parameterName, Float.parseFloat((String) entry.getValue()));
        }/* ww  w  .  j a  v a2  s .  c  o  m*/
    }

    asr.getCamera().loadProperties(props, "camera_", "");
    asr.getFrontMaterial().loadProperties(props, "front_material_", "");
    asr.getBackMaterial().loadProperties(props, "back_material_", "");
    for (int i = 0; i < asr.MAX_LIGHTS; i++) {
        asr.getLightSource(i).setStatus(LightSource.Status.OFF);
        asr.getLightSource(i).loadProperties(props, "light_", "_" + i);
    }
    asr.setBackgroundColor(BasicIO.fromColor3fString(props.getProperty("background_color")));
    setScale(Float.parseFloat(props.getProperty("scale_factor")));
    basic_rotation = BasicIO.fromMatrix4dString(props.getProperty("rotation_matrix"));
}

From source file:Main.java

/**
 * Fix properties keys./*from  w  w w.  ja va  2s . com*/
 *
 * @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:com.haulmont.yarg.console.ConsoleRunner.java

private static Map<String, Object> parseReportParams(CommandLine cmd, Report report) {
    if (cmd.hasOption(REPORT_PARAMETER)) {
        Map<String, Object> params = new HashMap<String, Object>();
        Properties optionProperties = cmd.getOptionProperties(REPORT_PARAMETER);
        for (ReportParameter reportParameter : report.getReportParameters()) {
            String paramValueStr = optionProperties.getProperty(reportParameter.getAlias());
            if (paramValueStr != null) {
                params.put(reportParameter.getAlias(),
                        converter.convertFromString(reportParameter.getParameterClass(), paramValueStr));
            }/* ww  w  .j av a  2s. c  o m*/
        }

        return params;
    } else {
        return Collections.emptyMap();
    }
}

From source file:io.apicurio.hub.api.bitbucket.BitbucketSourceConnectorTest.java

@BeforeClass
public static void globalSetUp() {
    File credsFile = new File(".bitbucket");
    if (!credsFile.isFile()) {
        return;// w  w w  . j  a  va2  s  .  c  o m
    }
    System.out.println("Loading Bitbucket credentials from: " + credsFile.getAbsolutePath());
    try (Reader reader = new FileReader(credsFile)) {
        Properties props = new Properties();
        props.load(reader);
        String userPass = props.getProperty("username") + ":" + props.getProperty("password");
        basicAuth = Base64.encodeBase64String(userPass.getBytes(StandardCharsets.UTF_8));
    } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}

From source file:com.axibase.tsd.client.ClientConfigurationFactory.java

private static String load(String name, Properties clientProperties, String defaultValue) {
    String value = System.getProperty(name);
    if (value == null) {
        value = clientProperties.getProperty(name);
        if (value == null) {
            if (defaultValue == null) {
                log.error("Could not find required property: {}", name);
                throw new IllegalStateException(name + " property is null");
            } else {
                value = defaultValue;/*from ww w  .j  a  va  2 s  .  co  m*/
            }
        }
    }
    return value;
}

From source file:com.magnet.mmx.server.plugin.mmxmgmt.wakeup.WakeupProcessorTest.java

@BeforeClass
public static void setup() throws Exception {
    InputStream inputStream = DeviceDAOImplTest.class.getResourceAsStream("/test.properties");

    Properties testProperties = new Properties();
    testProperties.load(inputStream);//  w w  w .ja v  a  2  s.c  o m

    String host = testProperties.getProperty("db.host");
    String port = testProperties.getProperty("db.port");
    String user = testProperties.getProperty("db.user");
    String password = testProperties.getProperty("db.password");
    String driver = testProperties.getProperty("db.driver");
    String schema = testProperties.getProperty("db.schema");

    String url = "jdbc:mysql://" + host + ":" + port + "/" + schema;

    ds = new BasicDataSource();
    ds.setDriverClassName(driver);
    ds.setUsername(user);
    ds.setPassword(password);
    ds.setUrl(url);
    //clean any existing records and load some records into the database.
    FlatXmlDataSetBuilder builder = new FlatXmlDataSetBuilder();
    builder.setColumnSensing(true);
    Connection setup = ds.getConnection();
    IDatabaseConnection con = new DatabaseConnection(setup);
    {
        InputStream xmlInput = DeviceDAOImplTest.class.getResourceAsStream("/data/wakeup-queue-1.xml");
        IDataSet dataSet = builder.build(xmlInput);
        DatabaseOperation.CLEAN_INSERT.execute(con, dataSet);
    }
    {
        InputStream xmlInput = DeviceDAOImplTest.class.getResourceAsStream("/data/message-data-1.xml");
        IDataSet dataSet = builder.build(xmlInput);
        DatabaseOperation.CLEAN_INSERT.execute(con, dataSet);
    }
}

From source file:hudson.plugins.blazemeter.utils.Utils.java

public static String version() {
    Properties props = new Properties();
    try {/* w ww  . j  av a 2  s .  c  o m*/
        props.load(Utils.class.getResourceAsStream("/version.properties"));
    } catch (IOException ex) {
        props.setProperty(Constants.VERSION, "N/A");
    }
    return props.getProperty(Constants.VERSION);
}