List of usage examples for java.util Properties size
@Override public int size()
From source file:nl.nn.adapterframework.util.Misc.java
public static Properties getEnvironmentVariables() throws IOException { Properties props = new Properties(); try {/*from ww w .j av a 2 s.c o m*/ Method getenvs = System.class.getMethod("getenv", (java.lang.Class[]) null); Map env = (Map) getenvs.invoke(null, (java.lang.Object[]) null); for (Iterator it = env.keySet().iterator(); it.hasNext();) { String key = (String) it.next(); String value = (String) env.get(key); props.setProperty(key, value); } } catch (NoSuchMethodException e) { log.debug("Caught NoSuchMethodException, just not on JDK 1.5: " + e.getMessage()); } catch (IllegalAccessException e) { log.debug("Caught IllegalAccessException, using JDK 1.4 method", e); } catch (InvocationTargetException e) { log.debug("Caught InvocationTargetException, using JDK 1.4 method", e); } if (props.size() == 0) { BufferedReader br = null; Process p = null; Runtime r = Runtime.getRuntime(); String OS = System.getProperty("os.name").toLowerCase(); if (OS.indexOf("windows 9") > -1) { p = r.exec("command.com /c set"); } else if ((OS.indexOf("nt") > -1) || (OS.indexOf("windows 20") > -1) || (OS.indexOf("windows xp") > -1)) { p = r.exec("cmd.exe /c set"); } else { //assume Unix p = r.exec("env"); } // props.load(p.getInputStream()); // this does not work, due to potential malformed escape sequences br = new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while ((line = br.readLine()) != null) { int idx = line.indexOf('='); if (idx >= 0) { String key = line.substring(0, idx); String value = line.substring(idx + 1); props.setProperty(key, value); } } } return props; }
From source file:org.restlet.ext.jdbc.JdbcClientHelper.java
/** * Returns a JDBC connection.//from w ww . ja v a2 s . c o m * * @param uri * The connection URI. * @param properties * The connection properties. * @param usePooling * Indicates if the connection pooling should be used. * @return The JDBC connection. * @throws SQLException */ protected Connection getConnection(String uri, Properties properties, boolean usePooling) throws SQLException { Connection result = null; if (usePooling) { for (ConnectionSource c : this.connectionSources) { // Check if the connection URI is identical // and if the same number of properties is present if ((result == null) && c.getUri().equalsIgnoreCase(uri) && (properties.size() == c.getProperties().size())) { // Check that the properties tables are equivalent boolean equal = true; for (Object key : c.getProperties().keySet()) { if (equal && properties.containsKey(key)) { equal = equal && (properties.get(key).equals(c.getProperties().get(key))); } else { equal = false; } } if (equal) { result = c.getConnection(); } } } if (result == null) { // No existing connection source found ConnectionSource cs = new ConnectionSource(uri, properties); this.connectionSources.add(cs); result = cs.getConnection(); } } else { result = DriverManager.getConnection(uri, properties); } return result; }
From source file:cz.alej.michalik.totp.client.AddDialog.java
/** * Odele nov zznam//from w ww.j ava2 s . c o m * * @param prop * Properties * @param name * Textov pole s jmnem * @param secret * Textov pole s heslem * @param exitOnError * Zave okno i pi chyb, pokud uivatel klikne na kek */ private void submit(final Properties prop, final JTextField name, final JTextField secret, boolean exitOnError) { System.out.printf("Jmno: %s | Heslo: %s\n", name.getText(), secret.getText()); boolean error = false; sanitize(secret); if (name.getText().equals("") || secret.getText().equals("") || !verify(secret)) { System.out.println("Nepidno"); error = true; } else { System.out.printf("Base32 heslo je: %s\n", new Base32().encodeToString(secret.getText().getBytes())); int id = prop.size(); // Po odstrann me bt nkter index pesko?en while (prop.containsKey(String.valueOf(id))) { id++; } StringBuilder sb = new StringBuilder(); // Zznam je ve tvaru "jmno;heslo" sb.append(name.getText()); sb.append(";"); sb.append(secret.getText()); prop.setProperty(String.valueOf(id), sb.toString()); App.saveProperties(); App.loadProperties(); } if (exitOnError || !error) { this.dispose(); } }
From source file:org.mili.ant.FileVersionTaskImpl.java
/** * Execute./* www . j av a 2s. co m*/ * * @throws BuildException the build exception */ public void execute() throws BuildException { if (this.fileToWrite == null || this.fileToWrite.length() == 0) { throw new BuildException("No file to write setted !"); } if (this.dirToCheck == null || this.dirToCheck.length() == 0) { throw new BuildException("No dir to check setted !"); } if (this.listOfExtensions == null || this.listOfExtensions.length() == 0) { throw new BuildException("No list of extensions setted !"); } String[] loe = this.listOfExtensions.split("[,]"); String[] dirs = this.dirToCheck.split("[,]"); Properties p = new Properties(); FileVersionFunction fvf = new FileVersionFunction(); for (int i = 0; i < dirs.length; i++) { File f0 = new File(dirs[i]); if (f0.exists()) { Collection<File> l = FileUtils.listFiles(f0, loe, true); for (Iterator<File> ii = l.iterator(); ii.hasNext();) { File f = ii.next(); FileInfo fi = fvf.evaluate(f); if (fi.isHasVersion()) { p.setProperty(fi.getName(), fi.getVersion()); p.setProperty(fi.getName().concat(".ext"), fi.getExtension()); } } } } if (p.size() > 0) { File ftw = new File(this.fileToWrite); try { FileOutputStream fos = new FileOutputStream(ftw); p.store(fos, null); } catch (FileNotFoundException e) { throw new BuildException("File[" + ftw.getAbsolutePath() + "] not found !", e); } catch (IOException e) { throw new BuildException("File[" + ftw.getAbsolutePath() + "] cannot be accessed !", e); } } return; }
From source file:com.noelios.restlet.ext.jdbc.JdbcClientHelper.java
/** * Returns a JDBC connection./*from ww w. ja va2s.c o m*/ * * @param uri * The connection URI. * @param properties * The connection properties. * @param usePooling * Indicates if the connection pooling should be used. * @return The JDBC connection. * @throws SQLException */ protected Connection getConnection(String uri, Properties properties, boolean usePooling) throws SQLException { Connection result = null; if (usePooling) { for (final ConnectionSource c : this.connectionSources) { // Check if the connection URI is identical // and if the same number of properties is present if ((result == null) && c.getUri().equalsIgnoreCase(uri) && (properties.size() == c.getProperties().size())) { // Check that the properties tables are equivalent boolean equal = true; for (final Object key : c.getProperties().keySet()) { if (equal && properties.containsKey(key)) { equal = equal && (properties.get(key).equals(c.getProperties().get(key))); } else { equal = false; } } if (equal) { result = c.getConnection(); } } } if (result == null) { // No existing connection source found final ConnectionSource cs = new ConnectionSource(uri, properties); this.connectionSources.add(cs); result = cs.getConnection(); } } else { result = DriverManager.getConnection(uri, properties); } return result; }
From source file:com.francetelecom.clara.cloud.logicalmodel.ProcessingNode.java
/** * Utility method to return a merged list of {@link LogicalConfigService} content in a {@link Properties} format. * * @return a @{link Properties} instance with {@link String} as keys and * @throws InvalidConfigServiceException if some of the {@link LogicalConfigService} associated to this object were * not valid *//*from w w w . ja v a 2 s . c o m*/ public Properties getMergedConfigServicesProperties() throws InvalidConfigServiceException { List<LogicalConfigService> logicalConfigServices = listLogicalServices(LogicalConfigService.class); Properties mergedProperties = new Properties(); Set<String> duplicates = new HashSet<String>(); StringBuffer collisions = new StringBuffer(); for (LogicalConfigService logicalConfigService : logicalConfigServices) { //Check overlap in key names among the subscribed config services logicalConfigService.mergeAndCheckForDuplicateKeys(mergedProperties, duplicates, collisions); } if (mergedProperties.size() > MAX_CONFIG_SET_ENTRIES_PER_EXEC_NODE) { InvalidConfigServiceException invalidConfigServiceException = new InvalidConfigServiceException( "Too many Config entries for ExecutionNode=" + this.getLabel()); invalidConfigServiceException.setType(ErrorType.TOO_MANY_ENTRIES); invalidConfigServiceException.setEntryCount(mergedProperties.size()); invalidConfigServiceException.setMaxEntryCount(MAX_CONFIG_SET_ENTRIES_PER_EXEC_NODE); invalidConfigServiceException.setImpactedElementName(getLabel()); throw invalidConfigServiceException; } if (collisions.length() > 0) { InvalidConfigServiceException invalidConfigServiceException = new InvalidConfigServiceException( "Collision for ExecutionNode=" + this.getLabel() + " collision=" + collisions.toString()); invalidConfigServiceException.setType(ErrorType.DUPLICATE_KEYS); invalidConfigServiceException.getDuplicateKeys().addAll(duplicates); invalidConfigServiceException.setImpactedElementName(getLabel()); throw invalidConfigServiceException; } return mergedProperties; }
From source file:org.alfresco.reporting.execution.ReportingRoot.java
public void setTargetQueries(String queries) { if (logger.isDebugEnabled()) logger.debug("enter getAllTargetQueries"); Properties returnProps = new Properties(); String[] lines = queries.split("\\n"); for (String line : lines) { line = line.trim();// w w w .j av a 2s . co m if (!line.trim().startsWith("#") && line.indexOf("=") > 1) { int i = line.indexOf("="); String key = line.substring(0, i); String value = line.substring(i + 1); returnProps.put(key, value); if (logger.isDebugEnabled()) logger.debug("getAllTargetQueries: Storing " + key + "=" + value); } // end if } // end for if (logger.isDebugEnabled()) logger.debug("exit getTargetQueries, size=" + returnProps.size()); this.targetQueries = returnProps; }
From source file:org.intermine.web.logic.config.WebConfig.java
/** * Load a set of files into a single merged properties file. These files should all be * located in the WEB-INF directory of the webapp war. * * @param fileNames The file names to load. * @throws FileNotFoundException If a file is listed but does not exist in WEB-INF. * @throws IllegalStateException If two files configure the same key. * @throws IOException if the properties cannot be loaded. *//*from w ww . java 2 s . com*/ private static Properties loadMergedProperties(final List<String> fileNames, final ServletContext context) throws IOException { final Properties props = new Properties(); for (final String fileName : fileNames) { LOG.info("Loading properties from " + fileName); final Properties theseProps = new Properties(); final InputStream is = context.getResourceAsStream("/WEB-INF/" + fileName); if (is == null) { throw new FileNotFoundException("Could not find mappings file: " + fileName); } try { theseProps.load(is); } catch (final IOException e) { throw new Error("Problem reading from " + fileName, e); } if (!props.isEmpty()) { for (@SuppressWarnings("rawtypes") final Enumeration e = props.propertyNames(); e.hasMoreElements();) { final String key = (String) e.nextElement(); if (theseProps.containsKey(key)) { throw new IllegalStateException("Duplicate label found for " + key + " in " + fileName); } } } if (theseProps.isEmpty()) { LOG.info("No properties loaded from " + fileName); } else { LOG.info("Merging in " + theseProps.size() + " mappings from " + fileName); props.putAll(theseProps); } } return props; }
From source file:org.rhq.enterprise.server.system.SystemManagerBean.java
private Map<String, String> toMap(Properties props) { HashMap<String, String> map = new HashMap<String, String>(props.size()); for (Map.Entry<Object, Object> entry : props.entrySet()) { map.put(String.valueOf(entry.getKey()), String.valueOf(entry.getValue())); }/*from w w w . jav a 2 s.c o m*/ return map; }