This project has retired. For details please refer to its
Attic page.
AbstractDefaultToStringRenderable xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.tiles.velocity.template;
23
24 import java.io.IOException;
25 import java.io.StringWriter;
26 import java.util.Map;
27
28 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpServletResponse;
30
31 import org.apache.tiles.velocity.TilesVelocityException;
32 import org.apache.velocity.context.Context;
33 import org.apache.velocity.exception.MethodInvocationException;
34 import org.apache.velocity.exception.ParseErrorException;
35 import org.apache.velocity.exception.ResourceNotFoundException;
36 import org.apache.velocity.runtime.Renderable;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39
40
41
42
43
44
45
46
47 public abstract class AbstractDefaultToStringRenderable implements Renderable {
48
49
50
51
52
53
54
55 protected final Context velocityContext;
56
57
58
59
60
61
62 protected final Map<String, Object> params;
63
64
65
66
67
68
69 protected final HttpServletResponse response;
70
71
72
73
74
75
76 protected final HttpServletRequest request;
77
78
79
80
81 private final Logger log = LoggerFactory.getLogger(getClass());
82
83
84
85
86
87
88
89
90
91
92 public AbstractDefaultToStringRenderable(Context velocityContext,
93 Map<String, Object> params, HttpServletResponse response,
94 HttpServletRequest request) {
95 this.velocityContext = velocityContext;
96 this.params = params;
97 this.response = response;
98 this.request = request;
99 }
100
101
102 @Override
103 public String toString() {
104 StringWriter writer = new StringWriter();
105 try {
106 render(null, writer);
107 } catch (MethodInvocationException e) {
108 throw new TilesVelocityException("Cannot invoke method when rendering", e);
109 } catch (ParseErrorException e) {
110 throw new TilesVelocityException("Cannot parse when rendering", e);
111 } catch (ResourceNotFoundException e) {
112 throw new TilesVelocityException("Cannot find resource when rendering", e);
113 } catch (IOException e) {
114 throw new TilesVelocityException("I/O exception when rendering", e);
115 } finally {
116 try {
117 writer.close();
118 } catch (IOException e) {
119 log.error("Error when closing a StringWriter, the impossible happened!", e);
120 }
121 }
122 return writer.toString();
123 }
124 }