List of usage examples for java.util Properties propertyNames
public Enumeration<?> propertyNames()
From source file:com.pearson.dashboard.util.Util.java
public static Configuration readConfigFile() throws FileNotFoundException { Properties prop = new Properties(); File file = new File(System.getProperty("user.home"), "config/config.properties"); InputStream stream = new FileInputStream(file); try {// w w w. jav a 2 s.c o m Configuration configuration = new Configuration(); prop.load(stream); configuration.setRallyURL(prop.getProperty("rallyURL")); configuration.setRallyUser(prop.getProperty("rallyUser")); configuration.setRallyPassword(prop.getProperty("rallyPassword")); file = new File(System.getProperty("user.home"), "config/tab.properties"); InputStream streamProject = new FileInputStream(file); Properties tabProperties = new Properties(); tabProperties.load(streamProject); List<Tab> tabs = new ArrayList<Tab>(); for (Enumeration<String> en = (Enumeration<String>) tabProperties.propertyNames(); en .hasMoreElements();) { String key = (String) en.nextElement(); String params = tabProperties.getProperty(key); if (null != params) { String param[] = params.split(":"); Tab tab = new Tab(); tab.setTabIndex(Integer.parseInt(param[0])); tab.setTabDisplayName(param[1]); tab.setTabUniqueId(param[2]); if (param[3].equals("null")) { tab.setRelease(null); } else { tab.setRelease(param[3]); } if (null != param[4] && !"null".equals(param[4])) { tab.setCutoffDate(param[4]); } if (null != param[5] && "true".equals(param[5])) { tab.setRegressionData(true); } else { tab.setRegressionData(false); } tab.setTabType("Parent"); tab.setInformation(param[6]); if (param[7].equals("null")) { tab.setTag(null); } else { tab.setTag(param[7]); } if (null == param[8] || param[8].equals("null") || param[8].equals("false")) { tab.setUseRegressionInputFile("false"); } else { tab.setUseRegressionInputFile("true"); } tab.setSubTabs(getSubTabs(param[2])); tabs.add(tab); } } Collections.sort(tabs); configuration.setTabs(tabs); return configuration; } catch (IOException e) { return null; } }
From source file:org.sakaiproject.util.BaseResourceProperties.java
/** * Add all the properties from the Properties object. * //from w ww. ja v a 2 s .c om * @param props * The Properties to add. */ public void addAll(Properties props) { // if there's a list, it must be deep copied for (Enumeration e = props.propertyNames(); e.hasMoreElements();) { String name = (String) e.nextElement(); Object value = props.get(name); if (value instanceof List) { List list = new Vector(); list.addAll((List) value); m_props.put(name, list); } else { m_props.put(name, value); } } }
From source file:com.soulgalore.velocity.MergeXMLWithVelocity.java
MergeXMLWithVelocity(Properties properties) { ve = new VelocityEngine(properties); ve.setProperty("resource.loader", "plainfile"); ve.setProperty("plainfile.resource.loader.instance", new PlainFileResourceLoader()); ve.init();//from ww w. ja v a 2s .c o m Map<String, String> keyAndClasses = getClasses(properties); for (Entry<String, String> value : keyAndClasses.entrySet()) { try { Class clazz = Class.forName(value.getValue()); context.put(value.getKey(), clazz.newInstance()); } catch (Exception e) { System.err.println("Couldn't instantiate class:" + value.getValue() + " with key:" + value.getKey() + " and put it in Velocity context:" + e.toString()); } } final Enumeration<?> e = properties.propertyNames(); while (e.hasMoreElements()) { final String key = (String) e.nextElement(); context.put(key, properties.getProperty(key)); } // Add all system properties starting with specific key Enumeration<Object> keys = System.getProperties().keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); if (key.startsWith(SYSTEM_PROPERTY_START)) { context.put(key.replace(SYSTEM_PROPERTY_START, ""), System.getProperties().get(key)); } } }
From source file:org.mili.ant.PropertiesReplaceTaskImpl.java
@Override public void execute() throws BuildException { try {/*from w w w. j a va 2s . com*/ Validate.notEmpty(this.propertiesFile, "propertiesFile"); } catch (IllegalArgumentException e) { throw new BuildException("No properties file is setted !", e); } try { Validate.notEmpty(this.fileToReplace, "fileToReplace"); } catch (IllegalArgumentException e) { throw new BuildException("No file to replace is setted !", e); } Properties p = new Properties(); File pf = new File(this.propertiesFile); try { p.load(new FileInputStream(pf)); } catch (FileNotFoundException e) { throw new BuildException("Properties file not found !", e); } catch (IOException e) { throw new BuildException("Properties file cannot be accessed !", e); } File rf = new File(this.fileToReplace); if (!rf.exists()) { if (this.errorIfFileToReplaceDontExists) { throw new BuildException("File to replace not found !"); } return; } String s = null; try { s = FileUtils.readFileToString(rf); } catch (IOException e) { throw new BuildException("File to replace cannot be accessed !", e); } for (Enumeration<?> e = p.propertyNames(); e.hasMoreElements();) { String pn = e.nextElement().toString(); if (!pn.endsWith(".ext")) { String pv = p.getProperty(pn); String pe = p.getProperty(pn.concat(".ext")); String nn = pn + "-" + pv + "." + pe; String re = pn + "[-]{0}[-][0-9](.*)[.]" + pe; s = s.replaceAll(re, nn); } } try { FileUtils.writeStringToFile(rf, s); } catch (IOException e) { throw new BuildException("File to replace cannot be accessed !", e); } return; }
From source file:org.apache.wiki.providers.AbstractFileProvider.java
/** * Default validation, validates that key and value is ASCII <code>StringUtils.isAsciiPrintable()</code> and within lengths set up in jspwiki-custom.properties. * This can be overwritten by custom FileSystemProviders to validate additional properties * See https://issues.apache.org/jira/browse/JSPWIKI-856 * @since 2.10.2// ww w . j ava 2 s .c o m * @param customProperties the custom page properties being added */ protected void validateCustomPageProperties(Properties customProperties) throws IOException { // Default validation rules if (customProperties != null && !customProperties.isEmpty()) { if (customProperties.size() > MAX_PROPLIMIT) { throw new IOException("Too many custom properties. You are adding " + customProperties.size() + ", but max limit is " + MAX_PROPLIMIT); } Enumeration propertyNames = customProperties.propertyNames(); while (propertyNames.hasMoreElements()) { String key = (String) propertyNames.nextElement(); String value = (String) customProperties.get(key); if (key != null) { if (key.length() > MAX_PROPKEYLENGTH) { throw new IOException("Custom property key " + key + " is too long. Max allowed length is " + MAX_PROPKEYLENGTH); } if (!StringUtils.isAsciiPrintable(key)) { throw new IOException("Custom property key " + key + " is not simple ASCII!"); } } if (value != null) { if (value.length() > MAX_PROPVALUELENGTH) { throw new IOException("Custom property key " + key + " has value that is too long. Value=" + value + ". Max allowed length is " + MAX_PROPVALUELENGTH); } if (!StringUtils.isAsciiPrintable(value)) { throw new IOException("Custom property key " + key + " has value that is not simple ASCII! Value=" + value); } } } } }
From source file:net.aepik.alasca.core.ldap.Schema.java
/** * Modify objects identifiers of this schema. * @param newOIDs New objects identifiers. *//*from w w w. j a v a2s . c o m*/ public void setObjectsIdentifiers(Properties newOIDs) { // Now delete existing oid. SchemaObject[] oids = this.getObjectsInOrder(this.getSyntax().getObjectIdentifierType()); for (SchemaObject object : oids) { this.delObject(object.getId()); } // And reimport the new one. for (Enumeration keys = newOIDs.propertyNames(); keys.hasMoreElements();) { String id = (String) keys.nextElement(); SchemaValue v = this.getSyntax().createSchemaValue(this.getSyntax().getObjectIdentifierType(), id, newOIDs.getProperty(id)); SchemaObject o = this.getSyntax().createSchemaObject(this.getSyntax().getObjectIdentifierType(), v.toString()); o.addValue(id, v); this.addObject(o); } }
From source file:org.nuxeo.theme.editor.Main.java
public static Map<String, List<StyleFieldProperty>> getAvailableStylePropertiesForSelectedElement() { String viewName = getViewNameOfSelectedElement(); Style style = getStyleOfSelectedElement(); Style selectedStyleLayer = getSelectedStyleLayer(); if (selectedStyleLayer != null) { style = selectedStyleLayer;/*from ww w . j a v a 2 s . co m*/ } Map<String, List<StyleFieldProperty>> styleFieldProperties = new LinkedHashMap<String, List<StyleFieldProperty>>(); if (style == null) { return styleFieldProperties; } String path = getSelectedStyleSelector(); if (path == null) { return styleFieldProperties; } if (style.getName() != null) { viewName = "*"; } Properties styleProperties = style.getPropertiesFor(viewName, path); Properties cssProperties = org.nuxeo.theme.html.CSSUtils.getCssProperties(); Properties cssStyleCategories = org.nuxeo.theme.editor.Utils.getCssStyleCategories(); Enumeration<?> cssStyleCategoryNames = cssStyleCategories.propertyNames(); int idx = 0; while (cssStyleCategoryNames.hasMoreElements()) { String cssStyleCategoryName = (String) cssStyleCategoryNames.nextElement(); List<StyleFieldProperty> fieldProperties = new ArrayList<StyleFieldProperty>(); for (String name : cssStyleCategories.getProperty(cssStyleCategoryName).split(",")) { String value = styleProperties == null ? "" : styleProperties.getProperty(name, ""); String type = cssProperties.getProperty(name, ""); String id = "s" + idx; fieldProperties.add(new StyleFieldProperty(name, value, type, id)); idx += 1; } styleFieldProperties.put(cssStyleCategoryName, fieldProperties); } return styleFieldProperties; }
From source file:org.intermine.bio.dataconversion.DoConverter.java
private void readConfig() { Properties props = new Properties(); try {//from w w w .j a v a2 s .c om props.load(getClass().getClassLoader().getResourceAsStream(PROP_FILE)); } catch (IOException e) { throw new RuntimeException("Problem loading properties '" + PROP_FILE + "'", e); } Enumeration<?> propNames = props.propertyNames(); while (propNames.hasMoreElements()) { String taxonId = (String) propNames.nextElement(); taxonId = taxonId.substring(0, taxonId.indexOf(".")); Properties taxonProps = PropertiesUtil.stripStart(taxonId, PropertiesUtil.getPropertiesStartingWith(taxonId, props)); String identifier = taxonProps.getProperty("identifier"); if (identifier == null) { throw new IllegalArgumentException("Unable to find geneAttribute property for " + "taxon: " + taxonId + " in file: " + PROP_FILE); } if (!("symbol".equals(identifier) || "primaryIdentifier".equals(identifier) || "secondaryIdentifier".equals(identifier) || "primaryAccession".equals(identifier))) { throw new IllegalArgumentException( "Invalid identifier value for taxon: " + taxonId + " was: " + identifier); } String readColumn = taxonProps.getProperty("readColumn"); if (readColumn != null) { readColumn = readColumn.trim(); if (!("symbol".equals(readColumn) || "identifier".equals(readColumn))) { throw new IllegalArgumentException( "Invalid readColumn value for taxon: " + taxonId + " was: " + readColumn); } } String annotationType = taxonProps.getProperty("typeAnnotated"); if (annotationType == null) { LOG.info("Unable to find annotationType property for " + "taxon: " + taxonId + " in file: " + PROP_FILE + ". Creating genes by default."); } Config config = new Config(identifier, readColumn, annotationType); configs.put(taxonId, config); } }
From source file:org.hyperic.hq.hqapi1.tools.Shell.java
static private Properties getClientProperties(String file) { Properties props = new Properties(); File clientProperties = null; if (file != null) { clientProperties = new File(file); if (!clientProperties.exists()) { System.err.println("Error: " + clientProperties.toString() + " does not exist"); System.exit(-1);//from w ww . j ava 2 s.co m } } else { InputStream is = Shell.class.getResourceAsStream("/client.properties"); try { if (is != null) { props.load(is); } } catch (IOException e) { // System.err..etc.. System.exit(-1); } finally { if (is != null) { try { is.close(); } catch (IOException ignore) { } } } if (is == null) { // Default to ~/.hq/client.properties String home = System.getProperty("user.home"); File hq = new File(home, ".hq"); clientProperties = new File(hq, "client.properties"); } } if (clientProperties != null && clientProperties.exists()) { FileInputStream fis = null; props = new Properties(); try { fis = new FileInputStream(clientProperties); props.load(fis); } catch (IOException e) { return props; } finally { try { if (fis != null) { fis.close(); } } catch (IOException ioe) { // Ignore } } } // Trim property values for (Enumeration e = props.propertyNames(); e.hasMoreElements();) { String prop = (String) e.nextElement(); props.setProperty(prop, props.getProperty(prop).trim()); } return props; }
From source file:com.ecyrd.jspwiki.ui.TemplateManager.java
/** * List all available timeformats, read from the jspwiki.properties * /*from www . j a v a 2 s . co m*/ * @param pageContext * @return map of TimeFormats * @since 2.7.x */ public Map listTimeFormats(PageContext pageContext) { WikiContext context = WikiContext.findContext(pageContext); Properties props = m_engine.getWikiProperties(); ArrayList<String> tfArr = new ArrayList<String>(40); LinkedHashMap<String, String> resultMap = new LinkedHashMap<String, String>(); /* filter timeformat properties */ for (Enumeration e = props.propertyNames(); e.hasMoreElements();) { String name = (String) e.nextElement(); if (name.startsWith(TIMEFORMATPROPERTIES)) { tfArr.add(name); } } /* fetch actual formats */ if (tfArr.size() == 0) /* * no props found - make sure some default * formats are avail */ { tfArr.add("dd-MMM-yy"); tfArr.add("d-MMM-yyyy"); tfArr.add("EEE, dd-MMM-yyyy, zzzz"); } else { Collections.sort(tfArr); for (int i = 0; i < tfArr.size(); i++) { tfArr.set(i, props.getProperty(tfArr.get(i))); } } String prefTimeZone = Preferences.getPreference(context, "TimeZone"); //TimeZone tz = TimeZone.getDefault(); TimeZone tz = TimeZone.getTimeZone(prefTimeZone); /*try { tz.setRawOffset(Integer.parseInt(prefTimeZone)); } catch (Exception e) { }*/ Date d = new Date(); // current date try { // dummy format pattern SimpleDateFormat fmt = Preferences.getDateFormat(context, TimeFormat.DATETIME); fmt.setTimeZone(tz); for (int i = 0; i < tfArr.size(); i++) { try { String f = tfArr.get(i); fmt.applyPattern(f); resultMap.put(f, fmt.format(d)); } catch (IllegalArgumentException e) { } // skip parameter } } catch (IllegalArgumentException e) { } // skip parameter return resultMap; }