Changed license to LGPLv3 or later.
[svjatoslav_commons.git] / src / main / java / eu / svjatoslav / commons / network / navigation / NavigationItem.java
index eef52fb..0deca95 100755 (executable)
@@ -1,3 +1,12 @@
+/*
+ * 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;
@@ -17,12 +26,12 @@ public class NavigationItem {
        private NavigationItem parent;
        private final String linkUrl;
 
-       public NavigationItem() {
-               this(Locale.ENG);
-       }
-
        public NavigationItem(final Locale... localeOrder) {
-               this.localeOrder = localeOrder;
+               if (localeOrder.length == 0)
+                       this.localeOrder = new Locale[] { Locale.ENG };
+               else
+                       this.localeOrder = localeOrder;
+
                matchingPattern = null;
                linkUrl = null;
        }
@@ -55,6 +64,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<NavigationItem> getSubElements() {
                return subElements;
        }
@@ -82,7 +105,6 @@ public class NavigationItem {
 
        public boolean matchesUrl(final String url) {
                return WildCardMatcher.match(url, matchingPattern);
-
        }
 
        public NavigationItem setPattern(final String pattern) {