KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > golfShop > presentation > xmlc > login > NewAccount


1 /*
2  * Enhydra Java Application Server
3  * The Initial Developer of the Original Code is Lutris Technologies Inc.
4  * Portions created by Lutris are Copyright (C) 1997-2000 Lutris Technologies
5  * Inc.
6  * All Rights Reserved.
7  *
8  * The contents of this file are subject to the Enhydra Public License Version
9  * 1.0 (the "License"); you may not use this file except in compliance with the
10  * License. You may obtain a copy of the License at
11  * http://www.enhydra.org/software/license/epl.html
12  *
13  * Software distributed under the License is distributed on an "AS IS" basis,
14  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
15  * License for the specific language governing rights and limitations under the
16  * License.
17  *
18  *
19  */

20
21 package golfShop.presentation.xmlc.login;
22
23 import org.enhydra.xml.xmlc.*;
24 import org.enhydra.xml.xmlc.html.*;
25 import com.lutris.appserver.server.httpPresentation.*;
26 import java.io.*;
27 import org.w3c.dom.*;
28 import org.w3c.dom.html.*;
29 import golfShop.presentation.xmlc.utilities.*;
30
31 /**
32  * This presentation object dynamically creates an HTML page for
33  * creating a new user account.
34  */

35 public class NewAccount implements HttpPresentation {
36     /**
37      * State object in session.
38      */

39     private LoginState loginState;
40
41     /**
42      * Generate DOM nodes for the account creation error message and add
43      * as the first children of the message paragraph element.
44      */

45     
46     private void addErrorMsg(HTMLDocument doc, HTMLElement msgElem,
47                              String JavaDoc errorMsg) {
48         // Resulting HTML is:
49
// <FONT SIZE=+3>!&nbsp;</FONT><FONT COLOR=red>errorMsg</FONT><BR>
50

51         // Create <FONT SIZE=+3>!&nbsp;</FONT>
52
HTMLFontElement fontSize = (HTMLFontElement)doc.createElement("font");
53         fontSize.setSize("+3");
54         fontSize.appendChild(doc.createTextNode("! "));
55
56
57         // Create <FONT COLOR=red>errorMsg</FONT>
58
HTMLFontElement fontColor = (HTMLFontElement)doc.createElement("font");
59         fontColor.setColor("red");
60         fontColor.appendChild(doc.createTextNode(errorMsg));
61
62         // finally <BR>
63
HTMLBRElement br = (HTMLBRElement)doc.createElement("br");
64
65         // Assemble, bottom-up so its before template text in message.
66
msgElem.insertBefore(br,
67                              msgElem.getFirstChild());
68         msgElem.insertBefore(fontColor,
69                              msgElem.getFirstChild());
70         msgElem.insertBefore(fontSize,
71                              msgElem.getFirstChild());
72         
73         // Indicate error reported
74
loginState.lastError = null;
75     }
76
77
78     /*
79      * Displays a username and two password fields. The url parameter
80      * create.deny is used to signal that a previous invoation had an error.
81      * If true, then the error string is stored in the url parameter
82      * create.message. If the url paramater create.initial is set, then use
83      * that as the initial username. This presentation object just gathers
84      * data. It sends the data to the AccountProcessor presentation object
85      * to actually create the new account and log the user in.
86      */

87     private void outputPage(HttpPresentationComms comms)
88             throws HttpPresentationException {
89         NewAccountHTML htmlObj
90             = (NewAccountHTML)comms.xmlcFactory.create(NewAccountHTML.class);
91
92         // If new account has just failied, modify message to user.
93
if (loginState.lastError != null) {
94             addErrorMsg(htmlObj, htmlObj.getElementMessage(),
95                         loginState.lastError);
96         }
97
98         // If we have a user name, set it as the default value.
99
HTMLInputElement userName = htmlObj.getElementUsername();
100         if (loginState.userName != null) {
101             userName.setDefaultValue(loginState.userName);
102         }
103         comms.response.writeDOM(htmlObj);
104     }
105
106     /**
107      * Entry.
108      */

109     public void run(HttpPresentationComms comms)
110         throws HttpPresentationException {
111
112         loginState = LoginState.get(comms.session);
113         outputPage(comms);
114     }
115 }
116
Popular Tags