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, String defaultValue) 

Source Link

Document

Searches for the property with the specified key in this property list.

Usage

From source file:forge.properties.ForgeProfileProperties.java

private static String getDir(final Properties props, final String propertyKey, final String defaultVal) {
    String retDir = props.getProperty(propertyKey, defaultVal).trim();
    if (retDir.isEmpty()) {
        // use default if dir is "defined" as an empty string in the properties file
        retDir = defaultVal;//from w  ww .  j av  a  2  s.  c  om
    }

    // canonicalize
    retDir = new File(retDir).getAbsolutePath();

    // ensure path ends in a slash
    if (File.separatorChar == retDir.charAt(retDir.length() - 1)) {
        return retDir;
    }
    return retDir + File.separatorChar;
}

From source file:gobblin.util.SchedulerUtils.java

private static Set<String> getJobConfigurationFileExtensions(Properties properties) {
    Iterable<String> jobConfigFileExtensionsIterable = Splitter.on(",").omitEmptyStrings().trimResults()
            .split(properties.getProperty(ConfigurationKeys.JOB_CONFIG_FILE_EXTENSIONS_KEY,
                    ConfigurationKeys.DEFAULT_JOB_CONFIG_FILE_EXTENSIONS));
    return ImmutableSet
            .copyOf(Iterables.transform(jobConfigFileExtensionsIterable, new Function<String, String>() {
                @Override//w  ww  .j  av  a2s .  c  o  m
                public String apply(String input) {
                    return null != input ? input.toLowerCase() : "";
                }
            }));
}

From source file:it.dontesta.sugarcrm.webservices.client.OAuthSimpleClientTest.java

/**
 * Loads the host, port, and method from the properties file the first time
 * this method is run./*from w  w  w.  j av  a  2s  .com*/
 */
private static void setConnectionParams() {
    if (null == getHost() || null == getPort() || null == getPort()) {
        Properties prop = loadProperties();
        setHost(prop.getProperty("oauth.hostname", DEFAULT_HOST));
        setPort(prop.getProperty("oauth.port", DEFAULT_PORT));
        setMethod(prop.getProperty("oauth.method", DEFAULT_METHOD));
        setApiUrl(prop.getProperty("oauth.apiurl", DEFAULT_API_RESOURCE));
        setPlatform(prop.getProperty("oauth.platform", DEFAULT_PLATFORM));
    }
}

From source file:com.facebook.tsdb.tsdash.server.TsdbServlet.java

private static void loadConfiguration() {
    Properties tsdbConf = new Properties();
    try {/*w w  w . ja  v a  2  s.c om*/
        PropertyConfigurator.configure(LOG4J_PROPERTIES_FILE);
        tsdbConf.load(new FileInputStream(PROPERTIES_FILE));
        HBaseConnection.configure(tsdbConf);
        URLPattern = tsdbConf.getProperty(URL_PATTERN_PARAM, DEFAULT_URL_PATTERN);
        logger.info("URL pattern: " + URLPattern);
        plotsDir = tsdbConf.getProperty(PLOTS_DIR_PARAM, DEFAULT_PLOTS_DIR);
        logger.info("Plots are being written to: " + plotsDir);
    } catch (FileNotFoundException e) {
        System.err.println("Cannot find " + PROPERTIES_FILE);
    } catch (IOException e) {
        System.err.println("Cannot read " + PROPERTIES_FILE);
    }
}

From source file:com.roche.iceboar.settings.GlobalSettingsFactory.java

/**
 * Reads system properties (incl. those specified in JNLP file).
 *
 * @param args// w w w.jav a 2s  .com
 */
public static GlobalSettings getGlobalSettings(String[] args) {
    long jvmStartTime = ManagementFactory.getRuntimeMXBean().getStartTime();

    String codeBase = getCodeBase();

    Properties properties = System.getProperties();
    boolean showDebug = getShowDebug(properties);
    String frameTitle = properties.getProperty(JNLP_FRAME_TITLE, DEFAULT_FRAME_TITLE);
    String currentJavaVersion = properties.getProperty(JAVA_VERSION);
    String targetJavaVersion = getTargetJavaVersion(currentJavaVersion, properties);
    String tempDirectory = properties.getProperty(TEMP_DIRECTORY);
    String mainClass = properties.getProperty(JNLP_MAIN_CLASS);
    String targetJavaURL = getTargetJavaUrl(codeBase, properties);
    List<String> jarURLs = getDependenciesJars(codeBase, properties);
    List<String> allPropertiesForTarget = getAllPropertiesForTarget(properties);
    String initialHeapSize = properties.getProperty(JNLP_INITIAL_HEAP_SIZE);
    String maxHeapSize = properties.getProperty(JNLP_MAX_HEAP_SIZE);
    String javaVmArgs = properties.getProperty(JNLP_JAVA_VM_ARGS);
    String operationSystemName = properties.getProperty(OS_NAME);
    String pathSeparator = properties.getProperty(PATH_SEPARATOR);
    boolean closeOnEnd = getCloseOnEnd(properties);
    String cachePath = tempDirectory + ".IceBoar.cache";
    CacheStatus cacheStatus = getCacheStatus(cachePath);
    List<String> icons = getIcons(codeBase, properties);
    String splash = getSplashScreen(codeBase, properties);
    boolean hideFrameBorder = getHideFrameBorder(properties);

    GlobalSettings settings = GlobalSettings.builder().applicationArguments(args).jvmStartTime(jvmStartTime)
            .showDebug(showDebug).frameTitle(frameTitle).currentJavaVersion(currentJavaVersion)
            .targetJavaVersion(targetJavaVersion).tempDirectory(tempDirectory).mainClass(mainClass)
            .targetJavaURL(targetJavaURL).jarURLs(jarURLs).allPropertiesForTarget(allPropertiesForTarget)
            .operationSystemName(operationSystemName).pathSeparator(pathSeparator)
            .initialHeapSize(initialHeapSize).maxHeapSize(maxHeapSize).javaVmArgs(javaVmArgs)
            .closeOnEnd(closeOnEnd).cachePath(cachePath).cacheStatus(cacheStatus).icons(icons)
            .customSplashImage(splash).hideFrameBorder(hideFrameBorder).build();
    return settings;
}

From source file:com.willwinder.universalgcodesender.utils.SettingsFactory.java

public static Settings loadSettings() {
    // the defaults are now in the settings bean
    Settings out = new Settings();

    File settingsFile = getSettingsFile();

    // Localized setting not available here.
    //logger.info(Localization.getString("settings.log.loading"));
    logger.info("Loading settings.");
    try {/* ww  w .  jav a 2  s.  c o m*/
        if (settingsFile.getName().endsWith("json") && settingsFile.exists()) {
            //logger.log(Level.INFO, "{0}: {1}", new Object[]{Localization.getString("settings.log.location"), settingsFile});
            logger.log(Level.INFO, "Log location: {0}", settingsFile.getAbsolutePath());
            out = new Gson().fromJson(new FileReader(settingsFile), Settings.class);
        } else if (settingsFile.getName().endsWith("properties")) {
            //logger.log(Level.INFO, "{0}: {1}", new Object[]{Localization.getString("settings.log.location"), settingsFile});
            logger.log(Level.INFO, "Log location: {0}", settingsFile.getAbsolutePath());
            Properties properties = new Properties();
            properties.load(new FileInputStream(settingsFile));
            out.setLastOpenedFilename(properties.getProperty("last.dir", System.getProperty(USER_HOME)));
            out.setPort(properties.getProperty("port", ""));
            out.setPortRate(properties.getProperty("port.rate", "9600"));
            out.setManualModeEnabled(Boolean.valueOf(properties.getProperty("manualMode.enabled", FALSE)));
            out.setManualModeStepSize(Double.valueOf(properties.getProperty("manualMode.stepsize", "1")));
            out.setScrollWindowEnabled(Boolean.valueOf(properties.getProperty("scrollWindow.enabled", "true")));
            out.setVerboseOutputEnabled(
                    Boolean.valueOf(properties.getProperty("verboseOutput.enabled", FALSE)));
            out.setOverrideSpeedSelected(
                    Boolean.valueOf(properties.getProperty("overrideSpeed.enabled", FALSE)));
            out.setOverrideSpeedValue(Double.valueOf(properties.getProperty("overrideSpeed.value", "60")));
            out.setFirmwareVersion(properties.getProperty("firmwareVersion", "GRBL"));
            out.setSingleStepMode(Boolean.valueOf(properties.getProperty("singleStepMode", FALSE)));
            out.setMaxCommandLength(Integer.valueOf(properties.getProperty("maxCommandLength", "50")));
            out.setTruncateDecimalLength(Integer.valueOf(properties.getProperty("truncateDecimalLength", "4")));
            out.setRemoveAllWhitespace(Boolean.valueOf(properties.getProperty("removeAllWhitespace", "true")));
            out.setStatusUpdatesEnabled(
                    Boolean.valueOf(properties.getProperty("statusUpdatesEnabled", "true")));
            out.setStatusUpdateRate(Integer.valueOf(properties.getProperty("statusUpdateRate", "200")));
            out.setDisplayStateColor(Boolean.valueOf(properties.getProperty("displayStateColor", "true")));
            out.setConvertArcsToLines(Boolean.valueOf(properties.getProperty("convertArcsToLines", FALSE)));
            out.setSmallArcThreshold(Double.valueOf(properties.getProperty("smallArcThreshold", "2.0")));
            out.setSmallArcSegmentLength(
                    Double.valueOf(properties.getProperty("smallArcSegmentLength", "1.3")));
            out.updateMacro(1, null, null, properties.getProperty("customGcode1", "G0 X0 Y0;"));
            out.updateMacro(2, null, null, properties.getProperty("customGcode2", "G0 G91 X10;G0 G91 Y10;"));
            out.updateMacro(3, null, null, properties.getProperty("customGcode3", ""));
            out.updateMacro(4, null, null, properties.getProperty("customGcode4", ""));
            out.updateMacro(5, null, null, properties.getProperty("customGcode5", ""));
            out.setLanguage(properties.getProperty("language", "en_US"));
        }
        out.finalizeInitialization();
    } catch (Exception e) {
        //logger.warning(Localization.getString("settings.log.error"));
        logger.warning("Can't load settings, using defaults.");
    }

    if (out == null)
        return new Settings();
    return out;
}

From source file:eu.edisonproject.classification.main.BatchMain.java

private static void text2Avro(String inputPath, String outputPath, Properties prop) {
    String stopWordsPath = System.getProperty("stop.words.file");

    if (stopWordsPath == null) {
        stopWordsPath = prop.getProperty("stop.words.file",
                ".." + File.separator + "etc" + File.separator + "stopwords.csv");
    }//  w ww. j a  v  a  2  s  . co  m
    CharArraySet stopWordArraySet = new CharArraySet(ConfigHelper.loadStopWords(stopWordsPath), true);
    StopWord cleanStopWord = new StopWord(stopWordArraySet);
    StanfordLemmatizer cleanLemmatisation = new StanfordLemmatizer();
    File filesInDir = new File(inputPath);
    for (File f : filesInDir.listFiles()) {
        if (f.isFile() && FilenameUtils.getExtension(f.getName()).endsWith("txt")) {
            ReaderFile rf = new ReaderFile(f.getAbsolutePath());
            String contents = rf.readFile();
            cleanStopWord.setDescription(contents);
            String cleanCont = cleanStopWord.execute().toLowerCase();
            cleanLemmatisation.setDescription(cleanCont);
            cleanCont = cleanLemmatisation.execute();
            WriterFile wf = new WriterFile(outputPath + File.separator + f.getName());
            wf.writeFile(cleanCont);
        }
    }
    //        IDataPrepare dp = new DataPrepare(inputPath, outputPath, stopWordsPath);
    //        dp.execute();

}

From source file:com.intel.cryptostream.utils.NativeCodeLoader.java

/**
 * Get the cryptostream version by reading pom.properties embedded in jar.
 * This version data is used as a suffix of a dll file extracted from the
 * jar.//from ww w  . ja  v a 2s .c om
 * 
 * @return the version string
 */
public static String getVersion() {
    URL versionFile = NativeCodeLoader.class
            .getResource("/META-INF/maven/com.intel.cryptostream/cryptostream/pom.properties");
    if (versionFile == null)
        versionFile = NativeCodeLoader.class.getResource("/com/intel/cryptostream/VERSION");

    String version = "unknown";
    try {
        if (versionFile != null) {
            Properties versionData = new Properties();
            versionData.load(versionFile.openStream());
            version = versionData.getProperty("version", version);
            if (version.equals("unknown"))
                version = versionData.getProperty("VERSION", version);
            version = version.trim().replaceAll("[^0-9M\\.]", "");
        }
    } catch (IOException e) {
        System.err.println(e);
    }
    return version;
}

From source file:com.massabot.codesender.utils.SettingsFactory.java

/**
 * Convert legacy property file to JSON, move files from top level setting directory to UGS
 * settings directory.//from   w ww  . ja  va2s.c o  m
 */
private static void migrateOldSettings() {
    File newSettingsDir = getSettingsDirectory();
    File oldSettingDir = newSettingsDir.getParentFile();
    File oldPropertyFile = new File(oldSettingDir, PROPERTIES_FILENAME);
    File oldJsonFile = new File(oldSettingDir, JSON_FILENAME);

    // Convert property file in old location to json file in new location.
    if (oldPropertyFile.exists()) {
        try {
            Settings out = new Settings();
            // logger.log(Level.INFO, "{0}: {1}", new
            // Object[]{Localization.getString("settings.log.location"), settingsFile});
            logger.log(Level.INFO, "Log location: {0}", oldPropertyFile.getAbsolutePath());
            Properties properties = new Properties();
            properties.load(new FileInputStream(oldPropertyFile));
            out.setLastOpenedFilename(properties.getProperty("last.dir", System.getProperty(USER_HOME)));
            out.setPort(properties.getProperty("port", ""));
            out.setPortRate(properties.getProperty("port.rate", "9600"));
            out.setManualModeEnabled(Boolean.valueOf(properties.getProperty("manualMode.enabled", FALSE)));
            out.setManualModeStepSize(Double.valueOf(properties.getProperty("manualMode.stepsize", "1")));
            out.setScrollWindowEnabled(Boolean.valueOf(properties.getProperty("scrollWindow.enabled", "true")));
            out.setVerboseOutputEnabled(
                    Boolean.valueOf(properties.getProperty("verboseOutput.enabled", FALSE)));
            out.setFirmwareVersion(properties.getProperty("firmwareVersion", "GRBL"));
            out.setSingleStepMode(Boolean.valueOf(properties.getProperty("singleStepMode", FALSE)));
            out.setStatusUpdatesEnabled(
                    Boolean.valueOf(properties.getProperty("statusUpdatesEnabled", "true")));
            out.setStatusUpdateRate(Integer.valueOf(properties.getProperty("statusUpdateRate", "200")));
            out.setDisplayStateColor(Boolean.valueOf(properties.getProperty("displayStateColor", "true")));
            out.updateMacro(1, null, null, properties.getProperty("customGcode1", "G0 X0 Y0;"));
            out.updateMacro(2, null, null, properties.getProperty("customGcode2", "G0 G91 X10;G0 G91 Y10;"));
            out.updateMacro(3, null, null, properties.getProperty("customGcode3", ""));
            out.updateMacro(4, null, null, properties.getProperty("customGcode4", ""));
            out.updateMacro(5, null, null, properties.getProperty("customGcode5", ""));
            out.setLanguage(properties.getProperty("language", "en_US"));
            saveSettings(out);

            // Delete the old settings file if it exists.
            oldPropertyFile.delete();
        } catch (IOException ex) {
            Logger.getLogger(SettingsFactory.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    // Move old json file from old location to new location.
    else if (oldJsonFile.exists()) {
        try {
            // If the new file doesn't exist, move the old one.
            if (!getSettingsFile().exists()) {
                FileUtils.moveFile(oldJsonFile, getSettingsFile());
            }
            // Delete the old settings file if it exists.
            oldJsonFile.delete();
        } catch (IOException ex) {
            Logger.getLogger(SettingsFactory.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

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

/**
 * Returns a property value as an integer value, with a default in case the range contract is not respected or
 * in case of null.// w  w w . j a  v  a2 s .co  m
 *
 * @param propertyKey     the key inside the properties entries.
 * @param defaultIntValue the default integer value to use in case it is not present inside the properties entries.
 * @param properties      the properties entries.
 * @param lowerLimit      the lower limit for the integer value against which the comparison is done using
 *                        {@literal >=} sign.
 * @param upperLimit      the upper limit for the integer value against which the comparison is done using &lt;
 *                        sign.
 * @return get the property or default
 */
public static int getIntFromPropertiesWithDefaultAndRange(String propertyKey, int defaultIntValue,
        Properties properties, Integer lowerLimit, Integer upperLimit) {
    validateArguments(propertyKey, properties);
    try {
        int value = parseInt(properties.getProperty(propertyKey, valueOf(defaultIntValue)));
        return ((lowerLimit != null) && (upperLimit != null))
                ? (((value >= lowerLimit) && (value < upperLimit)) ? value : defaultIntValue)
                : value;
    } catch (NumberFormatException nfEx) {
        return defaultIntValue;
    }
}