// Copyright (c) 2013, Webit Team. All Rights Reserved.
package webit.script.support.jodd.madvoc;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jodd.madvoc.ActionRequest;
import jodd.madvoc.ScopeType;
import jodd.madvoc.component.MadvocController;
import jodd.madvoc.meta.In;
import jodd.madvoc.result.ActionResult;
import webit.script.web.ServletUtil;
import webit.script.web.WebEngineManager;
import webit.script.web.WebEngineManager.ServletContextProvider;

/**
 *
 * @author Zqq
 */
public class WebitScriptResult extends ActionResult implements ServletContextProvider {

    public static final String NAME = "wtl";
    //
    @In(scope = ScopeType.CONTEXT)
    protected MadvocController madvocController;
    //
    protected final WebEngineManager engineManager;

    public WebitScriptResult() {
        super(NAME);
        this.engineManager = new WebEngineManager(this);

        Map<String, Object> settings = new HashMap<String, Object>(4);
        settings.put("webit.script.Engine.appendLostFileNameExtension", Boolean.TRUE);
        this.engineManager.setExtraSettings(settings);
    }

    public ServletContext getServletContext() {
        return this.madvocController.getApplicationContext();
    }

    public void setConfigPath(String configPath) {
        this.engineManager.setConfigPath(configPath);
    }

    public void resetEngine() {
        this.engineManager.resetEngine();
    }

    @Override
    public void render(ActionRequest actionRequest, Object resultObject, String resultValue, String resultPath) throws Exception {
        final HttpServletRequest request = actionRequest.getHttpServletRequest();
        final HttpServletResponse response = actionRequest.getHttpServletResponse();
        final Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("request", request);
        parameters.put("response", response);
        ServletUtil.exportAttributes(parameters, request);
        this.engineManager.renderTemplate(resultPath, parameters, response);
    }
}

@@ -872,24 +872,59 @@
 oller;%0D%0A
+    protected String contentType;%0D%0A
     //%0D%0A
     prot
@@ -911,24 +911,24 @@
 e;%0D%0A    //%0D%0A
-
     protecte
@@ -1424,32 +1424,136 @@
 xt();%0D%0A    %7D%0D%0A%0D%0A
+    public void setContentType(String contentType) %7B%0D%0A        this.contentType = contentType;%0D%0A    %7D%0D%0A%0D%0A
     public void 
@@ -1963,24 +1963,24 @@
 Request();%0D%0A
-
         fina
@@ -2049,24 +2049,122 @@
 esponse();%0D%0A
+        if (contentType != null) %7B%0D%0A            response.setContentType(contentType);%0D%0A        %7D%0D%0A
         fina

Update WebitScriptResult for jodd-madvoc