01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.webwork.util;
06:
07: import com.opensymphony.webwork.views.velocity.VelocityManager;
08: import com.opensymphony.xwork.util.OgnlValueStack;
09: import org.apache.velocity.context.Context;
10: import org.apache.velocity.exception.MethodInvocationException;
11: import org.apache.velocity.exception.ParseErrorException;
12: import org.apache.velocity.exception.ResourceNotFoundException;
13:
14: import javax.servlet.http.HttpServletRequest;
15: import javax.servlet.http.HttpServletResponse;
16: import java.io.CharArrayWriter;
17: import java.io.IOException;
18:
19: /**
20: * WebWork velocity related util.
21: *
22: * @author CameronBraid
23: */
24: public class VelocityWebWorkUtil extends WebWorkUtil {
25:
26: private Context ctx;
27:
28: public VelocityWebWorkUtil(Context ctx, OgnlValueStack stack,
29: HttpServletRequest request, HttpServletResponse response) {
30: super (stack, request, response);
31: this .ctx = ctx;
32: }
33:
34: public String evaluate(String expression) throws IOException,
35: ResourceNotFoundException, MethodInvocationException,
36: ParseErrorException {
37: CharArrayWriter writer = new CharArrayWriter();
38: VelocityManager.getInstance().getVelocityEngine().evaluate(ctx,
39: writer, "Error parsing " + expression, expression);
40:
41: return writer.toString();
42: }
43:
44: }
|