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.util.ArrayList;
009: import java.util.logging.Level;
010: import java.util.logging.Logger;
011:
012: import com.sun.portal.search.admin.model.SearchModel;
013: import com.sun.portal.search.admin.model.SearchModelImpl;
014: import com.sun.portal.log.common.PortalLogger;
015:
016: import javax.servlet.http.HttpServletRequest;
017: import javax.servlet.*;
018: import javax.servlet.http.*;
019:
020: import com.iplanet.jato.view.event.*;
021: import com.iplanet.jato.view.html.*;
022: import com.iplanet.jato.view.*;
023: import com.iplanet.jato.*;
024: import com.iplanet.jato.model.*;
025:
026: import com.iplanet.am.console.components.view.html.ParentagePath;
027: import com.iplanet.am.console.components.view.html.IPlanetButton;
028: import com.iplanet.am.console.components.view.html.MessageBox;
029:
030: /**
031: * iCS admin console view bean: TODO
032: */
033: public class AdvancedLogViewBean extends CSViewBeanBase {
034: public static final String DEFAULT_DISPLAY_URL = "/ps/searchadmin/AdvancedLog.jsp";
035: public static final String PAGE_NAME = "AdvancedLog";
036:
037: // list of Jato elements
038: public static final String ADVLOG_RDM_LOG_TEXT = "SearchRdmLogText";
039: public static final String ADVLOG_SEARCH_LOG_CHECKBOX = "SearchLogCheckbox";
040: public static final String ADVLOG_IDX_MAINT_LOG_TEXT = "IdxMainLogText";
041: public static final String ADVLOG_RD_MGR_LOG_TEXT = "RDManagerLogText";
042: public static final String ADVLOG_RDM_DBG_LOG_TEXT = "RDMDebugLogText";
043: public static final String ADVLOG_RDM_DBG_LEVEL_COMBOBOX = "RDMDebugLevelCombobox";
044: public static final String RESTART_WARNING = "RestartWarning";
045: public static final String ADVLOG_BUTTON_SUBMIT = "AdvLogButtonSubmit";
046: public static final String ADVLOG_BUTTON_RESET = "AdvLogButtonReset";
047: public static final String CHILD_ERROR_MSG_BOX = "errorMsgBox";
048: public static final String ERR_MSG = "ErrMsg";
049:
050: private ArrayList errors;
051:
052: // Create a logger for this class
053: private static Logger debugLogger = PortalLogger
054: .getLogger(AdvancedLogViewBean.class);
055:
056: /**
057: * constructor
058: *
059: * @param PageName of this view bean
060: * @param displayURL default display URL
061: */
062: public AdvancedLogViewBean() {
063: super (PAGE_NAME);
064: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
065: registerChildren();
066: }
067:
068: /**
069: * register child component
070: */
071: protected void registerChildren() {
072: registerChild(ADVLOG_RDM_LOG_TEXT, TextField.class);
073: registerChild(ADVLOG_SEARCH_LOG_CHECKBOX, CheckBox.class);
074: registerChild(ADVLOG_IDX_MAINT_LOG_TEXT, TextField.class);
075: registerChild(ADVLOG_RD_MGR_LOG_TEXT, TextField.class);
076: registerChild(ADVLOG_RDM_DBG_LOG_TEXT, TextField.class);
077: registerChild(ADVLOG_RDM_DBG_LEVEL_COMBOBOX, ComboBox.class);
078: registerChild(RESTART_WARNING, MessageBox.class);
079: registerChild(CHILD_ERROR_MSG_BOX, MessageBox.class);
080: registerChild(ADVLOG_BUTTON_SUBMIT, IPlanetButton.class);
081: registerChild(ADVLOG_BUTTON_RESET, IPlanetButton.class);
082: }
083:
084: /**
085: * create child component
086: *
087: * @param name of component
088: * @return child component
089: */
090: protected View createChild(String name) {
091: View child = super .createChild(name);
092: if (child != null)
093: return child;
094: if (name.equals(ADVLOG_RDM_LOG_TEXT)) {
095: return new TextField(this , ADVLOG_RDM_LOG_TEXT, "");
096: }
097: if (name.equals(ADVLOG_SEARCH_LOG_CHECKBOX)) {
098: return new CheckBox(this , ADVLOG_SEARCH_LOG_CHECKBOX,
099: "enabled", "disabled", true);
100:
101: }
102: if (name.equals(ADVLOG_IDX_MAINT_LOG_TEXT)) {
103: return new TextField(this , ADVLOG_IDX_MAINT_LOG_TEXT, "");
104: }
105: if (name.equals(ADVLOG_RD_MGR_LOG_TEXT)) {
106: return new TextField(this , ADVLOG_RD_MGR_LOG_TEXT, "");
107: }
108: if (name.equals(ADVLOG_RDM_DBG_LOG_TEXT)) {
109: return new TextField(this , ADVLOG_RDM_DBG_LOG_TEXT, "");
110: }
111: if (name.equals(ADVLOG_RDM_DBG_LEVEL_COMBOBOX)) {
112: ComboBox combobox = new ComboBox(this ,
113: ADVLOG_RDM_DBG_LEVEL_COMBOBOX, "");
114: OptionList debugOptions = new OptionList(
115: getLocalizedStringArray("advancedLog.level.label",
116: ","), new String[] { "1", "2", "10", "20",
117: "50", "100", "999" });
118: combobox.setOptions(debugOptions);
119: return combobox;
120: }
121: if (name.equals(RESTART_WARNING)) {
122: child = new MessageBox(this , RESTART_WARNING, "");
123: if (child != null) {
124: ((MessageBox) child).setEnabled(getSearchModel()
125: .needSrvRestart());
126: ((MessageBox) child).setType(MessageBox.TYPE_WARNING);
127: ((MessageBox) child)
128: .setMessage(getLocalizedString("server.restart_warning"));
129: }
130: return child;
131: }
132: if (name.equals(CHILD_ERROR_MSG_BOX)) {
133: child = new MessageBox(this , CHILD_ERROR_MSG_BOX, "");
134: return child;
135: }
136: if (name.equals(ADVLOG_BUTTON_SUBMIT)) {
137: return new IPlanetButton(this , ADVLOG_BUTTON_SUBMIT,
138: getLocalizedString("advancedLog.submit"));
139: }
140: if (name.equals(ADVLOG_BUTTON_RESET)) {
141: return new IPlanetButton(this , ADVLOG_BUTTON_RESET,
142: getLocalizedString("advancedLog.reset"));
143: }
144: debugLogger.log(Level.INFO, "PSSH_CSPSA0002", name);
145: throw new IllegalArgumentException("Invalid child name ["
146: + name + "]");
147: }
148:
149: /**
150: * Returns the model to be used for auto-retrieving. This means the
151: * model will automatically be executed via its retrieve() method
152: * when the tiled view begins display.
153: * @param modelType the auto-execution model type.
154: * @return an array of Model objects for the auto-execution.
155: */
156: public Model[] getWebActionModels(int modelType) {
157: Model[] result = null;
158:
159: switch (modelType) {
160: case MODEL_TYPE_RETRIEVE:
161: result = new Model[] { (Model) getSearchModel() };
162: break;
163:
164: default:
165: break;
166: }
167: return result;
168: }
169:
170: /** begin displaying page. we set the required information
171: *
172: * @param event display event
173: * @throws ModelControlException if problem access value of component
174: */
175: public void beginDisplay(DisplayEvent event) {
176: setPageEncoding();
177: setDisplayFieldValue(ADVLOG_BUTTON_SUBMIT,
178: getLocalizedString("advancedLog.submit"));
179: setDisplayFieldValue(ADVLOG_BUTTON_RESET,
180: getLocalizedString("advancedLog.reset"));
181:
182: // Get request attributes and store them as Page Session Attributes
183: RequestContext rc = getRequestContext();
184: HttpServletRequest req = rc.getRequest();
185:
186: // display Search RDM Log Path field
187: setDisplayFieldValue(ADVLOG_RDM_LOG_TEXT, getSearchModel()
188: .getSearchRDMLog());
189:
190: // set the Search Log status checkbox. (model should return a boolean
191: setDisplayFieldValue(ADVLOG_SEARCH_LOG_CHECKBOX,
192: getSearchModel().getSearchLogState());
193: CheckBox cb = (CheckBox) getChild(ADVLOG_SEARCH_LOG_CHECKBOX);
194: cb.setChecked(getSearchModel().getSearchLogState());
195:
196: // display Index Maintenance Log path field
197: setDisplayFieldValue(ADVLOG_IDX_MAINT_LOG_TEXT,
198: getSearchModel().getIndexMaintenanceLog());
199:
200: // display RD manager log
201: setDisplayFieldValue(ADVLOG_RD_MGR_LOG_TEXT, getSearchModel()
202: .getRdMgrLog());
203:
204: // display RDM Debug log
205: setDisplayFieldValue(ADVLOG_RDM_DBG_LOG_TEXT, getSearchModel()
206: .getRdmDebugLog());
207:
208: // display RDM Debug Level combobox
209: setDisplayFieldValue(ADVLOG_RDM_DBG_LEVEL_COMBOBOX,
210: getSearchModel().getRdmDebugLevel());
211:
212: // checking for error message
213: MessageBox errorMsgBox = (MessageBox) getChild(CHILD_ERROR_MSG_BOX);
214: String errMsgStr = getErrMsg();
215: if (errMsgStr != null) {
216: errorMsgBox.setType(MessageBox.TYPE_ERROR);
217: errorMsgBox.setMessage(errMsgStr);
218: errorMsgBox.setEnabled(true);
219: } else {
220: errorMsgBox.setEnabled(false);
221: }
222:
223: // clear errors, for next round.
224: errors = null;
225: removePageSessionAttribute(ERR_MSG);
226: }
227:
228: /*
229: * getting an error attribut set in request
230: */
231: public String getErrMsg() {
232: return (String) getPageSessionAttribute(ERR_MSG);
233: }
234:
235: /*
236: * setting an error attribute set in request
237: */
238: public void setErrMsg(String value) {
239: if (value != null) {
240: setPageSessionAttribute(ERR_MSG, value);
241: }
242: }
243:
244: /**
245: * handles the Submit button
246: * @param event request invocation event
247: * 1. persist the Model
248: * 2. forward to itself
249: */
250: public void handleAdvLogButtonSubmitRequest(
251: RequestInvocationEvent event) {
252: // 1. get input param from servlet request
253: update();
254: if (getErrMsg() == null) {
255: // 2. persist information
256: getSearchModel().store();
257: // 3. force reload of last saved
258: reset();
259: }
260: // 4. refresh page
261: forwardTo();
262: }
263:
264: /**
265: * handles the reset button
266: * @param event request invocation event
267: * 1. do nothing
268: * 2. refreshes the page
269: */
270: public void handleAdvLogButtonResetRequest(
271: RequestInvocationEvent event) {
272: forwardTo();
273: }
274:
275: /**
276: * handles the help button
277: * @param event request invocation event
278: * 1. forward to the help page
279: */
280: public void handleAdvLogButtonHelpRequest(
281: RequestInvocationEvent event) {
282:
283: // TODO - forward to the help page
284: forwardTo();
285: }
286:
287: private void update() {
288: // parse in user's input form
289: // server instance name
290: errors = new ArrayList();
291:
292: String searchRdmLog = getDisplayFieldStringValue(
293: AdvancedLogViewBean.ADVLOG_RDM_LOG_TEXT).trim();
294: try {
295: getSearchModel().setSearchRDMLog(searchRdmLog);
296: } catch (Exception e) {
297: errors.add(e.getMessage());
298: }
299:
300: boolean searchLogState = getDisplayFieldBooleanValue(AdvancedLogViewBean.ADVLOG_SEARCH_LOG_CHECKBOX);
301: getSearchModel().setSearchLogState(searchLogState);
302:
303: String idxMaintLog = getDisplayFieldStringValue(
304: AdvancedLogViewBean.ADVLOG_IDX_MAINT_LOG_TEXT).trim();
305: try {
306: getSearchModel().setIndexMaintenanceLog(idxMaintLog);
307: } catch (Exception e) {
308: errors.add(e.getMessage());
309: }
310:
311: String rdMgrLog = getDisplayFieldStringValue(
312: AdvancedLogViewBean.ADVLOG_RD_MGR_LOG_TEXT).trim();
313: try {
314: getSearchModel().setRdMgrLog(rdMgrLog);
315: } catch (Exception e) {
316: errors.add(e.getMessage());
317: }
318:
319: String rdmDbgLog = getDisplayFieldStringValue(
320: AdvancedLogViewBean.ADVLOG_RDM_DBG_LOG_TEXT).trim();
321: try {
322: getSearchModel().setRdmDebugLog(rdmDbgLog);
323: } catch (Exception e) {
324: errors.add(e.getMessage());
325: }
326:
327: String rdmDbgLevel = getDisplayFieldStringValue(
328: AdvancedLogViewBean.ADVLOG_RDM_DBG_LEVEL_COMBOBOX)
329: .trim();
330: getSearchModel().setRdmDebugLevel(rdmDbgLevel);
331:
332: // set the error message if any.
333: if (errors.size() != 0) {
334: StringBuffer sb = new StringBuffer();
335: sb.append("<UL>");
336: for (int i = 0; i < errors.size(); i++) {
337: sb.append("<LI>");
338: sb.append((String) errors.get(i));
339: sb.append("</LI>");
340: }
341: sb.append("</UL>");
342: setErrMsg(sb.toString());
343: }
344: }
345:
346: /**
347: * reset()
348: */
349: private void reset() {
350: // simply removing the Model from the context will for reloading of it
351: ServletContext sc = getRequestContext().getServletContext();
352: SearchModel scSearchModel = (SearchModel) sc
353: .getAttribute(SearchModel.MODEL_NAME);
354: if (scSearchModel != null) {
355: scSearchModel = null;
356: sc.removeAttribute(SearchModel.MODEL_NAME);
357: }
358: }
359:
360: /**
361: *
362: *
363: */
364: public SearchModel getSearchModel() {
365: ServletContext sc = getRequestContext().getServletContext();
366: SearchModel scSearchModel = (SearchModel) sc
367: .getAttribute(SearchModel.MODEL_NAME);
368: if (scSearchModel == null) {
369: scSearchModel = new SearchModelImpl(getRequestContext()
370: .getRequest(),
371: CompassAdminConstants.RESOURCE_BUNDLE_FILE);
372: sc.setAttribute(SearchModel.MODEL_NAME, scSearchModel);
373: }
374: return scSearchModel;
375: }
376: }
|