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.lang.*;
009: import java.util.logging.Logger;
010:
011: import javax.servlet.*;
012: import javax.servlet.http.*;
013:
014: import com.iplanet.jato.RequestContext;
015: import com.iplanet.jato.RequestHandler;
016:
017: import com.iplanet.jato.view.event.DisplayEvent;
018: import com.iplanet.jato.view.event.RequestInvocationEvent;
019:
020: import com.iplanet.jato.view.html.OptionList;
021: import com.iplanet.jato.view.html.Option;
022: import com.iplanet.jato.view.html.CheckBox;
023: import com.iplanet.jato.view.html.TextField;
024: import com.iplanet.jato.view.html.ListBox;
025: import com.iplanet.jato.view.html.StaticTextField;
026:
027: import com.iplanet.jato.view.View;
028: import com.iplanet.jato.view.ViewBean;
029: import com.iplanet.jato.view.ViewBeanBase;
030:
031: import com.iplanet.jato.ViewBeanManager;
032:
033: import com.iplanet.jato.model.ModelControlException;
034:
035: import com.iplanet.am.console.components.view.html.IPlanetButton;
036:
037: import com.sun.portal.search.admin.model.PurgeModel;
038: import com.sun.portal.search.util.SearchConfig;
039: import com.sun.portal.search.admin.cli.RobotController;
040: import com.sun.portal.log.common.PortalLogger;
041:
042: /**
043: */
044:
045: public class PurgeViewBean extends CSViewBeanBase implements
046: RequestHandler {
047:
048: // The "logical" name for this page.
049: public static final String PAGE_NAME = "Purge";
050: public static final String DEFAULT_DISPLAY_URL = "/ps/searchadmin/Purge.jsp";
051:
052: // String constants for child field names. This is simply good coding practice
053: // to minimize use of string literals.
054: public static final String CHK_PURGE = "purge";
055: public static final String BTN_OK = "ok";
056: public static final String STATUS1 = "status1";
057: public static final String STATUS2 = "status2";
058: public static final String STATUS3 = "status3";
059: public static final String STATUS4 = "status4";
060:
061: private PurgeModel model;
062:
063: // Create a Logger for this class
064: private static Logger debugLogger = PortalLogger
065: .getLogger(PurgeViewBean.class);
066:
067: /*
068: * Default constructor
069: *
070: */
071: public PurgeViewBean() {
072: super (PAGE_NAME);
073: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
074: registerChildren();
075: }
076:
077: /**
078: * Child methods
079: */
080: protected void registerChildren() {
081: // Add an entry for each child. Note, the children are not instantiated
082: // at this time. Instead, child instantiation is handled in a lazy fashion.
083:
084: registerChild(CHK_PURGE, CheckBox.class);
085: registerChild(BTN_OK, IPlanetButton.class);
086: registerChild(STATUS1, StaticTextField.class);
087: registerChild(STATUS2, StaticTextField.class);
088: registerChild(STATUS3, StaticTextField.class);
089: registerChild(STATUS4, StaticTextField.class);
090: }
091:
092: protected View createChild(String name) {
093: // Create HeaderView Child
094: View child = super .createChild(name);
095: if (child != null) {
096: return child;
097:
098: } else if (name.equals(BTN_OK)) {
099: return new IPlanetButton(this , BTN_OK, "");
100:
101: } else if (name.equals(CHK_PURGE)) {
102: return new CheckBox(this , CHK_PURGE, "true", "false", true);
103:
104: } else if (name.equals(STATUS1)) {
105: return new StaticTextField(this , STATUS1, "");
106:
107: } else if (name.equals(STATUS2)) {
108: return new StaticTextField(this , STATUS2, "");
109:
110: } else if (name.equals(STATUS3)) {
111: return new StaticTextField(this , STATUS3, "");
112:
113: } else if (name.equals(STATUS4)) {
114: return new StaticTextField(this , STATUS4, "");
115:
116: } else
117: throw new IllegalArgumentException("Invalid child name \""
118: + name + "\"");
119: }
120:
121: /*
122: * Begin displaying page. we set the required information
123: * @param event display event
124: * @throws ModelControlException if problem access value of component
125: **/
126: public void beginDisplay(DisplayEvent event)
127: throws ModelControlException {
128: setPageEncoding();
129: setDisplayFieldValue(BTN_OK, getLocalizedString("ok.text"));
130:
131: CheckBox c1 = (CheckBox) getChild(CHK_PURGE);
132: c1.setChecked(false);
133: }
134:
135: public boolean beginProgressDisplay() {
136: /*
137: if (model.getOutput().equals(""))
138: return false;
139: else
140: */
141: return true;
142: }
143:
144: public String endProgressDisplay() {
145: model = getModel();
146: return model.getOutput();
147: }
148:
149: /*
150: * Request event handler methods - for button and HREF fields
151: *
152: */
153: public void handleOkRequest(RequestInvocationEvent event)
154: throws ServletException {
155: model = getModel();
156:
157: if (!getDisplayFieldBooleanValue(CHK_PURGE)) {
158: forwardTo();
159: return;
160: }
161:
162: // Do a purge, display result status
163: // if (model.purgeDatabase("compass")) // XXX hardwired dbname
164: if (model.purgeDatabase(SearchConfig
165: .getValue(SearchConfig.DBNAME))) {// XXX hardwired dbname
166: setDisplayFieldValue(PurgeViewBean.STATUS1,
167: getLocalizedString("db.purge.success")); // XXX move text to jsp/props
168: RobotController robotController = new RobotController(
169: CSConfig.getServerRoot(), CSConfig.getBinPath(),
170: CSConfig.getLibDir(), CSConfig.getLibPath(), null,
171: null, null);
172: if (!robotController.remove_status_files()) {
173: setDisplayFieldValue(
174: PurgeViewBean.STATUS2,
175: getLocalizedString("db.purge.robotstatuswarning"));
176: }
177: } else
178: setDisplayFieldValue(PurgeViewBean.STATUS1,
179: getLocalizedString("db.purge.error"));
180:
181: forwardTo();
182: }
183:
184: /*
185: * handles invocation of Reset Button
186: *
187: * @param event request invocation event
188: */
189: public void handleResetRequest(RequestInvocationEvent event) {
190: forwardTo();
191: }
192:
193: protected synchronized PurgeModel getModel() {
194: if (model == null) {
195: debugLogger.finer("PSSH_CSPSA0069");
196: model = new PurgeModel();
197: }
198: return model;
199: }
200:
201: }
|