Browse Source

Pull request #10214: REPORT-75998 完善正则表达式匹配,增加单元测试、增加控件事件中的回调函数中的JS

Merge in DESIGN/design from ~DESTINY.LIN/design:feature/x to feature/x

* commit '07e01f472debcb051bd6244e020b98234989ad1b':
  REPORT-75998 完善正则表达式匹配,增加单元测试、增加控件事件中的回调函数中的JS
feature/x
Destiny.Lin-林锦龙 2 years ago
parent
commit
16bfe20dcd
  1. 6
      designer-realize/src/main/java/com/fr/design/actions/replace/action/content/formula/highlight/javascript/SearchExportJSFormulaAction.java
  2. 25
      designer-realize/src/main/java/com/fr/design/actions/replace/utils/SearchJSUtils.java
  3. 8
      designer-realize/src/main/java/com/fr/design/actions/replace/utils/ShowValueUtils.java
  4. 107
      designer-realize/src/test/java/com/fr/design/actions/replace/utils/ShowValueUtilsTest.java

6
designer-realize/src/main/java/com/fr/design/actions/replace/action/content/formula/highlight/javascript/SearchExportJSFormulaAction.java

@ -27,7 +27,7 @@ public class SearchExportJSFormulaAction implements SearchJSFormula {
@Override
public void searchJSFormulaFromOther(List<FormulaInfo> formulaInfos, ITContent content, JavaScript javaScript) {
//如果导出当前模板,可以存公式的地方就是命名方式-自定义
//如果导出当前模板,可以存公式的地方就是命名方式-自定义、参数设置
if (((ExportJavaScript) javaScript).isCurrentTemplate()) {
content.addOtherPos(Toolkit.i18nText("Fine-Design_Basic_Export_JS_Template_Current"));
dealSingleJavaScript(formulaInfos, content, ((ExportJavaScript) javaScript).getCurrentTemplateJavaScript());
@ -42,6 +42,8 @@ public class SearchExportJSFormulaAction implements SearchJSFormula {
}
}
public boolean isListExist(List<SingleJavaScript> list) {
return list != null && list.size() > 0;
}
@ -57,8 +59,8 @@ public class SearchExportJSFormulaAction implements SearchJSFormula {
formulaInfos.add(new FormulaInfo(newContent));
}
if (!javaScript.isExtendParameters()) {
ITContent paraContent = ITContent.copy(content);
for (ParameterProvider parameter : javaScript.getParameters()) {
ITContent paraContent = ITContent.copy(content);
if (parameter.getValue() instanceof Formula) {
paraContent.addOtherPos(Toolkit.i18nText("Fine-Design_Basic_Base_Value"));
paraContent.setReplaceObject(parameter.getValue());

25
designer-realize/src/main/java/com/fr/design/actions/replace/utils/SearchJSUtils.java

@ -12,6 +12,7 @@ import com.fr.design.i18n.Toolkit;
import com.fr.form.event.Listener;
import com.fr.form.ui.Widget;
import com.fr.general.GeneralUtils;
import com.fr.js.Commit2DBJavaScript;
import com.fr.js.JavaScript;
import com.fr.js.JavaScriptImpl;
import com.fr.js.NameJavaScript;
@ -49,10 +50,34 @@ public class SearchJSUtils {
ITContent newContent = ITContent.copy(content);
newContent.setReplaceObject(listener);
SearchJSUtils.addJSInfos(jsInfos, new JSInfo(newContent));
} else if (javaScript instanceof Commit2DBJavaScript){
dealCommit2DBJS(jsInfos, content, (Commit2DBJavaScript) javaScript);
}
}
}
private static void dealCommit2DBJS(List<JSInfo> jsInfos, ITContent content, Commit2DBJavaScript javaScript) {
if (!javaScript.getDBManipulation().isEmpty()) {
//处理回调函数
dealWithCallBack(jsInfos, content, javaScript);
}
}
private static void dealWithCallBack(List<JSInfo> jsInfos, ITContent content, Commit2DBJavaScript commit2DBJavaScript) {
JavaScript javaScript = commit2DBJavaScript.getCallBack();
ITContent newContent = ITContent.copy(content);
newContent.addOtherPos(
Toolkit.i18nText("Fine-Design_Basic_Set_Callback_Function")
);
if (javaScript instanceof JavaScriptImpl) {
newContent.setReplaceObject(javaScript);
jsInfos.add(new JSInfo(newContent));
} else if (javaScript instanceof Commit2DBJavaScript){
dealCommit2DBJS(jsInfos, newContent, (Commit2DBJavaScript) javaScript);
}
}
/**
* 获取HtmlLabel数组
*

8
designer-realize/src/main/java/com/fr/design/actions/replace/utils/ShowValueUtils.java

@ -59,9 +59,11 @@ public class ShowValueUtils {
private static List<String> specialCharList = new ArrayList<>();
static {
//正则特殊字符:? * () [] {} ^ $ .
//正则特殊字符:? * () [] {} ^ $ . \ + |
//如果是? 并采用通配符 ,会自动转成“.” 所以 ? 不用处理
//$同理
specialCharList.add("\\");
specialCharList.add("/");
specialCharList.add("*");
specialCharList.add("(");
specialCharList.add(")");
@ -71,6 +73,10 @@ public class ShowValueUtils {
specialCharList.add("}");
specialCharList.add("^");
specialCharList.add(".");
specialCharList.add("+");
specialCharList.add("|");
specialCharList.add("!");
}
/**

107
designer-realize/src/test/java/com/fr/design/actions/replace/utils/ShowValueUtilsTest.java

@ -0,0 +1,107 @@
package com.fr.design.actions.replace.utils;
import junit.framework.TestCase;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author Destiny.Lin
* @version 11.0
* created by Destiny.Lin on 2022-09-30
*/
public class ShowValueUtilsTest extends TestCase {
public void testChangeRegex() {
/**
* 字符"."
*/
String regex = ".";
String str = "=\"通配符:我(){}[]是*cu/r?y+单!^个字|+符串/?\\?.\"";
Pattern pattern = Pattern.compile(ShowValueUtils.changeRegex(regex));
Matcher matcher = pattern.matcher(str);
assertTrue(matcher.find());
while (matcher.find()){
assertEquals(".", matcher.group());
}
/**
* 字符"?"
*/
regex = "??.";
pattern =Pattern.compile(ShowValueUtils.changeRegex(regex));
Matcher matcher1 = pattern.matcher(str);
assertTrue(matcher1.find());
while (matcher1.find()){
assertEquals("\\?.", matcher1.group());
}
/**
* 字符"\"
*/
regex = "?\\";
pattern =Pattern.compile(ShowValueUtils.changeRegex(regex));
Matcher matcher2 = pattern.matcher(str);
assertTrue(matcher2.find());
while (matcher2.find()){
assertEquals("?\\", matcher2.group());
}
/**
* 字符"/"
*/
regex = "/";
pattern =Pattern.compile(ShowValueUtils.changeRegex(regex));
Matcher matcher3 = pattern.matcher(str);
assertTrue(matcher3.find());
while (matcher3.find()){
assertEquals("/", matcher3.group());
}
/**
* 字符"*"
*/
regex = "*";
pattern =Pattern.compile(ShowValueUtils.changeRegex(regex));
Matcher matcher4 = pattern.matcher(str);
assertTrue(matcher4.find());
while (matcher4.find()){
assertEquals("*", matcher4.group());
}
/**
* 字符"(){}[]"
*/
regex = "(){}[]";
pattern =Pattern.compile(ShowValueUtils.changeRegex(regex));
Matcher matcher5 = pattern.matcher(str);
assertTrue(matcher5.find());
while (matcher5.find()){
assertEquals("(){}[]", matcher5.group());
}
/**
* 字符"^"
*/
regex = "!^";
pattern =Pattern.compile(ShowValueUtils.changeRegex(regex));
Matcher matcher6 = pattern.matcher(str);
assertTrue(matcher6.find());
while (matcher6.find()){
assertEquals("!^", matcher6.group());
}
/**
* 字符"|+"
*/
regex = "|+";
pattern =Pattern.compile(ShowValueUtils.changeRegex(regex));
Matcher matcher7 = pattern.matcher(str);
assertTrue(matcher7.find());
while (matcher7.find()){
assertEquals("|+", matcher7.group());
}
}
}
Loading…
Cancel
Save