001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.search.admin;
007:
008: import java.net.URL;
009: import java.io.IOException;
010: import java.util.logging.Logger;
011: import java.util.logging.Level;
012:
013: import com.sun.portal.search.admin.CSViewBeanBase;
014:
015: import javax.servlet.http.HttpServletRequest;
016: import javax.servlet.http.HttpServletResponse;
017:
018: import com.iplanet.jato.RequestContext;
019:
020: import com.iplanet.jato.view.event.DisplayEvent;
021: import com.iplanet.jato.view.event.ChildDisplayEvent;
022: import com.iplanet.jato.view.event.RequestInvocationEvent;
023:
024: import com.iplanet.jato.view.html.StaticTextField;
025: import com.iplanet.jato.view.html.TextField;
026: import com.iplanet.jato.view.html.CheckBox;
027: import com.iplanet.jato.view.html.Button;
028: import com.iplanet.jato.view.html.ComboBox;
029: import com.iplanet.jato.view.html.RadioButtonGroup;
030:
031: import com.iplanet.jato.view.html.Option;
032: import com.iplanet.jato.view.html.OptionList;
033:
034: import com.iplanet.jato.view.View;
035: import com.iplanet.jato.view.ViewBean;
036: import com.iplanet.jato.view.ViewBeanBase;
037:
038: import com.iplanet.jato.ViewBeanManager;
039:
040: import com.iplanet.jato.model.*;
041:
042: import com.sun.portal.search.robot.*;
043: import com.sun.portal.log.common.PortalLogger;
044: import com.iplanet.am.console.components.view.html.IPlanetButton;
045:
046: /**
047: * iPS admin console view bean: TODO
048: */
049: public class SitesViewBean extends CSViewBeanBase {
050: public static final String DEFAULT_DISPLAY_URL = "/ps/searchadmin/Sites.jsp";
051: public static final String PAGE_NAME = "Sites";
052: public static final String NEW_SITE_SECTION = "NewSiteSection";
053: public static final String ADD_COMBO = "AddCombo";
054: public static final String URL_TEXT = "URLText";
055: public static final String DEPTH_COMBO = "DepthCombo";
056: public static final String CREATE_BUTTON = "CreateButton";
057: public static final String CREATEEDIT_BUTTON = "CreateEditButton";
058:
059: public static final String SITELIST_SECTION = "SitesListSection";
060: public static final String SITELIST_VIEW = "SitesList";
061: public static final String NEWSITE_BUTTON = "NewSiteButton";
062: public static final String DELETE_BUTTON = "DeleteButton";
063: public static final String SUBMIT_BUTTON = "SubmitButton";
064: public static final String RESET_BUTTON = "ResetButton";
065: public static final String CANCEL_BUTTON = "CancelButton";
066:
067: private boolean isNewSite = false;
068:
069: // Create a Logger for this class
070: private static Logger debugLogger = PortalLogger
071: .getLogger(SitesViewBean.class);
072:
073: /**
074: * constructor
075: *
076: * @param PageName of this view bean
077: * @param displayURL default display URL
078: */
079: public SitesViewBean() {
080: super (PAGE_NAME);
081: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
082: registerChildren();
083: }
084:
085: /**
086: * register child component
087: */
088: protected void registerChildren() {
089: registerChild(ADD_COMBO, ComboBox.class);
090: registerChild(URL_TEXT, TextField.class);
091: registerChild(DEPTH_COMBO, ComboBox.class);
092: registerChild(CREATE_BUTTON, IPlanetButton.class);
093: registerChild(CREATEEDIT_BUTTON, IPlanetButton.class);
094: registerChild(SITELIST_VIEW, SitesListView.class);
095: registerChild(NEWSITE_BUTTON, IPlanetButton.class);
096: registerChild(DELETE_BUTTON, IPlanetButton.class);
097: registerChild(SUBMIT_BUTTON, IPlanetButton.class);
098: registerChild(RESET_BUTTON, IPlanetButton.class);
099: registerChild(CANCEL_BUTTON, IPlanetButton.class);
100:
101: }
102:
103: /**
104: * create child component
105: *
106: * @param name of component
107: * @return child component
108: */
109: protected View createChild(String name) {
110: View Headerchild = super .createChild(name);
111: if (Headerchild != null)
112: return Headerchild;
113: if (name.equals(ADD_COMBO)) {
114: ComboBox child = new ComboBox(this , ADD_COMBO, "");
115: OptionList AddOptions = new OptionList(
116: getLocalizedStringArray("sites.type.options", ","),
117: new String[] { "URL", "domain" }); // values
118: child.setOptions(AddOptions);
119: return child;
120: }
121: if (name.equals(URL_TEXT)) {
122: return new TextField(this , URL_TEXT, "");
123: }
124: if (name.equals(DEPTH_COMBO)) {
125: String depth = CSConfig.getRobotConfig().processConf
126: .get("depth");
127: if (depth == null) {
128: depth = "-1";
129: }
130: ComboBox child = new ComboBox(this , DEPTH_COMBO, depth);
131: OptionList DepthOptions = new OptionList(
132: getLocalizedStringArray(
133: "sites.depth.options.label", ","),
134: getLocalizedStringArray(
135: "sites.depth.options.value", ","));
136: child.setOptions(DepthOptions);
137: return child;
138: }
139: if (name.equals(CREATE_BUTTON)) {
140: return new IPlanetButton(this , CREATE_BUTTON, "");
141: }
142: if (name.equals(CREATEEDIT_BUTTON)) {
143: return new IPlanetButton(this , CREATEEDIT_BUTTON, "");
144: }
145: if (name.equals(SITELIST_VIEW)) {
146: return new SitesListView(this , SITELIST_VIEW);
147: }
148: if (name.equals(NEWSITE_BUTTON)) {
149: return new IPlanetButton(this , NEWSITE_BUTTON, "");
150: }
151: if (name.equals(DELETE_BUTTON)) {
152: return new IPlanetButton(this , DELETE_BUTTON, "");
153: }
154: if (name.equals(SUBMIT_BUTTON)) {
155: return new IPlanetButton(this , SUBMIT_BUTTON, "");
156: }
157: if (name.equals(RESET_BUTTON)) {
158: return new IPlanetButton(this , RESET_BUTTON, "");
159: }
160: if (name.equals(CANCEL_BUTTON)) {
161: return new IPlanetButton(this , CANCEL_BUTTON, "");
162: }
163:
164: throw new IllegalArgumentException("Invalid child name ["
165: + name + "]");
166: }
167:
168: /** begin displaying page. we set the required information
169: *
170: * @param event display event
171: * @throws ModelControlException if problem access value of component
172: */
173: public void beginDisplay(DisplayEvent event) {
174: setPageEncoding();
175: setDisplayFieldValue(SUBMIT_BUTTON,
176: getLocalizedString("submit.text"));
177: setDisplayFieldValue(NEWSITE_BUTTON,
178: getLocalizedString("new.text"));
179: setDisplayFieldValue(DELETE_BUTTON,
180: getLocalizedString("delete.text"));
181: setDisplayFieldValue(RESET_BUTTON,
182: getLocalizedString("reset.text"));
183: setDisplayFieldValue(CANCEL_BUTTON,
184: getLocalizedString("cancel.text"));
185: setDisplayFieldValue(CREATEEDIT_BUTTON,
186: getLocalizedString("createsite.edit.text"));
187: setDisplayFieldValue(CREATE_BUTTON,
188: getLocalizedString("createsite.text"));
189: RobotConfig rc = CSConfig.getRobotConfig();
190: if (rc.numRuleset() == 0) {
191: IPlanetButton child = (IPlanetButton) getChild(DELETE_BUTTON);
192: child.setEnable(false);
193: }
194:
195: }
196:
197: public boolean beginNewSiteSectionDisplay(ChildDisplayEvent event) {
198: return isNewSite;
199: }
200:
201: public boolean beginSitesListSectionDisplay(ChildDisplayEvent event) {
202: return !isNewSite;
203: }
204:
205: public boolean beginListTableDisplay(ChildDisplayEvent event) {
206: RobotConfig rc = CSConfig.getRobotConfig();
207: return rc.numRuleset() > 0;
208: }
209:
210: public boolean beginEmptyListDisplay(ChildDisplayEvent event) {
211: RobotConfig rc = CSConfig.getRobotConfig();
212: return rc.numRuleset() == 0;
213: }
214:
215: private String CreateSite() {
216: RobotConfig rc = CSConfig.getRobotConfig();
217: String typeText = (String) this .getDisplayFieldValue(ADD_COMBO);
218: String urlText = (String) this .getDisplayFieldValue(URL_TEXT);
219: String depthText = (String) this
220: .getDisplayFieldValue(DEPTH_COMBO);
221: int depth = Integer.parseInt(depthText);
222: String newCreatedID = null;
223: String newRuleID = null;
224: try {
225: boolean isDomain = typeText.compareToIgnoreCase("DOMAIN") == 0;
226: URL url = null;
227: if (isDomain) {
228: FilterRuleset frs = rc
229: .findFiletrRulesetHasDomain(urlText
230: .substring(2));
231: if (frs != null) {
232: this .errorMessage = getLocalizedString("createsite.error.existdomain")
233: + frs.nickname;
234: return null;
235: }
236: url = new URL("http", "www" + urlText.substring(1), 80,
237: "/");
238: } else {
239: FilterRuleset frs = rc
240: .findFiletrRulesetHasStartingPoint(urlText);
241: if (frs != null) {
242: this .errorMessage = getLocalizedString("createsite.error.existstartingpoint")
243: + frs.nickname;
244: return null;
245: }
246: url = new URL(urlText);
247: }
248: String path = url.getPath();
249: int n = path.lastIndexOf('/');
250: if (n >= 0 && path.length() > 1) {
251: String path_filter = path.substring(0, n + 1);
252: String file_name = path.substring(n + 1);
253: if (file_name.indexOf('.') < 0) {
254: path_filter = path;
255: }
256: debugLogger.log(Level.FINER, "PSSH_CSPSA0113",
257: path_filter);
258: newRuleID = rc.newPathFilterRule(path_filter);
259: }
260:
261: debugLogger.log(Level.FINER, "PSSH_CSPSA0114",
262: new String[] { url.toString(),
263: String.valueOf(depth), newRuleID });
264: FilterRuleset frs = rc.newRuleset(url, depth, isDomain,
265: newRuleID);
266: if (frs != null) {
267: newCreatedID = frs.id;
268: }
269: rc.updateFile();
270: } catch (java.net.MalformedURLException e) {
271: debugLogger.log(Level.INFO, "PSSH_CSPSA0115", urlText);
272: }
273: return newCreatedID;
274: }
275:
276: /**
277: * handles invocation of view bean
278: *
279: * @param event request invocation event
280: */
281: public void handleCreateButtonRequest(RequestInvocationEvent event) {
282: if (CreateSite() == null) {
283: isNewSite = true;
284: }
285: forwardTo();
286: }
287:
288: /**
289: * handles invocation of view bean
290: *
291: * @param event request invocation event
292: */
293: public void handleCreateEditButtonRequest(
294: RequestInvocationEvent event) {
295: String id = CreateSite();
296: if (id != null) {
297: HttpServletResponse response = getRequestContext()
298: .getResponse();
299: try {
300: response.sendRedirect("Site?id=" + id);
301: } catch (IOException e) {
302: //TOFIX: handle this
303: }
304: } else {
305: isNewSite = true;
306: forwardTo();
307: }
308: }
309:
310: public void handleSubmitButtonRequest(RequestInvocationEvent event) {
311: SitesListView child = (SitesListView) getChild(SITELIST_VIEW);
312: try {
313: ModelExecutionContext modExe = new ModelExecutionContextBase(
314: ModelExecutionContext.OPERATION_UPDATE);
315: child.executeAutoUpdatingModels(modExe);
316: } catch (ModelControlException e) {
317: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
318: .getMessage());
319: }
320: forwardTo();
321: }
322:
323: public void handleResetButtonRequest(RequestInvocationEvent event) {
324: forwardTo();
325: }
326:
327: public void handleDeleteButtonRequest(RequestInvocationEvent event) {
328: SitesListView child = (SitesListView) getChild(SITELIST_VIEW);
329: try {
330: ModelExecutionContext modExe = new ModelExecutionContextBase(
331: ModelExecutionContext.OPERATION_DELETE);
332: child.executeAutoDeletingModels(modExe);
333: } catch (ModelControlException e) {
334: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
335: .getMessage());
336: }
337: forwardTo();
338: }
339:
340: public void handleNewSiteButtonRequest(RequestInvocationEvent event) {
341: isNewSite = true;
342: forwardTo();
343: }
344:
345: }
|