/*
 * Generated by the Jasper component of Apache Tomcat
 * Version: ......
 * Generated at: 2020-02-24 09:59:15 UTC
 * Note: The last modified time of this file was set to
 *       the last modified time of the source file after
 *       generation to assist with modification tracking.
 */
package org.apache.jsp.js;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;

public final class zrpc_js_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final javax.servlet.jsp.JspFactory _jspxFactory =
          javax.servlet.jsp.JspFactory.getDefaultFactory();

  private static java.util.Map<java.lang.String,java.lang.Long> _jspx_dependants;

  private volatile javax.el.ExpressionFactory _el_expressionfactory;
  private volatile org.apache.tomcat.InstanceManager _jsp_instancemanager;

  public java.util.Map<java.lang.String,java.lang.Long> getDependants() {
    return _jspx_dependants;
  }

  public javax.el.ExpressionFactory _jsp_getExpressionFactory() {
    if (_el_expressionfactory == null) {
      synchronized (this) {
        if (_el_expressionfactory == null) {
          _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
        }
      }
    }
    return _el_expressionfactory;
  }

  public org.apache.tomcat.InstanceManager _jsp_getInstanceManager() {
    if (_jsp_instancemanager == null) {
      synchronized (this) {
        if (_jsp_instancemanager == null) {
          _jsp_instancemanager = org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(getServletConfig());
        }
      }
    }
    return _jsp_instancemanager;
  }

  public void _jspInit() {
  }

  public void _jspDestroy() {
  }

  public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
        throws java.io.IOException, javax.servlet.ServletException {

    final javax.servlet.jsp.PageContext pageContext;
    javax.servlet.http.HttpSession session = null;
    final javax.servlet.ServletContext application;
    final javax.servlet.ServletConfig config;
    javax.servlet.jsp.JspWriter out = null;
    final java.lang.Object page = this;
    javax.servlet.jsp.JspWriter _jspx_out = null;
    javax.servlet.jsp.PageContext _jspx_page_context = null;


    try {
      response.setContentType("text/javascript;charset=utf-8");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("/***************************************************************************************************************\r\n");
      out.write(" * 作者：zengjun\r\n");
      out.write(" * \r\n");
      out.write(" *   基于json , jquery 的RPC方案 \r\n");
      out.write(" * \r\n");
      out.write(" *  示例：同步调用\r\n");
      out.write(" *  　　　 var  ret= $rpc( \"wiseoa.Demo\", \"hello\", p);\r\n");
      out.write(" *                      alert ( ret.success);\r\n");
      out.write(" * \r\n");
      out.write(" * 　　异步调用\r\n");
      out.write(" *                      $rpc( \"wiseoa.Demo\", \"hello\", p , callback);\r\n");
      out.write(" *                      function callback(data)\r\n");
      out.write(" *                      {\r\n");
      out.write(" *                          var  ret=  JSON.parse(data);\r\n");
      out.write(" *                          alert ( ret.success);\r\n");
      out.write(" *                      }\r\n");
      out.write(" * \r\n");
      out.write(" ***************************************************************************************************************/ \r\n");
      out.write("\r\n");
      out.write("\r\n");

	String subpath = request.getContextPath();
	if (subpath.equals("/")) subpath = "";
    out.println("var innervar_RootPath =getRootPath()+ '" +subpath + "';");

      out.write("\r\n");
      out.write("\r\n");
      out.write("//js获取项目根路径，如： http://localhost:8083/uimcardprj\r\n");
      out.write("function getRootPath(){\r\n");
      out.write("    //获取当前网址，如： http://localhost:8083/uimcardprj/share/meun.jsp\r\n");
      out.write("    var curWwwPath=window.document.location.href;\r\n");
      out.write("    //获取主机地址之后的目录，如： uimcardprj/share/meun.jsp\r\n");
      out.write("    var pathName=window.document.location.pathname;\r\n");
      out.write("    \r\n");
      out.write("    var pos=curWwwPath.indexOf(pathName);\r\n");
      out.write("    //获取主机地址，如： http://localhost:8083\r\n");
      out.write("    var localhostPaht=curWwwPath.substring(0,pos);\r\n");
      out.write("     \r\n");
      out.write("    return localhostPaht;\r\n");
      out.write("}\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("function $E(id) { \r\n");
      out.write("\t\r\n");
      out.write("\tvar ret= document.getElementById(id);\r\n");
      out.write("\tif(!ret) ret=document.getElementsByName(id)[0];\r\n");
      out.write("\treturn ret;\r\n");
      out.write("}\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("var $zrpc_inner_callback_data=null;\r\n");
      out.write("var $zrpc_inner_callback_raw_data=null;\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("/*\r\n");
      out.write(" *  当不提供　callback参数时，表示是同步调用，$rpc 的返回值即rpc调用的返回值\r\n");
      out.write(" *  如果提供了 callback参数，那么$rpc 返回\"\", 数据将在回调函数里以参数形式提供\r\n");
      out.write(" */\r\n");
      out.write("function $rpc( className , method, jsonParamString, callback)\r\n");
      out.write("{\r\n");
      out.write("\tvar paramString=jsonParamString;\r\n");
      out.write("    if (jsonParamString==undefined )  paramString='{ }';  //可能没有参数\r\n");
      out.write("\tif ( jsonParamString instanceof Object)  paramString= JSON.toString(jsonParamString);\r\n");
      out.write("\t\r\n");
      out.write("\tif ( callback===undefined) \r\n");
      out.write("\t{\r\n");
      out.write("\t     $.ajaxSettings.async=false;//同步\r\n");
      out.write("\t     $zrpc_inner_callback_data=null;\r\n");
      out.write("\t     $.post(innervar_RootPath+\"/zrpc.jsp\", { classname\t\t\t: className, \r\n");
      out.write("\t                                          methodname\t: method , \r\n");
      out.write("\t                                          parameter\t\t\t: paramString \r\n");
      out.write("\t                                       }, \r\n");
      out.write("\t                                      $zrpc_inner_callback );\r\n");
      out.write("\t     return $zrpc_inner_callback_data;\r\n");
      out.write("\t}else\r\n");
      out.write("\t{\r\n");
      out.write("\t\t$.ajaxSettings.async=true; //异步\r\n");
      out.write("\t\t$.post(innervar_RootPath+\"/zrpc.jsp\", { classname\t\t:className, \r\n");
      out.write("\t\t                                    methodname\t:method , \r\n");
      out.write("\t\t                                    parameter\t\t:paramString\r\n");
      out.write("\t\t                                  }, \r\n");
      out.write("\t\t                                  callback );\r\n");
      out.write("\t\treturn \"\"; \r\n");
      out.write("\t}\r\n");
      out.write(" \t\r\n");
      out.write("}\r\n");
      out.write("\r\n");
      out.write("//同步调用使用本函数做回调函数，并把结果放到全局变量中，供$rpc函数做返回值\r\n");
      out.write("function $zrpc_inner_callback( data)\r\n");
      out.write("{ \t\r\n");
      out.write("\tvar  d=  JSON.parse(data);\r\n");
      out.write("\t$zrpc_inner_callback_data =d;\r\n");
      out.write("}\r\n");
      out.write("\r\n");
      out.write("function $zrpc_inner_raw_callback( data)\r\n");
      out.write("{ \r\n");
      out.write("\t$zrpc_inner_callback_raw_data =data;\r\n");
      out.write("}\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("/**\r\n");
      out.write(" * 把data中的数据复制record中 ,注意中复制一层数据，即data中的数据如果又是一个Object，那么不处理\r\n");
      out.write(" * @data 是一个js对象\r\n");
      out.write(" * @record 是一个　Ext.data.Record对象\r\n");
      out.write(" */\r\n");
      out.write("function CopyToExtRecord( data , record)\r\n");
      out.write("{\r\n");
      out.write("    // varName 是data中的变量名\r\n");
      out.write("     for (varName  in data) \r\n");
      out.write("     {\r\n");
      out.write("           varValue = data[varName];\r\n");
      out.write("           if ( varValue instanceof Object) continue;\r\n");
      out.write("           if ( varValue instanceof Array)  continue;\r\n");
      out.write("           record.set ( varName , varValue);\r\n");
      out.write("     }\r\n");
      out.write("}\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("function  getStringFromURL( url )\r\n");
      out.write("{ \r\n");
      out.write("\t$.ajaxSettings.async=false;//同步\r\n");
      out.write("\t$zrpc_inner_callback_data=null;\r\n");
      out.write("\t$.post(url , {},  $zrpc_inner_raw_callback );\r\n");
      out.write("\treturn $zrpc_inner_callback_raw_data;\r\n");
      out.write("}\r\n");
      out.write("\r\n");
      out.write("//示例：alert( runTask(\"testdd\" ,{ a:'浙B23456' }) );\r\n");
      out.write("// 仅当根目录下的jsp中可以使用 runTask调用任务调度，如果是子目录中，那么下面的 'wiseoa.flow.engine.FlowEngine'路径就不对了\r\n");
      out.write("function runTask( task , param)\r\n");
      out.write("{\r\n");
      out.write("\t param.wiseoa_task_code=task;\r\n");
      out.write("\t var ret=$rpc( 'wiseoa.flow.engine.FlowEngine', 'runTask', param);\r\n");
      out.write("\t return ret.data;\r\n");
      out.write("}\r\n");
      out.write("\r\n");
      out.write("\r\n");
    } catch (java.lang.Throwable t) {
      if (!(t instanceof javax.servlet.jsp.SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try {
            if (response.isCommitted()) {
              out.flush();
            } else {
              out.clearBuffer();
            }
          } catch (java.io.IOException e) {}
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
        else throw new ServletException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
