package com.palacesun.masking.tools;

import org.apache.commons.jexl3.JexlBuilder;
import org.apache.commons.jexl3.JexlContext;
import org.apache.commons.jexl3.JexlEngine;
import org.apache.commons.jexl3.JexlExpression;
import org.apache.commons.jexl3.MapContext;

public class MaskingUtil {
   public static Object masking(Object param, String expression) {
      String newExp = expression.replace("$value", "\"" + param + "\"");
      JexlEngine jexl = (new JexlBuilder()).create();
      JexlExpression e = jexl.createExpression(newExp);
      JexlContext jc = new MapContext();
      Object o = null;

      try {
         o = e.evaluate(jc);
         return o;
      } catch (Exception exception) {
         exception.printStackTrace();
         return param;
      }
   }
}
