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 ClassificationRulesBean extends PSBaseBean {
035:
036: private DataProvider rules = null;
037:
038: private TableRowGroup tableRowGroup = null;
039: private TableSelectPhaseListener tspl = null;
040: private ArrayList classlist = null;
041:
042: public ClassificationRulesBean() {
043:
044: tspl = new TableSelectPhaseListener();
045: rules = generateClassificationRules();
046: }
047:
048: /*
049: * Button Actions
050: */
051: public String create() {
052: return "gotoCreateClassificationRule";
053: }
054:
055: public String delete() {
056: ArrayList ids = new ArrayList();
057: ObjectListDataProvider oldp = (ObjectListDataProvider) rules;
058: List l = oldp.getList();
059: RowKey[] rowKeys = tableRowGroup.getRenderedRowKeys();
060: for (int i = 0; i < rowKeys.length; i++) {
061: RowKey rowKey = rowKeys[i];
062: if (tspl.isSelected(rowKey)) {
063: ClassificationRuleBean crb = (ClassificationRuleBean) l
064: .get(Integer.parseInt(rowKey.getRowId()));
065: ids.add(crb.ruleId);
066: oldp.removeRow(rowKey);
067: }
068: }
069: oldp.commitChanges();
070: tspl.clear();
071:
072: try {
073: LinkedList path = new LinkedList();
074: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
075: path
076: .addFirst((String) getSessionAttribute("search.server.selected"));
077: path.addFirst("category");
078: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
079: AdminClientUtil.SEARCH_CATEGORY_MBEAN_TYPE, path);
080:
081: Object[] params0 = {};
082: String[] signature0 = {};
083:
084: Boolean result = (Boolean) getMBeanServerConnection()
085: .invoke(on, "syncClassConfig", params0, signature0);
086:
087: Object[] params = { ids };
088: String[] signature = { "java.util.ArrayList" };
089: getMBeanServerConnection().invoke(on, "deleteClassRules",
090: params, signature);
091: } catch (Exception e) {
092: log(
093: Level.SEVERE,
094: "ClassificationRulesBean.delete() failed to delete classification rules",
095: e);
096: }
097:
098: rules = generateClassificationRules();
099: return "gotoClassificationRulesHome";
100: }
101:
102: public String edit() {
103: ObjectListDataProvider oldp = (ObjectListDataProvider) rules;
104: List l = oldp.getList();
105: String id = null;
106: RowKey[] rowKeys = tableRowGroup.getRenderedRowKeys();
107: for (int i = 0; i < rowKeys.length; i++) {
108: RowKey rowKey = rowKeys[i];
109: if (tspl.isSelected(rowKey)) {
110: ClassificationRuleBean crb = (ClassificationRuleBean) l
111: .get(Integer.parseInt(rowKey.getRowId()));
112: id = crb.ruleId;
113: setSessionAttribute(
114: "robot.classificationrule.selected", id);
115: break;
116: }
117: }
118: if (id != null) {
119: tspl.clear();
120: return "gotoEditClassificationRule";
121: } else {
122: tspl.clear();
123: return "gotoClassificationRulesHome";
124: }
125:
126: }
127:
128: /*
129: * Methods to Get and Set Bean elements
130: */
131: public DataProvider getRules() {
132: return rules;
133: }
134:
135: public void setRules(DataProvider rules) {
136: this .rules = rules;
137: }
138:
139: public TableRowGroup getTableRowGroup() {
140: return tableRowGroup;
141: }
142:
143: public void setTableRowGroup(TableRowGroup tableRowGroup) {
144: this .tableRowGroup = tableRowGroup;
145: }
146:
147: public Object getSelected() {
148: return tspl.getSelected(getTableRow());
149: }
150:
151: public void setSelected(Object object) {
152: tspl.setSelected(getTableRow(), object);
153: }
154:
155: /*
156: * Private Methods
157: */
158: private String getLocalizedString(String key) {
159: return super .getLocalizedString("search", key);
160: }
161:
162: private ArrayList getStringList(String s) {
163:
164: ArrayList s_list = new ArrayList();
165: StringTokenizer st = new StringTokenizer(s, ",");
166: while (st.hasMoreTokens()) {
167: String label = st.nextToken();
168: s_list.add(label);
169: }
170: return s_list;
171: }
172:
173: private RowKey getTableRow() {
174: FacesContext context = FacesContext.getCurrentInstance();
175: ValueBinding vb = context.getApplication().createValueBinding(
176: "#{classificationRule.tableRow}");
177: return (RowKey) vb.getValue(context);
178: }
179:
180: private DataProvider generateClassificationRules() {
181:
182: try {
183: LinkedList path = new LinkedList();
184: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
185: path
186: .addFirst((String) getSessionAttribute("search.server.selected"));
187: path.addFirst("category");
188: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
189: AdminClientUtil.SEARCH_CATEGORY_MBEAN_TYPE, path);
190:
191: Object[] params0 = {};
192: String[] signature0 = {};
193:
194: Boolean result = (Boolean) getMBeanServerConnection()
195: .invoke(on, "syncClassConfig", params0, signature0);
196:
197: Object[] params = { "" };
198: String[] signature = { "java.lang.String" };
199:
200: classlist = (ArrayList) getMBeanServerConnection().invoke(
201: on, "listClassRules", params, signature);
202:
203: } catch (Exception e) {
204: log(
205: Level.SEVERE,
206: "ClassificationRulesBean.generateClassificationRules() failed to get classification rules",
207: e);
208: }
209:
210: ArrayList al = new ArrayList();
211:
212: if (classlist != null && classlist.size() > 0) {
213: for (int i = 0; i < classlist.size(); i++) {
214: HashMap rule = (HashMap) classlist.get(i);
215: String ruleId = Integer.toString(i);
216: String source = (String) rule.get("Source");
217: String method = (String) rule.get("Method");
218: String criterion = (String) rule.get("Criterion");
219: String classification = (String) rule
220: .get("Classification");
221: Boolean caseSensitive = (Boolean) rule
222: .get("CaseSensitive");
223: al.add(new ClassificationRuleBean(ruleId, source,
224: method, criterion, classification,
225: caseSensitive));
226: } // end of for
227: }
228:
229: return new ObjectListDataProvider(al);
230: }
231:
232: }
|