package org.t246osslab.easybuggy.performance;

import java.io.IOException;
import java.util.Date;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.t246osslab.easybuggy.core.utils.HTTPResponseCreator;
import org.t246osslab.easybuggy.core.utils.MessageUtils;

@SuppressWarnings("serial")
@WebServlet(urlPatterns = { "/slowre" })
public class SlowRegularExpressionServlet extends HttpServlet {

    private static Logger log = LoggerFactory.getLogger(SlowRegularExpressionServlet.class);

    protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

        try {
            String word = req.getParameter("word");
            Locale locale = req.getLocale();

            StringBuilder bodyHtml = new StringBuilder();

            bodyHtml.append("<form action=\"slowre\" method=\"post\">");
            bodyHtml.append(MessageUtils.getMsg("description.test.regular.expression", locale));
            bodyHtml.append("<br><br>");
            bodyHtml.append("<img src=\"images/regular-expression.png\">");
            bodyHtml.append("<br><br>");
            bodyHtml.append(MessageUtils.getMsg("label.string", locale) + ": ");
            bodyHtml.append("<input type=\"text\" name=\"word\" size=\"50\" maxlength=\"50\">");
            bodyHtml.append("<br><br>");
            bodyHtml.append("<input type=\"submit\" value=\"" + MessageUtils.getMsg("label.submit", locale) + "\">");
            bodyHtml.append("<br><br>");

            if (word != null && !word.equals("")) {
                Date startDdate = new Date();
                log.info("Start Ddate: " + startDdate.toString());
                Pattern compile = Pattern.compile("^([a-z0-9]+[-]{0,1}){1,100}$");
                Matcher matcher = compile.matcher(word);
                boolean matches = matcher.matches();
                Date endDdate = new Date();
                log.info("End Ddate: " + endDdate.toString());
                if (matches) {
                    bodyHtml.append(MessageUtils.getMsg("msg.match.regular.expression", locale));
                } else {
                    bodyHtml.append(MessageUtils.getMsg("msg.not.match.regular.expression", locale));
                }
            } else {
                bodyHtml.append(MessageUtils.getMsg("msg.enter.word", locale));
            }
            bodyHtml.append("<br><br>");
            bodyHtml.append(MessageUtils.getMsg("msg.note.slow.regular.expression", locale));
            bodyHtml.append("</form>");

            HTTPResponseCreator.createSimpleResponse(res, MessageUtils.getMsg("title.slow.regular.expression.page", locale),
                    bodyHtml.toString());

        } catch (Exception e) {
            log.error("Exception occurs: ", e);
        }
    }
}

@@ -1877,17 +1877,16 @@
 e startD
-d
 ate = ne
@@ -1928,17 +1928,16 @@
 %22Start D
-d
 ate: %22 +
@@ -1943,17 +1943,16 @@
 + startD
-d
 ate.toSt
@@ -2178,17 +2178,16 @@
 ate endD
-d
 ate = ne
@@ -2227,17 +2227,16 @@
 o(%22End D
-d
 ate: %22 +
@@ -2240,17 +2240,16 @@
 %22 + endD
-d
 ate.toSt

Fix typos