📄 permissionserviceimpl.java
字号:
package com.cownew.PIS.base.permission.bizLayer;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
import org.dom4j.tree.DefaultElement;
import com.cownew.PIS.base.permission.common.IPermissionService;
import com.cownew.PIS.base.permission.common.PermissionException;
import com.cownew.PIS.framework.server.helper.ServerConfig;
import com.cownew.ctk.common.ExceptionUtils;
import com.cownew.ctk.constant.StringConst;
import com.cownew.ctk.io.ResourceUtils;
public class PermissionServiceImpl implements IPermissionService
{
private static List allPermissionItemList;
public List getAllPermissionItem()
{
if(allPermissionItemList!=null)
{
return allPermissionItemList;
}
allPermissionItemList = new ArrayList();
try
{
String[] beanFiles = ServerConfig.getInstance().getBeanFiles();
for (int i = 0, n = beanFiles.length; i < n; i++)
{
List pItem = getPermissionItem(beanFiles[i]);
if (pItem != null && pItem.size() > 0)
{
allPermissionItemList.addAll(pItem);
}
}
} catch (UnsupportedEncodingException e)
{
ExceptionUtils.toRuntimeException(e);
} catch (DocumentException e)
{
ExceptionUtils.toRuntimeException(e);
}
checkPermItemDup(allPermissionItemList);
return allPermissionItemList;
}
/**
* 检验权限项定义是否有名称重复的
* @param permList
* @
*/
private void checkPermItemDup(List permList)
{
Set set = new HashSet(permList.size());
for (int i = 0, n = permList.size(); i < n; i++)
{
Object obj = permList.get(i);
if (set.contains(obj))
{
throw new PermissionException(
PermissionException.PERMISSIONITEMDUP,
new Object[] { obj.toString() });
}
set.add(obj);
}
}
/**
* 得到文件beanFile中定义的所有权限项
* @param beanFile
* @return
* @throws UnsupportedEncodingException
* @throws DocumentException
*/
private List getPermissionItem(String beanFile)
throws UnsupportedEncodingException, DocumentException
{
InputStream beansXFStream = null;
List permList = new ArrayList();
try
{
beansXFStream = getClass().getResourceAsStream(beanFile);
SAXReader saxReader = new SAXReader(false);
InputStreamReader inReader = new InputStreamReader(beansXFStream,
StringConst.UTF8);
Document doc = saxReader.read(inReader);
List beanList = doc.selectNodes("//beans/bean");
for (int i = 0, n = beanList.size(); i < n; i++)
{
DefaultElement beanElement = (DefaultElement) beanList.get(i);
List properties = beanElement.selectNodes("property");
for (int j = 0, m = properties.size(); j < m; j++)
{
DefaultElement prop = (DefaultElement) properties.get(j);
Attribute attribute = prop.attribute("name");
if (attribute != null
&& attribute.getValue().equals(
"permissionAttributes"))
{
permList.addAll(getPermissionsFromProp(prop));
}
prop = null;
}
beanElement = null;
properties = null;
}
} finally
{
ResourceUtils.close(beansXFStream);
}
return permList;
}
/**
* 得到bean xml文件中props节点中所有的权限项
* @param prop
* @return
*/
private List getPermissionsFromProp(DefaultElement prop)
{
List retList = new ArrayList();
List propList = prop.selectNodes("props/prop");
for(int i=0,n=propList.size();i<n;i++)
{
DefaultElement beanElement = (DefaultElement) propList.get(i);
String permItem = beanElement.getText().trim();
retList.add(permItem);
}
return retList;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -