KickJava   Java API By Example, From Geeks To Geeks.

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


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.appserver.server.httpPresentation.*;
26 import java.io.*;
27 import java.net.URLEncoder JavaDoc;
28 import org.w3c.dom.*;
29 import org.w3c.dom.html.*;
30 import golfShop.presentation.xmlc.utilities.*;
31
32 /**
33  * This presentation object that dynamically creates the buy (and
34  * other actions) button menu.
35  *
36  * Parameters:
37  * <UL>
38  * <LI> add - If specified, this identifies the item on the screen to associate
39  * with the add button.
40  * </UL>
41  */

42 public class Buy implements HttpPresentation {
43     /**
44      * Active and inactive button images and alt text.
45      */

46     private static final String JavaDoc ADD_INACTIVE_GIF = "../media/AddItem_d.gif";
47     private static final String JavaDoc ADD_INACTIVE_TEXT = "You Must Select An Item First";
48     private static final String JavaDoc ADD_ACTIVE_GIF = "../media/AddItem_n.gif";
49     private static final String JavaDoc ADD_ACTIVE_GIF_MOUSEOVER = "../media/AddItem_b.gif";
50     private static final String JavaDoc ADD_ACTIVE_GIF_MOUSEOUT = "../media/AddItem_n.gif";
51     private static final String JavaDoc ADD_ACTIVE_TEXT = "Click To Add Item to Your Shopping Cart";
52
53     /**
54      * URL to reference the item presentation object.
55      */

56     private static final String JavaDoc ITEM_URL = "Item.po";
57
58     /**
59      * Item identifier for adding to the cart. Maybe null.
60      */

61     private String JavaDoc add;
62
63     /**
64      * Output the page, setting dynamic values.
65      */

66     private void outputPage(HttpPresentationComms comms)
67             throws HttpPresentationException {
68         BuyHTML htmlObj = (BuyHTML)comms.xmlcFactory.create(BuyHTML.class);
69         HTMLImageElement img = htmlObj.getElementAddImage();
70         HTMLAnchorElement anchor = htmlObj.getElementAddAnchor();
71         
72         if (add == null) {
73             img.setSrc(ADD_INACTIVE_GIF);
74             img.setAlt(ADD_INACTIVE_TEXT);
75             anchor.removeAttribute("href");
76         } else {
77             img.setSrc(ADD_ACTIVE_GIF);
78             img.setAlt(ADD_ACTIVE_TEXT);
79
80             // When the add button is pressed, it goes back to Item.po, without
81
// the add parameter, but with the page being referenced as
82
// the shopping cart.
83
anchor.setHref(ITEM_URL + "?newItem=" + add);
84             anchor.setTarget("item");
85
86             // Set on/out javascript.; must URL encode the contents due to quoting.
87
anchor.setAttribute("onmouseover",
88                                 "add.src='" + ADD_ACTIVE_GIF_MOUSEOVER + "'");
89             anchor.setAttribute("onmouseout",
90                                 "add.src='" + ADD_ACTIVE_GIF_MOUSEOUT + "'");
91         }
92         comms.response.writeDOM(htmlObj);
93     }
94
95     /**
96      * Parse CGI arguments into fields.
97      */

98     private void parseArgs(HttpPresentationRequest request)
99         throws HttpPresentationException {
100
101         add = request.getParameter("add");
102     }
103
104     /**
105      * Entry.
106      */

107     public void run(HttpPresentationComms comms)
108         throws HttpPresentationException {
109
110         parseArgs(comms.request);
111         outputPage(comms);
112     }
113 }
114
Popular Tags