Example #1
0
  // Velocity init
  public static void initVelocity() {
    if (velocityCatch == null) {
      System.out.println("init VM");
      velocityCatch = new Object();

      Properties props = new Properties();
      props.setProperty("input.encoding", "UTF-8");
      props.setProperty("output.encoding", "UTF-8");

      if (getConfig().getChild("vmtemplatepath") != null) {
        props.setProperty("file.resource.loader.path", getConfig().getChildText("vmtemplatepath"));
      }
      if (System.getProperty("vmtemplatepath") != null) {
        props.setProperty("file.resource.loader.path", System.getProperty("vmtemplatepath"));
        // Velocity.setProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH,
        // System.getProperty("vmtemplatepath"));//oder new FIle()?
      }
      System.out.println("vmtemplatepath=" + props.getProperty("vmtemplatepath"));
      try {
        Velocity.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM, VeloLog.getInstance());
        Velocity.init(props);
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
  }
  protected void handleRequest(final HttpRequest request, final HttpResponse response)
      throws HttpException, IOException, JSONException, CalicoAPIErrorException {
    try {
      GUITemplate gt = new GUITemplate("command_help.vm");
      gt.setSection("console");

      // gt.put("test.param.yar", "this is a big test");
      gt.getOutput(response);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Example #3
0
  @SuppressWarnings("unchecked")
  private void handleAction(
      RenderVelocityAction action, String cmd, Vector[] args, HttpServletRequest request) {
    if (action != null) {
      // add parameter from path
      for (int p = 0; p < args[0].size(); p++) {
        action.putParam((String) args[0].get(p), (String) args[1].get(p));
      }

      VelocityContext c = new VelocityContext();
      try {
        c.put("action", action);
        c.put("encoding", action.encoding);
        c.put("cmd", cmd);

        // c.put("au", action.user);

        c.put("reqaddress", request.getRemoteAddr());
        c.put("scheme", request.getScheme());
        c.put("querystring", request.getQueryString());
        if (c.get("querystring") == null) {
          c.put("querystring", "");
        }

        String requesturl = request.getRequestURL().toString();

        // c.put("mid", ma.user.mandantid);
        c.put("request", request);
        c.put("requesturl", requesturl);
        c.put("server", request.getServerName());
        c.put("port", request.getServerPort());

        String ref = request.getHeader("Referer");
        if (ref == null) {
          ref = "#";
        }
        c.put("referer", ref);

        // process and render template
        action.process(c);

      } catch (Exception ex) {
        ex.printStackTrace();
        //	        		action.makeErrorOutput("Internal Error", null, c);
      }
    }
  }
Example #4
0
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {
    String qryDoc;
    String username;
    username = "";
    PrintWriter out = response.getWriter();
    request.setCharacterEncoding("GBK");
    try {
      request.getSession().setMaxInactiveInterval(60000);
      username =
          request.getSession().getAttribute("USERNAME") != null
              ? request.getSession().getAttribute("USERNAME").toString()
              : "";
    }
    // Misplaced declaration of an exception variable
    catch (Exception e) {
      e.printStackTrace();
    }
    if (request.getPathInfo() == null)
      qryDoc = getServletConfig().getServletContext().getRealPath(request.getServletPath());
    else qryDoc = request.getPathTranslated();
    try {
      WebApp app = new WebApp(FunctionLib.openFile(qryDoc));
      String path = getServletContext().getRealPath("/");
      VelocityEngine ve = new VelocityEngine();
      ve.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path);
      VelocityContext context = new VelocityContext();

      BufferedOutputStream outb = null;
      InputStream in = null;
      String msg = null;

      ve.init();

      ToNcEngine mainMod = new ToNcEngine(request, response, app, context, getServletConfig());
      // 处理用户请求
      Vector vsqls = app.getSqls();
      if (app.getSqlType().equals("select")) {
        List ldata = null;
        for (int i = 0; i < vsqls.size(); i++) {
          ldata = new ArrayList();
          ldata = mainMod.getData(vsqls.elementAt(i).toString(), app.getEscape());
          context.put(vsqls.elementAt(i).toString(), ldata);
        }
        context.put("CGI_url", request.getRequestURL().toString());
      }
      Template t = ve.getTemplate(app.getTemplate());
      StringWriter sw = new StringWriter();
      t.merge(context, sw);
      System.out.println("aaaaaaaa" + sw.toString());
      // String url = "http://10.7.3.225:8080/service/XchangeServlet";
      URL realURL = new URL(server);
      HttpURLConnection connection = (HttpURLConnection) realURL.openConnection();
      connection.setDoOutput(true);
      connection.setRequestProperty("Content-type", "text/xml");
      connection.setRequestMethod("POST");
      outb = new BufferedOutputStream(connection.getOutputStream());
      outb.write(sw.toString().getBytes());
      outb.close();
      in = new DataInputStream(connection.getInputStream());
      byte[] b = new byte[in.available()];
      in.read(b);
      msg = new String(b, "UTF-8");
      // System.out.println("返回信息:"+msg);
      Document resDoc = DocumentHelper.parseText(msg);

      List resCode_list = resDoc.selectNodes("ufinterface/sendresult/resultcode");
      List resDes_list = resDoc.selectNodes("ufinterface/sendresult/resultdescription");
      // 从回执信息中获得错误信息详细描述
      String invaliddoc_value = null;
      returnMsg.clear();
      for (Object obj : resDes_list) {
        Element invaliddoc = (Element) obj;
        invaliddoc_value = invaliddoc.getText();
        System.out.println("返回信息:" + invaliddoc_value);
        // 将回执信息赋值给静态变量returnMsg
        returnMsg.add(invaliddoc_value);
      }
      // 从回执信息中获取错误信息编号
      List<String> resCodeList = new ArrayList<String>();
      for (Object obj : resCode_list) {
        Element resCode = (Element) obj;
        String resCode_value = resCode.getText();
        // System.out.println("失败信息:"+resCode_value);
        // 只有resCode编号为1时才是正常处理完毕,没有错误
        if (!resCode_value.equals("1")) {
          resCodeList.add(resCode_value);
        }
      }
      if (resCodeList.size() == 0) {
        if (app.getUrl().equals("qbTonc")) {
          out.println("OK");
          out.close();
        } else {
          if (!app.getSuccessMsg().equals("")) invaliddoc_value = app.getSuccessMsg();
          out.println("<html>\n");
          out.println("<head>\n");
          out.println(
              "<script type=\"text/javascript\" language=\"JavaScript\" src=\"../js/title.js\"></script>\n");
          out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">\n");
          out.println("<script>");
          out.println(FunctionLib.gbToIso("alert('" + invaliddoc_value + "')"));
          out.println("window.location='" + app.getUrl() + "'");
          out.println("</script>");
          out.println("</head>\n");
          out.println("  </html>\n");
          out.close();
        }
      } else {
        if (!app.getFailMsg().equals("")) invaliddoc_value = app.getFailMsg();
        out.println("<html>\n");
        out.println("<head>\n");
        out.println(
            "<script type=\"text/javascript\" language=\"JavaScript\" src=\"../js/title.js\"></script>\n");
        out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">\n");
        out.println("<script>");
        out.println(FunctionLib.gbToIso("alert('" + invaliddoc_value + "')"));
        out.println("window.history.go(-1);");
        out.println("</script>");
        out.println("</head>\n");
        out.println("  </html>\n");
        out.close();
      }
    } catch (Exception e) {
      System.out.println(e.getMessage());
      e.printStackTrace();
      out.println("<html>\n");
      out.println("<head>\n");
      out.println(
          "<script type=\"text/javascript\" language=\"JavaScript\" src=\"../js/title.js\"></script>\n");
      out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">\n");
      out.println("<script>");
      out.println(FunctionLib.gbToIso("alert('提取数据时出错!')"));
      out.println("</script>");
      out.println("</head>\n");
      out.println("  </html>\n");
      out.close();
    }
  }