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.List;
008: import java.util.ArrayList;
009:
010: import javax.servlet.http.HttpServletRequest;
011:
012: import com.iplanet.jato.model.ModelControlException;
013: import com.iplanet.jato.RequestContext;
014: import com.iplanet.jato.ViewBeanManager;
015: import com.iplanet.jato.view.event.DisplayEvent;
016: import com.iplanet.jato.view.event.ChildDisplayEvent;
017: import com.iplanet.jato.view.event.RequestInvocationEvent;
018: import com.iplanet.jato.view.html.StaticTextField;
019: import com.iplanet.jato.view.html.CheckBox;
020: import com.iplanet.jato.view.View;
021: import com.iplanet.jato.view.ViewBean;
022:
023: import com.iplanet.am.console.base.AMMessageViewBean;
024: import com.iplanet.am.console.base.AMViewBeanBase;
025: import com.iplanet.am.console.components.view.html.MessageBox;
026:
027: import com.iplanet.am.console.components.view.html.IPlanetButton;
028:
029: import com.sun.portal.rewriter.admin.model.RewriterModel;
030: import com.sun.portal.rewriter.admin.model.RewriterModelImpl;
031:
032: /**
033: * The viewbean that provides the select Rule admin UI. Lists all the
034: * available ruleset(s) and allow the administrator to delete or modify
035: * them. Also allows the administrators to create new ruleset. The viewbean
036: * ,dmfkldfm
037: * works with other viewbeans to support the above functionality.
038: */
039: public class SelectRuleViewBean extends AMViewBeanBase {
040:
041: public static final String PAGE_NAME = "SelectRule";
042: public static final String DEFAULT_DISPLAY_URL = "/ps/rwadmin/SelectRule.jsp";
043: public static final String SELECTED_RULES = "ps-rwadmin-session-attrs";
044: public static final String CHILD_CC_MSGBOX = "ccMessageBox";
045: public static final String CHILD_HTMLPAGE_TITLE = "titleHtmlPage";
046: public static final String CHILD_TILEDVIEW = "TiledView1";
047: public static final String CHILD_DELETE_RULE_BUTTON = "deleteRuleButton";
048: public static final String CHILD_CREATE_RULE_BUTTON = "createRuleButton";
049: public static final String CHILD_UPLOAD_RULE_BUTTON = "uploadRuleButton";
050: public static final String CHILD_TITLE_FIELD = "serviceTitle";
051: public static final String CHILD_RULE_LABEL = "ruleLabel";
052: public static final String CHILD_NAME_LABEL = "nameLabel";
053: public static final String CHILD_ACTION_LABEL = "actionLabel";
054: public static final String CHILD_JAVASCRIPT_MSG = "alertMessage";
055: public static final String CHILD_UPLOADURL = "uploadURL";
056:
057: private String url = "";
058:
059: private RewriterModel model;
060:
061: /**
062: * Default constructor.
063: */
064: public SelectRuleViewBean() {
065: super (PAGE_NAME);
066: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
067: registerChildren();
068: }
069:
070: /**
071: * Creates the child view objects for this viewbean.
072: * @param name the name of the child view object to be created.
073: * @return the child view object.
074: */
075: protected View createChild(String name) {
076: View child = null;
077: if (name.equals(CHILD_CC_MSGBOX)) {
078: child = new MessageBox(this , CHILD_CC_MSGBOX, "");
079: } else if (name.equals(CHILD_TITLE_FIELD)) {
080: child = new StaticTextField(this , CHILD_TITLE_FIELD, "");
081: } else if (name.equals(CHILD_RULE_LABEL)) {
082: child = new StaticTextField(this , CHILD_RULE_LABEL, "");
083: } else if (name.equals(CHILD_NAME_LABEL)) {
084: child = new StaticTextField(this , CHILD_NAME_LABEL, "");
085: } else if (name.equals(CHILD_UPLOADURL)) {
086: child = new StaticTextField(this , CHILD_UPLOADURL, "");
087: } else if (name.equals(CHILD_ACTION_LABEL)) {
088: child = new StaticTextField(this , CHILD_ACTION_LABEL, "");
089: } else if (name.equals(CHILD_HTMLPAGE_TITLE)) {
090: child = new StaticTextField(this , CHILD_HTMLPAGE_TITLE, "");
091: } else if (name.equals(CHILD_JAVASCRIPT_MSG)) {
092: child = new StaticTextField(this , CHILD_JAVASCRIPT_MSG, "");
093: } else if (name.equals(CHILD_TILEDVIEW)) {
094: child = new SelectRuleTiledView(this , CHILD_TILEDVIEW);
095: } else if (name.equals(CHILD_DELETE_RULE_BUTTON)) {
096: child = new IPlanetButton(this , CHILD_DELETE_RULE_BUTTON,
097: "");
098: } else if (name.equals(CHILD_CREATE_RULE_BUTTON)) {
099: child = new IPlanetButton(this , CHILD_CREATE_RULE_BUTTON,
100: "");
101: } else if (name.equals(CHILD_UPLOAD_RULE_BUTTON)) {
102: child = new IPlanetButton(this , CHILD_UPLOAD_RULE_BUTTON,
103: "");
104: } else {
105: child = super .createChild(name);
106: }
107: return child;
108: }
109:
110: /**
111: * To register all the child view objects and their classes.
112: */
113: protected void registerChildren() {
114: super .registerChildren();
115: registerChild(CHILD_CC_MSGBOX, MessageBox.class);
116: registerChild(CHILD_TITLE_FIELD, StaticTextField.class);
117: registerChild(CHILD_RULE_LABEL, StaticTextField.class);
118: registerChild(CHILD_NAME_LABEL, StaticTextField.class);
119: registerChild(CHILD_UPLOADURL, StaticTextField.class);
120: registerChild(CHILD_JAVASCRIPT_MSG, StaticTextField.class);
121: registerChild(CHILD_ACTION_LABEL, StaticTextField.class);
122: registerChild(CHILD_DELETE_RULE_BUTTON, IPlanetButton.class);
123: registerChild(CHILD_UPLOAD_RULE_BUTTON, IPlanetButton.class);
124: registerChild(CHILD_CREATE_RULE_BUTTON, IPlanetButton.class);
125: registerChild(CHILD_TILEDVIEW, SelectRuleTiledView.class);
126: }
127:
128: /**
129: * begins displaying page. we set the required information
130: *
131: * @param event display event
132: * @throws ModelControlException if problem access value of component
133: */
134: public void beginDisplay(DisplayEvent event)
135: throws ModelControlException {
136: RewriterModel rwm = getModel(getRequestContext().getRequest());
137: setChildValues(rwm);
138: String pgEncoding = (String) getDisplayFieldValue(AMViewBeanBase.PAGE_ENCODING);
139: String reqURI = getRequestContext().getRequest()
140: .getRequestURI();
141: url = reqURI.substring(0, reqURI.indexOf('/', 1))
142: + "/RuleSetServlet?" + AMViewBeanBase.PAGE_ENCODING
143: + "=" + pgEncoding + "&action=NEW";
144: setDisplayFieldValue(CHILD_UPLOADURL, rwm
145: .getLocalizedString(url));
146: setDisplayFieldValue(CHILD_TITLE_FIELD, rwm
147: .getLocalizedString("SelectRuleJSP.rewriterLabel"));
148: setDisplayFieldValue(CHILD_RULE_LABEL, rwm
149: .getLocalizedString("SelectRuleJSP.ruleLabel"));
150: setDisplayFieldValue(CHILD_NAME_LABEL, rwm
151: .getLocalizedString("SelectRuleJSP.nameLabel"));
152: setDisplayFieldValue(CHILD_ACTION_LABEL, rwm
153: .getLocalizedString("SelectRuleJSP.actionLabel"));
154: setDisplayFieldValue(CHILD_HTMLPAGE_TITLE, rwm
155: .getLocalizedString("HTMLPage.title"));
156: setDisplayFieldValue(CHILD_JAVASCRIPT_MSG, rwm
157: .getLocalizedString("SelectRuleJSP.javascript.message"));
158: setDisplayFieldValue(CHILD_DELETE_RULE_BUTTON, rwm
159: .getLocalizedString("SelectRuleJSP.deleteRuleButton"));
160: setDisplayFieldValue(CHILD_CREATE_RULE_BUTTON, rwm
161: .getLocalizedString("SelectRuleJSP.createRuleButton"));
162: setDisplayFieldValue(CHILD_UPLOAD_RULE_BUTTON, rwm
163: .getLocalizedString("SelectRuleJSP.uploadRuleButton"));
164:
165: setDisplayFieldValue(HELP_DOC_URL, rwm
166: .getLocalizedString("help.toc"));
167: setDisplayFieldValue(HELP_ANCHOR_TAG, rwm.getHelpUrl(rwm
168: .getLocalizedString("SelectRuleJSP.help")));
169: }
170:
171: /**
172: * Returns the model object used by this viewbean.
173: * @return the model object that is tied to this viewbean.
174: */
175: public RewriterModel getModel(HttpServletRequest req) {
176: if (model == null) {
177: model = new RewriterModelImpl(req);
178: }
179: return model;
180: }
181:
182: public boolean beginDeleteRuleButtonBlockDisplay(
183: ChildDisplayEvent event) {
184: RewriterModel rwm = getModel(getRequestContext().getRequest());
185: List rules = rwm.getRuleSetNames();
186: return (rules.size() > 0);
187: }
188:
189: /*
190: * Handles the event when the delete rule button is clicked.
191: * @param the JATO event object
192: * @exception throws ModelControlException when error(s) occurred.
193: */
194: public void handleDeleteRuleButtonRequest(
195: RequestInvocationEvent event) throws ModelControlException {
196:
197: RewriterModel rwm = getModel(getRequestContext().getRequest());
198: SelectRuleTiledView tileView = (SelectRuleTiledView) getChild(CHILD_TILEDVIEW);
199: int tiles = tileView.getNumTiles();
200: List selections = new ArrayList();
201:
202: /* Loop through all the tiles and get the ruleset name(s)
203: * that are checked.
204: */
205: for (int i = 0; i < tiles; i++) {
206: CheckBox chkBox = (CheckBox) tileView.getChild(
207: SelectRuleTiledView.CHILD_CB_SELECT_RULE, i);
208: String value = (String) chkBox.getValue();
209: if (value.equals("true")) {
210: value = (String) tileView
211: .getDisplayFieldValue(SelectRuleTiledView.CHILD_HIDDEN_RULE_NAME);
212: selections.add(value);
213: }
214: }
215:
216: /* Display a recoverable error if no ruleset is selected */
217: if (selections.size() == 0) {
218: MessageBox msgBox = (MessageBox) getDisplayField(CHILD_CC_MSGBOX);
219: msgBox.setTitle(rwm
220: .getLocalizedString("noselectionmsgbox.title"));
221: msgBox.setMessage(rwm
222: .getLocalizedString("noselectionmsgbox.msg"));
223: msgBox.setType(MessageBox.TYPE_ERROR);
224: msgBox.setVisible(true);
225:
226: /* Redisplay the page with the error */
227: forwardTo();
228: } else {
229: StringBuffer sb = new StringBuffer("<ul>");
230:
231: /* Confirm the delete operation using common msgbox */
232: RequestContext rc = getRequestContext();
233: ViewBeanManager mgr = rc.getViewBeanManager();
234: AMMessageViewBean amMsgVB = (AMMessageViewBean) mgr
235: .getViewBean(com.iplanet.am.console.base.AMMessageViewBean.class);
236: amMsgVB.setMessageType(MessageBox.TYPE_QUESTION);
237:
238: /* Loop through the selected ruleset name(s) */
239: for (int i = 0; i < selections.size(); i++) {
240: sb.append("<li>");
241: sb.append((String) selections.get(i));
242: sb.append("</li>");
243: }
244:
245: amMsgVB.setTitle(rwm
246: .getLocalizedString("deleteconfirmmsgbox.title"));
247: amMsgVB.setMessage(sb.toString());
248:
249: amMsgVB
250: .addButton(
251: rwm
252: .getLocalizedString("deleteconfirmmsgbox.yeslabel"),
253: getModuleURL() + "/"
254: + DeleteRuleViewBean.PAGE_NAME);
255: amMsgVB
256: .addButton(
257: rwm
258: .getLocalizedString("deleteconfirmmsgbox.nolabel"),
259: getModuleURL() + "/"
260: + SelectRuleViewBean.PAGE_NAME);
261:
262: /* Store the selected ruleset name(s) into session */
263: rwm.storeToSession(SELECTED_RULES, selections);
264: amMsgVB.forwardTo(rc);
265: }
266: }
267:
268: /*
269: * Handles the event when the create rule button is clicked.
270: * @param the JATO event object
271: */
272: public void handleCreateRuleButtonRequest(
273: RequestInvocationEvent event) {
274:
275: /* Forward to the create rule viewbean */
276: ViewBean vb = getViewBean(CreateRuleViewBean.class);
277: vb.forwardTo(getRequestContext());
278: }
279:
280: public String getUpldJspURL() {
281: return url;
282: }
283:
284: }
|