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.lang.*;
017: import java.io.*;
018: import java.net.*;
019: import java.text.*;
020:
021: import javax.faces.context.FacesContext;
022: import javax.faces.component.*;
023: import javax.faces.el.*;
024: import javax.faces.event.*;
025: import javax.faces.application.Application;
026: import javax.servlet.http.HttpServletRequest;
027: import javax.management.*;
028:
029: import com.sun.web.ui.model.*;
030: import com.sun.web.ui.event.*;
031: import com.sun.web.ui.component.*;
032:
033: import com.sun.data.provider.*;
034: import com.sun.data.provider.impl.ObjectListDataProvider;
035:
036: import com.sun.cacao.agent.JmxClient;
037:
038: import com.sun.portal.admin.common.util.AdminClientUtil;
039: import com.sun.portal.admin.console.common.PSBaseBean;
040:
041: public class CommunitiesHomeBean extends PSBaseBean {
042:
043: private static final int MAX_COMMUNITIES = 75;
044:
045: private ObjectListDataProvider communities = null;
046:
047: public CommunitiesHomeBean() {
048: try {
049: LinkedList path = new LinkedList();
050: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
051: path
052: .addFirst((String) getSessionAttribute(ATTR_SELECTED_PORTAL));
053: path.addFirst("CommunityManager");
054: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
055: AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE, path);
056: Object[] params = {};
057: String[] signatures = {};
058: String searchServerID = (String) getMBeanServerConnection()
059: .invoke(on, "retrieveSearchServerID", params,
060: signatures);
061: setSessionAttribute("communities.searchserverid",
062: searchServerID);
063: } catch (Exception e) {
064: log(Level.SEVERE, "CommunitiesHomeBean : Exception ", e);
065: }
066:
067: String searchText = (String) getSessionAttribute("communitieshome.searchtext");
068: if (searchText == null) {
069: setSessionAttribute("communitieshome.searchtext", "");
070: }
071: retrieveSearchResults();
072: }
073:
074: public boolean getShowError() {
075: String value = (String) getSessionAttribute("communitieshome.showerror");
076: if (value == null || value.equals("false")) {
077: return false;
078: } else {
079: return true;
080: }
081: }
082:
083: public boolean getShowTooManyWarning() {
084: String value = (String) getSessionAttribute("communities.communitieshome.toomanysearchresults");
085: if (value == null || value.equals("false")) {
086: return false;
087: } else {
088: return true;
089: }
090: }
091:
092: public boolean getShowNoSearch() {
093: String searchText = (String) getSessionAttribute("communitieshome.searchtext");
094: if (searchText.equals("")) {
095: return true;
096: } else {
097: return false;
098: }
099: }
100:
101: public String getSearchText() {
102: return (String) getSessionAttribute("communitieshome.searchtext");
103: }
104:
105: public void setSearchText(String searchText) {
106: setSessionAttribute("communitieshome.searchtext", searchText);
107: }
108:
109: public ObjectListDataProvider getCommunities() {
110: return communities;
111: }
112:
113: public void setCommunities(ObjectListDataProvider communities) {
114: this .communities = communities;
115: }
116:
117: public boolean getHasCommunities() {
118: if (communities == null) {
119: return false;
120: }
121: List l = communities.getList();
122: if (l.size() == 0) {
123: return false;
124: }
125: return true;
126: }
127:
128: public String search() {
129: retrieveSearchResults();
130: return null;
131: }
132:
133: public String create() {
134: return "gotoCreateCommunity";
135: }
136:
137: public String gotoEditCommunity() {
138: return "gotoEditCommunity";
139: }
140:
141: public String gotoCommunityUsersHome() {
142: return "gotoCommunityUsersHome";
143: }
144:
145: public String manageUsers() {
146: List l = Checkbox.getSelected("checkbox");
147: for (int index = 0; index < l.size(); index++) {
148: setSessionAttribute(
149: "communityusershome.community.selected", (String) l
150: .get(index));
151: }
152: return "gotoCommunityUsersHome";
153: }
154:
155: public String managePendingUsers() {
156: List l = Checkbox.getSelected("checkbox");
157: for (int index = 0; index < l.size(); index++) {
158: setSessionAttribute(
159: "communitypendingusershome.community.selected",
160: (String) l.get(index));
161: }
162: return "gotoCommunityPendingUsersHome";
163: }
164:
165: public String enable() {
166: try {
167: LinkedList path = new LinkedList();
168: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
169: path
170: .addFirst((String) getSessionAttribute(ATTR_SELECTED_PORTAL));
171: path.addFirst("CommunityManager");
172: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
173: AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE, path);
174: List l = Checkbox.getSelected("checkbox");
175: for (int index = 0; index < l.size(); index++) {
176: Object[] params = { (String) l.get(index) };
177: String[] signatures = { "java.lang.String" };
178: getMBeanServerConnection().invoke(on,
179: "enableCommunity", params, signatures);
180: }
181: setSessionAttribute("communitieshome.showerror", "false");
182: } catch (Exception e) {
183: log(Level.SEVERE, "CommunitiesHome.enable()", e);
184: setSessionAttribute("communitieshome.showerror", "true");
185: }
186: retrieveSearchResults();
187: return null;
188: }
189:
190: public String disable() {
191: try {
192: LinkedList path = new LinkedList();
193: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
194: path
195: .addFirst((String) getSessionAttribute(ATTR_SELECTED_PORTAL));
196: path.addFirst("CommunityManager");
197: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
198: AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE, path);
199: List l = Checkbox.getSelected("checkbox");
200: for (int index = 0; index < l.size(); index++) {
201: Object[] params = { (String) l.get(index) };
202: String[] signatures = { "java.lang.String" };
203: getMBeanServerConnection().invoke(on,
204: "disableCommunity", params, signatures);
205: }
206: setSessionAttribute("communitieshome.showerror", "false");
207: } catch (Exception e) {
208: log(Level.SEVERE, "CommunitiesHome.disable()", e);
209: setSessionAttribute("communitieshome.showerror", "true");
210: }
211: retrieveSearchResults();
212: return null;
213: }
214:
215: public String undelete() {
216: try {
217: LinkedList path = new LinkedList();
218: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
219: path
220: .addFirst((String) getSessionAttribute(ATTR_SELECTED_PORTAL));
221: path.addFirst("CommunityManager");
222: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
223: AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE, path);
224: List l = Checkbox.getSelected("checkbox");
225: for (int index = 0; index < l.size(); index++) {
226: Object[] params = { (String) l.get(index) };
227: String[] signatures = { "java.lang.String" };
228: getMBeanServerConnection().invoke(on,
229: "undeleteCommunity", params, signatures);
230: }
231: setSessionAttribute("communitieshome.showerror", "false");
232: } catch (Exception e) {
233: log(Level.SEVERE, "CommunitiesHome.undelete()", e);
234: setSessionAttribute("communitieshome.showerror", "true");
235: }
236: retrieveSearchResults();
237: return null;
238: }
239:
240: public String delete() {
241: try {
242: LinkedList path = new LinkedList();
243: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
244: path
245: .addFirst((String) getSessionAttribute(ATTR_SELECTED_PORTAL));
246: path.addFirst("CommunityManager");
247: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
248: AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE, path);
249: List l = Checkbox.getSelected("checkbox");
250: for (int index = 0; index < l.size(); index++) {
251: Object[] params = { (String) l.get(index) };
252: String[] signatures = { "java.lang.String" };
253: getMBeanServerConnection().invoke(on,
254: "deleteCommunity", params, signatures);
255: }
256: setSessionAttribute("communitieshome.showerror", "false");
257: } catch (Exception e) {
258: log(Level.SEVERE, "CommunitiesHome.delete()", e);
259: setSessionAttribute("communitieshome.showerror", "true");
260: }
261: retrieveSearchResults();
262: return null;
263: }
264:
265: private void retrieveSearchResults() {
266: String searchText = (String) getSessionAttribute("communitieshome.searchtext");
267: searchText = searchText.replaceAll("\\*", ".*");
268:
269: ArrayList al = new ArrayList();
270: if (!searchText.equals("")) {
271: try {
272: LinkedList path = new LinkedList();
273: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
274: path
275: .addFirst((String) getSessionAttribute(ATTR_SELECTED_PORTAL));
276: path.addFirst("CommunityManager");
277: ObjectName on = AdminClientUtil
278: .getResourceMBeanObjectName(
279: AdminClientUtil.COMMUNITYMANAGER_MBEAN_TYPE,
280: path);
281: Object[] params = { searchText };
282: String[] signatures = { "java.lang.String" };
283: ArrayList data = (ArrayList) getMBeanServerConnection()
284: .invoke(on, "searchForCommunities", params,
285: signatures);
286: int size = data.size();
287: if (size > MAX_COMMUNITIES) {
288: size = MAX_COMMUNITIES;
289: setSessionAttribute(
290: "communities.communitieshome.toomanysearchresults",
291: "true");
292: } else {
293: setSessionAttribute(
294: "communities.communitieshome.toomanysearchresults",
295: "false");
296: }
297: for (int index = 0; index < size; index++) {
298: CommunityBean cb = new CommunityBean();
299: cb.initialize((Properties) data.get(index));
300: al.add(cb);
301: }
302: setSessionAttribute("communitieshome.showerror",
303: "false");
304: } catch (Exception e) {
305: log(Level.SEVERE,
306: "CommunitiesHome.retrieveSearchResults()", e);
307: setSessionAttribute("communitieshome.showerror", "true");
308: }
309: }
310: communities = new ObjectListDataProvider(al);
311: communities.setObjectType(CommunityBean.class);
312: }
313:
314: }
|