01: /*
02: * Enhydra Java Application Server
03: * The Initial Developer of the Original Code is Lutris Technologies Inc.
04: * Portions created by Lutris are Copyright (C) 1997-2000 Lutris Technologies
05: * Inc.
06: * All Rights Reserved.
07: *
08: * The contents of this file are subject to the Enhydra Public License Version
09: * 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,
37: java.io.Serializable {
38:
39: public void run(HttpPresentationComms comms) throws IOException,
40: PageRedirectException, Exception {
41:
42: // Update the user info to match what was entered in the form.
43: UserDO user = (UserDO) comms.session.getUser();
44:
45: String param = comms.request.getParameter("address1");
46: if (param != null)
47: user.setAddress1(param);
48:
49: param = comms.request.getParameter("address2");
50: if (param != null)
51: user.setAddress2(param);
52:
53: param = comms.request.getParameter("city");
54: if (param != null)
55: user.setCity(param);
56:
57: param = comms.request.getParameter("state");
58: if (param != null)
59: user.setState(param);
60:
61: param = comms.request.getParameter("zip");
62: if (param != null)
63: user.setZip(param);
64:
65: boolean badEmail = false;
66: boolean badCC = false;
67: param = comms.request.getParameter("email");
68: if (param != null)
69: user.setEmail(param);
70: else
71: badEmail = true;
72:
73: param = comms.request.getParameter("creditcard");
74: if (param != null)
75: user.setCreditCard(param);
76: else
77: badCC = true;
78:
79: // Save the changes, if some were made.
80: user.commitChanges();
81:
82: // If input is bad, redirect to Main.po, else redirect to Confirm.po.
83: String url = null;
84: if (badEmail || badCC) {
85: url = comms.request.getAppFileURIPath("checkout/Main.po");
86: } else {
87: url = comms.request
88: .getAppFileURIPath("checkout/Confirm.po");
89: }
90: ClientPageRedirectException e = new ClientPageRedirectException(
91: url);
92: if (badEmail)
93: e.addArgument("badEmail", "true");
94: if (badCC)
95: e.addArgument("badCC", "true");
96: throw e;
97: }
98: }
|