Example usage for java.util Properties isEmpty

List of usage examples for java.util Properties isEmpty

Introduction

In this page you can find the example usage for java.util Properties isEmpty.

Prototype

@Override
    public boolean isEmpty() 

Source Link

Usage

From source file:com.glaf.core.config.DBConfiguration.java

/**
 * ??//from w ww .  j a  va 2 s .  c  o  m
 * 
 * @param name
 *            ??
 * @param dbType
 *            ?
 * @param host
 *            
 * @param port
 *            ?
 * @param databaseName
 *            ???
 * @param user
 *            ??
 * @param password
 *            ?
 */
public static void addDataSourceProperties(String name, String dbType, String host, int port,
        String databaseName, String user, String password) {
    Properties props = getTemplateProperties(dbType);
    if (props != null && !props.isEmpty()) {
        Map<String, Object> context = new HashMap<String, Object>();
        context.put("host", host);
        if (port > 0) {
            context.put("port", port);
        } else {
            context.put("port", props.getProperty(PORT));
        }
        context.put("databaseName", databaseName);
        String driver = props.getProperty(JDBC_DRIVER);
        String url = props.getProperty(JDBC_URL);
        url = com.glaf.core.el.ExpressionTools.evaluate(url, context);
        logger.debug("name:" + name);
        logger.debug("driver:" + driver);
        logger.debug("url:" + url);
        addDataSourceProperties(name, driver, url, user, password);
    }
}

From source file:ddf.security.common.util.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.
 * /*from   ww  w.  ja  va2  s .c  om*/
 * @param propertiesFile
 * @param classLoader
 * @return Properties
 */
public static Properties loadProperties(String propertiesFile, ClassLoader classLoader) {
    boolean error = false;
    Properties properties = new Properties();
    if (propertiesFile != null) {
        try {
            if (logger.isDebugEnabled()) {
                logger.debug("Attempting to load properties from " + propertiesFile
                        + " with Spring PropertiesLoaderUtils.");
            }
            properties = PropertiesLoaderUtils.loadAllProperties(propertiesFile);
        } catch (IOException e) {
            error = true;
            logger.error("Unable to load properties using default Spring properties loader.", e);
        }
        if (error || properties.isEmpty()) {
            if (classLoader != null) {
                try {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Attempting to load properties from " + propertiesFile
                                + " with Spring PropertiesLoaderUtils with class loader.");
                    }
                    properties = PropertiesLoaderUtils.loadAllProperties(propertiesFile, classLoader);
                    error = false;
                } catch (IOException e) {
                    error = true;
                    logger.error("Unable to load properties using default Spring properties loader.", e);
                }
            } else {
                try {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Attempting to load properties from " + propertiesFile
                                + " with Spring PropertiesLoaderUtils with class loader.");
                    }
                    properties = PropertiesLoaderUtils.loadAllProperties(propertiesFile,
                            PropertiesLoader.class.getClassLoader());
                    error = false;
                } catch (IOException e) {
                    error = true;
                    logger.error("Unable to load properties using default Spring properties loader.", e);
                }
            }
        }

        if (error || properties.isEmpty()) {
            if (logger.isDebugEnabled()) {
                logger.debug("Attempting to load properties from file system: " + propertiesFile);
            }
            File propFile = null;
            if (propertiesFile.startsWith("/")) {
                propFile = new File(propertiesFile);
            } else {
                String karafHome = System.getProperty("karaf.home");
                if (karafHome != null && !karafHome.isEmpty()) {
                    propFile = new File(karafHome, propertiesFile);
                } else {
                    karafHome = System.getProperty("ddf.home");
                    if (karafHome != null && !karafHome.isEmpty()) {
                        propFile = new File(karafHome, propertiesFile);
                    } else {
                        propFile = new File(propertiesFile);
                    }
                }
            }
            properties = new Properties();
            try {
                properties.load(new FileReader(propFile));
            } catch (FileNotFoundException e) {
                error = true;
                logger.error("Could not find properties file: " + propFile.getAbsolutePath(), e);
            } catch (IOException e) {
                error = true;
                logger.error("Error reading properties file: " + propFile.getAbsolutePath(), e);
            }
        }
        if (error || properties.isEmpty()) {
            if (logger.isDebugEnabled()) {
                logger.debug("Attempting to load properties as a resource: " + propertiesFile);
            }
            InputStream ins = PropertiesLoader.class.getResourceAsStream(propertiesFile);
            if (ins != null) {
                try {
                    properties.load(ins);
                    ins.close();
                } catch (IOException e) {
                    logger.error("Unable to load properties: " + propertiesFile, e);
                } finally {
                    try {
                        ins.close();
                    } catch (IOException ignore) {
                    }
                }
            }
        }
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("Properties file must not be null.");
        }
    }

    return properties;
}

From source file:org.codice.ddf.security.common.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//w w w.  j a  va 2s. c  om
 * @param classLoader
 * @return Properties
 */
public static Properties loadProperties(String propertiesFile, ClassLoader classLoader) {
    boolean error = false;
    Properties properties = new Properties();
    if (propertiesFile != null) {
        try {
            if (logger.isDebugEnabled()) {
                logger.debug("Attempting to load properties from " + propertiesFile
                        + " with Spring PropertiesLoaderUtils.");
            }
            properties = PropertiesLoaderUtils.loadAllProperties(propertiesFile);
        } catch (IOException e) {
            error = true;
            logger.error("Unable to load properties using default Spring properties loader.", e);
        }
        if (error || properties.isEmpty()) {
            if (classLoader != null) {
                try {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Attempting to load properties from " + propertiesFile
                                + " with Spring PropertiesLoaderUtils with class loader.");
                    }
                    properties = PropertiesLoaderUtils.loadAllProperties(propertiesFile, classLoader);
                    error = false;
                } catch (IOException e) {
                    error = true;
                    logger.error("Unable to load properties using default Spring properties loader.", e);
                }
            } else {
                try {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Attempting to load properties from " + propertiesFile
                                + " with Spring PropertiesLoaderUtils with class loader.");
                    }
                    properties = PropertiesLoaderUtils.loadAllProperties(propertiesFile,
                            PropertiesLoader.class.getClassLoader());
                    error = false;
                } catch (IOException e) {
                    error = true;
                    logger.error("Unable to load properties using default Spring properties loader.", e);
                }
            }
        }

        if (error || properties.isEmpty()) {
            if (logger.isDebugEnabled()) {
                logger.debug("Attempting to load properties from file system: " + propertiesFile);
            }
            File propFile = new File(propertiesFile);
            // If properties file has fully-qualified absolute path (which
            // the blueprint file specifies) then can load it directly.
            if (propFile.isAbsolute()) {
                logger.debug("propertiesFile {} is absolute", propertiesFile);
                propFile = new File(propertiesFile);
            } else {
                // Otherwise need to prepend parent path which is based on
                // the installation directory
                String karafHome = System.getProperty("karaf.home");
                if (karafHome != null && !karafHome.isEmpty()) {
                    propFile = new File(karafHome, propertiesFile);
                } else {
                    karafHome = System.getProperty("ddf.home");
                    if (karafHome != null && !karafHome.isEmpty()) {
                        propFile = new File(karafHome, propertiesFile);
                    } else {
                        propFile = new File(propertiesFile);
                    }
                }
            }
            properties = new Properties();
            try (FileReader reader = new FileReader(propFile)) {
                properties.load(reader);
            } catch (FileNotFoundException e) {
                error = true;
                logger.error("Could not find properties file: " + propFile.getAbsolutePath(), e);
            } catch (IOException e) {
                error = true;
                logger.error("Error reading properties file: " + propFile.getAbsolutePath(), e);
            }
        }
        if (error || properties.isEmpty()) {
            if (logger.isDebugEnabled()) {
                logger.debug("Attempting to load properties as a resource: " + propertiesFile);
            }
            InputStream ins = PropertiesLoader.class.getResourceAsStream(propertiesFile);
            if (ins != null) {
                try {
                    properties.load(ins);
                    ins.close();
                } catch (IOException e) {
                    logger.error("Unable to load properties: " + propertiesFile, e);
                } finally {
                    try {
                        ins.close();
                    } catch (IOException ignore) {
                    }
                }
            }
        }
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("Properties file must not be null.");
        }
    }

    return properties;
}

From source file:net.ymate.platform.core.i18n.I18N.java

/**
 * @param resourceName ???/*from   w ww .  ja va2s .c o  m*/
 * @param key          
 * @param defaultValue 
 * @return ????key
 */
public static String load(String resourceName, String key, String defaultValue) {
    Locale _local = current();
    Map<String, Properties> _cache = __RESOURCES_CAHCES.get(_local);
    Properties _prop = _cache != null ? _cache.get(resourceName) : null;
    if (_prop == null) {
        if (__EVENT_HANDLER != null) {
            try {
                List<String> _localeResourceNames = __doGetResourceNames(_local, resourceName);
                InputStream _inputStream = null;
                for (String _localeResourceName : _localeResourceNames) {
                    _inputStream = __EVENT_HANDLER.onLoad(_localeResourceName);
                    if (_inputStream != null) {
                        _prop = new Properties();
                        _prop.load(_inputStream);
                        break;
                    }
                }
                if (_prop != null && !_prop.isEmpty()) {
                    if (_cache == null) {
                        __RESOURCES_CAHCES.put(_local, new ConcurrentHashMap<String, Properties>());
                    }
                    __RESOURCES_CAHCES.get(_local).put(resourceName, _prop);
                }
            } catch (IOException e) {
                _LOG.warn("", RuntimeUtils.unwrapThrow(e));
            }
        }
    }
    String _returnValue = null;
    if (_prop != null) {
        _returnValue = _prop.getProperty(key, defaultValue);
    } else {
        try {
            _returnValue = ResourceBundle.getBundle(resourceName, _local).getString(key);
        } catch (Exception ignored) {
        }
    }
    return StringUtils.defaultIfEmpty(_returnValue, defaultValue);
}

From source file:gdt.data.grain.Locator.java

/**
   * Convert the locator string into the Properties object.
   * @param locator$ the locator string. 
* @return the Properties object.   //from   www.j av a 2s  .  c o m
   */
public static Properties toProperties(String locator$) {
    // System.out.println("Locator:toProperties:locator="+locator$);
    if (locator$ == null) {
        //Logger.getLogger(Locator.class.getName()).severe(":toProperties:locator is null");
        return null;
    }
    Properties props = new Properties();
    String[] sa = locator$.split(NAME_DELIMITER);
    if (sa == null) {
        Logger.getLogger(Locator.class.getName()).severe(":toProperties:cannot split fields");
        return null;
    }
    String[] na;
    for (int i = 0; i < sa.length; i++) {
        try {

            na = sa[i].split(VALUE_DELIMITER);
            if (na == null || na.length < 2)
                continue;
            props.setProperty(na[0], na[1]);
        } catch (Exception e) {
            Logger.getLogger(Locator.class.getName()).severe(":toProperties:" + e.toString());
        }
    }
    if (props.isEmpty()) {
        Logger.getLogger(Locator.class.getName()).severe(":toProperties:empty");
        return null;
    }
    return props;
}

From source file:ws.salient.aws.dynamodb.DynamoDBProfilesIT.java

@Test
public void getProperties() {
    Properties properties = profiles.getProperties("test", Arrays.asList("demo"));
    assertFalse(properties.isEmpty());
}

From source file:org.openmrs.module.htmlwidgets.web.handler.PropertiesHandler.java

/** 
 * @see WidgetHandler#render(WidgetConfig)
 *///from  w w w . j  av a 2  s.  c  om
@Override
public void render(WidgetConfig config, Writer w) throws IOException {
    TextAreaWidget widget = WidgetFactory.getInstance(TextAreaWidget.class, config);
    Properties p = (Properties) config.getDefaultValue();
    if (p != null && !p.isEmpty()) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        OpenmrsUtil.storeProperties(p, baos, null);
        try {
            config.setDefaultValue(baos.toString("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("Unable to load properties from string", e);
        }
    } else {
        config.setDefaultValue(null);
    }
    widget.render(config, w);
}

From source file:org.zalando.crypto.spring.boot.EncryptedYamlPropertySourceLoader.java

@Override
public PropertySource<?> load(final String name, final Resource resource, final String profile)
        throws IOException {
    validateDecrypter();//www.  j  a  v a 2  s. co m
    if (ClassUtils.isPresent("org.yaml.snakeyaml.Yaml", null)) {
        YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
        if (profile == null) {
            factory.setMatchDefault(true);
            factory.setDocumentMatchers(new SpringProfileDocumentMatcher());
        } else {
            factory.setMatchDefault(false);
            factory.setDocumentMatchers(new SpringProfileDocumentMatcher(profile));
        }

        factory.setResources(new Resource[] { resource });

        Properties properties = factory.getObject();
        if (!properties.isEmpty()) {
            return new PropertiesPropertySource(name,
                    new EncryptableProperties(properties, decrypter, getPrefix()));
        }
    }

    return null;
}

From source file:org.zalando.crypto.spring.boot.EncryptedPropertySourceLoader.java

@Override
public PropertySource<?> load(final String name, final Resource resource, final String profile)
        throws IOException {
    validateDecrypter();//from  www .  java  2 s  .  c  o  m
    if (profile == null) {
        Properties properties = PropertiesLoaderUtils.loadProperties(resource);
        if (!properties.isEmpty()) {
            return new PropertiesPropertySource(name,
                    new EncryptableProperties(properties, decrypter, getPrefix()));
        }
    }

    return null;
}

From source file:com.thinkbiganalytics.jpa.TruncateStringUserType.java

@Override
public void setParameterValues(Properties parameters) {
    if (parameters != null && !parameters.isEmpty()) {
        final String lengthString = parameters.getProperty("length");
        try {//ww  w  . ja  va 2 s .c  o  m
            if (StringUtils.isNotBlank(lengthString)) {
                this.maxLength = Integer.parseInt(lengthString);
            }
        } catch (final NumberFormatException e) {

        }
    }
}