+++ /dev/null
-/*
- * Copyright (C) 2015 quix0r
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.pizzaapplication.tags.basket;
-
-import javax.servlet.jsp.tagext.BodyTag;
-import org.mxchange.jshop.beans.basket.BasketBean;
-
-/**
- *
- * @author quix0r
- */
-public interface BasketTag extends BodyTag {
-
- /**
- * @return the basket
- */
- public BasketBean getBasket ();
-
- /**
- * @param basket the basket to set
- */
- public void setBasket (final BasketBean basket);
-}
+++ /dev/null
-/*
- * Copyright (C) 2015 Roland Haeder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.pizzaapplication.tags.basket;
-
-import java.io.IOException;
-import java.rmi.RemoteException;
-import java.text.MessageFormat;
-import javax.servlet.ServletException;
-import javax.servlet.jsp.JspException;
-import javax.servlet.jsp.tagext.BodyTagSupport;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.mxchange.jshop.beans.basket.BasketBean;
-import org.mxchange.jshop.item.AddableBasketItem;
-import org.mxchange.jshop.product.Product;
-import org.mxchange.pizzaapplication.beans.controller.PizzaBean;
-
-/**
- * A basket tag that outputs a small basket and a link to the full basket website.
- *
- * @author Roland Haeder
- */
-public class MiniBasketTag extends BodyTagSupport implements BasketTag {
- /**
- * Serial number
- */
- private static final long serialVersionUID = 457415727452384L;
-
- /**
- * Basket instance
- */
- private BasketBean basket;
-
- /**
- * Logger instance
- */
- private final Logger LOG;
-
- /**
- * Initializer
- */
- {
- this.LOG = LogManager.getLogger(this);
- }
-
- /**
- * Outputs a div container with last added item + a link to the basket
- * web page.
- *
- * @return No need to process the body
- * @throws JspException If anything happens
- */
- @Override
- public int doStartTag () throws JspException {
- // Trace message
- this.LOG.trace("CALLED!"); //NOI18N
-
- // Init output
- StringBuilder out = new StringBuilder("<div class=\"mini_basket\">\n"); //NOI18N
-
- // basket should not be null
- if (this.getBasket() == null) {
- // Not set
- throw new NullPointerException("basket instance is null"); //NOI18N
- }
-
- try {
- // Some entries found?
- if (this.getBasket().isEmpty()) {
- // Empty basket
- out.append("<div class=\"mini_basket_box\">\n"); //NOI18N
- out.append(this.getBasket().getMessageStringFromKey("MiniBasketTag.basket_is_empty")).append("\n"); //NOI18N
- out.append("</div>\n"); //NOI18N
- } else {
- // Get all items
- AddableBasketItem item = this.getBasket().getLast();
-
- // item cannot be null here
- if (null == item) {
- // Abort here
- throw new NullPointerException("item is null"); //NOI18N
- }
-
- // Get application bean from session
- PizzaBean bean = (PizzaBean) this.getBasket().getSession().getAttribute("controller"); //NOI18N
-
- // Debug log
- this.LOG.debug(MessageFormat.format("bean={0}", bean)); //NOI18N
-
- // Should not be null
- if (null == bean) {
- // Abort here
- throw new NullPointerException("bean is null"); //NOI18N
- }
-
- // Get product instance
- Product product = bean.getProduct(item);
-
- // Debug message
- this.LOG.debug(MessageFormat.format("product={0}", product)); //NOI18N
-
- // Get last num rows
- int lastNumRows = this.getBasket().getLastNumRows();
-
- // Debug message
- this.LOG.debug(MessageFormat.format("lastNumRows={0}", lastNumRows)); //NOI18N
-
- // Output all
- out.append("<div class=\"mini_basket_box\">\n"); //NOI18N
- out.append(" <div class=\"mini_basket_header\">\n"); //NOI18N
- out.append(" ").append(this.getBasket().getMessageStringFromKey("MiniBasketTag.header")).append("\n"); //NOI18N
- out.append(" </div>\n"); //NOI18N
- out.append(" <div class=\"mini_basket_last\">\n"); //NOI18N
- out.append(" ").append(MessageFormat.format(this.getBasket().getMessageStringFromKey("MiniBasketTag.last_item"), product.getTitle())); //NOI18N
- out.append(" </div>\n"); //NOI18N
- out.append(" <div class=\"mini_basket_more\">\n"); //NOI18N
- out.append(" ").append(MessageFormat.format(this.getBasket().getMessageStringFromKey("MiniBasketTag.additional_items"), (lastNumRows - 1))); //NOI18N
- out.append(" </div>\n"); //NOI18N
- out.append(" <div class=\"mini_basket_link\">\n"); //NOI18N
- out.append(" <a href=\"").append(this.getBasket().getApplication().getContextPath()).append("/basket.jsp\">").append(this.getBasket().getMessageStringFromKey("MiniBasketTag.to_basket")).append("</a>\n"); //NOI18N
- out.append(" </div>\n"); //NOI18N
- out.append("</div>\n"); //NOI18N
- }
- } catch (final RemoteException ex) {
- // Continue to throw
- throw new JspException(ex);
- }
-
- try {
- // Get output instance and write it
- this.pageContext.getOut().print(out.toString());
- } catch (final IOException ex) {
- // Continue to throw
- throw new JspException(ex);
- }
-
- // Trace message
- this.LOG.trace(MessageFormat.format("Returning {0} ... - EXIT!", SKIP_BODY)); //NOI18N
-
- // Don't process any body
- return SKIP_BODY;
- }
-
- /**
- * @return the basket
- */
- @Override
- public BasketBean getBasket () {
- // Trace message
- //* NOISY-DEBUG: */ this.LOG.trace("basket=" + this.basket + " - EXIT!");
-
- // Return it
- return this.basket;
- }
-
- /**
- * @param basket the basket to set
- */
- @Override
- public void setBasket (final BasketBean basket) {
- // Trace message
- //* NOISY-DEBUG: */ this.LOG.trace("basked=" + basket + " - CALLED!");
-
- // Set it here
- this.basket = basket;
- }
-}