code.jsp 4.87 KB
<%@ page import="com.api.integration.util.FileUtil" %>
<%@ page import="com.api.integration.util.JavaCompiler" %>
<%@ page import="weaver.interfaces.workflow.action.jc.util.FileHelper" %>
<%@ page import="java.io.File" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%--
  Created by IntelliJ IDEA.
  User: SJZ
  Date: 2017/11/16
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ include file="/systeminfo/init_wev8.jsp" %>
<%@ taglib uri="/WEB-INF/weaver.tld" prefix="wea" %>
<%

    String fileName = Util.null2String(request.getParameter("fileName"));
    String resid = Util.null2String(request.getParameter("resid"));

    String javacode = null;
    if (!fileName.isEmpty() && !resid.isEmpty()) {
        String filePath = JavaCompiler.getJavaSrcPath(resid,fileName);
        File file = new File(filePath);
        if(file.isFile()) {
            javacode = FileUtil.read(filePath);
        }
    }
    if(javacode == null){
        //加载action模板
        String filepath = GCONST.getRootPath() + "/integration/resource/template/EsbOnline.tpl";
        String name = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());
        javacode = FileHelper.loadFile(filepath, "UTF-8");
        javacode = javacode.replace("$packageName", "package_" + name);
        javacode = javacode.replace("$className", "class_" + name);
    }
%>

<html>
<script src="/integration/js/codemirror/lib/codemirror_wev8.js"></script>
<script src="/integration/js/codemirror/mode/clike/clike_wev8.js"></script>
<link rel="stylesheet" href="/integration/js/codemirror/lib/codemirror_wev8.css"/>
<link rel="stylesheet" href="/integration/js/codemirror/theme/eclipse_wev8.css"/>

<body>
<div class="zDialog_div_content" style="height:580px;overflow-y:auto;">
    <FORM id="addFrmMain" name="addFrmMain" method=post>
        <input type="hidden" name="fileName" value="<%=fileName%>">
        <input type="hidden" name="resid" value="<%=resid%>">
        <wea:layout>
            <wea:group context='JavaCode'
                       attributes="{'samePair':'SetInfo','groupOperDisplay':'none','itemAreaDisplay':'block'}">
                <wea:item attributes="{'colspan':'2','isTableList':'true'}">
                    <div>
                        <textarea id="javaCode" name="javaCode"><%=javacode %></textarea>
                    </div>
                </wea:item>
            </wea:group>
        </wea:layout>
    </FORM>
</div>
</body>
</html>
<script language="javascript">
    var editor;
    jQuery(document).ready(function () {
        editor = CodeMirror.fromTextArea(document.getElementById("javaCode"), {
            lineNumbers: true,
            theme: "eclipse",
            indentUnit: 4,
            mode: "text/x-java"
        });
    });

    function forbiddenPage() {
        $("<div class=\"datagrid-mask\" style=\"position:fixed;z-index:2;opacity:0.4;filter:alpha(opacity=40);BACKGROUND-COLOR:#fff;\"></div>").css({
            display: "block",
            width: "100%",
            height: "100%",
            top: 0,
            left: 0
        }).appendTo("body");
        $("<div class=\"datagrid-mask-msg\" style=\"background:#fff;position:fixed;z-index:3;padding: 10px;padding-top: 6px;padding-bottom: 6px;border: 1px solid;\"></div>").html("<%=SystemEnv.getHtmlLabelName(25666,user.getLanguage())%>").appendTo("body").css({
            display: "block",
            left: ($(document.body).outerWidth(true) - 190) / 2,
            top: ($(window).height() - 45) / 2
        });
    }

    function releasePage() {
        $(".datagrid-mask,.datagrid-mask-msg").hide();
    }

    /**
     * 表单数据提交
     */
    function submitData(diag, func) {
        forbiddenPage();
        try {
            var url = "/api/integration/esb/service/compile";

            $("#javaCode").text(editor.getValue());
            $.ajax({
                type: "post",
                url: url,
                data: $("#addFrmMain").serialize(),
                success: function (data) {
                    data = jQuery.parseJSON(data);

                    //code == 100表示保存成功,其它都是失败。
                    if ("100" == data.code) {
                        func(data["data"]);
                        releasePage();
                        if (diag) {
                            diag.close();
                        }
                    } else {
                        if(data["description"]){
                            top.Dialog.alert(data.description, releasePage, 500, 300);
                        } else {
                            top.Dialog.alert("<%=SystemEnv.getHtmlLabelName(132169,user.getLanguage())%>");
                        }
                    }
                },
                error: function (jqXHR) {
                    top.Dialog.alert(jqXHR.statusText, releasePage);
                }
            });
        } catch (e) {
            console.log(e);
        }
    }
</script>