KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > airsent > presentation > messenger > MessengerLogin


1 /*
2  * Copyright (c) 1999-2001 Lutris Technologies, Inc. All Rights
3  * Reserved.
4  *
5  * This source code file is distributed by Lutris Technologies, Inc. for
6  * use only by licensed users of product(s) that include this source
7  * file. Use of this source file or the software that uses it is covered
8  * by the terms and conditions of the Lutris Enhydra Development License
9  * Agreement included with this product.
10  *
11  * This Software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
12  * ANY KIND, either express or implied. See the License for the specific terms
13  * governing rights and limitations under the License.
14  *
15  * Contributor(s):
16  *
17  * $Id: MessengerLogin.java,v 1.1 2004/08/16 09:33:18 slobodan Exp $
18  */

19
20 package com.lutris.airsent.presentation.messenger;
21
22 import com.lutris.appserver.server.httpPresentation.*;
23 import com.lutris.appserver.server.session.*;
24 import com.lutris.util.*;
25 //import com.lutris.xml.xmlc.*;
26
import org.enhydra.xml.xmlc.XMLCUtil;
27 import org.w3c.dom.*;
28 import org.enhydra.xml.xmlc.XMLObject;
29 import java.util.Date JavaDoc;
30 import com.lutris.airsent.presentation.AirSentPresentationException;
31 import com.lutris.airsent.presentation.AirSentConstants;
32 import com.lutris.airsent.presentation.DeviceBasePO;
33 import com.lutris.airsent.presentation.DeviceUtils;
34 import com.lutris.airsent.spec.messenger.Messenger;
35 import java.lang.reflect.Method JavaDoc;
36
37 /**
38  * MessengerLogin.java handles the login functionality for
39  * the messenger of the AirSent app.
40  *
41  * @author
42  * @version
43  */

44 public class MessengerLogin extends DeviceBasePO {
45
46     /**
47      * Constants
48      */

49     private static final int AUTH_LEVEL = AirSentConstants.UNAUTH_USER;
50
51     /**
52      * Superclass method override.
53      * returns the authorization level necessary to access this po.
54      *
55      * @return int required authorization level
56      */

57     public int getRequiredAuthLevel() {
58     return AUTH_LEVEL;
59     }
60
61     /**
62      * Default event. Just show the page.
63      *
64      * @return XMLObject document
65      * @exception HttpPresentationException
66      */

67     public XMLObject handleDefault() throws HttpPresentationException {
68     return showPage(null);
69     }
70
71     /**
72      * Displays the MessengerLogin page.
73      *
74      * @param errorMsg, the error messages
75      * @return wml document
76      * @exception HttpPresentationException
77      */

78     public XMLObject showPage(String JavaDoc errorMsg)
79     
80         throws HttpPresentationException {
81     Class JavaDoc tempClass=null;
82     Object JavaDoc page= null;
83     Method JavaDoc setTextErrorText = null;
84   Method JavaDoc getTagErrorText = null;
85   
86     try{
87     Class JavaDoc stringClass=Class.forName("java.lang.String");
88     tempClass = Class.forName(DeviceUtils.getPageName(myComms, "com.lutris.airsent.presentation.messenger.MessengerLogin"));
89     page= myComms.xmlcFactory.create(tempClass);
90     Class JavaDoc[] argTypeArr={stringClass};
91     setTextErrorText = tempClass.getMethod("setTextErrorText",argTypeArr);
92     getTagErrorText = tempClass.getMethod("getElementErrorText",null);
93   }catch(Exception JavaDoc e){}
94     
95     
96     
97 // MessengerLoginPage page =
98
// (MessengerLoginPage) create("com.lutris.airsent.presentation.messenger.MessengerLogin");
99

100     try {
101           Element error = (Element)getTagErrorText.invoke(page,null);
102        // Element error = page.getTagErrorText();
103

104         if (null != errorMsg
105             || null
106                != (errorMsg =
107                this.getSessionData().getAndClearUserMessage())) {
108                 
109         Object JavaDoc [] temp={errorMsg};
110         setTextErrorText.invoke(page,temp);
111         //page.setTextErrorText(errorMsg);
112
} else {
113         Object JavaDoc [] temp={""};
114         setTextErrorText.invoke(page,temp);
115         //page.setTextErrorText("");
116
}
117       
118         // Add a jsession key for those who requset it:
119
// Like the java client app.
120
if (error.getAttributeNode("jsessionid") != null) {
121         error.getAttributeNode("jsessionid").setValue(myComms.session.getSessionKey());
122         }
123     } catch (Exception JavaDoc ex) {
124         throw new AirSentPresentationException("Error in messenger login",
125                            ex);
126     }
127     DeviceUtils.setURLTimeStamp((XMLObject)page);
128     return ((XMLObject)page);
129     }
130
131     /**
132      * Process login data
133      *
134      * @return error String
135      */

136     public XMLObject handleLogin() throws HttpPresentationException {
137     String JavaDoc badge =
138         myComms.request.getParameter(AirSentConstants.LOGIN_NAME);
139     String JavaDoc password =
140         myComms.request.getParameter(AirSentConstants.PASSWORD_NAME);
141     Messenger messenger = null;
142
143     try {
144         if (badge == null ||
145         password == null ||
146         (messenger = getApplication().getHomeManager().getMessengerManager().validatePassword(badge, password)) == null) {
147         return showPage("Invalid login or password!!");
148         } else {
149         
150         getSessionData().setMessenger(messenger);
151         getSessionData().setUserAuth(AirSentConstants.MESSENGER_USER);
152         throw new ClientPageRedirectException(AirSentConstants.MESSENGER_MAIN_PAGE);
153        
154         }
155     } catch (Exception JavaDoc ex) {
156         throw new AirSentPresentationException("System error logging in Messenger.",
157                            ex);
158     }
159
160     }
161
162 }
163
164
Popular Tags