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:org.apache.geode.internal.util.CollectionUtilsJUnitTest.java

@Test
public void testCreateMultipleProperties() {
    Map<String, String> map = new HashMap<>(3);

    map.put("one", "A");
    map.put("two", "B");
    map.put("six", "C");

    Properties properties = CollectionUtils.createProperties(map);

    assertNotNull(properties);// w w  w  . j a v  a2s .c  o  m
    assertFalse(properties.isEmpty());
    assertEquals(map.size(), properties.size());

    for (Entry<String, String> entry : map.entrySet()) {
        assertTrue(properties.containsKey(entry.getKey()));
        assertEquals(entry.getValue(), properties.get(entry.getKey()));
    }
}

From source file:org.pentaho.platform.plugin.services.importer.LocaleImportHandler.java

private boolean isLocaleFolder(String localeFileName, Properties localePropertiesFromIndex) {
    return (localeFileName.startsWith(LOCALE_FOLDER) && localeFileName.endsWith(LOCALE_EXT))
            || (localeFileName.startsWith(LOCALE_FOLDER) && localeFileName.endsWith(OLD_LOCALE_EXT))
            || (localeFileName.equals(LOCALE_FOLDER + XML_LOCALE_EXT) && !localePropertiesFromIndex.isEmpty());
}

From source file:org.sakaiproject.util.SakaiProperties.java

/**
 * Dereferences property placeholders in the given {@link Properties}
 * in exactly the same way the {@link BeanFactoryPostProcessor}s in this
 * object perform their placeholder dereferencing. Unfortunately, this
 * process is not readily decoupled from the act of processing a
 * bean factory in the Spring libraries. Hence the reflection.
 * //w  w w  .j  av a 2s.c  om
 * @param srcProperties a collection of name-value pairs
 * @return a new collection of properties. If <code>srcProperties</code>
 *   is <code>null</code>, returns null. If <code>srcProperties</code>
 *   is empty, returns a reference to same object.
 * @throws RuntimeException if any aspect of processing fails
 */
private Properties dereferenceProperties(Properties srcProperties) throws RuntimeException {
    if (srcProperties == null) {
        return null;
    }
    if (srcProperties.isEmpty()) {
        return srcProperties;
    }
    try {
        Properties parsedProperties = new Properties();
        PropertyPlaceholderConfigurer resolver = new PropertyPlaceholderConfigurer();
        resolver.setIgnoreUnresolvablePlaceholders(true);
        Method parseStringValue = resolver.getClass().getDeclaredMethod("parseStringValue", String.class,
                Properties.class, Set.class);
        parseStringValue.setAccessible(true);
        for (Map.Entry<Object, Object> propEntry : srcProperties.entrySet()) {
            String parsedPropValue = (String) parseStringValue.invoke(resolver, (String) propEntry.getValue(),
                    srcProperties, new HashSet<Object>());
            parsedProperties.setProperty((String) propEntry.getKey(), parsedPropValue);
        }
        return parsedProperties;
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException("Failed to dereference properties", e);
    }
}

From source file:org.apache.synapse.commons.datasource.JNDIBasedDataSourceRepository.java

public void init(Properties jndiEnv) {

    initialized = true;/*from w  ww  .j  av a 2s  .c o  m*/
    if (jndiEnv == null || jndiEnv.isEmpty()) {
        if (log.isDebugEnabled()) {
            log.debug("Provided global JNDI environment properties is empty or null.");
        }
        return;
    }

    if (isValid(jndiEnv)) {
        jndiProperties = createJNDIEnvironment(jndiEnv, null);
        initialContext = createInitialContext(jndiProperties);
    }
}

From source file:org.pepstock.jem.node.StartUpSystem.java

/**
 * //from  ww w.jav  a 2 s. c  o  m
 * @param conf
 * @param substituter
 * @throws ConfigurationException
 */
private static void loadNode() throws ConfigurationException {
    // load node class, checking if they are configured.
    Node node = JEM_ENV_CONFIG.getNode();
    // load all factories for affinity factory
    // for all factories checking which have the right className. If
    // not,
    // exception occurs, otherwise it's loaded
    if (node != null && node.getClassName() != null) {
        String className = node.getClassName();
        try {
            // load by Class.forName of loader
            Object objectNode = Class.forName(className).newInstance();

            // check if it's a AffinityLoader. if not, exception occurs.
            if (objectNode instanceof NodeInfo) {
                Main.setNode((NodeInfo) objectNode);

                // gets properties defined. If not empty, substitutes
                // the value of property with variables
                Properties propsOfNode = node.getProperties();
                if (!propsOfNode.isEmpty()) {
                    // scans all properties
                    for (Enumeration<Object> e = propsOfNode.keys(); e.hasMoreElements();) {
                        // gets key and value
                        String key = e.nextElement().toString();
                        String value = propsOfNode.getProperty(key);
                        // substitutes variables if present
                        // and sets new value for the key
                        propsOfNode.setProperty(key, substituteVariable(value));
                    }
                }
                // initializes the factory with properties defined
                // and puts in the list if everything went good
                Main.getNode().init(propsOfNode);
                LogAppl.getInstance().emit(NodeMessage.JEMC090I, className);
                return;
            }
            LogAppl.getInstance().emit(NodeMessage.JEMC091E);
            throw new ConfigurationException(NodeMessage.JEMC091E.toMessage().getFormattedMessage(className));
        } catch (Exception e) {
            throw new ConfigurationException(e);
        }
        // in this case the class name is null so ignore, emitting a
        // warning
    }
    Main.setNode(new NodeInfo());
    LogAppl.getInstance().emit(NodeMessage.JEMC090I, NodeInfo.class.getName());
}

From source file:com.redhat.rcm.maven.plugin.buildmetadata.io.SdocBuilder.java

private void createMiscElement(final Element docRoot) {
    final Properties nonStandardProperties = Constant.calcNonStandardProperties(buildMetaDataProperties,
            selectedProperties);//from w  w  w .  j a v  a 2 s.co m
    if (!nonStandardProperties.isEmpty()) {
        final Element parent = document.createElement("misc");

        for (final Enumeration<Object> en = nonStandardProperties.keys(); en.hasMoreElements();) {
            final String key = String.valueOf(en.nextElement());
            createMetaDataElement(parent, key);
        }
        docRoot.appendChild(parent);
    }
}

From source file:org.apache.geode.internal.util.CollectionUtilsJUnitTest.java

@Test
public void testCreateProperties() {
    Properties properties = CollectionUtils.createProperties(Collections.singletonMap("one", "two"));

    assertNotNull(properties);/*from w  w  w .  j  av a2s.c o  m*/
    assertFalse(properties.isEmpty());
    assertTrue(properties.containsKey("one"));
    assertEquals("two", properties.getProperty("one"));
}

From source file:org.apache.ode.utils.HierarchicalProperties.java

/**
 * Clear all existing content, then read the file and parse each property. Simply logs a message and returns if the file does not exist.
 *
 * @throws IOException if the file is a Directory
 *///from w w w  .j ava  2 s . co m
public void loadFiles() throws IOException {
    // #1. clear all existing content
    clear();

    // #3. put the root map
    initRoot();

    for (File file : files) {
        Properties props = loadFile(file);
        if (!props.isEmpty())
            processProperties(props, file);
    }
    replacePlaceholders();
}

From source file:org.wso2.carbon.registry.security.vault.CipherInitializer.java

private boolean init() {

    Properties properties = SecureVaultUtil.loadProperties();// loadProperties();

    if (properties == null) {
        log.error("KeyStore configuration properties cannot be found");
        return false;
    }/*from  w  w  w. j  a va2s  . c  o  m*/

    String configurationFile = MiscellaneousUtil.getProperty(properties,
            SecureVaultConstants.PROP_SECRET_MANAGER_CONF, SecureVaultConstants.PROP_DEFAULT_CONF_LOCATION);

    Properties configurationProperties = MiscellaneousUtil.loadProperties(configurationFile);
    if (configurationProperties == null || configurationProperties.isEmpty()) {
        if (log.isDebugEnabled()) {
            log.debug("Configuration properties can not be loaded form : " + configurationFile
                    + " Will use registry properties");
        }
        configurationProperties = properties;

    }

    globalSecretProvider = MiscellaneousUtil.getProperty(configurationProperties,
            SecureVaultConstants.PROP_SECRET_PROVIDER, null);
    if (globalSecretProvider == null || "".equals(globalSecretProvider)) {
        if (log.isDebugEnabled()) {
            log.debug("No global secret provider is configured.");
        }
    }

    String repositoriesString = MiscellaneousUtil.getProperty(configurationProperties,
            SecureVaultConstants.PROP_SECRET_REPOSITORIES, null);
    if (repositoriesString == null || "".equals(repositoriesString)) {
        log.error("No secret repositories have been configured");
        return false;
    }

    String[] repositories = repositoriesString.split(",");
    if (repositories == null || repositories.length == 0) {
        log.error("No secret repositories have been configured");
        return false;
    }

    // Create a KeyStore Information for private key entry KeyStore
    IdentityKeyStoreInformation identityInformation = KeyStoreInformationFactory
            .createIdentityKeyStoreInformation(properties);

    // Create a KeyStore Information for trusted certificate KeyStore
    TrustKeyStoreInformation trustInformation = KeyStoreInformationFactory
            .createTrustKeyStoreInformation(properties);

    String identityKeyPass = null;
    String identityStorePass = null;
    String trustStorePass = null;
    if (identityInformation != null) {
        identityKeyPass = identityInformation.getKeyPasswordProvider().getResolvedSecret();
        identityStorePass = identityInformation.getKeyStorePasswordProvider().getResolvedSecret();
    }

    if (trustInformation != null) {
        trustStorePass = trustInformation.getKeyStorePasswordProvider().getResolvedSecret();
    }

    if (!validatePasswords(identityStorePass, identityKeyPass, trustStorePass)) {

        log.error("Either Identity or Trust keystore password is mandatory"
                + " in order to initialized secret manager.");
        return false;
    }

    identityKeyStoreWrapper = new IdentityKeyStoreWrapper();
    identityKeyStoreWrapper.init(identityInformation, identityKeyPass);

    trustKeyStoreWrapper = new TrustKeyStoreWrapper();
    if (trustInformation != null) {
        trustKeyStoreWrapper.init(trustInformation);
    }

    SecretRepository currentParent = null;
    for (String secretRepo : repositories) {

        StringBuffer sb = new StringBuffer();
        sb.append(SecureVaultConstants.PROP_SECRET_REPOSITORIES);
        sb.append(SecureVaultConstants.DOT);
        sb.append(secretRepo);
        String id = sb.toString();
        sb.append(SecureVaultConstants.DOT);
        sb.append(SecureVaultConstants.PROP_PROVIDER);

        String provider = MiscellaneousUtil.getProperty(configurationProperties, sb.toString(), null);
        if (provider == null || "".equals(provider)) {
            handleException("Repository provider cannot be null ");
        }

        if (log.isDebugEnabled()) {
            log.debug("Initiating a File Based Secret Repository");
        }

    }
    return true;
}

From source file:org.wso2.carbon.mediation.security.vault.CipherInitializer.java

private boolean init() {

    Properties properties = SecureVaultUtil.loadProperties();// loadProperties();

    if (properties == null) {
        log.error("KeyStore configuration properties cannot be found");
        return false;
    }//w w  w.ja  v  a2 s. c o  m

    String configurationFile = MiscellaneousUtil.getProperty(properties,
            SecureVaultConstants.PROP_SECRET_MANAGER_CONF, SecureVaultConstants.PROP_DEFAULT_CONF_LOCATION);

    Properties configurationProperties = MiscellaneousUtil.loadProperties(configurationFile);
    if (configurationProperties == null || configurationProperties.isEmpty()) {
        if (log.isDebugEnabled()) {
            log.debug("Configuration properties can not be loaded form : " + configurationFile
                    + " Will use synapse properties");
        }
        configurationProperties = properties;

    }

    globalSecretProvider = MiscellaneousUtil.getProperty(configurationProperties,
            SecureVaultConstants.PROP_SECRET_PROVIDER, null);
    if (globalSecretProvider == null || "".equals(globalSecretProvider)) {
        if (log.isDebugEnabled()) {
            log.debug("No global secret provider is configured.");
        }
    }

    String repositoriesString = MiscellaneousUtil.getProperty(configurationProperties,
            SecureVaultConstants.PROP_SECRET_REPOSITORIES, null);
    if (repositoriesString == null || "".equals(repositoriesString)) {
        log.error("No secret repositories have been configured");
        return false;
    }

    String[] repositories = repositoriesString.split(",");
    if (repositories == null || repositories.length == 0) {
        log.error("No secret repositories have been configured");
        return false;
    }

    // Create a KeyStore Information for private key entry KeyStore
    IdentityKeyStoreInformation identityInformation = KeyStoreInformationFactory
            .createIdentityKeyStoreInformation(properties);

    // Create a KeyStore Information for trusted certificate KeyStore
    TrustKeyStoreInformation trustInformation = KeyStoreInformationFactory
            .createTrustKeyStoreInformation(properties);

    String identityKeyPass = null;
    String identityStorePass = null;
    String trustStorePass = null;
    if (identityInformation != null) {
        identityKeyPass = identityInformation.getKeyPasswordProvider().getResolvedSecret();
        identityStorePass = identityInformation.getKeyStorePasswordProvider().getResolvedSecret();
    }

    if (trustInformation != null) {
        trustStorePass = trustInformation.getKeyStorePasswordProvider().getResolvedSecret();
    }

    if (!validatePasswords(identityStorePass, identityKeyPass, trustStorePass)) {

        log.error("Either Identity or Trust keystore password is mandatory"
                + " in order to initialized secret manager.");
        return false;
    }

    identityKeyStoreWrapper = new IdentityKeyStoreWrapper();
    identityKeyStoreWrapper.init(identityInformation, identityKeyPass);

    trustKeyStoreWrapper = new TrustKeyStoreWrapper();
    if (trustInformation != null) {
        trustKeyStoreWrapper.init(trustInformation);
    }

    SecretRepository currentParent = null;
    for (String secretRepo : repositories) {

        StringBuffer sb = new StringBuffer();
        sb.append(SecureVaultConstants.PROP_SECRET_REPOSITORIES);
        sb.append(SecureVaultConstants.DOT);
        sb.append(secretRepo);
        String id = sb.toString();
        sb.append(SecureVaultConstants.DOT);
        sb.append(SecureVaultConstants.PROP_PROVIDER);

        String provider = MiscellaneousUtil.getProperty(configurationProperties, sb.toString(), null);
        if (provider == null || "".equals(provider)) {
            handleException("Repository provider cannot be null ");
        }

        if (log.isDebugEnabled()) {
            log.debug("Initiating a File Based Secret Repository");
        }

    }
    return true;
}