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.*;
009: import java.util.*;
010: import java.util.logging.Logger;
011: import java.util.logging.Level;
012: import java.io.*;
013:
014: import javax.servlet.http.HttpServletRequest;
015: import javax.servlet.http.HttpServletResponse;
016:
017: import com.sun.portal.search.admin.CSViewBeanBase;
018:
019: import com.iplanet.jato.RequestContext;
020: import com.iplanet.jato.model.*;
021: import com.iplanet.jato.view.event.DisplayEvent;
022: import com.iplanet.jato.view.event.RequestInvocationEvent;
023:
024: import com.iplanet.jato.view.html.StaticTextField;
025: import com.iplanet.jato.view.html.TextField;
026: import com.iplanet.jato.view.html.CheckBox;
027: import com.iplanet.jato.view.html.Button;
028: import com.iplanet.jato.view.html.ComboBox;
029: import com.iplanet.jato.view.html.ListBox;
030: import com.iplanet.jato.view.html.HiddenField;
031:
032: import com.iplanet.jato.view.html.Option;
033: import com.iplanet.jato.view.html.OptionList;
034:
035: import com.iplanet.jato.view.View;
036: import com.iplanet.jato.view.ViewBean;
037: import com.iplanet.jato.view.ViewBeanBase;
038: import com.iplanet.jato.view.event.ChildDisplayEvent;
039:
040: import com.iplanet.jato.ViewBeanManager;
041:
042: import com.iplanet.jato.model.ModelControlException;
043: import com.iplanet.jato.util.Encoder;
044:
045: import com.iplanet.am.console.components.view.html.IPlanetButton;
046:
047: import com.iplanet.sso.SSOTokenManager;
048: import com.iplanet.sso.SSOToken;
049: import com.iplanet.sso.SSOException;
050: import com.iplanet.sso.SSOTokenID;
051:
052: import com.sun.portal.search.soif.SOIF;
053: import com.sun.portal.search.db.SToken;
054: import com.sun.portal.search.admin.util.DBUtil;
055: import com.sun.portal.log.common.PortalLogger;
056:
057: /**
058: * iPS admin console view bean: TODO
059: */
060: public class RDEditorViewBean extends CSViewBeanBase {
061: public static final String DEFAULT_DISPLAY_URL = "/ps/searchadmin/RDEditor.jsp";
062: public static final String PAGE_NAME = "RDEditor";
063: public static final String SEARCH_COMBO = "SearchBy";
064: public static final String SEARCH_DB_COMBO = "SearchDatabase";
065: public static final String SEARCH_TEXT = "SearchText";
066: public static final String SEARCHTEXT_LABEL = "SearchTextLabel";
067: public static final String SEARCH_BUTTON = "SearchButton";
068: public static final String SEARCHFOR_BUTTON = "BTNChangeSearchFor";
069: public static final String RESULT_SECTION = "ResultSection";
070: public static final String HITSNUM_TEXT = "HitsNum";
071: public static final String RD_SECTION = "RDSection";
072: public static final String HITS_VIEW = "HitsView";
073: public static final String DELETE_BUTTON = "DeleteButton";
074: public static final String NEXT_BUTTON = "NextButton";
075: public static final String PREV_BUTTON = "PrevButton";
076: public static final String ADDNEW_BUTTON = "AddNewButton";
077: public static final String HITSPERPAGE_TEXT = "HitsPerPage";
078: public static final String CURRPAGE_TEXT = "CurrPage";
079: public static final String TOTALPAGE_TEXT = "TotalPage";
080: public static final String BROWSER_VIEW = "TaxonomyBrowser";
081: public static final String TAXBROWSE_BUTTON = "TaxBrowser";
082: public static final String QUERY_TEXT = "QueryText";/*base64encoded of SEARCH_COMBO:SEARCH_TEXT*/
083: public static final String EDIT_ALL_TIMESTAMP = "editAllTimeStamp";
084: public static final String EDIT_SELECTED_TIMESTAMP = "editSelectedTimeStamp";
085: OptionList ops = null;
086: private SToken st = null;
087:
088: private int numOfHits = 0;
089: private static int hitsPerPage = 25;
090: private int currPage = 1;
091: private int totalPage = 1;
092: private int searchOption = 0;
093: private String editTimeStamp = null;
094:
095: // Create a Logger for this class
096: private static Logger debugLogger = PortalLogger
097: .getLogger(RDEditorViewBean.class);
098:
099: /**
100: * constructor
101: *
102: * @param PageName of this view bean
103: * @param displayURL default display URL
104: */
105: public RDEditorViewBean() {
106: super (PAGE_NAME);
107: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
108: registerChildren();
109:
110: }
111:
112: /**
113: * register child component
114: */
115: protected void registerChildren() {
116: registerChild(SEARCH_COMBO, ComboBox.class);
117: registerChild(SEARCH_DB_COMBO, ComboBox.class);
118: registerChild(SEARCH_TEXT, TextField.class);
119: registerChild(SEARCHTEXT_LABEL, StaticTextField.class);
120: registerChild(SEARCH_BUTTON, IPlanetButton.class);
121: registerChild(SEARCHFOR_BUTTON, IPlanetButton.class);
122: registerChild(HITSNUM_TEXT, StaticTextField.class);
123: registerChild(DELETE_BUTTON, IPlanetButton.class);
124: registerChild(HITS_VIEW, RDListView.class);
125: registerChild(NEXT_BUTTON, IPlanetButton.class);
126: registerChild(PREV_BUTTON, IPlanetButton.class);
127: registerChild(ADDNEW_BUTTON, IPlanetButton.class);
128: registerChild(CURRPAGE_TEXT, HiddenField.class);
129: registerChild(BROWSER_VIEW, TaxonomyBrowserView.class);
130: registerChild(TAXBROWSE_BUTTON, IPlanetButton.class);
131: registerChild(QUERY_TEXT, StaticTextField.class);
132: registerChild(EDIT_ALL_TIMESTAMP, StaticTextField.class);
133: registerChild(EDIT_SELECTED_TIMESTAMP, StaticTextField.class);
134: }
135:
136: OptionList getDBListOption() {
137: try {
138: String[] dbs = DBUtil.getDBStringArray(CSConfig
139: .getServerRoot());
140: return new OptionList(dbs, dbs);
141: } catch (Exception e) {
142: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
143: .getMessage());
144: }
145:
146: return new OptionList();
147:
148: }
149:
150: /**
151: * create child component
152: *
153: * @param name of component
154: * @return child component
155: */
156: protected View createChild(String name) {
157: View Headerchild = super .createChild(name);
158: if (Headerchild != null)
159: return Headerchild;
160: if (name.equals(SEARCH_COMBO)) {
161: ComboBox child = new ComboBox(this , SEARCH_COMBO, "");
162: OptionList SearchOptions = new OptionList(
163: getLocalizedStringArray(
164: "rd.search.option.listlabel", ","),
165: new String[] { "1", "2", "3", "4", "5", "6" }); // values
166: child.setOptions(SearchOptions);
167: return child;
168: }
169: if (name.equals(SEARCH_DB_COMBO)) {
170: ComboBox child = new ComboBox(this , SEARCH_DB_COMBO,
171: "default");
172: child.setOptions(getDBListOption());
173: return child;
174: }
175: if (name.equals(SEARCH_BUTTON)) {
176: return new IPlanetButton(this , SEARCH_BUTTON, "");
177: }
178: if (name.equals(SEARCHFOR_BUTTON)) {
179: return new IPlanetButton(this , SEARCHFOR_BUTTON, "");
180: }
181: if (name.equals(SEARCH_TEXT)) {
182: return new TextField(this , SEARCH_TEXT, "");
183: }
184: if (name.equals(SEARCHTEXT_LABEL)) {
185: return new StaticTextField(this , SEARCHTEXT_LABEL, "");
186: }
187: if (name.equals(QUERY_TEXT)) {
188: return new TextField(this , QUERY_TEXT, "");
189: }
190: if (name.equals(HITSNUM_TEXT)) {
191: return new StaticTextField(this , HITSNUM_TEXT, "0");
192: }
193: if (name.equals(TOTALPAGE_TEXT)) {
194: return new StaticTextField(this , TOTALPAGE_TEXT, "");
195: }
196: if (name.equals(CURRPAGE_TEXT)) {
197: return new StaticTextField(this , CURRPAGE_TEXT, "");
198: }
199: if (name.equals(DELETE_BUTTON)) {
200: return new IPlanetButton(this , DELETE_BUTTON, "");
201: }
202: if (name.equals(NEXT_BUTTON)) {
203: return new IPlanetButton(this , NEXT_BUTTON, "");
204: }
205: if (name.equals(PREV_BUTTON)) {
206: return new IPlanetButton(this , PREV_BUTTON, "");
207: }
208: if (name.equals(ADDNEW_BUTTON)) {
209: return new IPlanetButton(this , ADDNEW_BUTTON, "");
210: }
211: if (name.equals(HITS_VIEW)) {
212: return new RDListView(this , HITS_VIEW);
213: }
214: if (name.equals(CURRPAGE_TEXT)) {
215: return new HiddenField(this , CURRPAGE_TEXT, "1");
216: }
217: if (name.equals(BROWSER_VIEW)) {
218: return new TaxonomyBrowserView(this , BROWSER_VIEW);
219: }
220: if (name.equals(TAXBROWSE_BUTTON)) {
221: return new IPlanetButton(this , TAXBROWSE_BUTTON, "");
222: }
223: if (name.equals(EDIT_ALL_TIMESTAMP)) {
224: return new StaticTextField(this , EDIT_ALL_TIMESTAMP, "");
225: }
226: if (name.equals(EDIT_SELECTED_TIMESTAMP)) {
227: return new StaticTextField(this , EDIT_ALL_TIMESTAMP, "");
228: }
229: throw new IllegalArgumentException("Invalid child name ["
230: + name + "]");
231: }
232:
233: /** begin displaying page. we set the required information
234: *
235: * @param event display event
236: * @throws ModelControlException if problem access value of component
237: */
238: public void beginDisplay(DisplayEvent event) {
239: setPageEncoding();
240: if (beginBrowseSectionDisplay(null)) {
241: return;
242: }
243:
244: setDisplayFieldValue(SEARCH_BUTTON,
245: getLocalizedString("rd.search.button"));
246: setDisplayFieldValue(DELETE_BUTTON,
247: getLocalizedString("delete.text"));
248: setDisplayFieldValue(NEXT_BUTTON,
249: getLocalizedString("rd.next.text"));
250: setDisplayFieldValue(PREV_BUTTON,
251: getLocalizedString("rd.previous.text"));
252: setDisplayFieldValue(ADDNEW_BUTTON,
253: getLocalizedString("rd.addnew.text"));
254: setDisplayFieldValue(TAXBROWSE_BUTTON,
255: getLocalizedString("category.browser.launch"));
256:
257: editTimeStamp = (String) getPageSessionAttribute("editTimeStamp");
258: if (editTimeStamp == null) {
259: editTimeStamp = getRequestContext().getRequest()
260: .getParameter("editTimeStamp");
261: if (editTimeStamp != null) {
262: setPageSessionAttribute("editTimeStamp", editTimeStamp);
263: } else {
264: debugLogger.finer("PSSH_CSPSA0084");
265: }
266: }
267: String currDBStr = (String) getRequestContext().getRequest()
268: .getSession().getAttribute("database" + editTimeStamp);
269: if (currDBStr != null) {
270: setDisplayFieldValue(SEARCH_DB_COMBO, currDBStr);
271: }
272: String selText = (String) getRequestContext().getRequest()
273: .getSession().getAttribute(
274: TaxonomyBrowserView.SESION_ATTR_SELECTED_TAX
275: + editTimeStamp);
276: if (selText != null) {
277: getRequestContext()
278: .getRequest()
279: .getSession()
280: .removeAttribute(
281: TaxonomyBrowserView.SESION_ATTR_SELECTED_TAX
282: + editTimeStamp);
283: if (selText.trim().length() > 0) {
284: setDisplayFieldValue(SEARCH_TEXT, selText);
285: setDisplayFieldValue(SEARCH_COMBO, "4");
286: searchOption = 4;
287: }
288: } else {
289: String attSearchOption = (String) getPageSessionAttribute("searchOption");
290: if (attSearchOption != null) {
291: setDisplayFieldValue(SEARCH_COMBO, attSearchOption);
292: searchOption = getDisplayFieldIntValue(SEARCH_COMBO);
293: }
294: }
295: IPlanetButton browserBtn = (IPlanetButton) getChild(TAXBROWSE_BUTTON);
296: browserBtn.setEnable(searchOption == 4);
297: switch (searchOption) {
298: case 4:
299: setDisplayFieldValue(SEARCHTEXT_LABEL, this
300: .getLocalizedString("rd.searchtext.tax"));
301: break;
302: case 5:
303: setDisplayFieldValue(SEARCHTEXT_LABEL, this
304: .getLocalizedString("rd.searchtext.url"));
305: break;
306: case 6:
307: setDisplayFieldValue(SEARCHTEXT_LABEL, this
308: .getLocalizedString("rd.searchtext.text"));
309: break;
310: }
311: String queryString = (String) getPageSessionAttribute("queryString");
312: if (queryString != null) {
313: setDisplayFieldValue(SEARCH_TEXT, queryString);
314: }
315:
316: String currPageStr = (String) getPageSessionAttribute("currPage");
317: if (currPageStr != null) {
318: debugLogger.log(Level.FINER, "PSSH_CSPSA0085", currPageStr);
319: currPage = Integer.parseInt(currPageStr);
320: actionSearch();
321: setDisplayFieldValue(HITSNUM_TEXT, numOfHits);
322: setDisplayFieldValue(CURRPAGE_TEXT, currPage);
323: setDisplayFieldValue(TOTALPAGE_TEXT, totalPage);
324: }
325: /* setting the editTimeStamps.
326: the values is not as much important as they have to be distinct.
327: this timestamp, serves later as a HTTP session marker that enables
328: this was added to replace the use of jato pageSession which where
329: getting to big when certain large field like partial text are editable.
330: these time stamps enable distinguish if user is currently editing all
331: matching RDs or a subselection.
332: editing a single RD will also have a different timestamp set separatly
333: in the RDListView
334: */
335: long timeStamp = System.currentTimeMillis();
336: setDisplayFieldValue(EDIT_ALL_TIMESTAMP, Long
337: .toString(timeStamp));
338: setDisplayFieldValue(EDIT_SELECTED_TIMESTAMP, Long
339: .toString(timeStamp + 1));
340: }
341:
342: public boolean beginSearchTextDisplay(ChildDisplayEvent event) {
343: return (searchOption > 3);
344: }
345:
346: public boolean beginTaxBrowserDisplay(ChildDisplayEvent event) {
347: return (searchOption == 4);
348: }
349:
350: public boolean beginEditorSectionDisplay(ChildDisplayEvent event) {
351: String isBrowsing = (String) getPageSessionAttribute(TaxonomyBrowserView.SESION_ATTR_BROWSING_ON);
352: debugLogger.log(Level.FINER, "PSSH_CSPSA0071", isBrowsing);
353: return (isBrowsing == null || !isBrowsing
354: .equalsIgnoreCase("true"));
355: }
356:
357: public boolean beginBrowseSectionDisplay(ChildDisplayEvent event) {
358: String isBrowsing = (String) getPageSessionAttribute(TaxonomyBrowserView.SESION_ATTR_BROWSING_ON);
359: debugLogger.log(Level.FINER, "PSSH_CSPSA0071", isBrowsing);
360: return (isBrowsing != null && isBrowsing
361: .equalsIgnoreCase("true"));
362: }
363:
364: public boolean beginResultSectionDisplay(ChildDisplayEvent event) {
365: String currPage = (String) getPageSessionAttribute("currPage");
366: String batchMode = (String) getPageSessionAttribute("batchMode");
367: return (currPage != null);
368: }
369:
370: public boolean beginNoHitsSectionDisplay(ChildDisplayEvent event) {
371: return (numOfHits == 0);
372: }
373:
374: public boolean beginHitsSectionDisplay(ChildDisplayEvent event) {
375: return (numOfHits > 0);
376: }
377:
378: public boolean beginPageNavSectionDisplay(ChildDisplayEvent event) {
379: return (numOfHits > 25);
380: }
381:
382: public boolean beginPrevButtonSectionDisplay(ChildDisplayEvent event) {
383: return currPage > 1;
384: }
385:
386: public boolean beginNextButtonSectionDisplay(ChildDisplayEvent event) {
387: debugLogger.log(Level.FINER, "PSSH_CSPSA0086",
388: new String[] { Integer.toString(totalPage),
389: Integer.toString(currPage) });
390: return (totalPage > currPage);
391: }
392:
393: /*
394: public boolean beginAddNewButtonSectionDisplay(ChildDisplayEvent event) {
395: CSDebug.logln("total page=" + totalPage +" currPage=" + currPage);
396: return (totalPage > currPage );
397: }
398: */
399:
400: public void handleBTNChangeSearchForRequest(
401: RequestInvocationEvent event) {
402: String editTimeStamp = (String) getPageSessionAttribute("editTimeStamp");
403: searchOption = getDisplayFieldIntValue(SEARCH_COMBO);
404: removePageSessionAttribute("currPage");
405: removePageSessionAttribute("searchOption");
406: removePageSessionAttribute("queryString");
407: removePageSessionAttribute("database" + editTimeStamp);
408: this .forwardTo();
409: }
410:
411: /*
412: * Request event handler methods - for button and HREF fields
413: *
414: */
415: public void handleSearchButtonRequest(RequestInvocationEvent event) {
416: this .setPageSessionAttribute("currPage", "1");
417: int searchOption = getDisplayFieldIntValue(SEARCH_COMBO);
418: String queryString = getDisplayFieldStringValue(SEARCH_TEXT)
419: .trim();
420: String database = getDisplayFieldStringValue(SEARCH_DB_COMBO);
421: if (database != null) {
422: editTimeStamp = (String) getPageSessionAttribute("editTimeStamp");
423: getRequestContext().getRequest().getSession().setAttribute(
424: "database" + editTimeStamp, database);
425: }
426: setPageSessionAttribute("searchOption", Integer
427: .toString(searchOption));
428: setPageSessionAttribute("queryString", queryString);
429: this .forwardTo();
430: }
431:
432: private SToken getSToken() {
433: if (st == null) {
434: HttpServletRequest req = getRequestContext().getRequest();
435: try {
436: SSOTokenManager manager = SSOTokenManager.getInstance();
437: SSOToken token = null;
438: token = manager.createSSOToken(req);
439: st = new SToken((Object) token, true, true);
440: } catch (SSOException e) {
441: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
442: .getMessage());
443: // nothing, might be sso cookie is not there
444: }
445: }
446: return st;
447: }
448:
449: void actionSearch() {
450: int searchOption = getDisplayFieldIntValue(SEARCH_COMBO);
451: String queryString = getDisplayFieldStringValue(SEARCH_TEXT)
452: .trim();
453: String database = getDisplayFieldStringValue(SEARCH_DB_COMBO);
454: String queryText = searchOption + ":" + queryString;
455: try {
456: String base64queryText = URLEncoder.encode(Encoder
457: .encodeBase64(queryText.getBytes("utf-8")));
458: setDisplayFieldValue(this .QUERY_TEXT, base64queryText);
459: } catch (Exception e) {
460: }
461: debugLogger.log(Level.FINER, "PSSH_CSPSA0087", new String[] {
462: Integer.toString(searchOption), queryString });
463: String server_root = CSConfig.getServerRoot();
464:
465: // XXX try to init SearchServlet in order to use RDMUIBridge
466: HttpServletRequest req = getRequestContext().getRequest();
467: CSConfig.initSearch((req.isSecure() ? "https" : "http") + "://"
468: + req.getServerName() + ":" + req.getServerPort()
469: + req.getContextPath() + "/search");
470: RDListView hitsView = (RDListView) getChild(this .HITS_VIEW);
471: numOfHits = hitsView.doSearch(database, hitsPerPage, currPage,
472: queryString, searchOption, getSToken());
473: totalPage = numOfHits / hitsPerPage;
474: if (totalPage * hitsPerPage < numOfHits) {
475: totalPage++;
476: }
477: if (currPage > totalPage) {
478: currPage = totalPage;
479: }
480:
481: }
482:
483: public void handleDeleteButtonRequest(RequestInvocationEvent event) {
484: RDListView child = (RDListView) getChild(HITS_VIEW);
485: editTimeStamp = (String) getPageSessionAttribute("editTimeStamp");
486: String currDBStr = (String) getRequestContext().getRequest()
487: .getSession().getAttribute("database" + editTimeStamp);
488: if (currDBStr != null) {
489: child.setDatabase(currDBStr);
490: }
491: try {
492: ModelExecutionContext modExe = new ModelExecutionContextBase(
493: ModelExecutionContext.OPERATION_DELETE);
494: child.executeAutoDeletingModels(modExe);
495: } catch (ModelControlException e) {
496: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
497: .getMessage());
498: }
499: forwardTo();
500: }
501:
502: public void handleNextButtonRequest(RequestInvocationEvent event) {
503: String currPageStr = (String) getPageSessionAttribute("currPage");
504: currPage = Integer.parseInt(currPageStr) + 1;
505: setPageSessionAttribute("currPage", Integer.toString(currPage));
506: forwardTo();
507: }
508:
509: public void handlePrevButtonRequest(RequestInvocationEvent event) {
510: String currPageStr = (String) getPageSessionAttribute("currPage");
511: currPage = Integer.parseInt(currPageStr) - 1;
512: if (currPage < 1)
513: currPage = 1;
514: setPageSessionAttribute("currPage", Integer.toString(currPage));
515: forwardTo();
516: }
517:
518: public void handleAddNewButtonRequest(RequestInvocationEvent event) {
519: HttpServletResponse response = this .getRequestContext()
520: .getResponse();
521: try {
522: response.sendRedirect("RDAddNew");
523: } catch (IOException e) {
524: //TOFIX: handle this
525: }
526: }
527:
528: public void handleTaxBrowserRequest(RequestInvocationEvent event) {
529: removePageSessionAttribute("currPage");
530: removePageSessionAttribute("queryString");
531: setPageSessionAttribute(
532: TaxonomyBrowserView.SESION_ATTR_BROWSING_ON, "true");
533: editTimeStamp = (String) getPageSessionAttribute("editTimeStamp");
534: debugLogger.log(Level.FINER, "PSSH_CSPSA0082", editTimeStamp);
535: getRequestContext().getRequest().getSession().setAttribute(
536: TaxonomyBrowserView.SESION_ATTR_SELECTED_TAX
537: + editTimeStamp, "");
538: setPageSessionAttribute(TaxonomyBrowserView.CHILD_PAGE_HELP,
539: this .getLocalizedString("rd.search.browse.help"));
540: forwardTo();
541: }
542: }
|