📄 admingroups.java
字号:
/* * 作者: 胡李青 * qq: 31703299 * Copyright (c) 2007 huliqing * 主页 http://www.tbuy.biz/ * 你可以免费使用该软件,未经许可请勿作用于任何商业目的,如有技术问题请与本人联系! */package biz.tbuy.bbs.bean;import biz.tbuy.bbs.BBSGroups;import biz.tbuy.common.Constants;import biz.tbuy.common.Utils;import biz.tbuy.common.logs.Elog;import biz.tbuy.share.XmlOper;import java.util.ArrayList;import java.util.List;import java.util.Map;import java.util.Set;import javax.faces.component.UIData;import org.w3c.dom.Document;import org.w3c.dom.Element;import org.w3c.dom.NodeList;import org.w3c.dom.Text;/** * @author huliqing * <p><b>qq:</b>31703299 * <p><b>E-mail:</b><a href="mailto:huliqing.cn@gmail.com">huliqing.cn@gmail.com</a> * <p><b>Homepage:</b><a href="http://www.tbuy.biz/">http://www.tbuy.biz/</a> */public class AdminGroups extends BaseBean{ private String _groupId; // 用户组id private String _groupLabel; // 用户组标识 private String _groupValue; // 用户组所需积分 private List<Map<String, String>> _groups; // BBS的用户组列表 private UIData _uiGroups; // 绑定于用户组 /** Creates a new instance of AdminGroups */ public AdminGroups() { loadGroups(); } public void setGroupId(String groupId) { _groupId = groupId; } public String getGroupId() { return _groupId; } public void setGroupLabel(String groupLabel) { _groupLabel = groupLabel; } public String getGroupLabel() { return _groupLabel; } public void setGroupValue(String groupValue) { _groupValue = groupValue; } public String getGroupValue() { return _groupValue; } public void setGroups(List<Map<String, String>> groups) { _groups = groups; } public List<Map<String, String>> getGroups() { return _groups; } public void setUiGroups(UIData uiGroups) { _uiGroups = uiGroups; } public UIData getUiGroups() { return _uiGroups; } /** * 创建一个新的BBS用户组 */ public String newGroup() { try { String appConfig = getComApplication(). getServletContextPath() + BBSGroups.PATH_APPCONFIG; Document doc = XmlOper.getDocument(appConfig); Element root = doc.getDocumentElement(); Element groups1 = (Element)root.getElementsByTagName("groups").item(0); NodeList groups = groups1.getElementsByTagName("group"); int len = groups.getLength(); //System.out.println("id=" + id); for (int i = 0; i < len; i++) { Element gg = (Element)groups.item(i); String name = gg.getElementsByTagName("name").item(0).getTextContent(); //System.out.println("name=" + name); if (_groupId.toLowerCase().trim().equals(name.toLowerCase())) { Utils.addErrorMessage(getBundle(), "所要创建的用户组已经存在!"); return Constants.OUT_FAILURE; } } Element eGroup = doc.createElement("group"); Element eName = doc.createElement("name"); Element eLabel = doc.createElement("label"); Element eValue = doc.createElement("value"); Text tName = doc.createTextNode(_groupId.trim()); Text tLabel = doc.createTextNode(_groupLabel); Text tValue = doc.createTextNode(_groupValue); eName.appendChild(tName); eLabel.appendChild(tLabel); eValue.appendChild(tValue); eGroup.appendChild(eName); eGroup.appendChild(eLabel); eGroup.appendChild(eValue); groups1.appendChild(eGroup); XmlOper.saveDocument(doc, appConfig); // 重新载入BBS用户组信息 getBBSApplication().reloadGroups(); loadGroups(); _groupId = ""; _groupLabel = ""; _groupValue = ""; Utils.addInfoMessage(getBundle(), "创建新用户组成功"); return Constants.OUT_SUCCESS; }catch (Exception e) { Elog.log("Exception:AdminGroups:newGroup:" + e.getMessage()); Utils.addErrorMessage(getBundle(), "新增用户组时遇到问题!"); return Constants.OUT_FAILURE; } } /** * 编辑BBS用户组信息,然后重新载入用户组信息 */ public String edit() { try { String appConfig = getComApplication(). getServletContextPath() + BBSGroups.PATH_APPCONFIG; Document doc = XmlOper.getDocument(appConfig); Element root = doc.getDocumentElement(); Element groups1 = (Element)root.getElementsByTagName("groups").item(0); NodeList groups = groups1.getElementsByTagName("group"); int len = groups.getLength(); for (Map<String, String> group : _groups) { String id = group.get("id"); //System.out.println("id=" + id); for (int i = 0; i < len; i++) { Element gg = (Element)groups.item(i); String name = gg.getElementsByTagName("name").item(0).getTextContent(); //System.out.println("name=" + name); if (id.equals(name)) { gg.getElementsByTagName("label").item(0).setTextContent(group.get("label")); gg.getElementsByTagName("value").item(0).setTextContent(group.get("value")); break; } } } XmlOper.saveDocument(doc, appConfig); // 重新载入BBS用户组信息 getBBSApplication().reloadGroups(); loadGroups(); Utils.addInfoMessage(getBundle(), "用户组修改成功!"); return Constants.OUT_SUCCESS; }catch (Exception e) { Elog.log("Exception:AdminGroups:edit:" + e.getMessage()); Utils.addErrorMessage(getBundle(), "编辑用户组信息时遇到问题!"); return Constants.OUT_FAILURE; } } /** * 移除一个BBS用户组,并重新载入用户组信息 */ public String removeGroup() { @SuppressWarnings("unchecked") Map<String, String> group = (Map<String, String>)_uiGroups.getRowData(); if (group.get("id").equals("G1")) { Utils.addErrorMessage(getBundle(), "“G1”为默认用户组,你不应该删除它"); return Constants.OUT_FAILURE; } try { String appConfig = getComApplication(). getServletContextPath() + BBSGroups.PATH_APPCONFIG; Document doc = XmlOper.getDocument(appConfig); Element root = doc.getDocumentElement(); Element groups1 = (Element)root.getElementsByTagName("groups").item(0); NodeList groups = groups1.getElementsByTagName("group"); int len = groups.getLength(); for (int i = 0; i < len; i++) { Element gg = (Element)groups.item(i); String name = gg.getElementsByTagName("name").item(0).getTextContent(); if (group.get("id").equals(name)) { groups1.removeChild(gg); // 移除相应节点 break; } } XmlOper.saveDocument(doc, appConfig); // 重新载入BBS用户组信息 getBBSApplication().reloadGroups(); loadGroups(); Utils.addInfoMessage(getBundle(), "移除用户组成功"); return Constants.OUT_SUCCESS; }catch (Exception e) { Elog.log("Exception:AdminGroups:newGroup:" + e.getMessage()); Utils.addErrorMessage(getBundle(), "移除用户组时遇到问题!"); return Constants.OUT_FAILURE; } } private void loadGroups() { _groups = new ArrayList<Map<String, String>>(); Map<String, Map<String, String>> map = getBBSApplication().getGroups(); Set<String> keys = map.keySet(); for (String key : keys) { _groups.add(map.get(key)); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -