001package io.jboot.support.shiro; 002 003import com.jfinal.core.ActionKey; 004import com.jfinal.core.Controller; 005import io.jboot.web.controller.JbootController; 006 007import java.lang.reflect.Method; 008import java.util.HashSet; 009import java.util.Set; 010 011/** 012 * @author Michael Yang 杨福海 (fuhai999@gmail.com) 013 * @version V1.0 014 */ 015public class JbootShiroUtil { 016 017 private static final String SLASH = "/"; 018 019 /** 020 * 参考ActionMapping中的实现。 021 * 022 * @param controllerClass 023 * @param method 024 * @param controllerKey 025 * @return 026 */ 027 public static String createActionKey(Class<? extends Controller> controllerClass, 028 Method method, String controllerKey) { 029 String methodName = method.getName(); 030 String actionKey; 031 032 ActionKey ak = method.getAnnotation(ActionKey.class); 033 if (ak != null) { 034 actionKey = ak.value().trim(); 035 if ("".equals(actionKey)) { 036 throw new IllegalArgumentException(controllerClass.getName() + "." + methodName + "(): The argument of ActionKey can not be blank."); 037 } 038 if (!actionKey.startsWith(SLASH)) { 039 actionKey = SLASH + actionKey; 040 } 041 } else if (methodName.equals("index")) { 042 actionKey = controllerKey; 043 } else { 044 actionKey = controllerKey.equals(SLASH) ? SLASH + methodName : controllerKey + SLASH + methodName; 045 } 046 return actionKey; 047 } 048 049 private static final Set<String> excludedMethodName = new HashSet<String>(); 050 051 public static Set<String> getControllerExcludedMethodName() { 052 if (excludedMethodName.isEmpty()) { 053 Method[] methods = JbootController.class.getMethods(); 054 for (Method m : methods) { 055 excludedMethodName.add(m.getName()); 056 } 057 } 058 059 return excludedMethodName; 060 } 061 062}