001: /*
002: * Enhydra Java Application Server
003: * The Initial Developer of the Original Code is Lutris Technologies Inc.
004: * Portions created by Lutris are Copyright (C) 1997-2000 Lutris Technologies
005: * Inc.
006: * All Rights Reserved.
007: *
008: * The contents of this file are subject to the Enhydra Public License Version
009: * 1.0 (the "License"); you may not use this file except in compliance with the
010: * License. You may obtain a copy of the License at
011: * http://www.enhydra.org/software/license/epl.html
012: *
013: * Software distributed under the License is distributed on an "AS IS" basis,
014: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
015: * License for the specific language governing rights and limitations under the
016: * License.
017: *
018: *
019: */
020:
021: package golfShop.presentation.xmlc.login;
022:
023: import org.enhydra.xml.xmlc.*;
024: import org.enhydra.xml.xmlc.html.*;
025: import com.lutris.appserver.server.httpPresentation.*;
026: import java.io.*;
027: import org.w3c.dom.*;
028: import org.w3c.dom.html.*;
029: import golfShop.presentation.xmlc.utilities.*;
030:
031: /**
032: * This presentation object dynamically creates an HTML page for
033: * creating a new user account.
034: */
035: public class NewAccount implements HttpPresentation {
036: /**
037: * State object in session.
038: */
039: private LoginState loginState;
040:
041: /**
042: * Generate DOM nodes for the account creation error message and add
043: * as the first children of the message paragraph element.
044: */
045:
046: private void addErrorMsg(HTMLDocument doc, HTMLElement msgElem,
047: String errorMsg) {
048: // Resulting HTML is:
049: // <FONT SIZE=+3>! </FONT><FONT COLOR=red>errorMsg</FONT><BR>
050:
051: // Create <FONT SIZE=+3>! </FONT>
052: HTMLFontElement fontSize = (HTMLFontElement) doc
053: .createElement("font");
054: fontSize.setSize("+3");
055: fontSize.appendChild(doc.createTextNode("! "));
056:
057: // Create <FONT COLOR=red>errorMsg</FONT>
058: HTMLFontElement fontColor = (HTMLFontElement) doc
059: .createElement("font");
060: fontColor.setColor("red");
061: fontColor.appendChild(doc.createTextNode(errorMsg));
062:
063: // finally <BR>
064: HTMLBRElement br = (HTMLBRElement) doc.createElement("br");
065:
066: // Assemble, bottom-up so its before template text in message.
067: msgElem.insertBefore(br, msgElem.getFirstChild());
068: msgElem.insertBefore(fontColor, msgElem.getFirstChild());
069: msgElem.insertBefore(fontSize, msgElem.getFirstChild());
070:
071: // Indicate error reported
072: loginState.lastError = null;
073: }
074:
075: /*
076: * Displays a username and two password fields. The url parameter
077: * create.deny is used to signal that a previous invoation had an error.
078: * If true, then the error string is stored in the url parameter
079: * create.message. If the url paramater create.initial is set, then use
080: * that as the initial username. This presentation object just gathers
081: * data. It sends the data to the AccountProcessor presentation object
082: * to actually create the new account and log the user in.
083: */
084: private void outputPage(HttpPresentationComms comms)
085: throws HttpPresentationException {
086: NewAccountHTML htmlObj = (NewAccountHTML) comms.xmlcFactory
087: .create(NewAccountHTML.class);
088:
089: // If new account has just failied, modify message to user.
090: if (loginState.lastError != null) {
091: addErrorMsg(htmlObj, htmlObj.getElementMessage(),
092: loginState.lastError);
093: }
094:
095: // If we have a user name, set it as the default value.
096: HTMLInputElement userName = htmlObj.getElementUsername();
097: if (loginState.userName != null) {
098: userName.setDefaultValue(loginState.userName);
099: }
100: comms.response.writeDOM(htmlObj);
101: }
102:
103: /**
104: * Entry.
105: */
106: public void run(HttpPresentationComms comms)
107: throws HttpPresentationException {
108:
109: loginState = LoginState.get(comms.session);
110: outputPage(comms);
111: }
112: }
|