--- /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.basket;
+
+import java.sql.SQLException;
+import org.mxchange.pizzaapplication.database.frontend.basket.BasketDatabaseFrontend;
+import java.text.MessageFormat;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.mxchange.jcore.BaseFrameworkSystem;
+import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
+import org.mxchange.pizzaapplication.database.frontend.basket.BasketFrontend;
+import org.mxchange.pizzaapplication.item.AddableBasketItem;
+
+/**
+ * A general basket class
+ *
+ * @author Roland Haeder
+ */
+public class BaseBasket extends BaseFrameworkSystem implements Basket<AddableBasketItem> {
+ /**
+ * Item map
+ */
+ private final Map<Long, AddableBasketItem> items;
+
+ /**
+ * Protected constructor with session instance
+ *
+ * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If an unsupported backend has been configured
+ * @throws java.sql.SQLException If an SQL error occurs
+ */
+ protected BaseBasket () throws UnsupportedDatabaseBackendException, SQLException {
+ // Trace message
+ this.getLogger().trace("CALLED!");
+
+ // Init item map instance
+ this.items = new LinkedHashMap<>();
+
+ // Create frontend instance
+ BasketFrontend frontend = new BasketDatabaseFrontend();
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("frontend={0} being set ...", frontend));
+
+ // Instance it here
+ this.setFrontend(frontend);
+ }
+
+ @Override
+ public void addItem (final AddableBasketItem item) {
+ // Add it to map
+ this.items.put(item.getId(), item);
+ }
+}
--- /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.basket;
+
+import org.mxchange.jcore.FrameworkInterface;
+import org.mxchange.pizzaapplication.item.AddableBasketItem;
+
+/**
+ * An interface for baskets
+ *
+ * @author Roland Haeder
+ * @param <T> Any addable basket items
+ */
+public interface Basket<T extends AddableBasketItem> extends FrameworkInterface {
+
+ /**
+ * Adds given item instance to this basket
+ * @param item Item instance to add
+ */
+ public void addItem (final AddableBasketItem item);
+
+}
--- /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.basket.item;
+
+import java.sql.SQLException;
+import javax.servlet.http.HttpSession;
+import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
+import org.mxchange.pizzaapplication.basket.BaseBasket;
+import org.mxchange.pizzaapplication.basket.Basket;
+import org.mxchange.pizzaapplication.item.AddableBasketItem;
+
+/**
+ * A basket for orderable items
+ *
+ * @author Roland Haeder
+ */
+public class ItemBasket extends BaseBasket implements Basket<AddableBasketItem> {
+
+ /**
+ * Creates a singleton instance from given session's id
+ *
+ * @param session
+ * @return A session-id based singleton instance of this basket
+ * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If an unsupported backend was configured
+ * @throws java.sql.SQLException If an SQL error occurs
+ */
+ @SuppressWarnings ("unchecked")
+ public final static Basket<AddableBasketItem> getInstance (final HttpSession session) throws UnsupportedDatabaseBackendException, SQLException {
+ // Get instance
+ Basket<AddableBasketItem> basket = (Basket<AddableBasketItem>) session.getAttribute("basket");
+
+ // Is the basket already created?
+ if (!(basket instanceof BaseBasket)) {
+ // Not yet, so create it
+ basket = new ItemBasket();
+
+ // Add it in session
+ session.setAttribute("basket", basket);
+ }
+
+ // Return it casted
+ return basket;
+ }
+
+ /**
+ * Default constructor to be able to throw exceptions from super constructor
+ */
+ private ItemBasket () throws UnsupportedDatabaseBackendException, SQLException {
+ }
+}
--- /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.database.frontend.basket;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.sql.SQLException;
+import java.text.MessageFormat;
+import java.util.Map;
+import org.mxchange.jcore.database.frontend.BaseDatabaseFrontend;
+import org.mxchange.jcore.database.storage.Storeable;
+import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
+
+/**
+ * A database frontend for baskets
+ *
+ * @author Roland Haeder
+ */
+public class BasketDatabaseFrontend extends BaseDatabaseFrontend implements BasketFrontend {
+ /**
+ * General constructor
+ *
+ * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If an unsupported backend was configured
+ * @throws java.sql.SQLException If any SQL error occurs
+ */
+ public BasketDatabaseFrontend () throws UnsupportedDatabaseBackendException, SQLException {
+ // Trace message
+ this.getLogger().trace("CALLED!"); //NOI18N
+
+ // Set "table" name
+ this.setTableName("basket"); //NOI18N
+
+ // Initalize backend
+ this.initBackend();
+ }
+
+ /**
+ * Shuts down the database layer
+ *
+ * @throws java.sql.SQLException If an SQL error occurs
+ * @throws java.io.IOException If any IO error occurs
+ */
+ @Override
+ public void doShutdown () throws SQLException, IOException {
+ // Trace message
+ this.getLogger().trace("CALLED!"); //NOI18N
+
+ // Shutdown backend
+ this.getBackend().doShutdown();
+
+ // Trace message
+ this.getLogger().trace("EXIT!"); //NOI18N
+ }
+
+ /**
+ * Depending on column, an empty value may be converted to null
+ *
+ * @param key Key to check
+ * @param value Value to check
+ * @return Possible previous value or null
+ * @todo Nothing will be changed now
+ */
+ @Override
+ public Object emptyStringToNull (final String key, final Object value) {
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("key={0},value={1} - CALLED!", key, value)); //NOI18N
+
+ // Copy value
+ Object v = value;
+
+ // Is the value empty?
+ if ((value instanceof String) && ("".equals(value))) { //NOI18N
+ // This value may need to be changed
+ switch (key) {
+ }
+ }
+
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("v={0} - EXIT!", v)); //NOI18N
+
+ // Return it
+ return v;
+ }
+
+ @Override
+ public String getIdName () {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public Storeable toStoreable (final Map<String, String> map) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ throw new UnsupportedOperationException("Not supported yet: map=" + map);
+ }
+}
--- /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.database.frontend.basket;
+
+import org.mxchange.jcore.database.frontend.DatabaseFrontend;
+
+/**
+ * An interface for basket database frontends
+ *
+ * @author Roland Haeder
+ */
+public interface BasketFrontend extends DatabaseFrontend {
+}
@Override
public void addCategory (final String title, final Integer parent) throws SQLException, IOException {
// Trace message
- this.getLogger().trace(MessageFormat.format("title={0},parent={1} - CALLED!", title, parent));
+ this.getLogger().trace(MessageFormat.format("title={0},parent={1} - CALLED!", title, parent)); //NOI18N
// Title should not be null
if (title == null) {
// Abort here
- throw new NullPointerException("title is null");
+ throw new NullPointerException("title is null"); //NOI18N
}
// Clear dataset from previous usage
Result<? extends Storeable> result = this.doInsertDataSet();
// Debug message
- this.getLogger().debug(MessageFormat.format("result={0}", result));
+ this.getLogger().debug(MessageFormat.format("result={0}", result)); //NOI18N
// Trace message
- this.getLogger().trace("EXIT!");
+ this.getLogger().trace("EXIT!"); //NOI18N
}
/**
@Override
public Object emptyStringToNull (final String key, final Object value) {
// Trace message
- this.getLogger().trace(MessageFormat.format("key={0},value={1} - CALLED!", key, value));
+ this.getLogger().trace(MessageFormat.format("key={0},value={1} - CALLED!", key, value)); //NOI18N
// Copy value
Object v = value;
// Is the value empty?
- if ((value instanceof String) && ("".equals(value))) {
+ if ((value instanceof String) && ("".equals(value))) { //NOI18N
// This value may need to be changed
switch (key) {
case PizzaCategoryDatabaseConstants.COLUMN_PARENT: // Convert this
}
// Trace message
- this.getLogger().trace(MessageFormat.format("v={0} - EXIT!", v));
+ this.getLogger().trace(MessageFormat.format("v={0} - EXIT!", v)); //NOI18N
// Return it
return v;
@Override
public Category getCategory (final Product product) throws IOException, BadTokenException, CorruptedDatabaseFileException, SQLException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// Trace message
- this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product));
+ this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product)); //NOI18N
// product must not be null
if (product == null) {
// Abort here
- throw new NullPointerException("product is null");
+ throw new NullPointerException("product is null"); //NOI18N
}
// Get category id from it
Long id = product.getCategory();
// Debug message
- this.getLogger().debug(MessageFormat.format("id={0}", id));
+ this.getLogger().debug(MessageFormat.format("id={0}", id)); //NOI18N
// It should be >0 here
- assert(id > 0) : MessageFormat.format("id={0} must be larger zero", id);
+ assert(id > 0) : MessageFormat.format("id={0} must be larger zero", id); //NOI18N
// Then construct a search instance
SearchableCriteria criteria = new SearchCriteria();
Result<? extends Storeable> result = this.getBackend().doSelectByCriteria(criteria);
// Debug log
- this.getLogger().debug(MessageFormat.format("result({0})={1}", result, result.size()));
+ this.getLogger().debug(MessageFormat.format("result({0})={1}", result, result.size())); //NOI18N
// Init category instance
Category category = null;
Storeable storeable = result.next();
// Debug message
- this.getLogger().debug(MessageFormat.format("storeable={0}", storeable));
+ this.getLogger().debug(MessageFormat.format("storeable={0}", storeable)); //NOI18N
// Is it instance of Category?
if (storeable instanceof Category) {
}
// Trace message
- this.getLogger().trace(MessageFormat.format("category={0} - EXIT!", category));
+ this.getLogger().trace(MessageFormat.format("category={0} - EXIT!", category)); //NOI18N
// Return it
return category;
@Override
public Result<? extends Storeable> getResultFromSet (final ResultSet resultSet) throws SQLException {
// Trace message
- this.getLogger().trace(MessageFormat.format("resultSet={0} - CALLED!", resultSet));
+ this.getLogger().trace(MessageFormat.format("resultSet={0} - CALLED!", resultSet)); //NOI18N
// Init result instance
Result<? extends Storeable> result = new DatabaseResult();
Long parent = resultSet.getLong(PizzaCategoryDatabaseConstants.COLUMN_PARENT);
// Debug message
- this.getLogger().debug(MessageFormat.format("id={0},title={1},parent={2}", id, title, parent));
+ this.getLogger().debug(MessageFormat.format("id={0},title={1},parent={2}", id, title, parent)); //NOI18N
// Instance new object
Category category = new ProductCategory(id, title, parent);
// Debug log
- this.getLogger().debug(MessageFormat.format("category={0}", category));
+ this.getLogger().debug(MessageFormat.format("category={0}", category)); //NOI18N
// Add it to result
result.add(category);
}
// Trace message
- this.getLogger().trace(MessageFormat.format("result({0})={1} - EXIT!", result.size(), result));
+ this.getLogger().trace(MessageFormat.format("result({0})={1} - EXIT!", result.size(), result)); //NOI18N
// Return result
return result;
@Override
public boolean isCategoryTitleUsed (final String title) throws IOException, SQLException, BadTokenException, CorruptedDatabaseFileException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// Trace message
- this.getLogger().trace(MessageFormat.format("title={0} - CALLED!", title));
+ this.getLogger().trace(MessageFormat.format("title={0} - CALLED!", title)); //NOI18N
// Get search criteria
SearchableCriteria criteria = new SearchCriteria();
Result<? extends Storeable> result = this.getBackend().doSelectByCriteria(criteria);
// Debug log
- this.getLogger().debug(MessageFormat.format("result({0})={1}", result, result.size()));
+ this.getLogger().debug(MessageFormat.format("result({0})={1}", result, result.size())); //NOI18N
// Now check size of the result
boolean isFound = (result.size() == 1);
// Trace message
- this.getLogger().trace(MessageFormat.format("isFound={0} - EXIT!", isFound));
+ this.getLogger().trace(MessageFormat.format("isFound={0} - EXIT!", isFound)); //NOI18N
// Return it
return isFound;
@Override
public Storeable toStoreable (final Map<String, String> map) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// Trace message
- this.getLogger().trace(MessageFormat.format("map={0} - CALLED!", map));
+ this.getLogger().trace(MessageFormat.format("map={0} - CALLED!", map)); //NOI18N
// Is map null?
if (map == null) {
// Is null
- throw new NullPointerException("map is null");
+ throw new NullPointerException("map is null"); //NOI18N
} else if (map.isEmpty()) {
// Map is empty
- throw new IllegalArgumentException("map is empty.");
+ throw new IllegalArgumentException("map is empty."); //NOI18N
}
// Debug message
- this.getLogger().debug(MessageFormat.format("Has to handle {0} entries", map.size()));
+ this.getLogger().debug(MessageFormat.format("Has to handle {0} entries", map.size())); //NOI18N
// Get iterator on all entries
Iterator<Map.Entry<String, String>> iterator = map.entrySet().iterator();
Map.Entry<String, String> entry = iterator.next();
// Debug message
- this.getLogger().debug(MessageFormat.format("entry:{0}={1}", entry.getKey(), entry.getValue()));
+ this.getLogger().debug(MessageFormat.format("entry:{0}={1}", entry.getKey(), entry.getValue())); //NOI18N
// Try to set value
instance.setValueFromColumn(entry.getKey(), entry.getValue());
}
// Trace message
- this.getLogger().trace(MessageFormat.format("instance={0} - EXIT!", instance));
+ this.getLogger().trace(MessageFormat.format("instance={0} - EXIT!", instance)); //NOI18N
// Return it
return instance;
+++ /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.filter.http;
-
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import org.mxchange.jcore.BaseFrameworkSystem;
-
-/**
- * A general HTTP servlet filter class
- * @author Roland Haeder
- */
-public class BaseServletFilter extends BaseFrameworkSystem {
- /**
- * Configuration instance
- */
- private FilterConfig config;
-
- /**
- * Destroys this filter
- */
- public void destroy () {
- // Unset config instance
- this.setConfig(null);
- }
-
- /**
- * Initializes this filter
- *
- * @param filterConfig Filter configuration
- * @throws ServletException
- */
- public void init (final FilterConfig filterConfig) throws ServletException {
- // Set config instance
- this.setConfig(filterConfig);
- }
-
- /**
- * Configuration instance
- * @return the config
- */
- protected FilterConfig getConfig () {
- return this.config;
- }
-
- /**
- * Configuration instance
- * @param config the config to set
- */
- protected void setConfig (final FilterConfig config) {
- this.config = config;
- }
-}
+++ /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.filter.http.utf8;
-
-import java.io.IOException;
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import org.mxchange.pizzaapplication.filter.http.BaseServletFilter;
-
-/**
- * A HTTP filter for setting UTF-8 character encoding.
- *
- * @author Roland Haeder
- */
-public class Utf8HttpFilter extends BaseServletFilter implements Filter {
- /**
- * Filter to set UTF-8 encoding
- *
- * @param request ServletRequest instance
- * @param response ServletResponse instance
- * @param chain FilterChain instance
- * @throws IOException
- * @throws ServletException
- */
- @Override
- public void doFilter (final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
- // Call super method
- chain.doFilter(request, response);
-
- // Set response/request both to UTF-8
- request.setCharacterEncoding("UTF-8"); //NOI18N
- response.setCharacterEncoding("UTF-8"); //NOI18N
- }
-}
--- /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.filter.servlet;
+
+import java.text.MessageFormat;
+import javax.servlet.Filter;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import org.mxchange.jcore.BaseFrameworkSystem;
+
+/**
+ * A general servlet filter class. If you need to override init() or
+ * destroy() please always call the super method first and handle over all
+ * parameter.
+ *
+ * @author Roland Haeder
+ */
+public abstract class BaseServletFilter extends BaseFrameworkSystem implements Filter {
+ /**
+ * Configuration instance
+ */
+ private FilterConfig config;
+
+ /**
+ * Destroys this filter
+ */
+ @Override
+ public void destroy () {
+ // Unset config instance
+ this.setConfig(null);
+ }
+
+ /**
+ * Initializes this filter
+ *
+ * @param filterConfig Filter configuration
+ * @throws ServletException
+ */
+ @Override
+ public void init (final FilterConfig filterConfig) throws ServletException {
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("filterConfig={0} - CALLED!", filterConfig));
+
+ // Set config instance
+ this.setConfig(filterConfig);
+
+ // Trace message
+ this.getLogger().trace("EXIT!");
+ }
+
+ /**
+ * Configuration instance
+ * @return the config
+ */
+ protected final FilterConfig getConfig () {
+ return this.config;
+ }
+
+ /**
+ * Configuration instance
+ * @param config the config to set
+ */
+ private void setConfig (final FilterConfig config) {
+ this.config = config;
+ }
+}
--- /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.filter.servlet.basket;
+
+import java.io.IOException;
+import java.sql.SQLException;
+import java.text.MessageFormat;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException;
+import org.mxchange.pizzaapplication.basket.Basket;
+import org.mxchange.pizzaapplication.basket.item.ItemBasket;
+import org.mxchange.pizzaapplication.filter.servlet.BaseServletFilter;
+import org.mxchange.pizzaapplication.item.AddableBasketItem;
+
+/**
+ * A filter for handling added basket items
+ *
+ * @author Roland Haeder
+ */
+public class BasketItemAddedFilter extends BaseServletFilter implements Filter {
+
+ @Override
+ public void doFilter (final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("request={0},response={1},chain={2} - CALLED!", request, response, chain));
+
+ // All must be set
+ if (request == null) {
+ // request is null
+ throw new NullPointerException("request is null");
+ } else if (response == null) {
+ // response is null
+ throw new NullPointerException("response is null");
+ } else if (chain == null) {
+ // chain is null
+ throw new NullPointerException("chain is null");
+ }
+
+ // Call doFilter to move on
+ chain.doFilter(request, response);
+
+ // Get session instance
+ HttpSession session = ((HttpServletRequest) request).getSession();
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("session={0}", session));
+
+ // Should not be null
+ if (session == null) {
+ // session is null
+ throw new NullPointerException("session is null");
+ }
+
+ // Get item instance
+ Object item = session.getAttribute("item");
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("item={0}", item));
+
+ // item should not be null
+ if (item == null) {
+ // item is null
+ throw new NullPointerException("item is null");
+ } else if (!(item instanceof AddableBasketItem)) {
+ // Not right instance
+ throw new IllegalArgumentException("item does not implement OrderableItem");
+ }
+
+ // Get basket instance
+ Basket<AddableBasketItem> basket;
+ try {
+ basket = ItemBasket.getInstance(session);
+ } catch (final UnsupportedDatabaseBackendException | SQLException ex) {
+ // Continue to throw
+ throw new ServletException(ex);
+ }
+
+ // Register item with it
+ basket.addItem((AddableBasketItem) item);
+
+ // Trace message
+ this.getLogger().trace("EXIT!");
+ }
+
+}
--- /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.filter.servlet.utf8;
+
+import java.io.IOException;
+import java.text.MessageFormat;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import org.mxchange.pizzaapplication.filter.servlet.BaseServletFilter;
+
+/**
+ * A HTTP filter for setting UTF-8 character encoding.
+ *
+ * @author Roland Haeder
+ */
+public class Utf8ServletFilter extends BaseServletFilter implements Filter {
+ /**
+ * Filter to set UTF-8 encoding
+ *
+ * @param request ServletRequest instance
+ * @param response ServletResponse instance
+ * @param chain FilterChain instance
+ * @throws IOException
+ * @throws ServletException
+ */
+ @Override
+ public void doFilter (final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
+ // Trace message
+ this.getLogger().trace(MessageFormat.format("request={0},response={1},chain={2} - CALLED!", request, response, chain));
+
+ // Call super method
+ chain.doFilter(request, response);
+
+ // Set response/request both to UTF-8
+ request.setCharacterEncoding("UTF-8"); //NOI18N
+ response.setCharacterEncoding("UTF-8"); //NOI18N
+
+ // Trace message
+ this.getLogger().trace("EXIT!");
+ }
+}
--- /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.item;
+
+import org.mxchange.jcore.FrameworkInterface;
+
+/**
+ * An interface for addable basket items
+ *
+ * @author Roland Haeder
+ */
+public interface AddableBasketItem extends FrameworkInterface {
+
+ /**
+ * @return the id
+ */
+ public Long getId ();
+
+ /**
+ * @param id the id to set
+ */
+ public void setId (final Long id);
+
+ /**
+ * @return the type
+ */
+ public String getType ();
+
+ /**
+ * @param type the type to set
+ */
+ public void setType (final String type);
+}
* A general item cl
* @author Roland Haeder
*/
-public class BaseItem extends BaseFrameworkSystem implements OrderableItem {
+public class BaseItem extends BaseFrameworkSystem implements AddableBasketItem {
/**
* Item id number
*/
+++ /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.item;
-
-import org.mxchange.jcore.FrameworkInterface;
-
-/**
- *
-* @author Roland Haeder
- */
-public interface OrderableItem extends FrameworkInterface {
-}
<param-value>data</param-value>
</context-param>
<filter>
- <description>A filter for setting character encoding to UTF-8</description>
- <filter-name>Utf8HttpFilter</filter-name>
- <filter-class>org.mxchange.pizzaapplication.filter.http.utf8.Utf8HttpFilter</filter-class>
+ <description>A servlet filter for setting character encoding to UTF-8</description>
+ <filter-name>Utf8ServletFilter</filter-name>
+ <filter-class>org.mxchange.pizzaapplication.filter.servlet.utf8.Utf8ServletFilter</filter-class>
</filter>
+ <filter>
+ <description>A filter for handling added basket items</description>
+ <filter-name>BasketItemAddedFilter</filter-name>
+ <filter-class>org.mxchange.pizzaapplication.filter.servlet.basket.BasketItemAddedFilter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>BasketItemAddedFilter</filter-name>
+ <url-pattern>/form_handler/add_item.jsp</url-pattern>
+ </filter-mapping>
<filter-mapping>
- <filter-name>Utf8HttpFilter</filter-name>
+ <filter-name>Utf8ServletFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%>
<%@page import="org.mxchange.pizzaapplication.item.OrderableItem"%>
+<jsp:useBean id="item" scope="session" class="org.mxchange.pizzaapplication.item.basket.BasketItem" type="OrderableItem" />
+<jsp:setProperty name="item" property="*" />
+
<%
// Init application instance
PizzaApplication app = PizzaServiceApplication.getInstance(application);