/** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    if (toSearchIn == null) {
      response.sendError(
          HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
          "Internal error, could not find object to search.");
      return;
    }

    String searchTerm = request.getParameter("term");
    String whereToSearch = request.getParameter("whereToSearch");
    String samples = request.getParameter("samples");
    String whichSamples = request.getParameter("whichSamples");
    if (whereToSearch == null || samples == null || whichSamples == null) {
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Problem in parameters.");
      return;
    }
    if (searchTerm == null) {
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Problem in search term.");
      return;
    }

    if (searchTerm.length() < 3) {
      response.sendError(
          HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Please search for 3 chars or more.");
      return;
    }

    boolean searchAll = false;
    boolean searchOnlyComments = false;
    boolean searchOnlyContent = false;

    boolean searchEverywhereInSample = false;
    boolean searchOnlyInSample = false;

    Integer sample = null;

    if (whichSamples.equals("-1")) sample = -1;
    else sample = Integer.parseInt(whichSamples);

    if (whereToSearch.equals("-1")) searchAll = true;
    else if (whereToSearch.equals("0")) searchOnlyComments = true;
    else searchOnlyContent = true;

    if (samples.equals("-1")) searchEverywhereInSample = true;
    else if (samples.equals("0")) searchOnlyInSample = true;
    if (!searchTerm.startsWith("%")) {
      searchTerm = "%" + searchTerm;
    }
    if (!searchTerm.endsWith("%")) {
      searchTerm = searchTerm + "%";
    }
    IPageWrapper resultWrapper =
        Focal.performSearch(
            toSearchIn,
            searchTerm,
            sample,
            searchAll,
            searchOnlyComments,
            searchOnlyContent,
            searchEverywhereInSample,
            searchOnlyInSample);
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String responseText = generateHttpResponse(resultWrapper, searchTerm.split("%"));
    System.out.println(responseText);
    out.println(responseText);
  }
 public static boolean makeSureStoryExists(Integer ID) {
   return Focal.makeSureStoryExists(ID);
 }