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 CreateClassificationRuleBean extends PSBaseBean {
039:
040: private String source = "Author";
041: private String method = "is";
042: private String criterion = "";
043: private String classification = "";
044: private String caseSensitive = "true";
045:
046: private Boolean renderDupClassRule = Boolean.FALSE;
047:
048: public Option[] sourceOption;
049: public Option[] methodOption;
050:
051: public CreateClassificationRuleBean() {
052: source = "Author";
053: method = "is";
054: criterion = "";
055: classification = "";
056: caseSensitive = "true";
057: renderDupClassRule = Boolean.FALSE;
058: setSessionAttribute("search.categoriespopupcrcr.mode", "browse");
059: setSessionAttribute("search.categoriespopupcrcr.category", null);
060: }
061:
062: /*
063: * Button Actions
064: */
065: public String create() {
066: Boolean isCaseSensitive = null;
067: if (caseSensitive.equalsIgnoreCase("true"))
068: isCaseSensitive = Boolean.TRUE;
069: else
070: isCaseSensitive = Boolean.FALSE;
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[] params1 = { source, method, criterion,
088: classification };
089: String[] signature1 = { "java.lang.String",
090: "java.lang.String", "java.lang.String",
091: "java.lang.String" };
092:
093: Boolean exist = (Boolean) getMBeanServerConnection()
094: .invoke(on, "existClassRule", params1, signature1);
095:
096: if (exist.booleanValue()) {
097: renderDupClassRule = Boolean.TRUE;
098: return "gotoCreateClassificationRule";
099: } else {
100: renderDupClassRule = Boolean.FALSE;
101: }
102:
103: Object[] params = { source, method, criterion,
104: classification, isCaseSensitive };
105: String[] signature = { "java.lang.String",
106: "java.lang.String", "java.lang.String",
107: "java.lang.String", "java.lang.Boolean" };
108:
109: Boolean b = (Boolean) getMBeanServerConnection().invoke(on,
110: "createClassRule", params, signature);
111:
112: } catch (Exception e) {
113: log(
114: Level.SEVERE,
115: "CreateClassificationRuleBean.create() failed to create the classification rule",
116: e);
117: }
118:
119: source = "Author";
120: method = "is";
121: criterion = "";
122: classification = "";
123: caseSensitive = "true";
124: renderDupClassRule = Boolean.FALSE;
125: return "gotoClassificationRulesHome";
126: }
127:
128: public String cancel() {
129: source = "Author";
130: method = "is";
131: criterion = "";
132: classification = "";
133: caseSensitive = "true";
134: renderDupClassRule = Boolean.FALSE;
135: return "gotoClassificationRulesHome";
136: }
137:
138: public void validate(FacesContext fc, UIComponent component,
139: Object value) throws ValidatorException {
140:
141: String taxonomy = value.toString();
142:
143: if ((taxonomy.indexOf(';') != -1)
144: || (taxonomy.indexOf('<') != -1)
145: || (taxonomy.indexOf('>') != -1)
146: || (taxonomy.indexOf('"') != -1)
147: || (taxonomy.indexOf('\\') != -1)) {
148:
149: String msgString = getLocalizedString("search.error.specialcharacters");
150: FacesMessage msg = new FacesMessage(msgString);
151: throw new ValidatorException(msg);
152: }
153:
154: }
155:
156: /*
157: * Methods for UI options
158: */
159: public Option[] getSourceOption() {
160: ArrayList al = new ArrayList();
161: try {
162: LinkedList path = new LinkedList();
163: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
164: path
165: .addFirst((String) getSessionAttribute("search.server.selected"));
166: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
167: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
168:
169: Object[] params1 = {};
170: String[] signatures1 = {};
171: ArrayList data = (ArrayList) getMBeanServerConnection()
172: .invoke(on, "retrieveAllSchema", params1,
173: signatures1);
174: for (int index = 0; index < data.size(); index++) {
175: String name = (String) data.get(index);
176:
177: Object[] params2 = { name };
178: String[] signature2 = { "java.lang.String" };
179: Properties p = (Properties) getMBeanServerConnection()
180: .invoke(on, "getSchemaAttributes", params2,
181: signature2);
182:
183: if (p.getProperty("noninternal").equals("true")) {
184: al.add(name);
185: }
186: }
187: } catch (Exception e) {
188: log(
189: Level.SEVERE,
190: "CreateClassificationRuleBean.getSourceOption() failed to get the schema list for source options ",
191: e);
192: }
193:
194: sourceOption = new Option[al.size() + 5];
195: for (int i = 0; i < al.size(); i++) {
196: String name = (String) al.get(i);
197: sourceOption[i] = new Option(name, name);
198: }
199: ArrayList sources = getStringList(getLocalizedString("robot.classificationrule.source.listlabel"));
200: sourceOption[al.size() + 0] = new Option((String) sources
201: .get(0), (String) sources.get(0));
202: sourceOption[al.size() + 1] = new Option((String) sources
203: .get(1), (String) sources.get(1));
204: sourceOption[al.size() + 2] = new Option((String) sources
205: .get(2), (String) sources.get(2));
206: sourceOption[al.size() + 3] = new Option((String) sources
207: .get(3), (String) sources.get(3));
208: sourceOption[al.size() + 4] = new Option((String) sources
209: .get(4), (String) sources.get(4));
210:
211: return sourceOption;
212: }
213:
214: public Option[] getMethodOption() {
215: methodOption = new Option[5];
216: ArrayList methods = getStringList(getLocalizedString("robot.classificationrule.method.listlabel"));
217: methodOption[0] = new Option("is", (String) methods.get(0));
218: methodOption[1] = new Option("contains", (String) methods
219: .get(1));
220: methodOption[2] = new Option("begins with", (String) methods
221: .get(2));
222: methodOption[3] = new Option("ends with", (String) methods
223: .get(3));
224: methodOption[4] = new Option("regular", (String) methods.get(4));
225: return methodOption;
226: }
227:
228: /*
229: * Methods to Get/Set Bean elements
230: */
231: public String getSource() {
232: return source;
233: }
234:
235: public void setSource(String s) {
236: this .source = s;
237: }
238:
239: public String getMethod() {
240: return method;
241: }
242:
243: public void setMethod(String s) {
244: this .method = s;
245: }
246:
247: public String getCriterion() {
248: return criterion;
249: }
250:
251: public void setCriterion(String s) {
252: this .criterion = s;
253: }
254:
255: public String getCaseSensitive() {
256: return caseSensitive;
257: }
258:
259: public void setCaseSensitive(String s) {
260: if (s == null)
261: this .caseSensitive = "false";
262: else
263: this .caseSensitive = "true";
264: }
265:
266: public String getClassification() {
267: return classification;
268: }
269:
270: public void setClassification(String s) {
271: this .classification = s;
272: }
273:
274: public Boolean getRenderDupClassRule() {
275: return renderDupClassRule;
276: }
277:
278: /*
279: * Private Methods
280: */
281: private ArrayList getStringList(String s) {
282:
283: ArrayList s_list = new ArrayList();
284: StringTokenizer st = new StringTokenizer(s, ",");
285: while (st.hasMoreTokens()) {
286: String label = st.nextToken();
287: s_list.add(label);
288: }
289: return s_list;
290: }
291:
292: private String getLocalizedString(String key) {
293: return super .getLocalizedString("search", key);
294: }
295:
296: }
|