1 package com.genimen.djeneric.web.controller; 2 3 import java.io.IOException ; 4 5 import javax.servlet.ServletException ; 6 import javax.servlet.http.HttpServletRequest ; 7 import javax.servlet.http.HttpServletResponse ; 8 import javax.xml.parsers.FactoryConfigurationError ; 9 import javax.xml.parsers.ParserConfigurationException ; 10 11 import org.w3c.dom.Document ; 12 13 import com.genimen.djeneric.repository.exceptions.DjenericException; 14 import com.genimen.djeneric.repository.exceptions.LogonException; 15 import com.genimen.djeneric.web.renderers.LoginRenderer; 16 import com.genimen.djeneric.web.util.DjenericSessionManager; 17 import com.genimen.djeneric.web.util.DjenericXSLTransform; 18 19 public class LoginCommand 20 { 21 LoginRenderer _renderer = new LoginRenderer(); 22 23 public void get(DjenericSessionManager sessionManager, HttpServletRequest request, HttpServletResponse response) 24 throws IOException , ServletException , DjenericException, FactoryConfigurationError , ParserConfigurationException 25 { 26 DjenericXSLTransform xsl = sessionManager.getTransformer(); 27 response.setContentType("text/html; charset=UTF-8"); 28 Document doc = _renderer.asXml(sessionManager, null); 29 String page = xsl.transform(doc, "login.xsl"); 30 response.getWriter().print(page); 31 } 32 33 public boolean post(DjenericSessionManager sessionManager, HttpServletRequest request, HttpServletResponse response) 34 throws IOException , ServletException , DjenericException, FactoryConfigurationError , ParserConfigurationException 35 { 36 try 37 { 38 sessionManager.login(request.getParameter("userid"), request.getParameter("password")); 39 return true; 40 } 41 catch (LogonException le) 42 { 43 DjenericXSLTransform xsl = sessionManager.getTransformer(); 44 response.setContentType("text/html; charset=UTF-8"); 45 Document doc = _renderer.asXml(sessionManager, le.getMessage()); 46 String page = xsl.transform(doc, "login.xsl"); 47 response.getWriter().print(page); 48 return false; 49 } 50 } 51 } 52 | Popular Tags |