com.alogic.xscript.plugins.Trim Maven / Gradle / Ivy
package com.alogic.xscript.plugins;
import java.util.Map;
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.util.MapProperties;
import com.anysoft.util.Properties;
import com.anysoft.util.PropertiesConstants;
/**
* 对取值进行trim操作,然后设置为变量
*
* @author duanyy
*
*/
public class Trim extends AbstractLogiclet {
protected String id;
protected String value;
public Trim(String tag, Logiclet p) {
super(tag, p);
}
public void configure(Properties p){
super.configure(p);
id = PropertiesConstants.getString(p,"id","",true);
value = p.GetValue("value", "", false, true);
}
@Override
protected void onExecute(Map root,
Map current, LogicletContext ctx, ExecuteWatcher watcher) {
if (StringUtils.isNotEmpty(id)){
MapProperties p = new MapProperties(current,ctx);
ctx.SetValue(id, p.transform(value).trim());
}
}
}