![JAR search and dependency download from the Maven repository](/logo.png)
com.alogic.xscript.plugins.Repeat Maven / Gradle / Ivy
package com.alogic.xscript.plugins;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.lang3.StringUtils;
import com.alogic.xscript.ExecuteWatcher;
import com.alogic.xscript.Logiclet;
import com.alogic.xscript.LogicletContext;
import com.alogic.xscript.doc.XsObject;
import com.alogic.xscript.doc.json.JsonObject;
import com.anysoft.util.BaseException;
import com.anysoft.util.Properties;
import com.anysoft.util.PropertiesConstants;
import com.jayway.jsonpath.JsonPath;
/**
* 循环
*
* @author duanyy
* @version 1.6.7.22 [20170306 duanyy]
* - 当jsonPath语法错误或者节点不存在时,不再抛出异常
*
* @version 1.6.8.4 [20170329 duanyy]
* - 对象的属性可以循环处理
*
* @version 1.6.9.1 [20170516 duanyy]
* - 修复部分插件由于使用新的文档模型产生的兼容性问题
*
* @version 1.6.12.50 [20191202 duanyy]
* - 不再支持异步模式
*/
public class Repeat extends Segment{
protected String jsonPath;
protected String value = "$value";
protected String key = "$key";
public Repeat(String tag, Logiclet p) {
super(tag, p);
}
public void configure(Properties p){
super.configure(p);
jsonPath = PropertiesConstants.getString(p, "path", jsonPath,true);
value = PropertiesConstants.getString(p,"value",value,true);
key = PropertiesConstants.getString(p,"key",key,true);
}
@SuppressWarnings("unchecked")
@Override
protected void onExecute(XsObject root,XsObject current, LogicletContext ctx, ExecuteWatcher watcher) {
if (current instanceof JsonObject){
if (StringUtils.isNotEmpty(jsonPath)){
Object result = null;
try {
result = JsonPath.read(current.getContent(), jsonPath);
}catch (Exception ex){
logger.warn("Can not read jsonpath :" + jsonPath);
logger.warn(ex.getMessage());
}
if (result != null){
if (result instanceof List>){
repeat((List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy