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 java.math.BigDecimal;
029: import org.w3c.dom.*;
030: import org.w3c.dom.html.*;
031: import golfShop.presentation.xmlc.utilities.*;
032: import golfShop.presentation.xmlc.cart.*;
033: import golfShop.spec.user.UserDO;
034:
035: import golfShop.spec.cart.Cart;
036:
037: import golfShop.presentation.xmlc.utilities.CartUtils;
038: import com.lutris.appserver.server.session.Session;
039:
040: /**
041: * This presentation object dynamically creates an HTML page showing
042: * confirmation information from the user's order.
043: */
044: public class Confirm implements java.io.Serializable, HttpPresentation {
045: /**
046: * Cart object for session.
047: */
048: private Cart cart;
049:
050: /**
051: * User data object.
052: */
053: private UserDO user;
054:
055: /**
056: * Fill in the user and order information in the page.
057: */
058: private void addInfoToTable(ConfirmHTML htmlObj) {
059: try {
060: BigDecimal total = new BigDecimal(cart.getTotal());
061: total = total.setScale(2, BigDecimal.ROUND_HALF_UP);
062: htmlObj.setTextTotal(total.toString());
063:
064: String email = user.getEmail();
065: if ((email == null) || (email.length() == 0)) {
066: email = "(no email address configured)";
067: }
068: htmlObj.setTextUserName(HtmlEncoder.encode(user.getName()));
069: htmlObj.setTextEmail(HtmlEncoder.encode(email));
070: //same thing
071: } catch (NullPointerException ex) {
072: }
073:
074: }
075:
076: /**
077: * Output the page, setting dynamic values.
078: */
079: private void outputPage(HttpPresentationComms comms)
080: throws HttpPresentationException {
081: ConfirmHTML htmlObj = (ConfirmHTML) comms.xmlcFactory
082: .create(ConfirmHTML.class);
083: ContentsTableFormatter.fillInTable(htmlObj, cart, false);
084: addInfoToTable(htmlObj);
085: comms.response.writeDOM(htmlObj);
086: }
087:
088: /**
089: * Entry.
090: */
091: public void run(HttpPresentationComms comms)
092: throws HttpPresentationException {
093:
094: cart = CartUtils.getCart(comms.session);
095:
096: user = (UserDO) comms.session.getUser();
097:
098: outputPage(comms);
099: try {
100: // Empty out their cart.
101: cart.reset();
102: //if cart is null ( GolfShop_pres )
103: } catch (NullPointerException ex) {
104: }
105: }
106: }
|