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