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 CreateRobotSiteBean extends PSBaseBean {
039:
040: private String newsite = "";
041: private String newsiteType = "url";
042: private String depth = "10";
043: private String database = "";
044:
045: private Option[] newsiteOption;
046: private Option[] depthOption;
047:
048: public CreateRobotSiteBean() {
049: newsite = "";
050: newsiteType = "url";
051: depth = "10";
052: database = "";
053: }
054:
055: /*
056: * Button Actions
057: */
058: public String createRobotSite() {
059: Boolean domain;
060: if (newsiteType.equalsIgnoreCase("url")) {
061: domain = Boolean.FALSE;
062: } else {
063: domain = Boolean.TRUE;
064: }
065:
066: String siteID = null;
067: try {
068: LinkedList path = new LinkedList();
069: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
070: path
071: .addFirst((String) getSessionAttribute("search.server.selected"));
072: path.addFirst("robot");
073: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
074: AdminClientUtil.SEARCH_ROBOT_MBEAN_TYPE, path);
075:
076: Object[] params = { domain, newsite, depth, database };
077: String[] signature = { "java.lang.Boolean",
078: "java.lang.String", "java.lang.String",
079: "java.lang.String" };
080:
081: siteID = (String) getMBeanServerConnection().invoke(on,
082: "createSite", params, signature);
083:
084: } catch (Exception e) {
085: log(Level.SEVERE,
086: "CreateRobotSiteBean.createRobotSite() failed to create the robot site "
087: + newsite, e);
088: }
089:
090: log(Level.INFO, "CreateRobotSiteBean created site id " + siteID);
091: return "gotoRobotSitesHome";
092: }
093:
094: public String cancel() {
095: return "gotoRobotSitesHome";
096: }
097:
098: public void validateSite(FacesContext fc, UIComponent component,
099: Object value) throws ValidatorException {
100:
101: String sitename = value.toString();
102: String msgKey = "";
103: try {
104: LinkedList path = new LinkedList();
105: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
106: path
107: .addFirst((String) getSessionAttribute("search.server.selected"));
108: path.addFirst("robot");
109: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
110: AdminClientUtil.SEARCH_ROBOT_MBEAN_TYPE, path);
111:
112: Object[] params = { sitename };
113: String[] signature = { "java.lang.String" };
114:
115: msgKey = (String) getMBeanServerConnection().invoke(on,
116: "validateSiteURL", params, signature);
117:
118: } catch (Exception e) {
119: log(Level.SEVERE,
120: "CreateRobotSiteBean.validateSite() failed to validate the site "
121: + sitename, e);
122: }
123:
124: if (!msgKey.equals("")) {
125: String msgString = getLocalizedString(msgKey);
126: FacesMessage msg = new FacesMessage(msgString);
127: throw new ValidatorException(msg);
128: }
129:
130: }
131:
132: /*
133: * Methods to Get/Set Bean elements
134: */
135: public String getNewsite() {
136: return newsite;
137: }
138:
139: public void setNewsite(String s) {
140: this .newsite = s;
141: }
142:
143: public String getNewsiteType() {
144: return newsiteType;
145: }
146:
147: public void setNewsiteType(String type) {
148: this .newsiteType = type;
149: }
150:
151: public String getDepth() {
152: return depth;
153: }
154:
155: public void setDepth(String d) {
156: this .depth = d;
157: }
158:
159: public String getDatabase() {
160: return database;
161: }
162:
163: public void setDatabase(String d) {
164: this .database = d;
165: }
166:
167: /*
168: * Methods for UI options
169: */
170: public Option[] getNewsiteOption() {
171:
172: newsiteOption = new Option[2];
173: newsiteOption[0] = new Option("url",
174: getLocalizedString("robot.site.create.url"));
175: newsiteOption[1] = new Option("domain",
176: getLocalizedString("robot.site.create.domain"));
177: return newsiteOption;
178: }
179:
180: public Option[] getDepthOption() {
181:
182: depthOption = new Option[12];
183: ArrayList values = getStringList(getLocalizedString("robot.site.create.depthlistvalue"));
184: ArrayList labels = getStringList(getLocalizedString("robot.site.create.depthlistlabel"));
185: for (int i = 0; i < 12; i++) {
186: depthOption[i] = new Option((String) values.get(i),
187: (String) labels.get(i));
188: }
189: return depthOption;
190: }
191:
192: /*
193: * Private Methods
194: */
195: private ArrayList getStringList(String s) {
196:
197: ArrayList s_list = new ArrayList();
198: StringTokenizer st = new StringTokenizer(s, ",");
199: while (st.hasMoreTokens()) {
200: String label = st.nextToken();
201: s_list.add(label);
202: }
203: return s_list;
204: }
205:
206: private String getLocalizedString(String key) {
207: return super .getLocalizedString("search", key);
208: }
209:
210: }
|