19 package org.turro.elephant.user.menu;
21 import java.util.Collections;
22 import java.util.List;
25 import java.util.TreeSet;
26 import java.util.concurrent.locks.Lock;
27 import java.util.concurrent.locks.ReentrantLock;
28 import org.turro.string.Strings;
29 import org.turro.action.UserSummaries;
30 import org.turro.elephant.context.Application;
31 import org.turro.elephant.context.IConstructor;
32 import org.turro.path.Path;
33 import org.turro.reflection.ClassNames;
34 import org.turro.reflection.Reflections;
43 if(constructor.
getUser() !=
null) {
48 return Collections.EMPTY_SET;
53 return doExecuteMenu(userMenus(), idMenu);
57 if(!Strings.isBlank(path) && path.startsWith(
"/user/")) {
58 IUserMenu userMenu = getUserMenuByPath(userMenus(), Path.reduce(path, 2));
59 return userMenu !=
null ? userMenu.
isInRole() :
true;
64 private static IUserMenu getUserMenuByPath(Set<IUserMenu> menus, String path) {
67 if(path.equals(userMenu.getLink())) {
70 if(userMenu.getChildren() !=
null) {
71 result = getUserMenuByPath(userMenu.getChildren(), path);
73 if(result !=
null)
break;
78 private static Object doExecuteMenu(Set<IUserMenu> menus, String idMenu) {
79 for(IUserMenu userMenu : menus) {
80 if(idMenu.equals(userMenu.getId())) {
83 if(userMenu.getChildren() !=
null) doExecuteMenu(userMenu.getChildren(), idMenu);
137 private static TreeSet<IUserMenu> _userMenus;
138 private static final Lock lock =
new ReentrantLock();
140 private static Set<IUserMenu> userMenus() {
141 if(_userMenus ==
null) {
144 if(_userMenus ==
null) {
145 _userMenus =
new TreeSet<>();
146 List<String> menus = ClassNames.cached().byAnnotation(
UserMenu.class.getName());
148 for(String menu : menus) {
149 Object obj = Reflections.of(menu).instance();
157 for(IUserMenu um : _userMenus) {
168 private UserMenus() {
static void initSummaries(IConstructor constructor)
IConstructor getConstructor()
static Application getApplication()
Object findAttribute(String key)
ElContext getCurrentContext()
Map< String, Object > getSessionAttributeMap(String prefix)
void setSessionAttribute(String key, Object value)
void removeSessionAttribute(String key)
Object getSessionAttribute(String key)