forked from actframework/actframework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenderTemplate.java
More file actions
51 lines (43 loc) · 1.41 KB
/
RenderTemplate.java
File metadata and controls
51 lines (43 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package act.view;
import act.Act;
import act.app.ActionContext;
import act.exception.ActException;
import org.osgl.http.H;
import org.osgl.util.E;
import java.util.Map;
/**
* Render a template with template path and arguments provided
* by {@link ActionContext}
*/
public class RenderTemplate extends RenderAny {
private Map<String, Object> renderArgs;
public RenderTemplate() {
}
public RenderTemplate(Map<String, Object> renderArgs) {
this();
this.renderArgs = renderArgs;
}
@Override
public void apply(H.Request req, H.Response resp) {
throw E.unsupport("RenderTemplate does not support " +
"apply to request and response. Please use apply(AppContext) instead");
}
public void apply(ActionContext context) {
if (null != renderArgs && !renderArgs.isEmpty()) {
for (String key : renderArgs.keySet()) {
context.renderArg(key, renderArgs.get(key));
}
}
ViewManager vm = Act.viewManager();
Template t = vm.load(context);
if (null == t) {
throw new ActException("Render template[%s] not found", context.templatePath());
}
applyStatus(context.resp());
H.Request req = context.req();
H.Response resp = context.resp();
applyBeforeCommitHandler(req, resp);
t.merge(context);
applyAfterCommitHandler(req, resp);
}
}