rolesAllowed = Sets.newHashSet(StringUtils.split(config.getString(prefix + "rolesAllowed", ""), ","));
String items = config.getString(prefix + "menu");
Map<String, String> menuLayout = getMenuLayout();
if (menuLayout != null) {
rootMenu = new MenuItem().setName("root").setTitle("root");
for (Entry<String, String> item : menuLayout.entrySet()) {
// Parse the menu hierarchy and build it if necessary
String[] nameComponents = StringUtils.split(item.getKey(), "/");
String[] pathComponents = StringUtils.split(item.getValue(), "/");
if (nameComponents.length == 1) {
rootMenu.addChild(new MenuItem()
.setName(item.getKey())
.setHref(item.getValue())
.setTitle(item.getKey()));
}
else {
if (nameComponents.length != pathComponents.length)
LOG.error("Name and path must have same number of components: " + item.getKey() + " -> " + item.getValue());
MenuItem node = rootMenu;
for (int i = 0; i < nameComponents.length - 1; i++) {
MenuItem next = node.getChild(pathComponents[i]);
if (next == null) {
next = new MenuItem()
.setName(pathComponents[i])
.setTitle(nameComponents[i]);
node.addChild(next);
}
node = next;
}
MenuItem leaf = new MenuItem()
.setName(pathComponents[pathComponents.length - 1])
.setHref(item.getValue())
.setTitle(nameComponents[nameComponents.length - 1]);
// Add the menu item to the leaf
node.addChild(leaf);
}
}
}
else if (items != null) {
rootMenu = new MenuItem().setName("root").setTitle("root");
for (String item : StringUtils.split(items, ",")) {
String[] parts = StringUtils.splitByWholeSeparator(item, "->");
try {
String[] nameComponents = StringUtils.split(parts[0].trim(), "/");
MenuItem node = rootMenu;
for (int i = 0; i < nameComponents.length; i++) {
MenuItem next = node.getChild(nameComponents[i]);
if (next == null) {
next = new MenuItem()
.setName(nameComponents[i])
.setTitle(nameComponents[i]);
node.addChild(next);
}
node = next;