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.application.FacesMessage;
019: import javax.faces.component.UIComponent;
020: import javax.faces.validator.*;
021: import javax.faces.context.FacesContext;
022: import javax.faces.el.ValueBinding;
023: import javax.servlet.http.HttpServletRequest;
024: import javax.management.*;
025:
026: import com.sun.web.ui.component.*;
027: import com.sun.web.ui.model.*;
028: import com.sun.web.ui.event.*;
029:
030: import com.sun.data.provider.*;
031: import com.sun.data.provider.impl.ObjectListDataProvider;
032:
033: import com.sun.cacao.agent.JmxClient;
034:
035: import com.sun.portal.admin.common.util.AdminClientUtil;
036: import com.sun.portal.admin.console.common.PSBaseBean;
037:
038: public class EditClassificationRuleBean extends PSBaseBean {
039:
040: private String ruleId = "";
041: private String source = "Author";
042: private String method = "is";
043: private String criterion = "";
044: private String classification = "";
045: private String caseSensitive = "true";
046:
047: private Boolean renderDupClassRule = Boolean.FALSE;
048:
049: private ArrayList classlist = null;
050:
051: public Option[] sourceOption;
052: public Option[] methodOption;
053:
054: public EditClassificationRuleBean() {
055: setSessionAttribute("search.categoriespopupercr.mode", "browse");
056: setSessionAttribute("search.categoriespopupercr.category", null);
057: }
058:
059: /*
060: * Button Actions
061: */
062: public String save() {
063: Boolean isCaseSensitive = null;
064: if (caseSensitive.equalsIgnoreCase("true"))
065: isCaseSensitive = Boolean.TRUE;
066: else
067: isCaseSensitive = Boolean.FALSE;
068:
069: try {
070: LinkedList path = new LinkedList();
071: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
072: path
073: .addFirst((String) getSessionAttribute("search.server.selected"));
074: path.addFirst("category");
075: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
076: AdminClientUtil.SEARCH_CATEGORY_MBEAN_TYPE, path);
077:
078: Object[] params0 = {};
079: String[] signature0 = {};
080:
081: Boolean result = (Boolean) getMBeanServerConnection()
082: .invoke(on, "syncClassConfig", params0, signature0);
083:
084: Object[] params1 = { source, method, criterion,
085: classification, ruleId };
086: String[] signature1 = { "java.lang.String",
087: "java.lang.String", "java.lang.String",
088: "java.lang.String", "java.lang.String" };
089:
090: Boolean exist = (Boolean) getMBeanServerConnection()
091: .invoke(on, "existClassRule", params1, signature1);
092:
093: if (exist.booleanValue()) {
094: renderDupClassRule = Boolean.TRUE;
095: return "gotoEditClassificationRule";
096: } else {
097: renderDupClassRule = Boolean.FALSE;
098: }
099:
100: Object[] params = { ruleId, source, method, criterion,
101: classification, isCaseSensitive };
102: String[] signature = { "java.lang.String",
103: "java.lang.String", "java.lang.String",
104: "java.lang.String", "java.lang.String",
105: "java.lang.Boolean" };
106:
107: Boolean b = (Boolean) getMBeanServerConnection().invoke(on,
108: "editClassRule", params, signature);
109:
110: } catch (Exception e) {
111: log(Level.SEVERE,
112: "EditClassificationRuleBean.save(): failed to edit the classification rule id "
113: + ruleId, e);
114: }
115:
116: ruleId = "";
117: source = "Author";
118: method = "is";
119: criterion = "";
120: classification = "";
121: caseSensitive = "true";
122: renderDupClassRule = Boolean.FALSE;
123: return "gotoClassificationRulesHome";
124: }
125:
126: public String cancel() {
127: ruleId = "";
128: source = "Author";
129: method = "is";
130: criterion = "";
131: classification = "";
132: caseSensitive = "true";
133: renderDupClassRule = Boolean.FALSE;
134: return "gotoClassificationRulesHome";
135: }
136:
137: public void validate(FacesContext fc, UIComponent component,
138: Object value) throws ValidatorException {
139:
140: String taxonomy = value.toString();
141:
142: if ((taxonomy.indexOf(';') != -1)
143: || (taxonomy.indexOf('<') != -1)
144: || (taxonomy.indexOf('>') != -1)
145: || (taxonomy.indexOf('"') != -1)
146: || (taxonomy.indexOf('\\') != -1)) {
147:
148: String msgString = getLocalizedString("search.error.specialcharacters");
149: FacesMessage msg = new FacesMessage(msgString);
150: throw new ValidatorException(msg);
151: }
152: }
153:
154: /*
155: * Methods for UI options
156: */
157: public Option[] getSourceOption() {
158: ArrayList al = new ArrayList();
159: try {
160: LinkedList path = new LinkedList();
161: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
162: path
163: .addFirst((String) getSessionAttribute("search.server.selected"));
164: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
165: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
166:
167: Object[] params1 = {};
168: String[] signatures1 = {};
169: ArrayList data = (ArrayList) getMBeanServerConnection()
170: .invoke(on, "retrieveAllSchema", params1,
171: signatures1);
172: for (int index = 0; index < data.size(); index++) {
173: String name = (String) data.get(index);
174:
175: Object[] params2 = { name };
176: String[] signatures2 = { "java.lang.String" };
177: Properties p = (Properties) getMBeanServerConnection()
178: .invoke(on, "getSchemaAttributes", params2,
179: signatures2);
180:
181: if (p.getProperty("noninternal").equals("true")) {
182: al.add(name);
183: }
184: }
185: } catch (Exception e) {
186: log(
187: Level.SEVERE,
188: "EditClassificationRuleBean.getSourceOption(): failed to get the schema list for source options ",
189: e);
190: }
191:
192: sourceOption = new Option[al.size() + 5];
193: for (int i = 0; i < al.size(); i++) {
194: String name = (String) al.get(i);
195: sourceOption[i] = new Option(name, name);
196: }
197: ArrayList sources = getStringList(getLocalizedString("robot.classificationrule.source.listlabel"));
198: sourceOption[al.size() + 0] = new Option((String) sources
199: .get(0), (String) sources.get(0));
200: sourceOption[al.size() + 1] = new Option((String) sources
201: .get(1), (String) sources.get(1));
202: sourceOption[al.size() + 2] = new Option((String) sources
203: .get(2), (String) sources.get(2));
204: sourceOption[al.size() + 3] = new Option((String) sources
205: .get(3), (String) sources.get(3));
206: sourceOption[al.size() + 4] = new Option((String) sources
207: .get(4), (String) sources.get(4));
208:
209: return sourceOption;
210: }
211:
212: public Option[] getMethodOption() {
213: methodOption = new Option[5];
214: ArrayList methods = getStringList(getLocalizedString("robot.classificationrule.method.listlabel"));
215: methodOption[0] = new Option("is", (String) methods.get(0));
216: methodOption[1] = new Option("contains", (String) methods
217: .get(1));
218: methodOption[2] = new Option("begins with", (String) methods
219: .get(2));
220: methodOption[3] = new Option("ends with", (String) methods
221: .get(3));
222: methodOption[4] = new Option("regular", (String) methods.get(4));
223: return methodOption;
224: }
225:
226: /*
227: * Methods to Get/Set Bean elements
228: */
229: public String getSource() {
230: if (!ruleId
231: .equals((String) getSessionAttribute("robot.classificationrule.selected"))) {
232: generateClassificationRule();
233: }
234: return source;
235: }
236:
237: public void setSource(String s) {
238: this .source = s;
239: }
240:
241: public String getMethod() {
242: if (!ruleId
243: .equals((String) getSessionAttribute("robot.classificationrule.selected"))) {
244: generateClassificationRule();
245: }
246: return method;
247: }
248:
249: public void setMethod(String s) {
250: this .method = s;
251: }
252:
253: public String getCriterion() {
254: if (!ruleId
255: .equals((String) getSessionAttribute("robot.classificationrule.selected"))) {
256: generateClassificationRule();
257: }
258: return criterion;
259: }
260:
261: public void setCriterion(String s) {
262: this .criterion = s;
263: }
264:
265: public String getCaseSensitive() {
266: if (!ruleId
267: .equals((String) getSessionAttribute("robot.classificationrule.selected"))) {
268: generateClassificationRule();
269: }
270: return caseSensitive;
271: }
272:
273: public void setCaseSensitive(String s) {
274: if (s == null)
275: this .caseSensitive = "false";
276: else
277: this .caseSensitive = "true";
278: }
279:
280: public String getClassification() {
281: if (!ruleId
282: .equals((String) getSessionAttribute("robot.classificationrule.selected"))) {
283: generateClassificationRule();
284: }
285: return classification;
286: }
287:
288: public void setClassification(String s) {
289: this .classification = s;
290: }
291:
292: public Boolean getRenderDupClassRule() {
293: return renderDupClassRule;
294: }
295:
296: /*
297: * Private Methods
298: */
299: private ArrayList getStringList(String s) {
300:
301: ArrayList s_list = new ArrayList();
302: StringTokenizer st = new StringTokenizer(s, ",");
303: while (st.hasMoreTokens()) {
304: String label = st.nextToken();
305: s_list.add(label);
306: }
307: return s_list;
308: }
309:
310: private String getLocalizedString(String key) {
311: return super .getLocalizedString("search", key);
312: }
313:
314: private void generateClassificationRule() {
315:
316: ruleId = (String) getSessionAttribute("robot.classificationrule.selected");
317:
318: try {
319: LinkedList path = new LinkedList();
320: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
321: path
322: .addFirst((String) getSessionAttribute("search.server.selected"));
323: path.addFirst("category");
324: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
325: AdminClientUtil.SEARCH_CATEGORY_MBEAN_TYPE, path);
326:
327: Object[] params = { ruleId };
328: String[] signature = { "java.lang.String" };
329:
330: classlist = (ArrayList) getMBeanServerConnection().invoke(
331: on, "listClassRules", params, signature);
332:
333: } catch (Exception e) {
334: log(
335: Level.SEVERE,
336: "EditClassificationRuleBean.generateClassificationRule(): failed to get the classification rule id "
337: + ruleId, e);
338: }
339:
340: if (classlist != null && classlist.size() > 0) {
341: HashMap rule = (HashMap) classlist.get(0);
342: source = (String) rule.get("Source");
343: method = (String) rule.get("Method");
344: criterion = (String) rule.get("Criterion");
345: classification = (String) rule.get("Classification");
346: Boolean isCaseSensitive = (Boolean) rule
347: .get("CaseSensitive");
348: if (isCaseSensitive.booleanValue())
349: caseSensitive = "true";
350: else
351: caseSensitive = "false";
352: }
353:
354: }
355:
356: }
|