Search in sources :

Example 1 with IPage

use of cn.cerc.jbean.form.IPage in project summer-mis by cn-cerc.

the class StartForms method callForm.

// 调用页面控制器指定的函数
protected void callForm(IForm form, String funcCode) throws ServletException, IOException {
    HttpServletResponse response = form.getResponse();
    HttpServletRequest request = form.getRequest();
    if ("excel".equals(funcCode)) {
        response.setContentType("application/vnd.ms-excel; charset=UTF-8");
        response.addHeader("Content-Disposition", "attachment; filename=excel.csv");
    } else
        response.setContentType("text/html;charset=UTF-8");
    Object pageOutput = "";
    String sid = request.getParameter(RequestData.appSession_Key);
    if (sid == null || sid.equals(""))
        sid = request.getSession().getId();
    Method method = null;
    long startTime = System.currentTimeMillis();
    try {
        String CLIENTVER = request.getParameter("CLIENTVER");
        if (CLIENTVER != null)
            request.getSession().setAttribute("CLIENTVER", CLIENTVER);
        // 是否拥有此菜单调用权限
        if (!Application.getPassport(form.getHandle()).passForm(form)) {
            log.warn(String.format("无权限执行 %s", request.getRequestURL()));
            throw new RuntimeException("对不起,您没有权限执行此功能!");
        }
        // 若是iphone应用商店测试,则跳过设备认证的判断,用于专用测试账号
        if (getIphoneAppstoreAccount().equals(request.getParameter("login_usr"))) {
            try {
                if (form.getClient().isPhone()) {
                    try {
                        method = form.getClass().getMethod(funcCode + "_phone");
                    } catch (NoSuchMethodException e) {
                        method = form.getClass().getMethod(funcCode);
                    }
                } else
                    method = form.getClass().getMethod(funcCode);
                pageOutput = method.invoke(form);
            } catch (PageException e) {
                form.setParam("message", e.getMessage());
                pageOutput = e.getViewFile();
            }
        } else {
            // 检验此设备是否需要设备验证码
            if (form.getHandle().getProperty(Application.userId) == null || form.passDevice() || passDevice(form)) {
                try {
                    if (form.getClient().isPhone()) {
                        try {
                            method = form.getClass().getMethod(funcCode + "_phone");
                        } catch (NoSuchMethodException e) {
                            method = form.getClass().getMethod(funcCode);
                        }
                    } else {
                        method = form.getClass().getMethod(funcCode);
                    }
                    pageOutput = method.invoke(form);
                } catch (PageException e) {
                    form.setParam("message", e.getMessage());
                    pageOutput = e.getViewFile();
                }
            } else {
                log.debug("没有进行认证过,跳转到设备认证页面");
                pageOutput = new RedirectPage(form, Application.getAppConfig().getFormVerifyDevice());
            }
        }
        // 处理返回值
        if (pageOutput != null) {
            if (pageOutput instanceof IPage) {
                IPage output = (IPage) pageOutput;
                output.execute();
            } else {
                log.warn(String.format("%s pageOutput is not IPage: %s", funcCode, pageOutput));
                JspPage output = new JspPage(form);
                output.setJspFile((String) pageOutput);
                output.execute();
            }
        }
    } catch (Exception e) {
        Throwable err = e.getCause();
        if (err == null)
            err = e;
        ErrorPage opera = new ErrorPage(form, err);
        opera.execute();
    } finally {
        if (method != null) {
            long timeout = 1000;
            Webpage webpage = method.getAnnotation(Webpage.class);
            if (webpage != null)
                timeout = webpage.timeout();
            checkTimeout(form, funcCode, startTime, timeout);
        }
    }
}
Also used : PageException(cn.cerc.jbean.core.PageException) ErrorPage(cn.cerc.jmis.page.ErrorPage) HttpServletResponse(javax.servlet.http.HttpServletResponse) Method(java.lang.reflect.Method) JspPage(cn.cerc.jmis.page.JspPage) PageException(cn.cerc.jbean.core.PageException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) HttpServletRequest(javax.servlet.http.HttpServletRequest) IPage(cn.cerc.jbean.form.IPage) Webpage(cn.cerc.jmis.form.Webpage) RedirectPage(cn.cerc.jmis.page.RedirectPage)

Example 2 with IPage

use of cn.cerc.jbean.form.IPage in project summer-mis by cn-cerc.

the class StartApp method doFilter.

// private static final Logger log = Logger.getLogger(AppStart.class);
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse resp = (HttpServletResponse) response;
    String uri = req.getRequestURI();
    // 处理默认首页问题
    if (uri.equals("/")) {
        if (req.getParameter(ClientDevice.deviceId_key) != null)
            req.getSession().setAttribute(ClientDevice.deviceId_key, req.getParameter(ClientDevice.deviceId_key));
        if (req.getParameter(ClientDevice.deviceType_key) != null)
            req.getSession().setAttribute(ClientDevice.deviceType_key, req.getParameter(ClientDevice.deviceType_key));
        AppConfig conf = Application.getAppConfig();
        resp.sendRedirect(String.format("/%s/%s", conf.getPathForms(), conf.getFormWelcome()));
        return;
    } else if (uri.equals("/MobileConfig")) {
        if (req.getParameter(ClientDevice.deviceId_key) != null)
            req.getSession().setAttribute(ClientDevice.deviceId_key, req.getParameter(ClientDevice.deviceId_key));
        if (req.getParameter(ClientDevice.deviceType_key) != null)
            req.getSession().setAttribute(ClientDevice.deviceType_key, req.getParameter(ClientDevice.deviceType_key));
        try {
            IForm form = Application.getBean("MobileConfig", IForm.class);
            form.setRequest((HttpServletRequest) request);
            form.setResponse((HttpServletResponse) response);
            try (AppHandle handle = new AppHandle()) {
                handle.setProperty(Application.sessionId, req.getSession().getId());
                form.setHandle(handle);
            }
            IPage page = form.execute();
            page.execute();
        } catch (Exception e) {
            resp.getWriter().print(e.getMessage());
        }
        return;
    }
    chain.doFilter(req, resp);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AppConfig(cn.cerc.jbean.core.AppConfig) IPage(cn.cerc.jbean.form.IPage) HttpServletResponse(javax.servlet.http.HttpServletResponse) IForm(cn.cerc.jbean.form.IForm) AppHandle(cn.cerc.jbean.core.AppHandle) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 3 with IPage

use of cn.cerc.jbean.form.IPage in project summer-mis by cn-cerc.

the class MarkdownPanel method setFileName.

public void setFileName(String fileName) {
    this.fileName = fileName;
    if (this.getOwner() instanceof IPage) {
        IPage page = (IPage) this.getOwner();
        MarkdownDoc doc = new MarkdownDoc(page.getForm());
        doc.setOutHtml(true);
        this.setReadme(doc.getContext("/docs/" + fileName, "(暂未编写相应的说明)"));
    }
}
Also used : IPage(cn.cerc.jbean.form.IPage)

Aggregations

IPage (cn.cerc.jbean.form.IPage)3 IOException (java.io.IOException)2 ServletException (javax.servlet.ServletException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 AppConfig (cn.cerc.jbean.core.AppConfig)1 AppHandle (cn.cerc.jbean.core.AppHandle)1 PageException (cn.cerc.jbean.core.PageException)1 IForm (cn.cerc.jbean.form.IForm)1 Webpage (cn.cerc.jmis.form.Webpage)1 ErrorPage (cn.cerc.jmis.page.ErrorPage)1 JspPage (cn.cerc.jmis.page.JspPage)1 RedirectPage (cn.cerc.jmis.page.RedirectPage)1 Method (java.lang.reflect.Method)1