001: /**
002: * Copyright 2005 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */package com.sun.portal.admin.console.search;
013:
014: import java.util.*;
015: import java.util.logging.Level;
016: import java.lang.*;
017: import java.io.*;
018:
019: import javax.faces.context.FacesContext;
020: import javax.servlet.http.HttpServletRequest;
021: import javax.management.*;
022:
023: import com.sun.web.ui.model.*;
024: import com.sun.web.ui.component.*;
025:
026: import com.sun.data.provider.*;
027: import com.sun.data.provider.impl.ObjectListDataProvider;
028:
029: import com.sun.cacao.agent.JmxClient;
030:
031: import com.sun.portal.admin.common.util.AdminClientUtil;
032: import com.sun.portal.admin.console.common.PSBaseBean;
033:
034: public class PopularSearchesBean extends PSBaseBean {
035:
036: private ObjectListDataProvider popularSearches = null;
037: private String filter = null;
038:
039: public PopularSearchesBean() {
040: filter = "allitems";
041: retrievePopularSearches();
042: }
043:
044: public ObjectListDataProvider getPopularSearches() {
045: return popularSearches;
046: }
047:
048: public void setPopularSearches(
049: ObjectListDataProvider popularSearches) {
050: this .popularSearches = popularSearches;
051: }
052:
053: public Option[] getAvailableFilters() {
054: Option[] filterOptions = new Option[2];
055: filterOptions[0] = new Option("allitems", getLocalizedString(
056: "search", "search.popularsearches.filter.allitems"));
057: filterOptions[1] = new Option("excludebrowse",
058: getLocalizedString("search",
059: "search.popularsearches.filter.excludebrowse"));
060: return filterOptions;
061: }
062:
063: public String getFilter() {
064: return filter;
065: }
066:
067: public void setFilter(String filter) {
068: this .filter = filter;
069: }
070:
071: public void applyFilter() {
072: retrievePopularSearches();
073: }
074:
075: private void retrievePopularSearches() {
076: ArrayList al = new ArrayList();
077: try {
078: LinkedList path = new LinkedList();
079: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
080: path
081: .addFirst((String) getSessionAttribute("search.server.selected"));
082: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
083: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
084:
085: Object[] params = {
086: new Boolean(false),
087: new Boolean((filter.equals("excludebrowse")) ? true
088: : false) };
089: String[] signatures = { "java.lang.Boolean",
090: "java.lang.Boolean" };
091: ArrayList data = (ArrayList) getMBeanServerConnection()
092: .invoke(on, "getPopularSearch", params, signatures);
093:
094: ArrayList list = (ArrayList) data.get(2);
095: for (int index = 0; index < list.size(); index++) {
096: Properties p = (Properties) list.get(index);
097:
098: PopularSearchBean psb = new PopularSearchBean();
099: psb.initialize(p.getProperty("frequency"), p
100: .getProperty("scope"));
101: al.add(psb);
102: }
103: } catch (Exception e) {
104: log(
105: Level.SEVERE,
106: "PopularSearchesBean.retrievePopularSearches() : Exception ",
107: e);
108: }
109: popularSearches = new ObjectListDataProvider(al);
110: popularSearches.setObjectType(PopularSearchBean.class);
111: }
112:
113: }
|