<authority>
<!-- 管理员-->
<!-- 普通用户-->
<role name="native">
<function>
<functionCode>aa</functionCode>
<method>comEdit</method>
<actionCode>native</actionCode>
<functionName>修改普通用户信息</functionName>
</function>
</role>
<!-- 代理商-->
<role name="agent">
<function>
<functionCode>ba</functionCode>
<method>viewUI</method>
<actionCode>agent</actionCode>
<functionName>代理商信息</functionName>
</function>
<function>
<functionCode>bb</functionCode>
<method>editBaseInf</method>
<actionCode>agent</actionCode>
<functionName>代理商信息修改</functionName>
</function>
</role>
</authority>
public static Map<String,String> authorityMap(String filePath){
Map<String,String> authorityMap = new HashMap<String,String>();
SAXReader saxReader = new SAXReader();
// 得到xml文档
Document document = null;
try {
document = saxReader.read(new File(filePath));
} catch (DocumentException e) {
e.printStackTrace();
}
Element root = document.getRootElement();//取得根结点
List<Element> role = root.elements("role");
for(Element note :role){
String ro = note.attributeValue("name");
List<Element> function = note.elements("function");
String authority = "";
for(Element fun : function){
String au = fun.element("functionCode").getTextTrim();
authority += au+",";
}
authorityMap.put(ro, authority);
}
return authorityMap;
}