Example usage for java.util Properties stringPropertyNames

List of usage examples for java.util Properties stringPropertyNames

Introduction

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

Prototype

public Set<String> stringPropertyNames() 

Source Link

Document

Returns an unmodifiable set of keys from this property list where the key and its corresponding value are strings, including distinct keys in the default property list if a key of the same name has not already been found from the main properties list.

Usage

From source file:io.dataapps.chlorine.mask.Redactor.java

private static Map<String, String> readReplacements(String configurationFileName) {
    Properties properties = new Properties();
    Map<String, String> map = new HashMap<>();
    try (final InputStream stream = MaskFactory.class.getClassLoader()
            .getResourceAsStream(configurationFileName)) {
        properties.load(stream);/*from   w  ww.j  a  va2  s.  co m*/
        for (final String name : properties.stringPropertyNames()) {
            map.put(name, properties.getProperty(name));
        }
    } catch (IOException e) {
        LOG.error(e);
    }
    return map;
}

From source file:org.wso2.carbon.device.mgt.mobile.android.impl.util.MobileDeviceManagementUtil.java

public static MobileOperation convertToMobileOperation(Operation operation) {
    MobileOperation mobileOperation = new MobileOperation();
    MobileOperationProperty operationProperty;
    List<MobileOperationProperty> properties = new LinkedList<MobileOperationProperty>();
    mobileOperation.setFeatureCode(operation.getCode());
    mobileOperation.setCreatedDate(new Date().getTime());
    Properties operationProperties = operation.getProperties();
    for (String key : operationProperties.stringPropertyNames()) {
        operationProperty = new MobileOperationProperty();
        operationProperty.setProperty(key);
        operationProperty.setValue(operationProperties.getProperty(key));
        properties.add(operationProperty);
    }//from w  w w .j a  v  a  2s.  c  om
    mobileOperation.setProperties(properties);
    return mobileOperation;
}

From source file:org.apache.beam.runners.apex.ApexYarnLauncher.java

/**
 * Transfer the properties to the configuration object.
 *//*from w ww .  j a  v a2s  . c  o  m*/
public static void addProperties(Configuration conf, Properties props) {
    for (final String propertyName : props.stringPropertyNames()) {
        String propertyValue = props.getProperty(propertyName);
        conf.set(propertyName, propertyValue);
    }
}

From source file:adalid.util.google.Translator.java

public static Properties translate(Properties properties) {
    if (properties == null || properties.isEmpty()) {
        return properties;
    }/*from   www  .ja  va 2  s .  c o  m*/
    String arg, translation;
    URIBuilder builder = newURIBuilder();
    try (CloseableHttpClient client = HttpClients.createDefault()) {
        Set<String> names = properties.stringPropertyNames();
        for (String name : names) {
            arg = properties.getProperty(name);
            logger.info(arg);
            translation = translate(arg, builder, client);
            logger.info(translation);
            if (translation != null) {
                properties.setProperty(name, translation);
            }
        }
    } catch (IOException | URISyntaxException ex) {
        logger.fatal(ex);
    }
    return properties;
}

From source file:org.apache.crunch.kafka.inputformat.KafkaInputFormat.java

/**
 * Writes the Kafka connection properties to the {@code bundle}.
 *
 * @param connectionProperties the Kafka connection properties
 * @param bundle the bundle into which the information should be persisted.
 *//*  w  ww  .j a v  a  2  s .co m*/
public static void writeConnectionPropertiesToBundle(Properties connectionProperties, FormatBundle bundle) {
    for (final String name : connectionProperties.stringPropertyNames()) {
        bundle.set(name, connectionProperties.getProperty(name));
    }
}

From source file:org.apache.rocketmq.jms.support.MessageConverter.java

public static Message convert2RMQMessage(RocketMQMessage jmsMsg) throws Exception {
    Message rmqMsg = new MessageExt();

    rmqMsg.setKeys(System.currentTimeMillis() + "" + counter.incrementAndGet());

    // 1. Transform message body
    rmqMsg.setBody(MessageConverter.getContentFromJms(jmsMsg).getContent());

    // 2. Transform topic and messageType
    String topic, tag;/* w w  w . j  a v a 2s.c o  m*/
    Destination destination = (Destination) jmsMsg.getHeaders().get(Constant.JMS_DESTINATION);
    if (destination instanceof Topic) {
        topic = ((RocketMQTopic) destination).getTopicName();
        tag = ((RocketMQTopic) destination).getTypeName();
    } else {
        topic = ((RocketMQQueue) destination).getQueueName();
        tag = NO_MESSAGE_SELECTOR;
    }
    checkState(!tag.contains("||"), "'||' can not be in the destination when sending a message");
    rmqMsg.setTopic(topic);
    rmqMsg.setTags(tag);

    // 3. Transform message properties
    Properties properties = getAllProperties(jmsMsg, topic, tag);
    for (String name : properties.stringPropertyNames()) {
        String value = properties.getProperty(name);
        if (MessageConst.PROPERTY_KEYS.equals(name)) {
            rmqMsg.setKeys(value);
        } else if (MessageConst.PROPERTY_TAGS.equals(name)) {
            rmqMsg.setTags(value);
        } else if (MessageConst.PROPERTY_DELAY_TIME_LEVEL.equals(name)) {
            rmqMsg.setDelayTimeLevel(Integer.parseInt(value));
        } else if (MessageConst.PROPERTY_WAIT_STORE_MSG_OK.equals(name)) {
            rmqMsg.setWaitStoreMsgOK(Boolean.parseBoolean(value));
        } else if (MessageConst.PROPERTY_BUYER_ID.equals(name)) {
            rmqMsg.setBuyerId(value);
        } else {
            rmqMsg.putUserProperty(name, value);
        }
    }

    return rmqMsg;
}

From source file:org.wso2.carbon.email.mgt.config.EmailConfigTransformer.java

public static EmailTemplateDTO[] transform(Properties props) throws I18nMgtEmailConfigException {

    List<EmailTemplateDTO> emailTemplates = new ArrayList<EmailTemplateDTO>();

    if (log.isDebugEnabled()) {
        log.debug("Transforming Properties to EmailTemplateDTO[]");
    }/*from  ww  w  . j av  a  2 s .  c om*/

    Set<String> keySet = props.stringPropertyNames();
    String emailTemplateLanguage;
    String emailTemplateDisplayType;
    String emailContentType;

    for (String key : keySet) {
        EmailTemplateDTO template = new EmailTemplateDTO();
        String[] emailTemplateKeyArray = key.split("\\|");
        template.setName(emailTemplateKeyArray[0]);
        emailTemplateDisplayType = emailTemplateKeyArray[1];
        emailContentType = emailTemplateKeyArray[2];

        // Retrieves the content of each email template.
        String[] emailTemplateContent = props.getProperty(key).split("\\|");
        if (emailTemplateContent.length > 3) {
            throw new I18nMgtEmailConfigException("Cannot have | character in the template");
        }

        String[] emailTypeKeyArray = emailTemplateKeyArray[0].split("\\.");
        String[] emailLocalCodeArray = emailTypeKeyArray[1].split("_");
        Locale localeObject = new Locale(emailLocalCodeArray[0], emailLocalCodeArray[1]);

        emailTemplateLanguage = localeObject.getDisplayName();
        String subject = emailTemplateContent[0];
        String body = emailTemplateContent[1];
        String footer = emailTemplateContent[2];

        if (log.isDebugEnabled()) {
            log.debug("Template info - name: " + key + " locale: " + emailTemplateLanguage + " subject: "
                    + subject + " body: " + body + " footer: " + footer + " displayName:"
                    + emailTemplateDisplayType);
        }

        template.setLocale(emailTemplateLanguage);
        template.setSubject(subject);
        template.setBody(body);
        template.setFooter(footer);
        template.setDisplayName(emailTemplateDisplayType);
        template.setEmailContentType(emailContentType);

        emailTemplates.add(template);
    }

    return emailTemplates.toArray(new EmailTemplateDTO[emailTemplates.size()]);
}

From source file:org.ofbiz.core.entity.transaction.DBCPConnectionFactory.java

private static Properties loadDbcpProperties() {
    Properties dbcpProperties = new Properties();

    // load everything in c3p0.properties
    InputStream fileProperties = DBCPConnectionFactory.class.getResourceAsStream("/" + DBCP_PROPERTIES);
    if (fileProperties != null) {
        try {//from   w ww  . j  a  v  a 2  s .c  om
            dbcpProperties.load(fileProperties);
        } catch (IOException e) {
            log.error("Error loading " + DBCP_PROPERTIES, e);
        }
    }

    // also look at all dbcp.* system properties
    Properties systemProperties = System.getProperties();
    for (String systemProp : systemProperties.stringPropertyNames()) {
        final String prefix = "dbcp.";
        if (systemProp.startsWith(prefix)) {
            dbcpProperties.setProperty(systemProp.substring(prefix.length()), System.getProperty(systemProp));
        }
    }

    return dbcpProperties;
}

From source file:org.ofbiz.core.entity.transaction.DBCPConnectionFactory.java

private static String toString(Properties properties) {
    List<String> props = new ArrayList<String>();
    for (String key : properties.stringPropertyNames()) {
        props.add(key + "=" + properties.getProperty(key));
    }//from   w  w w. ja va2  s  . c o  m

    return Joiner.on(';').skipNulls().join(props);
}

From source file:org.wso2.carbon.identity.mgt.config.EmailConfigTransformer.java

public static EmailTemplateDTO[] transform(Properties props) throws IdentityException {

    List<EmailTemplateDTO> emailTemplates = new ArrayList<EmailTemplateDTO>();

    if (log.isDebugEnabled()) {
        log.debug("Transforming Properties to EmailTemplateDTO[]");
    }/* www .java 2 s.c  o  m*/

    Set<String> keySet = props.stringPropertyNames();
    for (String key : keySet) {

        EmailTemplateDTO template = new EmailTemplateDTO();

        if (IdentityMgtConstants.Notification.PASSWORD_RESET_RECOVERY.equals(key)) {
            template.setDisplayName("Password Reset");
        } else if (IdentityMgtConstants.Notification.ACCOUNT_CONFORM.equals(key)) {
            template.setDisplayName("Account Confirm");
        } else if (IdentityMgtConstants.Notification.ACCOUNT_ID_RECOVERY.equals(key)) {
            template.setDisplayName("Account Id Recovery");
        } else if (IdentityMgtConstants.Notification.ACCOUNT_UNLOCK.equals(key)) {
            template.setDisplayName("Account Unlock");
        } else if (IdentityMgtConstants.Notification.ASK_PASSWORD.equals(key)) {
            template.setDisplayName("Ask Password");
        } else if (IdentityMgtConstants.Notification.OTP_PASSWORD.equals(key)) {
            template.setDisplayName("One Time Password");
        } else if (IdentityMgtConstants.Notification.TEMPORARY_PASSWORD.equals(key)) {
            template.setDisplayName("Temporary Password");
        } else {
            // Ignore all other keys in the registry mount.
            continue;
        }

        template.setName(key);

        String[] contents = props.getProperty(key).split("\\|");

        if (contents.length > 3) {
            throw new IdentityException("Cannot have | character in the template");
        }

        String subject = contents[0];
        String body = contents[1];
        String footer = contents[2];

        if (log.isDebugEnabled()) {
            log.debug("Template info - name:" + key + " subject:" + subject + " " + "body:" + body + " footer:"
                    + footer);
        }

        template.setSubject(subject);
        template.setBody(body);
        template.setFooter(footer);

        emailTemplates.add(template);
    }

    return emailTemplates.toArray(new EmailTemplateDTO[emailTemplates.size()]);
}