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: import java.text.*;
018:
019: import javax.faces.context.FacesContext;
020: import javax.faces.application.FacesMessage;
021: import javax.faces.component.UIComponent;
022: import javax.faces.validator.*;
023: import javax.faces.el.ValueBinding;
024: import javax.servlet.http.HttpServletRequest;
025: import javax.management.*;
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.data.provider.*;
032: import com.sun.data.provider.impl.ObjectListDataProvider;
033:
034: import com.sun.cacao.agent.JmxClient;
035:
036: import com.sun.portal.admin.common.util.AdminClientUtil;
037: import com.sun.portal.admin.console.common.PSBaseBean;
038:
039: public class EditCategoryBean extends PSBaseBean {
040:
041: public String nodeID = "";
042: public String parentNodeID = "";
043: public String category = "";
044: public String description = "";
045: public String matchingRule = "";
046:
047: public EditCategoryBean() {
048: nodeID = (String) getSessionAttribute("search.categorieshome.edit");
049:
050: String[] strings = nodeID.split(":");
051:
052: parentNodeID = "";
053: for (int index = 0; index < strings.length - 1; index++) {
054: if (index == 0) {
055: parentNodeID = strings[index];
056: } else {
057: parentNodeID = parentNodeID + ":" + strings[index];
058: }
059: }
060:
061: category = strings[strings.length - 1];
062:
063: try {
064: LinkedList path = new LinkedList();
065: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
066: path
067: .addFirst((String) getSessionAttribute("search.server.selected"));
068: path.addFirst("category");
069: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
070: AdminClientUtil.SEARCH_CATEGORY_MBEAN_TYPE, path);
071:
072: Object[] params = { nodeID };
073: String[] signatures = { "java.lang.String" };
074: description = (String) getMBeanServerConnection().invoke(
075: on, "getTaxTreeNodeDesc", params, signatures);
076: matchingRule = (String) getMBeanServerConnection().invoke(
077: on, "getTaxTreeNodeRule", params, signatures);
078: } catch (Exception e) {
079: log(Level.SEVERE, "EditCategoryBean.EditCategoryBean()", e);
080: }
081: }
082:
083: public boolean getShowAlert() {
084: return isOutOfSync();
085: }
086:
087: public boolean getShowError() {
088: String value = (String) getSessionAttribute("search.editcategory.showerror");
089: if (value == null || value.equals("false")) {
090: return false;
091: } else {
092: return true;
093: }
094: }
095:
096: public String getPageTitle() {
097: MessageFormat mf = new MessageFormat("");
098: mf.applyPattern(getLocalizedString("search",
099: "search.editcategory.pagetitle"));
100: return mf.format(new Object[] { nodeID });
101: }
102:
103: public String getCategory() {
104: return category;
105: }
106:
107: public void setCategory(String category) {
108: this .category = category;
109: }
110:
111: public String getDescription() {
112: return description;
113: }
114:
115: public void setDescription(String description) {
116: this .description = description;
117: }
118:
119: public String getMatchingRule() {
120: return matchingRule;
121: }
122:
123: public void setMatchingRule(String matchingRule) {
124: this .matchingRule = matchingRule;
125: }
126:
127: public void validate(FacesContext fc, UIComponent component,
128: Object value) throws ValidatorException {
129: String id = component.getId();
130: if (id.equals("category")) {
131: if (!Validators.isCategoryValid((String) value)) {
132: throw new ValidatorException(new FacesMessage(
133: FacesMessage.SEVERITY_ERROR,
134: getLocalizedString("search",
135: "search.error.error"),
136: getLocalizedString("search",
137: "search.error.badcategory")));
138: }
139: if (!value.equals(category) && isDuplicate((String) value)) {
140: throw new ValidatorException(new FacesMessage(
141: FacesMessage.SEVERITY_ERROR,
142: getLocalizedString("search",
143: "search.error.error"),
144: getLocalizedString("search",
145: "search.error.duplicatecategory")));
146: }
147: } else if (id.equals("description")) {
148: } else if (id.equals("matchingRule")) {
149: }
150: }
151:
152: public String save() {
153: if (isOutOfSync()) {
154: String s = (String) getSessionAttribute("search.editcategory.alertlevel");
155: if (s == null || s.equals("")) {
156: setSessionAttribute("search.editcategory.alertlevel",
157: "on");
158: return null;
159: } else {
160: setSessionAttribute("search.editcategory.alertlevel",
161: "");
162: return doSave();
163: }
164: } else {
165: setSessionAttribute("search.editcategory.alertlevel", "");
166: return doSave();
167: }
168: }
169:
170: public String cancel() {
171: setSessionAttribute("search.editcategory.showerror", "false");
172: setSessionAttribute("search.editcategory.alertlevel", "");
173: return "gotoCategoriesHome";
174: }
175:
176: private boolean isDuplicate(String value) {
177: String currentNodeID = (String) getSessionAttribute("search.categorieshome.category");
178: if (currentNodeID.equals("")) {
179: currentNodeID = "ROOT";
180: }
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[] params = { currentNodeID };
192: String[] signatures = { "java.lang.String" };
193: ArrayList data = (ArrayList) getMBeanServerConnection()
194: .invoke(on, "getTaxTreeChildren", params,
195: signatures);
196: for (int index = 0; index < data.size(); index++) {
197: String nodeID = (String) data.get(index);
198: String[] strings = nodeID.split(":");
199: if (strings[strings.length - 1].equals(value)) {
200: return true;
201: }
202: }
203: } catch (Exception e) {
204: }
205: return false;
206: }
207:
208: private boolean isOutOfSync() {
209: try {
210: LinkedList path = new LinkedList();
211: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
212: path
213: .addFirst((String) getSessionAttribute("search.server.selected"));
214: path.addFirst("category");
215: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
216: AdminClientUtil.SEARCH_CATEGORY_MBEAN_TYPE, path);
217:
218: Object[] params = {};
219: String[] signatures = {};
220: Boolean result = (Boolean) getMBeanServerConnection()
221: .invoke(on, "isOutOfSync", params, signatures);
222: return result.booleanValue();
223: } catch (Exception e) {
224: log(Level.SEVERE, "EditCategoryBean.isOutOfSync()", e);
225: }
226: return false;
227: }
228:
229: private String doSave() {
230: try {
231: LinkedList path = new LinkedList();
232: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
233: path
234: .addFirst((String) getSessionAttribute("search.server.selected"));
235: path.addFirst("category");
236: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
237: AdminClientUtil.SEARCH_CATEGORY_MBEAN_TYPE, path);
238:
239: Object[] params = { nodeID, category, description,
240: matchingRule };
241: String[] signatures = { "java.lang.String",
242: "java.lang.String", "java.lang.String",
243: "java.lang.String" };
244: getMBeanServerConnection().invoke(on, "updateTaxTreeNode",
245: params, signatures);
246:
247: setSessionAttribute("search.editcategory.showerror",
248: "false");
249: return "gotoCategoriesHome";
250: } catch (Exception e) {
251: log(Level.SEVERE, "EditCategoryBean.doSave()", e);
252: setSessionAttribute("search.editcategory.showerror", "true");
253: return null;
254: }
255: }
256:
257: }
|