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: import java.text.*;
019:
020: import javax.faces.context.FacesContext;
021: import javax.faces.el.ValueBinding;
022: import javax.servlet.http.HttpServletRequest;
023: import javax.management.*;
024:
025: import com.sun.web.ui.model.*;
026: import com.sun.web.ui.event.*;
027: import com.sun.web.ui.component.*;
028:
029: import com.sun.data.provider.*;
030: import com.sun.data.provider.impl.ObjectListDataProvider;
031:
032: import com.sun.cacao.agent.JmxClient;
033:
034: import com.sun.portal.admin.common.util.AdminClientUtil;
035: import com.sun.portal.admin.console.common.PSBaseBean;
036:
037: public class ResourceDescriptionsBean extends PSBaseBean {
038:
039: private ObjectListDataProvider resourceDescriptions = null;
040: private String basicFilter = null;
041: private String advanceFilter = null;
042: private String advanceFilterQuery = null;
043:
044: public ResourceDescriptionsBean() {
045: basicFilter = "all";
046: advanceFilter = "by_query";
047: advanceFilterQuery = "";
048:
049: resourceDescriptions = (ObjectListDataProvider) getSessionAttribute("search.resourcedescriptions.resourcedescriptions");
050: if (resourceDescriptions == null) {
051: retrieveResourceDescriptions();
052: }
053:
054: setSessionAttribute("search.categoriespopupdrdh.mode", "browse");
055: setSessionAttribute("search.categoriespopupdrdh.category", null);
056: }
057:
058: public String getPageTitle() {
059: MessageFormat mf = new MessageFormat("");
060: mf.applyPattern(getLocalizedString("search",
061: "search.resourcedescriptions.pagetitle"));
062: return mf
063: .format(new Object[] { (String) getSessionAttribute("search.database.selected") });
064: }
065:
066: public ObjectListDataProvider getResourceDescriptions() {
067: return resourceDescriptions;
068: }
069:
070: public void setResourceDescriptions(
071: ObjectListDataProvider resourceDescriptions) {
072: this .resourceDescriptions = resourceDescriptions;
073: }
074:
075: public boolean getHasNoResourceDescriptions() {
076: if (resourceDescriptions == null) {
077: return true;
078: }
079:
080: List l = resourceDescriptions.getList();
081: if (l.size() == 0) {
082: return true;
083: }
084:
085: return false;
086: }
087:
088: public Option[] getAvailableBasicFilters() {
089: Option[] filterOptions = new Option[3];
090: filterOptions[0] = new Option("all", getLocalizedString(
091: "search", "search.resourcedescription.filter.all"));
092: filterOptions[1] = new Option(
093: "categorized",
094: getLocalizedString("search",
095: "search.resourcedescription.filter.categorized"));
096: filterOptions[2] = new Option(
097: "uncategorized",
098: getLocalizedString("search",
099: "search.resourcedescription.filter.uncategorized"));
100: return Table.getFilterOptions(filterOptions,
101: basicFilter == Table.CUSTOM_FILTER_APPLIED);
102: }
103:
104: public String getBasicFilter() {
105: return basicFilter;
106: }
107:
108: public void setBasicFilter(String filter) {
109: this .basicFilter = filter;
110: }
111:
112: public Option[] getAvailableAdvanceFilters() {
113: Option[] filterOptions = new Option[3];
114: filterOptions[0] = new Option("by_query", getLocalizedString(
115: "search", "search.resourcedescription.filter.byquery"));
116: filterOptions[1] = new Option("by_url", getLocalizedString(
117: "search", "search.resourcedescription.filter.byurl"));
118: filterOptions[2] = new Option("by_category",
119: getLocalizedString("search",
120: "search.resourcedescription.filter.bycategory"));
121: return filterOptions;
122: }
123:
124: public String getAdvanceFilter() {
125: return advanceFilter;
126: }
127:
128: public void setAdvanceFilter(String filter) {
129: this .advanceFilter = filter;
130: }
131:
132: public String getAdvanceFilterQuery() {
133: return advanceFilterQuery;
134: }
135:
136: public void setAdvanceFilterQuery(String query) {
137: this .advanceFilterQuery = query;
138: }
139:
140: public void applyBasicFilter() {
141: advanceFilter = "by_query";
142: advanceFilterQuery = "";
143: retrieveResourceDescriptions();
144: }
145:
146: public void applyAdvanceFilter() {
147: basicFilter = Table.CUSTOM_FILTER_APPLIED;
148: retrieveResourceDescriptions();
149:
150: advanceFilter = "by_query";
151: advanceFilterQuery = "";
152: }
153:
154: public String gotoCreateResourceDescription() {
155: setSessionAttribute(
156: "search.resourcedescriptions.resourcedescriptions",
157: null);
158: setSessionAttribute("search.createresourcedescription.url",
159: null);
160: setSessionAttribute(
161: "search.createresourcedescription.attributes", null);
162: return "gotoCreateResourceDescription";
163: }
164:
165: public String edit() {
166: List l = Checkbox.getSelected("checkbox");
167: if (l != null) {
168: if (l.size() > 1) {
169: setSessionAttribute(
170: "search.resourcedescriptions.resourcedescriptions",
171: null);
172: setSessionAttribute(
173: "search.resourcedescriptions.selected", l);
174: setSessionAttribute(
175: "search.editresourcedescriptions.attributes",
176: null);
177: return "gotoEditResourceDescriptions";
178: } else {
179: setSessionAttribute(
180: "search.resourcedescriptions.resourcedescriptions",
181: null);
182: setSessionAttribute(
183: "search.resourcedescription.selected",
184: (String) l.get(0));
185: setSessionAttribute(
186: "search.editresourcedescription.attributes",
187: null);
188: return "gotoEditResourceDescription";
189: }
190: } else {
191: return null;
192: }
193: }
194:
195: public String editAll() {
196: if (basicFilter.equals("all")) {
197: setSessionAttribute(
198: "search.resourcedescriptions.resourcedescriptions",
199: null);
200: setSessionAttribute("search.resourcedescriptions.selected",
201: new ArrayList());
202: setSessionAttribute(
203: "search.editresourcedescriptions.attributes", null);
204: } else {
205: ArrayList al = new ArrayList();
206: List l = resourceDescriptions.getList();
207: for (int index = 0; index < l.size(); index++) {
208: ResourceDescriptionBean rdb = (ResourceDescriptionBean) l
209: .get(index);
210: al.add(rdb.url);
211: }
212: setSessionAttribute(
213: "search.resourcedescriptions.resourcedescriptions",
214: null);
215: setSessionAttribute("search.resourcedescriptions.selected",
216: al);
217: setSessionAttribute(
218: "search.editresourcedescriptions.attributes", null);
219: }
220: return "gotoEditResourceDescriptions";
221: }
222:
223: public String delete() {
224: try {
225: LinkedList path = new LinkedList();
226: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
227: path
228: .addFirst((String) getSessionAttribute("search.server.selected"));
229: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
230: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
231:
232: Object[] params = {
233: Checkbox.getSelected("checkbox"),
234: (String) getSessionAttribute("search.database.selected") };
235: String[] signatures = { "java.util.List",
236: "java.lang.String" };
237: getMBeanServerConnection().invoke(on,
238: "deleteResourceDescriptions", params, signatures);
239: } catch (Exception e) {
240: log(Level.SEVERE,
241: "ResourceDescriptionsBean.delete() : Exception ", e);
242: }
243: retrieveResourceDescriptions();
244: return null;
245: }
246:
247: public String cancel() {
248: setSessionAttribute(
249: "search.resourcedescriptions.resourcedescriptions",
250: null);
251: return "gotoDatabasesHome";
252: }
253:
254: private void retrieveResourceDescriptions() {
255: ArrayList al1 = new ArrayList();
256: try {
257: LinkedList path = new LinkedList();
258: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
259: path
260: .addFirst((String) getSessionAttribute("search.server.selected"));
261: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
262: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
263:
264: String searchType = (basicFilter == Table.CUSTOM_FILTER_APPLIED) ? advanceFilter
265: : basicFilter;
266: String query = advanceFilterQuery;
267: ArrayList viewAttributes = new ArrayList();
268: viewAttributes.add("url");
269: viewAttributes.add("title");
270: Integer startPage = new Integer(0);
271: Integer hitsPerPage = new Integer(0);
272: Object[] params = {
273: searchType,
274: query,
275: viewAttributes,
276: startPage,
277: hitsPerPage,
278: (String) getSessionAttribute("search.database.selected") };
279: String[] signatures = { "java.lang.String",
280: "java.lang.String", "java.util.List",
281: "java.lang.Integer", "java.lang.Integer",
282: "java.lang.String" };
283: ArrayList data = (ArrayList) getMBeanServerConnection()
284: .invoke(on, "getAllResourceDescriptions", params,
285: signatures);
286:
287: ArrayList al2 = (ArrayList) data.get(3);
288: for (int index = 0; index < al2.size(); index++) {
289: HashMap hm = (HashMap) al2.get(index);
290:
291: ArrayList values = (ArrayList) hm.get("url");
292: String url = (String) values.get(0);
293:
294: values = (ArrayList) hm.get("title");
295: String title = (values != null && values.size() > 0) ? (String) values
296: .get(0)
297: : "";
298:
299: ResourceDescriptionBean rdb = new ResourceDescriptionBean();
300: rdb.initialize(url, title);
301: al1.add(rdb);
302: }
303: } catch (Exception e) {
304: log(
305: Level.SEVERE,
306: "ResourceDescriptionsBean.retrieveResourceDescriptions() : Exception ",
307: e);
308: }
309:
310: resourceDescriptions = new ObjectListDataProvider(al1);
311: resourceDescriptions
312: .setObjectType(ResourceDescriptionBean.class);
313:
314: setSessionAttribute(
315: "search.resourcedescriptions.resourcedescriptions",
316: resourceDescriptions);
317: }
318:
319: }
|