Java Cart .

Java Cart AccountScreenWrangler java

package cart.screenWranglers;

import cart.Category;
import cart.Account;
import cart.AccountHolder;
import cart.Address;
import cart.Country;
import cart.EMail;
import cart.Password;
import cart.Phone;
import cart.State;
import cart.Zip;
import cart.sessionBeans.AccountBean;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.ListIterator;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.ServletContext;

//AccountScreenWrangler
//author - Lawrence Truett - FluffyCat.com
//date - August 13, 2003 - San Diego, CA
public class AccountScreenWrangler extends BaseScreenWrangler {
    
    public AccountScreenWrangler() {this("/cart/jsps/Account.jsp");}
    
    public AccountScreenWrangler(String nextScreenIn) {
        super(nextScreenIn);
    }
    
    public void wrangleScreen(HttpServletRequest request, 
                              ServletContext servletContext) {
        
        char action = baseNextScreenSwitch(request, 
        servletContext);
        
        if (action != 'A') {
            getNextWrangler().prepFirstScreen(request, 
                                              servletContext);
        } else {
            StringBuffer acctSubs = 
                this.allScreens(request, servletContext);
        }
    }
    
    void prepFirstScreen(HttpServletRequest request, 
        ServletContext servletContext) {
        String stringSubAction = 
            request.getParameter("subAction");
        if ('N' == stringSubAction.charAt(0)) {
            StringBuffer accountSb = 
                newAccountFirstScreen(request, servletContext);
            request.setAttribute("jspAccount", "");
        } else {
            StringBuffer accountSb = 
                allScreens(request, servletContext);
            request.setAttribute("jspAccount", accountSb);
        }
    }
    
    StringBuffer newAccountFirstScreen(HttpServletRequest request, 
                                       ServletContext servletContext) {
        StringBuffer accountSb = new StringBuffer("");
        Account account = new Account();
        
        AccountBean accountBean = new AccountBean(account);
        accountBean.setNewAccount(true);
        accountBean.setValidData(false);
        
        request.getSession().setAttribute("accountBean", accountBean);
        
        return accountSb;        
    }
    
    StringBuffer allScreens(HttpServletRequest request, 
                            ServletContext servletContext) {
        
        StringBuffer accountSb = new StringBuffer("");
        AccountBean accountBean = 
            (AccountBean)(request.getSession().getAttribute("accountBean"));
        accountBean.setAccountHolderFirstName(
            request.getParameter("accountHolderFirstName"));
        accountBean.setAccountHolderLastName(
            request.getParameter("accountHolderLastName"));
        accountBean.setAccountHolderPhone(
            request.getParameter("accountHolderPhone"));     
        accountBean.setAccountHolderAddressState(
            request.getParameter("accountHolderAddressState"));        
        //if new account
        //return account subs
        //else ...
        //return account subs
        /*
        ItemBean itemBean = (ItemBean)servletContext.
            getAttribute("itemBean");
        ItemInventoryBean itemInventoryBean = 
            (ItemInventoryBean)servletContext.
                getAttribute("itemInventoryBean");
        StringBuffer itemSubs = new StringBuffer();
        String stringKey = request.getParameter("item");
        if (stringKey == null) {stringKey = "0";}
        request.getSession().setAttribute("lastItem", stringKey);
        long key = Long.parseLong(stringKey);
        if (key != 0) {
            Item item = itemBean.getItem(key);
            if (item instanceof ItemOfGroup) {
                itemSubs.append("Item Group");
                itemSubs.append("
Key: " + item.getKey()); itemSubs.append("
Description: " + item.getDescription()); long[] itemsInGroup = ((ItemOfGroup)item).getItemsInGroup(); itemSubs.append("
Number of items in group: " + itemsInGroup.length); itemSubs.append("
"); for (int counter = 0; counter < itemsInGroup.length; counter++) { Item groupItem = itemBean.getItem(itemsInGroup[counter]); itemSubs.append( this.itemCommon(request, servletContext, groupItem)); itemSubs.append("
"); } } else { itemSubs.append(this.itemCommon(request, servletContext, item)); } }*/ return accountSb; } StringBuffer accountCommon(HttpServletRequest request, ServletContext servletContext, Account account) { //ItemBean itemBean = //(ItemBean)servletContext.getAttribute("itemBean"); //ItemInventoryBean itemInventoryBean = //(ItemInventoryBean)servletContext. // getAttribute("itemInventoryBean"); StringBuffer accountSubs = new StringBuffer(); /* long key = item.getKey(); itemSubs.append("
Key: " + item.getKey()); itemSubs.append("
Price: " + item.getPrice()); itemSubs.append("
Description: " + item.getDescription()); if (item.getHasInventory()) { ItemInventory itemInventory = itemInventoryBean.getItemInventory(key); long inventory = itemInventory.getInventory(); long reserved = itemInventory.getReserved(); itemSubs.append("Inventory: " + inventory); itemSubs.append("Reserved: " + reserved); if ((inventory - reserved) > 0) { itemSubs.append("Add To Cart"); } else { itemSubs.append("
Item is out of Stock"); } if (item instanceof ItemOfStuffWSizeColor) { itemSubs.append("
Size: " + ((ItemOfStuffWSizeColor)item).getSize()); itemSubs.append("
Color: " + ((ItemOfStuffWSizeColor)item).getColor()); } } else { itemSubs.append("Inventory: NA"); itemSubs.append("Reserved: NA"); itemSubs.append("<"+ "a href="/servlet/servlet.ControllerServlet?"+ "action=R&subaction=R&item="); itemSubs.append(item.getKey() + "&amount=1">Add To Cart"); } itemSubs.append("
"); itemSubs.append("");*/ return accountSubs; } }
To download source right-click here and "Save As...".
Comments
Sign in to be the first to comment on Java Cart AccountScreenWrangler java.