Package com.sun.bookstore.cart

Examples of com.sun.bookstore.cart.ShoppingCart


        String clear = null;
        BookDBAO bookDBAO = (BookDBAO) getServletContext()
                                           .getAttribute("bookDBAO");
        HttpSession session = request.getSession();
        String selectedScreen = request.getServletPath();
        ShoppingCart cart = (ShoppingCart) session.getAttribute("cart");

        if (cart == null) {
            cart = new ShoppingCart();
            session.setAttribute("cart", cart);
        }

        if (selectedScreen.equals("/bookcatalog")) {
            bookId = request.getParameter("Add");

            if (!bookId.equals("")) {
                try {
                    book = bookDBAO.getBook(bookId);

                    if (book.getOnSale()) {
                        double sale = book.getPrice() * .85;
                        Float salePrice = new Float(sale);
                        book.setPrice(salePrice.floatValue());
                    }

                    cart.add(bookId, book);
                } catch (BookNotFoundException ex) {
                    // not possible
                }
            }
        } else if (selectedScreen.equals("/bookshowcart")) {
            bookId = request.getParameter("Remove");

            if (bookId != null) {
                cart.remove(bookId);
            }

            clear = request.getParameter("Clear");

            if ((clear != null) && clear.equals("clear")) {
                cart.clear();
            }
        } else if (selectedScreen.equals("/bookreceipt")) {
            // Update the inventory
            try {
                utx.begin();
View Full Code Here


        PrintWriter writer = new PrintWriter(sw);
        ServletContext context = filterConfig.getServletContext();
        Counter counter = (Counter) context.getAttribute("orderCounter");
        HttpServletRequest hsr = (HttpServletRequest) request;
        HttpSession session = hsr.getSession();
        ShoppingCart cart = (ShoppingCart) session.getAttribute("cart");
        Currency c = (Currency) session.getAttribute("currency");
        c.setAmount(cart.getTotal());
        writer.println();
        writer.println(
                "=======================================================");
        writer.println(
                "The total number of orders is: " + counter.incCounter());
        writer.println(
                "This order Received at "
                + (new Timestamp(System.currentTimeMillis())));
        writer.println();
        writer.print("Purchased by: " + request.getParameter("cardname"));
        writer.println();
        writer.print("Total: " + c.getFormat());
        writer.println();

        int num = cart.getNumberOfItems();

        if (num > 0) {
            Iterator i = cart.getItems()
                             .iterator();

            while (i.hasNext()) {
                ShoppingCartItem item = (ShoppingCartItem) i.next();
                Book book = (Book) item.getItem();
View Full Code Here

        // Get the user's session and shopping cart
        HttpSession session = request.getSession(true);
        ResourceBundle messages = (ResourceBundle) session.getAttribute(
                    "messages");
        ShoppingCart cart = (ShoppingCart) session.getAttribute("cart");

        if (cart == null) {
            cart = new ShoppingCart();
            session.setAttribute("cart", cart);
        }

        // Update the inventory
        try {
View Full Code Here

        // Get the user's session and shopping cart
        HttpSession session = request.getSession(true);
        ResourceBundle messages = (ResourceBundle) session.getAttribute(
                    "messages");

        ShoppingCart cart = (ShoppingCart) session.getAttribute("cart");

        // If the user has no cart, create a new one
        if (cart == null) {
            cart = new ShoppingCart();
            session.setAttribute("cart", cart);
        }

        // set content type header before accessing the Writer
        response.setContentType("text/html");
        response.setBufferSize(8192);

        PrintWriter out = response.getWriter();

        //Print out the response
        out.println(
                "<html>" + "<head><title>"
                + messages.getString("TitleShoppingCart") + "</title></head>");

        // Get the dispatcher; it gets the banner to the user
        RequestDispatcher dispatcher = getServletContext()
                                           .getRequestDispatcher("/banner");

        if (dispatcher != null) {
            dispatcher.include(request, response);
        }

        /* Handle any pending deletes from the shopping cart and
           indicate the outcome as part of the response */
        String bookId = request.getParameter("Remove");
        Book bd;

        if (bookId != null) {
            try {
                bd = bookDB.getBook(bookId);
                cart.remove(bookId);
                out.println(
                        "<font color=\"#ff00000\" size=\"+2\">"
                        + messages.getString("CartRemoved") + "<strong>"
                        + bd.getTitle() + "</strong> <br> &nbsp; <br>"
                        + "</font>");
            } catch (BookNotFoundException ex) {
                response.reset();
                throw new ServletException(ex);
            }
        } else if (request.getParameter("Clear") != null) {
            cart.clear();
            out.println(
                    "<font color=\"#ff0000\" size=\"+2\"><strong>"
                    + messages.getString("CartCleared")
                    + "</strong> <br>&nbsp; <br> </font>");
        }

        // Print a summary of the shopping cart
        int num = cart.getNumberOfItems();

        if (num > 0) {
            out.println(
                    "<font size=\"+2\">" + messages.getString("CartContents")
                    + num
                    + ((num == 1) ? messages.getString("CartItem")
                                  : messages.getString("CartItems"))
                    + "</font><br>&nbsp;");

            // Return the Shopping Cart
            out.println(
                    "<table summary=\"layout\">" + "<tr>" + "<th align=left>"
                    + messages.getString("ItemQuantity") + "</TH>"
                    + "<th align=left>" + messages.getString("ItemTitle")
                    + "</TH>" + "<th align=left>"
                    + messages.getString("ItemPrice") + "</TH>" + "</tr>");

            Iterator i = cart.getItems()
                             .iterator();
            Currency c = (Currency) session.getAttribute("currency");

            if (c == null) {
                c = new Currency();
                c.setLocale(request.getLocale());
                session.setAttribute("currency", c);
            }

            while (i.hasNext()) {
                ShoppingCartItem item = (ShoppingCartItem) i.next();
                bd = (Book) item.getItem();
                c.setAmount(bd.getPrice());

                out.println(
                        "<tr>" + "<td align=\"right\" bgcolor=\"#ffffff\">"
                        + item.getQuantity() + "</td>"
                        + "<td bgcolor=\"#ffffaa\">" + "<strong><a href=\""
                        + response.encodeURL(
                                request.getContextPath()
                                + "/bookdetails?bookId=" + bd.getBookId())
                        + "\">" + bd.getTitle() + "</a></strong>" + "</td>"
                        + "<td bgcolor=\"#ffffaa\" align=\"right\">"
                        + c.getFormat() + "</td>" + "<td bgcolor=\"#ffffaa\">"
                        + "<strong>" + "<a href=\""
                        + response.encodeURL(
                                request.getContextPath()
                                + "/bookshowcart?Remove=" + bd.getBookId())
                        + "\">" + messages.getString("RemoveItem")
                        + "</a></strong>" + "</td></tr>");
            }

            c.setAmount(cart.getTotal());
            // Print the total at the bottom of the table
            out.println(
                    "<tr><td colspan=\"5\" bgcolor=\"#ffffff\">"
                    + "<br></td></tr>" + "<tr>"
                    + "<td colspan=\"2\" align=\"right\""
View Full Code Here

        // Get the user's session and shopping cart
        HttpSession session = request.getSession(true);
        ResourceBundle messages = (ResourceBundle) session.getAttribute(
                    "messages");

        ShoppingCart cart = (ShoppingCart) session.getAttribute("cart");

        // If the user has no cart, create a new one
        if (cart == null) {
            cart = new ShoppingCart();
            session.setAttribute("cart", cart);
        }

        // set content-type header before accessing the Writer
        response.setContentType("text/html");
        response.setBufferSize(8192);

        PrintWriter out = response.getWriter();

        // then write the data of the response
        out.println(
                "<html>" + "<head><title>"
                + messages.getString("TitleBookCatalog") + "</title></head>");

        // Get the dispatcher; it gets the banner to the user
        RequestDispatcher dispatcher = getServletContext()
                                           .getRequestDispatcher("/banner");

        if (dispatcher != null) {
            dispatcher.include(request, response);
        }

        //Information on the books is from the database through its front end

        // Additions to the shopping cart
        String bookId = request.getParameter("bookId");

        if (bookId != null) {
            try {
                Book book = bookDB.getBook(bookId);
                cart.add(bookId, book);
                out.println(
                        "<p><h3>" + "<font color=\"#ff0000\">"
                        + messages.getString("CartAdded1") + "<i>"
                        + book.getTitle() + "</i> "
                        + messages.getString("CartAdded2") + "</font></h3>");
            } catch (BookNotFoundException ex) {
                response.reset();
                throw new ServletException(ex);
            }
        }

        //Give the option of checking cart or checking out if cart not empty
        if (cart.getNumberOfItems() > 0) {
            out.println(
                    "<p><strong><a href=\""
                    + response.encodeURL(
                            request.getContextPath() + "/bookshowcart") + "\">"
                    + messages.getString("CartCheck")
View Full Code Here

        // Get the user's session and shopping cart
        HttpSession session = request.getSession();
        ResourceBundle messages = (ResourceBundle) session.getAttribute(
                    "messages");

        ShoppingCart cart = (ShoppingCart) session.getAttribute("cart");

        if (cart == null) {
            cart = new ShoppingCart();
            session.setAttribute("cart", cart);
        }

        // set content-type header before accessing Writer
        response.setContentType("text/html");

        PrintWriter out = response.getWriter();
        Currency c = (Currency) session.getAttribute("currency");

        if (c == null) {
            c = new Currency();
            c.setLocale(request.getLocale());
            session.setAttribute("currency", c);
        }

        c.setAmount(cart.getTotal());

        // then write the data of the response
        out.println(
                "<html>" + "<head><title>" + messages.getString("TitleCashier")
                + "</title></head>");
View Full Code Here

        BookDBAO bookDBAO = (BookDBAO) getServletContext()
                                           .getAttribute("bookDBAO");
        HttpSession session = request.getSession();
        String selectedScreen = request.getServletPath();

        ShoppingCart cart = (ShoppingCart) session.getAttribute("cart");

        if (cart == null) {
            cart = new ShoppingCart();
            session.setAttribute("cart", cart);
        }

        if (selectedScreen.equals("/books/bookcatalog")) {
            bookId = request.getParameter("Add");

            if (!bookId.equals("")) {
                try {
                    book = bookDBAO.getBook(bookId);
                    cart.add(bookId, book);
                } catch (BookNotFoundException ex) {
                    // not possible
                }
            }
        } else if (selectedScreen.equals("/books/bookshowcart")) {
            bookId = request.getParameter("Remove");

            if (bookId != null) {
                cart.remove(bookId);
            }

            clear = request.getParameter("Clear");

            if ((clear != null) && clear.equals("clear")) {
                cart.clear();
            }
        } else if (selectedScreen.equals("/books/bookreceipt")) {
            // Update the inventory
            try {
                utx.begin();
View Full Code Here

        BookDBAO bookDBAO = (BookDBAO) getServletContext()
                                           .getAttribute("bookDBAO");
        HttpSession session = request.getSession();
        String selectedScreen = request.getServletPath();

        ShoppingCart cart = (ShoppingCart) session.getAttribute("cart");

        if (cart == null) {
            cart = new ShoppingCart();
            session.setAttribute("cart", cart);
        }

        if (selectedScreen.equals("/books/bookcatalog")) {
            bookId = request.getParameter("Add");

            if (!bookId.equals("")) {
                try {
                    book = bookDBAO.getBook(bookId);
                    cart.add(bookId, book);
                } catch (BookNotFoundException ex) {
                    // not possible
                }
            }
        } else if (selectedScreen.equals("/books/bookshowcart")) {
            bookId = request.getParameter("Remove");

            if (bookId != null) {
                cart.remove(bookId);
            }

            clear = request.getParameter("Clear");

            if ((clear != null) && clear.equals("clear")) {
                cart.clear();
            }
        } else if (selectedScreen.equals("/books/bookreceipt")) {
            // Update the inventory
            try {
                utx.begin();
View Full Code Here

TOP

Related Classes of com.sun.bookstore.cart.ShoppingCart

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.