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.logging.Level;
011: import java.util.logging.Logger;
012:
013: import com.sun.portal.search.util.SearchConfig;
014: import com.sun.portal.log.common.PortalLogger;
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:
036: //import com.iplanet.am.console.components.view.html.ParentagePath;
037: import com.iplanet.am.console.components.view.html.IPlanetButton;
038:
039: //import com.sun.portal.search.admin.model.PropertiesModel;
040: //import com.sun.portal.search.admin.model.PropertiesModelImpl;
041:
042: /**
043: * iPS admin console view bean: TODO
044: */
045: public class RunExpireViewBean extends CSViewBeanBase {
046: public static final String DEFAULT_DISPLAY_URL = "/ps/searchadmin/RunExpire.jsp";
047: public static final String PAGE_NAME = "RunExpire";
048: public static final String PROGRESS_TEXT = "ProgressText";
049:
050: // Create a Logger for this class
051: private static Logger debugLogger = PortalLogger
052: .getLogger(RunExpireViewBean.class);
053:
054: /**
055: * constructor
056: *
057: * @param PageName of this view bean
058: * @param displayURL default display URL
059: */
060: public RunExpireViewBean() {
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(PROGRESS_TEXT, StaticTextField.class);
071:
072: }
073:
074: /**
075: * create child component
076: *
077: * @param name of component
078: * @return child component
079: */
080: protected View createChild(String name) {
081: View Headerchild = super .createChild(name);
082: if (Headerchild != null)
083: return Headerchild;
084: if (name.equals(PROGRESS_TEXT)) {
085: return new StaticTextField(this , PROGRESS_TEXT, "");
086: }
087: throw new IllegalArgumentException("Invalid child name ["
088: + name + "]");
089: }
090:
091: public void beginDisplay(DisplayEvent event) {
092: setPageEncoding();
093: }
094:
095: private boolean executeCli(String cmd, String[] env, JspWriter out) {
096: Runtime rt = Runtime.getRuntime();
097: try {
098: if (out != null) {
099: out.flush();
100: }
101: Process ps = rt.exec(cmd, env);
102: BufferedReader buf = new BufferedReader(
103: new InputStreamReader(ps.getInputStream()));
104: String outLine = null;
105: while ((outLine = buf.readLine()) != null) {
106: if (out != null) {
107: out.println(outLine);
108: out.flush();
109: }
110: }
111: // return ps.exitValue() == 0 ? true : false;
112: } catch (IOException e) {
113: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
114: .getMessage());
115: return false;
116: }
117: return true;
118: }
119:
120: public boolean beginProgressTextDisplay(ChildDisplayEvent event)
121: throws IOException {
122: String r_env[] = { CSConfig.getLibPath() };
123:
124: //RunExpireAgent runImp = new RunExpireAgent(null, null, null, null, null);
125: // This demonstates how to use the supplied display event to output
126: // directly to the JSP output stream
127: JspWriter out = ((JspChildDisplayEvent) event).getPageContext()
128: .getOut();
129: out.println("<pre>");
130:
131: debugLogger.finer("PSSH_CSPSA0106");
132:
133: String cmd;
134:
135: if (System.getProperty("os.name").startsWith("win")
136: || System.getProperty("os.name").startsWith("Win")
137: || System.getProperty("os.name").startsWith("WIN")) {
138: cmd = CSConfig.getServerRoot() + File.separator
139: + "run-cs-cli.bat rdmgr -p stdout -E";
140: } else {
141: cmd = CSConfig.getServerRoot() + File.separator
142: + "run-cs-cli rdmgr -p stdout -E";
143: }
144: debugLogger.log(Level.FINER, "PSSH_CSPSA0107", cmd);
145: executeCli(cmd, r_env, out);
146: return true;
147: }
148: }
|