Beispiel #1
0
  /** 更新pattern */
  public void update() throws Exception {
    Pattern p = new Pattern();
    try {
      p.setId(Integer.parseInt(request.getParameter("id")));
      p.setName(request.getParameter("name"));
      p.setExpression(request.getParameter("expression"));
      p.setWarning(request.getParameter("warning"));
      p.setCategory(request.getParameter("category"));
      p.setScope(request.getParameter("scope"));
      p.setExample(request.getParameter("example"));
      p.setPriority(Integer.parseInt(request.getParameter("priority")));
    } catch (Exception e) { // 参数错误
      error("Pattern Update Fail:" + e.getMessage());
      return;
    }

    PatternDao dao = new PatternDaoImpl();
    boolean bResult = false;
    try {
      bResult = dao.update(p);
    } catch (Exception e) { // 产生异常
      error("Pattern Update Fail:" + e.getMessage());
      return;
    }
    if (bResult) {
      Json j = new Json(1, "Pattern Update Success");
      j.setData(p.getTBJsonNode());
      echo(j.toString());
    } else {
      error("Pattern Update Fail");
    }
  }
Beispiel #2
0
  /** 上传ruleset */
  public void upRuleset() throws Exception {
    /**
     * form中的enctype必须是multipart/... 组件提供方法检测form表单的enctype属性 在isMultipartContent方法中同时检测了是否是post提交
     * 如果不是post提交则返回false
     */
    if (ServletFileUpload.isMultipartContent(request)) {
      String RulePath = (String) application.getAttribute("Ruleset");
      DiskFileItemFactory factory = new DiskFileItemFactory();
      factory.setRepository(new File(RulePath + "tmp")); // 临时文件目录
      // 内存最大占用
      factory.setSizeThreshold(1024000);
      ServletFileUpload sfu = new ServletFileUpload(factory);
      // 单个文件最大值byte
      sfu.setFileSizeMax(102400000);
      // 所有上传文件的总和最大值byte
      sfu.setSizeMax(204800000);

      List<FileItem> items = null;
      try {
        items = sfu.parseRequest(request);
      } catch (SizeLimitExceededException e) {
        error("size limit exception!");
        return;
      } catch (Exception e) {
        error("Exception:" + e.getMessage());
        return;
      }

      Json j = new Json(1, "ok");
      JsonObjectNode data = j.createData();
      JsonArrayNode files = new JsonArrayNode("filename");
      data.addChild(files);

      Iterator<FileItem> iter = (items == null) ? null : items.iterator();
      while (iter != null && iter.hasNext()) {
        FileItem item = (FileItem) iter.next();
        // 文件域
        if (!item.isFormField()) {
          String fileName = item.getName();
          int index = fileName.lastIndexOf("\\");
          if (index < 0) index = 0;
          fileName = fileName.substring(index);
          if (!fileName.endsWith(".xml")) fileName += ".xml";
          BufferedInputStream in = new BufferedInputStream(item.getInputStream());
          BufferedOutputStream out =
              new BufferedOutputStream(new FileOutputStream(new File(RulePath + fileName)));
          Streams.copy(in, out, true);
          files.addItem(new JsonLeafNode("", fileName));
        }
      }

      echo(j.toString());
    } else {
      error("enctype error!");
    }
  }
Beispiel #3
0
 /** 获取指定id的pattern */
 public void get() throws Exception {
   try {
     int id = Integer.parseInt(request.getParameter("id"));
     PatternDao dao = new PatternDaoImpl();
     Pattern p = dao.get(id);
     Json j = new Json(1, "ok");
     j.setData(p.getObjectNode("data"));
     echo(j.toString());
   } catch (Exception e) {
     error("Exception:" + e.getMessage());
   }
 }
Beispiel #4
0
 /** 获得rulesets */
 public void rulesets() throws Exception {
   Json j = new Json(1);
   JsonObjectNode data = j.createData();
   JsonArrayNode rules = new JsonArrayNode("rules");
   data.addChild(rules);
   List<String> files =
       ToolUtil.getFileFromPath((String) application.getAttribute("Ruleset"), "xml");
   Iterator<String> it = files.iterator();
   while (it.hasNext()) {
     rules.addItem(new JsonLeafNode("", it.next()));
   }
   echo(j.toString());
 }