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