/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.opensymphony.xwork2.ActionSupport
 *  javax.servlet.http.HttpServletRequest
 *  javax.servlet.http.HttpServletResponse
 *  org.apache.commons.logging.Log
 *  org.apache.commons.logging.LogFactory
 *  org.apache.struts2.ServletActionContext
 */
package com.hst.framework.action;

import com.hst.framework.domain.JsonDomain;
import com.opensymphony.xwork2.ActionSupport;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;

public abstract class SimpleActionSupport
extends ActionSupport {
    public static Log logger = LogFactory.getLog(SimpleActionSupport.class);
    public static final String JSON = "json";
    protected JsonDomain result;

    protected String render(String text, String contentType) {
        try {
            HttpServletResponse response = ServletActionContext.getResponse();
            response.setContentType(contentType);
            response.getWriter().write(text);
        }
        catch (IOException e) {
            logger.error((Object)e.getMessage(), (Throwable)e);
        }
        return null;
    }

    protected String renderText(String text) {
        return this.render(text, "text/plain;charset=UTF-8");
    }

    protected String renderHtml(String html) {
        return this.render(html, "text/html;charset=UTF-8");
    }

    protected String renderXML(String xml) {
        return this.render(xml, "text/xml;charset=UTF-8");
    }

    protected String renderExcel(String excel) {
        return this.render(excel, "application/msexcel;charset=gbk");
    }

    protected String success(String message) {
        this.result = new JsonDomain(Boolean.TRUE, message);
        return JSON;
    }

    public JsonDomain getResult() {
        return this.result;
    }

    protected String fail(String message) {
        this.result = new JsonDomain(Boolean.FALSE, message);
        return JSON;
    }

    protected String success(String message, Object data) {
        this.result = new JsonDomain(Boolean.TRUE, message, data);
        return JSON;
    }

    protected HttpServletRequest getRequest() throws Exception {
        return ServletActionContext.getRequest();
    }
}
