提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.framework.desensitize.core.regex.handler; |
H |
2 |
|
|
3 |
import com.iailab.framework.desensitize.core.base.handler.DesensitizationHandler; |
|
4 |
|
|
5 |
import java.lang.annotation.Annotation; |
|
6 |
|
|
7 |
/** |
|
8 |
* 正则表达式脱敏处理器抽象类,已实现通用的方法 |
|
9 |
* |
|
10 |
* @author gaibu |
|
11 |
*/ |
|
12 |
public abstract class AbstractRegexDesensitizationHandler<T extends Annotation> |
|
13 |
implements DesensitizationHandler<T> { |
|
14 |
|
|
15 |
@Override |
|
16 |
public String desensitize(String origin, T annotation) { |
|
17 |
String regex = getRegex(annotation); |
|
18 |
String replacer = getReplacer(annotation); |
|
19 |
return origin.replaceAll(regex, replacer); |
|
20 |
} |
|
21 |
|
|
22 |
/** |
|
23 |
* 获取注解上的 regex 参数 |
|
24 |
* |
|
25 |
* @param annotation 注解信息 |
|
26 |
* @return 正则表达式 |
|
27 |
*/ |
|
28 |
abstract String getRegex(T annotation); |
|
29 |
|
|
30 |
/** |
|
31 |
* 获取注解上的 replacer 参数 |
|
32 |
* |
|
33 |
* @param annotation 注解信息 |
|
34 |
* @return 待替换的字符串 |
|
35 |
*/ |
|
36 |
abstract String getReplacer(T annotation); |
|
37 |
|
|
38 |
} |