X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fcommons%2Fnetwork%2Fnavigation%2FNavigationItem.java;h=14c8b0ab3f0fa2756f535346c001f0a416e673bc;hb=aa03fa52face6f13f8da2e9b89e798671653a074;hp=eef52fb5a18505d03587a4877a7318bf7f833e10;hpb=a1959a0ecf6a3cb60687b6eb3b1be62466b77c65;p=svjatoslav_commons.git 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 eef52fb..14c8b0a 100755 --- a/src/main/java/eu/svjatoslav/commons/network/navigation/NavigationItem.java +++ b/src/main/java/eu/svjatoslav/commons/network/navigation/NavigationItem.java @@ -1,3 +1,12 @@ +/* + * Svjatoslav Commons - shared library of common functionality. + * Copyright ©2012-2014, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 3 of the GNU Lesser General Public License + * or later as published by the Free Software Foundation. + */ + package eu.svjatoslav.commons.network.navigation; import java.util.ArrayList; @@ -17,12 +26,17 @@ public class NavigationItem { private NavigationItem parent; private final String linkUrl; - public NavigationItem() { - this(Locale.ENG); - } + /** + * CSS prefix is inherited to child menu items. + */ + private String cssPrefix; public NavigationItem(final Locale... localeOrder) { - this.localeOrder = localeOrder; + if (localeOrder.length == 0) + this.localeOrder = new Locale[] { Locale.ENG }; + else + this.localeOrder = localeOrder; + matchingPattern = null; linkUrl = null; } @@ -44,6 +58,16 @@ public class NavigationItem { return item; } + protected String getCssPrefix() { + if (cssPrefix != null) + return cssPrefix; + + if (parent == null) + return null; + + return parent.getCssPrefix(); + } + public String getLinkUrl() { return linkUrl; } @@ -55,13 +79,28 @@ public class NavigationItem { return parent.getLocaleOrder(); } + NavigationItem getMatchingNavigationItem(final String requestPath) { + if (matchesUrl(requestPath)) + return this; + + for (final NavigationItem childNavigationItem : subElements) { + final NavigationItem match = childNavigationItem + .getMatchingNavigationItem(requestPath); + + if (match != null) + return match; + } + return null; + } + public List getSubElements() { return subElements; } public String getTitle() { if (localeToTitle.size() != 1) - throw new RuntimeException("there shall be exactly one title"); + throw new RuntimeException( + "NavigationItem.getTitle() was called without locale parameter, but there there are multiple titles in diffirent locales available."); return localeToTitle.values().iterator().next(); } @@ -82,7 +121,10 @@ public class NavigationItem { public boolean matchesUrl(final String url) { return WildCardMatcher.match(url, matchingPattern); + } + public void setCssPrefix(final String cssPrefix) { + this.cssPrefix = cssPrefix; } public NavigationItem setPattern(final String pattern) {