From a2b2acd6d8c6a73c0897a2002a313266b1b74872 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Thu, 26 Dec 2013 20:24:17 +0200 Subject: [PATCH] check matching navigation items recursively --- .../commons/network/navigation/Navigation.java | 8 +++++--- .../network/navigation/NavigationItem.java | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 4 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 1afd5c7..408372a 100755 --- a/src/main/java/eu/svjatoslav/commons/network/navigation/Navigation.java +++ b/src/main/java/eu/svjatoslav/commons/network/navigation/Navigation.java @@ -25,9 +25,11 @@ public class Navigation { try { final String requestPath = new URL(requestUrl).getPath(); - for (final NavigationItem item : rootNavigationItem.subElements) - if (item.matchesUrl(requestPath)) - return item; + final NavigationItem match = rootNavigationItem + .getMatchingNavigationItem(requestPath); + + if (match != null) + return match; } catch (final MalformedURLException e) { System.out.println("Cannot handle URL: " + requestUrl); e.printStackTrace(); 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..a9ad856 100755 --- a/src/main/java/eu/svjatoslav/commons/network/navigation/NavigationItem.java +++ b/src/main/java/eu/svjatoslav/commons/network/navigation/NavigationItem.java @@ -55,6 +55,20 @@ 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; } @@ -82,7 +96,6 @@ public class NavigationItem { public boolean matchesUrl(final String url) { return WildCardMatcher.match(url, matchingPattern); - } public NavigationItem setPattern(final String pattern) { -- 2.20.1