1 package org.apache.turbine.services.velocity;
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
52
53
54
55
56
57 import java.io.OutputStream;
58 import java.io.Writer;
59
60 import org.apache.turbine.pipeline.PipelineData;
61 import org.apache.turbine.services.Service;
62 import org.apache.turbine.util.RunData;
63 import org.apache.turbine.util.TurbineException;
64
65 import org.apache.velocity.context.Context;
66
67 /***
68 * Implementations of the VelocityService interface.
69 *
70 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
71 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
72 * @author <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
73 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
74 * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a>
75 * @version $Id: VelocityService.java,v 1.12 2004/08/02 08:57:31 epugh Exp $
76 */
77 public interface VelocityService
78 extends Service
79 {
80 /*** The Service Name */
81 String SERVICE_NAME = "VelocityService";
82
83 /*** Key for storing the Context in the RunData object */
84 String CONTEXT = "VELOCITY_CONTEXT";
85
86 /*** The default extension of Velocity Pages */
87 String VELOCITY_EXTENSION = "vm";
88
89 /*** The Key for storing the RunData Object in the Context */
90 String RUNDATA_KEY = "data";
91
92 /*** The Key for storing the PipelineData Object in the Context */
93 String PIPELINEDATA_KEY = "pipelineData";
94
95 /*** Shall we catch Velocity Errors and report them? */
96 String CATCH_ERRORS_KEY = "catch.errors";
97
98 /*** Default: Yes */
99 boolean CATCH_ERRORS_DEFAULT = true;
100
101 /***
102 * Process the request and fill in the template with the values
103 * you set in the Context.
104 *
105 * @param context A Context.
106 * @param template A String with the filename of the template.
107 * @return The process template as a String.
108 * @exception Exception a generic exception.
109 */
110 String handleRequest(Context context, String template)
111 throws Exception;
112
113 /***
114 * Process the request and fill in the template with the values
115 * you set in the Context.
116 *
117 * @param context A Context.
118 * @param filename A String with the filename of the template.
119 * @param out A OutputStream where we will write the process template as
120 * a String.
121 * @throws TurbineException Any exception trown while processing will be
122 * wrapped into a TurbineException and rethrown.
123 */
124 void handleRequest(Context context, String filename, OutputStream out)
125 throws TurbineException;
126
127 /***
128 * Process the request and fill in the template with the values
129 * you set in the Context.
130 *
131 * @param context A Context.
132 * @param filename A String with the filename of the template.
133 * @param writer A Writer where we will write the process template as
134 * a String.
135 * @throws TurbineException Any exception trown while processing will be
136 * wrapped into a TurbineException and rethrown.
137 */
138 void handleRequest(Context context, String filename, Writer writer)
139 throws TurbineException;
140
141 /***
142 * Create an empty WebContext object.
143 *
144 * @return An empty WebContext object.
145 */
146 Context getContext();
147
148 /***
149 * This method returns a new, empty Context object.
150 *
151 * @return A WebContext.
152 */
153 Context getNewContext();
154
155 /***
156 * Create a Context from the RunData object. Adds a pointer to
157 * the RunData object to the Context so that RunData is available in
158 * the templates.
159 *
160 * @param data The Turbine RunData object.
161 * @return A clone of the Context needed by Velocity.
162 */
163 Context getContext(RunData data);
164
165 /***
166 * Create a Context from the RunData object. Adds a pointer to
167 * the RunData object to the Context so that RunData is available in
168 * the templates.
169 *
170 * @param data The Turbine RunData object.
171 * @return A clone of the Context needed by Velocity.
172 */
173 Context getContext(PipelineData pipelineData);
174
175
176
177 /***
178 * Performs post-request actions (releases context
179 * tools back to the object pool).
180 *
181 * @param context a Velocity Context
182 */
183 void requestFinished(Context context);
184 }