📄 carthtmlaction.java
字号:
/* Copyright 2004 Sun Microsystems, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistribution in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of Sun Microsystems, Inc. or the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. This software is provided "AS IS," without a warranty of any kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. You acknowledge that Software is not designed, licensed or intended for use in the design, construction, operation or maintenance of any nuclear facility. $Id: CartHTMLAction.java,v 1.2 2004/03/30 00:40:28 yutayoshida Exp $ */package com.sun.j2ee.blueprints.consumerwebsite.actions;import java.io.IOException;import java.util.*;// j2ee importsimport javax.servlet.http.*;// waf importsimport com.sun.j2ee.blueprints.waf.controller.Event;import com.sun.j2ee.blueprints.waf.controller.web.html.*;//adventure importsimport com.sun.j2ee.blueprints.consumerwebsite.*;// Catalog importsimport com.sun.j2ee.blueprints.catalog.*;/** * Implementation of HTMLAction that processes a * user change in language. */public final class CartHTMLAction extends HTMLActionSupport { public Event perform(HttpServletRequest request) throws HTMLActionException { String actionType= (String)request.getParameter("target_action"); HttpSession session = request.getSession(); if (actionType == null) { getResultBean(request); return null; } if (actionType.equals("select_package")) { String packageId = request.getParameter("package_id").trim(); // look up the adventure package AdventureComponentManager acm = (AdventureComponentManager)session.getAttribute(AdventureKeys.COMPONENT_MANAGER); Cart ac = acm.getCart(session); // clear the cart ac.clear(); CatalogFacade facade = acm.getCatalogFacade(session); try { Locale locale = new Locale("en","us"); AdventurePackage pack = facade.getAdventurePackage(packageId, locale); // put the info into the Adventure Cart ac.setPackageId(packageId); ac.setLodgingId(pack.getLodgingId()); ac.setDestination(pack.getLocation()); Iterator it = pack.getActivities().iterator(); // add the activities and set default people to 1 while (it.hasNext()) { String activityId = (String)it.next(); ac.addActivity(activityId.trim(), 1); } } catch (Exception ex) { ex.printStackTrace(); } } else if (actionType.equals("purchase_activities")) { purchaseActivities(request); getResultBean(request); } else if (actionType.equals("purchase_activity")) { String activityId = request.getParameter("activity_id"); String headCountString = request.getParameter("head_count"); // don't do anything if a hotel was not specified if (activityId == null && headCountString != null) { getResultBean(request); return null; } activityId = activityId.trim(); int headCount = Integer.parseInt(headCountString); // look up the cart AdventureComponentManager acm = (AdventureComponentManager)session.getAttribute(AdventureKeys.COMPONENT_MANAGER); Cart cart = acm.getCart(session); cart.addActivity(activityId,headCount); getResultBean(request); } else if (actionType.equals("update_activities")) { updateActivityHeadCounts(request); getResultBean(request); } else if (actionType.equals("set_package_options")) { updatePackage(request); getResultBean(request); } else if (actionType.equals("update_package_options")) { updatePackage(request); getResultBean(request); } else if (actionType.equals("update_lodging_room_count")) { updatePackage(request); getResultBean(request); } else if (actionType.equals("purchase_lodging")) { String hotelId = request.getParameter("lodging_id"); // don't do anything if a hotel was not specified if (hotelId == null) { getResultBean(request); return null; } hotelId = hotelId.trim(); // look up the adventure package AdventureComponentManager acm = (AdventureComponentManager)session.getAttribute(AdventureKeys.COMPONENT_MANAGER); Cart cart = acm.getCart(session); cart.setLodgingId(hotelId); // update the room count updatePackage(request); getResultBean(request); } else if (actionType.equals("no_transportation")) { AdventureComponentManager acm = (AdventureComponentManager)session.getAttribute(AdventureKeys.COMPONENT_MANAGER); Cart cart = acm.getCart(session); cart.setOrigin("None"); cart.setConfigurationComplete(true); getResultBean(request); } else if (actionType.equals("purchase_transportation")) { String departureFlight = request.getParameter("departure_flight"); if (departureFlight != null) departureFlight = departureFlight.trim(); String returnFlight = request.getParameter("return_flight"); if (returnFlight != null) returnFlight = returnFlight.trim(); // look up the adventure package AdventureComponentManager acm = (AdventureComponentManager)session.getAttribute(AdventureKeys.COMPONENT_MANAGER); Cart cart = acm.getCart(session); cart.setDepartureFlight(departureFlight); cart.setReturnFlight(returnFlight); cart.setConfigurationComplete(true); getResultBean(request); } else if (actionType.equals("cancel_departure_flight")) { AdventureComponentManager acm = (AdventureComponentManager)session.getAttribute(AdventureKeys.COMPONENT_MANAGER); Cart cart = acm.getCart(session); cart.setDepartureFlight(null); getResultBean(request); } else if (actionType.equals("cancel_return_flight")) { AdventureComponentManager acm = (AdventureComponentManager)session.getAttribute(AdventureKeys.COMPONENT_MANAGER); Cart cart = acm.getCart(session); cart.setReturnFlight(null); getResultBean(request);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -