KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > util > VelocityWebWorkUtil


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 /*
6  * Created on 19/04/2004
7  */

8 package com.opensymphony.webwork.util;
9
10 import com.opensymphony.util.TextUtils;
11 import com.opensymphony.xwork.util.OgnlValueStack;
12 import com.opensymphony.webwork.views.velocity.VelocityManager;
13 import org.apache.velocity.context.Context;
14 import org.apache.velocity.exception.MethodInvocationException;
15 import org.apache.velocity.exception.ParseErrorException;
16 import org.apache.velocity.exception.ResourceNotFoundException;
17
18 import javax.servlet.http.HttpServletRequest JavaDoc;
19 import javax.servlet.http.HttpServletResponse JavaDoc;
20 import java.io.CharArrayWriter JavaDoc;
21 import java.io.IOException JavaDoc;
22
23
24 /**
25  * @author CameronBraid
26  */

27 public class VelocityWebWorkUtil extends WebWorkUtil {
28     //~ Instance fields ////////////////////////////////////////////////////////
29

30     private Context ctx;
31
32     //~ Constructors ///////////////////////////////////////////////////////////
33

34     public VelocityWebWorkUtil(Context ctx, OgnlValueStack stack, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
35         super(stack, request, response);
36         this.ctx = ctx;
37     }
38
39     //~ Methods ////////////////////////////////////////////////////////////////
40

41     /**
42      */

43     public String JavaDoc evaluate(String JavaDoc expression) throws IOException JavaDoc, ResourceNotFoundException, MethodInvocationException, ParseErrorException {
44         CharArrayWriter JavaDoc writer = new CharArrayWriter JavaDoc();
45         VelocityManager.getInstance().getVelocityEngine().evaluate(ctx, writer, "Error parsing " + expression, expression);
46
47
48         return writer.toString();
49     }
50 }
51
Popular Tags