From 531b4f95785def09d09e5db52ad8c6da0650b648 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 14 Aug 2015 13:59:23 +0200 Subject: [PATCH] =?utf8?q?Added=20decodedTitle()=20which=20decodes=20the?= =?utf8?q?=20UTF-8=20+=20added=20new=20exception=20Signed-off-by:Roland=20?= =?utf8?q?H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../category/BaseCategory.java | 15 +++++++ .../pizzaapplication/category/Category.java | 9 +++++ .../CategoryTitleAlreadyUsedException.java | 40 +++++++++++++++++++ web/admin/category.jsp | 2 +- web/admin/product.jsp | 12 ++++++ web/static/admin/category_selection_box.jsp | 21 ++++++++++ .../admin/parent_category_selection_box.jsp | 11 +++++ 7 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 src/java/org/mxchange/pizzaapplication/exceptions/CategoryTitleAlreadyUsedException.java create mode 100644 web/static/admin/category_selection_box.jsp diff --git a/src/java/org/mxchange/pizzaapplication/category/BaseCategory.java b/src/java/org/mxchange/pizzaapplication/category/BaseCategory.java index 859edd23..5043b940 100644 --- a/src/java/org/mxchange/pizzaapplication/category/BaseCategory.java +++ b/src/java/org/mxchange/pizzaapplication/category/BaseCategory.java @@ -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"); + } } diff --git a/src/java/org/mxchange/pizzaapplication/category/Category.java b/src/java/org/mxchange/pizzaapplication/category/Category.java index 02b30d8f..75de6b96 100644 --- a/src/java/org/mxchange/pizzaapplication/category/Category.java +++ b/src/java/org/mxchange/pizzaapplication/category/Category.java @@ -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 { */ @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 index 00000000..7d695927 --- /dev/null +++ b/src/java/org/mxchange/pizzaapplication/exceptions/CategoryTitleAlreadyUsedException.java @@ -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 . + */ +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))); + } + +} diff --git a/web/admin/category.jsp b/web/admin/category.jsp index febeb8b0..3d328717 100644 --- a/web/admin/category.jsp +++ b/web/admin/category.jsp @@ -62,7 +62,7 @@ - ${category.getTitle()} + ${category.decodedTitle()} ${app.generateLinkForParent(category)} diff --git a/web/admin/product.jsp b/web/admin/product.jsp index 453f70cc..4383f963 100644 --- a/web/admin/product.jsp +++ b/web/admin/product.jsp @@ -123,6 +123,18 @@
+ +
+
+ Kategorie: +
+ +
+ +
+ +
+