All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alogic.xscript.plugins.Get Maven / Gradle / Ivy

There is a newer version: 1.6.17
Show newest version
package com.alogic.xscript.plugins;

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.anysoft.util.Properties;
import com.anysoft.util.PropertiesConstants;

/**
 * 从上下文变量中获取变量值,并设置到当前节点上
 * 
 * @author duanyy
 * 
 * @version 1.6.6.11 [duanyy 20161227] 
* - 增加类型
* * @version 1.6.7.21 [duanyy 20170303]
* - 修改xscript的Get插件,可支持为空时忽略
* * @version 1.6.7.22 [duanyy 20170306]
* - 不再将当前文档节点的属性作为变量
* * @version 1.6.8.14 [20170509 duanyy]
* - 增加xscript的中间文档模型,以便支持多种报文协议
* * @version 1.6.11.43 [20180708 duanyy]
* - 支持raw模式
* * @version 1.6.12.24 [20190311 duanyy]
* - 增加对boolean类型的支持;
* * @version 1.6.12.28 [20190407]
* - 优化对不同类型数据的支持
* * @version 1.6.12.30 [20190425 duanyy]
* - 修正Long和Integer输出反了的笔误
*/ public class Get extends AbstractLogiclet { protected String id; protected String value; protected String type; protected boolean ignoreIfNull = false; protected boolean raw = false; public Get(String tag, Logiclet p) { super(tag, p); } public void configure(Properties p){ super.configure(p); id = PropertiesConstants.getRaw(p,"id",""); value = PropertiesConstants.getRaw(p,"value",""); type = PropertiesConstants.getString(p,"type","string",true); ignoreIfNull = PropertiesConstants.getBoolean(p,"ignoreIfNull",ignoreIfNull,true); raw = PropertiesConstants.getBoolean(p, "raw", raw); } @Override protected void onExecute(XsObject root,XsObject current, LogicletContext ctx, ExecuteWatcher watcher) { String idValue = ctx.transform(id); if (StringUtils.isNotEmpty(idValue)){ String v = raw?PropertiesConstants.getRaw(ctx,value,""):ctx.transform(value); if (StringUtils.isNotEmpty(v)){ switch (getType(type)){ case LONG: current.addProperty(idValue,asTypeValue(v,0L)); break; case INTEGER: current.addProperty(idValue,asTypeValue(v,0)); break; case DOUBLE: current.addProperty(idValue,asTypeValue(v,0.0d)); break; case FLOAT: current.addProperty(idValue,asTypeValue(v,0.0f)); break; case BOOLEAN: current.addProperty(idValue,asTypeValue(v,false)); break; default:current.addProperty(idValue, v); } }else{ if (!ignoreIfNull){ current.remove(idValue); } } } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy