1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.freemarker;
17
18 import java.io.IOException;
19 import java.io.Serializable;
20
21 import org.kuali.rice.krad.uif.component.Component;
22 import org.springframework.util.StringUtils;
23
24 import freemarker.core.Environment;
25 import freemarker.core.InlineTemplateAdaptor;
26 import freemarker.template.TemplateException;
27
28
29
30
31
32
33 public class FreeMarkerScriptAdaptor implements InlineTemplateAdaptor, Serializable {
34
35 private static final long serialVersionUID = 1675270336764602352L;
36
37
38
39
40
41
42 @Override
43 public void accept(Environment env) throws TemplateException, IOException {
44 String script = FreeMarkerInlineRenderUtils.resolve(env, "value", String.class);
45
46 if (!StringUtils.hasText(script)) {
47 return;
48 }
49
50 Component component = FreeMarkerInlineRenderUtils.resolve(env, "component", Component.class);
51 String role = FreeMarkerInlineRenderUtils.resolve(env, "role", String.class);
52 FreeMarkerInlineRenderUtils.renderScript(script, component, role, env.getOut());
53 }
54
55 }