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 EditSchemaBean extends PSBaseBean {
040:
041: public String schemaName = "";
042: public String name = "";
043: public String description = "";
044: public String aliases = "";
045: public String editable = "true";
046: public String indexable = "true";
047: public String scoreMultiplier = "";
048: public String dataType = "string";
049:
050: public EditSchemaBean() {
051: schemaName = (String) getSessionAttribute("search.schema.selected");
052:
053: try {
054: LinkedList path = new LinkedList();
055: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
056: path
057: .addFirst((String) getSessionAttribute("search.server.selected"));
058: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
059: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
060:
061: Object[] params = { schemaName };
062: String[] signatures = { "java.lang.String" };
063: Properties p = (Properties) getMBeanServerConnection()
064: .invoke(on, "getSchemaAttributes", params,
065: signatures);
066: name = getValue(p, "name");
067: description = getValue(p, "description");
068: aliases = getValue(p, "aliases");
069: editable = getValue(p, "editable");
070: indexable = getValue(p, "indexable");
071: scoreMultiplier = getValue(p, "score-multiplier");
072: dataType = getValue(p, "datatype");
073: } catch (Exception e) {
074: log(Level.SEVERE,
075: "EditSchemaBean.EditSchemaBean() : Exception ", e);
076: }
077: }
078:
079: public boolean getShowError() {
080: String value = (String) getSessionAttribute("search.editschema.showerror");
081: if (value == null || value.equals("false")) {
082: return false;
083: } else {
084: return true;
085: }
086: }
087:
088: public String getPageTitle() {
089: MessageFormat mf = new MessageFormat("");
090: mf.applyPattern(getLocalizedString("search",
091: "search.editschema.pagetitle"));
092: return mf.format(new Object[] { schemaName });
093: }
094:
095: public Option[] getAvailableBoolean() {
096: Option[] options = new Option[2];
097: options[0] = new Option("true", getLocalizedString("search",
098: "search.general.true"));
099: options[1] = new Option("false", getLocalizedString("search",
100: "search.general.false"));
101: return options;
102: }
103:
104: public String getName() {
105: return name;
106: }
107:
108: public void setName(String name) {
109: this .name = name;
110: }
111:
112: public String getDescription() {
113: return description;
114: }
115:
116: public void setDescription(String description) {
117: this .description = description;
118: }
119:
120: public String getAliases() {
121: return aliases;
122: }
123:
124: public void setAliases(String aliases) {
125: this .aliases = aliases;
126: }
127:
128: public String getEditable() {
129: return editable;
130: }
131:
132: public void setEditable(String editable) {
133: this .editable = editable;
134: }
135:
136: public String getIndexable() {
137: return indexable;
138: }
139:
140: public void setIndexable(String indexable) {
141: this .indexable = indexable;
142: }
143:
144: public String getScoreMultiplier() {
145: return scoreMultiplier;
146: }
147:
148: public void setScoreMultiplier(String scoreMultiplier) {
149: this .scoreMultiplier = scoreMultiplier;
150: }
151:
152: public String getDataType() {
153: return dataType;
154: }
155:
156: public void setDataType(String dataType) {
157: this .dataType = dataType;
158: }
159:
160: public void validate(FacesContext fc, UIComponent component,
161: Object value) throws ValidatorException {
162: String id = component.getId();
163: if (id.equals("name")) {
164: if (Validators.containsSpace((String) value)) {
165: throw new ValidatorException(new FacesMessage(
166: FacesMessage.SEVERITY_ERROR,
167: getLocalizedString("search",
168: "search.error.error"),
169: getLocalizedString("search",
170: "search.error.space")));
171: }
172: if (Validators.containsSpecialCharacters((String) value)) {
173: throw new ValidatorException(new FacesMessage(
174: FacesMessage.SEVERITY_ERROR,
175: getLocalizedString("search",
176: "search.error.error"),
177: getLocalizedString("search",
178: "search.error.specialcharacters")));
179: }
180: if (Validators.containsInvalidCharacters((String) value)) {
181: throw new ValidatorException(new FacesMessage(
182: FacesMessage.SEVERITY_ERROR,
183: getLocalizedString("search",
184: "search.error.error"),
185: getLocalizedString("search",
186: "search.error.invalidcharacters")));
187: }
188: } else if (id.equals("description")) {
189: } else if (id.equals("aliases")) {
190: } else if (id.equals("scoreMultiplier")) {
191: if (!Validators.isFloat((String) value, true)) {
192: throw new ValidatorException(new FacesMessage(
193: FacesMessage.SEVERITY_ERROR,
194: getLocalizedString("search",
195: "search.error.error"),
196: getLocalizedString("search",
197: "search.error.positivenumber")));
198: }
199: }
200: }
201:
202: public String save() {
203: try {
204: LinkedList path = new LinkedList();
205: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
206: path
207: .addFirst((String) getSessionAttribute("search.server.selected"));
208: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
209: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
210:
211: Object[] params = { schemaName, name, description, aliases,
212: new Boolean(editable), new Boolean(indexable),
213: scoreMultiplier, dataType };
214: String[] signatures = { "java.lang.String",
215: "java.lang.String", "java.lang.String",
216: "java.lang.String", "java.lang.Boolean",
217: "java.lang.Boolean", "java.lang.String",
218: "java.lang.String" };
219: getMBeanServerConnection().invoke(on,
220: "setSchemaAttributes", params, signatures);
221:
222: setSessionAttribute("search.editschema.showerror", "false");
223: return "gotoDatabaseSchemasHome";
224: } catch (Exception e) {
225: log(Level.SEVERE, "EditSchemaBean.save() : Exception ", e);
226: setSessionAttribute("search.editschema.showerror", "true");
227: return null;
228: }
229: }
230:
231: public String cancel() {
232: setSessionAttribute("search.editschema.showerror", "false");
233: return "gotoDatabaseSchemasHome";
234: }
235:
236: private String getValue(Properties p, String key) {
237: if (p.containsKey(key)) {
238: return p.getProperty(key);
239: } else {
240: return "";
241: }
242: }
243:
244: }
|