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);
 }
  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\"}");
    }
  }
  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\"}");
    }
  }
 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;
 }