mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-18 13:58:07 +08:00
!165 绝对路径的目录位置及其所有子目录下规则配置文件的侦听
Merge pull request !165 from 与或非/issues/I6BDLN
This commit is contained in:
@@ -3,6 +3,7 @@ package com.yomahub.liteflow.spi.solon;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.stream.StreamUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.exception.ConfigErrorException;
|
||||
@@ -10,17 +11,42 @@ import com.yomahub.liteflow.spi.PathContentParser;
|
||||
import org.noear.solon.Utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SolonPathContentParser implements PathContentParser {
|
||||
@Override
|
||||
public List<String> parseContent(List<String> pathList) throws Exception {
|
||||
if(CollectionUtil.isEmpty(pathList)){
|
||||
List<URL> allResource = getUrls(pathList);
|
||||
|
||||
//转换成内容List
|
||||
List<String> contentList = new ArrayList<>();
|
||||
for (URL resource : allResource) {
|
||||
String content = IoUtil.read(resource.openStream(), CharsetUtil.CHARSET_UTF_8);
|
||||
if (StrUtil.isNotBlank(content)) {
|
||||
contentList.add(content);
|
||||
}
|
||||
}
|
||||
|
||||
return contentList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getFileAbsolutePath(List<String> pathList) throws Exception {
|
||||
List<URL> allResource = getUrls(pathList);
|
||||
return StreamUtil.of(allResource)
|
||||
.map(URL::getPath)
|
||||
.filter(FileUtil::isFile)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static List<URL> getUrls(List<String> pathList) throws MalformedURLException {
|
||||
if (CollectionUtil.isEmpty(pathList)) {
|
||||
throw new ConfigErrorException("rule source must not be null");
|
||||
}
|
||||
|
||||
@@ -34,27 +60,19 @@ public class SolonPathContentParser implements PathContentParser {
|
||||
path = path.substring(ResourceUtils.CLASSPATH_URL_PREFIX.length());
|
||||
}
|
||||
|
||||
allResource.add(Utils.getResource(path));
|
||||
if (Utils.getResource(path) != null) {
|
||||
allResource.add(Utils.getResource(path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//如果有多个资源,检查资源都是同一个类型,如果出现不同类型的配置,则抛出错误提示
|
||||
Set<String> fileTypeSet = new HashSet<>();
|
||||
allResource.forEach(resource -> fileTypeSet.add(FileUtil.extName(resource.getPath())));
|
||||
if (fileTypeSet.size() != 1) {
|
||||
if (fileTypeSet.size() > 1) {
|
||||
throw new ConfigErrorException("config error,please use the same type of configuration");
|
||||
}
|
||||
|
||||
//转换成内容List
|
||||
List<String> contentList = new ArrayList<>();
|
||||
for (URL resource : allResource) {
|
||||
String content = IoUtil.read(resource.openStream(), CharsetUtil.CHARSET_UTF_8);
|
||||
if (StrUtil.isNotBlank(content)){
|
||||
contentList.add(content);
|
||||
}
|
||||
}
|
||||
|
||||
return contentList;
|
||||
return allResource;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user