package com.ctrip.ops.sysdev.render;

import java.io.IOException;
import java.util.Map;
import java.util.regex.Pattern;

public interface TemplateRender {
    Pattern p = Pattern.compile("\\[\\S+\\]+");

    public Object render(Map event);

    static public TemplateRender getRender(Object template) throws IOException {
        if (!String.class.isAssignableFrom(template.getClass())) {
            return new DirectRender(template);
        }
        if (p.matcher((String) template).matches()) {
            return new FieldRender((String) template);
        }

        return new FreeMarkerRender((String) template, (String) template);

    }


    static public TemplateRender getRender(String template, boolean ignoreOneLevelRender) throws IOException {
        if (ignoreOneLevelRender == true) {
            return getRender(template);
        }

        if (!String.class.isAssignableFrom(template.getClass())) {
            return new DirectRender(template);
        }
        if (p.matcher(template).matches()) {
            return new FieldRender(template);
        }
        if (template.contains("$")) {
            return new FreeMarkerRender(template, template);
        }
        return new OneLevelRender(template);
    }


    static public TemplateRender getRender(String template, String timezone) throws IOException {
        return new DateFormatter(template, timezone);
    }
}
@@ -114,16 +114,17 @@
 ttern;%0A%0A
+%0A
 public i
@@ -1348,50 +1348,198 @@
     
-return new DateFormatter(template, timezon
+Pattern p = Pattern.compile(%22%5C%5C%25%5C%5C%7B%5C%5C+.*?%5C%5C%7D%22);%0A        if (p.matcher(template).find()) %7B%0A            return new DateFormatter(template, timezone);%0A        %7D%0A        return getRender(templat
 e);%0A

index config in ES output may not be %{+XX}