001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions
006: * are met:
007: *
008: * - Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: *
011: * - Redistribution in binary form must reproduce the above copyright
012: * notice, this list of conditions and the following disclaimer in
013: * the documentation and/or other materials provided with the
014: * distribution.
015: *
016: * Neither the name of Sun Microsystems, Inc. or the names of
017: * contributors may be used to endorse or promote products derived
018: * from this software without specific prior written permission.
019: *
020: * This software is provided "AS IS," without a warranty of any
021: * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
022: * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
023: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
024: * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
025: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
026: * DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
027: * OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
028: * FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
029: * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
030: * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE SOFTWARE,
031: * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
032: *
033: * You acknowledge that Software is not designed, licensed or intended
034: * any nuclear facility.
035: */
036:
037: package com.sun.portal.search.providers.faces;
038:
039: import com.sun.web.ui.component.Hyperlink;
040: import java.util.*;
041: import java.text.SimpleDateFormat;
042: import com.sun.web.ui.model.Option;
043: import com.sun.web.ui.component.TabSet;
044: import com.sun.web.ui.component.PanelGroup;
045: import com.sun.web.ui.component.Tab;
046: import javax.faces.model.ArrayDataModel;
047: import javax.faces.context.FacesContext;
048: import java.util.logging.Level;
049: import java.util.logging.Logger;
050:
051: /**
052: * This is the main bean to use this search faces provider framework.
053: *
054: * It can be used as a managed session bean,
055: * the default navigation rules will need to be defined for
056: * NAVIGATION_SEARCH ="search";
057: * NAVIGATION_BROWSE ="browse";
058: * NAVIGATION_NAMEDSEARCH ="namedsearch";
059: *
060: * or a properties of a session managed bean which implements the searchActionListener interface.
061: */
062: public class SearchHandler {
063: /**
064: * Basic mode for the UI
065: */
066: static public final String BASIC_MODE = "basicSearch";
067: /**
068: * Advanced Mode for the UI
069: */
070: static public final String ADV_MODE = "advacedSearch";
071: /**
072: * The param name used for browse a given category.
073: */
074: static public final String BROWSEID_PARAMETER = "browseidParam";
075: private Option[] findOptions;
076: private Option[] containOptions;
077: private Option[] withinOptions;
078: private Option[] resultsOptions;
079: private ResourceBundle rb;
080: private String basicSearchText;
081: private String searchServerUrl;
082: private String categoryRoot = "ROOT";
083: private String findText;
084: private String findOption = "any";
085: private String titleText;
086: private String titleOption = "contains";
087: private String authorText;
088: private String authorOption = "contains";
089: private String withinOption = "anytime";
090: private String showResultsOption;
091: private String mode = BASIC_MODE;
092: private boolean searched = false;
093: private String sessionId;
094: private boolean withinCurrentCategory = false;
095: private boolean browseMode = false;
096:
097: private String viewOrder = null;
098: private static Logger logger = SearchLogger
099: .getLogger(SearchHandler.class);
100:
101: private boolean showSearchBox = true;
102: private String name;
103: private Locale userLocale = Locale.getDefault();
104: private String baseName = "com.sun.portal.search.providers.faces.bundle.SearchClient";
105:
106: private Category currentCategory;
107: private Category rootCategory;
108: private SearchDatabase currentSearchDatabase;
109: private int databaseIdIndex = 0;
110:
111: /**
112: * defaul outcome for a <B>search</B> action in the naviagtion.
113: */
114: public static final String NAVIGATION_SEARCH = "search";
115: /**
116: * defaul outcome for a <B>browse</B> action in the naviagtion.
117: */
118: public static final String NAVIGATION_BROWSE = "browse";
119: /**
120: * defaul outcome for a <B>named search</B> action in the naviagtion.
121: */
122: public static final String NAVIGATION_NAMEDSEARCH = "namedsearch";
123:
124: protected String getLocalizedMessage(String key) {
125: if (rb == null) {
126: rb = ResourceBundle.getBundle(baseName, userLocale);
127: }
128: if (rb != null) {
129: try {
130: return rb.getString(key);
131: } catch (Exception e) {
132: logger.log(Level.WARNING, "PSCPL_CSPACF00108", e);
133: }
134: }
135: return key;
136: }
137:
138: ArrayList availableDatabases = new ArrayList();
139: HashMap dbMaps = new HashMap();
140: TaxonomyDatabase taxonomyDb;
141: SearchActionListener actionListener;
142:
143: //ArrayDataModel databases;
144: /**
145: * Creates a new instance of Searchhandler.
146: */
147: public SearchHandler() {
148: }
149:
150: /**
151: * Creates a new instance of Searchhandler
152: * @param actionListener A bean indtance implemented actionListener interface to override the default navigation
153: *
154: * @param searchServerUrl Url for the search server
155: * @param userLocale override the default system locale
156: * @param baseName override the default baseName
157: */
158: public SearchHandler(SearchActionListener actionListener,
159: String searchServerUrl, Locale userLocale, String baseName) {
160: this .searchServerUrl = searchServerUrl;
161: this .actionListener = actionListener;
162: this .userLocale = userLocale;
163: this .baseName = baseName;
164: }
165:
166: public void setTaxonomyDatabase(TaxonomyDatabase db) {
167: taxonomyDb = db;
168: taxonomyDb.setUiId("taxonomy");
169: }
170:
171: public TaxonomyDatabase getTaxonomyDatabase() {
172: return taxonomyDb;
173: }
174:
175: public void addDatabase(SearchDatabase db) {
176: db.setUiId(Integer.toString(++databaseIdIndex));
177: availableDatabases.add(db);
178: dbMaps.put(db.displayName, db);
179: }
180:
181: public Option[] getFindOptions() {
182: if (this .findOptions == null) {
183: findOptions = new Option[4];
184: findOptions[0] = new Option("all",
185: getLocalizedMessage("find_all"));
186: findOptions[1] = new Option("any",
187: getLocalizedMessage("find_any"));
188: findOptions[2] = new Option("exact",
189: getLocalizedMessage("find_exact"));
190: findOptions[3] = new Option("passage",
191: getLocalizedMessage("find_passage"));
192: }
193: return findOptions;
194: }
195:
196: public Option[] getContainOptions() {
197: if (this .containOptions == null) {
198: containOptions = new Option[2];
199: containOptions[0] = new Option("contains",
200: getLocalizedMessage("opt_contain"));
201: containOptions[1] = new Option("notcontains",
202: getLocalizedMessage("opt_notcontain"));
203: }
204: return containOptions;
205: }
206:
207: public Option[] getWithinOptions() {
208: if (this .withinOptions == null) {
209: withinOptions = new Option[5];
210: withinOptions[0] = new Option("anytime",
211: getLocalizedMessage("opt_anytime"));
212: withinOptions[1] = new Option("7",
213: getLocalizedMessage("opt_lastweek"));
214: withinOptions[2] = new Option("30",
215: getLocalizedMessage("opt_lastmonth"));
216: withinOptions[3] = new Option("90",
217: getLocalizedMessage("opt_last3month"));
218: withinOptions[4] = new Option("365",
219: getLocalizedMessage("opt_lastyear"));
220: }
221: return withinOptions;
222: }
223:
224: public String getBasicSearchText() {
225: return basicSearchText;
226: }
227:
228: public void setBasicSearchText(String value) {
229: basicSearchText = value;
230: }
231:
232: public void setViewOrder(String value) {
233: viewOrder = value;
234: }
235:
236: public String getFindText() {
237: return findText;
238: }
239:
240: public void setFindText(String value) {
241: findText = value;
242: }
243:
244: public String getFindOption() {
245: return findOption;
246: }
247:
248: public void setFindOption(String value) {
249: findOption = value;
250: }
251:
252: public String getTitleOption() {
253: return this .titleOption;
254: }
255:
256: public void setTitleOption(String value) {
257: this .titleOption = value;
258: }
259:
260: public String getTitleText() {
261: return this .titleText;
262: }
263:
264: public void setTitleText(String value) {
265: this .titleText = value;
266: }
267:
268: public String getAuthorOption() {
269: return this .authorOption;
270: }
271:
272: public void setAuthorOption(String value) {
273: this .authorOption = value;
274: }
275:
276: public String getAuthorText() {
277: return this .authorText;
278: }
279:
280: public void setAuthorText(String value) {
281: this .authorText = value;
282: }
283:
284: public String getWithinOption() {
285: return this .withinOption;
286: }
287:
288: public void setWithinOption(String value) {
289: this .withinOption = value;
290: }
291:
292: public String getShowResultsOption() {
293: return this .showResultsOption;
294: }
295:
296: public void setShowResultsOption(String value) {
297: this .showResultsOption = value;
298: }
299:
300: String getFindQuery(String option, String q) {
301: if (q != null && q.trim().length() > 0) {
302: if (option.equals("all")) {
303: return "(" + q.trim() + ")";
304: } else if (option.equals("any")) {
305: return "(<or> " + q.trim() + ")";
306: } else if (option.equals("exact")) {
307: return "(<phrase> " + q.trim() + ")";
308: } else if (option.equals("passage")) {
309: return "(<pand> " + q.trim() + ")";
310: }
311: }
312: return null;
313:
314: }
315:
316: String getContainOptionQuery(String field, String option, String q) {
317: if (q != null && q.trim().length() > 0) {
318: if (option.equals("contains")) {
319: return "(" + field + " <contains> " + q.trim() + ")";
320: } else {
321: return "(<not> " + field + " <contains> " + q.trim()
322: + ")";
323: }
324: }
325: return null;
326: }
327:
328: String getWithinOptionQuery(String field, String option) {
329: if (option != null && option.trim().length() > 0
330: && !option.equals("anytime")) {
331: try {
332: long days = Long.parseLong(option);
333: Date date = new Date(new Date().getTime() - days * 24
334: * 60 * 60 * 1000);
335: String dateStr = new SimpleDateFormat("M/d/y H:m:s",
336: Locale.US).format(date);
337: return "(rd-last-changed" + "> \"" + dateStr + "\")";
338: } catch (Exception e) {
339: return null;
340: }
341:
342: }
343: return null;
344: }
345:
346: protected String constructAdvSearchQuery() {
347: String qry = null;
348: String q = getFindQuery(findOption, findText);
349: if (q != null) {
350: qry = q;
351: }
352: q = this .getContainOptionQuery("author", this .authorOption,
353: this .authorText);
354: if (q != null) {
355: qry = (qry != null) ? (qry + " <and> " + q) : q;
356: }
357: q = this .getContainOptionQuery("title", this .titleOption,
358: this .titleText);
359: if (q != null) {
360: qry = (qry != null) ? (qry + " <and> " + q) : q;
361: }
362: q = this .getWithinOptionQuery("rd-last-changed",
363: this .withinOption);
364: if (q != null) {
365: qry = (qry != null) ? (qry + " <and> " + q) : q;
366: }
367:
368: return qry;
369: }
370:
371: PanelGroup sdatabasesGP;
372:
373: public void setSearchableDatabasePanelGroup(PanelGroup v) {
374: sdatabasesGP = v;
375: }
376:
377: public PanelGroup getSearchableDatabasePanelGroup() {
378: if (sdatabasesGP == null) {
379: ArrayList dbs = new ArrayList();
380: sdatabasesGP = new PanelGroup();
381: //sdatabasesGP.setTransient(true);
382: for (int i = 0; i < this .availableDatabases.size(); i++) {
383: SearchDatabase db = (SearchDatabase) this .availableDatabases
384: .get(i);
385: if (this .currentSearchDatabase == null) {
386: currentSearchDatabase = db;
387: }
388: Hyperlink link = db.getTargetLink();
389: if (db.equals(currentSearchDatabase)) {
390: link.setStyleClass("targetedDatabase");
391: link.setDisabled(true);
392: } else {
393: link.setStyleClass("untargetedDatabase");
394: link.setDisabled(false);
395: }
396:
397: dbs.add(link);
398: }
399: Hyperlink link = taxonomyDb.getTargetLink();
400: if (taxonomyDb.equals(currentSearchDatabase)) {
401: link.setStyleClass("targetedDatabase");
402: link.setDisabled(true);
403: } else {
404: link.setStyleClass("untargetedDatabase");
405: link.setDisabled(false);
406: }
407:
408: dbs.add(link);
409: sdatabasesGP.getChildren().addAll(dbs);
410: }
411: return sdatabasesGP;
412:
413: }
414:
415: public String doTarget() {
416: String dbName;
417: FacesContext c = FacesContext.getCurrentInstance();
418: dbName = (String) c.getExternalContext()
419: .getRequestParameterMap().get("targetDb");
420: if (dbName != null) {
421: if (taxonomyDb.getUiId().equals(dbName)) {
422: this .currentSearchDatabase = taxonomyDb;
423: } else {
424: for (int i = 0; i < this .availableDatabases.size(); i++) {
425: SearchDatabase s = (SearchDatabase) availableDatabases
426: .get(i);
427: if (s.getUiId().equals(dbName)) {
428: this .currentSearchDatabase = s;
429: }
430: }
431: }
432: }
433: String previousScope = currentSearchDatabase.getScope();
434: if (basicSearchText != null && basicSearchText.length() > 0
435: && !basicSearchText.equals(previousScope)) {
436: currentSearchDatabase.reset();
437: currentSearchDatabase.setScope(basicSearchText);
438: } else {
439: basicSearchText = previousScope;
440: }
441:
442: this .syncSearchableUI();
443:
444: return "";
445: }
446:
447: public String doBrowseTarget() {
448: String dbUiId;
449: FacesContext c = FacesContext.getCurrentInstance();
450: dbUiId = (String) c.getExternalContext()
451: .getRequestParameterMap().get("targetDb");
452: if (dbUiId != null) {
453:
454: for (int i = 0; i < this .availableDatabases.size(); i++) {
455: SearchDatabase s = (SearchDatabase) availableDatabases
456: .get(i);
457: if (s.getUiId().equals(dbUiId)) {
458: this .currentSearchDatabase = s;
459: }
460: }
461: syncBrowsableUI();
462:
463: }
464:
465: return "";
466: }
467:
468: public ArrayDataModel getSearchableDatabases() {
469: Object[] os = new Object[availableDatabases.size() + 1];
470: os[0] = this .taxonomyDb;
471: for (int i = 0; i < availableDatabases.size(); i++) {
472: os[i + 1] = availableDatabases.get(i);
473: }
474: return new ArrayDataModel(os);
475: }
476:
477: public void setBrowsableDatabasePanelGroup(PanelGroup v) {
478: bdatabasesGP = v;
479: }
480:
481: PanelGroup bdatabasesGP;
482:
483: public PanelGroup getBrowsableDatabasePanelGroup() {
484: if (bdatabasesGP == null) {
485: ArrayList dbs = new ArrayList();
486: bdatabasesGP = new PanelGroup();
487: //sdatabasesGP.setTransient(true);
488: for (int i = 0; i < this .availableDatabases.size(); i++) {
489: SearchDatabase db = (SearchDatabase) this .availableDatabases
490: .get(i);
491: if (this .currentSearchDatabase == null) {
492: currentSearchDatabase = db;
493: }
494: Hyperlink link = db.getBrowseTargetLink();
495: if (db.equals(currentSearchDatabase)) {
496: link.setStyleClass("targetedDatabase");
497: link.setDisabled(true);
498: } else {
499: link.setStyleClass("untargetedDatabase");
500: link.setDisabled(false);
501: }
502:
503: dbs.add(link);
504: }
505:
506: bdatabasesGP.getChildren().addAll(dbs);
507: }
508: return bdatabasesGP;
509:
510: }
511:
512: public ArrayDataModel getBrowsableDatabases() {
513: return new ArrayDataModel(availableDatabases.toArray());
514: }
515:
516: TabSet searchableTabSet;
517:
518: public void setSearchableTabset(TabSet ts) {
519: if (ts != null) {
520: searchableTabSet = ts;
521: }
522: }
523:
524: public TabSet getSearchableTabset() {
525: if (searchableTabSet != null) {
526: return searchableTabSet;
527: }
528: searchableTabSet = new TabSet();
529: ArrayList tabs = new ArrayList();
530: for (int i = 0; i < availableDatabases.size(); i++) {
531: SearchDatabase s = (SearchDatabase) availableDatabases
532: .get(i);
533: Tab tabUI = s.getTabUI();
534: tabUI.setId("databaseTab_" + Integer.toString(i));
535: tabs.add(tabUI);
536: }
537: searchableTabSet.getChildren().addAll(tabs);
538: return searchableTabSet;
539: }
540:
541: public SearchDatabase getCurrentTabSearchDatabase() {
542: String selectTabid = searchableTabSet.getSelected();
543: //Tab tab = searchableTabSet.findChildTab(selectTabid);
544: //SearchDatabase.MyTab myTab = (SearchDatabase.MyTab)tab;
545: //currentTabDatabase = myTab.getMyDatabase();
546: currentSearchDatabase = (SearchDatabase) dbMaps
547: .get(selectTabid);
548: if (currentSearchDatabase == null) {
549: currentSearchDatabase = (SearchDatabase) this .availableDatabases
550: .get(0);
551: }
552: return currentSearchDatabase;
553: }
554:
555: public void setCurrentSearchDatabase(SearchDatabase db) {
556: currentSearchDatabase = db;
557: }
558:
559: public SearchDatabase getCurrentSearchDatabase() {
560: if (currentSearchDatabase == null) {
561: currentSearchDatabase = (SearchDatabase) this .availableDatabases
562: .get(0);
563: }
564: return currentSearchDatabase;
565: }
566:
567: public ArrayDataModel getSearchedDatabases() {
568: ArrayList dbs = new ArrayList();
569: if (this .taxonomyDb.isSelected()) {
570: dbs.add(taxonomyDb);
571: }
572: for (int i = 0; i < availableDatabases.size(); i++) {
573: SearchDatabase s = (SearchDatabase) availableDatabases
574: .get(i);
575: if (s.isSelected()) {
576: dbs.add(s);
577: }
578: }
579: return new ArrayDataModel(dbs.toArray());
580: }
581:
582: public ArrayDataModel getBrowsedDatabases() {
583: ArrayList dbs = new ArrayList();
584: for (int i = 0; i < availableDatabases.size(); i++) {
585: SearchDatabase s = (SearchDatabase) availableDatabases
586: .get(i);
587: if (s.isSelected()) {
588: dbs.add(s);
589: }
590: }
591: return new ArrayDataModel(dbs.toArray());
592: }
593:
594: public boolean getIsBasicMode() {
595: return mode.equals(BASIC_MODE);
596: }
597:
598: public boolean getSearched() {
599: return searched;
600: }
601:
602: public void setSearched(boolean value) {
603: searched = value;
604: }
605:
606: public String advSearch() {
607: mode = ADV_MODE;
608: searched = false;
609: if (actionListener != null) {
610: return this .actionListener.doSearch();
611: }
612: return NAVIGATION_SEARCH;
613: }
614:
615: public String basicSearch() {
616: mode = BASIC_MODE;
617: searched = false;
618: if (actionListener != null) {
619: return this .actionListener.doSearch();
620: }
621: return NAVIGATION_SEARCH;
622: }
623:
624: public String doNamedSearch() {
625: //taking parameters from <h:hyperlink> component
626: FacesContext c = FacesContext.getCurrentInstance();
627: String scope = (String) c.getExternalContext()
628: .getRequestParameterMap().get("scope");
629: String database = (String) c.getExternalContext()
630: .getRequestParameterMap().get("database");
631: String searchName = (String) c.getExternalContext()
632: .getRequestParameterMap().get("name");
633: ;
634: String type = (String) c.getExternalContext()
635: .getRequestParameterMap().get("type");
636: String viewOrder = (String) c.getExternalContext()
637: .getRequestParameterMap().get("vieworder");
638: String hidesearchbox = (String) c.getExternalContext()
639: .getRequestParameterMap().get("hidesearchbox");
640:
641: if (scope != null) {
642: if ("advance".equalsIgnoreCase(type)) {
643: //mode = ADV_MODE;
644: //setFindText(scope);
645: String withinDays = (String) c.getExternalContext()
646: .getRequestParameterMap().get("withindays");
647: if (withinDays != null) {
648: scope = scope
649: + " <and> "
650: + getWithinOptionQuery("rd-last-changed",
651: withinDays);
652: }
653: }
654: // setting the target database
655: for (int i = 0; i < this .availableDatabases.size(); i++) {
656: SearchDatabase sdb = (SearchDatabase) this .availableDatabases
657: .get(i);
658: if (sdb.getDisplayName().equalsIgnoreCase(database)) {
659: sdb.reset();
660: //sdb.setSelected(true);
661: sdb.setScope(scope);
662: this .setCurrentSearchDatabase(sdb);
663: if (viewOrder != null) {
664: sdb.setViewOrder(viewOrder);
665: }
666: }
667: /*else {
668: sdb.setSelected(false);
669: }*/
670: }
671: //this.taxonomyDb.setSelected(false);
672: setName(searchName);
673: }
674: if (actionListener != null) {
675: return this .actionListener.doNamedSearch();
676: }
677: return NAVIGATION_NAMEDSEARCH;
678: }
679:
680: public String doSearch() {
681: setName(""); // clear a previous named search
682: // checking if a search was request from a browse mode within current category.
683: // otherwise turn to a fresh search
684: if (browseMode && withinCurrentCategory) {
685: return doBrowse();
686: } else {
687: browseMode = false;
688: withinCurrentCategory = false;
689: }
690: searched = true;
691: if (mode.equals(BASIC_MODE) && this .taxonomyDb.isSelected()) {
692: taxonomyDb.reset();
693: taxonomyDb.setScope(basicSearchText);
694: }
695: for (int i = 0; i < this .availableDatabases.size(); i++) {
696: SearchDatabase s = (SearchDatabase) availableDatabases
697: .get(i);
698: s.reset();
699: //if (s.isSelected()) {
700:
701: if (mode.equals(BASIC_MODE)) {
702: s.setScope(basicSearchText);
703: } else if (mode.equals(ADV_MODE)) {
704: String scope = this .constructAdvSearchQuery();
705: s.setScope(scope);
706: }
707: //}
708: }
709: this .getCurrentSearchDatabase();
710: this .syncSearchableUI();
711:
712: if (actionListener != null) {
713: return this .actionListener.doSearch();
714: }
715: return NAVIGATION_SEARCH;
716:
717: }
718:
719: public boolean isShowSearchBox() {
720: return showSearchBox;
721: }
722:
723: public void setShowSearchBox(boolean showSearchBox) {
724: this .showSearchBox = showSearchBox;
725: }
726:
727: public String getName() {
728: return name;
729: }
730:
731: public void setName(String name) {
732: this .name = name;
733: }
734:
735: public String getSessionId() {
736: return sessionId;
737: }
738:
739: public void setSessionId(String id) {
740: sessionId = id;
741: }
742:
743: public String getCategoryRoot() {
744: return categoryRoot;
745: }
746:
747: public void setCategoryRoot(String categoryRoot) {
748: if (categoryRoot != null) {
749: this .categoryRoot = categoryRoot;
750: }
751: }
752:
753: public String getDoTargetMethod() {
754: if (this .actionListener != null) {
755: return actionListener.getSearchHandlerPath() + ".doTarget";
756: }
757: return "search.doTarget";
758: }
759:
760: public String getDoBrowseTargetMethod() {
761: if (this .actionListener != null) {
762: return actionListener.getSearchHandlerPath()
763: + ".doBrowseTarget";
764: }
765: return "search.doBrowseTarget";
766: }
767:
768: private void syncSearchableUI() {
769: PanelGroup ui = this .getSearchableDatabasePanelGroup();
770: List links = ui.getChildren();
771: for (int i = 0; i < links.size(); i++) {
772: Hyperlink link = (Hyperlink) links.get(i);
773: String id = link.getId();
774: if (id.equals(SearchDatabase.TARGET_SEARCH_ID_PREFIX
775: + currentSearchDatabase.getUiId())) {
776: link.setStyleClass("targetedDatabase");
777: link.setDisabled(true);
778: } else {
779: link.setStyleClass("untargetedDatabase");
780: link.setDisabled(false);
781: }
782:
783: }
784: }
785:
786: private void syncBrowsableUI() {
787: PanelGroup ui = getBrowsableDatabasePanelGroup();
788: List links = ui.getChildren();
789: for (int i = 0; i < links.size(); i++) {
790: Hyperlink link = (Hyperlink) links.get(i);
791: String id = link.getId();
792: if (id.equals(SearchDatabase.TARGET_BROWSE_ID_PREFIX
793: + currentSearchDatabase.getUiId())) {
794: link.setStyleClass("targetedDatabase");
795: link.setDisabled(true);
796: } else {
797: link.setStyleClass("untargetedDatabase");
798: link.setDisabled(false);
799: }
800:
801: }
802: }
803:
804: public String doBrowse() {
805: String category;
806: FacesContext c = FacesContext.getCurrentInstance();
807: category = (String) c.getExternalContext()
808: .getRequestParameterMap().get(BROWSEID_PARAMETER);
809: if (category != null) {
810: setCurrentCategoryId(category);
811: }
812: if (!this .browseMode) {
813: this .basicSearchText = "";
814: }
815:
816: for (int i = 0; i < this .availableDatabases.size(); i++) {
817: SearchDatabase s = (SearchDatabase) availableDatabases
818: .get(i);
819: s.reset();
820: if (s.isSelected()) {
821: s.setBrowsedCategory(getCurrentCategory().getId());
822: if (withinCurrentCategory && basicSearchText != null
823: && basicSearchText.length() > 0) {
824: s.setScope(basicSearchText);
825: }
826: }
827: this .searched = true;
828:
829: }
830: if (availableDatabases.size() > 0
831: && (currentSearchDatabase == null || currentSearchDatabase
832: .equals(taxonomyDb))) {
833: currentSearchDatabase = (SearchDatabase) availableDatabases
834: .get(0);
835: syncBrowsableUI();
836: }
837: browseMode = true;
838:
839: return actionListener.doBrowse();
840: }
841:
842: public String getBrowseMethod() {
843: return actionListener.getBrowseMethod() + ".doBrowse";
844: }
845:
846: public Category getCurrentCategory() {
847: if (currentCategory == null) {
848: currentCategory = getTopCategory();
849: }
850: return currentCategory;
851: }
852:
853: public void setCurrentCategory(Category currentCategory) {
854: this .currentCategory = currentCategory;
855: }
856:
857: public void setCurrentCategoryId(String id) {
858: if (id == null) {
859: id = getCategoryRoot();
860: }
861: currentCategory = new Category(this , getCategoryRoot(), id);
862: }
863:
864: public Category getTopCategory() {
865: if (rootCategory == null) {
866: rootCategory = new Category(this , getCategoryRoot(),
867: getCategoryRoot());
868: }
869: return rootCategory;
870: }
871:
872: public String getSearchServerUrl() {
873: return searchServerUrl;
874: }
875:
876: public void setSearchServerUrl(String searchServerUrl) {
877: this .searchServerUrl = searchServerUrl;
878: }
879:
880: public void reset() {
881: this .currentCategory = null;
882: this .searched = false;
883: this .mode = this .BASIC_MODE;
884: this .basicSearchText = "";
885: this .withinCurrentCategory = false;
886: }
887:
888: public boolean isWithinCurrentCategory() {
889: return withinCurrentCategory;
890: }
891:
892: public void setWithinCurrentCategory(boolean withinCurrentCategory) {
893: this .withinCurrentCategory = withinCurrentCategory;
894: }
895:
896: public boolean isBrowseMode() {
897: return browseMode;
898: }
899:
900: public void setBrowseMode(boolean browseMode) {
901: this.browseMode = browseMode;
902: }
903:
904: }
|