package ru.org.linux.site;

import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import com.octo.captcha.service.CaptchaServiceException;
import com.octo.captcha.service.image.DefaultManageableImageCaptchaService;
import com.octo.captcha.service.image.ImageCaptchaService;

import ru.org.linux.util.LorHttpUtils;

public class CaptchaSingleton {
  private static final Logger logger = Logger.getLogger("ru.org.linux");
  private static final ImageCaptchaService instance = new DefaultManageableImageCaptchaService();

  private CaptchaSingleton() {
  }

  public static ImageCaptchaService getInstance() {
    return instance;
  }

  public static void checkCaptcha(HttpSession session, HttpServletRequest request) throws BadInputException {
    String captchaId = session.getId();
    String captchaResponse = request.getParameter("j_captcha_response");
	if (request.getAttribute("j_captcha_response")!=null && !"".equals(request.getAttribute("j_captcha_response"))) {
	  captchaResponse = (String)request.getAttribute("j_captcha_response");
	}
    try {
      if (!CaptchaSingleton.getInstance().validateResponseForID(captchaId, captchaResponse)) {
        String logmessage = "Captcha:   response='" + captchaResponse + "' " + LorHttpUtils.getRequestIP(request);
        logger.info(logmessage);

        throw new BadInputException(" :    ");
      }
    } catch (CaptchaServiceException e) {
      throw new BadInputException(" :    ");
    }
  }
}

@@ -914,17 +914,21 @@
 onse%22);%0A
-%09
+%0A    
 if (requ
@@ -969,10 +969,12 @@
 se%22)
+ 
 !=
+ 
 null
@@ -1035,17 +1035,20 @@
 e%22))) %7B%0A
-%09
+    
   captch
@@ -1067,16 +1067,17 @@
 (String)
+ 
 request.
@@ -1116,10 +1116,14 @@
 %22);%0A
-%09%7D
+    %7D%0A
 %0A   

reformat code