From: Svjatoslav Agejenko Date: Tue, 24 Dec 2013 22:01:43 +0000 (+0200) Subject: support for localized navigation titles X-Git-Tag: svjatoslavcommons-1.8~121 X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=887df187ed4313734587c4dc2f00c07d3563fba0;p=svjatoslav_commons.git support for localized navigation titles --- diff --git a/src/main/java/eu/svjatoslav/commons/network/LocaleHelper.java b/src/main/java/eu/svjatoslav/commons/network/LocaleHelper.java index a073900..2a61d9f 100644 --- a/src/main/java/eu/svjatoslav/commons/network/LocaleHelper.java +++ b/src/main/java/eu/svjatoslav/commons/network/LocaleHelper.java @@ -9,14 +9,12 @@ public class LocaleHelper { final String sessionLocaleString = (String) request.getSession().getAttribute("locale"); Locale sessionLocale = localeFromString(sessionLocaleString); - if (sessionLocale == null) { - sessionLocale = Locale.ENG; - } + if (sessionLocale == null) + sessionLocale = Locale.ENG; final Locale requestLocale = localeFromString(request.getParameter("locale")); - if (requestLocale != null) { - sessionLocale = requestLocale; - } + if (requestLocale != null) + sessionLocale = requestLocale; request.getSession().setAttribute("locale", sessionLocale.asString()); @@ -24,11 +22,9 @@ public class LocaleHelper { } public static Locale localeFromString(final String localeString) { - for (final Locale locale : Locale.values()) { - if (locale.asString().equals(localeString)) { - return locale; - } - } + for (final Locale locale : Locale.values()) + if (locale.asString().equals(localeString)) + return locale; return null; } diff --git a/src/main/java/eu/svjatoslav/commons/network/navigation/NavigationItem.java b/src/main/java/eu/svjatoslav/commons/network/navigation/NavigationItem.java index 6392fa9..fdf6985 100755 --- a/src/main/java/eu/svjatoslav/commons/network/navigation/NavigationItem.java +++ b/src/main/java/eu/svjatoslav/commons/network/navigation/NavigationItem.java @@ -1,27 +1,26 @@ package eu.svjatoslav.commons.network.navigation; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import eu.svjatoslav.commons.network.Locale; import eu.svjatoslav.commons.string.WildCardMatcher; public class NavigationItem { - private final String title; private final String link; private final String matchingWildcard; - + private final Map titles = new HashMap(); ArrayList subElements = new ArrayList(); - public NavigationItem(final String title, final String link) { - this.title = title; + public NavigationItem(final String link) { this.link = link; matchingWildcard = link; } - public NavigationItem(final String title, final String link, - final String wildcard) { - this.title = title; + public NavigationItem(final String link, final String wildcard) { this.link = link; matchingWildcard = wildcard; } @@ -30,6 +29,16 @@ public class NavigationItem { subElements.add(item); } + public NavigationItem addTitle(final Locale locale, final String title) { + titles.put(locale, title); + return this; + } + + public NavigationItem addTitle(final String title) { + titles.put(Locale.ENG, title); + return this; + } + public String getLink() { return link; } @@ -39,7 +48,11 @@ public class NavigationItem { } public String getTitle() { - return title; + return titles.get(Locale.ENG); + } + + public String getTitle(final Locale locale) { + return titles.get(locale); } public boolean matchesUrl(final String url) {