001: /**
002: * Copyright 2002 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: *
013: * @ Author Bhavanishankar
014: */package com.sun.portal.netlet.admin;
015:
016: // JDK classes
017:
018: import java.io.Serializable;
019: import java.text.MessageFormat;
020: import java.util.HashMap;
021: import java.util.HashSet;
022: import java.util.Iterator;
023: import java.util.Map;
024: import java.util.NoSuchElementException;
025: import java.util.Set;
026: import java.util.StringTokenizer;
027: import java.util.Vector;
028:
029: import javax.servlet.http.HttpServletRequest;
030:
031: import com.iplanet.am.console.base.AMMessageViewBean;
032: import com.iplanet.am.console.base.AMViewBeanBase;
033: import com.iplanet.am.console.base.AMViewBeanUtils;
034: import com.iplanet.am.console.components.view.html.IPlanetButton;
035: import com.iplanet.am.console.components.view.html.MessageBox;
036: import com.iplanet.jato.model.ModelControlException;
037: import com.iplanet.jato.view.View;
038: import com.iplanet.jato.view.ViewBean;
039: import com.iplanet.jato.view.event.ChildDisplayEvent;
040: import com.iplanet.jato.view.event.DisplayEvent;
041: import com.iplanet.jato.view.event.RequestInvocationEvent;
042: import com.iplanet.jato.view.html.CheckBox;
043: import com.iplanet.jato.view.html.HREF;
044: import com.iplanet.jato.view.html.HiddenField;
045: import com.iplanet.jato.view.html.ListBox;
046: import com.iplanet.jato.view.html.OptionList;
047: import com.iplanet.jato.view.html.StaticTextField;
048: import com.iplanet.jato.view.html.TextField;
049: import com.sun.portal.netlet.admin.model.NetletAdminUserProfileModelImpl;
050: import com.sun.portal.netlet.util.NetletConstants;
051:
052: public class EditNetletRuleUserProfileViewBean extends AMViewBeanBase {
053:
054: public static final String PAGE_NAME = "EditNetletRuleUserProfile";
055:
056: public static final String DEFAULT_DISPLAY_URL = "/ps/netletadmin/EditNetletRuleUserProfile.jsp";
057:
058: public static final String PAGE_TITLE = "titleHtmlPage";
059:
060: public static final String PAGE_DESC = "serviceDescription"; // Netlet
061:
062: public static final String PAGE_DESC_HREF = "serviceDescHref";
063:
064: public static final String PAGE_DESC_ACTION = "serviceDescAction"; // >
065: // Edit
066: // Rule
067:
068: public static final String CHILD_RULENAME_LBL = "rulenameLabel";
069:
070: public static final String CHILD_RULENAME = "rulename";
071:
072: public static final String CHILD_ALGORITHMS_LBL = "algorithmsLabel";
073:
074: public static final String CHILD_ALGO_DEFAULT = "algorithmDefault";
075:
076: public static final String CHILD_ALGO_OTHER = "algorithmOther";
077:
078: public static final String CHILD_ALGORITHMS = "algorithms";
079:
080: public static final String CHILD_URL_LBL = "urlLabel";
081:
082: public static final String CHILD_URL = "url";
083:
084: public static final String CHILD_DOWNLOADAPPLET_LBL = "downloadappletLabel";
085:
086: public static final String CHILD_DOWNLOADAPPLET_CB = "downloadappletcb";
087:
088: public static final String CHILD_DOWNLOADAPPLET_NAME = "downloadappletname";
089:
090: public static final String CHILD_EXTEND_LBL = "extendLabel";
091:
092: public static final String CHILD_EXTEND = "extend";
093:
094: public static final String CHILD_PHPLIST_LBL = "phplistLabel";
095:
096: public static final String CHILD_PHPLIST = "phplist";
097:
098: public static final String CHILD_CLIENTPORT_LBL = "clientportLabel";
099:
100: public static final String CHILD_CLIENTPORT = "clientport";
101:
102: public static final String CHILD_TARGETHOST_LBL = "targethostLabel";
103:
104: public static final String CHILD_TARGETHOST = "targethost";
105:
106: public static final String CHILD_TARGETPORT_LBL = "targetportLabel";
107:
108: public static final String CHILD_TARGETPORT = "targetport";
109:
110: public static final String CHILD_SELECTED_ALGOS = "selectedAlgos";
111:
112: public static final String CHILD_RULE_INDEX = "ruleIndex";
113:
114: public static final String CHILD_ERRORMSGS = "errorMessages";
115:
116: public static final String CHILD_SAVE_BTN = "saveButton";
117:
118: public static final String CHILD_CANCEL_BTN = "cancelButton";
119:
120: public static final String CHILD_REMOVE_BTN = "removeButton";
121:
122: public static final String CHILD_ADDTOLIST_BTN = "addtolistButton";
123:
124: private NetletAdminModelManager modelManager = null;
125:
126: private NetletAdminUserProfileModelImpl model = null;
127:
128: private Vector netletRules = null;
129:
130: private int currentRow = -1;
131:
132: public static final String RULE_DELIM = "|";
133:
134: public static final String ALGO_DELIM = "^";
135:
136: private final String SAMPLE_RULE = "MyRule|/ps/sample.html|50000:machinename:80|40000|TARGET|11041|EXTEND";
137:
138: private String userDN = null;
139:
140: /**
141: * Default Constructor
142: */
143: public EditNetletRuleUserProfileViewBean() {
144: super (PAGE_NAME);
145: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
146: registerChildren();
147: }
148:
149: public EditNetletRuleUserProfileViewBean(String pageName) {
150: super (pageName);
151: registerChildren();
152: }
153:
154: /**
155: * Creates the child view objects for this viewbean.
156: *
157: * @param name
158: * the name of the child view object to be created.
159: * @return the child view object.
160: */
161: protected View createChild(String name) {
162: getModelMgr();
163: if (name.equals(PAGE_TITLE)) {
164: return new StaticTextField(this , PAGE_TITLE, modelManager
165: .getString("HTMLPage.title"));
166: } else if (name.equals(PAGE_DESC)) {
167: return new StaticTextField(this , PAGE_DESC, "");
168: } else if (name.equals(PAGE_DESC_HREF)) {
169: return new HREF(this , PAGE_DESC_HREF, "");
170: } else if (name.equals(PAGE_DESC_ACTION)) {
171: return new StaticTextField(this , PAGE_DESC_ACTION,
172: modelManager.getString("editrule.pagetitle"));
173: } else if (name.equals(CHILD_RULENAME_LBL)) {
174: return new StaticTextField(this , CHILD_RULENAME_LBL,
175: modelManager.getString("rulename.label"));
176: } else if (name.equals(CHILD_RULENAME)) {
177: return new TextField(this , CHILD_RULENAME, "");
178: } else if (name.equals(CHILD_ALGORITHMS_LBL)) {
179: return new StaticTextField(this , CHILD_ALGORITHMS_LBL,
180: modelManager.getString("algorithms.label"));
181: } else if (name.equals(CHILD_ALGORITHMS)) {
182: return new ListBox(this , CHILD_ALGORITHMS, "");
183: } else if (name.equals(CHILD_ALGO_DEFAULT)) {
184: return new StaticTextField(this , CHILD_ALGO_DEFAULT,
185: modelManager.getString("algorithm.default"));
186: } else if (name.equals(CHILD_ALGO_OTHER)) {
187: return new StaticTextField(this , CHILD_ALGO_OTHER,
188: modelManager.getString("algorithm.other"));
189: } else if (name.equals(CHILD_URL_LBL)) {
190: return new StaticTextField(this , CHILD_URL_LBL,
191: modelManager.getString("url.label"));
192: } else if (name.equals(CHILD_URL)) {
193: return new TextField(this , CHILD_URL, "");
194: } else if (name.equals(CHILD_DOWNLOADAPPLET_LBL)) {
195: return new StaticTextField(this , CHILD_DOWNLOADAPPLET_LBL,
196: modelManager.getString("downloadapplet.label"));
197: } else if (name.equals(CHILD_DOWNLOADAPPLET_CB)) {
198: return new CheckBox(this , CHILD_DOWNLOADAPPLET_CB, "true",
199: "false", false);
200: } else if (name.equals(CHILD_DOWNLOADAPPLET_NAME)) {
201: return new TextField(this , CHILD_DOWNLOADAPPLET_NAME, "");
202: } else if (name.equals(CHILD_EXTEND_LBL)) {
203: return new StaticTextField(this , CHILD_EXTEND_LBL,
204: modelManager.getString("extend.label"));
205: } else if (name.equals(CHILD_EXTEND)) {
206: return new CheckBox(this , CHILD_EXTEND, "true", "false",
207: false);
208: } else if (name.equals(CHILD_PHPLIST_LBL)) {
209: return new StaticTextField(this , CHILD_PHPLIST_LBL,
210: modelManager.getString("phplist.label"));
211: } else if (name.equals(CHILD_PHPLIST)) {
212: return new ListBox(this , CHILD_PHPLIST, "");
213: } else if (name.equals(CHILD_CLIENTPORT_LBL)) {
214: return new StaticTextField(this , CHILD_CLIENTPORT_LBL,
215: modelManager.getString("clientport.label"));
216: } else if (name.equals(CHILD_CLIENTPORT)) {
217: return new TextField(this , CHILD_CLIENTPORT, "");
218: } else if (name.equals(CHILD_CLIENTPORT_LBL)) {
219: return new StaticTextField(this , CHILD_CLIENTPORT_LBL,
220: modelManager.getString("clientport.label"));
221: } else if (name.equals(CHILD_CLIENTPORT)) {
222: return new TextField(this , CHILD_CLIENTPORT, "");
223: } else if (name.equals(CHILD_TARGETHOST_LBL)) {
224: return new StaticTextField(this , CHILD_TARGETHOST_LBL,
225: modelManager.getString("targethost.label"));
226: } else if (name.equals(CHILD_TARGETHOST)) {
227: return new TextField(this , CHILD_TARGETHOST, "");
228: } else if (name.equals(CHILD_TARGETPORT_LBL)) {
229: return new StaticTextField(this , CHILD_TARGETPORT_LBL,
230: modelManager.getString("targetport.label"));
231: } else if (name.equals(CHILD_TARGETPORT)) {
232: return new TextField(this , CHILD_TARGETPORT, "");
233: } else if (name.equals(CHILD_SELECTED_ALGOS)) {
234: return new HiddenField(this , CHILD_SELECTED_ALGOS, "");
235: } else if (name.equals(CHILD_RULE_INDEX)) {
236: return new HiddenField(this , CHILD_RULE_INDEX, "");
237: } else if (name.equals(CHILD_SAVE_BTN)) {
238: return new IPlanetButton(this , CHILD_SAVE_BTN, modelManager
239: .getString("ok.button"));
240: } else if (name.equals(CHILD_CANCEL_BTN)) {
241: return new IPlanetButton(this , CHILD_CANCEL_BTN,
242: modelManager.getString("cancel.button"));
243: } else if (name.equals(CHILD_REMOVE_BTN)) {
244: return new StaticTextField(this , CHILD_REMOVE_BTN,
245: modelManager.getString("remove.button"));
246: } else if (name.equals(CHILD_ADDTOLIST_BTN)) {
247: return new StaticTextField(this , CHILD_ADDTOLIST_BTN,
248: modelManager.getString("addtolist.button"));
249: } else if (name.equals(CHILD_ERRORMSGS)) {
250: return new StaticTextField(this , CHILD_ERRORMSGS, "");
251: } else {
252: return super .createChild(name);
253: }
254: }
255:
256: /**
257: * To register all the child view objects and their classes.
258: */
259: protected void registerChildren() {
260: registerChild(PAGE_TITLE, StaticTextField.class);
261: registerChild(PAGE_DESC, StaticTextField.class);
262: registerChild(PAGE_DESC_HREF, HREF.class);
263: registerChild(PAGE_DESC_ACTION, StaticTextField.class);
264: registerChild(CHILD_RULENAME_LBL, StaticTextField.class);
265: registerChild(CHILD_RULENAME, TextField.class);
266: registerChild(CHILD_ALGORITHMS_LBL, StaticTextField.class);
267: registerChild(CHILD_ALGO_DEFAULT, StaticTextField.class);
268: registerChild(CHILD_ALGO_OTHER, StaticTextField.class);
269: registerChild(CHILD_ALGORITHMS, ListBox.class);
270: registerChild(CHILD_URL_LBL, StaticTextField.class);
271: registerChild(CHILD_URL, TextField.class);
272: registerChild(CHILD_DOWNLOADAPPLET_LBL, StaticTextField.class);
273: registerChild(CHILD_DOWNLOADAPPLET_CB, CheckBox.class);
274: registerChild(CHILD_DOWNLOADAPPLET_NAME, TextField.class);
275: registerChild(CHILD_EXTEND_LBL, StaticTextField.class);
276: registerChild(CHILD_EXTEND, CheckBox.class);
277: registerChild(CHILD_PHPLIST_LBL, StaticTextField.class);
278: registerChild(CHILD_PHPLIST, ListBox.class);
279: registerChild(CHILD_CLIENTPORT_LBL, StaticTextField.class);
280: registerChild(CHILD_CLIENTPORT, TextField.class);
281: registerChild(CHILD_TARGETHOST_LBL, StaticTextField.class);
282: registerChild(CHILD_TARGETHOST, TextField.class);
283: registerChild(CHILD_TARGETPORT_LBL, StaticTextField.class);
284: registerChild(CHILD_TARGETPORT, TextField.class);
285: registerChild(CHILD_SELECTED_ALGOS, HiddenField.class);
286: registerChild(CHILD_RULE_INDEX, HiddenField.class);
287: registerChild(CHILD_ERRORMSGS, StaticTextField.class);
288: registerChild(CHILD_SAVE_BTN, IPlanetButton.class);
289: registerChild(CHILD_CANCEL_BTN, IPlanetButton.class);
290: registerChild(CHILD_REMOVE_BTN, StaticTextField.class);
291: registerChild(CHILD_ADDTOLIST_BTN, StaticTextField.class);
292: }
293:
294: /**
295: * Initialize display field values, which require backend data.
296: */
297: public void beginDisplay(DisplayEvent event)
298: throws ModelControlException {
299: getModel();
300: setChildValues(model);
301: Set s = model.getNetletRules();
302: netletRules = new Vector(s);
303: currentRow = modelManager.getCurrentNetletRulesRow();
304: setDisplayFieldValue(PAGE_DESC, model.getServiceDescription());
305: setDisplayFieldValue(CHILD_ERRORMSGS, getErrorMessages());
306: setAlgorithmOptions(model);
307: String currentRule = null;
308:
309: if (currentRow == -1) { // Adding new rule
310: currentRule = SAMPLE_RULE;
311: setDisplayFieldValue(PAGE_DESC_ACTION, modelManager
312: .getString("addrule.pagetitle"));
313: } else { // Editing an existing rule
314: currentRule = (String) netletRules.get(currentRow);
315: setDisplayFieldValue(PAGE_DESC_ACTION, modelManager
316: .getString("editrule.pagetitle"));
317: }
318: setDisplayFieldValue(CHILD_RULE_INDEX, currentRow);
319:
320: if (currentRule.endsWith("EXTEND")) {
321: currentRule = currentRule.substring(0,
322: currentRule.lastIndexOf("EXTEND")).trim();
323: setDisplayFieldValue(CHILD_EXTEND, "true");
324: } else {
325: setDisplayFieldValue(CHILD_EXTEND, "false");
326: }
327: StringTokenizer st = new StringTokenizer(currentRule,
328: RULE_DELIM);
329: String tmp = null;
330: try {
331: tmp = st.nextToken();
332: setDisplayFieldValue(CHILD_SELECTED_ALGOS, tmp); // Set the
333: // hidden field
334: // value
335: // required for
336: // JS
337: // to select appropriate algorithms for this rule
338: tmp = (new StringTokenizer(tmp, ALGO_DELIM)).nextToken();
339: setDisplayFieldValue(CHILD_RULENAME, tmp);
340:
341: tmp = st.nextToken();
342: setDisplayFieldValue(CHILD_URL, tmp);
343:
344: tmp = st.nextToken();
345: if (tmp.equalsIgnoreCase("false")) {
346: setDisplayFieldValue(CHILD_DOWNLOADAPPLET_CB, "false");
347: } else if (tmp.equalsIgnoreCase("true")) {
348: setDisplayFieldValue(CHILD_DOWNLOADAPPLET_CB, "true");
349: } else {
350: setDisplayFieldValue(CHILD_DOWNLOADAPPLET_CB, "true");
351: setDisplayFieldValue(CHILD_DOWNLOADAPPLET_NAME, tmp);
352: }
353:
354: OptionList optList = new OptionList();
355: ListBox lb = (ListBox) getChild(CHILD_PHPLIST);
356: String phpentry = null;
357: while (st.hasMoreTokens()) {
358: phpentry = st.nextToken();
359: phpentry += " " + st.nextToken();
360: phpentry += " " + st.nextToken();
361: optList.add(phpentry, phpentry);
362: }
363: optList.add("_______________________________________", "");
364: lb.setOptions(optList);
365: } catch (NoSuchElementException nsee) {
366: NetletAdminModelManager
367: .debugError("Error parsing netlet rules " + nsee);
368: }
369: }
370:
371: /**
372: * Returns true if Netlet attributes can be modified by the current user,
373: * false otherwise.
374: */
375: public boolean beginNetletRulesBtnBlockDisplay(
376: ChildDisplayEvent event) {
377: getModel();
378: return !model.isReadOnly("sunPortalNetletRules");
379: }
380:
381: /**
382: * Sets the default algotithms for Netlet rule.
383: */
384: public void setAlgorithmOptions(NetletAdminUserProfileModelImpl m) {
385: OptionList optList = new OptionList();
386: String[] ciphers = NetletConstants.NETLET_CIPHERS;
387: for (int i = 0; i < ciphers.length; i++) {
388: String option = ciphers[i];
389: optList.add(option, option);
390: }
391: ListBox lb = (ListBox) getChild(CHILD_ALGORITHMS);
392: lb.setOptions(optList);
393: }
394:
395: /**
396: * Creates a new NetletAdminServiceModel and returns the same if the model
397: * is not already been created.
398: */
399: public NetletAdminUserProfileModelImpl getModel() {
400: if (model == null) {
401: HttpServletRequest request = getRequestContext()
402: .getRequest();
403: model = new NetletAdminUserProfileModelImpl(request,
404: getPageSessionAttributes());
405: model.initModel(getUserDN());
406: }
407: return model;
408: }
409:
410: /**
411: * Creates a new NetletAdminModelManager and returns the same, if the model
412: * is not already been created.
413: */
414: public NetletAdminModelManager getModelMgr() {
415: if (modelManager == null) {
416: modelManager = (NetletAdminModelManager) getRequestContext()
417: .getModelManager();
418: }
419: return modelManager;
420: }
421:
422: /**
423: * Returns the current User DN.
424: */
425: public String getUserDN() {
426: if (userDN == null) {
427: Map pageSessAttrs = getPageSessionAttributes();
428: userDN = (String) pageSessAttrs
429: .get("com-iplanet-am-admin-user-current-object");
430: }
431: return userDN;
432: }
433:
434: /**
435: * Tests whether the given rule name is already in the list of Netlet rules. @ Returns
436: * true if the rule name is duplicate, false otherwise
437: */
438: public boolean isDuplicate(String ruleName) {
439: if (netletRules != null && ruleName != null) {
440: for (int i = 0; i < netletRules.size(); i++) {
441: if (i == currentRow) {
442: continue;
443: }
444: StringTokenizer st1 = new StringTokenizer(
445: (String) netletRules.get(i), RULE_DELIM);
446: String str2 = null;
447: if (st1.hasMoreTokens()) {
448: str2 = st1.nextToken();
449: st1 = new StringTokenizer(str2, ALGO_DELIM);
450: if (st1.hasMoreTokens()) {
451: str2 = st1.nextToken();
452: if (ruleName.equals(str2)) {
453: return true;
454: }
455: }
456: }
457: }
458: }
459: return false;
460: }
461:
462: /**
463: * Returns the vector of all configured client ports.
464: */
465: private Vector getClientPorts() {
466: Vector clientPorts = new Vector();
467: if (netletRules != null) {
468: for (int i = 0; i < netletRules.size(); ++i) {
469: if (i == currentRow) {
470: continue;
471: }
472: String nr = (String) netletRules.get(i);
473: if (nr.endsWith("EXTEND"))
474: nr = nr.substring(0, nr.lastIndexOf("|"));
475: StringTokenizer tok = new StringTokenizer(nr, "|");
476: try {
477: String func = (String) tok.nextElement();
478: String tmp = (String) tok.nextElement(); // url
479: tmp = (String) tok.nextElement(); // loopback
480: while (tok.hasMoreElements()) {
481: tmp = (String) tok.nextElement(); // local port
482: clientPorts.addElement(tmp);
483: tmp = (String) tok.nextElement(); // dest host
484: tmp = (String) tok.nextElement(); // dest port
485: }
486: } catch (NoSuchElementException nsee) {
487: continue; // skip non-parsable rules
488: }
489: }
490: }
491: return clientPorts;
492: }
493:
494: /**
495: * Tests whether the given client port is already in the list of Netlet
496: * rules. @ Returns true if the client port is duplicate, false otherwise 8 @ Returns
497: * the StringBuffer with the list of client ports which are in use.
498: */
499: public boolean isClientPortDuplicate(StringBuffer result) {
500: boolean duplicateFound = false;
501: int indexOfDuplicate = 0;
502: Vector clientPorts = getClientPorts();
503: ListBox lb = (ListBox) getDisplayField(CHILD_PHPLIST);
504: Object[] objValues = (Object[]) lb.getValues();
505: if ((objValues != null)) {
506: int size = objValues.length;
507: for (int i = 0; i < size && !duplicateFound; i++) {
508: String phpentry = (String) objValues[i];
509: StringTokenizer tok = new StringTokenizer(phpentry, " ");
510: try {
511: String tmp = tok.nextToken();
512: if (clientPorts.contains(tmp)) {
513: duplicateFound = true;
514: indexOfDuplicate = clientPorts.indexOf(tmp);
515: }
516: } catch (NoSuchElementException nsee) {
517: } catch (NumberFormatException nfe) {
518: }
519: }
520: }
521: if (duplicateFound) {
522: result.append("<ul>");
523: for (int i = 0; i < clientPorts.size(); ++i) {
524: result.append("<li>");
525: if (i == indexOfDuplicate) {
526: result.append("<font color=red>").append(
527: clientPorts.get(i)).append("</font>");
528: } else {
529: result.append(clientPorts.get(i));
530: }
531: result.append("</li>");
532: }
533: result.append("</ul>");
534: }
535: return duplicateFound;
536: }
537:
538: /**
539: * Appends the selected algorithms to the Netlet rule buffer.
540: */
541: public void appendAlgorithm(StringBuffer nrBuffer) {
542: ListBox lb = (ListBox) getDisplayField(CHILD_ALGORITHMS);
543: Object[] objValues = (Object[]) lb.getValues();
544: if (objValues != null) {
545: int size = objValues.length;
546: if (size > 1) {
547: nrBuffer.append(ALGO_DELIM + "ALGO");
548: }
549: boolean firstAlgo = true;
550: for (int i = 0; i < size; i++) {
551: if ((objValues[i] != null)
552: && (((String) objValues[i]).trim().length() != 0)) {
553: if (firstAlgo) {
554: firstAlgo = false;
555: nrBuffer.append(ALGO_DELIM
556: + (String) objValues[i]);
557: } else {
558: nrBuffer.append("+" + (String) objValues[i]);
559: }
560: }
561: }
562: }
563: }
564:
565: /**
566: * Appends the "Download Applet" field value to the netlet rule.
567: */
568: public void appendDownloadApplet(StringBuffer nrBuffer) {
569: String str1 = (String) getDisplayFieldValue(CHILD_DOWNLOADAPPLET_CB);
570: if (str1.equals("false")) {
571: nrBuffer.append(RULE_DELIM + str1);
572: } else {
573: str1 = (String) getDisplayFieldValue(CHILD_DOWNLOADAPPLET_NAME);
574: if ((str1 == null) || (str1.trim().length() == 0)) {
575: nrBuffer.append(RULE_DELIM + "true");
576: } else {
577: StringTokenizer tok = new StringTokenizer(str1, ":");
578: StringBuffer sb = new StringBuffer();
579: try {
580: String tmp = tok.nextToken();
581: int port = Integer.parseInt(tmp);
582: sb.append(tmp);
583: sb.append(":" + tok.nextToken());
584: tmp = tok.nextToken();
585: port = Integer.parseInt(tmp);
586: sb.append(":" + tmp);
587: nrBuffer.append(RULE_DELIM + sb.toString());
588: } catch (NoSuchElementException nse) {
589: nrBuffer.append(RULE_DELIM + "true");
590: } catch (NumberFormatException nfe) {
591: nrBuffer.append(RULE_DELIM + "true");
592: }
593: }
594: }
595: }
596:
597: /**
598: * Appends the Port-Host-Port list to the rule. @ Returns true on success,
599: * false if error occurs.
600: */
601: public boolean appendPortHostPort(StringBuffer nrBuffer) {
602: ListBox lb = (ListBox) getDisplayField(CHILD_PHPLIST);
603: Object[] objValues = (Object[]) lb.getValues();
604: if ((objValues == null) || (objValues.length == 0)) {
605: return false;
606: } else {
607: int size = objValues.length;
608: boolean atleastOne = false;
609: for (int i = 0; i < size; i++) {
610: String phpentry = (String) objValues[i];
611: StringTokenizer tok = new StringTokenizer(phpentry, " ");
612: StringBuffer sb = new StringBuffer();
613: try {
614: String tmp = tok.nextToken();
615: int port = Integer.parseInt(tmp);
616: sb.append(tmp);
617: sb.append(RULE_DELIM + tok.nextToken());
618: sb.append(RULE_DELIM + tok.nextToken());
619: nrBuffer.append(RULE_DELIM + sb.toString());
620: atleastOne = true;
621: } catch (NoSuchElementException nsee) {
622: } catch (NumberFormatException nfe) {
623: }
624: }
625: if (!atleastOne) {
626: return false;
627: }
628: }
629: return true;
630: }
631:
632: /**
633: * Handles Save button request in EditNetletRule Page.
634: */
635: public void handleSaveButtonRequest(RequestInvocationEvent event)
636: throws ModelControlException {
637: /*
638: * Get all the display field values and store it to the backend
639: */
640: getModel();
641: Set s = model.getNetletRules();
642: netletRules = new Vector(s);
643: String currRow = (String) getDisplayFieldValue(CHILD_RULE_INDEX);
644: try {
645: currentRow = Integer.parseInt(currRow);
646: } catch (NumberFormatException nfe) {
647: currentRow = -1;
648: NetletAdminModelManager
649: .debugError("Error getting rule index : " + nfe);
650: }
651: StringBuffer nrBuffer = new StringBuffer();
652: String newRule = null;
653: Set newRuleSet = null;
654: Map newMap = null;
655:
656: String str1 = (String) getDisplayFieldValue(CHILD_RULENAME);
657:
658: /**
659: * Test whether the rule name is null or empty.
660: */
661: if ((str1 == null) || (str1.trim().length() == 0)) {
662: redirectToMsgVB("invalidrule.title", "rulename.error", null);
663: return;
664: }
665:
666: /**
667: * Test for duplicate rulenames when adding a new rule
668: */
669: if (isDuplicate(str1)) {
670: redirectToMsgVB("invalidrule.title",
671: "duplicaterulename.error", null);
672: return;
673: }
674: nrBuffer.append(str1);
675:
676: /**
677: * Append the selected algorithms to the rule.
678: */
679: appendAlgorithm(nrBuffer);
680:
681: /**
682: * Append the URL to the rule.
683: */
684: str1 = (String) getDisplayFieldValue(CHILD_URL);
685: if ((str1 == null) || (str1.trim().length() == 0)) {
686: str1 = "null";
687: }
688: nrBuffer.append(RULE_DELIM + str1);
689:
690: /**
691: * Append "Download applet" field value to the rule.
692: */
693: appendDownloadApplet(nrBuffer);
694:
695: /**
696: * Test for duplicate client ports when adding a new Netlet rule
697: */
698: StringBuffer sb = new StringBuffer();
699: if (isClientPortDuplicate(sb)) {
700: redirectToMsgVB("invalidrule.title",
701: "duplicateclientport.error", new Object[] { sb });
702: return;
703: }
704:
705: /**
706: * Append the port-host-port list to the rule.
707: */
708: if (!appendPortHostPort(nrBuffer)) {
709: redirectToMsgVB("invalidrule.title", "phplist.error", null);
710: return;
711: }
712:
713: /**
714: * Append "Extend Session" field value to the Netlet rule.
715: */
716: str1 = (String) getDisplayFieldValue(CHILD_EXTEND);
717: if (str1.equals("true")) {
718: nrBuffer.append(RULE_DELIM + "EXTEND");
719: }
720:
721: /**
722: * Convert Netlet rule to String object and store it to the backend.
723: */
724: newRule = nrBuffer.toString();
725: NetletAdminModelManager.debugMessage("newRule = " + newRule);
726:
727: if (netletRules == null) {
728: netletRules = new Vector();
729: }
730:
731: if (currentRow == -1) { // New rule
732: netletRules.add(netletRules.size(), newRule);
733: } else {
734: netletRules.set(currentRow, newRule);
735: }
736:
737: newRuleSet = new HashSet(netletRules);
738: newMap = new HashMap();
739: newMap.put("sunPortalNetletRules", newRuleSet);
740: boolean success = model.store(newMap);
741:
742: /**
743: * Forward the request to the NetletAdminServiceViewBean
744: */
745: redirectToNASURL();
746: }
747:
748: /**
749: * Handles the Cancel button request.
750: */
751: public void handleCancelButtonRequest(RequestInvocationEvent event)
752: throws ModelControlException {
753: redirectToNASURL();
754: }
755:
756: /**
757: * Handles the page title HREF link request.
758: */
759: public void handleServiceDescHrefRequest(
760: RequestInvocationEvent event) throws ModelControlException {
761: redirectToNASURL();
762: }
763:
764: /**
765: * Passes the current page session Map to the another view bean.
766: */
767: public void passPgSessionMap(ViewBean other) {
768: Map attributes = getPageSessionAttributes();
769: if ((attributes != null) && (attributes.size() > 0)) {
770: Iterator iter = attributes.keySet().iterator();
771: while (iter.hasNext()) {
772: String key = (String) iter.next();
773: other.setPageSessionAttribute(key,
774: (Serializable) attributes.get(key));
775: }
776: }
777: }
778:
779: /**
780: * Redirects the Request to NetletAdminServiceViewBean.
781: */
782: public void redirectToNASURL() {
783: NetletAdminUserProfileViewBean vb = (NetletAdminUserProfileViewBean) getViewBean(NetletAdminUserProfileViewBean.class);
784: passPgSessionMap(vb);
785: vb.forwardTo(getRequestContext());
786: }
787:
788: /**
789: * Redirects request to Message view bean.
790: */
791: public void redirectToMsgVB(String title, String msgKey,
792: Object objs[]) {
793: AMMessageViewBean msgVB = (AMMessageViewBean) getViewBean(com.iplanet.am.console.base.AMMessageViewBean.class);
794: msgVB.setMessageType(MessageBox.TYPE_WARNING);
795: msgVB.setTitle(modelManager.getString(title));
796: if (objs != null) {
797: msgVB.setMessage(MessageFormat.format(modelManager
798: .getString(msgKey), objs));
799: } else {
800: msgVB.setMessage(modelManager.getString(msgKey));
801: }
802: String nasURL = getModuleURL() + "/"
803: + NetletAdminUserProfileViewBean.PAGE_NAME;
804: nasURL = AMViewBeanUtils.appendPgSession(nasURL,
805: getPageSessionAttributes());
806: msgVB.addButton(modelManager.getString("ok.button"), nasURL);
807: msgVB.forwardTo(getRequestContext());
808: }
809:
810: /**
811: * Returns localized JavaScript error messages.
812: */
813: private String getErrorMessages() {
814: getModelMgr();
815: StringBuffer sb = new StringBuffer();
816: sb.append("errorMessages['emptyFields'] = '"
817: + modelManager.getString("emptyFields") + "';\n");
818: sb.append("errorMessages['invalidclientport'] = '"
819: + modelManager.getString("invalidclientport") + "';\n");
820: sb.append("errorMessages['invalidtargethost'] = '"
821: + modelManager.getString("invalidtargethost") + "';\n");
822: sb.append("errorMessages['invalidtargetport'] = '"
823: + modelManager.getString("invalidtargetport") + "';\n");
824: sb.append("errorMessages['dynamictargetport'] = '"
825: + modelManager.getString("dynamictargetport") + "';\n");
826: sb.append("errorMessages['targetportlist'] = '"
827: + modelManager.getString("targetportlist") + "';\n");
828: sb.append("errorMessages['duplicatetargets'] = '"
829: + modelManager.getString("duplicatetargets") + "';\n");
830: sb.append("errorMessages['duplicateclientport'] = '"
831: + modelManager.getString("duplicateclientport") + "';");
832: return sb.toString();
833: }
834:
835: }
|