1 5 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 ; 19 import javax.servlet.http.HttpServletResponse ; 20 import java.io.CharArrayWriter ; 21 import java.io.IOException ; 22 23 24 27 public class VelocityWebWorkUtil extends WebWorkUtil { 28 30 private Context ctx; 31 32 34 public VelocityWebWorkUtil(Context ctx, OgnlValueStack stack, HttpServletRequest request, HttpServletResponse response) { 35 super(stack, request, response); 36 this.ctx = ctx; 37 } 38 39 41 43 public String evaluate(String expression) throws IOException , ResourceNotFoundException, MethodInvocationException, ParseErrorException { 44 CharArrayWriter writer = new CharArrayWriter (); 45 VelocityManager.getInstance().getVelocityEngine().evaluate(ctx, writer, "Error parsing " + expression, expression); 46 47 48 return writer.toString(); 49 } 50 } 51 | Popular Tags |