KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > transactionsDiscRack > presentation > personMgmt > Login


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: Login.java,v 1.1 2004/08/16 10:48:52 slobodan Exp $
22  */

23
24 package transactionsDiscRack.presentation.personMgmt;
25
26 import transactionsDiscRack.spec.*;
27 import transactionsDiscRack.presentation.BasePO;
28 import transactionsDiscRack.presentation.TransactionsDiscRackPresentationException;
29
30 import com.lutris.appserver.server.httpPresentation.*;
31 import com.lutris.appserver.server.session.*;
32 import com.lutris.util.*;
33 //import com.lutris.xml.xmlc.*;
34
//import com.lutris.xml.xmlc.html.*;
35
import org.w3c.dom.*;
36 import org.w3c.dom.html.*;
37 import org.enhydra.xml.xmlc.XMLObject;
38
39 /**
40  * Login.java handles the login functionality of the DiscRack app.
41  *
42  */

43 public class Login extends BasePO {
44
45     /**
46      * Constants
47      */

48     private static String JavaDoc SUBMIT_NAME = "submit";
49     private static String JavaDoc LOGIN_NAME = "login";
50     private static String JavaDoc PASSWORD_NAME = "password";
51     private static String JavaDoc ERROR_NAME = "ERROR_NAME";
52
53     /**
54      * Superclass method override
55      */

56     public boolean loggedInUserRequired() {
57         return false;
58     }
59
60     /**
61      * Default event. Just show the page.
62      */

63     public XMLObject handleDefault()
64         throws HttpPresentationException {
65         return showPage(null);
66     }
67
68     /**
69      * Process login data
70      *
71      * @return wml document
72      * @exception HttpPresentationException
73      */

74     public XMLObject handleLogin()
75         throws HttpPresentationException {
76         String JavaDoc login = this.getComms().request.getParameter(LOGIN_NAME);
77         String JavaDoc password = this.getComms().request.getParameter(PASSWORD_NAME);
78         
79         
80         Person user = null;
81
82 /*
83  * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run discRack_pres )
84  * We need to allow discRack_pres to be functional , to allow users who run discRack_pres response
85  * will be default HTML page
86  */

87         try {
88             
89    user =((PersonGenerator)PersonGeneratorFactory.getPersonGenerator("transactionsDiscRack.business.person.PersonGeneratorImpl")).findPerson(login);
90      if(null == user || !user.getPassword().equals(password)) {
91                 return showPage("Invalid username or password");
92                 // Show error message that user not found (bad username/password)
93
} else {
94                 this.setUser(user);
95         user.dbtRelease();
96                 throw new ClientPageRedirectException(getComms().request.getApplicationPath()+DISC_CATALOG_PAGE);
97
98             }
99         }catch(NullPointerException JavaDoc ex){
100                     
101               throw new ClientPageRedirectException(getComms().request.getApplicationPath()+DISC_CATALOG_PAGE);
102         
103
104         } catch(TransactionsDiscRackException ex) {
105         if (user != null)
106         user.dbtRelease();
107             this.writeDebugMsg("System error finding user: " + ex.getMessage());
108             throw new TransactionsDiscRackPresentationException("System error finding user", ex);
109         }
110     }
111
112     /**
113      * handle logout event
114      *
115      * @return html document
116      * @exception HttpPresentationException
117      */

118     public XMLObject handleLogout()
119         throws HttpPresentationException {
120         this.removeUserFromSession();
121         return (ExitHTML)myComms.xmlcFactory.create(ExitHTML.class);
122 // return new ExitHTML();
123
}
124
125     /**
126      * handle throw exception event.
127      *
128      * @return html document
129      * @exception Exception
130      */

131     public XMLObject handleThrowException()
132         throws Exception JavaDoc {
133         throw new Exception JavaDoc("This is a test exception thrown from Login.java handleThrowException()");
134     }
135
136     /**
137      * display page
138      *
139      * @param errorMsg the error messages
140      * @return html document
141      */

142     public XMLObject showPage(String JavaDoc errorMsg) {
143
144     LoginHTML page = (LoginHTML)myComms.xmlcFactory.create(LoginHTML.class);
145
146         if(null != errorMsg ||
147            null != (errorMsg = this.getSessionData().getAndClearUserMessage())) {
148             page.setTextErrorText(errorMsg);
149         } else {
150             page.getElementErrorText().getParentNode().removeChild(page.getElementErrorText());
151         }
152
153         return page;
154     }
155 }
156
157
158
Popular Tags