List of usage examples for java.util Properties keys
@Override
public Enumeration<Object> keys()
From source file:org.smartfrog.services.quartz.JobImpl.java
/** * Reads and sets system properties given in input stream. * * @param is input stream/*from www . j ava 2s . c o m*/ * @throws IOException failed to read properties */ private void readPropertiesFrom(InputStream is) throws IOException { Properties props = new Properties(); props.load(is); Properties sysProps = System.getProperties(); String name = ""; for (Enumeration e = props.keys(); e.hasMoreElements();) { Object key = e.nextElement(); Object value = props.get(key); if (key.equals(ATTR_MACHINES)) { // log.info("-----------------" + key + "====" + value); String list = value.toString(); int length = list.length(); for (int i = 0; i < length; i++) { if (list.charAt(i) != ':') { name = name.concat(list.valueOf(list.charAt(i))); } else { // log.info("---Adding host---" + name + "----to machines vector"); machines.addElement(name); name = ""; } } } } }
From source file:com.stimulus.archiva.language.LanguageIdentifier.java
/** * Constructs a new Language Identifier. *//*from w ww .j a va 2 s. c om*/ public LanguageIdentifier() { // Gets ngram sizes to take into account from the Nutch Config minLength = NGramProfile.DEFAULT_MIN_NGRAM_LENGTH; maxLength = NGramProfile.DEFAULT_MAX_NGRAM_LENGTH; // Ensure the min and max values are in an acceptale range // (ie min >= DEFAULT_MIN_NGRAM_LENGTH and max <= DEFAULT_MAX_NGRAM_LENGTH) maxLength = Math.min(maxLength, NGramProfile.ABSOLUTE_MAX_NGRAM_LENGTH); maxLength = Math.max(maxLength, NGramProfile.ABSOLUTE_MIN_NGRAM_LENGTH); minLength = Math.max(minLength, NGramProfile.ABSOLUTE_MIN_NGRAM_LENGTH); minLength = Math.min(minLength, maxLength); // Gets the value of the maximum size of data to analyze analyzeLength = DEFAULT_ANALYSIS_LENGTH; Properties p = new Properties(); try { p.load(this.getClass().getResourceAsStream("langmappings.properties")); Enumeration alllanguages = p.keys(); logger.debug("language identifier configuration {minLength='" + minLength + "',maxLength='" + maxLength + "',analyzeLength='" + analyzeLength + "'}"); StringBuffer list = new StringBuffer("language identifier service supports:"); HashMap tmpIdx = new HashMap(); while (alllanguages.hasMoreElements()) { String lang = (String) (alllanguages.nextElement()); InputStream is = this.getClass().getClassLoader().getResourceAsStream( "com/stimulus/archiva/language/" + lang + "." + NGramProfile.FILE_EXTENSION); if (is != null) { NGramProfile profile = new NGramProfile(lang, minLength, maxLength); try { profile.load(is); languages.add(profile); supportedLanguages.add(lang); List ngrams = profile.getSorted(); for (int i = 0; i < ngrams.size(); i++) { NGramEntry entry = (NGramEntry) ngrams.get(i); List registered = (List) tmpIdx.get(entry); if (registered == null) { registered = new ArrayList(); tmpIdx.put(entry, registered); } registered.add(entry); entry.setProfile(profile); } list.append(" " + lang + "(" + ngrams.size() + ")"); is.close(); } catch (IOException e1) { logger.error("failed to initialize language identifier module", e1); } } } // transform all ngrams lists to arrays for performances Iterator keys = tmpIdx.keySet().iterator(); while (keys.hasNext()) { NGramEntry entry = (NGramEntry) keys.next(); List l = (List) tmpIdx.get(entry); if (l != null) { NGramEntry[] array = (NGramEntry[]) l.toArray(new NGramEntry[l.size()]); ngramsIdx.put(entry.getSeq(), array); } } logger.debug(list.toString()); // Create the suspect profile suspect = new NGramProfile("suspect", minLength, maxLength); } catch (Exception e) { logger.error("failed to initialize language identifier service", e); } }
From source file:org.silverpeas.dbbuilder.DBBuilderPiece.java
public DBBuilderPiece(Console console, String pieceName, String actionName, boolean traceMode) throws Exception { this.console = console; this.traceMode = traceMode; this.actionName = actionName; this.pieceName = pieceName; if (pieceName.endsWith(".jar")) { content = ""; } else {// w ww.jav a 2s. c o m // charge son contenu sauf pour un jar qui doit tre dans le classpath File myFile = new File(pieceName); if (!myFile.exists() || !myFile.isFile() || !myFile.canRead()) { console.printMessage("\t\t***Unable to load : " + pieceName); throw new Exception("Unable to find or load : " + pieceName); } int fileSize = (int) myFile.length(); byte[] data = new byte[fileSize]; DataInputStream in = new DataInputStream(new FileInputStream(pieceName)); try { in.readFully(data); } finally { IOUtils.closeQuietly(in); } content = new String(data, Charsets.UTF_8); } Properties res = DBBuilder.getdbBuilderResources(); if (res != null) { for (Enumeration e = res.keys(); e.hasMoreElements();) { String key = (String) e.nextElement(); String value = res.getProperty(key); content = StringUtil.sReplace("${" + key + '}', value, content); } } }
From source file:org.apache.nutch.searcher.custom.CustomFieldQueryFilter.java
public void setConf(Configuration conf) { try {//from w w w . jav a 2 s .co m this.conf = conf; FileSystem fs = FileSystem.get(conf); String configFile = conf.get("custom.fields.config", "custom-fields.xml"); LOG.info("Reading configuration field configuration from " + configFile); Properties customFieldProps = new Properties(); InputStream fis = CustomFields.class.getClassLoader().getResourceAsStream(configFile); if (fis == null) { throw new IOException("Was unable to open " + configFile); } customFieldProps.loadFromXML(fis); Enumeration keys = customFieldProps.keys(); while (keys.hasMoreElements()) { String prop = (String) keys.nextElement(); if (prop.endsWith(".name")) { String propName = prop.substring(0, prop.length() - 5); String name = customFieldProps.getProperty(prop); fieldNames.add(name); String boostKey = propName + ".boost"; if (customFieldProps.containsKey(boostKey)) { float boost = Float.parseFloat(customFieldProps.getProperty(boostKey)); boosts.put(name, boost); } } } } catch (Exception e) { LOG.error("Error loading custom field properties:\n" + StringUtils.stringifyException(e)); } }
From source file:at.spardat.xma.boot.BootRuntime.java
/** * debug java environment parameters.// w ww.j a v a 2 s . c o m */ public void debugJavaParameter() { bootLogger.log(LogLevel.ALL, "java system properties are:"); Properties p = System.getProperties(); Enumeration enumer = p.keys(); while (enumer.hasMoreElements()) { String element = (String) enumer.nextElement(); bootLogger.log(LogLevel.ALL, "{0} : {1}", new Object[] { element, p.getProperty(element) }); } }
From source file:fr.fastconnect.factory.tibco.bw.maven.packaging.MergePropertiesMojo.java
protected Properties removeWildCards(Properties properties) { String key;/* w w w .j a v a2 s . co m*/ Enumeration<Object> e = properties.keys(); while (e.hasMoreElements()) { key = (String) e.nextElement(); if (isAWildCard(key)) { properties.remove(key); } } return properties; }
From source file:org.apache.woden.internal.resolver.SimpleURIResolver.java
/** * Takes a set of properties representing {resolved-from, resolved-to} URI pairs * and converts to a Hashtable. /* w w w . jav a2 s . com*/ * Any relative resolved-to URIs are "converted ("resolved"!) to absolute location * using the supplied classloader. Any entries for which such a convesion fails are ignored noisily. * * @param p * @param loader - class * @param h * @return HashTable mapping resolved-from URIs to absolute resolved-to URIs * @throws URISyntaxException */ private Hashtable toURI(Properties p, ClassLoader loader, Hashtable h) throws URISyntaxException { // TODO change to throw a WSDLException if (p != null) { Enumeration keys = p.keys(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); String value = p.getProperty(key); try { // if value represents an absolute URL (ie has a scheme) keep as-is // otherwise treat as relative to the URLClassloader search locations. // If the relative resource cannot be located via the class loader, // ignore the entry noisily. URI valueURI = new URI(value); if (!valueURI.isAbsolute()) { // Relative URI so use class loader lookup... URL valueURL = loader.getResource(value); if (valueURL != null) { // lookup successful valueURI = new URI(valueURL.toString()); h.put(new URI(key), valueURI); //TODO - can we replace with java.net.URL's? } else { // Report failed lookup on relative URL on RHS of catalog entry // TODO ignore noisily logger.error("Lookup failed for URL " + value); } } else { // Absolute URI - preserve as-is h.put(new URI(key), valueURI); } } catch (URISyntaxException e) { // TODO ignore noisily logger.error("Invalid URL " + value + ": " + e.getMessage()); } } } return h; }
From source file:com.ikon.principal.UsersRolesPrincipalAdapter.java
@Override public List<String> getUsers() throws PrincipalAdapterException { log.debug("getUsers()"); List<String> list = new ArrayList<String>(); Properties prop = new Properties(); try {// w w w .j a v a2 s . com prop.load(new FileInputStream(Config.HOME_DIR + "/server/default/conf/props/openkm-users.properties")); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } for (Enumeration<Object> e = prop.keys(); e.hasMoreElements();) { String user = (String) e.nextElement(); if (!Config.SYSTEM_USER.equals(user)) { list.add(user); } } log.debug("getUsers: {}", list); return list; }
From source file:org.apache.jmeter.util.JMeterUtils.java
/** * Creates a vector of strings for all the properties that start with a * common prefix.//from ww w. j av a 2 s. c om * * @param properties * Description of Parameter * @param name * Description of Parameter * @return The Vector value */ public static Vector<String> getVector(Properties properties, String name) { Vector<String> v = new Vector<>(); Enumeration<?> names = properties.keys(); while (names.hasMoreElements()) { String prop = (String) names.nextElement(); if (prop.startsWith(name)) { v.addElement(properties.getProperty(prop)); } } return v; }
From source file:com.medigy.persist.model.data.EntitySeedDataPopulator.java
/** * Loads the reference data contained in separate data files *//*from ww w . j a v a 2 s. com*/ protected void loadExternalReferenceData() { try { InputStream propertyFileStream = Environment.class.getResourceAsStream(EXTERNAL_DATA_PROPERTY_FILE); if (propertyFileStream == null) propertyFileStream = Thread.currentThread().getContextClassLoader() .getResourceAsStream(EXTERNAL_DATA_PROPERTY_FILE); if (propertyFileStream == null) { log.warn("'" + EXTERNAL_DATA_PROPERTY_FILE + "' property file not found for loading reference data contained " + "in external files."); return; } Properties props = new java.util.Properties(); props.load(propertyFileStream); final Enumeration keys = props.keys(); while (keys.hasMoreElements()) { final String className = (String) keys.nextElement(); final String dataFileName = props.getProperty(className); InputStream stream = Environment.class.getResourceAsStream(dataFileName); if (stream == null) stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(dataFileName); Scanner sc = new Scanner(stream); int rowsAdded = 0; if (sc.hasNextLine()) { sc.findInLine( "\\\"([ \\.0-9a-zA-Z]*)\\\"\\s*\\\"([ \\.0-9a-zA-Z]*)\\\"\\s*\\\"([ \\.0-9a-zA-Z]*)\\\"\\s*\\\"([ \\.0-9a-zA-Z]*)\\\""); try { MatchResult result = sc.match(); final Class refClass = Class.forName(className); final Object refObject = refClass.newInstance(); if (refObject instanceof AbstractReferenceEntity) { final AbstractReferenceEntity refEntity = (AbstractReferenceEntity) refObject; refEntity.setCode(result.group(0)); refEntity.setLabel(result.group(1)); refEntity.setDescription(result.group(2)); HibernateUtil.getSession().save(refEntity); rowsAdded++; } } catch (Exception e) { log.error(className + ": Error at data row count = " + rowsAdded + " \n" + ExceptionUtils.getStackTrace(e)); } } sc.close(); log.info(className + ", Rows Added = " + rowsAdded); } //InputStream stream = new FileInputStream("e:\\netspective\\medigy\\persistence\\database\\refdata\\icd9-codes.txt"); } catch (Exception e) { log.error(ExceptionUtils.getStackTrace(e)); } }