50 changed files with 730 additions and 95 deletions
@ -0,0 +1,61 @@ |
|||||
|
package io.sc.engine.rule.core.util; |
||||
|
|
||||
|
import io.sc.platform.util.PlaceHolderExpressionUtil; |
||||
|
|
||||
|
import java.util.LinkedHashSet; |
||||
|
import java.util.Set; |
||||
|
|
||||
|
public class PlaceHolder { |
||||
|
private Set<String> variableRefs =new LinkedHashSet<>(); |
||||
|
private Set<String> enumRefs =new LinkedHashSet<>(); |
||||
|
private Set<String> userFunctionRefs =new LinkedHashSet<>(); |
||||
|
|
||||
|
public static PlaceHolder extract(String... contents){ |
||||
|
if(contents==null || contents.length<=0){ |
||||
|
return new PlaceHolder(); |
||||
|
} |
||||
|
PlaceHolder result =new PlaceHolder(); |
||||
|
for(String content : contents) { |
||||
|
// 抽取变量站位符
|
||||
|
result.variableRefs.addAll(PlaceHolderExpressionUtil.extract(content)); |
||||
|
result.enumRefs.addAll(PlaceHolderEnumExpressionUtil.extract(content)); |
||||
|
result.userFunctionRefs.addAll(UserFunctionExpressionUtil.extract(content)); |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
public PlaceHolder add(PlaceHolder placeHolder){ |
||||
|
if(placeHolder==null){ |
||||
|
return this; |
||||
|
} |
||||
|
variableRefs.addAll(placeHolder.getVariableRefs()); |
||||
|
enumRefs.addAll(placeHolder.getEnumRefs()); |
||||
|
userFunctionRefs.addAll(placeHolder.getUserFunctionRefs()); |
||||
|
return this; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public Set<String> getVariableRefs() { |
||||
|
return variableRefs; |
||||
|
} |
||||
|
|
||||
|
public void setVariableRefs(Set<String> variableRefs) { |
||||
|
this.variableRefs = variableRefs; |
||||
|
} |
||||
|
|
||||
|
public Set<String> getEnumRefs() { |
||||
|
return enumRefs; |
||||
|
} |
||||
|
|
||||
|
public void setEnumRefs(Set<String> enumRefs) { |
||||
|
this.enumRefs = enumRefs; |
||||
|
} |
||||
|
|
||||
|
public Set<String> getUserFunctionRefs() { |
||||
|
return userFunctionRefs; |
||||
|
} |
||||
|
|
||||
|
public void setUserFunctionRefs(Set<String> userFunctionRefs) { |
||||
|
this.userFunctionRefs = userFunctionRefs; |
||||
|
} |
||||
|
} |
@ -0,0 +1,29 @@ |
|||||
|
package io.sc.engine.rule.core.util; |
||||
|
|
||||
|
import io.sc.platform.util.CollectionUtil; |
||||
|
import io.sc.platform.util.support.PlaceholderExpression; |
||||
|
import io.sc.platform.util.support.PlaceholderExpressionPart; |
||||
|
import io.sc.platform.util.support.StringLengthDescComparator; |
||||
|
import org.springframework.util.StringUtils; |
||||
|
|
||||
|
import java.util.*; |
||||
|
import java.util.regex.Matcher; |
||||
|
import java.util.regex.Pattern; |
||||
|
|
||||
|
/** |
||||
|
* 占位符表达式工具类 |
||||
|
*/ |
||||
|
public class UserFunctionExpressionUtil { |
||||
|
private static final Pattern PATTERN =Pattern.compile("UDF\\s.\\s(.+?)\\("); |
||||
|
|
||||
|
public static Set<String> extract(String content){ |
||||
|
Set<String> result =new LinkedHashSet<>(); |
||||
|
if(StringUtils.hasText(content)){ |
||||
|
Matcher matcher =PATTERN.matcher(content); |
||||
|
while(matcher.find()){ |
||||
|
result.add(matcher.group(1)); |
||||
|
} |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
} |
@ -0,0 +1,29 @@ |
|||||
|
import org.springframework.util.StringUtils; |
||||
|
|
||||
|
import java.util.ArrayList; |
||||
|
import java.util.Collections; |
||||
|
import java.util.List; |
||||
|
import java.util.regex.Matcher; |
||||
|
import java.util.regex.Pattern; |
||||
|
|
||||
|
/** |
||||
|
* 占位符表达式工具类 |
||||
|
*/ |
||||
|
public class UserFunctionExpressionUtil { |
||||
|
private static final Pattern PATTERN =Pattern.compile("UDF\\s*.\\s*(.+?)\\("); |
||||
|
|
||||
|
public static List<String> extract(String content){ |
||||
|
if(!StringUtils.hasText(content)){ |
||||
|
return Collections.emptyList(); |
||||
|
} |
||||
|
List<String> result =new ArrayList<>(); |
||||
|
Matcher matcher =PATTERN.matcher(content); |
||||
|
while(matcher.find()){ |
||||
|
String group =matcher.group(1).trim(); |
||||
|
if(StringUtils.hasText(group)){ |
||||
|
result.add(group); |
||||
|
} |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue