001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.search.admin;
007:
008: import java.net.URL;
009: import java.io.*;
010: import java.text.DateFormat;
011: import java.util.Date;
012: import java.util.logging.Logger;
013: import java.util.logging.Level;
014:
015: import com.sun.portal.search.admin.CSViewBeanBase;
016: import com.sun.portal.search.util.DateParser;
017:
018: import javax.servlet.http.HttpServletRequest;
019: import javax.servlet.http.HttpServletResponse;
020:
021: import com.iplanet.jato.RequestContext;
022:
023: import com.iplanet.jato.view.event.DisplayEvent;
024: import com.iplanet.jato.view.event.ChildDisplayEvent;
025: import com.iplanet.jato.view.event.RequestInvocationEvent;
026:
027: import com.iplanet.jato.view.html.StaticTextField;
028: import com.iplanet.jato.view.html.ComboBox;
029: import com.iplanet.jato.view.html.HiddenField;
030:
031: import com.iplanet.jato.view.html.Option;
032: import com.iplanet.jato.view.html.OptionList;
033:
034: import com.iplanet.jato.view.View;
035: import com.iplanet.jato.view.ViewBean;
036: import com.iplanet.jato.view.ViewBeanBase;
037:
038: import com.iplanet.jato.ViewBeanManager;
039:
040: import com.iplanet.jato.model.*;
041:
042: import com.iplanet.am.console.components.view.html.IPlanetButton;
043:
044: import com.sun.portal.search.admin.cli.RobotController;
045: import com.sun.portal.log.common.PortalLogger;
046:
047: /**
048: * iPS admin console view bean: TODO
049: */
050: public class RobotAdvancedReportViewBean extends CSViewBeanBase {
051: public static final String DEFAULT_DISPLAY_URL = "/ps/searchadmin/RobotAdvancedReport.jsp";
052: public static final String PAGE_NAME = "RobotAdvancedReport";
053: public static final String REPORTS_LIST = "Reports";
054: public static final String REFRESH_BUTTON = "Refresh";
055: public static final String REPORT_TEXT = "ReportText";
056: public static final String ROBOT_RUNNING = "RobotRunning";
057: public static final String ROBOT_NOTRUNNING = "RobotNotRunning";
058:
059: public static String reportsLabels[] = { "Version",
060: "DNS Cache Dump", "Performance", "Servers Found - All",
061: "Servers Found - RDM", "Status - Current Configuration",
062: "Status - Database (internal)", "Status - Libnet",
063: "Status - Modules", "Status - Overview",
064: "URLs - ready for extraction", "URLs - ready for indexing",
065: "URLs - waiting for filtering (URL Pool)",
066: "URLs - waiting for indexing", "all reports" };
067: public static String reportsQuerys[] = { "query?fn=version",
068: "query?fn=dns-mapping", "query?fn=performance",
069: "query?fn=sites-status", "query?fn=rdm-server",
070: "query?fn=run-status", "query?fn=database",
071: "query?fn=libnet", "query?fn=status",
072: "query?fn=robot-states", "query?fn=enum-ready",
073: "query?fn=rdgen-ready", "query?fn=enum-pool",
074: "query?fn=rdgen-pool", "all" };
075:
076: RobotController rc = null;
077:
078: // Create a Logger for this class
079: private static Logger debugLogger = PortalLogger
080: .getLogger(RobotAdvancedReportViewBean.class);
081:
082: /**
083: * constructor
084: *
085: * @param PageName of this view bean
086: * @param displayURL default display URL
087: */
088: public RobotAdvancedReportViewBean() {
089: super (PAGE_NAME);
090: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
091: registerChildren();
092: rc = new RobotController(CSConfig.getServerRoot(), CSConfig
093: .getBinPath(), CSConfig.getLibDir(), CSConfig
094: .getLibPath(), null, null, null);
095: }
096:
097: /**
098: * register child component
099: */
100: protected void registerChildren() {
101: registerChild(REPORTS_LIST, ComboBox.class);
102: registerChild(REPORT_TEXT, StaticTextField.class);
103: registerChild(REFRESH_BUTTON, IPlanetButton.class);
104:
105: }
106:
107: /**
108: * create child component
109: *
110: * @param name of component
111: * @return child component
112: */
113: protected View createChild(String name) {
114: debugLogger.log(Level.FINER, "PSSH_CSPSA0044", name);
115: View Headerchild = super .createChild(name);
116: if (Headerchild != null)
117: return Headerchild;
118: if (name.equals(REPORTS_LIST)) {
119: ComboBox child = new ComboBox(this , REPORTS_LIST, "");
120: OptionList reportOptions = new OptionList(
121: getLocalizedStringArray("robot.adv.report.labels",
122: ","), reportsQuerys);
123: child.setOptions(reportOptions);
124: return child;
125: }
126:
127: if (name.equals(this .REPORT_TEXT)) {
128: return new StaticTextField(this , this .REPORT_TEXT, "");
129: }
130: if (name.equals(REFRESH_BUTTON)) {
131: return new IPlanetButton(this , REFRESH_BUTTON, "");
132: }
133: throw new IllegalArgumentException("Invalid child name ["
134: + name + "]");
135: }
136:
137: String getLocalizedContent(byte[] bytes) {
138: int tagStart;
139: int tagDateStart;
140: int tagEnd;
141: int tagDateEnd;
142: int currIndex = 0;
143: StringBuffer sb = new StringBuffer();
144: DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG,
145: DateFormat.LONG, getUserLocale());
146:
147: try {
148: String str = new String(bytes, "UTF-8");
149: tagStart = str.indexOf("<i18nkey>", currIndex);
150: tagDateStart = str.indexOf("<i18ndatetime>", currIndex);
151: while (tagStart >= 0 || tagDateStart >= 0) {
152: if ((tagStart >= 0 && tagDateStart < 0)
153: || (tagStart >= 0 && tagDateStart >= 0 && tagStart < tagDateStart)) {
154: sb.append(str.substring(currIndex, tagStart));
155: currIndex = tagStart + 9;
156: tagEnd = str.indexOf("</i18nkey>", currIndex);
157: if (tagEnd > 0) {
158: currIndex = tagEnd + 10;
159: String i18nKey = str.substring(tagStart + 9,
160: tagEnd);
161: if (i18nKey.equalsIgnoreCase("now")) {
162: sb.append(df.format(new Date()));
163: } else {
164: sb.append(this .getLocalizedString(i18nKey));
165: }
166: }
167: } else {
168: sb.append(str.substring(currIndex, tagDateStart));
169: currIndex = tagDateStart + 14;
170: tagDateEnd = str.indexOf("</i18ndatetime>",
171: currIndex);
172: if (tagDateEnd > 0) {
173: currIndex = tagDateEnd + 15;
174: String i18nDate = str.substring(
175: tagDateStart + 14, tagDateEnd);
176: try {
177: sb.append(df.format(DateParser
178: .parse(i18nDate)));
179: } catch (Exception e) {
180: debugLogger.log(Level.INFO,
181: "PSSH_CSPSA0101", new String[] {
182: i18nDate, e.getMessage() });
183: }
184: }
185: }
186: tagStart = str.indexOf("<i18nkey>", currIndex);
187: tagDateStart = str.indexOf("<i18ndatetime>", currIndex);
188: }
189: sb.append(str.substring(currIndex));
190:
191: return sb.toString();
192: } catch (Exception e) {
193: return "";
194: }
195: }
196:
197: String getContent(byte[] bytes) {
198: try {
199: String str = getLocalizedContent(bytes);
200: char[] r = str.toCharArray();
201: StringBuffer buffer = new StringBuffer();
202: if (r == null)
203: return null;
204: boolean inTag = false;
205: for (int i = 0; i < r.length; i++) {
206: if (inTag) {
207: if (r[i] == '>') {
208: inTag = false;
209: continue;
210: }
211: } else {
212: if (r[i] == '<') {
213: inTag = true;
214: continue;
215: }
216: buffer.append(r[i]);
217: }
218: }
219: return buffer.toString();
220: } catch (NullPointerException npe) {
221: return null;
222: }
223: /*
224: String str = new String(r);
225: int start= str.indexOf("<BODY>");
226: if (start > 0) {
227: int end = str.indexOf("</BODY>", start + 6);
228: if (end > 0 ) {
229: return str.substring(start + 6, end);
230: }
231: return str.substring(start + 6);
232: }
233: return str;*/
234: }
235:
236: /** begin displaying page. we set the required information
237: *
238: * @param event display event
239: * @throws ModelControlException if problem access value of component
240: */
241: public void beginDisplay(DisplayEvent event) {
242: setPageEncoding();
243: setDisplayFieldValue(REFRESH_BUTTON,
244: getLocalizedString("robot.adv.refresh"));
245:
246: // Get request attributes and store them as Page Session Attributes
247:
248: HttpServletRequest req = getRequestContext().getRequest();
249: String reportSelected = (String) req
250: .getParameter("reportSelected");
251: if (reportSelected == null) {
252: reportSelected = (String) getPageSessionAttribute("reportSelected");
253: }
254: if (reportSelected != null) {
255: setDisplayFieldValue(REPORTS_LIST, reportSelected);
256: debugLogger.log(Level.FINER, "PSSH_CSPSA0102",
257: reportSelected);
258: if (reportSelected.compareTo("all") != 0) {
259: byte[] r = rc.robotURLGet(reportSelected
260: + "&format=i18n");
261: this .setDisplayFieldValue(this .REPORT_TEXT, this
262: .getContent(r));
263: } else {
264: StringBuffer buffer = new StringBuffer();
265: for (int i = 0; i < reportsQuerys.length - 1; i++) {
266: byte[] r = rc.robotURLGet(reportsQuerys[i]
267: + "&format=i18n");
268: buffer.append(getContent(r));
269: }
270: setDisplayFieldValue(REPORT_TEXT, buffer.toString());
271: }
272: }
273:
274: }
275:
276: public boolean beginRobotRunningDisplay(ChildDisplayEvent event) {
277: return (rc.isRunning());
278: }
279:
280: public boolean beginRobotNotRunningDisplay(ChildDisplayEvent event) {
281: return (!rc.isRunning());
282: }
283:
284: public void handleRefreshRequest(RequestInvocationEvent event) {
285: this .setPageSessionAttribute("reportSelected",
286: getDisplayFieldStringValue(REPORTS_LIST));
287: forwardTo();
288: }
289:
290: }
|