KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > golfShop > presentation > xmlc > main > Item


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.main;
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.net.URLEncoder JavaDoc;
29 import org.w3c.dom.*;
30 import org.w3c.dom.html.*;
31 import golfShop.presentation.xmlc.utilities.*;
32 import golfShop.spec.LoginException;
33 /**
34  * This presentation object dynamically creates an HTML page with two frames,
35  * consisting of the Buy presentation object and the URL of the item
36  * in question. <P>
37  *
38  * Parameters:
39  * <UL>
40  * <LI> add - If specified, the Buy presentation object is passed this value,
41  * identifying the item on the screen.
42  * <LI> ref - The value is the URL used for the lower frame, otherwise a default
43  * HTML file is loaded.
44  * <LI> newItem - If specified, this item is added to the cart and the cart
45  * object displayed.
46  * </UL>
47  */

48 public class Item implements HttpPresentation {
49     /**
50      * Buy presentation object.
51      */

52     private static final String JavaDoc buyPO = "Buy.po";
53
54     /**
55      * Cart contents PO.
56      */

57     private static final String JavaDoc CART_CONTENTS_URL = "../cart/Contents.po";
58
59     /**
60      * Default item html page.
61      */

62     private static final String JavaDoc defaultItem = "noItem.html";
63
64     /**
65      * Item identifier for adding to the cart. Maybe null.
66      */

67     private String JavaDoc add;
68
69     /**
70      * URL of page for the item. Maybe null.
71      */

72     private String JavaDoc ref;
73
74     /**
75      * Item to add to the cart. Maybe null.
76      */

77     private Long JavaDoc newItem;
78
79     /**
80      * Output the page, setting dynamic values.
81      */

82     private void outputPage(HttpPresentationComms comms)
83             throws HttpPresentationException {
84         ItemHTML htmlObj = (ItemHTML)comms.xmlcFactory.create(ItemHTML.class);
85         
86         HTMLFrameElement buyFrame = htmlObj.getElementBuy();
87         String JavaDoc buyUrl = buyPO;
88         if (add != null) {
89             buyUrl += "?add=" + URLEncoder.encode(add);
90         }
91         buyFrame.setSrc(buyUrl);
92
93         htmlObj.getElementItem().setSrc(ref);
94
95         comms.response.writeDOM(htmlObj);
96     }
97
98     /**
99      * Parse CGI arguments into fields.
100      */

101     private void parseArgs(HttpPresentationRequest request)
102         throws HttpPresentationException {
103
104         add = request.getParameter("add");
105         ref = request.getParameter("ref");
106         if (ref == null) {
107             ref = defaultItem;
108         }
109         String JavaDoc newItemStr = request.getParameter("newItem");
110         if (newItemStr != null) {
111             newItem = new Long JavaDoc(newItemStr);
112         }
113     }
114
115     /**
116      * Entry.
117      */

118     public void run(HttpPresentationComms comms)
119         throws HttpPresentationException {
120
121         parseArgs(comms.request);
122         if (newItem != null) {
123             CartUtils.addItem(comms.session, newItem.longValue());
124             ref = CART_CONTENTS_URL;
125         }
126         outputPage(comms);
127     }
128 }
129
Popular Tags