From e49d583cb64523c584cd848c8a421140c5193514 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Wed, 20 Aug 2014 17:39:51 +0300 Subject: [PATCH] possibility to use CSS prefix for menu items --- .../network/navigation/Navigation.java | 22 ++++++++++++++----- .../network/navigation/NavigationItem.java | 21 +++++++++++++++++- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/svjatoslav/commons/network/navigation/Navigation.java b/src/main/java/eu/svjatoslav/commons/network/navigation/Navigation.java index 339db68..3a2877f 100755 --- a/src/main/java/eu/svjatoslav/commons/network/navigation/Navigation.java +++ b/src/main/java/eu/svjatoslav/commons/network/navigation/Navigation.java @@ -24,6 +24,13 @@ public class Navigation { return defaultNavigationItem; } + private String getGetNotNullString(final String string) { + if (string != null) + return string; + + return ""; + } + public NavigationItem getRootNavigationItem() { return rootNavigationItem; } @@ -52,17 +59,22 @@ public class Navigation { final NavigationItem selectedItem = getSelectedItem(request); final StringBuffer result = new StringBuffer(); - result.append("
"); + result.append("
"); for (final NavigationItem item : getRootNavigationItem() .getSubElements()) { if (item == selectedItem) - result.append(""); + result.append(""); else - result.append(""); + result.append(""); result.append("
" + item.getTitle() + "
"); result.append("
"); 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 0deca95..22ba6b0 100755 --- a/src/main/java/eu/svjatoslav/commons/network/navigation/NavigationItem.java +++ b/src/main/java/eu/svjatoslav/commons/network/navigation/NavigationItem.java @@ -1,7 +1,7 @@ /* * 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. @@ -26,6 +26,11 @@ public class NavigationItem { private NavigationItem parent; private final String linkUrl; + /** + * CSS prefix is inherited to child menu items. + */ + private String cssPrefix; + public NavigationItem(final Locale... localeOrder) { if (localeOrder.length == 0) this.localeOrder = new Locale[] { Locale.ENG }; @@ -53,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; } @@ -107,6 +122,10 @@ public class NavigationItem { return WildCardMatcher.match(url, matchingPattern); } + public void setCssPrefix(final String cssPrefix) { + this.cssPrefix = cssPrefix; + } + public NavigationItem setPattern(final String pattern) { matchingPattern = pattern; return this; -- 2.20.1