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

com.alogic.xscript.plugins.SetAsJson 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;
import com.jayway.jsonpath.spi.JsonProvider;
import com.jayway.jsonpath.spi.JsonProviderFactory;

public class SetAsJson extends AbstractLogiclet{
	protected String id;
	protected JsonProvider provider = JsonProviderFactory.createProvider();
	
	public SetAsJson(String tag, Logiclet p) {
		super(tag, p);
	}
	
	@Override
	public void configure(Properties p){
		super.configure(p);
		
		id = PropertiesConstants.getString(p,"id","",true);
	}	

	@Override
	protected void onExecute(Map root,
			Map current, LogicletContext ctx,
			ExecuteWatcher watcher) {
		if (StringUtils.isNotEmpty(id)){
			String content = provider.toJson(current);
			if (StringUtils.isNotEmpty(content)){
				ctx.SetValue(id, content);
			}
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy