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:
019: import javax.faces.context.FacesContext;
020: import javax.servlet.http.HttpServletRequest;
021: import javax.management.*;
022:
023: import com.sun.web.ui.model.*;
024:
025: import com.sun.data.provider.*;
026: import com.sun.data.provider.impl.ObjectListDataProvider;
027:
028: import com.sun.cacao.agent.JmxClient;
029:
030: import com.sun.portal.admin.common.util.AdminClientUtil;
031: import com.sun.portal.admin.console.common.PSBaseBean;
032:
033: public class RobotReportsBean extends PSBaseBean {
034:
035: private String report = null;
036: private String text = null;
037:
038: public RobotReportsBean() {
039: report = "";
040: text = "";
041: }
042:
043: public boolean getShowAlert() {
044: try {
045: LinkedList path = new LinkedList();
046: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
047: path
048: .addFirst((String) getSessionAttribute("search.server.selected"));
049: path.addFirst("robot");
050: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
051: AdminClientUtil.SEARCH_ROBOT_MBEAN_TYPE, path);
052:
053: Object[] params = {};
054: String[] signatures = {};
055: Boolean result = (Boolean) getMBeanServerConnection()
056: .invoke(on, "isRobotRunning", params, signatures);
057: return (result.booleanValue()) ? false : true;
058: } catch (Exception e) {
059: log(Level.SEVERE,
060: "RobotReportsBean.getShowAlert() : Exception", e);
061: }
062: return true;
063: }
064:
065: public Option[] getAvailableReports() {
066: Option[] options = new Option[15];
067: options[0] = new Option("", getLocalizedString("search",
068: "search.general.select"));
069: options[1] = new Option("overview", getLocalizedString(
070: "search", "search.robotreports.overview"));
071: options[2] = new Option("version", getLocalizedString("search",
072: "search.robotreports.version"));
073: options[3] = new Option("configuration", getLocalizedString(
074: "search", "search.robotreports.configuration"));
075: options[4] = new Option("performance", getLocalizedString(
076: "search", "search.robotreports.performance"));
077: options[5] = new Option("databasestatus", getLocalizedString(
078: "search", "search.robotreports.database"));
079: options[6] = new Option("libnetstatus", getLocalizedString(
080: "search", "search.robotreports.libnet"));
081: options[7] = new Option("modulesstatus", getLocalizedString(
082: "search", "search.robotreports.modules"));
083: options[8] = new Option("dnscachedump", getLocalizedString(
084: "search", "search.robotreports.dnscachedump"));
085: options[9] = new Option("allserversfound", getLocalizedString(
086: "search", "search.robotreports.allserversfound"));
087: options[10] = new Option("rdmserverfound", getLocalizedString(
088: "search", "search.robotreports.rdmserverfound"));
089: options[11] = new Option("urlreadyforextraction",
090: getLocalizedString("search",
091: "search.robotreports.urlreadyforextraction"));
092: options[12] = new Option("urlreadyforindexing",
093: getLocalizedString("search",
094: "search.robotreports.urlreadyforindexing"));
095: options[13] = new Option("urlwaitingforfiltering",
096: getLocalizedString("search",
097: "search.robotreports.urlwaitingforfiltering"));
098: options[14] = new Option("urlwaitingforindexing",
099: getLocalizedString("search",
100: "search.robotreports.urlwaitingforindexing"));
101: return options;
102: }
103:
104: public String getReport() {
105: return report;
106: }
107:
108: public void setReport(String report) {
109: this .report = report;
110: }
111:
112: public String getReportText() {
113: return text;
114: }
115:
116: public boolean isShowing() {
117: if (report.equals("")) {
118: return false;
119: } else {
120: return true;
121: }
122: }
123:
124: public String show() {
125: try {
126: LinkedList path = new LinkedList();
127: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
128: path
129: .addFirst((String) getSessionAttribute("search.server.selected"));
130: path.addFirst("robot");
131: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
132: AdminClientUtil.SEARCH_ROBOT_MBEAN_TYPE, path);
133:
134: Object[] params = { report };
135: String[] signatures = { "java.lang.String" };
136: String result = (String) getMBeanServerConnection().invoke(
137: on, "getAdvanceReport", params, signatures);
138: text = swapL10NTokens(result.replaceAll(
139: "<HTML>\n<BODY>\n<pre>\n", "").replaceAll(
140: "</pre>\n\n</BODY></HTML>", "").replaceAll("\n",
141: "<br>"));
142: } catch (Exception e) {
143: log(Level.SEVERE, "RobotReportsBean.show() : Exception", e);
144: }
145: return null;
146: }
147:
148: private String swapL10NTokens(String src) {
149: String startTag = "<i18nkey>";
150: String endTag = "</i18nkey>";
151:
152: StringBuffer sb = new StringBuffer(src);
153:
154: boolean done = false;
155: while (!done) {
156: int index = sb.indexOf(startTag);
157: if (index == -1) {
158: done = true;
159: } else {
160: int startIndex = index + startTag.length();
161: int endIndex = sb.indexOf(endTag, index);
162: if (endIndex == -1) {
163: return src;
164: } else {
165: String key = sb.substring(startIndex, endIndex);
166: sb = sb.replace(index, endIndex + endTag.length(),
167: getLocalizedString("search", key));
168: }
169: }
170: }
171: return sb.toString();
172: }
173:
174: }
|