KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > golfShop > presentation > xmlc > checkout > Confirm


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.checkout;
22
23 import org.enhydra.xml.xmlc.*;
24 import org.enhydra.xml.xmlc.html.*;
25 import com.lutris.util.*;
26 import com.lutris.appserver.server.httpPresentation.*;
27 import java.io.*;
28 import java.math.BigDecimal JavaDoc;
29 import org.w3c.dom.*;
30 import org.w3c.dom.html.*;
31 import golfShop.presentation.xmlc.utilities.*;
32 import golfShop.presentation.xmlc.cart.*;
33 import golfShop.spec.user.UserDO;
34
35 import golfShop.spec.cart.Cart;
36
37 import golfShop.presentation.xmlc.utilities.CartUtils;
38 import com.lutris.appserver.server.session.Session;
39
40 /**
41  * This presentation object dynamically creates an HTML page showing
42  * confirmation information from the user's order.
43  */

44 public class Confirm implements java.io.Serializable JavaDoc, HttpPresentation {
45     /**
46      * Cart object for session.
47      */

48     private Cart cart;
49
50     /**
51      * User data object.
52      */

53     private UserDO user;
54
55     /**
56      * Fill in the user and order information in the page.
57      */

58     private void addInfoToTable(ConfirmHTML htmlObj) {
59     try{
60     BigDecimal JavaDoc total = new BigDecimal JavaDoc(cart.getTotal());
61     total = total.setScale(2, BigDecimal.ROUND_HALF_UP);
62         htmlObj.setTextTotal(total.toString());
63
64         String JavaDoc email = user.getEmail();
65         if ((email == null) || (email.length() == 0)) {
66             email = "(no email address configured)";
67         }
68         htmlObj.setTextUserName(HtmlEncoder.encode(user.getName()));
69         htmlObj.setTextEmail(HtmlEncoder.encode(email));
70     //same thing
71
} catch(NullPointerException JavaDoc ex) {
72        }
73     
74     }
75
76     /**
77      * Output the page, setting dynamic values.
78      */

79     private void outputPage(HttpPresentationComms comms)
80             throws HttpPresentationException {
81         ConfirmHTML htmlObj
82             = (ConfirmHTML)comms.xmlcFactory.create(ConfirmHTML.class);
83         ContentsTableFormatter.fillInTable(htmlObj, cart, false);
84         addInfoToTable(htmlObj);
85         comms.response.writeDOM(htmlObj);
86     }
87
88     /**
89      * Entry.
90      */

91     public void run(HttpPresentationComms comms)
92         throws HttpPresentationException {
93
94         cart = CartUtils.getCart(comms.session);
95         
96         
97        user = (UserDO)comms.session.getUser();
98    
99         outputPage(comms);
100     try{
101          // Empty out their cart.
102
cart.reset();
103     //if cart is null ( GolfShop_pres )
104
} catch(NullPointerException JavaDoc ex) {
105        }
106     }
107 }
108
Popular Tags