List of usage examples for java.util Properties propertyNames
public Enumeration<?> propertyNames()
From source file:Main.java
private void addProperties(Properties props) { Enumeration names = props.propertyNames(); while (names.hasMoreElements()) { model.add(names.nextElement());/*from w ww .j av a 2 s . c o m*/ } }
From source file:Main.java
private void addProperties(Properties props) { // Load//from w ww .j a v a2 s. c o m Enumeration e = props.propertyNames(); while (e.hasMoreElements()) { model.add(e.nextElement()); } }
From source file:ORG.oclc.os.SRW.Lucene.SRWLuceneDatabase.java
public static String makeIndexInfo(Properties props, IndexSearcher searcher, HashMap<String, String> indexMappings) { Collection c = searcher.getIndexReader().getFieldNames(IndexReader.FieldOption.INDEXED); HashMap<String, String> sets = new HashMap<String, String>(); int indexNum = 0; String index, indexSet, luceneIndex, prop; StringBuilder sb = new StringBuilder(" <indexInfo>\n"); StringTokenizer st;/* w ww. ja v a2 s .c o m*/ Iterator iter = c.iterator(); while (iter.hasNext()) { index = (String) iter.next(); props.put("qualifier.local." + index, index); } makeUnqualifiedIndexes(props); Enumeration enumer = props.propertyNames(); while (enumer.hasMoreElements()) { prop = (String) enumer.nextElement(); if (prop.startsWith("qualifier.")) { st = new StringTokenizer(prop.substring(10)); index = st.nextToken(); st = new StringTokenizer(index, "."); if (st.countTokens() == 1) { indexSet = "local"; index = prop.substring(10); } else { indexSet = st.nextToken(); index = prop.substring(10 + indexSet.length() + 1); } if (log.isDebugEnabled()) log.debug("indexSet=" + indexSet + ", index=" + index); if (sets.get(indexSet) == null) { // new set sb.append(" <set identifier=\"").append(props.getProperty("indexSet." + indexSet)) .append("\" name=\"").append(indexSet).append("\"/>\n"); sets.put(indexSet, indexSet); } sb.append(" <index>\n").append(" <title>").append(indexSet).append('.') .append(index).append("</title>\n").append(" <map>\n") .append(" <name set=\"").append(indexSet).append("\">").append(index) .append("</name>\n").append(" </map>\n").append(" </index>\n"); if (indexMappings != null) { // now for a bit of trickery for the CQL parser // the line we just read isn't in the format the parser // expect. we just read: // qualifier.<indexSet>.indexName=luceneIndexName // the parser is expecting: // qualifier.<indexSet>.indexName=1=<z39.50UseAttribute> // it doesn't really care what Use attribute we provide, // so we'll make up Use attribute numbers to correspond // with the lucene indexes. luceneIndex = props.getProperty(prop); indexMappings.put(indexSet + "." + index, luceneIndex); if (log.isDebugEnabled()) log.debug("mapping " + indexSet + "." + index + " to " + luceneIndex); props.put(prop, "1=" + (++indexNum)); } } else if (prop.startsWith("hiddenQualifier.")) { st = new StringTokenizer(prop.substring(16)); index = st.nextToken(); if (indexMappings != null) { // now for a bit of trickery for the CQL parser // the line we just read isn't in the format the parser // expect. we just read: // qualifier.<indexSet>.indexName=luceneIndexName // the parser is expecting: // qualifier.<indexSet>.indexName=1=<z39.50UseAttribute> // it doesn't really care what Use attribute we provide, // so we'll make up Use attribute numbers to correspond // with the lucene indexes. luceneIndex = props.getProperty(prop); indexMappings.put(index, luceneIndex); if (log.isDebugEnabled()) log.debug("mapping " + index + " to " + luceneIndex); props.put(prop, "1=" + (++indexNum)); } } } sb.append(" </indexInfo>\n"); return sb.toString(); }
From source file:org.apache.kylin.common.KylinConfig.java
public static void writeOverrideProperties(Properties properties) throws IOException { File propFile = getKylinPropertiesFile(); File overrideFile = new File(propFile.getParentFile(), propFile.getName() + ".override"); overrideFile.createNewFile();//from w ww. j a v a2 s . c o m FileInputStream fis2 = null; Properties override = new Properties(); try { fis2 = new FileInputStream(overrideFile); override.load(fis2); for (Map.Entry<Object, Object> entries : properties.entrySet()) { override.setProperty(entries.getKey().toString(), entries.getValue().toString()); } } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(fis2); } PrintWriter pw = null; try { pw = new PrintWriter(overrideFile); Enumeration<?> e = override.propertyNames(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); pw.println(key + "=" + override.getProperty(key)); } pw.close(); } finally { IOUtils.closeQuietly(pw); } }
From source file:org.openlmis.notification.i18n.ExposedMessageSourceImpl.java
/** * Get all messages for given locale.//from ww w .j a va 2s . c o m * * @param locale Locale. * @return Map with messages. */ public Map<String, String> getAllMessages(Locale locale) { Properties props = getAllProperties(locale); Enumeration<String> keys = (Enumeration<String>) props.propertyNames(); Map<String, String> asMap = new HashMap<>(); while (keys.hasMoreElements()) { String key = keys.nextElement(); asMap.put(key, props.getProperty(key)); } return asMap; }
From source file:org.openlmis.fulfillment.i18n.ExposedMessageSourceImpl.java
/** * Get all messages for given locale./*w w w. j ava 2s.c o m*/ * * @param locale Locale. * @return Map with messages. */ @Override public Map<String, String> getAllMessages(Locale locale) { Properties props = getAllProperties(locale); Enumeration<String> keys = (Enumeration<String>) props.propertyNames(); Map<String, String> asMap = new HashMap<>(); while (keys.hasMoreElements()) { String key = keys.nextElement(); asMap.put(key, props.getProperty(key)); } return asMap; }
From source file:com.cloud.test.regression.ApiCommand.java
public static boolean verifyEvents(String fileName, String level, String host, String account) { boolean result = false; HashMap<String, Integer> expectedEvents = new HashMap<String, Integer>(); HashMap<String, Integer> actualEvents = new HashMap<String, Integer>(); String key = ""; File file = new File(fileName); if (file.exists()) { Properties pro = new Properties(); try {/*w w w . ja v a 2s. c om*/ // get expected events FileInputStream in = new FileInputStream(file); pro.load(in); Enumeration<?> en = pro.propertyNames(); while (en.hasMoreElements()) { key = (String) en.nextElement(); expectedEvents.put(key, Integer.parseInt(pro.getProperty(key))); } // get actual events String url = host + "/?command=listEvents&account=" + account + "&level=" + level + "&domainid=1&pagesize=100"; s_logger.info("Getting events with the following url " + url); HttpClient client = new HttpClient(); HttpMethod method = new GetMethod(url); int responseCode = client.executeMethod(method); if (responseCode == 200) { InputStream is = method.getResponseBodyAsStream(); ArrayList<HashMap<String, String>> eventValues = UtilsForTest.parseMulXML(is, new String[] { "event" }); for (int i = 0; i < eventValues.size(); i++) { HashMap<String, String> element = eventValues.get(i); if (element.get("level").equals(level)) { if (actualEvents.containsKey(element.get("type")) == true) { actualEvents.put(element.get("type"), actualEvents.get(element.get("type")) + 1); } else { actualEvents.put(element.get("type"), 1); } } } } method.releaseConnection(); // compare actual events with expected events // compare expected result and actual result Iterator<?> iterator = expectedEvents.keySet().iterator(); Integer expected; Integer actual; int fail = 0; while (iterator.hasNext()) { expected = null; actual = null; String type = iterator.next().toString(); expected = expectedEvents.get(type); actual = actualEvents.get(type); if (actual == null) { s_logger.error("Event of type " + type + " and level " + level + " is missing in the listEvents response. Expected number of these events is " + expected); fail++; } else if (expected.compareTo(actual) != 0) { fail++; s_logger.info("Amount of events of " + type + " type and level " + level + " is incorrect. Expected number of these events is " + expected + ", actual number is " + actual); } } if (fail == 0) { result = true; } } catch (Exception ex) { s_logger.error(ex); } } else { s_logger.info("File " + fileName + " not found"); } return result; }
From source file:ParseNonXML.java
public void parse(Properties props) throws SAXException { handler = getContentHandler();/*w w w . ja v a2s . c o m*/ handler.startDocument(); Enumeration e = props.propertyNames(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); String val = (String) props.getProperty(key); handler.startElement("", key, key, new AttributesImpl()); char[] chars = getChars(val); handler.characters(chars, 0, chars.length); handler.endElement("", key, key); } handler.endDocument(); }
From source file:org.silverpeas.core.test.util.lang.TestSystemWrapper.java
@Override public void setProperties(final Properties props) { Enumeration<?> propertyNames = props.propertyNames(); while (propertyNames.hasMoreElements()) { String key = (String) propertyNames.nextElement(); System.setProperty(key, props.getProperty(key)); }/*from ww w. ja v a 2 s . c o m*/ }
From source file:org.openvpms.web.component.im.archetype.PropertiesReader.java
/** * Reads the configuration at the specified URL. * * @param url the URL to read/* w w w.j a v a 2 s . c om*/ */ protected void read(URL url) { try { Properties properties = new Properties(); properties.load(url.openStream()); Enumeration keys = properties.propertyNames(); String path = url.toString(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); String value = properties.getProperty(key).trim(); // trim required as Properties doesn't seem to remove // trailing whitespace parse(key, value, path); } } catch (IOException exception) { log.error(exception, exception); } }