final String requestPath = new URL(requestUrl).getPath();
@SuppressWarnings("unchecked")
- final NI match = (NI) rootNavigationItem
- .getMatchingNavigationItem(requestPath);
+ final NI match = (NI) rootNavigationItem.getMatchingNavigationItem(requestPath);
if (match != null)
return match;
@SuppressWarnings("unchecked")
public String getTopMenu(final HttpServletRequest request) {
- final String currentLocale = localeConfiguration
- .detectCurrentLocale(request);
+ final String currentLocale = localeConfiguration.detectCurrentLocale(request);
final NI selectedItem = getSelectedItem(request);
final StringBuffer result = new StringBuffer();
- result.append("<div class=\""
- + getGetNotNullString(rootNavigationItem.getCssPrefix())
- + "navigationMenu\">");
+ result.append("<div class=\"" + getGetNotNullString(rootNavigationItem.getCssPrefix()) + "navigationMenu\">");
- for (final NI item : (List<NI>) getRootNavigationItem()
- .getSubElements()) {
+ for (final NI item : (List<NI>) getRootNavigationItem().getSubElements()) {
if (item == selectedItem)
- result.append("<a class=\""
- + getGetNotNullString(item.getCssPrefix())
- + "menuItemSelected\" href=\"" + item.getLinkUrl()
- + "\">");
+ result.append("<a class=\"" + getGetNotNullString(item.getCssPrefix()) + "menuItemSelected\" href=\""
+ + item.getLinkUrl() + "\">");
else
- result.append("<a class=\""
- + getGetNotNullString(item.getCssPrefix())
- + "menuItem\" href=\"" + item.getLinkUrl() + "\">");
+ result.append("<a class=\"" + getGetNotNullString(item.getCssPrefix()) + "menuItem\" href=\""
+ + item.getLinkUrl() + "\">");
result.append("<div>" + item.getTitle(currentLocale) + "</div>");
result.append("</a>");
private final Map<String, String> localeToTitle = new HashMap<String, String>();
private final ArrayList<NavigationItem> subElements = new ArrayList<NavigationItem>();
private final NavigationItem parent;
- private final Navigation<NavigationItem> navigation;
+ private final Navigation<? extends NavigationItem> navigation;
private final String linkUrl;
/**
* CSS prefix is inherited to child menu items.
*/
private String cssPrefix;
- public NavigationItem(final Navigation<NavigationItem> navigation) {
+ /**
+ * Used to build root navigation item.
+ */
+ public NavigationItem(final Navigation<? extends NavigationItem> navigation) {
this.navigation = navigation;
parent = null;
matchingPattern = null;
linkUrl = null;
}
- public NavigationItem(final NavigationItem parent, final String linkUrl,
- final String... titles) {
+ public NavigationItem(final NavigationItem parent, final String linkUrl, final String... titles) {
+
navigation = parent.getNavigation();
this.parent = parent;
this.linkUrl = linkUrl;
return this;
for (final NavigationItem childNavigationItem : subElements) {
- final NavigationItem match = childNavigationItem
- .getMatchingNavigationItem(requestPath);
+ final NavigationItem match = childNavigationItem.getMatchingNavigationItem(requestPath);
if (match != null)
return match;
return null;
}
- public Navigation<NavigationItem> getNavigation() {
+ public Navigation<? extends NavigationItem> getNavigation() {
return navigation;
}
}
private void initializeLocalizedTitles(final String... titles) {
- final List<String> locales = getNavigation().getLocaleConfiguration()
- .getAllowedLocales();
+ final List<String> locales = getNavigation().getLocaleConfiguration().getAllowedLocales();
if (locales.size() != titles.length)
- throw new RuntimeException("There should be exactly "
- + locales.size() + " title(s).");
+ 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]);
@Override
public String toString() {
- return "NavigationItem [matchingPattern=" + matchingPattern
- + ", localeToTitle=" + localeToTitle + ", subElements count="
- + subElements.size() + ", linkUrl=" + linkUrl + ", cssPrefix="
- + cssPrefix + "]";
+ return "NavigationItem [matchingPattern=" + matchingPattern + ", localeToTitle=" + localeToTitle
+ + ", subElements count=" + subElements.size() + ", linkUrl=" + linkUrl + ", cssPrefix=" + cssPrefix
+ + "]";
}
}