1 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 35 public class Login implements HttpPresentation { 36 40 private static final String defaultUserName = "enhydra"; 41 private static final String defaultPassowrd = "lutris"; 42 43 46 private LoginState loginState; 47 48 52 private void addErrorMsg(HTMLDocument doc, HTMLElement msgElem, 53 String errorMsg) { 54 57 HTMLFontElement fontSize = (HTMLFontElement)doc.createElement("font"); 59 fontSize.setSize("+3"); 60 fontSize.appendChild(doc.createTextNode("! ")); 61 62 63 HTMLFontElement fontColor = (HTMLFontElement)doc.createElement("font"); 65 fontColor.setColor("red"); 66 fontColor.appendChild(doc.createTextNode(errorMsg)); 67 68 HTMLBRElement br = (HTMLBRElement)doc.createElement("br"); 70 71 msgElem.insertBefore(br, 73 msgElem.getFirstChild()); 74 msgElem.insertBefore(fontColor, 75 msgElem.getFirstChild()); 76 msgElem.insertBefore(fontSize, 77 msgElem.getFirstChild()); 78 79 loginState.lastError = null; 81 } 82 83 86 private void promptPage(HttpPresentationComms comms) 87 throws HttpPresentationException { 88 LoginHTML htmlObj 89 = (LoginHTML)comms.xmlcFactory.create(LoginHTML.class); 90 91 if (loginState.lastError != null) { 93 addErrorMsg(htmlObj, htmlObj.getElementMessage(), 94 loginState.lastError); 95 } 96 97 HTMLInputElement userName = htmlObj.getElementUsername(); 100 if (loginState.userName != null) { 101 userName.setValue(loginState.userName); 102 } else { 103 userName.setValue(defaultUserName); 104 htmlObj.getElementPassword().setValue(defaultPassowrd); 105 } 106 107 comms.response.writeDOM(htmlObj); 108 } 109 110 113 public void run(HttpPresentationComms comms) 114 throws HttpPresentationException { 115 116 loginState = LoginState.get(comms.session); 117 promptPage(comms); 118 } 119 } 120 | Popular Tags |