]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Added decodedTitle() which decodes the UTF-8 + added new exception
authorRoland Haeder <roland@mxchange.org>
Fri, 14 Aug 2015 11:59:23 +0000 (13:59 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 14 Aug 2015 11:59:23 +0000 (13:59 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

src/java/org/mxchange/pizzaapplication/category/BaseCategory.java
src/java/org/mxchange/pizzaapplication/category/Category.java
src/java/org/mxchange/pizzaapplication/exceptions/CategoryTitleAlreadyUsedException.java [new file with mode: 0644]
web/admin/category.jsp
web/admin/product.jsp
web/static/admin/category_selection_box.jsp [new file with mode: 0644]
web/static/admin/parent_category_selection_box.jsp

index 859edd2315349022b54e61f731402426cc5cd724..5043b940f370b77e8b6976c9d2ed53ba2b1f919d 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.pizzaapplication.category;
 
+import java.io.UnsupportedEncodingException;
 import java.text.MessageFormat;
 import java.util.Objects;
 import org.mxchange.jcore.BaseFrameworkSystem;
@@ -139,4 +140,18 @@ public class BaseCategory extends BaseFrameworkSystem implements Category {
        public final void setTitle (final String title) {
                this.title = title;
        }
+
+       /**
+        * Decodes the UTF8-encoded title
+        *
+        * @return Decoded title
+        */
+       @Override
+       public final String decodedTitle () throws UnsupportedEncodingException {
+               // Get title
+               byte[] t = this.getTitle().getBytes();
+
+               // Decode it
+               return new String(t, "UTF-8");
+       }
 }
index 02b30d8fa898fdd2075ac89511b1e16d086bdf72..75de6b960ef6db95a9dfe90e0174886a0be89772 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.pizzaapplication.category;
 
+import java.io.UnsupportedEncodingException;
 import org.mxchange.jcore.database.storage.Storeable;
 
 /**
@@ -67,4 +68,12 @@ public interface Category extends Storeable, Comparable<Category> {
         */
        @Override
        public int compareTo (final Category category);
+
+       /**
+        * Decodes the UTF8-encoded title
+        *
+        * @return Decoded title
+        * @throws java.io.UnsupportedEncodingException If the encoding UTF-8 is not supported
+        */
+       public String decodedTitle () throws UnsupportedEncodingException ;
 }
diff --git a/src/java/org/mxchange/pizzaapplication/exceptions/CategoryTitleAlreadyUsedException.java b/src/java/org/mxchange/pizzaapplication/exceptions/CategoryTitleAlreadyUsedException.java
new file mode 100644 (file)
index 0000000..7d69592
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * 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.exceptions;
+
+import java.text.MessageFormat;
+import javax.servlet.http.HttpServletRequest;
+import org.mxchange.pizzaapplication.database.category.PizzaCategoryDatabaseConstants;
+
+/**
+ * An exception thrown when the given title is already used
+ * 
+ * @author Roland Haeder
+ */
+public class CategoryTitleAlreadyUsedException extends Exception {
+
+       /**
+        * Constructor with HttpServletRequest instance
+        *
+        * @param request A HttpServletRequest instance
+        */
+       public CategoryTitleAlreadyUsedException (final HttpServletRequest request) {
+               // Call super constructor
+               super(MessageFormat.format("Title {0} is already used.", request.getParameter(PizzaCategoryDatabaseConstants.COLUMN_TITLE)));
+       }
+       
+}
index febeb8b0359c307d1d383f0bcaffb9142e677b94..3d328717f615479fa2fa92736bf59e2504f8def5 100644 (file)
@@ -62,7 +62,7 @@
                                                                        <input type="checkbox" name="<%=PizzaCategoryDatabaseConstants.COLUMN_ID%>[${category.getId()}]" value="1" />
                                                                </td>
                                                                <td>
-                                                                       ${category.getTitle()}
+                                                                       ${category.decodedTitle()}
                                                                </td>
                                                                <td>
                                                                        ${app.generateLinkForParent(category)}
index 453f70ccf53694560b94327568c79e39409b3225..4383f963ddea30d25e1510c1e072620f2804f045 100644 (file)
 
                                                                <div class="clear"></div>
                                                        </div>
+
+                                                       <div class="data_row">
+                                                               <div class="table_left">
+                                                                       Kategorie:
+                                                               </div>
+
+                                                               <div class="table_right">
+                                                                       <jsp:include flush="true" page="/static/admin/category_selection_box.jsp" />
+                                                               </div>
+
+                                                               <div class="clear"></div>
+                                                       </div>
                                                </fieldset>
 
                                                <div class="table_footer">
diff --git a/web/static/admin/category_selection_box.jsp b/web/static/admin/category_selection_box.jsp
new file mode 100644 (file)
index 0000000..ea09c0b
--- /dev/null
@@ -0,0 +1,21 @@
+<%-- 
+       Document   : parent_category_selection_box
+       Created on : 14.08.2015, 12:51:05
+       Author     : Roland Haeder
+--%>
+
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%@page import="org.mxchange.pizzaapplication.database.category.PizzaCategoryDatabaseConstants"%>
+<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%>
+<%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%>
+
+<%
+       // Init application instance
+       PizzaApplication app = PizzaServiceApplication.getInstance(application);
+%>
+
+<select name="<%=PizzaCategoryDatabaseConstants.COLUMN_ID%>" size="1">
+       <c:forEach var="category" items="<%=app.getCategories()%>">
+               <option value="${category.getId()}">${category.decodedTitle()}</option>
+       </c:forEach>
+</select>
index 936fe664a5080869b0d0700ea217ad337faf1a36..b6642006f67bb743a54571d48f3f2c29d0f48d94 100644 (file)
@@ -4,8 +4,19 @@
        Author     : Roland Haeder
 --%>
 
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
 <%@page import="org.mxchange.pizzaapplication.database.category.PizzaCategoryDatabaseConstants"%>
+<%@page import="org.mxchange.pizzaapplication.application.PizzaServiceApplication"%>
+<%@page import="org.mxchange.pizzaapplication.application.PizzaApplication"%>
+
+<%
+       // Init application instance
+       PizzaApplication app = PizzaServiceApplication.getInstance(application);
+%>
 
 <select name="<%=PizzaCategoryDatabaseConstants.COLUMN_PARENT%>" size="1">
        <option value="">Ist oberste Kategorie</option>
+       <c:forEach var="category" items="<%=app.getCategories()%>">
+               <option value="${category.getId()}">${category.decodedTitle()}</option>
+       </c:forEach>
 </select>