List of usage examples for java.util Properties stringPropertyNames
public Set<String> stringPropertyNames()
From source file:org.apache.rocketmq.jms.util.MessageConverter.java
public static Message convert2RMQMessage(JmsBaseMessage jmsMsg) throws Exception { Message rocketmqMsg = new MessageExt(); // 1. Transform message body rocketmqMsg.setBody(MessageConverter.getContentFromJms(jmsMsg)); // 2. Transform topic and messageType JmsBaseTopic destination = (JmsBaseTopic) jmsMsg.getHeaders().get(JmsBaseConstant.JMS_DESTINATION); String topic = destination.getMessageTopic(); rocketmqMsg.setTopic(topic);//from w ww . ja v a 2 s . co m String messageType = destination.getMessageType(); Preconditions.checkState(!messageType.contains("||"), "'||' can not be in the destination when sending a message"); rocketmqMsg.setTags(messageType); // 3. Transform message properties Properties properties = initRocketMQHeaders(jmsMsg, topic, messageType); for (String name : properties.stringPropertyNames()) { String value = properties.getProperty(name); if (MessageConst.PROPERTY_KEYS.equals(name)) { rocketmqMsg.setKeys(value); } else if (MessageConst.PROPERTY_TAGS.equals(name)) { rocketmqMsg.setTags(value); } else if (MessageConst.PROPERTY_DELAY_TIME_LEVEL.equals(name)) { rocketmqMsg.setDelayTimeLevel(Integer.parseInt(value)); } else if (MessageConst.PROPERTY_WAIT_STORE_MSG_OK.equals(name)) { rocketmqMsg.setWaitStoreMsgOK(Boolean.parseBoolean(value)); } else if (MessageConst.PROPERTY_BUYER_ID.equals(name)) { rocketmqMsg.setBuyerId(value); } else { rocketmqMsg.putUserProperty(name, value); } } return rocketmqMsg; }
From source file:org.apache.storm.command.rebalance.java
private static HashMap<String, Integer> parseExecutor(String str) { str = org.apache.commons.lang.StringUtils.deleteWhitespace(str); HashMap<String, Integer> executor = new HashMap<String, Integer>(); String[] strs = str.split(","); Properties properties = new Properties(); try {//from w w w .ja v a2 s .c om for (String s : strs) { properties.load(new StringBufferInputStream(s)); for (final String name : properties.stringPropertyNames()) { Integer value = CoreUtil.parseInt(properties.getProperty(name)); executor.put(name, value.intValue()); } } } catch (Exception e) { System.err.println(e.getMessage()); } return executor; }
From source file:org.wisdom.maven.osgi.Instructions.java
/** * Utility method to merge instructions from {@code props2} into the {@code props1}. The instructions * from {@code props2} do not override the instructions from {@code props1} (when both contain the same * instruction), so instructions from {@code props1} stay unchanged and are contained in the file set of * instructions.// ww w .java 2s . c om * <p> * Notice that entries with empty values from {@code props2} are <strong>not</strong> merged. * * @param props1 the first set of instructions * @param props2 the second set of instructions * @return the new set of instructions containing the instructions from {@code props2} merged into {@code props1}. */ public static Properties mergeAndSkipExisting(Properties props1, Properties props2) { Properties properties = new Properties(); properties.putAll(props1); for (String key : props2.stringPropertyNames()) { if (!props1.containsKey(key) && !Strings.isNullOrEmpty(props2.getProperty(key))) { properties.put(key, props2.getProperty(key)); } } return properties; }
From source file:nl.armatiek.xslweb.utils.XSLWebUtils.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public static Map<QName, XdmValue> getStylesheetParameters(WebApp webApp, HttpServletRequest req, HttpServletResponse resp, File homeDir) throws Exception { Map<QName, XdmValue> params = new HashMap<QName, XdmValue>(); /* Property parameters : */ Properties props = Context.getInstance().getProperties(); for (String key : props.stringPropertyNames()) { String value = props.getProperty(key); params.put(new QName(Definitions.NAMESPACEURI_XSLWEB_CONFIGURATION, key), new XdmAtomicValue(value)); }//from ww w . java2 s . c o m params.put(new QName(Definitions.NAMESPACEURI_XSLWEB_CONFIGURATION, "home-dir"), new XdmAtomicValue(homeDir.getAbsolutePath())); params.put(new QName(Definitions.NAMESPACEURI_XSLWEB_CONFIGURATION, "webapp-dir"), new XdmAtomicValue(webApp.getHomeDir().getAbsolutePath())); params.put(new QName(Definitions.NAMESPACEURI_XSLWEB_CONFIGURATION, "webapp-path"), new XdmAtomicValue(webApp.getPath())); params.put(new QName(Definitions.NAMESPACEURI_XSLWEB_CONFIGURATION, "development-mode"), new XdmAtomicValue(webApp.getDevelopmentMode())); /* Object parameters: */ params.put(new QName(Definitions.NAMESPACEURI_XSLWEB_REQUEST, "request"), XdmValue.wrap(new ObjectValue(req))); params.put(new QName(Definitions.NAMESPACEURI_XSLWEB_RESPONSE, "response"), XdmValue.wrap(new ObjectValue(resp))); params.put(new QName(Definitions.NAMESPACEURI_XSLWEB_WEBAPP, "webapp"), XdmValue.wrap(new ObjectValue(webApp))); /* Webapp parameters: */ addStylesheetParameters(params, webApp.getParameters()); return params; }
From source file:de.tudarmstadt.ukp.dkpro.core.api.lexmorph.TagsetMappingFactory.java
public static Map<String, String> loadProperties(URL aUrl) { InputStream is = null;/*from www .java2 s .com*/ try { is = aUrl.openStream(); Properties mappingProperties = new Properties(); mappingProperties.load(is); Map<String, String> mapping = new HashMap<String, String>(); for (String key : mappingProperties.stringPropertyNames()) { mapping.put(key.trim(), mappingProperties.getProperty(key).trim()); } return mapping; } catch (IOException e) { throw new RuntimeException(e); } finally { closeQuietly(is); } }
From source file:cl.niclabs.tscrypto.common.utils.Util.java
public static void trimProperties(Properties props) { for (String name : props.stringPropertyNames()) { props.setProperty(name, props.getProperty(name).trim()); }/* w w w. ja va 2s . c o m*/ }
From source file:com.linkedin.whiteelephant.mapreduce.lib.job.StagedOutputJob.java
public static Configuration createConfigurationFromProps(Properties props) { final Configuration config = new Configuration(); for (String key : props.stringPropertyNames()) { String newKey = key;// ww w .ja v a 2 s. c o m String value = props.getProperty(key); if (key.toLowerCase().startsWith(HADOOP_PREFIX)) { newKey = key.substring(HADOOP_PREFIX.length()); config.set(newKey, value); } } return config; }
From source file:org.apache.sqoop.submission.spark.SqoopSparkClientFactory.java
public static Map<String, String> prepareSparkConfMapFromSqoopConfig(SqoopConf sqoopConf) { Map<String, String> sparkConf = new HashMap<String, String>(); // set default spark configurations. sparkConf.put(Constants.SPARK_MASTER, SPARK_DEFAULT_MASTER); sparkConf.put(Constants.SPARK_APP_NAME, SPARK_DEFAULT_APP_NAME); sparkConf.put(Constants.SPARK_SERIALIZER, SPARK_DEFAULT_SERIALIZER); for (Map.Entry<String, String> p : sqoopConf.getProps().entrySet()) { LOG.info("sqoop spark properties from: " + p.getKey() + ": " + p.getValue()); }/*w ww . java 2 s .co m*/ // load properties from spark-defaults.conf. InputStream inputStream = null; try { inputStream = SqoopSparkClientFactory.class.getClassLoader() .getResourceAsStream(SPARK_DEFAULT_CONF_FILE); if (inputStream != null) { LOG.info("Loading spark properties from:" + SPARK_DEFAULT_CONF_FILE); Properties properties = new Properties(); properties.load(new InputStreamReader(inputStream, CharsetNames.UTF_8)); for (String propertyName : properties.stringPropertyNames()) { if (propertyName.startsWith("spark")) { String value = properties.getProperty(propertyName); sparkConf.put(propertyName, properties.getProperty(propertyName)); LOG.info(String.format("Load spark property from %s (%s -> %s).", SPARK_DEFAULT_CONF_FILE, propertyName, value)); } } } } catch (IOException e) { LOG.info("Failed to open spark configuration file:" + SPARK_DEFAULT_CONF_FILE, e); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { LOG.debug("Failed to close inputstream.", e); } } } return sparkConf; }
From source file:adalid.util.i18n.Merger.java
private static Properties merge(File bundle, Properties baseProperties, Properties localeProperties) { Properties properties = new SortedProperties(); Set<String> baseNames = baseProperties.stringPropertyNames(); Set<String> localeNames = localeProperties.stringPropertyNames(); String baseValue, localeValue, newValue; int newProperties = 0; int oldProperties = 0; int translationRequired = 0; for (String name : baseNames) { if (localeNames.contains(name)) { } else {//from w w w. jav a2s.c om newProperties++; } baseValue = baseProperties.getProperty(name); localeValue = localeProperties.getProperty(name); boolean noTranslationRequired = noTranslationRequired(baseValue); if (noTranslationRequired || isNotTranslated(localeValue)) { if (noTranslationRequired) { newValue = baseValue; } else { newValue = TRAN_REQD + baseValue; translationRequired++; } properties.setProperty(name, newValue); } else { properties.setProperty(name, localeValue); } } for (String name : localeNames) { if (baseNames.contains(name)) { } else { oldProperties++; } } if (newProperties > 0) { logger.warn(NEW_VALUE + " " + bundle.getName() + " = " + newProperties); } if (oldProperties > 0) { logger.warn(OLD_VALUE + " " + bundle.getName() + " = " + oldProperties); } if (translationRequired > 0) { logger.warn(TRAN_REQD + " " + bundle.getName() + " = " + translationRequired); } return properties; }
From source file:org.bonitasoft.engine.util.APITypeManager.java
private static Map<String, String> getProperties() throws IOException { Map<String, String> properties = getPropertiesFromSystemProperties(); Properties propertiesFromBonitaHome = getPropertiesFromBonitaHome(); for (String property : propertiesFromBonitaHome.stringPropertyNames()) { if (!properties.containsKey(property)) { properties.put(property, propertiesFromBonitaHome.getProperty(property)); }//from w w w .j a v a 2 s . c om } return properties; }