Java Cart .

Java Cart BaseScreenWrangler java

package cart.screenWranglers;

import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.ServletContext;

//baseScreenWrangler
//author - Lawrence Truett - FluffyCat.com
//date - June 5, 2003 - San Diego, CA
public abstract class BaseScreenWrangler {
    String nextScreen;
    BaseScreenWrangler nextWrangler;
    
    public BaseScreenWrangler() {}
    
    public BaseScreenWrangler(String nextScreenIn) {
        setNextScreen(nextScreenIn);
    }
    
    public abstract void wrangleScreen(HttpServletRequest request, 
                                       ServletContext servletContext);
    
    char baseNextScreenSwitch(HttpServletRequest request, 
                              ServletContext servletContext) {
        char action;
        
        String stringAction = request.getParameter("action");
        if (null == stringAction) {action = 'M';}
        else {action = stringAction.charAt(0);}
        
        switch (action) {
            case 'A' :
                HttpSession httpSession = request.getSession();
                boolean signedIn = 
                    ((Boolean)httpSession.
                    getAttribute("signedIn")).
                    booleanValue();
                if (signedIn) {
                    setNextWrangler(new AccountScreenWrangler());
                } else {
                    String stringSubAction = 
                        request.getParameter("subAction");
                    if ('N' ==  (null == stringSubAction ? 
                                 ' ' : stringSubAction.charAt(0))) {
                        setNextWrangler(new AccountScreenWrangler());
                    } else {
                        setNextWrangler(new PasswordScreenWrangler());
                    }
                }
                break;
            case 'R' :  
                setNextWrangler(new CartScreenWrangler()); break;
            case 'C' :  
                setNextWrangler(new CategoryScreenWrangler()); break;
            case 'I' :  
                setNextWrangler(new ItemScreenWrangler()); break;
            case 'M' :  
                setNextWrangler(new MainScreenWrangler()); break;
            case 'P' :  
                setNextWrangler(new PasswordScreenWrangler()); break;
            //case 'S' :  
            //  setNextWrangler(new SearchScreenWrangler()); break;
            default  :  
                setNextWrangler(new MainScreenWrangler());
        }
        return action;
    }
    
    abstract void prepFirstScreen(HttpServletRequest request, 
                                  ServletContext servletContext);
    
    public BaseScreenWrangler getNextWrangler() {
        return nextWrangler;
    }
    void setNextWrangler(BaseScreenWrangler nextWranglerIn) {
        nextWrangler = nextWranglerIn;
    }
    
    public String getNextScreen() {
        return nextScreen;
    }
    void setNextScreen(String nextScreenIn) {
        nextScreen = nextScreenIn;
    }
    
    void jspCatAttribute(HttpServletRequest request) {
        String lastCategory = 
            (String)(request.getSession().getAttribute("lastCategory"));
        StringBuffer catSubs = new StringBuffer();
        catSubs.append("Categories");
        request.setAttribute("jspCat", catSubs);
    }
    
    void jspItemAttribute(HttpServletRequest request) {
        String lastItem = 
            (String)(request.getSession().getAttribute("lastItem"));
        StringBuffer itemSubs = new StringBuffer();
        if (null == lastItem) {
            itemSubs.append("");
        } else {
            itemSubs.append(
                "<"+"a href="/servlet/servlet.ControllerServlet?"+
                "action=I&item=" + 
                lastItem + 
                "">back to last item<"+"/a>");
        }
        request.setAttribute("jspItem", itemSubs);
    }
}
To download source right-click here and "Save As...".
Comments
Sign in to be the first to comment on Java Cart BaseScreenWrangler java.