001: /*
002: * Enhydra Java Application Server
003: * The Initial Developer of the Original Code is Lutris Technologies Inc.
004: * Portions created by Lutris are Copyright (C) 1997-2000 Lutris Technologies
005: * Inc.
006: * All Rights Reserved.
007: *
008: * The contents of this file are subject to the Enhydra Public License Version
009: * 1.0 (the "License"); you may not use this file except in compliance with the
010: * License. You may obtain a copy of the License at
011: * http://www.enhydra.org/software/license/epl.html
012: *
013: * Software distributed under the License is distributed on an "AS IS" basis,
014: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
015: * License for the specific language governing rights and limitations under the
016: * License.
017: *
018: *
019: */
020:
021: package golfShop.presentation.xmlc.main;
022:
023: import org.enhydra.xml.xmlc.*;
024: import org.enhydra.xml.xmlc.html.*;
025: import com.lutris.appserver.server.httpPresentation.*;
026: import java.io.*;
027: import java.net.URLEncoder;
028: import org.w3c.dom.*;
029: import org.w3c.dom.html.*;
030: import golfShop.presentation.xmlc.utilities.*;
031:
032: /**
033: * This presentation object that dynamically creates the buy (and
034: * other actions) button menu.
035: *
036: * Parameters:
037: * <UL>
038: * <LI> add - If specified, this identifies the item on the screen to associate
039: * with the add button.
040: * </UL>
041: */
042: public class Buy implements HttpPresentation {
043: /**
044: * Active and inactive button images and alt text.
045: */
046: private static final String ADD_INACTIVE_GIF = "../media/AddItem_d.gif";
047: private static final String ADD_INACTIVE_TEXT = "You Must Select An Item First";
048: private static final String ADD_ACTIVE_GIF = "../media/AddItem_n.gif";
049: private static final String ADD_ACTIVE_GIF_MOUSEOVER = "../media/AddItem_b.gif";
050: private static final String ADD_ACTIVE_GIF_MOUSEOUT = "../media/AddItem_n.gif";
051: private static final String ADD_ACTIVE_TEXT = "Click To Add Item to Your Shopping Cart";
052:
053: /**
054: * URL to reference the item presentation object.
055: */
056: private static final String ITEM_URL = "Item.po";
057:
058: /**
059: * Item identifier for adding to the cart. Maybe null.
060: */
061: private String add;
062:
063: /**
064: * Output the page, setting dynamic values.
065: */
066: private void outputPage(HttpPresentationComms comms)
067: throws HttpPresentationException {
068: BuyHTML htmlObj = (BuyHTML) comms.xmlcFactory
069: .create(BuyHTML.class);
070: HTMLImageElement img = htmlObj.getElementAddImage();
071: HTMLAnchorElement anchor = htmlObj.getElementAddAnchor();
072:
073: if (add == null) {
074: img.setSrc(ADD_INACTIVE_GIF);
075: img.setAlt(ADD_INACTIVE_TEXT);
076: anchor.removeAttribute("href");
077: } else {
078: img.setSrc(ADD_ACTIVE_GIF);
079: img.setAlt(ADD_ACTIVE_TEXT);
080:
081: // When the add button is pressed, it goes back to Item.po, without
082: // the add parameter, but with the page being referenced as
083: // the shopping cart.
084: anchor.setHref(ITEM_URL + "?newItem=" + add);
085: anchor.setTarget("item");
086:
087: // Set on/out javascript.; must URL encode the contents due to quoting.
088: anchor.setAttribute("onmouseover", "add.src='"
089: + ADD_ACTIVE_GIF_MOUSEOVER + "'");
090: anchor.setAttribute("onmouseout", "add.src='"
091: + ADD_ACTIVE_GIF_MOUSEOUT + "'");
092: }
093: comms.response.writeDOM(htmlObj);
094: }
095:
096: /**
097: * Parse CGI arguments into fields.
098: */
099: private void parseArgs(HttpPresentationRequest request)
100: throws HttpPresentationException {
101:
102: add = request.getParameter("add");
103: }
104:
105: /**
106: * Entry.
107: */
108: public void run(HttpPresentationComms comms)
109: throws HttpPresentationException {
110:
111: parseArgs(comms.request);
112: outputPage(comms);
113: }
114: }
|