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.util.*;
026: import com.lutris.appserver.server.httpPresentation.*;
027: import java.io.*;
028: import java.net.URLEncoder;
029: import org.w3c.dom.*;
030: import org.w3c.dom.html.*;
031: import golfShop.presentation.xmlc.utilities.*;
032: import golfShop.spec.LoginException;
033:
034: /**
035: * This presentation object dynamically creates an HTML page with two frames,
036: * consisting of the Buy presentation object and the URL of the item
037: * in question. <P>
038: *
039: * Parameters:
040: * <UL>
041: * <LI> add - If specified, the Buy presentation object is passed this value,
042: * identifying the item on the screen.
043: * <LI> ref - The value is the URL used for the lower frame, otherwise a default
044: * HTML file is loaded.
045: * <LI> newItem - If specified, this item is added to the cart and the cart
046: * object displayed.
047: * </UL>
048: */
049: public class Item implements HttpPresentation {
050: /**
051: * Buy presentation object.
052: */
053: private static final String buyPO = "Buy.po";
054:
055: /**
056: * Cart contents PO.
057: */
058: private static final String CART_CONTENTS_URL = "../cart/Contents.po";
059:
060: /**
061: * Default item html page.
062: */
063: private static final String defaultItem = "noItem.html";
064:
065: /**
066: * Item identifier for adding to the cart. Maybe null.
067: */
068: private String add;
069:
070: /**
071: * URL of page for the item. Maybe null.
072: */
073: private String ref;
074:
075: /**
076: * Item to add to the cart. Maybe null.
077: */
078: private Long newItem;
079:
080: /**
081: * Output the page, setting dynamic values.
082: */
083: private void outputPage(HttpPresentationComms comms)
084: throws HttpPresentationException {
085: ItemHTML htmlObj = (ItemHTML) comms.xmlcFactory
086: .create(ItemHTML.class);
087:
088: HTMLFrameElement buyFrame = htmlObj.getElementBuy();
089: String buyUrl = buyPO;
090: if (add != null) {
091: buyUrl += "?add=" + URLEncoder.encode(add);
092: }
093: buyFrame.setSrc(buyUrl);
094:
095: htmlObj.getElementItem().setSrc(ref);
096:
097: comms.response.writeDOM(htmlObj);
098: }
099:
100: /**
101: * Parse CGI arguments into fields.
102: */
103: private void parseArgs(HttpPresentationRequest request)
104: throws HttpPresentationException {
105:
106: add = request.getParameter("add");
107: ref = request.getParameter("ref");
108: if (ref == null) {
109: ref = defaultItem;
110: }
111: String newItemStr = request.getParameter("newItem");
112: if (newItemStr != null) {
113: newItem = new Long(newItemStr);
114: }
115: }
116:
117: /**
118: * Entry.
119: */
120: public void run(HttpPresentationComms comms)
121: throws HttpPresentationException {
122:
123: parseArgs(comms.request);
124: if (newItem != null) {
125: CartUtils.addItem(comms.session, newItem.longValue());
126: ref = CART_CONTENTS_URL;
127: }
128: outputPage(comms);
129: }
130: }
|