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

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

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

import java.util.Map;
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 ForEach extends Segment{
	protected String in;
	protected String id = "$value";
	protected String delimeter=";";
	
	public ForEach(String tag, Logiclet p) {
		super(tag, p);
	}
	
	public void configure(Properties p){
		super.configure(p);
		in = PropertiesConstants.getRaw(p,"in","");
		delimeter = PropertiesConstants.getString(p,"delimeter",delimeter,true);
		id = PropertiesConstants.getString(p,"id",id,true);
	}

	@Override
	protected void onExecute(Map root,
			Map current, LogicletContext ctx, ExecuteWatcher watcher) {
		String[] values = ctx.transform(in).split(delimeter);
		
		if (values.length > 0){
			for (String value:values){
				ctx.SetValue(id, value);
				super.onExecute(root, current, ctx, watcher);
			}
		}
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy