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.utilities;
22:
23: import java.math.BigDecimal;
24: import java.util.Enumeration;
25:
26: import golfShop.spec.cart.*;
27:
28: import com.lutris.util.*;
29: import com.lutris.appserver.server.session.*;
30: import com.lutris.appserver.server.httpPresentation.*;
31:
32: /**
33: * This class provides static functions for formatted output of the
34: * cart contents.
35: */
36: public class CartUtils {
37:
38: private static String FF = "<FONT FACE=\"Arial,Helvetica,C Univers 57 Condensed,Futura Book\" SIZE=\"2\">";
39:
40: /**
41: * A CartUtils constructor. Prevent instantiation with a private
42: * constructor.
43: */
44: private CartUtils() {
45: }
46:
47: /**
48: * Find the cart object in session. Creating it if it doesn't
49: * exist.
50: */
51: public static Cart getCart(Session session)
52: throws HttpPresentationException {
53: try {
54: Cart cart = (Cart) session.getSessionData().get("cart");
55: if (cart == null) {
56:
57: Cart car = CartFactory
58: .getCart("golfShop.business.cart.CartImpl");
59:
60: session.getSessionData().set("cart", car);
61:
62: }
63: return cart;
64: /*
65: * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run GolfShop_pres )
66: * We need to allow GolfShop_pres to be functional
67: * so the cart will be null
68: */
69:
70: } catch (NullPointerException ex) {
71: return null;
72: } catch (KeywordValueException except) {
73: throw new HttpPresentationException(except);
74: }
75: }
76:
77: /**
78: * Add an item to the cart.
79: */
80: public static void addItem(Session session, long objectId)
81: throws HttpPresentationException {
82:
83: Cart cart = getCart(session);
84: cart.addItem(objectId);
85: cart.doneModifying();
86: }
87:
88: }
|