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.util.ArrayList;
010: import java.util.logging.Level;
011: import java.util.logging.Logger;
012:
013: import com.sun.portal.search.admin.CSViewBeanBase; //import com.sun.portal.search.admin.cli.RobotController;
014:
015: import javax.servlet.http.HttpServletRequest;
016:
017: import com.iplanet.jato.RequestContext;
018: import com.iplanet.jato.model.*;
019: import com.iplanet.jato.view.event.DisplayEvent;
020: import com.iplanet.jato.view.event.RequestInvocationEvent;
021:
022: import com.iplanet.jato.view.html.StaticTextField;
023: import com.iplanet.jato.view.html.TextField;
024: import com.iplanet.jato.view.html.CheckBox;
025: import com.iplanet.jato.view.html.Button;
026: import com.iplanet.jato.view.html.ComboBox;
027: import com.iplanet.jato.view.html.ListBox;
028: import com.iplanet.jato.view.html.RadioButtonGroup;
029:
030: import com.iplanet.jato.view.html.Option;
031: import com.iplanet.jato.view.html.OptionList;
032:
033: import com.iplanet.jato.view.View;
034: import com.iplanet.jato.view.ViewBean;
035: import com.iplanet.jato.view.ViewBeanBase;
036: import com.iplanet.jato.view.event.ChildDisplayEvent;
037:
038: import com.iplanet.jato.ViewBeanManager;
039:
040: import com.iplanet.jato.model.ModelControlException;
041: import com.iplanet.jato.util.Encoder;
042:
043: //import com.iplanet.am.console.components.view.html.ParentagePath;
044: import com.iplanet.am.console.components.view.html.IPlanetButton;
045:
046: import com.iplanet.sso.SSOTokenManager;
047: import com.iplanet.sso.SSOToken;
048: import com.iplanet.sso.SSOException;
049: import com.iplanet.sso.SSOTokenID;
050:
051: import com.sun.portal.search.soif.SOIF;
052: import com.sun.portal.search.db.SToken;
053: import com.sun.portal.search.admin.util.DBUtil;
054: import com.sun.portal.log.common.PortalLogger;
055:
056: /**
057: * PS admin console view bean
058: */
059: public class RDAddNewViewBean extends CSViewBeanBase {
060: public static final String DEFAULT_DISPLAY_URL = "/ps/searchadmin/RDAddNew.jsp";
061: public static final String PAGE_NAME = "RDAddNew";
062: public static final String RD_ADDVIEW = "RDAddView";
063: public static final String SUBMIT_BUTTON = "SubmitButton";
064: public static final String RESET_BUTTON = "ResetButton";
065: public static final String CANCEL_BUTTON = "CancelButton";
066: public static final String BROWSER_VIEW = "TaxonomyBrowser";
067: public static final String SEARCH_DB_COMBO = "SearchDatabase";
068:
069: private boolean isSingle = false;
070: private boolean isUpdated = false;
071:
072: // Create a Logger for this class
073: private static Logger debugLogger = PortalLogger
074: .getLogger(RDAddNewViewBean.class);
075:
076: /**
077: * constructor
078: *
079: * @param PageName of this view bean
080: * @param displayURL default display URL
081: */
082: public RDAddNewViewBean() {
083: super (PAGE_NAME);
084: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
085: registerChildren();
086:
087: }
088:
089: /**
090: * register child component
091: */
092: protected void registerChildren() {
093: registerChild(RD_ADDVIEW, RDAddView.class);
094: registerChild(SUBMIT_BUTTON, IPlanetButton.class);
095: registerChild(RESET_BUTTON, IPlanetButton.class);
096: registerChild(CANCEL_BUTTON, IPlanetButton.class);
097: registerChild(BROWSER_VIEW, TaxonomyBrowserView.class);
098: registerChild(SEARCH_DB_COMBO, ComboBox.class);
099:
100: }
101:
102: /**
103: * create child component
104: *
105: * @param name of component
106: * @return child component
107: */
108: protected View createChild(String name) {
109: View Headerchild = super .createChild(name);
110: if (Headerchild != null) {
111: return Headerchild;
112: }
113: if (name.equals(RD_ADDVIEW)) {
114: return new RDAddView(this , RD_ADDVIEW);
115: }
116: if (name.equals(SUBMIT_BUTTON)) {
117: IPlanetButton btn = new IPlanetButton(this , SUBMIT_BUTTON,
118: "");
119: btn.validate(true);
120: return btn;
121: }
122: if (name.equals(RESET_BUTTON)) {
123: return new IPlanetButton(this , RESET_BUTTON, "");
124: }
125: if (name.equals(CANCEL_BUTTON)) {
126: return new IPlanetButton(this , CANCEL_BUTTON, "");
127: }
128: if (name.equals(BROWSER_VIEW)) {
129: return new TaxonomyBrowserView(this , BROWSER_VIEW);
130: }
131: if (name.equals(SEARCH_DB_COMBO)) {
132: ComboBox child = new ComboBox(this , SEARCH_DB_COMBO,
133: "default");
134: child.setOptions(getDBListOption());
135: return child;
136: }
137: throw new IllegalArgumentException("Invalid child name ["
138: + name + "]");
139: }
140:
141: OptionList getDBListOption() {
142: try {
143: String[] dbs = DBUtil.getDBStringArray(CSConfig
144: .getServerRoot());
145: return new OptionList(dbs, dbs);
146: } catch (Exception e) {
147: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
148: .getMessage());
149: }
150:
151: return new OptionList();
152:
153: }
154:
155: public boolean beginEditorSectionDisplay(ChildDisplayEvent event) {
156: String isBrowsing = (String) getPageSessionAttribute(TaxonomyBrowserView.SESION_ATTR_BROWSING_ON);
157: debugLogger.log(Level.FINER, "PSSH_CSPSA0071", isBrowsing);
158: return (isBrowsing == null || !isBrowsing
159: .equalsIgnoreCase("true"))
160: && !beginBatchConfirmSectionDisplay(event);
161: }
162:
163: public boolean beginBrowseSectionDisplay(ChildDisplayEvent event) {
164: String isBrowsing = (String) getPageSessionAttribute(TaxonomyBrowserView.SESION_ATTR_BROWSING_ON);
165: debugLogger.log(Level.FINER, "PSSH_CSPSA0071", isBrowsing);
166: return (isBrowsing != null && isBrowsing
167: .equalsIgnoreCase("true"));
168: }
169:
170: public boolean beginBatchConfirmSectionDisplay(
171: ChildDisplayEvent event) {
172: return isUpdated && !isSingle;
173: }
174:
175: /** begin displaying page. we set the required information
176: *
177: * @param event display event
178: * @throws ModelControlException if problem access value of component
179: */
180: public void beginDisplay(DisplayEvent event) {
181: setPageEncoding();
182: if (getPageSessionAttribute(TaxonomyBrowserView.SESION_ATTR_BROWSING_ON) != null) {
183: return;
184: }
185:
186: String editTimeStamp = (String) getPageSessionAttribute("editTimeStamp");
187: String currDBStr = (String) getPageSessionAttribute("database"
188: + editTimeStamp);
189: if (currDBStr != null) {
190: setDisplayFieldValue(SEARCH_DB_COMBO, currDBStr);
191: }
192:
193: setDisplayFieldValue(SUBMIT_BUTTON,
194: getLocalizedString("submit.text"));
195: setDisplayFieldValue(RESET_BUTTON,
196: getLocalizedString("reset.text"));
197: setDisplayFieldValue(CANCEL_BUTTON,
198: getLocalizedString("cancel.text"));
199:
200: }
201:
202: /**
203: * handles invocation of view bean
204: *
205: * @param event request invocation event
206: */
207: public void handleResetButtonRequest(RequestInvocationEvent event) {
208: this .forwardTo();
209: }
210:
211: public void handleSubmitButtonRequest(RequestInvocationEvent event) {
212:
213: String editTimeStamp = (String) getPageSessionAttribute("editTimeStamp");
214: setPageSessionAttribute(
215: "database" + editTimeStamp,
216: (java.io.Serializable) getDisplayFieldValue(SEARCH_DB_COMBO));
217:
218: RDAddView rdaddview = (RDAddView) getChild(RD_ADDVIEW);
219: try {
220: rdaddview.addRD();
221: infoMessage = getLocalizedString("rd.update.success");
222: isUpdated = true;
223: } catch (Exception e) {
224: errorMessage = getLocalizedString("rd.update.error");
225: }
226:
227: RequestContext rc = getRequestContext();
228: ViewBeanManager mgr = rc.getViewBeanManager();
229: RDEditorViewBean target = (RDEditorViewBean) mgr
230: .getViewBean(com.sun.portal.search.admin.RDEditorViewBean.class);
231: target.forwardTo(rc);
232: }
233:
234: }
|