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

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

There is a newer version: 1.6.17
Show newest version
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.anysoft.util.Properties;
import com.anysoft.util.PropertiesConstants;

/**
 * 检查参数,如果为空,就设置缺省值
 * 
 * @author duanyy
 *
 */
public class CheckAndSetDefault extends AbstractLogiclet{
	protected String arguId;	
	protected String dftValue;
	
	public CheckAndSetDefault(String tag, Logiclet p) {
		super(tag, p);
	}

	@Override
	public void configure(Properties p) {
		super.configure(p);
		
		arguId = PropertiesConstants.getString(p,"id", arguId);
		dftValue = PropertiesConstants.getRaw(p, "dft", "");
	}		
	
	@Override
	protected void onExecute(Map root,
			Map current, LogicletContext ctx,
			ExecuteWatcher watcher) {
		if (StringUtils.isNotEmpty(arguId)){
			String value = ctx.GetValue(arguId, "");
			if (StringUtils.isEmpty(value)){
				ctx.SetValue(arguId, ctx.transform(dftValue));
			}
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy