All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.alogic.xscript.plugins.StringList Maven / Gradle / Ivy
package com.alogic.xscript.plugins;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import com.alogic.xscript.AbstractLogiclet;
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.plugins.Segment;
import com.anysoft.util.Properties;
import com.anysoft.util.PropertiesConstants;
/**
* 字符串形式的数组
*
* @author duanyy
* @since 1.6.12.20 [20190130 duanyy]
*/
public class StringList extends Segment {
protected String $id = "";
protected String cid = "$stringlist";
protected String delimeter = ",";
public StringList(String tag, Logiclet p) {
super(tag, p);
registerModule("strlist-add",Add.class);
}
@Override
public void configure(Properties p){
super.configure(p);
$id = PropertiesConstants.getRaw(p,"id",$id);
cid = PropertiesConstants.getString(p,"cid",cid,true);
delimeter = PropertiesConstants.getString(p,"delimeter",delimeter,true);
}
protected void onExecute(XsObject root,XsObject current, LogicletContext ctx, ExecuteWatcher watcher) {
String id = PropertiesConstants.transform(ctx, $id, "");
if (StringUtils.isNotEmpty(id)){
//只有定义了输出id才有效
List list = new ArrayList();
try {
ctx.setObject(cid, list);
super.onExecute(root, current, ctx, watcher);
}finally{
ctx.removeObject(cid);
ctx.SetValue(id, StringUtils.join(list.toArray(new String[list.size()]), delimeter));
}
}
}
/**
* 向数组中增加值
*
* @author duanyy
*
*/
public static class Add extends AbstractLogiclet {
protected String pid = "$stringlist";
protected String $value = "";
protected boolean raw = false;
protected boolean ref = false;
public Add(String tag, Logiclet p) {
super(tag, p);
}
@Override
public void configure(Properties p){
super.configure(p);
pid = PropertiesConstants.getString(p,"pid",pid,true);
$value = PropertiesConstants.getRaw(p,"value",$value);
raw = PropertiesConstants.getBoolean(p, "raw", raw,true);
ref = PropertiesConstants.getBoolean(p, "ref", ref,true);
}
protected void onExecute(XsObject root,XsObject current, LogicletContext ctx, ExecuteWatcher watcher) {
List list = ctx.getObject(pid);
if (list != null){
if (raw){
if (ref){
String v = PropertiesConstants.getRaw(ctx, $value, "");
if (StringUtils.isNotEmpty(v)){
list.add(v);
}
}else{
list.add($value);
}
}else{
String v = ref?PropertiesConstants.getString(ctx,$value,"",false):PropertiesConstants.transform(ctx, $value, "");
if (StringUtils.isNotEmpty(v)){
list.add(v);
}
}
}
}
}
}