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.util.StringTokenizer;
011: import java.util.logging.Logger;
012: import java.util.logging.Level;
013:
014: import com.sun.portal.search.util.SearchConfig;
015:
016: import javax.servlet.http.HttpServletRequest;
017: import javax.servlet.http.HttpServletResponse;
018: import javax.servlet.jsp.JspWriter;
019: import com.iplanet.jato.RequestContext;
020:
021: import com.iplanet.jato.view.event.DisplayEvent;
022: import com.iplanet.jato.view.event.ChildDisplayEvent;
023: import com.iplanet.jato.view.event.JspChildDisplayEvent;
024: import com.iplanet.jato.view.event.RequestInvocationEvent;
025:
026: import com.iplanet.jato.view.html.StaticTextField;
027:
028: import com.iplanet.jato.view.View;
029: import com.iplanet.jato.view.ViewBean;
030: import com.iplanet.jato.view.ViewBeanBase;
031:
032: import com.iplanet.jato.ViewBeanManager;
033:
034: import com.iplanet.jato.model.*;
035: import com.sun.portal.search.admin.util.DBUtil;
036:
037: import com.iplanet.am.console.components.view.html.IPlanetButton;
038: import com.sun.portal.search.admin.cli.RobotController;
039: import com.sun.portal.log.common.PortalLogger;
040:
041: public class RunAutoclassifyViewBean extends CSViewBeanBase {
042: public static final String DEFAULT_DISPLAY_URL = "/ps/searchadmin/RunAutoclassify.jsp";
043: public static final String PAGE_NAME = "RunAutoclassify";
044: public static final String CHILD_PROGRESS_TEXT = "ProgressText";
045: public static final String CHILD_CLOSEBUTTON = "CloseButton";
046: public static final String CHILD_ACTION_TEXT = "Action";
047:
048: private String action = null;
049:
050: // Create a Logger for this class
051: private static Logger debugLogger = PortalLogger
052: .getLogger(RunAutoclassifyViewBean.class);
053:
054: /**
055: * constructor
056: *
057: * @param PageName of this view bean
058: * @param displayURL default display URL
059: */
060: public RunAutoclassifyViewBean() {
061: super (PAGE_NAME);
062: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
063: registerChildren();
064: }
065:
066: /**
067: * register child component
068: */
069: protected void registerChildren() {
070: registerChild(CHILD_PROGRESS_TEXT, StaticTextField.class);
071: registerChild(CHILD_CLOSEBUTTON, IPlanetButton.class);
072: registerChild(CHILD_ACTION_TEXT, StaticTextField.class);
073:
074: }
075:
076: /**
077: * create child component
078: *
079: * @param name of component
080: * @return child component
081: */
082: protected View createChild(String name) {
083: View Headerchild = super .createChild(name);
084: if (Headerchild != null)
085: return Headerchild;
086: if (name.equals(CHILD_PROGRESS_TEXT)) {
087: return new StaticTextField(this , CHILD_PROGRESS_TEXT, "");
088: }
089: if (name.equals(CHILD_ACTION_TEXT)) {
090: return new StaticTextField(this , CHILD_ACTION_TEXT, "");
091: }
092: if (name.equals(CHILD_CLOSEBUTTON)) {
093: return new IPlanetButton(this , CHILD_CLOSEBUTTON, "");
094: }
095: throw new IllegalArgumentException("Invalid child name ["
096: + name + "]");
097: }
098:
099: public void beginDisplay(DisplayEvent event) {
100: setPageEncoding();
101: setDisplayFieldValue(CHILD_CLOSEBUTTON,
102: getLocalizedString("close.text"));
103: }
104:
105: public boolean beginProgressTextDisplay(ChildDisplayEvent event)
106: throws IOException {
107: JspWriter out = ((JspChildDisplayEvent) event).getPageContext()
108: .getOut();
109: out.println("<pre>");
110: String localStr = this .getUserLocale().toString();
111: HttpServletRequest req = getRequestContext().getRequest();
112: String serverURL = (req.isSecure() ? "https" : "http") + "://"
113: + req.getServerName() + ":" + req.getServerPort()
114: + req.getContextPath() + "/search";
115: String cmd = CSConfig.getServerRoot() + File.separator
116: + "run-cs-cli autoclassify -s " + serverURL + " -l "
117: + localStr;
118: String dbs = getRequestContext().getRequest().getParameter(
119: DatabaseManageViewBean.PARAMETER_SELECTEDDBS);
120: if (dbs != null) {
121: cmd = cmd + " -d " + dbs;
122: }
123: debugLogger.log(Level.FINER, "PSSH_CSPSA0105", cmd);
124: Runtime rt = Runtime.getRuntime();
125: try {
126: Process process = DBUtil.exec(cmd);
127: BufferedReader buf = new BufferedReader(
128: new InputStreamReader(process.getInputStream(),
129: "UTF-8"));
130: String outLine = null;
131: while ((outLine = buf.readLine()) != null) {
132: //CSDebug.logln("outLine=" + outLine);
133: if (out != null) {
134: out.println(outLine);
135: out.flush();
136: }
137: }
138: //process.waitFor() == 0;
139: } catch (Exception e) {
140: // XXX Not logging exceptions? XXX
141: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
142: .getMessage());
143: }
144: return true;
145: }
146: }
|