1 package com.opensymphony.webwork.views.freemarker.tags; 2 3 import com.opensymphony.webwork.components.Component; 4 import com.opensymphony.xwork.util.OgnlValueStack; 5 import freemarker.template.TemplateModelException; 6 import freemarker.template.TemplateTransformModel; 7 8 import javax.servlet.http.HttpServletRequest ; 9 import javax.servlet.http.HttpServletResponse ; 10 import java.io.IOException ; 11 import java.io.Writer ; 12 import java.util.HashMap ; 13 import java.util.Iterator ; 14 import java.util.Map ; 15 16 21 public abstract class TagModel implements TemplateTransformModel { 22 protected OgnlValueStack stack; 23 protected HttpServletRequest req; 24 protected HttpServletResponse res; 25 26 public TagModel(OgnlValueStack stack, HttpServletRequest req, HttpServletResponse res) { 27 this.stack = stack; 28 this.req = req; 29 this.res = res; 30 } 31 32 public Writer getWriter(Writer writer, Map params) throws TemplateModelException, IOException { 33 Component bean = getBean(); 34 params = convertParams(params); 35 bean.copyParams(params); 36 bean.start(writer); 38 return new CallbackWriter(bean, writer); 39 } 40 41 protected abstract Component getBean(); 42 43 private Map convertParams(Map params) { 44 HashMap map = new HashMap (params.size()); 45 for (Iterator iterator = params.entrySet().iterator(); iterator.hasNext();) { 46 Map.Entry entry = (Map.Entry ) iterator.next(); 47 map.put(entry.getKey(), entry.getValue().toString()); 48 } 49 return map; 50 } 51 52 } 53 | Popular Tags |