KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.*;
24 import golfShop.spec.user.UserDO;
25 import com.lutris.appserver.server.session.Session;
26 import com.lutris.appserver.server.httpPresentation.*;
27
28 /**
29  * Presentation object that processes the checkout request. If the user
30  * data is OK, it redirects to the confirmation page. If any of the
31  * required fields are missing, it redirects back to the checkout page.
32  *
33  * @author Andrew John
34  * @version $Revision: 1.1 $
35  */

36 public class CheckoutProcessor implements HttpPresentation, java.io.Serializable JavaDoc {
37
38     public void run(HttpPresentationComms comms)
39             throws IOException, PageRedirectException, Exception JavaDoc {
40
41     // Update the user info to match what was entered in the form.
42
UserDO user = (UserDO) comms.session.getUser();
43
44     String JavaDoc param = comms.request.getParameter("address1");
45     if (param != null) user.setAddress1(param);
46
47     param = comms.request.getParameter("address2");
48     if (param != null) user.setAddress2(param);
49
50     param = comms.request.getParameter("city");
51     if (param != null) user.setCity(param);
52
53     param = comms.request.getParameter("state");
54     if (param != null) user.setState(param);
55
56     param = comms.request.getParameter("zip");
57     if (param != null) user.setZip(param);
58
59     
60     boolean badEmail = false;
61     boolean badCC = false;
62     param = comms.request.getParameter("email");
63     if (param != null)
64         user.setEmail(param);
65     else
66         badEmail = true;
67
68     param = comms.request.getParameter("creditcard");
69     if (param != null)
70         user.setCreditCard(param);
71     else
72         badCC = true;
73
74     // Save the changes, if some were made.
75
user.commitChanges();
76
77     // If input is bad, redirect to Main.po, else redirect to Confirm.po.
78
String JavaDoc url = null;
79     if (badEmail || badCC) {
80             url = comms.request.getAppFileURIPath("checkout/Main.po");
81     } else {
82             url = comms.request.getAppFileURIPath("checkout/Confirm.po");
83         }
84     ClientPageRedirectException e = new ClientPageRedirectException(url);
85     if (badEmail)
86         e.addArgument("badEmail", "true");
87     if (badCC)
88         e.addArgument("badCC", "true");
89         throw e;
90     }
91 }
92
Popular Tags