From: Roland Haeder Date: Fri, 14 Aug 2015 11:59:23 +0000 (+0200) Subject: Added decodedTitle() which decodes the UTF-8 + added new exception X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=531b4f95785def09d09e5db52ad8c6da0650b648;p=pizzaservice-war.git Added decodedTitle() which decodes the UTF-8 + added new exception Signed-off-by:Roland Häder --- 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: +
+ +
+ +
+ +
+