
prerna.reactor.export.mustache.MustacheUtility Maven / Gradle / Ivy
The newest version!
package prerna.reactor.export.mustache;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Array;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;
import com.github.mustachejava.SafeMustacheFactory;
import com.github.mustachejava.reflect.ReflectionObjectHandler;
public class MustacheUtility {
private MustacheUtility() {
}
public static String compile(String template, Map variables) throws Exception {
if(variables == null || variables.isEmpty()) {
return template;
}
ReflectionObjectHandler oh = new ReflectionObjectHandler() {
@Override
public Object coerce(final Object object) {
if (object != null && object.getClass().isArray()) {
return new ArrayMap(object);
} else if(object instanceof List) {
return new ListMap(object);
} else if(object instanceof Collection) {
return new ListMap(new ArrayList
© 2015 - 2025 Weber Informatics LLC | Privacy Policy