com.github.ayongw.thymeleaf.dynamicurl.service.impl.PropertyDynamicResourceLocationServiceImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of thymeleaf-dynamic-url-dialect Show documentation
Show all versions of thymeleaf-dynamic-url-dialect Show documentation
dynamic replace resources url for thymeleaf
package com.github.ayongw.thymeleaf.dynamicurl.service.impl;
import com.github.ayongw.thymeleaf.dynamicurl.service.DynamicResourceLocationService;
import org.apache.commons.lang3.StringUtils;
import java.util.Map;
/**
* 根据配置的属性列表进行替换,一个默认的实现
*
* @author jiangguangtao
*/
public class PropertyDynamicResourceLocationServiceImpl implements DynamicResourceLocationService {
private Map resourceMap;
public PropertyDynamicResourceLocationServiceImpl(Map resourceMap) {
this.resourceMap = resourceMap;
}
@Override
public String findRemoteUrl(String localUrl) {
localUrl = StringUtils.trim(localUrl);
if (StringUtils.isBlank(localUrl)) {
return null;
}
if (null == resourceMap || resourceMap.size() == 0) {
return localUrl;
}
if (!resourceMap.containsKey(localUrl)) {
return localUrl;
}
return resourceMap.get(localUrl);
}
}