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.ArrayList;
010: import java.io.IOException;
011:
012: import javax.servlet.*;
013: import javax.servlet.http.*;
014:
015: import com.iplanet.jato.RequestContext;
016: import com.iplanet.jato.RequestHandler;
017:
018: import com.iplanet.jato.view.event.DisplayEvent;
019: import com.iplanet.jato.view.event.ChildDisplayEvent;
020: import com.iplanet.jato.view.event.RequestInvocationEvent;
021:
022: import com.iplanet.jato.view.html.OptionList;
023: import com.iplanet.jato.view.html.Option;
024: import com.iplanet.jato.view.html.TextField;
025: import com.iplanet.jato.view.html.HREF;
026: import com.iplanet.jato.view.html.StaticTextField;
027: import com.iplanet.jato.view.html.HiddenField;
028: import com.iplanet.jato.view.html.ComboBox;
029: import com.iplanet.jato.view.html.CheckBox;
030:
031: import com.iplanet.jato.view.View;
032: import com.iplanet.jato.view.ViewBean;
033: import com.iplanet.jato.view.ViewBeanBase;
034:
035: import com.iplanet.jato.ViewBeanManager;
036:
037: import com.iplanet.jato.model.ModelControlException;
038:
039: import com.iplanet.am.console.components.view.html.IPlanetButton;
040: import com.iplanet.am.console.components.view.html.MessageBox;
041:
042: import com.sun.portal.search.admin.model.RobotClassRuleListModel;
043: import com.sun.portal.search.admin.TaxonomyBrowserView;
044:
045: /**
046: * Schema Editor Wizard for editing database schema
047: * It extends from <code>CSViewBeanBase</code>.
048: */
049:
050: public class RobotClassRuleEditorViewBean extends CSViewBeanBase
051: implements RequestHandler {
052:
053: // The "logical" name for this page.
054: public static final String PAGE_NAME = "RobotClassRuleEditor";
055: public static final String DEFAULT_DISPLAY_URL = "/ps/searchadmin/RobotClassRuleEditor.jsp";
056:
057: public static final String INDEX_TEXT = "Index";
058: public static final String SRC_COMBO = "Src";
059: public static final String METHOD_COMBO = "Method";
060: public static final String CRITERIA_TEXT = "Criteria";
061: public static final String CASE_CHECKBOX = "Case";
062: public static final String CLASSIFICATION_TEXT = "Classification";
063: public static final String BTN_BROWSE = "Browse";
064:
065: public static final String BTN_SUBMIT = "Submit";
066: public static final String BTN_CANCEL = "Cancel";
067: public static final String CHILD_ERROR_MSG_BOX = "errorMsgBox";
068:
069: public static final String BROWSER_VIEW = "TaxonomyBrowser";
070:
071: // Model
072:
073: /*
074: * Default constructor
075: *
076: */
077: public RobotClassRuleEditorViewBean() {
078: super (PAGE_NAME);
079: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
080: registerChildren();
081: }
082:
083: /**
084: * Child methods
085: */
086: protected void registerChildren() {
087: // Add an entry for each child. Note, the children are not instantiated
088: // at this time. Instead, child instantiation is handled in a lazy fashion.
089:
090: //registerChild(LST_SCHEMA,ListBox.class);
091: registerChild(SRC_COMBO, ComboBox.class);
092: registerChild(INDEX_TEXT, HiddenField.class);
093: registerChild(METHOD_COMBO, ComboBox.class);
094: registerChild(CRITERIA_TEXT, TextField.class);
095: registerChild(CASE_CHECKBOX, CheckBox.class);
096: registerChild(CLASSIFICATION_TEXT, TextField.class);
097: registerChild(BTN_BROWSE, IPlanetButton.class);
098: registerChild(BTN_SUBMIT, IPlanetButton.class);
099: registerChild(BTN_CANCEL, IPlanetButton.class);
100: registerChild(CHILD_ERROR_MSG_BOX, MessageBox.class);
101: registerChild(BROWSER_VIEW, TaxonomyBrowserView.class);
102: }
103:
104: protected View createChild(String name) {
105: // Create HeaderView Child
106: View child = super .createChild(name);
107: if (child != null) {
108: return child;
109: } else if (name.equals(BTN_SUBMIT)) {
110: return new IPlanetButton(this , BTN_SUBMIT, "");
111: } else if (name.equals(BTN_CANCEL)) {
112: return new IPlanetButton(this , BTN_CANCEL, "");
113: } else if (name.equals(SRC_COMBO)) {
114: return new ComboBox(this , SRC_COMBO, "");
115: } else if (name.equals(INDEX_TEXT)) {
116: return new HiddenField(this , INDEX_TEXT, "");
117: } else if (name.equals(METHOD_COMBO)) {
118: return new ComboBox(this , METHOD_COMBO, "");
119: } else if (name.equals(CRITERIA_TEXT)) {
120: return new TextField(this , CRITERIA_TEXT, "");
121: } else if (name.equals(CASE_CHECKBOX)) {
122: return new CheckBox(this , CASE_CHECKBOX, "true", "false",
123: true);
124: } else if (name.equals(CLASSIFICATION_TEXT)) {
125: return new TextField(this , CLASSIFICATION_TEXT, "");
126: } else if (name.equals(CHILD_ERROR_MSG_BOX)) {
127: return new MessageBox(this , CHILD_ERROR_MSG_BOX, "");
128: } else if (name.equals(BTN_BROWSE)) {
129: return new IPlanetButton(this , BTN_BROWSE, "");
130: } else if (name.equals(BROWSER_VIEW)) {
131: return new TaxonomyBrowserView(this , BROWSER_VIEW);
132: } else
133: throw new IllegalArgumentException("Invalid child name \""
134: + name + "\"");
135: }
136:
137: /*
138: * Begin displaying page. we set the required information
139: * set the individual display fields in the view bean
140: * @param event display event
141: * @throws ModelControlException if problem access value of component
142: **/
143: public void beginDisplay(DisplayEvent event)
144: throws ModelControlException {
145: setPageEncoding();
146: if (getPageSessionAttribute(TaxonomyBrowserView.SESION_ATTR_BROWSING_ON) != null) {
147: return;
148: }
149: setDisplayFieldValue(BTN_SUBMIT,
150: getLocalizedString("submit.text"));
151: setDisplayFieldValue(BTN_CANCEL,
152: getLocalizedString("cancel.text"));
153: setDisplayFieldValue(BTN_BROWSE,
154: getLocalizedString("category.browser.launch"));
155: setDisplayFieldValue(CASE_CHECKBOX, "true");
156: ComboBox child = (ComboBox) this .getChild(SRC_COMBO);
157: child.setOptions(RobotClassRuleListModel
158: .getSrcLst(getUserLocale()));
159: child = (ComboBox) this .getChild(METHOD_COMBO);
160: child.setOptions(RobotClassRuleListModel
161: .getMethodLst(getUserLocale()));
162:
163: /* restore values after browsing */
164: String Index = (String) getPageSessionAttribute("Index");
165: if (Index != null) {
166: setDisplayFieldValue(INDEX_TEXT, Index);
167: setDisplayFieldValue(SRC_COMBO,
168: (String) getPageSessionAttribute(SRC_COMBO));
169: setDisplayFieldValue(METHOD_COMBO,
170: (String) getPageSessionAttribute(METHOD_COMBO));
171: setDisplayFieldValue(CRITERIA_TEXT,
172: (String) getPageSessionAttribute(CRITERIA_TEXT));
173: setDisplayFieldValue(CASE_CHECKBOX,
174: (String) getPageSessionAttribute(CASE_CHECKBOX));
175: setDisplayFieldValue(
176: CLASSIFICATION_TEXT,
177: (String) getRequestContext()
178: .getRequest()
179: .getSession()
180: .getAttribute(
181: TaxonomyBrowserView.SESION_ATTR_SELECTED_TAX
182: + (String) getPageSessionAttribute("editTimeStamp")));
183: clearPageSessionAttributes();
184: } else {
185: Index = getRequestContext().getRequest().getParameter(
186: "Index");
187: if (Index != null) {
188: int ndx = Integer.parseInt(Index);
189: if (ndx >= 0) {
190: String server_root = CSConfig.getServerRoot();
191: CnConfig cnconfig = new CnConfig(server_root);
192: ArrayList rlist = cnconfig.getRulesList();
193: if (ndx < rlist.size()) {
194: Rule r = (Rule) rlist.get(ndx);
195: setDisplayFieldValue(INDEX_TEXT, ndx);
196: setDisplayFieldValue(SRC_COMBO, r.getSrc());
197: setDisplayFieldValue(METHOD_COMBO, r
198: .getMethod());
199: setDisplayFieldValue(CRITERIA_TEXT, r.getName());
200: setDisplayFieldValue(CASE_CHECKBOX, r
201: .isCaseSensitive() ? "true" : "false");
202: setDisplayFieldValue(CLASSIFICATION_TEXT, r
203: .getAction());
204: }
205: }
206: }
207: }
208:
209: }
210:
211: public boolean beginEditorSectionDisplay(ChildDisplayEvent event) {
212: String isBrowsing = (String) getPageSessionAttribute(TaxonomyBrowserView.SESION_ATTR_BROWSING_ON);
213: return (isBrowsing == null || !isBrowsing
214: .equalsIgnoreCase("true"));
215: }
216:
217: public boolean beginBrowseSectionDisplay(ChildDisplayEvent event) {
218: String isBrowsing = (String) getPageSessionAttribute(TaxonomyBrowserView.SESION_ATTR_BROWSING_ON);
219: return (isBrowsing != null && isBrowsing
220: .equalsIgnoreCase("true"));
221: }
222:
223: private void forwardToRobotClassRuleList() {
224: try {
225: HttpServletResponse response = getRequestContext()
226: .getResponse();
227: response.sendRedirect("RobotClassRuleList");
228: } catch (IOException e) {
229: //TOFIX: handle this
230: }
231: }
232:
233: private void setErrorMessage(String key) {
234: MessageBox errorMsgBox = (MessageBox) getChild(CHILD_ERROR_MSG_BOX);
235: errorMsgBox.setType(MessageBox.TYPE_ERROR);
236: errorMsgBox.setMessage(getLocalizedString(key));
237: errorMsgBox.setEnabled(true);
238: }
239:
240: /*
241: * handles invocation of Update Button
242: *
243: * @param event request invocation event
244: */
245: public void handleSubmitRequest(RequestInvocationEvent event) {
246:
247: String src = getDisplayFieldStringValue(SRC_COMBO);
248: String method = getDisplayFieldStringValue(METHOD_COMBO);
249: String critera = getDisplayFieldStringValue(CRITERIA_TEXT)
250: .trim();
251: boolean iscase = getDisplayFieldBooleanValue(CASE_CHECKBOX);
252: String taxonomy = getDisplayFieldStringValue(
253: CLASSIFICATION_TEXT).trim();
254:
255: if (src.length() == 0 || method.length() == 0
256: || critera.length() == 0 || taxonomy.length() == 0) {
257: setErrorMessage("classrules.error.emptyfield");
258: forwardTo();
259: } else if ((taxonomy.indexOf(';') != -1)
260: || (taxonomy.indexOf('<') != -1)
261: || (taxonomy.indexOf('>') != -1)
262: || (taxonomy.indexOf('"') != -1)
263: || (taxonomy.indexOf('\\') != -1)) {
264: setErrorMessage("classrules.error.invalid_tax");
265: forwardTo();
266: } else {
267:
268: String indexStr = getDisplayFieldStringValue(INDEX_TEXT);
269: String server_root = CSConfig.getServerRoot();
270: CnConfig cnconfig = new CnConfig(server_root);
271: try {
272: int ndx = Integer.parseInt(indexStr);
273: if (cnconfig.isExist(src, method, critera, taxonomy,
274: ndx)) {
275: setErrorMessage("classrules.error.duplicated");
276: forwardTo();
277: return;
278: }
279:
280: ArrayList rlist = cnconfig.getRulesList();
281: Rule r = (Rule) rlist.get(ndx);
282: r.setSrc(src);
283: r.setMethod(method);
284: r.setName(critera);
285: r.setAction(taxonomy);
286: r.setCaseSensitive(iscase);
287: } catch (NumberFormatException e) {
288: if (!cnconfig.add(src, method, critera, taxonomy,
289: iscase)) {
290: setErrorMessage("classrules.error.duplicated");
291: forwardTo();
292: return;
293: }
294: }
295: cnconfig.save();
296: forwardToRobotClassRuleList();
297: }
298: }
299:
300: public void handleCancelRequest(RequestInvocationEvent event) {
301: forwardToRobotClassRuleList();
302: }
303:
304: public void handleBrowseRequest(RequestInvocationEvent event)
305: throws ModelControlException {
306: /* push current values into page session*/
307: setPageSessionAttribute(SRC_COMBO,
308: getDisplayFieldStringValue(SRC_COMBO));
309: setPageSessionAttribute(METHOD_COMBO,
310: getDisplayFieldStringValue(METHOD_COMBO));
311: setPageSessionAttribute(CRITERIA_TEXT,
312: getDisplayFieldStringValue(CRITERIA_TEXT));
313: setPageSessionAttribute(CASE_CHECKBOX,
314: getDisplayFieldStringValue(CASE_CHECKBOX));
315: setPageSessionAttribute(INDEX_TEXT,
316: getDisplayFieldStringValue(INDEX_TEXT));
317:
318: setPageSessionAttribute(
319: TaxonomyBrowserView.SESION_ATTR_BROWSING_ON, "true");
320: getRequestContext().getRequest().getSession().setAttribute(
321: TaxonomyBrowserView.SESION_ATTR_SELECTED_TAX
322: + getPageSessionAttribute("editTimeStamp"),
323: getDisplayFieldStringValue(CLASSIFICATION_TEXT));
324: setPageSessionAttribute(TaxonomyBrowserView.CHILD_PAGE_HELP,
325: this .getLocalizedString("classrules.browse.help"));
326: forwardTo();
327: }
328:
329: }
|