package com.app.admin.common.ueditor.servlet;

import com.app.admin.common.ueditor.ActionEnter;
import org.apache.commons.lang.StringUtils;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 百度编辑器文件上传(管理)入口
 */
public class BaiduUeditorServlet extends HttpServlet {

    private String configRootPath;

    public void init(ServletConfig config) {
        configRootPath = config.getInitParameter("configRootPath");
    }

    protected void doGet(HttpServletRequest request,
                         HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setHeader("Content-Type", "text/html");

        if (StringUtils.isBlank(configRootPath)) {
            configRootPath = "static/common/plugins/ueditor";
        }
        response.getWriter().write(new ActionEnter(request, configRootPath).exec());
    }

    protected void doPost(HttpServletRequest request,
                          HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
