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.io.*;
017:
018: import javax.faces.context.FacesContext;
019: import javax.faces.el.ValueBinding;
020: import javax.servlet.http.HttpServletRequest;
021: import javax.management.*;
022:
023: import com.sun.data.provider.*;
024: import com.sun.data.provider.impl.ListDataProvider;
025: import com.sun.data.provider.impl.ObjectListDataProvider;
026:
027: import com.sun.web.ui.model.*;
028: import com.sun.web.ui.event.*;
029: import com.sun.web.ui.component.*;
030:
031: import com.sun.portal.admin.common.util.AdminClientUtil;
032: import com.sun.portal.admin.console.common.PSBaseBean;
033:
034: public class RobotSitesBean extends PSBaseBean {
035:
036: private DataProvider sites = null;
037: private String newsiteType = "url";
038: private String newsite;
039: private String depth = "10";
040:
041: private Option[] newsiteOption;
042: private Option[] depthOption;
043: private TableRowGroup tableRowGroup = null;
044: private TableSelectPhaseListener tspl = null;
045:
046: public static final FieldKey SITEID = new FieldKey("siteid");
047:
048: public RobotSitesBean() {
049:
050: tspl = new TableSelectPhaseListener();
051: sites = generateRobotSites();
052: }
053:
054: /*
055: * Button Actions
056: */
057: public String create() {
058: return "gotoCreateRobotSite";
059: }
060:
061: public String delete() {
062: ArrayList ids = new ArrayList();
063: ObjectListDataProvider oldp = (ObjectListDataProvider) sites;
064: List l = oldp.getList();
065: RowKey[] rowKeys = tableRowGroup.getRenderedRowKeys();
066: for (int i = 0; i < rowKeys.length; i++) {
067: RowKey rowKey = rowKeys[i];
068: if (tspl.isSelected(rowKey)) {
069: RobotSiteBean rsb = (RobotSiteBean) l.get(Integer
070: .parseInt(rowKey.getRowId()));
071: ids.add(rsb.id);
072: }
073: }
074:
075: try {
076: LinkedList path = new LinkedList();
077: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
078: path
079: .addFirst((String) getSessionAttribute("search.server.selected"));
080: path.addFirst("robot");
081: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
082: AdminClientUtil.SEARCH_ROBOT_MBEAN_TYPE, path);
083:
084: Object[] params = { ids };
085: String[] signature = { "java.util.ArrayList" };
086: getMBeanServerConnection().invoke(on, "deleteSites",
087: params, signature);
088: } catch (Exception e) {
089: log(
090: Level.SEVERE,
091: "RobotSitesBean.delete() failed to delete robot sites",
092: e);
093: }
094:
095: sites = generateRobotSites();
096: tspl.clear();
097: return "gotoRobotSitesHome";
098: }
099:
100: public String enable() {
101: ArrayList ids = new ArrayList();
102: ObjectListDataProvider oldp = (ObjectListDataProvider) sites;
103: //List l = oldp.getList();
104: //RowKey[] rowKeys = tableRowGroup.getRenderedRowKeys();
105: RowKey[] rowKeys = oldp.getRowKeys(oldp.getRowCount(), null);
106: for (int i = 0; i < rowKeys.length; i++) {
107: RowKey rowKey = rowKeys[i];
108: if (tspl.isSelected(rowKey)) {
109: //RobotSiteBean rsb = (RobotSiteBean)l.get(Integer.parseInt(rowKey.getRowId()));
110: RobotSiteBean rsb = (RobotSiteBean) oldp
111: .getObject(rowKey);
112: ids.add(rsb.id);
113: }
114: }
115:
116: try {
117: LinkedList path = new LinkedList();
118: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
119: path
120: .addFirst((String) getSessionAttribute("search.server.selected"));
121: path.addFirst("robot");
122: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
123: AdminClientUtil.SEARCH_ROBOT_MBEAN_TYPE, path);
124:
125: Object[] params = { ids };
126: String[] signature = { "java.util.ArrayList" };
127: getMBeanServerConnection().invoke(on, "enableSites",
128: params, signature);
129: } catch (Exception e) {
130: log(
131: Level.SEVERE,
132: "RobotSitesBean.enable() failed to enable robot sites",
133: e);
134: }
135:
136: sites = generateRobotSites();
137: tspl.clear();
138: return "gotoRobotSitesHome";
139: }
140:
141: public String disable() {
142: ArrayList ids = new ArrayList();
143: ObjectListDataProvider oldp = (ObjectListDataProvider) sites;
144: //List l = oldp.getList();
145: // RowKey[] rowKeys = tableRowGroup.getRenderedRowKeys();
146: RowKey[] rowKeys = oldp.getRowKeys(oldp.getRowCount(), null);
147: for (int i = 0; i < rowKeys.length; i++) {
148: RowKey rowKey = rowKeys[i];
149: if (tspl.isSelected(rowKey)) {
150: //RobotSiteBean rsb = (RobotSiteBean)l.get(Integer.parseInt(rowKey.getRowId()));
151: RobotSiteBean rsb = (RobotSiteBean) oldp
152: .getObject(rowKey);
153: ids.add(rsb.id);
154: }
155: }
156:
157: try {
158: LinkedList path = new LinkedList();
159: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
160: path
161: .addFirst((String) getSessionAttribute("search.server.selected"));
162: path.addFirst("robot");
163: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
164: AdminClientUtil.SEARCH_ROBOT_MBEAN_TYPE, path);
165:
166: Object[] params = { ids };
167: String[] signature = { "java.util.ArrayList" };
168: getMBeanServerConnection().invoke(on, "disableSites",
169: params, signature);
170: } catch (Exception e) {
171: log(
172: Level.SEVERE,
173: "RobotSitesBean.disable() failed to disable robot sites",
174: e);
175: }
176:
177: sites = generateRobotSites();
178: tspl.clear();
179: return "gotoRobotSitesHome";
180: }
181:
182: public String edit() {
183: HttpServletRequest hsr = (HttpServletRequest) FacesContext
184: .getCurrentInstance().getExternalContext().getRequest();
185: String id = (String) hsr.getParameter("robot.site.selected");
186: setSessionAttribute("robot.site.selected", id);
187: return "gotoEditRobotSite";
188: }
189:
190: public String cancel() {
191: return "gotoRobotSitesHome";
192: }
193:
194: /*
195: * Methods to Get and Set Bean elements
196: */
197: public DataProvider getSites() {
198: return sites;
199: }
200:
201: public void setSites(DataProvider sites) {
202: this .sites = sites;
203: }
204:
205: public String getNewsiteType() {
206: return newsiteType;
207: }
208:
209: public void setNewsiteType(String type) {
210: this .newsiteType = type;
211: }
212:
213: public String getNewsite() {
214: return newsite;
215: }
216:
217: public void setNewsite(String s) {
218: this .newsite = s;
219: }
220:
221: public String getDepth() {
222: return depth;
223: }
224:
225: public void setDepth(String d) {
226: this .depth = d;
227: }
228:
229: public TableRowGroup getTableRowGroup() {
230: return tableRowGroup;
231: }
232:
233: public void setTableRowGroup(TableRowGroup tableRowGroup) {
234: this .tableRowGroup = tableRowGroup;
235: }
236:
237: public Object getSelected() {
238: return tspl.getSelected(getTableRow());
239: }
240:
241: public void setSelected(Object object) {
242: tspl.setSelected(getTableRow(), object);
243: }
244:
245: public Option[] getNewsiteOption() {
246:
247: newsiteOption = new Option[2];
248: newsiteOption[0] = new Option("url",
249: getLocalizedString("robot.site.create.url"));
250: newsiteOption[1] = new Option("domain",
251: getLocalizedString("robot.site.create.domain"));
252: return newsiteOption;
253: }
254:
255: public Option[] getDepthOption() {
256:
257: depthOption = new Option[12];
258: ArrayList values = getStringList(getLocalizedString("robot.site.create.depthlistvalue"));
259: ArrayList labels = getStringList(getLocalizedString("robot.site.create.depthlistlabel"));
260: for (int i = 0; i < 12; i++) {
261: depthOption[i] = new Option((String) values.get(i),
262: (String) labels.get(i));
263: }
264: return depthOption;
265: }
266:
267: /*
268: * Private Methods
269: */
270: private String getLocalizedString(String key) {
271: return super .getLocalizedString("search", key);
272: }
273:
274: private ArrayList getStringList(String s) {
275:
276: ArrayList s_list = new ArrayList();
277: StringTokenizer st = new StringTokenizer(s, ",");
278: while (st.hasMoreTokens()) {
279: String label = st.nextToken();
280: s_list.add(label);
281: }
282: return s_list;
283: }
284:
285: private RowKey getTableRow() {
286: FacesContext context = FacesContext.getCurrentInstance();
287: ValueBinding vb = context.getApplication().createValueBinding(
288: "#{site.tableRow}");
289: return (RowKey) vb.getValue(context);
290: }
291:
292: private DataProvider generateRobotSites() {
293: HashMap sitemap = null;
294: try {
295: LinkedList path = new LinkedList();
296: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
297: path
298: .addFirst((String) getSessionAttribute("search.server.selected"));
299: path.addFirst("robot");
300: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
301: AdminClientUtil.SEARCH_ROBOT_MBEAN_TYPE, path);
302:
303: Object[] params = { "" };
304: String[] signature = { "java.lang.String" };
305:
306: sitemap = (HashMap) getMBeanServerConnection().invoke(on,
307: "listSites", params, signature);
308:
309: } catch (Exception e) {
310: log(
311: Level.SEVERE,
312: "RobotSitesBean.generateRobotSites() failed to get robot sites",
313: e);
314: }
315:
316: ArrayList al = new ArrayList();
317:
318: if (sitemap != null) {
319: HashMap site = null;
320: String siteID;
321:
322: Iterator it = sitemap.keySet().iterator();
323: while (it.hasNext()) {
324: siteID = (String) it.next();
325: site = (HashMap) sitemap.get(siteID);
326: if (site != null) {
327: al.add(new RobotSiteBean(siteID, site));
328: }
329: }
330: }
331:
332: return new ObjectListDataProvider(al);
333: }
334:
335: }
|