001: /**
002: * Copyright 2005 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */package com.sun.portal.admin.console.communities;
013:
014: import java.util.*;
015: import java.util.logging.Level;
016: import java.io.*;
017: import java.text.*;
018:
019: import javax.faces.context.FacesContext;
020: import javax.faces.application.FacesMessage;
021: import javax.faces.component.UIComponent;
022: import javax.faces.validator.*;
023: import javax.faces.el.ValueBinding;
024: import javax.servlet.http.HttpServletRequest;
025: import javax.management.*;
026:
027: import com.sun.web.ui.model.*;
028: import com.sun.web.ui.event.*;
029: import com.sun.web.ui.component.*;
030:
031: import com.sun.data.provider.*;
032: import com.sun.data.provider.impl.ObjectListDataProvider;
033:
034: import com.sun.cacao.agent.JmxClient;
035:
036: import com.sun.portal.admin.common.util.AdminClientUtil;
037: import com.sun.portal.admin.console.common.PSBaseBean;
038:
039: public class CommunityUsersHomeBean extends PSBaseBean {
040:
041: public String communityName = "";
042: private ObjectListDataProvider communityUsers = null;
043:
044: public CommunityUsersHomeBean() {
045: communityName = (String) getSessionAttribute("communityusershome.community.selected");
046:
047: retrieveCommunityUsers();
048: }
049:
050: public String getPageTitle() {
051: MessageFormat mf = new MessageFormat("");
052: mf.applyPattern(getLocalizedString("communities",
053: "communityusershome.pagetitle"));
054: return mf.format(new Object[] { communityName });
055: }
056:
057: public boolean getShowError() {
058: String value = (String) getSessionAttribute("communityusershome.showerror");
059: if (value == null || value.equals("false")) {
060: return false;
061: } else {
062: return true;
063: }
064: }
065:
066: public ObjectListDataProvider getCommunityUsers() {
067: return communityUsers;
068: }
069:
070: public void setCommunityUsers(ObjectListDataProvider communityUsers) {
071: this .communityUsers = communityUsers;
072: }
073:
074: public String add() {
075: setSessionAttribute("addcommunityuser.community.selected",
076: communityName);
077: return "gotoAddCommunityUser";
078: }
079:
080: public String remove() {
081: try {
082: LinkedList path = new LinkedList();
083: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
084: path
085: .addFirst((String) getSessionAttribute(ATTR_SELECTED_PORTAL));
086: path.addFirst("CommunityManager");
087: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
088: AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE, path);
089:
090: List l = Checkbox.getSelected("checkbox");
091: for (int index = 0; index < l.size(); index++) {
092: Object[] params = { communityName,
093: (String) l.get(index) };
094: String[] signatures = { "java.lang.String",
095: "java.lang.String" };
096: getMBeanServerConnection().invoke(on,
097: "removeCommunityUser", params, signatures);
098: }
099: setSessionAttribute("communityusershome.showerror", "false");
100: } catch (Exception e) {
101: log(Level.SEVERE, "CommunityUsersHomeBean.remove()", e);
102: setSessionAttribute("communityusershome.showerror", "true");
103: }
104:
105: retrieveCommunityUsers();
106: return null;
107: }
108:
109: public String ban() {
110: try {
111: LinkedList path = new LinkedList();
112: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
113: path
114: .addFirst((String) getSessionAttribute(ATTR_SELECTED_PORTAL));
115: path.addFirst("CommunityManager");
116: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
117: AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE, path);
118:
119: List l = Checkbox.getSelected("checkbox");
120: for (int index = 0; index < l.size(); index++) {
121: Object[] params = { communityName,
122: (String) l.get(index) };
123: String[] signatures = { "java.lang.String",
124: "java.lang.String" };
125: getMBeanServerConnection().invoke(on,
126: "banCommunityUser", params, signatures);
127: }
128: setSessionAttribute("communityusershome.showerror", "false");
129: } catch (Exception e) {
130: log(Level.SEVERE, "CommunityUsersHomeBean.ban()", e);
131: setSessionAttribute("communityusershome.showerror", "true");
132: }
133:
134: retrieveCommunityUsers();
135: return null;
136: }
137:
138: public String unban() {
139: try {
140: LinkedList path = new LinkedList();
141: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
142: path
143: .addFirst((String) getSessionAttribute(ATTR_SELECTED_PORTAL));
144: path.addFirst("CommunityManager");
145: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
146: AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE, path);
147:
148: List l = Checkbox.getSelected("checkbox");
149: for (int index = 0; index < l.size(); index++) {
150: Object[] params = { communityName,
151: (String) l.get(index) };
152: String[] signatures = { "java.lang.String",
153: "java.lang.String" };
154: getMBeanServerConnection().invoke(on,
155: "unbanCommunityUser", params, signatures);
156: }
157: setSessionAttribute("communityusershome.showerror", "false");
158: } catch (Exception e) {
159: log(Level.SEVERE, "CommunityUsersHomeBean.unban()", e);
160: setSessionAttribute("communityusershome.showerror", "true");
161: }
162:
163: retrieveCommunityUsers();
164: return null;
165: }
166:
167: public String addOwner() {
168: try {
169: LinkedList path = new LinkedList();
170: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
171: path
172: .addFirst((String) getSessionAttribute(ATTR_SELECTED_PORTAL));
173: path.addFirst("CommunityManager");
174: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
175: AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE, path);
176:
177: List l = Checkbox.getSelected("checkbox");
178: for (int index = 0; index < l.size(); index++) {
179: Object[] params = { communityName,
180: (String) l.get(index) };
181: String[] signatures = { "java.lang.String",
182: "java.lang.String" };
183: getMBeanServerConnection().invoke(on,
184: "addCommunityOwner", params, signatures);
185: }
186: setSessionAttribute("communityusershome.showerror", "false");
187: } catch (Exception e) {
188: log(Level.SEVERE, "CommunityUsersHomeBean.addOwner()", e);
189: setSessionAttribute("communityusershome.showerror", "true");
190: }
191:
192: retrieveCommunityUsers();
193: return null;
194: }
195:
196: public String removeOwner() {
197: try {
198: LinkedList path = new LinkedList();
199: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
200: path
201: .addFirst((String) getSessionAttribute(ATTR_SELECTED_PORTAL));
202: path.addFirst("CommunityManager");
203: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
204: AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE, path);
205:
206: List l = Checkbox.getSelected("checkbox");
207: for (int index = 0; index < l.size(); index++) {
208: Object[] params = { communityName,
209: (String) l.get(index) };
210: String[] signatures = { "java.lang.String",
211: "java.lang.String" };
212: getMBeanServerConnection().invoke(on,
213: "removeCommunityOwner", params, signatures);
214: }
215: setSessionAttribute("communityusershome.showerror", "false");
216: } catch (Exception e) {
217: log(Level.SEVERE, "CommunityUsersHomeBean.removeOwner()", e);
218: setSessionAttribute("communityusershome.showerror", "true");
219: }
220:
221: retrieveCommunityUsers();
222: return null;
223: }
224:
225: public String back() {
226: return "gotoCommunitiesHome";
227: }
228:
229: private void retrieveCommunityUsers() {
230: ArrayList al = new ArrayList();
231: try {
232: LinkedList path = new LinkedList();
233: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
234: path
235: .addFirst((String) getSessionAttribute(ATTR_SELECTED_PORTAL));
236: path.addFirst("CommunityManager");
237: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
238: AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE, path);
239:
240: Object[] params = { communityName };
241: String[] signatures = { "java.lang.String" };
242: ArrayList data = (ArrayList) getMBeanServerConnection()
243: .invoke(on, "getCommunityUsers", params, signatures);
244: for (int index = 0; index < data.size(); index++) {
245: CommunityUserBean cub = new CommunityUserBean();
246: cub.initialize((Properties) data.get(index));
247: al.add(cub);
248: }
249: setSessionAttribute("communityusershome.showerror", "false");
250: } catch (Exception e) {
251: log(
252: Level.SEVERE,
253: "CommunityUsersHomeBean.retrieveCommunityUsers() : Exception ",
254: e);
255: setSessionAttribute("communityusershome.showerror", "true");
256: }
257: communityUsers = new ObjectListDataProvider(al);
258: communityUsers.setObjectType(CommunityUserBean.class);
259: }
260:
261: }
|