001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.rewriter.admin;
006:
007: import java.util.Set;
008: import java.util.List;
009: import java.util.Map;
010: import java.util.Iterator;
011: import java.util.Collections;
012:
013: import javax.servlet.http.HttpServletRequest;
014:
015: import com.iplanet.jato.RequestContext;
016: import com.iplanet.jato.NavigationException;
017: import com.iplanet.jato.view.View;
018: import com.iplanet.jato.view.ViewBean;
019: import com.iplanet.jato.view.html.StaticTextField;
020:
021: import com.iplanet.am.console.base.AMViewBeanBase;
022: import com.iplanet.am.console.components.view.html.MessageBox;
023:
024: import com.sun.portal.rewriter.admin.model.RewriterModel;
025: import com.sun.portal.rewriter.admin.model.RewriterModelImpl;
026:
027: /**
028: * The viewbean that provides the delete ruleset functionality.
029: */
030: public class DeleteRuleViewBean extends AMViewBeanBase {
031:
032: public static final String PAGE_NAME = "DeleteRule";
033: public static final String DEFAULT_DISPLAY_URL = "/ps/rwadmin/DeleteRule.jsp";
034: public static final String CHILD_HTMLPAGE_TITLE = "titleHtmlPage";
035: public static final String CHILD_CC_MSGBOX = "ccMessageBox";
036:
037: private RewriterModel model = null;
038:
039: /**
040: * Default constructor
041: *
042: */
043: public DeleteRuleViewBean() {
044: super (PAGE_NAME);
045: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
046: registerChildren();
047: }
048:
049: /**
050: * Creates the child view objects for this viewbean.
051: * @param name the name of the child view object to be created.
052: * @return the child view object.
053: */
054: protected View createChild(String name) {
055: if (name.equals(CHILD_CC_MSGBOX)) {
056: return new MessageBox(this , CHILD_CC_MSGBOX, "");
057: } else if (name.equals(CHILD_HTMLPAGE_TITLE)) {
058: return new StaticTextField(this , CHILD_HTMLPAGE_TITLE,
059: "HTMLPage.title");
060: } else {
061: //Bug#4879730
062: return super .createChild(name);
063: }
064: }
065:
066: /**
067: * To register all the child view objects and their classes.
068: */
069: protected void registerChildren() {
070: registerChild(CHILD_CC_MSGBOX, MessageBox.class);
071: }
072:
073: /**
074: * Returns the model object for the create rule UI.
075: * @return the model object for the create rule UI.
076: */
077: public RewriterModel getModel(HttpServletRequest req) {
078: if (model == null) {
079: model = (RewriterModel) new RewriterModelImpl(req);
080: }
081: return model;
082: }
083:
084: public void forwardTo(RequestContext reqContext)
085: throws NavigationException {
086: setRequestContext(reqContext);
087: RewriterModel m = getModel(reqContext.getRequest());
088: List rules = m
089: .getFromSession(SelectRuleViewBean.SELECTED_RULES);
090: Map failedRules = m.deleteRules(rules);
091: m.storeToSession(SelectRuleViewBean.SELECTED_RULES,
092: Collections.EMPTY_LIST);
093:
094: if (failedRules.isEmpty()) {
095: ViewBean vb = getViewBean(SelectRuleViewBean.class);
096: vb.forwardTo(reqContext);
097: } else {
098: /* Display an error msgbox when excetion occurres */
099: MessageBox msgbox = (MessageBox) getDisplayField(CHILD_CC_MSGBOX);
100: StringBuffer sb = new StringBuffer("<ul>");
101: Set errorsSet = failedRules.keySet();
102: Iterator it = errorsSet.iterator();
103: while (it.hasNext()) {
104: String ruleName = (String) it.next();
105: Exception e = (Exception) failedRules.get(ruleName);
106: sb.append("<li>");
107: sb.append(ruleName);
108: sb.append(" - ");
109: sb.append(e.getLocalizedMessage());
110: sb.append("</li>");
111: }
112: sb.append("</ul>");
113: msgbox.setType(MessageBox.TYPE_ERROR);
114: msgbox.setMessage(sb.toString());
115: msgbox.setTitle(m
116: .getLocalizedString("deleteruleerrormsgbox.title"));
117: msgbox
118: .addButton(
119: m
120: .getLocalizedString("deleteruleerrormsgbox.oklabel"),
121: getModuleURL() + "/"
122: + SelectRuleViewBean.PAGE_NAME);
123: msgbox.setVisible(true);
124: super.forwardTo(reqContext);
125: }
126: }
127:
128: }
|