StrutsUtil 类
import java.util.HashSet; import java.util.Map; import java.util.Set; import org.apache.commons.lang.StringUtils; import org.apache.struts2.dispatcher.Dispatcher; import com.opensymphony.xwork2.config.Configuration; import com.opensymphony.xwork2.config.ConfigurationManager; import com.opensymphony.xwork2.config.entities.ActionConfig; public class StrutsUtil { /** * 获取Struts2配置信息. * * @return Struts2 Configuration */ public static Configuration getConfiguration() { Dispatcher dispatcher = Dispatcher.getInstance(); ConfigurationManager configurationManager = dispatcher.getConfigurationManager(); return configurationManager.getConfiguration(); } /** * 获取所有namespace名称. * * @return namespace名称的集合 */ public static Set getAllNamespaces() { Set namespaces = new HashSet(); Configuration configuration = getConfiguration(); Map> actionConfigs = configuration.getRuntimeConfiguration().getActionConfigs(); for (String namespace : actionConfigs.keySet()) { namespaces.add(namespace); } return namespaces; } /** * 获取所有Action名称. * * @return Action名称的集合 */ public static Set getAllActionName() { Set actionNames = new HashSet(); Configuration configuration = getConfiguration(); Map> actionConfigs = configuration.getRuntimeConfiguration().getActionConfigs(); for (String namespace : actionConfigs.keySet()) { Map actionConfigMap = actionConfigs.get(namespace); for (String actionName : actionConfigMap.keySet()) { actionNames.add(actionName); } } return actionNames; } /** * 获取所有Action类名称(不包含com.opensymphony.xwork2.ActionSupport类). * * @return Action类名称的集合 */ public static Set getAllActionClassName() { Set actionClassNames = new HashSet(); Configuration configuration = getConfiguration(); Map> actionConfigs = configuration.getRuntimeConfiguration().getActionConfigs(); for (String namespace : actionConfigs.keySet()) { Map actionConfigMap = actionConfigs.get(namespace); for (String actionName : actionConfigMap.keySet()) { String actionClassName = actionConfigMap.get(actionName).getClassName(); if (!StringUtils.equals(actionClassName, "com.opensymphony.xwork2.ActionSupport")) { actionClassNames.add(actionClassName); } } } return actionClassNames; } /** * 获取所有Action类. * * @return Action类的集合 */ @SuppressWarnings("unchecked") public static Set getAllActionClass() { Set actionClasss = new HashSet(); Configuration configuration = getConfiguration(); Map> actionConfigs = configuration.getRuntimeConfiguration().getActionConfigs(); for (String namespace : actionConfigs.keySet()) { Map actionConfigMap = actionConfigs.get(namespace); for (String actionName : actionConfigMap.keySet()) { Class actionClass = actionConfigMap.get(actionName).getClass(); actionClasss.add(actionClass); } } return actionClasss; } }
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~