Examples of MusicStoreAppBean


Examples of org.apache.taglibs.rdc.sampleapps.musicstore.MusicStoreAppBean

            throws Exception {

        AlbumFilterForm afForm = (AlbumFilterForm) form;
        MusicAlbum albums[] = null;
        HttpSession session = request.getSession();
        MusicStoreAppBean msBean = (MusicStoreAppBean) session
                .getAttribute(MusicStoreAppBean.SESSION_KEY);
       
        try {
            AmazonMenuTemplate.AmazonMenuResult selection = afForm.getChoice();
            if (selection == null) {
                selection = msBean.getMenuResult();
            } else {
                msBean.setMenuResult(selection);
            }
            int genre = Integer.parseInt(selection.getGenre());
            int catgr = Integer.parseInt(selection.getCategory());
            MusicStore ms = msBean.getMusicStore();
            switch (catgr) {
            case CATEGORY_FEATURED_ITEMS:
                albums = ms.getFeaturedItems(genre);
            case CATEGORY_NEW_RELEASES:
                albums = ms.getNewReleases(genre);
            case CATEGORY_TOP_SELLERS:
                albums = ms.getTopSellers(genre);
                break;
            default:
                throw new IllegalArgumentException("Illegal category: " +
                                                   catgr);
            }

            if (msBean.getChannel() == MusicStoreAppBean.GUI_APP) {
                // GUI Channel
                HTMLMenuLinks menuLinks = msBean.getMenuLinks();
                menuLinks.generateAlbumLinks(albums);
            } else {
                // Voice Channel
                //cleanup RDC history
                session.removeAttribute("dialogMap");
                SelectOne.Options options = new SelectOne.Options();
                for (int i = 0; i < albums.length; i++) {
                    options.add(albums[i].getASIN(), albums[i].getTitle()
                            .replaceAll("&", "and"));
                }
                msBean.setOptions(options);
                msBean.setChoice(selection.getReadableValue());
            }
            msBean.setAlbums(albums);
            return mapping.findForward("OK");
        } catch (Exception e) {
            log.error("An exception caught while applying parameters.", e);
            msBean.setErrorDescription(e.getMessage());
            return mapping.findForward("invalidParams");
        }
    }
View Full Code Here

Examples of org.apache.taglibs.rdc.sampleapps.musicstore.MusicStoreAppBean

  public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
     
    HttpSession session = request.getSession();
    MusicStoreAppBean msBean = (MusicStoreAppBean)
      session.getAttribute(MusicStoreAppBean.SESSION_KEY);

    if (msBean == null) {
      String subscriptionId = session.getServletContext().
      getInitParameter("com.amazon.ecs.subscriptionId");
      msBean = new MusicStoreAppBean(subscriptionId);
      session.setAttribute(MusicStoreAppBean.SESSION_KEY, msBean);
     
      // Initialize channel information
      String userAgent = request.getHeader(USERAGENT);
      if (userAgent.indexOf(MOZILLA) >= 0) {
        if (request.getParameter("VDEBUG") == null) {
          msBean.setChannel(MusicStoreAppBean.GUI_APP)
        } else {
          // if VDEBUG is set, output voice page instead    
          msBean.setChannel(MusicStoreAppBean.VOICE_DBG);
        }
      } else {
        msBean.setChannel(MusicStoreAppBean.VOICE_APP);
      }
    }
   
    if (msBean.getChannel() == MusicStoreAppBean.GUI_APP) {
      // GUI Channel
      HTMLMenuLinks menuLinks = msBean.getMenuLinks();

      if (menuLinks == null) {
        String baseURI = "http://" + request.getServerName();
        int port = request.getServerPort();
        if (80 != port && 0 != port && 443 != port) {
          baseURI += ":" + Integer.toString(port, 10);
        }
        baseURI += request.getContextPath();
        menuLinks = new HTMLMenuLinks(baseURI);
        msBean.setMenuLinks(menuLinks);
      }

      String genre = request.getParameter("genre");
      if (genre == null) {
        if (request.getParameter("browseMusic") == null) {
          menuLinks.generateCategoryLinks(
                  HTMLMenuLinks.DEFAULT_GENRE, true);
        } else {
          menuLinks.generateGenreLinks();
        }
      } else {
        menuLinks.generateCategoryLinks(genre, false);
      }
    } else {
      // Voice Channel
      ProactiveHelp ph = msBean.getProactiveHelp();

      if(ph == null) {
        ph = new ProactiveHelp();
        ResourceBundle rb = ResourceBundle.
          getBundle("org.apache.taglibs.rdc.sampleapps.musicstore.resources.MusicHints",
            Locale.US);
        ph.setHints(rb);
        ph.setThreshold(60);
        ph.setUsageWeighted(true);
        msBean.setProactiveHelp(ph);
      }
     
      if (ph.strike()) {
        request.setAttribute("proactiveHelp_hint", ph.nextHint());
      }
View Full Code Here

Examples of org.apache.taglibs.rdc.sampleapps.musicstore.MusicStoreAppBean

  public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {

    HttpSession session = request.getSession();
    MusicStoreAppBean msBean = (MusicStoreAppBean) session.
      getAttribute(MusicStoreAppBean.SESSION_KEY);
    CheckoutForm coForm = (CheckoutForm) form;
    String action = coForm.getAction();
    Cart currentCart = msBean.getCart();
   
    if (currentCart == null && !action.equals("shopping")) {
      msBean.setErrorDescription("Shopping cart is empty or " +
        "cart not found.");
      return mapping.findForward("onerror");
    }

    // Voice specified calls
    if (msBean.getChannel() == MusicStoreAppBean.VOICE_APP ||
          msBean.getChannel() == MusicStoreAppBean.VOICE_DBG ) {
         
          //cleanup session from RDCs
      session.removeAttribute("dialogMap");
     
      if (action.equals("checkout")) {
        String hostURI = getHostAsPrompt(request.getServerName());
        int port = request.getServerPort();         
        if (80 != port && 0 != port && 443 != port) {
          hostURI += " colon " + Integer.toString(port, 10) ;
        }
        String prompt = createCartLink(session, currentCart, hostURI);
        msBean.setCheckoutPrompt(prompt);
      } else if (action.equals("viewcart")) {
        StringBuffer prompt = new StringBuffer("These following titles " +
          "are in your cart. ");
        CartItem[] items = currentCart.getCartItems();
        for (int i = 0; i < items.length; i++) {
          prompt.append(items[i].getTitle()).append(", ");
        }
        request.setAttribute("promptContent", prompt.toString());
      }
    }

    if (action.equals("checkout")) {
      return mapping.findForward("goodbye");
    } else if (action.equals("viewcart")) {
      return mapping.findForward("viewcart");
    } else if (action.equals("shopping")) {
      return mapping.findForward("continueshop");
    } else {
      msBean.setErrorDescription("Error, unknown checkout action.");
      return mapping.findForward("onerror");
    }
  }
View Full Code Here

Examples of org.apache.taglibs.rdc.sampleapps.musicstore.MusicStoreAppBean

    throws Exception {
     
    IndividualAlbumForm iaForm = (IndividualAlbumForm) form;
    String asin = iaForm.getAsin();
    HttpSession session = request.getSession();
    MusicStoreAppBean msBean = (MusicStoreAppBean) session.
      getAttribute(MusicStoreAppBean.SESSION_KEY);
    MusicAlbum[] albums = msBean.getAlbums();
    if (albums == null) {
      msBean.setErrorDescription("Albums array not found in session");
      return mapping.findForward("notFound");
    }   
    MusicAlbum currentAlbum = null;
    for (int i = 0; i < albums.length; i++) {
      if (asin.equals(albums[i].getASIN())) {
        currentAlbum = albums[i];
        break;
      }
    }
   
    if (msBean.getChannel() == MusicStoreAppBean.VOICE_APP) {
      //cleanup RDC history
      session.removeAttribute("dialogMap");
    }

    if (currentAlbum == null) {
      msBean.setErrorDescription("Album (" + asin + ") not found.");
      return mapping.findForward("notFound");
    } else {
      msBean.setCurrentAlbum(currentAlbum);
      return mapping.findForward("albumfound");
    }
  }
View Full Code Here

Examples of org.apache.taglibs.rdc.sampleapps.musicstore.MusicStoreAppBean

    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        HttpSession session = request.getSession();
        MusicStoreAppBean msBean = (MusicStoreAppBean) session
                .getAttribute(MusicStoreAppBean.SESSION_KEY);

        MusicAlbum album = msBean.getCurrentAlbum();
       
        if (album == null) {
            msBean.setErrorDescription("Current album not found in "
                    + "MusicStoreAppBean");
            return mapping.findForward("onerror");
        }
       
        MusicStore ms = msBean.getMusicStore();
        MusicAlbum albums[] = ms.getSimilarItems(album);
        //override the old Albums array in session
        msBean.setAlbums(albums);
       
        if (msBean.getChannel() == MusicStoreAppBean.GUI_APP) {
            // GUI Channel
            HTMLMenuLinks menuLinks = msBean.getMenuLinks();
            menuLinks.generateAlbumLinks(albums);
        } else {
            // Voice Channel
            //cleanup RDC history
            session.removeAttribute("dialogMap");
            SelectOne.Options options = new SelectOne.Options();
            for (int i = 0; i < albums.length; i++) {
                options.add(albums[i].getASIN(), albums[i].getTitle()
                        .replaceAll("&", "and"));
            }
            msBean.setOptions(options);
            msBean.setChoice(" items similar to " + album.getTitle());
        }
        return mapping.findForward("OK");
    }
View Full Code Here

Examples of org.apache.taglibs.rdc.sampleapps.musicstore.MusicStoreAppBean

    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        HttpSession session = request.getSession();
    MusicStoreAppBean msBean = (MusicStoreAppBean) session.
      getAttribute(MusicStoreAppBean.SESSION_KEY);
        MusicStore ms = msBean.getMusicStore();
        Cart currentCart = msBean.getCart();
        MusicAlbum currentAlbum = msBean.getCurrentAlbum();

        if (currentCart != null) {
            currentCart = ms.addToCart(currentCart, currentAlbum, 1);
        } else {
            if (currentAlbum != null) {
                currentCart = ms.createCart(currentAlbum, 1);
            }
        }
    //cleanup session from RDCs
    session.removeAttribute("dialogMap");
   
        if (currentAlbum == null || currentCart == null) {
            msBean.setErrorDescription("Failed to add album to your " +
              "shopping cart. please try again.");
            return mapping.findForward("onerror");
        }

        msBean.setCart(currentCart);
        String title = currentAlbum.getTitle();
        request.setAttribute("promptContent", "Added " + title +
      " to the shopping cart.");
    return mapping.findForward("OK");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.