KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.w3c.dom.*;
29 import org.w3c.dom.html.*;
30 import golfShop.presentation.xmlc.utilities.*;
31 import golfShop.presentation.xmlc.cart.*;
32 import golfShop.spec.user.UserDO;
33
34 import golfShop.spec.cart.*;
35 import golfShop.presentation.xmlc.utilities.CartUtils;
36 import com.lutris.appserver.server.session.Session;
37
38 /**
39  * This presentation object dynamically creates an HTML page showing an order
40  * form. The order form contains the shopping cart information and the user
41  * information.
42  */

43 public class Main implements HttpPresentation {
44     /**
45      * Cart object for session.
46      */

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

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

57     private void addUserToTable(MainHTML htmlObj) {
58     // set the username, this field will always be set
59
try{
60         htmlObj.setTextUserName(HtmlEncoder.encode(user.getName()));
61   
62     
63     // set any other fields that may have been set if the user established a new account
64
HTMLInputElement address1 = htmlObj.getElementAddress1();
65     address1.setValue(user.getAddress1());
66     
67     HTMLInputElement address2 = htmlObj.getElementAddress2();
68     address2.setValue(user.getAddress2());
69
70     HTMLInputElement city = htmlObj.getElementCity();
71     city.setValue(user.getCity());
72
73     HTMLInputElement state = htmlObj.getElementState();
74     state.setValue(user.getState());
75
76     HTMLInputElement zip = htmlObj.getElementZip();
77     zip.setValue(user.getZip());
78
79     HTMLInputElement email = htmlObj.getElementEmail();
80     email.setValue(user.getEmail());
81
82     HTMLInputElement cardnum = htmlObj.getElementCreditCard();
83     if((user.getCreditCard() != null) && (user.getCreditCard().length() > 0))
84         cardnum.setValue(user.getCreditCard());
85   
86    
87     } catch(NullPointerException JavaDoc ex) {
88        }
89     }
90         
91
92     /**
93      * Output the page, setting dynamic values.
94      */

95     private void outputPage(HttpPresentationComms comms)
96             throws HttpPresentationException {
97         MainHTML htmlObj
98             = (MainHTML)comms.xmlcFactory.create(MainHTML.class);
99         ContentsTableFormatter.fillInTable(htmlObj, cart, false);
100         addUserToTable(htmlObj);
101         comms.response.writeDOM(htmlObj);
102     }
103
104     /**
105      * Entry.
106      */

107     public void run(HttpPresentationComms comms)
108         throws HttpPresentationException {
109
110         cart = CartUtils.getCart(comms.session);
111         user = (UserDO)comms.session.getUser();
112         outputPage(comms);
113     }
114 }
115
Popular Tags