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.io.*;
017:
018: import javax.faces.context.FacesContext;
019: import javax.faces.el.ValueBinding;
020: import javax.servlet.http.HttpServletRequest;
021: import javax.management.*;
022:
023: import com.sun.web.ui.component.*;
024: import com.sun.web.ui.model.*;
025: import com.sun.web.ui.event.*;
026:
027: import com.sun.data.provider.*;
028: import com.sun.data.provider.impl.ObjectListDataProvider;
029:
030: import com.sun.cacao.agent.JmxClient;
031:
032: import com.sun.portal.admin.common.util.AdminClientUtil;
033: import com.sun.portal.admin.console.common.PSBaseBean;
034:
035: public class RunAutoclassifyBean extends PSBaseBean implements
036: WizardEventListener {
037:
038: public String database = "default";
039: public String result = "";
040:
041: public RunAutoclassifyBean() {
042: }
043:
044: public boolean handleEvent(WizardEvent event) {
045: int eventCode = event.getNavigationEvent();
046: if (eventCode == WizardEvent.FINISH) {
047: runAutoclassify();
048: } else if (eventCode == WizardEvent.CLOSE) {
049: database = "default";
050: result = "";
051: }
052: return true;
053: }
054:
055: public String getDatabase() {
056: return database;
057: }
058:
059: public void setDatabase(String database) {
060: this .database = database;
061: }
062:
063: public String getResult() {
064: return result;
065: }
066:
067: public void setResult(String result) {
068: this .result = result;
069: }
070:
071: public boolean isTransient() {
072: return false;
073: }
074:
075: public void setTransient(boolean flag) {
076: }
077:
078: public Object saveState(FacesContext context) {
079: return null;
080: }
081:
082: public void restoreState(FacesContext context, Object state) {
083: }
084:
085: private void runAutoclassify() {
086: FacesContext fc = FacesContext.getCurrentInstance();
087: HttpServletRequest request = (HttpServletRequest) fc
088: .getExternalContext().getRequest();
089: Locale locale = request.getLocale();
090: if (locale == null) {
091: locale = Locale.getDefault();
092: }
093:
094: StringBuffer sb = new StringBuffer();
095: try {
096: LinkedList path = new LinkedList();
097: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
098: path
099: .addFirst((String) getSessionAttribute("search.server.selected"));
100: path.addFirst("autoclassify");
101: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
102: AdminClientUtil.SEARCH_AUTOCLASSIFY_MBEAN_TYPE,
103: path);
104:
105: String output = "";
106:
107: String[] list = database.split(":");
108: if (list.length > 0) {
109: ArrayList al = new ArrayList();
110: for (int i = 0; i < list.length; i++) {
111: al.add(list[i]);
112: }
113: Object[] params = { al, locale.toString(), "" };
114: String[] signature = { "java.util.ArrayList",
115: "java.lang.String", "java.lang.String" };
116: output = (String) getMBeanServerConnection().invoke(on,
117: "runAutoclassify", params, signature);
118: } else {
119: Object[] params = { database, locale.toString(), "" };
120: String[] signature = { "java.lang.String",
121: "java.lang.String", "java.lang.String" };
122: output = (String) getMBeanServerConnection().invoke(on,
123: "runAutoclassify", params, signature);
124: }
125: if (output != null) {
126: StringTokenizer st = new StringTokenizer(output, "\n");
127: while (st.hasMoreTokens()) {
128: String message = st.nextToken();
129: sb.append(message + "<br><br>");
130: }
131: }
132: } catch (Exception e) {
133: log(
134: Level.SEVERE,
135: "RunAutoclassifyBean.runAutoclassify() : Exception ",
136: e);
137: }
138: result = sb.toString();
139: }
140:
141: }
|