예제 #1
0
 public Frontend(DataService ds) {
   user = new User(ds);
   forum = new Forum(ds);
   thread = new Thread(ds);
   utils = new Utils(ds);
   post = new Post(ds);
   utils.exec("clear", null);
 }
예제 #2
0
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    counter++;
    response.setContentType("text/html;charset=utf-8");
    response.setStatus(HttpServletResponse.SC_OK);

    String[] tokens = parseUrl(request.getPathInfo()); //  __/db/api/{{entity}}/{{method}}/

    String line = request.getReader().readLine();
    if ((tokens.length >= 3) && tokens[3].equals("clear")) {
      utils.exec("clear", null);
      response.getWriter().print("{code:0, \"message\":\"cleared\"}");
    } else if (tokens.length > 4) {
      String result = executeApiQuery(tokens[3], tokens[4], line);
      response.getWriter().print(result);
    } else {
      response.getWriter().print("{code:1, \"message\":\"invalid request\"}");
    }
  }
예제 #3
0
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    counter++;
    response.setContentType("text/html;charset=utf-8");
    response.setStatus(HttpServletResponse.SC_OK);

    String[] tokens = parseUrl(request.getPathInfo());
    String decodedQuery = null;
    if (request.getQueryString() != null) {
      decodedQuery = URLDecoder.decode(request.getQueryString(), "UTF-8");
    }
    if ((tokens.length >= 3) && tokens[3].equals("clear")) {
      utils.exec("clear", null);
      response.getWriter().print("{code:0, \"message\":\"cleared\"}");
    } else if (tokens.length > 4) {
      String result = executeApiQuery(tokens[3], tokens[4], decodedQuery);
      response.getWriter().print(result);
    } else {
      response.getWriter().print("{code:1, \"message\":\"invalid url\"}");
    }
  }
예제 #4
0
 private String executeApiQuery(String entity, String method, String content) {
   String result = null;
   switch (entity) {
     case "forum":
       result = forum.exec(method, content);
       break;
     case "post":
       result = post.exec(method, content);
       break;
     case "user":
       result = user.exec(method, content);
       break;
     case "thread":
       result = thread.exec(method, content);
       break;
     case "util":
       result = utils.exec(method, content);
       break;
   }
   if (result != null) return result;
   else return ERROR;
 }