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:
012: import com.sun.portal.search.util.SearchConfig;
013:
014: import javax.servlet.http.HttpServletRequest;
015: import javax.servlet.http.HttpServletResponse;
016: import javax.servlet.jsp.JspWriter;
017: import com.iplanet.jato.RequestContext;
018:
019: import com.iplanet.jato.view.event.DisplayEvent;
020: import com.iplanet.jato.view.event.ChildDisplayEvent;
021: import com.iplanet.jato.view.event.JspChildDisplayEvent;
022: import com.iplanet.jato.view.event.RequestInvocationEvent;
023:
024: import com.iplanet.jato.view.html.StaticTextField;
025:
026: import com.iplanet.jato.view.View;
027: import com.iplanet.jato.view.ViewBean;
028: import com.iplanet.jato.view.ViewBeanBase;
029:
030: import com.iplanet.jato.ViewBeanManager;
031:
032: import com.iplanet.jato.model.*;
033: import com.sun.portal.search.admin.util.DBUtil;
034:
035: import com.iplanet.am.console.components.view.html.IPlanetButton;
036: import com.sun.portal.search.admin.cli.RobotController;
037:
038: public class RunDatabaseActionViewBean extends CSViewBeanBase {
039: public static final String DEFAULT_DISPLAY_URL = "/ps/searchadmin/RunDatabaseAction.jsp";
040: public static final String PAGE_NAME = "RunDatabaseAction";
041: public static final String CHILD_PROGRESS_TEXT = "ProgressText";
042: public static final String CHILD_CLOSEBUTTON = "CloseButton";
043: public static final String CHILD_ACTION_TEXT = "Action";
044:
045: private String action = null;
046:
047: /**
048: * constructor
049: *
050: * @param PageName of this view bean
051: * @param displayURL default display URL
052: */
053: public RunDatabaseActionViewBean() {
054: super (PAGE_NAME);
055: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
056: registerChildren();
057: }
058:
059: /**
060: * register child component
061: */
062: protected void registerChildren() {
063: registerChild(CHILD_PROGRESS_TEXT, StaticTextField.class);
064: registerChild(CHILD_CLOSEBUTTON, IPlanetButton.class);
065: registerChild(CHILD_ACTION_TEXT, StaticTextField.class);
066:
067: }
068:
069: /**
070: * create child component
071: *
072: * @param name of component
073: * @return child component
074: */
075: protected View createChild(String name) {
076: View Headerchild = super .createChild(name);
077: if (Headerchild != null)
078: return Headerchild;
079: if (name.equals(CHILD_PROGRESS_TEXT)) {
080: return new StaticTextField(this , CHILD_PROGRESS_TEXT, "");
081: }
082: if (name.equals(CHILD_ACTION_TEXT)) {
083: return new StaticTextField(this , CHILD_ACTION_TEXT, "");
084: }
085: if (name.equals(CHILD_CLOSEBUTTON)) {
086: return new IPlanetButton(this , CHILD_CLOSEBUTTON, "");
087: }
088: throw new IllegalArgumentException("Invalid child name ["
089: + name + "]");
090: }
091:
092: public void beginDisplay(DisplayEvent event) {
093: setPageEncoding();
094: action = getRequestContext().getRequest().getParameter(
095: DatabaseManageViewBean.PARAMETER_ACTION);
096: if (action != null) {
097: setDisplayFieldValue(CHILD_ACTION_TEXT,
098: getLocalizedString("db.action." + action));
099: }
100: setDisplayFieldValue(CHILD_CLOSEBUTTON,
101: getLocalizedString("close.text"));
102: }
103:
104: public boolean beginProgressTextDisplay(ChildDisplayEvent event)
105: throws IOException {
106: JspWriter out = ((JspChildDisplayEvent) event).getPageContext()
107: .getOut();
108: out.println("<pre>");
109: String dbs = getRequestContext().getRequest().getParameter(
110: DatabaseManageViewBean.PARAMETER_SELECTEDDBS);
111: if (dbs != null) {
112: StringTokenizer st = new StringTokenizer(dbs, ",");
113: while (st.hasMoreTokens()) {
114: String db = st.nextToken().trim();
115: if (db.length() > 0) {
116: if (action
117: .equals(DatabaseManageViewBean.ACTION_EXPIRE)) {
118: DBUtil.expireDatabase(CSConfig.getServerRoot(),
119: db, out);
120: } else if (action
121: .equals(DatabaseManageViewBean.ACTION_DELETE)) {
122: DBUtil.deleteDatabase(CSConfig.getServerRoot(),
123: db, out);
124: } else if (action
125: .equals(DatabaseManageViewBean.ACTION_PURGE)) {
126: //remove robot status only if purge default db
127: if (db.equals("default")) {
128: RobotController robotController = new RobotController(
129: CSConfig.getServerRoot(), CSConfig
130: .getBinPath(), CSConfig
131: .getLibDir(), CSConfig
132: .getLibPath(), null, null,
133: null);
134: robotController.remove_status_files();
135: }
136: DBUtil.purgeDatabase(CSConfig.getServerRoot(),
137: db, out);
138: } else if (action
139: .equals(DatabaseManageViewBean.ACTION_REINDEX)) {
140: DBUtil.reindexDatabase(
141: CSConfig.getServerRoot(), db, out);
142: }
143: }
144: }
145: }
146: return true;
147: }
148: }
|