Search in sources :

Example 31 with GroupTemplate

use of org.beetl.core.GroupTemplate in project beetl2.0 by javamonkey.

the class Struts2BeetlActionResult method doExecute.

protected void doExecute(String locationArg, ActionInvocation invocation) throws Exception {
    ActionContext ctx = invocation.getInvocationContext();
    HttpServletRequest req = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
    HttpServletResponse rsp = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE);
    if (!locationArg.startsWith("/")) {
        String base = ResourceUtil.getResourceBase(req);
        locationArg = base + "/" + locationArg;
    }
    Object action = invocation.getAction();
    Map<String, Object> values = reflectionProvider.getBeanMap(action);
    rsp.setContentType(this.pContentType);
    WebRender render = new WebRender(groupTemplate) {

        protected void modifyTemplate(Template template, String key, HttpServletRequest request, HttpServletResponse response, Object... args) {
            Map model = (Map) args[0];
            for (Object o : model.entrySet()) {
                Entry entry = (Entry) o;
                String name = (String) entry.getKey();
                Object value = entry.getValue();
                template.binding(name, value);
            }
        }
    };
    render.render(locationArg, req, rsp, values);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebRender(org.beetl.ext.web.WebRender) Entry(java.util.Map.Entry) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletActionContext(org.apache.struts2.ServletActionContext) ActionContext(com.opensymphony.xwork2.ActionContext) Map(java.util.Map) Template(org.beetl.core.Template) GroupTemplate(org.beetl.core.GroupTemplate)

Aggregations

GroupTemplate (org.beetl.core.GroupTemplate)31 Configuration (org.beetl.core.Configuration)22 Template (org.beetl.core.Template)19 ClasspathResourceLoader (org.beetl.core.resource.ClasspathResourceLoader)10 FileResourceLoader (org.beetl.core.resource.FileResourceLoader)7 IOException (java.io.IOException)5 Test (org.testng.annotations.Test)5 Map (java.util.Map)4 Properties (java.util.Properties)4 StringTemplateResourceLoader (org.beetl.core.resource.StringTemplateResourceLoader)4 WebRender (org.beetl.ext.web.WebRender)4 HashMap (java.util.HashMap)3 InputStream (java.io.InputStream)2 List (java.util.List)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 WebAppResourceLoader (org.beetl.core.resource.WebAppResourceLoader)2 ToolUtil (com.ikoori.vip.server.core.util.ToolUtil)1 ActionContext (com.opensymphony.xwork2.ActionContext)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1