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.springframework.batch.core.jsr.configuration.support.BatchPropertyBeanPostProcessor.java

@Override
public Object postProcessBeforeInitialization(final Object bean, String beanName) throws BeansException {
    if (!isBatchArtifact(bean)) {
        return bean;
    }//from   ww  w. jav a 2s.c  o m

    String beanPropertyName = getBeanPropertyName(beanName);

    final Properties artifactProperties = batchPropertyContext.getBatchProperties(beanPropertyName);

    if (artifactProperties.isEmpty()) {
        return bean;
    }

    injectBatchProperties(bean, artifactProperties);

    return bean;
}

From source file:org.mule.transport.email.transformers.StringToEmailMessage.java

@Override
public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException {
    String endpointAddress = endpoint.getEndpointURI().getAddress();
    SmtpConnector connector = (SmtpConnector) endpoint.getConnector();
    String to = lookupProperty(message, MailProperties.TO_ADDRESSES_PROPERTY, endpointAddress);
    String cc = lookupProperty(message, MailProperties.CC_ADDRESSES_PROPERTY, connector.getCcAddresses());
    String bcc = lookupProperty(message, MailProperties.BCC_ADDRESSES_PROPERTY, connector.getBccAddresses());
    String from = lookupProperty(message, MailProperties.FROM_ADDRESS_PROPERTY, connector.getFromAddress());
    String replyTo = lookupProperty(message, MailProperties.REPLY_TO_ADDRESSES_PROPERTY,
            connector.getReplyToAddresses());
    String subject = lookupProperty(message, MailProperties.SUBJECT_PROPERTY, connector.getSubject());
    String contentType = lookupProperty(message, MailProperties.CONTENT_TYPE_PROPERTY,
            connector.getContentType());

    Properties headers = new Properties();
    Properties customHeaders = connector.getCustomHeaders();

    if (customHeaders != null && !customHeaders.isEmpty()) {
        headers.putAll(customHeaders);// ww w .j  a va2  s  .  c o m
    }

    Properties otherHeaders = message.getOutboundProperty(MailProperties.CUSTOM_HEADERS_MAP_PROPERTY);
    if (otherHeaders != null && !otherHeaders.isEmpty()) {
        //TODO Whats going on here?
        //                final MuleContext mc = context.getMuleContext();
        //                for (Iterator iterator = message.getPropertyNames().iterator(); iterator.hasNext();)
        //                {
        //                    String propertyKey = (String) iterator.next();
        //                    mc.getRegistry().registerObject(propertyKey, message.getProperty(propertyKey), mc);
        //                }
        headers.putAll(templateParser.parse(new TemplateParser.TemplateCallback() {
            public Object match(String token) {
                return muleContext.getRegistry().lookupObject(token);
            }
        }, otherHeaders));

    }

    if (logger.isDebugEnabled()) {
        StringBuffer buf = new StringBuffer();
        buf.append("Constructing email using:\n");
        buf.append("To: ").append(to);
        buf.append(", From: ").append(from);
        buf.append(", CC: ").append(cc);
        buf.append(", BCC: ").append(bcc);
        buf.append(", Subject: ").append(subject);
        buf.append(", ReplyTo: ").append(replyTo);
        buf.append(", Content type: ").append(contentType);
        buf.append(", Payload type: ").append(message.getPayload().getClass().getName());
        buf.append(", Custom Headers: ").append(MapUtils.toString(headers, false));
        logger.debug(buf.toString());
    }

    try {
        MimeMessage email = new MimeMessage(
                ((SmtpConnector) endpoint.getConnector()).getSessionDetails(endpoint).getSession());

        email.setRecipients(Message.RecipientType.TO, MailUtils.stringToInternetAddresses(to));

        // sent date
        email.setSentDate(Calendar.getInstance().getTime());

        if (StringUtils.isNotBlank(from)) {
            email.setFrom(MailUtils.stringToInternetAddresses(from)[0]);
        }

        if (StringUtils.isNotBlank(cc)) {
            email.setRecipients(Message.RecipientType.CC, MailUtils.stringToInternetAddresses(cc));
        }

        if (StringUtils.isNotBlank(bcc)) {
            email.setRecipients(Message.RecipientType.BCC, MailUtils.stringToInternetAddresses(bcc));
        }

        if (StringUtils.isNotBlank(replyTo)) {
            email.setReplyTo(MailUtils.stringToInternetAddresses(replyTo));
        }

        email.setSubject(subject, outputEncoding);

        for (Iterator iterator = headers.entrySet().iterator(); iterator.hasNext();) {
            Map.Entry entry = (Map.Entry) iterator.next();
            email.setHeader(entry.getKey().toString(), entry.getValue().toString());
        }

        setContent(message.getPayload(), email, contentType, message);

        return email;
    } catch (Exception e) {
        throw new TransformerException(this, e);
    }
}

From source file:org.apache.synapse.securevault.secret.repository.FileBaseSecretRepository.java

/**
 * Initializes the repository based on provided properties
 *
 * @param properties Configuration properties
 * @param id         Identifier to identify properties related to the corresponding repository
 *//*from   w w  w .j  av  a2s .c  o  m*/
public void init(Properties properties, String id) {
    StringBuffer sb = new StringBuffer();
    sb.append(id);
    sb.append(DOT);
    sb.append(LOCATION);

    String filePath = MiscellaneousUtil.getProperty(properties, sb.toString(), DEFAULT_CONF_LOCATION);

    Properties cipherProperties = MiscellaneousUtil.loadProperties(filePath);
    if (cipherProperties.isEmpty()) {
        if (log.isDebugEnabled()) {
            log.debug("Cipher texts cannot be loaded form : " + filePath);
        }
        return;
    }

    StringBuffer sbTwo = new StringBuffer();
    sbTwo.append(id);
    sbTwo.append(DOT);
    sbTwo.append(ALGORITHM);
    //Load algorithm
    String algorithm = MiscellaneousUtil.getProperty(properties, sbTwo.toString(), DEFAULT_ALGORITHM);
    StringBuffer buffer = new StringBuffer();
    buffer.append(DOT);
    buffer.append(KEY_STORE);

    //Load keyStore
    String keyStore = MiscellaneousUtil.getProperty(properties, buffer.toString(), null);
    KeyStoreWrapper keyStoreWrapper;
    if (TRUSTED.equals(keyStore)) {
        keyStoreWrapper = trust;

    } else {
        keyStoreWrapper = identity;
    }

    //Creates a cipherInformation

    CipherInformation cipherInformation = new CipherInformation();
    cipherInformation.setAlgorithm(algorithm);
    cipherInformation.setCipherOperationMode(CipherOperationMode.DECRYPT);
    cipherInformation.setInType(EncodingType.BASE64); //TODO
    DecryptionProvider baseCipher = CipherFactory.createCipher(cipherInformation, keyStoreWrapper);

    for (Object alias : cipherProperties.keySet()) {
        //decrypt the encrypted text 
        String key = String.valueOf(alias);
        String encryptedText = cipherProperties.getProperty(key);
        encryptedData.put(key, encryptedText);
        if (encryptedText == null || "".equals(encryptedText.trim())) {
            if (log.isDebugEnabled()) {
                log.debug("There is no secret for the alias : " + alias);
            }
            continue;
        }

        String decryptedText = new String(baseCipher.decrypt(encryptedText.trim().getBytes()));
        secrets.put(key, decryptedText);
    }
    initialize = true;
}

From source file:org.jahia.modules.ugp.showcase.DbUserProvider.java

private Criteria filterQuery(Criteria query, Properties searchCriteria) {
    if (searchCriteria == null || searchCriteria.isEmpty()) {
        return query;
    }//from w w  w .j ava 2s .co  m

    String v = StringUtils.defaultIfBlank(searchCriteria.getProperty("username"),
            searchCriteria.getProperty("*"));
    if (StringUtils.isNotEmpty(v) && !"*".equals(v)) {
        query.add(Restrictions.ilike("username", StringUtils.replace(v, "*", "%")));
    }

    List<Criterion> propsFilters = new LinkedList<>();
    Criteria propsQuery = addPropertyCriteria("j:firstName", query, searchCriteria, null, propsFilters);
    propsQuery = addPropertyCriteria("j:firstName", query, searchCriteria, propsQuery, propsFilters);
    propsQuery = addPropertyCriteria("j:lastName", query, searchCriteria, propsQuery, propsFilters);
    propsQuery = addPropertyCriteria("j:email", query, searchCriteria, propsQuery, propsFilters);

    if (propsQuery != null && !propsFilters.isEmpty()) {
        propsQuery.add(Restrictions.or(propsFilters.toArray(new Criterion[] {})));
    }

    return propsQuery != null ? propsQuery : query;
}

From source file:edu.cornell.med.icb.geo.TestIndexedIdentifier.java

/**
 * Validates that an empty {@link edu.cornell.med.icb.identifier.IndexedIdentifier} object
 * is transformed to properties properly.
 *//*from  w ww  .  j  a  va  2 s.c  o  m*/
@Test
public void emptyObject() {
    final IndexedIdentifier indexedIdentifier = new IndexedIdentifier();
    assertTrue("Initial state should be empty", indexedIdentifier.isEmpty());
    assertEquals("Initial state should have no elements", 0, indexedIdentifier.size());
    assertEquals("Default value", -1, indexedIdentifier.defaultReturnValue());

    final Map<String, Properties> propertyMap = indexedIdentifier.toPropertyMap();
    assertNotNull("Property map should never be null", propertyMap);
    assertFalse("Property map should never be empty", propertyMap.isEmpty());
    assertEquals("Property map should have 2 keys", 2, propertyMap.size());

    final Properties id2IndexProperties = propertyMap.get("id2Index");
    assertNotNull("id2Index map should never be null", id2IndexProperties);
    assertTrue("id2Index map should be empty", id2IndexProperties.isEmpty());
    assertEquals("id2Index map should have no elements", 0, id2IndexProperties.size());

    final Properties runningIndexProperties = propertyMap.get("runningIndex");
    assertNotNull("runningIndex map should never be null", runningIndexProperties);
    assertFalse("runningIndex map should not be empty", runningIndexProperties.isEmpty());
    assertEquals("runningIndex map should have one element", 1, runningIndexProperties.size());

    final String runningIndexProperty = runningIndexProperties.getProperty("runningIndex");
    assertNotNull("runningIndex must not be null", runningIndexProperty);
    assertTrue("runningIndex must not be blank", StringUtils.isNotBlank(runningIndexProperty));
    assertEquals("runningIndex should be zero", 0, Integer.parseInt(runningIndexProperty));
}

From source file:org.springframework.cloud.config.server.environment.VaultEnvironmentRepository.java

@Override
public Environment findOne(String application, String profile, String label) {

    String state = request.getHeader(STATE_HEADER);
    String newState = this.watch.watch(state);

    String[] profiles = StringUtils.commaDelimitedListToStringArray(profile);
    List<String> scrubbedProfiles = scrubProfiles(profiles);

    List<String> keys = findKeys(application, scrubbedProfiles);

    Environment environment = new Environment(application, profiles, label, null, newState);

    for (String key : keys) {
        // read raw 'data' key from vault
        String data = read(key);// w ww.  ja v  a 2 s  .c  o m
        if (data != null) {
            // data is in json format of which, yaml is a superset, so parse
            final YamlPropertiesFactoryBean yaml = new YamlPropertiesFactoryBean();
            yaml.setResources(new ByteArrayResource(data.getBytes()));
            Properties properties = yaml.getObject();

            if (!properties.isEmpty()) {
                environment.add(new PropertySource("vault:" + key, properties));
            }
        }
    }

    return environment;
}

From source file:org.wisdom.maven.utils.Properties2HoconConverterTest.java

@Test
public void testOnWikipediaSampleUsingRawProperties() throws IOException {
    File props = new File(root, "/wiki.properties");
    File hocon = Properties2HoconConverter.convert(props, true);

    Properties properties = loadProperties(props);

    Config config = load(hocon);/*from   w  w w  .j a  v a 2 s.c  om*/
    assertThat(properties.isEmpty()).isFalse();
    assertThat(config.isEmpty()).isFalse();

    for (String name : properties.stringPropertyNames()) {
        // Ignored properties are they are not supported in the 'regular' raw format.
        if (name.equalsIgnoreCase("targetCities") || name.equalsIgnoreCase("Los")) {
            continue;
        }
        String o = (String) properties.get(name);
        String v = config.getString(name);
        assertThat(o).isEqualTo(v);
    }

}

From source file:org.mule.util.PropertiesUtilsTestCase.java

@Test
public void testLoadAllPropertiesEmptyFile() {
    Properties properties = PropertiesUtils.loadAllProperties(
            "META-INF/services/org/mule/config/mule-empty.properties", this.getClass().getClassLoader());
    assertThat(properties, IsNull.notNullValue());
    assertThat(properties.isEmpty(), is(true));
}

From source file:edu.cornell.med.icb.geo.TestIndexedIdentifier.java

/**
 * Validates that a populated {@link edu.cornell.med.icb.identifier.IndexedIdentifier} object
 * is transformed to properties properly.
 *///from  w ww . j a  v  a 2  s .  c  o m
@Test
public void toPropertyMap() {
    final IndexedIdentifier indexedIdentifier = new IndexedIdentifier();
    indexedIdentifier.registerIdentifier(new MutableString("one"));
    indexedIdentifier.registerIdentifier(new MutableString("two"));
    indexedIdentifier.registerIdentifier(new MutableString("three"));

    assertFalse("State should not be empty", indexedIdentifier.isEmpty());
    assertEquals("State should have 3 elements", 3, indexedIdentifier.size());
    assertEquals("Default value", -1, indexedIdentifier.defaultReturnValue());

    final Map<String, Properties> propertyMap = indexedIdentifier.toPropertyMap();
    assertNotNull("Property map should never be null", propertyMap);
    assertFalse("Property map should never be empty", propertyMap.isEmpty());
    assertEquals("Property map should have 2 keys", 2, propertyMap.size());

    final Properties id2IndexProperties = propertyMap.get("id2Index");
    assertNotNull("id2Index map should never be null", id2IndexProperties);
    assertFalse("id2Index map should not be empty", id2IndexProperties.isEmpty());
    assertEquals("id2Index map should have three elements", 3, id2IndexProperties.size());

    assertEquals("Element one", "0", id2IndexProperties.getProperty("one"));
    assertEquals("Element two", "1", id2IndexProperties.getProperty("two"));
    assertEquals("Element three", "2", id2IndexProperties.getProperty("three"));

    final Properties runningIndexProperties = propertyMap.get("runningIndex");
    assertNotNull("runningIndex map should never be null", runningIndexProperties);
    assertFalse("runningIndex map should not be empty", runningIndexProperties.isEmpty());
    assertEquals("runningIndex map should have one element", 1, runningIndexProperties.size());

    final String runningIndexProperty = runningIndexProperties.getProperty("runningIndex");
    assertNotNull("runningIndex must not be null", runningIndexProperty);
    assertTrue("runningIndex must not be blank", StringUtils.isNotBlank(runningIndexProperty));
    assertEquals("runningIndex should be three", 3, Integer.parseInt(runningIndexProperty));
}

From source file:org.wso2.carbon.mdm.mobileservices.windows.common.authenticator.OAuthTokenValidationStubFactory.java

/**
 * Creates an instance of MultiThreadedHttpConnectionManager using HttpClient 3.x APIs
 *
 * @param properties Properties to configure MultiThreadedHttpConnectionManager
 * @return An instance of properly configured MultiThreadedHttpConnectionManager
 *///from w w w.ja va  2 s .  c o m
private HttpConnectionManager createConnectionManager(Properties properties) {
    HttpConnectionManagerParams params = new HttpConnectionManagerParams();
    if (properties == null || properties.isEmpty()) {
        throw new IllegalArgumentException("Parameters required to initialize HttpClient instances "
                + "associated with OAuth token validation service stub are not provided");
    }
    String maxConnectionsPerHostParam = properties
            .getProperty(PluginConstants.AuthenticatorProperties.MAX_CONNECTION_PER_HOST);
    if (maxConnectionsPerHostParam == null || maxConnectionsPerHostParam.isEmpty()) {
        if (log.isDebugEnabled()) {
            log.debug("MaxConnectionsPerHost parameter is not explicitly defined. Therefore, the default, "
                    + "which is 2, will be used");
        }
    } else {
        params.setDefaultMaxConnectionsPerHost(Integer.parseInt(maxConnectionsPerHostParam));
    }

    String maxTotalConnectionsParam = properties
            .getProperty(PluginConstants.AuthenticatorProperties.MAX_TOTAL_CONNECTIONS);
    if (maxTotalConnectionsParam == null || maxTotalConnectionsParam.isEmpty()) {
        if (log.isDebugEnabled()) {
            log.debug("MaxTotalConnections parameter is not explicitly defined. Therefore, the default, "
                    + "which is 10, will be used");
        }
    } else {
        params.setMaxTotalConnections(Integer.parseInt(maxTotalConnectionsParam));
    }
    HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    connectionManager.setParams(params);
    return connectionManager;
}