2 * Svjatoslav Commons - shared library of common functionality.
3 * Copyright ©2012-2020, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 3 of the GNU Lesser General Public License
7 * or later as published by the Free Software Foundation.
10 package eu.svjatoslav.commons.network.navigation;
12 import eu.svjatoslav.commons.string.GlobMatcher;
14 import java.util.ArrayList;
15 import java.util.List;
17 public class NavigationItem {
19 private final ArrayList<NavigationItem> children = new ArrayList<>();
20 private final String url;
21 private String pattern;
23 private boolean isDefault;
25 public NavigationItem(final String url, String pattern, String title ) {
27 this.pattern = pattern;
31 public NavigationItem setDefault(){
36 public boolean isDefault(){
40 public void add(final NavigationItem navigationItem) {
41 children.add(navigationItem);
44 public String getUrl() {
48 NavigationItem getMatch(final String requestPath) {
49 if (matchesUrl(requestPath))
52 for (final NavigationItem childNavigationItem : children) {
53 final NavigationItem match = childNavigationItem.getMatch(requestPath);
61 public List<NavigationItem> getChildren() {
65 public String getTitle() {
69 public boolean matchesUrl(final String url) {
70 return GlobMatcher.match(url, pattern);
73 public NavigationItem getDefaultNavigationItem() {
74 for (NavigationItem child : children)
75 if (child.isDefault())