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 EditCommunityCategoriesPopupBean extends PSBaseBean {
042:
043: private String rootNodeID = null;
044: private String currentNodeID = null;
045: private Hyperlink[] categories = null;
046: private ObjectListDataProvider children = null;
047:
048: private String searchText = null;
049: private String searchScope = null;
050:
051: private ObjectListDataProvider searchResults = null;
052:
053: public EditCommunityCategoriesPopupBean() {
054: sync();
055:
056: rootNodeID = retrieveRootNodeID();
057:
058: String mode = (String) getSessionAttribute("editcommunitycategoriespopup.mode");
059: if (mode == null || mode.equals("")) {
060: mode = "browse";
061: setSessionAttribute("editcommunitycategoriespopup.mode",
062: "browse");
063: }
064: if (mode.equals("browse")) {
065: HttpServletRequest hsr = (HttpServletRequest) FacesContext
066: .getCurrentInstance().getExternalContext()
067: .getRequest();
068: currentNodeID = (String) hsr
069: .getParameter("editcommunitycategoriespopup.category");
070: if (currentNodeID == null) {
071: currentNodeID = (String) getSessionAttribute("editcommunitycategoriespopup.category");
072: }
073: if (currentNodeID == null) {
074: currentNodeID = "";
075: }
076: setSessionAttribute(
077: "editcommunitycategoriespopup.category",
078: currentNodeID);
079:
080: retrieveCategories(currentNodeID);
081: retrieveChildren(currentNodeID);
082:
083: searchText = "";
084: setSessionAttribute(
085: "editcommunitycategoriespopup.searchtext",
086: searchText);
087: searchScope = "all";
088: setSessionAttribute(
089: "editcommunitycategoriespopup.searchscope",
090: searchScope);
091: } else {
092: searchText = (String) getSessionAttribute("editcommunitycategoriespopup.searchtext");
093: if (searchText == null) {
094: searchText = "";
095: }
096: setSessionAttribute(
097: "editcommunitycategoriespopup.searchtext",
098: searchText);
099:
100: searchScope = (String) getSessionAttribute("editcommunitycategoriespopup.searchscope");
101: if (searchScope == null) {
102: searchScope = "all";
103: }
104: setSessionAttribute(
105: "editcommunitycategoriespopup.searchscope",
106: searchScope);
107:
108: retrieveSearchResults();
109: }
110: }
111:
112: public String getSelectedNodeID() {
113: return (String) getSessionAttribute("editcommunitycategoriespopup.category");
114: }
115:
116: public void setSelectedNodeID(String value) {
117: }
118:
119: public boolean getInSearchResults() {
120: String mode = (String) getSessionAttribute("editcommunitycategoriespopup.mode");
121: if (mode == null && mode.equals("")) {
122: mode = "browse";
123: setSessionAttribute("editcommunitycategoriespopup.mode",
124: "browse");
125: }
126: if (mode.equals("browse")) {
127: return false;
128: } else {
129: return true;
130: }
131: }
132:
133: public String getSearchText() {
134: return searchText;
135: }
136:
137: public void setSearchText(String searchText) {
138: this .searchText = searchText;
139: }
140:
141: public String doSearch() {
142: setSessionAttribute("editcommunitycategoriespopup.searchtext",
143: searchText);
144: setSessionAttribute("editcommunitycategoriespopup.searchscope",
145: searchScope);
146: retrieveSearchResults();
147:
148: setSessionAttribute("editcommunitycategoriespopup.mode",
149: "searchresults");
150: return null;
151: }
152:
153: public Hyperlink[] getCategories() {
154: return categories;
155: }
156:
157: public void setCategories(Hyperlink[] categories) {
158: this .categories = categories;
159: }
160:
161: public ObjectListDataProvider getChildren() {
162: return children;
163: }
164:
165: public void setChildren(ObjectListDataProvider children) {
166: this .children = children;
167: }
168:
169: public String drillDown() {
170: return null;
171: }
172:
173: public ObjectListDataProvider getSearchResults() {
174: return searchResults;
175: }
176:
177: public void setSearchResults(ObjectListDataProvider searchResults) {
178: this .searchResults = searchResults;
179: }
180:
181: public String selectSearchResult() {
182: FacesContext fc = FacesContext.getCurrentInstance();
183: ValueBinding vb = fc.getApplication().createValueBinding(
184: "#{category.value.nodeID}");
185: String value = (String) vb.getValue(fc);
186: setSessionAttribute("editcommunitycategoriespopup.category",
187: value);
188: retrieveCategories(value);
189: retrieveChildren(value);
190:
191: setSessionAttribute("editcommunitycategoriespopup.mode",
192: "browse");
193: return null;
194: }
195:
196: public String back() {
197: String value = (String) getSessionAttribute("editcommunitycategoriespopup.category");
198: retrieveCategories(value);
199: retrieveChildren(value);
200:
201: setSessionAttribute("editcommunitycategoriespopup.mode",
202: "browse");
203: return null;
204: }
205:
206: private void sync() {
207: try {
208: LinkedList path = new LinkedList();
209: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
210: path
211: .addFirst((String) getSessionAttribute("communities.searchserverid"));
212: path.addFirst("category");
213: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
214: AdminClientUtil.SEARCH_CATEGORY_MBEAN_TYPE, path);
215: Object[] params = {};
216: String[] signatures = {};
217: getMBeanServerConnection().invoke(on, "syncTaxFile",
218: params, signatures);
219: } catch (Exception e) {
220: log(
221: Level.SEVERE,
222: "EditCommunityCategoriesPopupBean.sync() : Exception ",
223: e);
224: }
225: }
226:
227: private String retrieveRootNodeID() {
228: try {
229: LinkedList path = new LinkedList();
230: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
231: path
232: .addFirst((String) getSessionAttribute("communities.searchserverid"));
233: path.addFirst("category");
234: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
235: AdminClientUtil.SEARCH_CATEGORY_MBEAN_TYPE, path);
236: Object[] params = {};
237: String[] signatures = {};
238: return (String) getMBeanServerConnection().invoke(on,
239: "retrieveTaxName", params, signatures);
240: } catch (Exception e) {
241: log(
242: Level.SEVERE,
243: "EditCommunityCategoriesPopupBean.retrieveRootNodeID() : Exception ",
244: e);
245: return "";
246: }
247: }
248:
249: private void retrieveCategories(String startNodeID) {
250: Random r = new Random();
251:
252: if (startNodeID.equals("")) {
253: Hyperlink hl = new Hyperlink();
254: hl.setId("hl_" + Integer.toString(r.nextInt()));
255: hl.setText(rootNodeID);
256: try {
257: hl
258: .setUrl("../faces/communities/EditCommunityCategoriesPopup.jsp?editcommunitycategoriespopup.category=");
259: } catch (Exception e) {
260: log(
261: Level.SEVERE,
262: "EditCommunityCategoriesPopupBean.retrieveCategories() : Exception ",
263: e);
264: }
265:
266: categories = new Hyperlink[1];
267: categories[0] = hl;
268: } else {
269: String[] strings = startNodeID.split(":");
270:
271: categories = new Hyperlink[strings.length + 1];
272:
273: Hyperlink hl = new Hyperlink();
274: hl.setId("hl_" + Integer.toString(r.nextInt()));
275: hl.setText(rootNodeID);
276: try {
277: hl
278: .setUrl("../faces/communities/EditCommunityCategoriesPopup.jsp?editcommunitycategoriespopup.category=");
279: } catch (Exception e) {
280: log(
281: Level.SEVERE,
282: "EditCommunityCategoriesPopupBean.retrieveCategories() : Exception ",
283: e);
284: }
285:
286: categories[0] = hl;
287:
288: String runningNodeID = "";
289: for (int index = 0; index < strings.length; index++) {
290: String nodeID = strings[index];
291:
292: runningNodeID = (!runningNodeID.equals("")) ? runningNodeID
293: + ":" + nodeID
294: : nodeID;
295:
296: hl = new Hyperlink();
297: hl.setId("hl_" + Integer.toString(r.nextInt()));
298: hl.setText(nodeID);
299: try {
300: hl
301: .setUrl("../faces/communities/EditCommunityCategoriesPopup.jsp?editcommunitycategoriespopup.category="
302: + URLEncoder.encode(runningNodeID,
303: "UTF-8"));
304: } catch (Exception e) {
305: log(
306: Level.SEVERE,
307: "EditCommunityCategoriesPopupBean.retrieveCategories() : Exception ",
308: e);
309: }
310:
311: categories[index + 1] = hl;
312: }
313: }
314: }
315:
316: private void retrieveChildren(String startNodeID) {
317: ArrayList al = new ArrayList();
318: try {
319: LinkedList path = new LinkedList();
320: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
321: path
322: .addFirst((String) getSessionAttribute("communities.searchserverid"));
323: path.addFirst("category");
324: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
325: AdminClientUtil.SEARCH_CATEGORY_MBEAN_TYPE, path);
326:
327: Object[] params = { (startNodeID.equals("")) ? rootNodeID
328: : startNodeID };
329: String[] signatures = { "java.lang.String" };
330: ArrayList data = (ArrayList) getMBeanServerConnection()
331: .invoke(on, "getTaxTreeChildren", params,
332: signatures);
333: for (int index = 0; index < data.size(); index++) {
334: String nodeID = (String) data.get(index);
335:
336: CategoryBean cb = new CategoryBean();
337: cb.initialize(nodeID, hasChildren(nodeID));
338: al.add(cb);
339: }
340: } catch (Exception e) {
341: log(
342: Level.SEVERE,
343: "EditCommunityCategoriesPopupBean.retrieveChildren() : Exception ",
344: e);
345: }
346: children = new ObjectListDataProvider(al);
347: children.setObjectType(CategoryBean.class);
348: }
349:
350: private boolean hasChildren(String startNodeID) {
351: try {
352: LinkedList path = new LinkedList();
353: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
354: path
355: .addFirst((String) getSessionAttribute("communities.searchserverid"));
356: path.addFirst("category");
357: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
358: AdminClientUtil.SEARCH_CATEGORY_MBEAN_TYPE, path);
359:
360: Object[] params = { (startNodeID.equals("")) ? rootNodeID
361: : startNodeID };
362: String[] signatures = { "java.lang.String" };
363: ArrayList data = (ArrayList) getMBeanServerConnection()
364: .invoke(on, "getTaxTreeChildren", params,
365: signatures);
366: if (data.size() > 0) {
367: return true;
368: } else {
369: return false;
370: }
371: } catch (Exception e) {
372: log(
373: Level.SEVERE,
374: "EditCommunityCategoriesPopupBean.hasChildren() : Exception ",
375: e);
376: }
377: return false;
378: }
379:
380: private void retrieveSearchResults() {
381: String searchServer = (String) getSessionAttribute("communities.searchserverid");
382: String searchText = (String) getSessionAttribute("editcommunitycategoriespopup.searchtext");
383: String searchScope = (String) getSessionAttribute("editcommunitycategoriespopup.searchscope");
384:
385: ArrayList al = new ArrayList();
386: try {
387: LinkedList path1 = new LinkedList();
388: path1.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
389: path1.addFirst(searchServer);
390: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
391: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path1);
392:
393: Properties p = (Properties) getMBeanServerConnection()
394: .getAttribute(on, "Vitals");
395: String url = p.getProperty("url");
396:
397: LinkedList path2 = new LinkedList();
398: path2.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
399: path2.addFirst(searchServer);
400: path2.addFirst("category");
401: on = AdminClientUtil.getResourceMBeanObjectName(
402: AdminClientUtil.SEARCH_CATEGORY_MBEAN_TYPE, path2);
403:
404: Object[] params = { url + "/search", searchText, "1000",
405: searchScope };
406: String[] signatures = { "java.lang.String",
407: "java.lang.String", "java.lang.String",
408: "java.lang.String" };
409: ArrayList data = (ArrayList) getMBeanServerConnection()
410: .invoke(on, "searchTaxTree", params, signatures);
411:
412: for (int index = 0; index < data.size(); index++) {
413: String nodeID = (String) data.get(index);
414:
415: CategoryBean cb = new CategoryBean();
416: cb.initialize(nodeID, hasChildren(nodeID));
417: al.add(cb);
418: }
419: } catch (Exception e) {
420: log(
421: Level.SEVERE,
422: "EditCommunityCategoriesPopupBean.retrieveSearchResults() : Exception ",
423: e);
424: }
425: searchResults = new ObjectListDataProvider(al);
426: searchResults.setObjectType(CategoryBean.class);
427: }
428:
429: }
|