KickJava   Java API By Example, From Geeks To Geeks.

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


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: Register.java,v 1.1 2004/08/16 10:48:52 slobodan Exp $
22  */

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

48 public class Register extends BasePO {
49
50     /**
51      * Constants
52      */

53     private static String JavaDoc LOGINNAME = "login";
54     private static String JavaDoc PASSWORD = "password";
55     private static String JavaDoc REPASSWORD = "repassword";
56     private static String JavaDoc FIRSTNAME = "firstname";
57     private static String JavaDoc LASTNAME = "lastname";
58
59     /**
60      * Superclass method override
61      */

62     public boolean loggedInUserRequired() {
63         return false;
64     }
65
66     /**
67      * Default event. Just show the page.
68      *
69      * @return html document
70      * @exception HttpPresentationException
71      */

72     public XMLObject handleDefault()
73         throws HttpPresentationException {
74         return showPage(null);
75     }
76
77     /**
78      * process login data, save fields to PersonManager if correct,
79      * otherwise output error messages
80      *
81      * @return html document
82      * @exception HttpPresentationException
83      */

84     public XMLObject handleRegister()
85         throws HttpPresentationException {
86
87         String JavaDoc login = this.getComms().request.getParameter(LOGINNAME);
88         String JavaDoc password = this.getComms().request.getParameter(PASSWORD);
89         String JavaDoc firstname = this.getComms().request.getParameter(FIRSTNAME);;
90         String JavaDoc lastname = this.getComms().request.getParameter(LASTNAME);
91         String JavaDoc repassword = this.getComms().request.getParameter(REPASSWORD);
92
93         // if login or password field is empty, generate error and redirect to this PO
94
if (login.length() == 0 || password.length() ==0 ||
95             firstname.length() == 0 || lastname.length() == 0) {
96             return showPage("Missing information. Please make sure all fields are filled out exactly");
97         }
98
99         //Check that password was duplicated correctly
100
if(!repassword.equals(password)) {
101             return showPage("Please make sure your password and password confirmation match exactly");
102         }
103         
104         
105 /*
106  * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run transactionsDiscRack_pres )
107  * We need to allow discRack_pres to be functional , response
108  * will be default HTML page with message
109  */

110         try {
111             
112         Person user=((PersonGenerator)PersonGeneratorFactory.getPersonGenerator("transactionsDiscRack.business.person.PersonGeneratorImpl")).findPerson(login);
113             
114             // Now check that the login name is not taken.
115
if(null == user)
116              {
117             
118              user= PersonFactory.getPerson("transactionsDiscRack.business.person.PersonImpl");
119                
120             user.setLogin(login);
121             user.setPassword(password);
122             user.setFirstname(firstname);
123             user.setLastname(lastname);
124           //Add the user to the database.
125
user.save();
126           
127               
128                 this.getSessionData().setUserMessage("You are registered, " +
129                                                      user.getFirstname() + ", please log in");
130         user.dbtRelease();
131                 throw new ClientPageRedirectException(getComms().request.getApplicationPath()+LOGIN_PAGE);
132             } else {
133                 // Login name already taken
134
// Redirect to this same PO with informative error message
135
return showPage("The login name " + login + " is already taken. Please try another.");
136             }
137          }catch(NullPointerException JavaDoc ex){
138             return showPage("You canot register while you in TransactionsDiscRack_pres ");
139         }
140         catch (AssertionDataObjectException ex) {
141             return showPage("Table person is read-only: can't register another person.");
142         }
143         catch(TransactionsDiscRackException ex) {
144             throw new TransactionsDiscRackPresentationException("Exception logging in user: ", ex);
145         }
146     }
147
148     /**
149      * display page
150      *
151      * @param errorMsg the error messages
152      * @return html document
153      * @exception HttpPresentationException
154      */

155     public XMLObject showPage(String JavaDoc errorMsg)
156         throws HttpPresentationException {
157
158     RegisterHTML page = (RegisterHTML)myComms.xmlcFactory.create(RegisterHTML.class);
159
160         if(null == errorMsg) {
161             page.getElementErrorText().getParentNode().removeChild(page.getElementErrorText());
162         } else {
163             page.setTextErrorText(errorMsg);
164         }
165
166         if(null != this.getComms().request.getParameter(LOGINNAME)) {
167             page.getElementLogin().setValue(this.getComms().request.getParameter(LOGINNAME));
168         }
169         if(null != this.getComms().request.getParameter(FIRSTNAME)) {
170             page.getElementFirstname().setValue(this.getComms().request.getParameter(FIRSTNAME));
171         }
172         if(null != this.getComms().request.getParameter(LASTNAME)) {
173             page.getElementLastname().setValue(this.getComms().request.getParameter(LASTNAME));
174         }
175
176         return page;
177     }
178 }
179
Popular Tags