KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > discRack > 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 09:39:21 slobodan Exp $
22  */

23
24 package discRack.presentation.personMgmt;
25
26 import discRack.spec.*;
27 import discRack.presentation.BasePO;
28 import discRack.presentation.DiscRackPresentationException;
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  * @author
43  * @version
44  */

45 public class Login extends BasePO {
46
47     /**
48      * Constants
49      */

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

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

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

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

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

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

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

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