KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > web > controller > LoginCommand


1 package com.genimen.djeneric.web.controller;
2
3 import java.io.IOException JavaDoc;
4
5 import javax.servlet.ServletException JavaDoc;
6 import javax.servlet.http.HttpServletRequest JavaDoc;
7 import javax.servlet.http.HttpServletResponse JavaDoc;
8 import javax.xml.parsers.FactoryConfigurationError JavaDoc;
9 import javax.xml.parsers.ParserConfigurationException JavaDoc;
10
11 import org.w3c.dom.Document JavaDoc;
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 JavaDoc request, HttpServletResponse JavaDoc response)
24       throws IOException JavaDoc, ServletException JavaDoc, DjenericException, FactoryConfigurationError JavaDoc, ParserConfigurationException JavaDoc
25   {
26     DjenericXSLTransform xsl = sessionManager.getTransformer();
27     response.setContentType("text/html; charset=UTF-8");
28     Document JavaDoc doc = _renderer.asXml(sessionManager, null);
29     String JavaDoc page = xsl.transform(doc, "login.xsl");
30     response.getWriter().print(page);
31   }
32
33   public boolean post(DjenericSessionManager sessionManager, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
34       throws IOException JavaDoc, ServletException JavaDoc, DjenericException, FactoryConfigurationError JavaDoc, ParserConfigurationException JavaDoc
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 JavaDoc doc = _renderer.asXml(sessionManager, le.getMessage());
46       String JavaDoc page = xsl.transform(doc, "login.xsl");
47       response.getWriter().print(page);
48       return false;
49     }
50   }
51 }
52
Popular Tags