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();
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<NavigationItem> getSubElements() {
return subElements;
}
public boolean matchesUrl(final String url) {
return WildCardMatcher.match(url, matchingPattern);
-
}
public NavigationItem setPattern(final String pattern) {