X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fcommons%2Fnetwork%2Fnavigation%2FNavigationItem.java;h=168b809808bf1587793d0a9e1ccb233b879e64a8;hb=HEAD;hp=76a7d073a674a7030db0b45ca0560f85f9ca3877;hpb=eed1c70de986cf74cf15de291abd7495e4a6bcd1;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 deleted file mode 100755 index 76a7d07..0000000 --- a/src/main/java/eu/svjatoslav/commons/network/navigation/NavigationItem.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * 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; -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 String matchingPattern; - - private final Map localeToTitle = new HashMap(); - private final ArrayList subElements = new ArrayList(); - private final NI parent; - private final N navigation; - private final String linkUrl; - /** - * CSS prefix is inherited to child menu items. - */ - private String cssPrefix; - - public NavigationItem(final N navigation) { - this.navigation = navigation; - parent = null; - matchingPattern = null; - linkUrl = null; - } - - public NavigationItem(final NI parent, final String linkUrl, - final String... titles) { - this.navigation = (N) parent.getNavigation(); - this.parent = parent; - this.linkUrl = linkUrl; - matchingPattern = linkUrl; - - initializeLocalizedTitles(titles); - - parent.addNavigationItem(this); - } - - public void addNavigationItem(final NI navigationItem) { - subElements.add(navigationItem); - } - - protected String getCssPrefix() { - if (cssPrefix != null) - return cssPrefix; - - if (parent == null) - return null; - - return parent.getCssPrefix(); - } - - public String getLinkUrl() { - return linkUrl; - } - - NI getMatchingNavigationItem(final String requestPath) { - if (matchesUrl(requestPath)) - return (NI) this; - - for (final NI childNavigationItem : subElements) { - final NI match = (NI) childNavigationItem - .getMatchingNavigationItem(requestPath); - - if (match != null) - return match; - } - return null; - } - - public N getNavigation() { - return navigation; - } - - public List getSubElements() { - return subElements; - } - - public String getTitle(final Locale locale) { - return localeToTitle.get(locale); - } - - private void initializeLocalizedTitles(final String... titles) { - final List locales = getNavigation().getLocaleConfiguration() - .getAllowedLocales(); - if (locales.size() != titles.length) - throw new RuntimeException("There should be exactly " - + locales.size() + " title(s)."); - - for (int i = 0; i < titles.length; i++) - localeToTitle.put(locales.get(i), titles[i]); - } - - 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) { - matchingPattern = pattern; - return this; - } - - @Override - public String toString() { - return "NavigationItem [matchingPattern=" + matchingPattern - + ", localeToTitle=" + localeToTitle + ", subElements count=" - + subElements.size() + ", linkUrl=" + linkUrl + ", cssPrefix=" - + cssPrefix + "]"; - } - -}