List of usage examples for java.util Properties isEmpty
@Override public boolean isEmpty()
From source file:org.codice.ddf.platform.util.properties.PropertiesLoader.java
/** * Will attempt to load properties from a file using the given classloader. If that fails, several * other methods will be tried until the properties file is located. * * @param propertiesFile the resource name or the file path of the properties file * @param classLoader the class loader with access to the properties file * @return Properties deserialized from the specified file, or empty if the load failed *//*from ww w . j a va 2 s.c o m*/ public Properties loadProperties(String propertiesFile, ClassLoader classLoader) { Properties properties = new Properties(); if (propertiesFile == null) { LOGGER.debug("Properties file must not be null."); return properties; } Iterator<BiFunction<String, ClassLoader, Properties>> strategiesIterator = PROPERTY_LOADING_STRATEGIES .iterator(); do { properties = strategiesIterator.next().apply(propertiesFile, classLoader); } while (properties.isEmpty() && strategiesIterator.hasNext()); properties = substituteSystemPropertyPlaceholders(properties); return properties; }
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/* w w w. j a v a 2s . com*/ * @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:com.iyonger.apm.web.configuration.Config.java
/** * Load system related properties. (system.conf) *//*from w ww. j a v a2s .c o m*/ public synchronized void loadProperties() { Properties properties = checkNotNull(home).getProperties("system.conf"); properties.put("NGRINDER_HOME", home.getDirectory().getAbsolutePath()); if (exHome.exists()) { Properties exProperties = exHome.getProperties("system-ex.conf"); if (exProperties.isEmpty()) { exProperties = exHome.getProperties("system.conf"); } properties.putAll(exProperties); } properties.putAll(System.getProperties()); // Override if exists controllerProperties = new PropertiesWrapper(properties, controllerPropertiesKeyMapper); //clusterProperties = new PropertiesWrapper(properties, clusterPropertiesKeyMapper); }
From source file:org.ldmud.jldmud.GameConfiguration.java
/** * Load the settings from the given input source and/or the override properties, and validate them. * If the validation fails, an error message is printed to stderr. * * @param propertyFileName The name of the settings file in properties format. * @param overrideProperties A manually created set of properties, overriding those in the settings file. If this set * is not empty, the {@code propertyFileName} need not exist. * @return {@code true} if the file was successfully loaded. *///w w w.ja va 2s.c om public boolean loadProperties(String propertyFileName, Properties overrideProperties) { Properties properties = new Properties(); try (InputStream in = new FileInputStream(propertyFileName)) { properties.load(in); } catch (IOException ioe) { final String message = (ioe instanceof FileNotFoundException) ? "File not found" : ioe.toString(); if (overrideProperties.isEmpty()) { System.err.println("Error: Problem loading ".concat(propertyFileName).concat(": ").concat(message)); return false; } System.err.println("Warning: Problem loading ".concat(propertyFileName).concat(": ").concat(message)); } List<String> errors = loadProperties(properties, overrideProperties, allSettings); if (!errors.isEmpty()) { System.err.println( "Error: Property validation problems loading the configuration '" + propertyFileName + "':"); for (String entry : errors) { System.err.println(" " + entry); } } return errors.isEmpty(); }
From source file:org.apache.sqoop.core.SqoopConfiguration.java
private synchronized void configureLogging() { Properties props = new Properties(); for (Map.Entry<String, String> entry : config.entrySet()) { String key = entry.getKey(); if (key.startsWith(ConfigurationConstants.PREFIX_LOG_CONFIG)) { String logConfigKey = key.substring(ConfigurationConstants.PREFIX_GLOBAL_CONFIG.length()); props.put(logConfigKey, entry.getValue()); }/*from w ww. j a v a 2 s . c o m*/ } if (props.isEmpty()) { LOG.info("Skipping log4j configuration as it's not configured in sqoop.properties file."); return; } PropertyConfigurator.configure(props); }
From source file:org.apache.openjpa.jdbc.schema.DBCPDriverDataSource.java
/** * Merge the passed in properties with a copy of the existing _connectionProperties * @param props/*from w w w .j a va 2 s . c o m*/ * @return Merged properties */ private Properties mergeConnectionProperties(final Properties props) { Properties mergedProps = new Properties(); mergedProps.putAll(getConnectionProperties()); // need to map "user" to "username" for Commons DBCP String uid = removeProperty(mergedProps, "user"); if (uid != null) { mergedProps.setProperty("username", uid); } // now, merge in any passed in properties if (props != null && !props.isEmpty()) { for (Iterator<Object> itr = props.keySet().iterator(); itr.hasNext();) { String key = (String) itr.next(); String value = props.getProperty(key); // need to map "user" to "username" for Commons DBCP if ("user".equalsIgnoreCase(key)) { key = "username"; } // case-insensitive search for existing key String existingKey = hasKey(mergedProps, key); if (existingKey != null) { // update existing entry mergedProps.setProperty(existingKey, value); } else { // add property to the merged set mergedProps.setProperty(key, value); } } } return mergedProps; }
From source file:org.dhatim.routing.jms.JMSRouter.java
@Initialize public void initialize() throws SmooksConfigurationException, JMSException { Context context = null;//from w ww .ja va 2 s. c o m boolean initialized = false; if (beanId == null) { throw new SmooksConfigurationException("Mandatory 'beanId' property not defined."); } if (jmsProperties.getDestinationName() == null) { throw new SmooksConfigurationException("Mandatory 'destinationName' property not defined."); } try { if (correlationIdPattern != null) { correlationIdTemplate = new FreeMarkerTemplate(correlationIdPattern); } Properties jndiContextProperties = jndiProperties.toProperties(); if (jndiContextProperties.isEmpty()) { context = new InitialContext(); } else { context = new InitialContext(jndiContextProperties); } destination = (Destination) context.lookup(jmsProperties.getDestinationName()); msgProducer = createMessageProducer(destination, context); setMessageProducerProperties(); initialized = true; } catch (NamingException e) { final String errorMsg = "NamingException while trying to lookup [" + jmsProperties.getDestinationName() + "]"; logger.error(errorMsg, e); throw new SmooksConfigurationException(errorMsg, e); } finally { if (context != null) { try { context.close(); } catch (NamingException e) { logger.debug("NamingException while trying to close initial Context"); } } if (!initialized) { releaseJMSResources(); } } }
From source file:net.ymate.platform.configuration.provider.impl.JConfigProvider.java
public Map<String, String> getMap(String keyHead) { Map<String, String> map = new HashMap<String, String>(); if (StringUtils.isBlank(keyHead)) { return map; }/*from www . ja v a2s. c o m*/ String[] keys = StringUtils.split(keyHead, IConfiguration.CFG_KEY_SEPERATE); int keysSize = keys.length; Properties properties = null; // "|"0?? if (keysSize == 1) { properties = config.getProperties(); } else if (keysSize == 2) { properties = config.getProperties(keys[0]); } int headLength = keysSize == 1 ? keys[0].length() : keys[1].length(); if (properties != null && !properties.isEmpty()) { for (Object name : properties.keySet()) { if (name != null && name.toString().startsWith(keysSize == 1 ? keys[0] : keys[1])) { String key = name.toString(); Object value = properties.get(name); map.put(key.substring(headLength), value.toString()); } } } return map; }
From source file:org.plukh.fluffymeow.config.S3Properties.java
public synchronized void load(String deploymentId, String applicationName, InputStream in) throws IOException { if (in != null) { try {//w w w . jav a 2 s . c o m log.debug("Trying to load properties from provided input stream"); super.load(in); if (log.isDebugEnabled()) log.debug("Loaded " + size() + " total properties"); return; } catch (IOException e) { log.debug("Failed to load properties from provided input stream", e); } } log.debug("Proceeding with S3 download"); log.trace("Downloading default properties"); Properties defaultProperties = downloadFromS3(bucket, DEFAULT_PROPERTIES, null); log.trace("Downloading deployment-default properties"); Properties deplDefaultProperties = downloadFromS3(bucket, deploymentId + "/" + DEFAULT_PROPERTIES, defaultProperties); log.trace("Downloading application-specific properties"); Properties appProperties = downloadFromS3(bucket, deploymentId + "/" + applicationName + "/" + applicationName + ".properties", deplDefaultProperties); log.trace("Downloading version-specific properties"); Properties versionProperties = downloadFromS3(bucket, deploymentId + "/" + applicationName + "/" + applicationName + "-" + versionInfoProvider.getVersion() + ".properties", appProperties); //Validate properties (at least one specific property file should be found!) if (appProperties.isEmpty() && versionProperties.isEmpty()) throw new ConfigException("No specific configuration files found!"); clear(); Enumeration<?> names = versionProperties.propertyNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); this.setProperty(name, versionProperties.getProperty(name)); } if (log.isDebugEnabled()) log.debug("Loaded " + size() + " total properties"); }
From source file:org.apache.synapse.commons.datasource.JNDIBasedDataSourceRepository.java
/** * Register a DataSource in the JNDI tree * * @see DataSourceRepository#register(DataSourceInformation) *//*from w w w .jav a 2 s. c o m*/ public void register(DataSourceInformation information) { validateInitialized(); String dataSourceName = information.getDatasourceName(); validateDSName(dataSourceName); Properties properties = information.getProperties(); InitialContext context = null; Properties jndiEvn = null; if (properties == null || properties.isEmpty()) { if (initialContext != null) { context = initialContext; if (log.isDebugEnabled()) { log.debug("Empty JNDI properties for datasource " + dataSourceName); log.debug("Using system-wide jndi properties : " + jndiProperties); } jndiEvn = jndiProperties; } } if (context == null) { jndiEvn = createJNDIEnvironment(properties, information.getAlias()); context = createInitialContext(jndiEvn); if (context == null) { validateInitialContext(initialContext); context = initialContext; if (log.isDebugEnabled()) { log.debug("Cannot create a name context with provided jndi properties : " + jndiEvn); log.debug("Using system-wide JNDI properties : " + jndiProperties); } jndiEvn = jndiProperties; } else { perDataSourceICMap.put(dataSourceName, context); } } String dsType = information.getType(); String driver = information.getDriver(); String url = information.getUrl(); String user = information.getSecretInformation().getUser(); String password = information.getSecretInformation().getResolvedSecret(); String maxActive = String.valueOf(information.getMaxActive()); String maxIdle = String.valueOf(information.getMaxIdle()); String maxWait = String.valueOf(information.getMaxWait()); //populates context tree populateContextTree(context, dataSourceName); if (DataSourceInformation.BASIC_DATA_SOURCE.equals(dsType)) { Reference ref = new Reference("javax.sql.DataSource", "org.apache.commons.dbcp.BasicDataSourceFactory", null); ref.add(new StringRefAddr(DataSourceConstants.PROP_DRIVER_CLS_NAME, driver)); ref.add(new StringRefAddr(DataSourceConstants.PROP_URL, url)); ref.add(new StringRefAddr(SecurityConstants.PROP_USER_NAME, user)); ref.add(new StringRefAddr(SecurityConstants.PROP_PASSWORD, password)); ref.add(new StringRefAddr(DataSourceConstants.PROP_MAX_ACTIVE, maxActive)); ref.add(new StringRefAddr(DataSourceConstants.PROP_MAX_IDLE, maxIdle)); ref.add(new StringRefAddr(DataSourceConstants.PROP_MAX_WAIT, maxWait)); // set BasicDataSource specific parameters setBasicDataSourceParameters(ref, information); //set default jndiProperties for reference setCommonParameters(ref, information); try { if (log.isDebugEnabled()) { log.debug("Registering a DataSource with name : " + dataSourceName + " in the JNDI tree with jndiProperties : " + jndiEvn); } context.rebind(dataSourceName, ref); } catch (NamingException e) { String msg = " Error binding name ' " + dataSourceName + " ' to " + "the DataSource(BasicDataSource) reference"; throw new SynapseCommonsException(msg, e, log); } } else if (DataSourceInformation.PER_USER_POOL_DATA_SOURCE.equals(dsType)) { // Construct DriverAdapterCPDS reference String className = (String) information.getParameter(DataSourceConstants.PROP_CPDS_ADAPTER + DataSourceConstants.DOT_STRING + DataSourceConstants.PROP_CPDS_CLASS_NAME); String factory = (String) information.getParameter(DataSourceConstants.PROP_CPDS_ADAPTER + DataSourceConstants.DOT_STRING + DataSourceConstants.PROP_CPDS_FACTORY); String name = (String) information.getParameter(DataSourceConstants.PROP_CPDS_ADAPTER + DataSourceConstants.DOT_STRING + DataSourceConstants.PROP_CPDS_NAME); Reference cpdsRef = new Reference(className, factory, null); cpdsRef.add(new StringRefAddr(DataSourceConstants.PROP_DRIVER, driver)); cpdsRef.add(new StringRefAddr(DataSourceConstants.PROP_URL, url)); cpdsRef.add(new StringRefAddr(DataSourceConstants.PROP_USER, user)); cpdsRef.add(new StringRefAddr(SecurityConstants.PROP_PASSWORD, password)); try { context.rebind(name, cpdsRef); } catch (NamingException e) { String msg = "Error binding name '" + name + "' to " + "the DriverAdapterCPDS reference"; throw new SynapseCommonsException(msg, e, log); } // Construct PerUserPoolDataSource reference Reference ref = new Reference("org.apache.commons.dbcp.datasources.PerUserPoolDataSource", "org.apache.commons.dbcp.datasources.PerUserPoolDataSourceFactory", null); ref.add(new BinaryRefAddr(DataSourceConstants.PROP_JNDI_ENV, MiscellaneousUtil.serialize(jndiEvn))); ref.add(new StringRefAddr(DataSourceConstants.PROP_DATA_SOURCE_NAME, name)); ref.add(new StringRefAddr(DataSourceConstants.PROP_DEFAULT_MAX_ACTIVE, maxActive)); ref.add(new StringRefAddr(DataSourceConstants.PROP_DEFAULT_MAX_IDLE, maxIdle)); ref.add(new StringRefAddr(DataSourceConstants.PROP_DEFAULT_MAX_WAIT, maxWait)); //set default jndiProperties for reference setCommonParameters(ref, information); try { if (log.isDebugEnabled()) { log.debug("Registering a DataSource with name : " + dataSourceName + " in the JNDI tree with jndiProperties : " + jndiEvn); } context.rebind(dataSourceName, ref); } catch (NamingException e) { String msg = "Error binding name ' " + dataSourceName + " ' to " + "the PerUserPoolDataSource reference"; throw new SynapseCommonsException(msg, e, log); } } else { throw new SynapseCommonsException("Unsupported data source type : " + dsType, log); } cachedNameList.add(dataSourceName); }