Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
update DomainListener ,if value isNullOrEmpty, will set contextPath
Browse files Browse the repository at this point in the history
  • Loading branch information
venusdrogon committed Apr 20, 2015
1 parent c0e1fe8 commit 3bb5352
Showing 1 changed file with 14 additions and 5 deletions.
Expand Up @@ -111,7 +111,7 @@ public void contextInitialized(ServletContextEvent servletContextEvent){
private void initDomain(ServletContext servletContext){
String domainConfigLocation = getDomainConfigLocation(servletContext);
Properties properties = loadDomainProperties(servletContext, domainConfigLocation);
Map<String, DomainConfig> domainConfigMap = propertiesToMap(properties);
Map<String, DomainConfig> domainConfigMap = propertiesToMap(servletContext, properties);

setServletContextAttribute(servletContext, domainConfigMap);

Expand Down Expand Up @@ -177,32 +177,41 @@ private void setServletContextAttribute(ServletContext servletContext,Map<String
/**
* Properties to map 将全部的配置转成map key就是properties中的key.
*
* @param servletContext
* the servlet context
* @param properties
* the properties
* @return the map< string, domain config>
* @since 1.0.9
*/
private Map<String, DomainConfig> propertiesToMap(Properties properties){
private Map<String, DomainConfig> propertiesToMap(ServletContext servletContext,Properties properties){
Map<String, String> map = PropertiesUtil.toMap(properties);
Map<String, DomainConfig> domainConfigMap = new LinkedHashMap<String, DomainConfig>();

//如果 配置的value是空,则使用 contextPath
String defaultValue = servletContext.getContextPath();

for (Map.Entry<String, String> entry : map.entrySet()){
String key = entry.getKey();
String value = entry.getValue();

DomainConfig domainConfig = null;
DomainConfig domainConfig = new DomainConfig();
if (Validator.isNotNullOrEmpty(value)){
//json
if (value.startsWith("{")){
domainConfig = JsonUtil.toBean(value, DomainConfig.class);
}else{
domainConfig = new DomainConfig();
//不是 json 那么直接设置值
domainConfig.setValue(value);
}
domainConfig.setKey(key);
}else{
//nothing to do
}
domainConfig.setKey(key);
if (Validator.isNullOrEmpty(domainConfig.getValue())){
log.debug("key:[{}] 's value isNullOrEmpty,use ContextPath:[{}]", key, defaultValue);
domainConfig.setValue(defaultValue);
}
domainConfigMap.put(key, domainConfig);
}
return domainConfigMap;
Expand Down

0 comments on commit 3bb5352

Please sign in to comment.