List of usage examples for java.util Properties propertyNames
public Enumeration<?> propertyNames()
From source file:com.intellij.ide.fileTemplates.FileTemplateUtil.java
public static String[] calculateAttributes(String templateContent, Properties properties, boolean includeDummies) throws ParseException { Set<String> propertiesNames = new HashSet<String>(); for (Enumeration e = properties.propertyNames(); e.hasMoreElements();) { propertiesNames.add((String) e.nextElement()); }// ww w. j a v a2 s .c o m return calculateAttributes(templateContent, propertiesNames, includeDummies); }
From source file:org.freebxml.omar.common.AbstractProperties.java
/** * Replace pre-defined variables in property values with the variable value from the * corresponding property.//from w w w . j a va 2 s . c o m * * @param properties the Properties object to be changed * @param oldKeyPrefix String to be replaced from properties' keys * @param newKeyPrefix replacement String * */ protected static void substituteVariables(Properties properties, String oldKeySubstring, String newKeySubstring) { //Iterate and replace the variable int oldKeySubstringSize = oldKeySubstring.length(); for (Enumeration keys = properties.propertyNames(); keys.hasMoreElements();) { String key = (String) keys.nextElement(); String value = properties.getProperty(key); //System.err.println("key = " + key + " value = " + value); if (key.startsWith("omar.")) { int index = -1; boolean modified = false; while (true) { index = value.indexOf(oldKeySubstring); if (index == -1) { break; } value = value.substring(0, index) + newKeySubstring + value.substring(index + oldKeySubstringSize); modified = true; } if (modified) { properties.put(key, value); } } } }
From source file:org.apache.directory.fortress.core.rest.RestUtils.java
/** * * @param properties//from ww w . j a v a 2s . com * @return Prop contains name value pairs. */ public static Props getProps(Properties properties) { Props props = null; if (properties != null) { props = new ObjectFactory().createProps(); for (Enumeration<?> e = properties.propertyNames(); e.hasMoreElements();) { String key = (String) e.nextElement(); String val = properties.getProperty(key); Props.Entry entry = new Props.Entry(); entry.setKey(key); entry.setValue(val); props.getEntry().add(entry); } } return props; }
From source file:com.intellij.ide.fileTemplates.FileTemplateUtil.java
public static String mergeTemplate(Properties attributes, String content, boolean useSystemLineSeparators) throws IOException { VelocityContext context = new VelocityContext(); Enumeration<?> names = attributes.propertyNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); context.put(name, attributes.getProperty(name)); }//from w w w. ja v a 2 s .c o m return mergeTemplate(content, context, useSystemLineSeparators); }
From source file:org.apache.wiki.util.PropertyReader.java
/** * You define a property variable by using the prefix "var.x" as a * property. In property values you can then use the "$x" identifier * to use this variable./*w w w .java2 s .c om*/ * * For example you could declare a base directory for all your files * like this and use it in all your other property definitions with * a "$basedir". Note that it does not matter if you define the * variable before its usage. * <pre> * var.basedir = /p/mywiki; * jspwiki.fileSystemProvider.pageDir = $basedir/www/ * jspwiki.basicAttachmentProvider.storageDir = $basedir/www/ * jspwiki.workDir = $basedir/wrk/ * </pre> * * @param properties - properties to expand; */ public static void expandVars(Properties properties) { //get variable name/values from properties... Map<String, String> vars = new HashMap<String, String>(); Enumeration<?> propertyList = properties.propertyNames(); while (propertyList.hasMoreElements()) { String propertyName = (String) propertyList.nextElement(); String propertyValue = properties.getProperty(propertyName); if (propertyName.startsWith(PARAM_VAR_DECLARATION)) { String varName = propertyName.substring(4, propertyName.length()).trim(); String varValue = propertyValue.trim(); vars.put(varName, varValue); } } //now, substitute $ values in property values with vars... propertyList = properties.propertyNames(); while (propertyList.hasMoreElements()) { String propertyName = (String) propertyList.nextElement(); String propertyValue = properties.getProperty(propertyName); //skip var properties itself... if (propertyName.startsWith(PARAM_VAR_DECLARATION)) { continue; } Iterator<Map.Entry<String, String>> iter = vars.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<String, String> entry = iter.next(); String varName = entry.getKey(); String varValue = entry.getValue(); //replace old property value, using the same variabe. If we don't overwrite //the same one the next loop works with the original one again and //multiple var expansion won't work... propertyValue = TextUtil.replaceString(propertyValue, PARAM_VAR_IDENTIFIER + varName, varValue); //add the new PropertyValue to the properties properties.put(propertyName, propertyValue); } } }
From source file:org.mili.core.templating.TemplateStore.java
/** * Replaces a template with given component sheets. * * @param template The template./* ww w . ja va 2 s . co m*/ * @param defaultComponentSheet The default component Sheet. * @param givenComponentSheet Component sheet. * @return Replaced template. */ public static String replaceWithComponentSheets(String template, Properties defaultComponentSheet, Properties givenComponentSheet) { String s = template; try { for (Enumeration<?> e = defaultComponentSheet.propertyNames(); e.hasMoreElements();) { String name = e.nextElement().toString(); log.debug("check: " + name); String prop = givenComponentSheet.getProperty(name, defaultComponentSheet.getProperty(name)); log.debug("prop: " + prop); if (prop != null && prop.length() > 0) { s = s.replace("${" + name + "}", prop); } else { log.debug("Component sheet style[" + name + "] not found."); } } } catch (Exception e) { e.printStackTrace(); } return s; }
From source file:dk.hippogrif.prettyxml.PrettyPrint.java
/** * Checks known properties -/*from w ww . jav a2 s .c o m*/ * present boolean properties are set to either "true" or "false", * indent=0 is removed, * string properties are trimmed and empty properties removed - * however, TEXT_MODE is checked when format is initialized * and ENCODING when used. * * @param prop holds the properties * @param extended to include in/out properties * @throws Exception if property error */ public static void checkProperties(Properties prop, boolean extended) throws Exception { for (Enumeration elements = prop.propertyNames(); elements.hasMoreElements();) { String s = (String) elements.nextElement(); if (!keys.contains(s)) { prop.remove(s); } } checkBoolean(EXPAND_EMPTY_ELEMENTS, prop); checkBoolean(OMIT_DECLARATION, prop); checkBoolean(OMIT_ENCODING, prop); checkBoolean(INDENT_ATTRIBUTES, prop); checkBoolean(SORT_ATTRIBUTES, prop); if (prop.containsKey(INDENT)) { try { int i = Integer.parseInt(prop.getProperty(INDENT)); if (i == 0) { prop.remove(INDENT); } else if (i < 1 || i > 99) { throw new Exception(INDENT + " must be an integer >= 0 and < 100"); } } catch (NumberFormatException e) { throw new Exception(INDENT + " must be an integer >= 0 and < 100"); } } if (prop.containsKey(LINE_SEPARATOR)) { String s = prop.getProperty(LINE_SEPARATOR); boolean err = true; for (int i = 0; i < LINE_SEPARATORS.length; i++) { if (LINE_SEPARATORS[i].equals(s)) { err = false; break; } } if (err) { throw new Exception(LINE_SEPARATOR + " must be \\r, \\n or \\r\\n"); } } checkString(TRANSFORM, prop); if (extended) { checkString(INPUT, prop); checkString(URL, prop); checkString(OUTPUT, prop); if (prop.containsKey(INPUT) && prop.containsKey(URL)) { throw new Exception("do not use " + INPUT + " and " + URL + " at the same time"); } } else { prop.remove(INPUT); prop.remove(URL); prop.remove(OUTPUT); } }
From source file:com.sds.acube.ndisc.mts.xserver.util.XNDiscConfig.java
/** * // w w w . ja v a 2 s. com */ private static void init() { Properties props = null; String[] categoryNames = configuration.getCategoryNames(); for (String catgnm : categoryNames) { props = configuration.getProperties(catgnm); Enumeration<?> enumeration = props.propertyNames(); while (enumeration.hasMoreElements()) { String key = (String) enumeration.nextElement(); String value = props.getProperty(key); config.put(key, replaceValueByVariables(value)); } } }
From source file:it.cnr.icar.eric.common.AbstractProperties.java
/** * Replace pre-defined variables in property values with the variable value from the * corresponding property./*from w ww.ja v a 2s . c om*/ * * @param properties the Properties object to be changed * @param oldKeyPrefix String to be replaced from properties' keys * @param newKeyPrefix replacement String * */ protected static void substituteVariables(Properties properties, String oldKeySubstring, String newKeySubstring) { //Iterate and replace the variable int oldKeySubstringSize = oldKeySubstring.length(); for (Enumeration<?> keys = properties.propertyNames(); keys.hasMoreElements();) { String key = (String) keys.nextElement(); String value = properties.getProperty(key); //System.err.println("key = " + key + " value = " + value); if (key.startsWith("eric.")) { int index = -1; boolean modified = false; while (true) { index = value.indexOf(oldKeySubstring); if (index == -1) { break; } value = value.substring(0, index) + newKeySubstring + value.substring(index + oldKeySubstringSize); modified = true; } if (modified) { properties.put(key, value); } } } }
From source file:net.sf.jasperreports.engine.JRPropertiesMap.java
/** * Loads a properties file from a location. * /*from w ww. java 2s .c o m*/ * @param location the properties file URL * @return the properties file loaded as a in-memory properties map */ public static JRPropertiesMap loadProperties(URL location) { boolean close = true; InputStream stream = null; try { stream = location.openStream(); Properties props = new Properties(); props.load(stream); close = false; stream.close(); JRPropertiesMap properties = new JRPropertiesMap(); for (Enumeration<?> names = props.propertyNames(); names.hasMoreElements();) { String name = (String) names.nextElement(); String value = props.getProperty(name); properties.setProperty(name, value); } return properties; } catch (IOException e) { throw new JRRuntimeException(e); } finally { if (close && stream != null) { try { stream.close(); } catch (IOException e) { if (log.isWarnEnabled()) { log.warn("Error closing stream for " + location, e); } } } } }