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 javax.servlet.http.HttpServletRequest;
008:
009: import com.iplanet.jato.RequestContext;
010: import com.iplanet.jato.ViewBeanManager;
011: import com.iplanet.jato.view.View;
012: import com.iplanet.jato.view.ViewBean;
013: import com.iplanet.jato.view.event.DisplayEvent;
014: import com.iplanet.jato.view.event.RequestInvocationEvent;
015: import com.iplanet.jato.view.html.HREF;
016: import com.iplanet.jato.view.html.TextField;
017: import com.iplanet.jato.view.html.StaticTextField;
018: import com.iplanet.jato.model.ModelControlException;
019:
020: import com.iplanet.am.console.components.view.html.IPlanetButton;
021:
022: import com.sun.portal.rewriter.admin.model.RewriterModel;
023: import com.sun.portal.rewriter.admin.model.RewriterModelImpl;
024:
025: import com.iplanet.am.console.base.AMViewBeanBase;
026: import com.iplanet.am.console.components.view.html.MessageBox;
027:
028: /**
029: * The viewbean that provides the create ruleset functionality.
030: */
031: public class CreateRuleViewBean extends AMViewBeanBase {
032:
033: public static final String PAGE_NAME = "CreateRule";
034: public static final String DEFAULT_DISPLAY_URL = "/ps/rwadmin/CreateRule.jsp";
035: public static final String CHILD_CC_MSGBOX = "ccMessageBox";
036: public static final String CHILD_HTMLPAGE_TITLE = "titleHtmlPage";
037: public static final String CHILD_RULESET_TITLE = "createRuleTitle";
038: public static final String CHILD_RULESET_XML = "ruleSetXML";
039: public static final String CHILD_SUBMIT_BUTTON = "submitButton";
040: public static final String CHILD_CANCEL_BUTTON = "cancelButton";
041: public static final String CHILD_SERVICE_TITLE_TEXT = "serviceTitle";
042: public static final String CHILD_SERVICE_TITLE_HREF = "titleHref";
043: public static final String CHILD_TITLE_ACTION_TEXT = "titleAction";
044:
045: private RewriterModel model = null;
046:
047: /**
048: * Default Constructor
049: */
050: public CreateRuleViewBean() {
051: super (PAGE_NAME);
052: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
053: registerChildren();
054: }
055:
056: /**
057: * Creates the child view objects for this viewbean.
058: * @param name the name of the child view object to be created.
059: * @return the child view object.
060: */
061: protected View createChild(String name) {
062: View child = null;
063: if (name.equals(CHILD_CC_MSGBOX)) {
064: child = new MessageBox(this , CHILD_CC_MSGBOX, "");
065: } else if (name.equals(CHILD_HTMLPAGE_TITLE)) {
066: child = new StaticTextField(this , CHILD_HTMLPAGE_TITLE, "");
067: } else if (name.equals(CHILD_SERVICE_TITLE_HREF)) {
068: child = new HREF(this , CHILD_SERVICE_TITLE_HREF, "");
069: } else if (name.equals(CHILD_SERVICE_TITLE_TEXT)) {
070: child = new StaticTextField(this , CHILD_SERVICE_TITLE_TEXT,
071: "");
072: } else if (name.equals(CHILD_TITLE_ACTION_TEXT)) {
073: child = new StaticTextField(this , CHILD_TITLE_ACTION_TEXT,
074: "");
075: } else if (name.equals(CHILD_RULESET_TITLE)) {
076: child = new StaticTextField(this , CHILD_RULESET_TITLE, "");
077: } else if (name.equals(CHILD_RULESET_XML)) {
078: child = new TextField(this , CHILD_RULESET_XML, "", null);
079: } else if (name.equals(CHILD_SUBMIT_BUTTON)) {
080: child = new IPlanetButton(this , CHILD_SUBMIT_BUTTON, "");
081: } else if (name.equals(CHILD_CANCEL_BUTTON)) {
082: child = new IPlanetButton(this , CHILD_CANCEL_BUTTON, "");
083: } else {
084: child = super .createChild(name);
085: }
086: return child;
087: }
088:
089: /**
090: * To register all the child view objects and their classes.
091: */
092: protected void registerChildren() {
093: super .registerChildren();
094: registerChild(CHILD_CC_MSGBOX, MessageBox.class);
095: registerChild(CHILD_SERVICE_TITLE_HREF, HREF.class);
096: registerChild(CHILD_SERVICE_TITLE_TEXT, StaticTextField.class);
097: registerChild(CHILD_TITLE_ACTION_TEXT, StaticTextField.class);
098: registerChild(CHILD_RULESET_XML, TextField.class);
099: registerChild(CHILD_SUBMIT_BUTTON, IPlanetButton.class);
100: registerChild(CHILD_CANCEL_BUTTON, IPlanetButton.class);
101: }
102:
103: /**
104: * begins displaying page. we set the required information
105: *
106: * @param event display event
107: * @throws ModelControlException if problem access value of component
108: */
109: public void beginDisplay(DisplayEvent event)
110: throws ModelControlException {
111: RewriterModel rwm = getModel(getRequestContext().getRequest());
112: setChildValues(rwm);
113: setDisplayFieldValue(CHILD_HTMLPAGE_TITLE, rwm
114: .getLocalizedString("HTMLPage.title"));
115: setDisplayFieldValue(CHILD_SERVICE_TITLE_TEXT, rwm
116: .getLocalizedString("CreateRuleJSP.serviceTitle"));
117: setDisplayFieldValue(CHILD_TITLE_ACTION_TEXT, rwm
118: .getLocalizedString("CreateRuleJSP.titleAction"));
119: setDisplayFieldValue(CHILD_RULESET_TITLE, rwm
120: .getLocalizedString("CreateRuleJSP.title"));
121: setDisplayFieldValue(CHILD_SUBMIT_BUTTON, rwm
122: .getLocalizedString("CreateRuleJSP.submitButton"));
123: setDisplayFieldValue(CHILD_CANCEL_BUTTON, rwm
124: .getLocalizedString("CreateRuleJSP.cancelButton"));
125: MessageBox msgBox = (MessageBox) getDisplayField(CHILD_CC_MSGBOX);
126: if (!msgBox.isVisible()) {
127: String ruleXMLFromTemplate = rwm.getRulesetXMLTemplate();
128: if (!ruleXMLFromTemplate.equals("")) {
129: setDisplayFieldValue(CHILD_RULESET_XML,
130: ruleXMLFromTemplate);
131: } else {
132: msgBox
133: .setTitle(rwm
134: .getLocalizedString("createruleerrormsgbox.title"));
135: msgBox
136: .setMessage(rwm
137: .getLocalizedString("createruleerrormsgbox.msg"));
138: msgBox.setType(0);
139: msgBox.setVisible(true);
140: }
141: }
142:
143: setDisplayFieldValue(HELP_DOC_URL, rwm
144: .getLocalizedString("help.toc"));
145: setDisplayFieldValue(HELP_ANCHOR_TAG, rwm.getHelpUrl(rwm
146: .getLocalizedString("CreateRuleJSP.help")));
147: }
148:
149: /**
150: * Returns the model object for the create rule UI.
151: * @return the model object for the create rule UI.
152: */
153: public RewriterModel getModel(HttpServletRequest req) {
154: if (model == null) {
155: model = (RewriterModel) new RewriterModelImpl(req);
156: }
157: return model;
158: }
159:
160: /**
161: * Handles the event to finish creating a ruleset XML.
162: * @param event the event to finish creating a ruleset XML.
163: * @exception throws ModelControlException when error(s) occurred.
164: */
165: public void handleSubmitButtonRequest(RequestInvocationEvent event)
166: throws ModelControlException, Exception {
167:
168: /* Gets the model object of this viewbean. */
169: RewriterModel model = getModel(getRequestContext().getRequest());
170: String xml = (String) getDisplayFieldValue(CHILD_RULESET_XML);
171: try {
172: if (!model.isCreateOverwrite(xml)) {
173: model.saveRulesetXML(xml, false);
174: /* Returns control back to the select rule UI. */
175: ViewBean vb = getViewBean(SelectRuleViewBean.class);
176: vb.forwardTo(getRequestContext());
177: } else {
178: MessageBox msgBox = (MessageBox) getDisplayField(CHILD_CC_MSGBOX);
179: msgBox.setType(0);
180: msgBox
181: .setTitle(model
182: .getLocalizedString("duplicaterulenameerr.title"));
183: msgBox
184: .setMessage(model
185: .getLocalizedString("duplicaterulenameerr.msg"));
186: msgBox.setVisible(true);
187: forwardTo();
188: }
189: } catch (Exception e) {
190: MessageBox msgBox = (MessageBox) getDisplayField(CHILD_CC_MSGBOX);
191: msgBox.setTitle(model
192: .getLocalizedString("saveruleerrormsgbox.title"));
193: msgBox.setMessage(e.getMessage());
194: msgBox.setType(0);
195: msgBox.setVisible(true);
196: /* Redisplays to include the error message box */
197: forwardTo();
198: }
199: }
200:
201: /**
202: * Handles the event to cancel creating a ruleset XML.
203: * @param event the event to cancel creating a ruleset XML.
204: * @exception throws ModelControlException when error(s) occurred.
205: */
206: public void handleCancelButtonRequest(RequestInvocationEvent event) {
207: ViewBean vb = getViewBean(SelectRuleViewBean.class);
208: vb.forwardTo(getRequestContext());
209: }
210:
211: /**
212: * Handles the event to display rulesets.
213: * @param event the event to display available ruleset.
214: * @exception throws ModelControlException when error(s) occurred.
215: */
216: public void handleTitleHrefRequest(RequestInvocationEvent event)
217: throws ModelControlException {
218:
219: /* Forward to the edit rule viewbean. */
220: ViewBean vb = getViewBean(SelectRuleViewBean.class);
221: vb.forwardTo(getRequestContext());
222: }
223:
224: }
|