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.checkout;
022:
023: import org.enhydra.xml.xmlc.*;
024: import org.enhydra.xml.xmlc.html.*;
025: import com.lutris.util.*;
026: import com.lutris.appserver.server.httpPresentation.*;
027: import java.io.*;
028: import org.w3c.dom.*;
029: import org.w3c.dom.html.*;
030: import golfShop.presentation.xmlc.utilities.*;
031: import golfShop.presentation.xmlc.cart.*;
032: import golfShop.spec.user.UserDO;
033:
034: import golfShop.spec.cart.*;
035: import golfShop.presentation.xmlc.utilities.CartUtils;
036: import com.lutris.appserver.server.session.Session;
037:
038: /**
039: * This presentation object dynamically creates an HTML page showing an order
040: * form. The order form contains the shopping cart information and the user
041: * information.
042: */
043: public class Main implements HttpPresentation {
044: /**
045: * Cart object for session.
046: */
047: private Cart cart;
048:
049: /**
050: * User data object.
051: */
052: private UserDO user;
053:
054: /**
055: * Fill in the user information in the page.
056: */
057: private void addUserToTable(MainHTML htmlObj) {
058: // set the username, this field will always be set
059: try {
060: htmlObj.setTextUserName(HtmlEncoder.encode(user.getName()));
061:
062: // set any other fields that may have been set if the user established a new account
063: HTMLInputElement address1 = htmlObj.getElementAddress1();
064: address1.setValue(user.getAddress1());
065:
066: HTMLInputElement address2 = htmlObj.getElementAddress2();
067: address2.setValue(user.getAddress2());
068:
069: HTMLInputElement city = htmlObj.getElementCity();
070: city.setValue(user.getCity());
071:
072: HTMLInputElement state = htmlObj.getElementState();
073: state.setValue(user.getState());
074:
075: HTMLInputElement zip = htmlObj.getElementZip();
076: zip.setValue(user.getZip());
077:
078: HTMLInputElement email = htmlObj.getElementEmail();
079: email.setValue(user.getEmail());
080:
081: HTMLInputElement cardnum = htmlObj.getElementCreditCard();
082: if ((user.getCreditCard() != null)
083: && (user.getCreditCard().length() > 0))
084: cardnum.setValue(user.getCreditCard());
085:
086: } catch (NullPointerException ex) {
087: }
088: }
089:
090: /**
091: * Output the page, setting dynamic values.
092: */
093: private void outputPage(HttpPresentationComms comms)
094: throws HttpPresentationException {
095: MainHTML htmlObj = (MainHTML) comms.xmlcFactory
096: .create(MainHTML.class);
097: ContentsTableFormatter.fillInTable(htmlObj, cart, false);
098: addUserToTable(htmlObj);
099: comms.response.writeDOM(htmlObj);
100: }
101:
102: /**
103: * Entry.
104: */
105: public void run(HttpPresentationComms comms)
106: throws HttpPresentationException {
107:
108: cart = CartUtils.getCart(comms.session);
109: user = (UserDO) comms.session.getUser();
110: outputPage(comms);
111: }
112: }
|