List of usage examples for java.util Properties keySet
@Override
public Set<Object> keySet()
From source file:com.github.dakusui.symfonion.CLI.java
private Map<String, Pattern> initializeMidiPorts(CommandLine cmd, String optionName) throws CLIException { Properties props = cmd.getOptionProperties(optionName); Map<String, Pattern> ret = new HashMap<String, Pattern>(); for (Object key : props.keySet()) { String portname = key.toString(); String p = props.getProperty(portname); try {//from www . j av a 2 s . c o m Pattern portpattern = Pattern.compile(p); ret.put(portname, portpattern); } catch (PatternSyntaxException e) { String msg = String.format("Regular expression '%' for '%s' isn't a valid regular expression.", portname, p); throw new CLIException(composeErrMsg(msg, optionName, null), e); } } return ret; }
From source file:com.ms.commons.test.classloader.util.SimpleAntxLoader.java
protected void setProperties(Properties dest, Properties src) { if (src == null) { return;/*from w w w . j av a2 s . com*/ } for (Object key : src.keySet()) { if (String.class == key.getClass()) { String strKey = (String) key; dest.setProperty(strKey, src.getProperty(strKey)); } } }
From source file:de.flashpixx.rrd_antlr4.TestCLanguageLabels.java
/** * test-case all resource strings/*www .j ava 2 s. c om*/ * * @throws IOException throws on io errors */ @Test public void testResourceString() throws IOException { assumeTrue("no languages are defined for checking", !LANGUAGEPROPERY.isEmpty()); final Set<String> l_ignoredlabel = new HashSet<>(); // --- parse source and get label definition final Set<String> l_label = Collections.unmodifiableSet(Files.walk(Paths.get(SEARCHPATH)) .filter(Files::isRegularFile).filter(i -> i.toString().endsWith(".java")).flatMap(i -> { try { final CJavaVistor l_parser = new CJavaVistor(); l_parser.visit(JavaParser.parse(new FileInputStream(i.toFile())), null); return l_parser.labels().stream(); } catch (final IOException l_excpetion) { assertTrue(MessageFormat.format("io error on file [{0}]: {1}", i, l_excpetion.getMessage()), false); return Stream.<String>empty(); } catch (final ParseException l_exception) { // add label build by class path to the ignore list l_ignoredlabel.add(i.toAbsolutePath().toString() // remove path to class directory .replace(FileSystems.getDefault().provider().getPath(SEARCHPATH).toAbsolutePath() .toString(), "") // string starts with path separator .substring(1) // remove file extension .replace(".java", "") // replace separators with dots .replace("/", CLASSSEPARATOR) // convert to lower-case .toLowerCase() // remove package-root name .replace(CCommon.PACKAGEROOT + CLASSSEPARATOR, "")); System.err.println(MessageFormat.format("parsing error on file [{0}]:\n{1}", i, l_exception.getMessage())); return Stream.<String>empty(); } }).collect(Collectors.toSet())); // --- check of any label is found assertFalse("translation labels are empty, check naming of translation method", l_label.isEmpty()); // --- check label towards the property definition if (l_ignoredlabel.size() > 0) System.err.println(MessageFormat.format( "labels that starts with {0} are ignored, because parsing errors are occurred", l_ignoredlabel)); LANGUAGEPROPERY.entrySet().forEach(i -> { try { final Properties l_property = new Properties(); l_property.load(new FileInputStream(new File(i.getValue()))); final Set<String> l_parseditems = new HashSet<>(l_label); final Set<String> l_propertyitems = l_property.keySet().parallelStream().map(Object::toString) .collect(Collectors.toSet()); // --- check if all property items are within the parsed labels l_parseditems.removeAll(l_propertyitems); assertTrue(MessageFormat.format( "the following {1,choice,1#key|1<keys} in language [{0}] {1,choice,1#is|1<are} not existing within the language file:\n{2}", i.getKey(), l_parseditems.size(), StringUtils.join(l_parseditems, ", ")), l_parseditems.isEmpty()); // --- check if all parsed labels within the property item and remove ignored labels l_propertyitems.removeAll(l_label); final Set<String> l_ignoredpropertyitems = l_propertyitems.parallelStream() .filter(j -> l_ignoredlabel.parallelStream().map(j::startsWith).allMatch(l -> false)) .collect(Collectors.toSet()); assertTrue(MessageFormat.format( "the following {1,choice,1#key|1<keys} in language [{0}] {1,choice,1#is|1<are} not existing within the source code:\n{2}", i.getKey(), l_ignoredpropertyitems.size(), StringUtils.join(l_ignoredpropertyitems, ", ")), l_ignoredpropertyitems.isEmpty()); } catch (final IOException l_exception) { assertTrue(MessageFormat.format("io exception: {0}", l_exception.getMessage()), false); } }); }
From source file:org.geoserver.wps.gs.GeorectifyConfiguration.java
/** * Load the configured parameters through the properties file. TODO: Move to XML instead of * properties file/*from w w w . j a v a 2s .co m*/ * * @throws IOException */ private void loadConfig() throws IOException { final boolean hasPropertiesFile = configFile != null && configFile.getType() == Type.RESOURCE; if (hasPropertiesFile) { Properties props = new Properties(); InputStream fis = null; try { fis = configFile.in(); props.load(fis); Iterator<Object> keys = props.keySet().iterator(); envVariables = Maps.newHashMap(); while (keys.hasNext()) { String key = (String) keys.next(); if (key.equalsIgnoreCase(GRKeys.GDAL_CACHEMAX)) { // Setting GDAL_CACHE_MAX Environment variable if available String cacheMax = null; try { cacheMax = (String) props.get(GRKeys.GDAL_CACHEMAX); if (cacheMax != null) { int gdalCacheMaxMemory = Integer.parseInt(cacheMax); // Only for validation envVariables.put(GRKeys.GDAL_CACHEMAX, cacheMax); } } catch (NumberFormatException nfe) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.log(Level.WARNING, "Unable to parse the specified property as a number: " + cacheMax, nfe); } } } else if (key.equalsIgnoreCase(GRKeys.GDAL_DATA) || key.equalsIgnoreCase(GRKeys.GDAL_LOGGING_DIR) || key.equalsIgnoreCase(GRKeys.TEMP_DIR)) { // Parsing specified folder path String path = (String) props.get(key); if (path != null) { final File directory = new File(path); if (directory.exists() && directory.isDirectory() && ((key.equalsIgnoreCase(GRKeys.GDAL_DATA) && directory.canRead()) || directory.canWrite())) { envVariables.put(key, path); } else { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.log(Level.WARNING, "The specified folder for " + key + " variable isn't valid, " + "or it doesn't exist or it isn't a readable directory or it is a " + "destination folder which can't be written: " + path); } } } } else if (key.equalsIgnoreCase(GRKeys.EXECUTION_TIMEOUT)) { // Parsing execution timeout String timeout = null; try { timeout = (String) props.get(GRKeys.EXECUTION_TIMEOUT); if (timeout != null) { executionTimeout = Long.parseLong(timeout); // Only for validation } } catch (NumberFormatException nfe) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.log(Level.WARNING, "Unable to parse the specified property as a number: " + timeout, nfe); } } } else if (key.equalsIgnoreCase(GRKeys.GDAL_WARP_PARAMS) || key.equalsIgnoreCase(GRKeys.GDAL_TRANSLATE_PARAMS)) { // Parsing gdal operations custom option parameters String param = (String) props.get(key); if (param != null) { if (key.equalsIgnoreCase(GRKeys.GDAL_WARP_PARAMS)) { gdalWarpingParameters = param.trim(); } else { gdalTranslateParameters = param.trim(); } } } else if (key.endsWith("PATH")) { // Dealing with properties like LD_LIBRARY_PATH, PATH, ... String param = (String) props.get(key); if (param != null) { envVariables.put(key, param); } } } } catch (FileNotFoundException e) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.log(Level.WARNING, "Unable to parse the config file: " + configFile.path(), e); } } catch (IOException e) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.log(Level.WARNING, "Unable to parse the config file: " + configFile.path(), e); } } finally { if (fis != null) { try { fis.close(); } catch (Throwable t) { // Does nothing } } } } }
From source file:eu.annocultor.context.EnvironmentImpl.java
private void loadParametersFromFile() throws Exception { Properties props = new Properties(); File propertiesFile = new File(getCollectionDir(), "annocultor.properties"); if (propertiesFile.exists()) { // load properties FileInputStream inStream = new FileInputStream(propertiesFile); props.load(inStream);//from w ww.j a va2s . c o m inStream.close(); for (Object key : props.keySet()) { PARAMETERS parameterName = PARAMETERS.valueOf(key.toString()); if (parameterName == null) throw new Exception("Unknown parameter " + key); String parameterValue = props.getProperty(key.toString()); setParameter(parameterName, parameterValue); } setParameter(PARAMETERS.ANNOCULTOR_LOCAL_PROFILE_FILE, propertiesFile.getCanonicalPath()); setParameter(PARAMETERS.ANNOCULTOR_HOME_SOURCE, (getParameter(PARAMETERS.ANNOCULTOR_HOME) == null) ? "ERROR! not set up" : "file annocultor.properties"); } ; }
From source file:com.smartitengineering.loadtest.engine.impl.LoadTestEngineImpl.java
private void createTestCaseResult(UnitTestInstance instance) { TestCaseResult caseResult = new TestCaseResult(); caseResult.setName(instance.getName()); caseResult.setInstanceFactoryClassName(instance.getInstanceFactoryClassName()); final Properties testProperties = instance.getProperties(); Set<TestProperty> testPropertySet = new HashSet<TestProperty>(testProperties.size()); final Iterator<Object> keySetIterator = testProperties.keySet().iterator(); while (keySetIterator.hasNext()) { TestProperty property = new TestProperty(); final String key = keySetIterator.next().toString(); property.setKey(key);/* w w w .jav a 2s. c om*/ property.setValue(testProperties.getProperty(key)); testPropertySet.add(property); } caseResult.setTestProperties(testPropertySet); caseResult.setTestCaseInstanceResults(new HashSet<TestCaseInstanceResult>()); UnitTestInstanceRecord record = new UnitTestInstanceRecord(caseResult); instanceRecords.put(instance, record); }
From source file:com.izforge.izpack.event.AntAction.java
private void addProperties(Project proj, Properties props) { if (proj == null) { return;//from ww w. ja v a2s . c o m } if (props.size() > 0) { for (Object o : props.keySet()) { String key = (String) o; proj.setProperty(key, props.getProperty(key)); } } }
From source file:org.alfresco.ibatis.HierarchicalXMLConfigBuilder.java
private void settingsElement(XNode context) throws Exception { if (context != null) { Properties props = context.getChildrenAsProperties(); // Check that all settings are known to the configuration class MetaClass metaConfig = MetaClass.forClass(Configuration.class); for (Object key : props.keySet()) { if (!metaConfig.hasSetter(String.valueOf(key))) { throw new BuilderException("The setting " + key + " is not known. Make sure you spelled it correctly (case sensitive)."); }//from w w w . j a v a 2s. c o m } configuration.setAutoMappingBehavior( AutoMappingBehavior.valueOf(props.getProperty("autoMappingBehavior", "PARTIAL"))); configuration.setCacheEnabled(booleanValueOf(props.getProperty("cacheEnabled"), true)); configuration.setProxyFactory((ProxyFactory) createInstance(props.getProperty("proxyFactory"))); configuration.setLazyLoadingEnabled(booleanValueOf(props.getProperty("lazyLoadingEnabled"), false)); configuration .setAggressiveLazyLoading(booleanValueOf(props.getProperty("aggressiveLazyLoading"), true)); configuration.setMultipleResultSetsEnabled( booleanValueOf(props.getProperty("multipleResultSetsEnabled"), true)); configuration.setUseColumnLabel(booleanValueOf(props.getProperty("useColumnLabel"), true)); configuration.setUseGeneratedKeys(booleanValueOf(props.getProperty("useGeneratedKeys"), false)); configuration.setDefaultExecutorType( ExecutorType.valueOf(props.getProperty("defaultExecutorType", "SIMPLE"))); configuration .setDefaultStatementTimeout(integerValueOf(props.getProperty("defaultStatementTimeout"), null)); configuration.setMapUnderscoreToCamelCase( booleanValueOf(props.getProperty("mapUnderscoreToCamelCase"), false)); configuration.setSafeRowBoundsEnabled(booleanValueOf(props.getProperty("safeRowBoundsEnabled"), false)); configuration .setLocalCacheScope(LocalCacheScope.valueOf(props.getProperty("localCacheScope", "SESSION"))); configuration.setJdbcTypeForNull(JdbcType.valueOf(props.getProperty("jdbcTypeForNull", "OTHER"))); configuration.setLazyLoadTriggerMethods(stringSetValueOf(props.getProperty("lazyLoadTriggerMethods"), "equals,clone,hashCode,toString")); configuration.setSafeResultHandlerEnabled( booleanValueOf(props.getProperty("safeResultHandlerEnabled"), true)); configuration.setDefaultScriptingLanguage(resolveClass(props.getProperty("defaultScriptingLanguage"))); configuration.setCallSettersOnNulls(booleanValueOf(props.getProperty("callSettersOnNulls"), false)); configuration.setLogPrefix(props.getProperty("logPrefix")); configuration.setLogImpl(resolveClass(props.getProperty("logImpl"))); } }
From source file:de.suse.swamp.webswamp.SwampUIManager.java
/** * Load the specified skin on top of the "common" skin. *///from www. j a v a 2 s. co m private void loadSkin() { resourceProperties = new Properties(); try { FileInputStream is = new FileInputStream(skinsDirectory + "/common/" + RESOURCES_PROPS_FILE); resourceProperties.load(is); for (Iterator it = resourceProperties.keySet().iterator(); it.hasNext();) { String key = (String) it.next(); resourceProperties.put(key, "common/images/" + resourceProperties.get(key)); } } catch (Exception e) { Logger.ERROR("Cannot load resources for skin: common! " + e.getMessage()); } try { FileInputStream is = new FileInputStream(skinsDirectory + "/" + getSkin() + "/" + RESOURCES_PROPS_FILE); Properties resourceProperties2 = new Properties(); resourceProperties2.load(is); for (Iterator it = resourceProperties2.keySet().iterator(); it.hasNext();) { String key = (String) it.next(); resourceProperties2.put(key, getSkin() + "/images/" + resourceProperties2.get(key)); } resourceProperties.putAll(resourceProperties2); } catch (Exception e) { Logger.ERROR("Cannot load resources for skin: " + super.getSkin()); } skinProperties = new Properties(); try { FileInputStream is = new FileInputStream(skinsDirectory + "/common/" + SKIN_PROPS_FILE); skinProperties.load(is); } catch (Exception e) { Logger.ERROR("Cannot load common skin props: " + super.getSkin()); } try { FileInputStream is = new FileInputStream(skinsDirectory + "/" + getSkin() + "/" + SKIN_PROPS_FILE); Properties skinProperties2 = new Properties(); skinProperties2.load(is); skinProperties.putAll(skinProperties2); } catch (Exception e) { Logger.ERROR("Cannot load skin props for: " + super.getSkin()); } }
From source file:org.apache.roller.weblogger.business.plugins.entry.AcronymsPlugin.java
public String render(WeblogEntry entry, String str) { String text = str;/*from ww w . j a va 2 s . c o m*/ if (mLogger.isDebugEnabled()) { mLogger.debug("render(entry = " + entry.getId() + ")"); } /* * Get acronyms Properties. */ Properties acronyms = loadAcronyms(entry.getWebsite()); mLogger.debug("acronyms.size()=" + acronyms.size()); if (acronyms.size() == 0) { return text; } /* * Compile the user's acronyms into RegEx patterns. */ Pattern[] acronymPatterns = new Pattern[acronyms.size()]; String[] acronymTags = new String[acronyms.size()]; int count = 0; for (Iterator iter = acronyms.keySet().iterator(); iter.hasNext();) { String acronym = (String) iter.next(); acronymPatterns[count] = Pattern.compile("\\b" + acronym + "\\b"); mLogger.debug("match '" + acronym + "'"); acronymTags[count] = "<acronym title=\"" + acronyms.getProperty(acronym) + "\">" + acronym + "</acronym>"; count++; } // if there are none, no work to do if (acronymPatterns == null || acronymPatterns.length == 0) { return text; } return matchAcronyms(text, acronymPatterns, acronymTags); }