1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.springframework.extensions.webscripts;
20
21 import java.io.IOException;
22 import java.util.Map;
23
24 import javax.servlet.jsp.tagext.BodyTagSupport;
25
26 import org.springframework.extensions.surf.render.RenderContext;
27 import org.springframework.extensions.surf.taglib.ResourceTag;
28 import org.springframework.extensions.surf.util.StringBuilderWriter;
29
30 import freemarker.core.Environment;
31 import freemarker.template.TemplateDirectiveBody;
32 import freemarker.template.TemplateException;
33 import freemarker.template.TemplateModel;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 public class ResourceFreemarkerTagDirective extends FreemarkerTagSupportDirective
50 {
51 public ResourceFreemarkerTagDirective(RenderContext context)
52 {
53 super(context);
54 }
55
56 public void execute(Environment env, Map params, TemplateModel[] loopVars,
57 TemplateDirectiveBody body) throws TemplateException, IOException
58 {
59
60 ResourceTag tag = new ResourceTag();
61
62
63 tag.setName(getStringParameter(params, "name"));
64
65
66 tag.setId(getStringParameter(params, "id"));
67
68
69 tag.setProtocol(getStringParameter(params, "protocol"));
70 tag.setEndpoint(getStringParameter(params, "endpoint"));
71 tag.setObject(getStringParameter(params, "object"));
72
73
74 tag.setPayload(getStringParameter(params, "payload"));
75
76
77 String bodyContentString = null;
78 if (body != null)
79 {
80 if (tag instanceof BodyTagSupport)
81 {
82
83 StringBuilderWriter bodyStringWriter = new StringBuilderWriter(256);
84 body.render(bodyStringWriter);
85 bodyContentString = bodyStringWriter.toString();
86 }
87 }
88
89
90
91
92 try
93 {
94 String output = executeTag(tag, bodyContentString);
95 env.getOut().write(output);
96 }
97 catch (Exception ex)
98 {
99 throw new TemplateException("Unable to process tag and commit output", ex, env);
100 }
101 }
102 }