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.IOException;
010: import java.io.File;
011: import java.util.logging.Level;
012: import java.util.logging.Logger;
013:
014: import com.sun.portal.search.admin.CSViewBeanBase;
015: import com.sun.portal.search.admin.model.SearchModel;
016: import com.sun.portal.search.admin.model.SearchModelImpl;
017:
018: import javax.servlet.ServletContext;
019: import javax.servlet.http.HttpServletRequest;
020: import javax.servlet.http.HttpServletResponse;
021:
022: import com.iplanet.jato.RequestContext;
023:
024: import com.iplanet.jato.view.event.DisplayEvent;
025: import com.iplanet.jato.view.event.ChildDisplayEvent;
026: import com.iplanet.jato.view.event.RequestInvocationEvent;
027:
028: import com.iplanet.jato.view.html.StaticTextField;
029: import com.iplanet.jato.view.html.TextField;
030: import com.iplanet.jato.view.html.CheckBox;
031: import com.iplanet.jato.view.html.Button;
032: import com.iplanet.jato.view.html.ComboBox;
033: import com.iplanet.jato.view.html.RadioButtonGroup;
034: import com.iplanet.jato.view.html.HiddenField;
035:
036: import com.iplanet.jato.view.html.Option;
037: import com.iplanet.jato.view.html.OptionList;
038:
039: import com.iplanet.jato.view.View;
040: import com.iplanet.jato.view.ViewBean;
041: import com.iplanet.jato.view.ViewBeanBase;
042:
043: import com.iplanet.jato.ViewBeanManager;
044:
045: import com.iplanet.jato.model.*;
046:
047: import com.iplanet.am.console.components.view.html.IPlanetButton;
048:
049: import com.sun.portal.search.autoclassify.*;
050: import com.sun.portal.search.admin.resources.SearchResource;
051: import com.sun.portal.log.common.PortalLogger;
052:
053: /**
054: * iPS admin console view bean: TODO
055: */
056: public class AutoclassifyViewBean extends CSViewBeanBase {
057: public static final String DEFAULT_DISPLAY_URL = "/ps/searchadmin/Autoclassify.jsp";
058: public static final String PAGE_NAME = "Autoclassify";
059: public static final String CACHESIZE_TEXT = "cachesize";
060: public static final String DBPATH_TEXT = "dbpath";
061: public static final String LOGPATH_TEXT = "logpath";
062: public static final String RUN_BUTTON = "RunButton";
063: public static final String SUBMIT_BUTTON = "SubmitButton";
064: public static final String RESET_BUTTON = "ResetButton";
065:
066: String ruleID = null;
067:
068: // Create a logger for this class
069: private static Logger debugLogger = PortalLogger
070: .getLogger(AutoclassifyViewBean.class);
071:
072: /**
073: * constructor
074: *
075: * @param PageName of this view bean
076: * @param displayURL default display URL
077: */
078: public AutoclassifyViewBean() {
079: super (PAGE_NAME);
080: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
081: registerChildren();
082: }
083:
084: /**
085: * register child component
086: */
087: protected void registerChildren() {
088: registerChild(CACHESIZE_TEXT, TextField.class);
089: registerChild(DBPATH_TEXT, TextField.class);
090: registerChild(LOGPATH_TEXT, TextField.class);
091: registerChild(RUN_BUTTON, IPlanetButton.class);
092: registerChild(SUBMIT_BUTTON, IPlanetButton.class);
093: registerChild(RESET_BUTTON, IPlanetButton.class);
094:
095: }
096:
097: /**
098: * create child component
099: *
100: * @param name of component
101: * @return child component
102: */
103: protected View createChild(String name) {
104:
105: View Headerchild = super .createChild(name);
106: if (Headerchild != null)
107: return Headerchild;
108: if (name.equals(CACHESIZE_TEXT)) {
109: return new TextField(this , CACHESIZE_TEXT, "");
110: }
111: if (name.equals(DBPATH_TEXT)) {
112: return new TextField(this , DBPATH_TEXT, "");
113: }
114: if (name.equals(LOGPATH_TEXT)) {
115: return new TextField(this , LOGPATH_TEXT, "");
116: }
117: if (name.equals(RUN_BUTTON)) {
118: return new IPlanetButton(this , RUN_BUTTON, "");
119: }
120: if (name.equals(SUBMIT_BUTTON)) {
121: return new IPlanetButton(this , SUBMIT_BUTTON, "");
122: }
123: if (name.equals(RESET_BUTTON)) {
124: return new IPlanetButton(this , RESET_BUTTON, "");
125: }
126: throw new IllegalArgumentException("Invalid child name ["
127: + name + "]");
128: }
129:
130: /** begin displaying page. we set the required information
131: *
132: * @param event display event
133: * @throws ModelControlException if problem access value of component
134: */
135: public void beginDisplay(DisplayEvent event) {
136: // Get request attributes and store them as Page Session Attributes
137: debugLogger.finer("PSSH_CSPSA0004");
138:
139: setPageEncoding();
140: setDisplayFieldValue(SUBMIT_BUTTON,
141: getLocalizedString("submit.text"));
142: setDisplayFieldValue(RESET_BUTTON,
143: getLocalizedString("reset.text"));
144: setDisplayFieldValue(RUN_BUTTON, getLocalizedString("run.text"));
145: SearchModel model = getSearchModel();
146: if (model != null) {
147: String value = model
148: .getStringValue(AutoclassifyConfig.NAME_LOGFILE);
149: if (value == null) {
150: value = CSConfig.getServerRoot() + File.separator
151: + "logs" + File.separator
152: + AutoclassifyConfig.DEFAULT_LOGFILE_NAME;
153: }
154: setDisplayFieldValue(LOGPATH_TEXT, value);
155: value = model
156: .getStringValue(AutoclassifyConfig.NAME_DBFILE);
157: if (value == null) {
158: value = CSConfig.getServerRoot() + File.separator
159: + "tmp" + File.separator
160: + AutoclassifyConfig.DEFAULT_DBFILE_NAME;
161: }
162: setDisplayFieldValue(this .DBPATH_TEXT, value);
163: value = model
164: .getStringValue(AutoclassifyConfig.NAME_HASHTABLE_SIZE);
165: if (value == null) {
166: value = Integer
167: .toString(AutoclassifyConfig.DEFAULT_HASHTABLE_SIZE);
168: }
169: setDisplayFieldValue(this .CACHESIZE_TEXT, value);
170:
171: }
172:
173: }
174:
175: public void handleResetButtonRequest(RequestInvocationEvent event)
176: throws ModelControlException {
177: this .infoMessage = this .getLocalizedString("text.reseted");
178: forwardTo();
179: }
180:
181: public void handleSubmitButtonRequest(RequestInvocationEvent event)
182: throws ModelControlException {
183: SearchModel model = getSearchModel();
184: boolean isChanged = false;
185: if (model != null) {
186: String value = model
187: .getStringValue(AutoclassifyConfig.NAME_LOGFILE);
188: String newValue = this
189: .getDisplayFieldStringValue(LOGPATH_TEXT);
190: if ((value == null && newValue.trim().length() >= 0)
191: || (value.compareTo(newValue) != 0)) {
192: model.setStringValue(AutoclassifyConfig.NAME_LOGFILE,
193: newValue);
194: isChanged = true;
195: }
196: value = model
197: .getStringValue(AutoclassifyConfig.NAME_DBFILE);
198: newValue = this .getDisplayFieldStringValue(DBPATH_TEXT);
199: if ((value == null && newValue.trim().length() >= 0)
200: || (value.compareTo(newValue) != 0)) {
201: model.setStringValue(AutoclassifyConfig.NAME_DBFILE,
202: newValue);
203: isChanged = true;
204: }
205:
206: value = model
207: .getStringValue(AutoclassifyConfig.NAME_HASHTABLE_SIZE);
208: newValue = this
209: .getDisplayFieldStringValue(this .CACHESIZE_TEXT);
210: if ((value == null && newValue.trim().length() >= 0)
211: || (value.compareTo(newValue) != 0)) {
212: model.setStringValue(
213: AutoclassifyConfig.NAME_HASHTABLE_SIZE,
214: newValue);
215: isChanged = true;
216: }
217: if (isChanged) {
218: model.store();
219: }
220: }
221: this .infoMessage = this .getLocalizedString("text.submitted");
222: forwardTo();
223:
224: }
225:
226: /**
227: *
228: *
229: */
230: public SearchModel getSearchModel() {
231: ServletContext sc = getRequestContext().getServletContext();
232: SearchModel scSearchModel = (SearchModel) sc
233: .getAttribute(SearchModel.MODEL_NAME);
234: if (scSearchModel == null) {
235: scSearchModel = new SearchModelImpl(getRequestContext()
236: .getRequest(),
237: CompassAdminConstants.RESOURCE_BUNDLE_FILE);
238: sc.setAttribute(SearchModel.MODEL_NAME, scSearchModel);
239: }
240: return scSearchModel;
241: }
242:
243: }
|