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());
}
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;
}
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<Locale, String> titles = new HashMap<Locale, String>();
ArrayList<NavigationItem> subElements = new ArrayList<NavigationItem>();
- 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;
}
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;
}
}
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) {