📄 topicauth.java
字号:
/* * 作者: 胡李青 * qq: 31703299 * Copyright (c) 2007 huliqing * 主页 http://www.tbuy.biz/ * 你可以免费使用该软件,未经许可请勿作用于任何商业目的,如有技术问题请与本人联系! */package biz.tbuy.bbs.bean;import biz.tbuy.bbs.BBSGroups;import biz.tbuy.bbs.TopicBuilder;import biz.tbuy.bbs.TopicFactory;import biz.tbuy.bbs.TopicModel;import biz.tbuy.common.Constants;import biz.tbuy.common.Utils;import java.util.ArrayList;import java.util.List;import java.util.Map;import java.util.Set;import javax.faces.component.UISelectMany;import javax.faces.event.ValueChangeEvent;import javax.faces.model.SelectItem;/** * @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 TopicAuth extends BaseBean{ private TopicModel _topic; // 正在被编辑阅读权限的主题 private List<SelectItem> _authTypes; // 所有可选的阅读权限类型,如:all,login,groups private List<String> _authGroups; // 最终选择的authGroups类型 private UISelectMany _uiAuthGroups; // 绑定于authGroups; private List<SelectItem> _authGroupsAll;// 所有可选的Groups /** Creates a new instance of TopicAuth */ public TopicAuth() { _topic = new TopicModel(); } public void setTopic(TopicModel topic) { _topic = topic; } public TopicModel getTopic() { return _topic; } public void setAuthTypes(List<SelectItem> authTypes) { _authTypes = authTypes; } public List<SelectItem> getAuthTypes() { _authTypes = new ArrayList<SelectItem>(3); _authTypes.add(new SelectItem(BBSGroups.READER_AUTH_ALL, "所有人")); _authTypes.add(new SelectItem(BBSGroups.READER_AUTH_LOGIN, "登录用户")); _authTypes.add(new SelectItem(BBSGroups.READER_AUTH_GROUPS, "特定用户组")); return _authTypes; } public void setAuthGroups(List<String> authGroups) { _authGroups = authGroups; } public List<String> getAuthGroups() { return _authGroups; } public void setUiAuthGroups(UISelectMany uiAuthGroups) { _uiAuthGroups = uiAuthGroups; } public UISelectMany getUiAuthGroups() { String[] authGroups = _topic.getAuthGroups().split(","); List<String> groups = new ArrayList<String>(); for (int i = 0; i < authGroups.length; i++) { groups.add(authGroups[i]); } _uiAuthGroups = new UISelectMany(); _uiAuthGroups.setValue(groups); if (_topic.getAuthType() ==BBSGroups.READER_AUTH_GROUPS) { _uiAuthGroups.getAttributes().put("disabled", false); } else { _uiAuthGroups.getAttributes().put("disabled", true); } return _uiAuthGroups; } public void setAuthGroupsAll(List<SelectItem> authGroupsAll) { _authGroupsAll = authGroupsAll; } public List<SelectItem> getAuthGroupsAll() { _authGroupsAll = new ArrayList<SelectItem>(); Map<String, Map<String, String>> groups = getBBSApplication().getGroups(); if (!groups.isEmpty()) { Set<String> keys = groups.keySet(); for (String key : keys) { _authGroupsAll.add(new SelectItem(key, groups.get(key).get("label"))); } } return _authGroupsAll; } /** * 监测页面中是否选中了“特定用户组”选项,如果选中,则打开用户组选项 * 使其"disabled"属性为false */ public void checkType(ValueChangeEvent event) { int authType = Integer.parseInt(event.getNewValue().toString()); if (authType == BBSGroups.READER_AUTH_GROUPS) { _uiAuthGroups.getAttributes().put("disabled", false); } else { _uiAuthGroups.getAttributes().put("disabled", true); } } /** * 编辑阅读权限 */ public String displayAuth() { // 如果选择了特定用户组的阅读权限 int authType = _topic.getAuthType(); this.reload(); TopicBuilder tBuilder = TopicFactory.newBuilder(_topic); if (tBuilder.updateAuth(authType, _authGroups)) { Utils.addInfoMessage(getBundle(), "阅读权限设置成功!"); return Constants.OUT_SUCCESS; } return Constants.OUT_FAILURE; } /** * 重新载入topic,以免属性丢失 */ private void reload() { _topic = TopicFactory.getTopic(_topic.getNum()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -