/**
* Copyright 2002 Sun Microsystems, Inc. All
* rights reserved. Use of this product is subject
* to license terms. Federal Acquisitions:
* Commercial Software -- Government Users
* Subject to Standard License Terms and
* Conditions.
*
* Sun, Sun Microsystems, the Sun logo, and Sun ONE
* are trademarks or registered trademarks of Sun Microsystems,
* Inc. in the United States and other countries.
*
* @ Author Bhavanishankar
*/
package com.sun.portal.netlet.admin;
// JDK classes
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import com.iplanet.am.console.base.AMMessageViewBean;
import com.iplanet.am.console.base.AMViewBeanBase;
import com.iplanet.am.console.base.AMViewBeanUtils;
import com.iplanet.am.console.components.view.html.IPlanetButton;
import com.iplanet.am.console.components.view.html.MessageBox;
import com.iplanet.jato.model.ModelControlException;
import com.iplanet.jato.view.View;
import com.iplanet.jato.view.ViewBean;
import com.iplanet.jato.view.event.ChildDisplayEvent;
import com.iplanet.jato.view.event.DisplayEvent;
import com.iplanet.jato.view.event.RequestInvocationEvent;
import com.iplanet.jato.view.html.CheckBox;
import com.iplanet.jato.view.html.HREF;
import com.iplanet.jato.view.html.HiddenField;
import com.iplanet.jato.view.html.ListBox;
import com.iplanet.jato.view.html.OptionList;
import com.iplanet.jato.view.html.StaticTextField;
import com.iplanet.jato.view.html.TextField;
import com.sun.portal.netlet.admin.model.NetletAdminUserProfileModelImpl;
import com.sun.portal.netlet.util.NetletConstants;
public class EditNetletRuleUserProfileViewBean extends AMViewBeanBase {
public static final String PAGE_NAME = "EditNetletRuleUserProfile";
public static final String DEFAULT_DISPLAY_URL = "/ps/netletadmin/EditNetletRuleUserProfile.jsp";
public static final String PAGE_TITLE = "titleHtmlPage";
public static final String PAGE_DESC = "serviceDescription"; // Netlet
public static final String PAGE_DESC_HREF = "serviceDescHref";
public static final String PAGE_DESC_ACTION = "serviceDescAction"; // >
// Edit
// Rule
public static final String CHILD_RULENAME_LBL = "rulenameLabel";
public static final String CHILD_RULENAME = "rulename";
public static final String CHILD_ALGORITHMS_LBL = "algorithmsLabel";
public static final String CHILD_ALGO_DEFAULT = "algorithmDefault";
public static final String CHILD_ALGO_OTHER = "algorithmOther";
public static final String CHILD_ALGORITHMS = "algorithms";
public static final String CHILD_URL_LBL = "urlLabel";
public static final String CHILD_URL = "url";
public static final String CHILD_DOWNLOADAPPLET_LBL = "downloadappletLabel";
public static final String CHILD_DOWNLOADAPPLET_CB = "downloadappletcb";
public static final String CHILD_DOWNLOADAPPLET_NAME = "downloadappletname";
public static final String CHILD_EXTEND_LBL = "extendLabel";
public static final String CHILD_EXTEND = "extend";
public static final String CHILD_PHPLIST_LBL = "phplistLabel";
public static final String CHILD_PHPLIST = "phplist";
public static final String CHILD_CLIENTPORT_LBL = "clientportLabel";
public static final String CHILD_CLIENTPORT = "clientport";
public static final String CHILD_TARGETHOST_LBL = "targethostLabel";
public static final String CHILD_TARGETHOST = "targethost";
public static final String CHILD_TARGETPORT_LBL = "targetportLabel";
public static final String CHILD_TARGETPORT = "targetport";
public static final String CHILD_SELECTED_ALGOS = "selectedAlgos";
public static final String CHILD_RULE_INDEX = "ruleIndex";
public static final String CHILD_ERRORMSGS = "errorMessages";
public static final String CHILD_SAVE_BTN = "saveButton";
public static final String CHILD_CANCEL_BTN = "cancelButton";
public static final String CHILD_REMOVE_BTN = "removeButton";
public static final String CHILD_ADDTOLIST_BTN = "addtolistButton";
private NetletAdminModelManager modelManager = null;
private NetletAdminUserProfileModelImpl model = null;
private Vector netletRules = null;
private int currentRow = -1;
public static final String RULE_DELIM = "|";
public static final String ALGO_DELIM = "^";
private final String SAMPLE_RULE = "MyRule|/ps/sample.html|50000:machinename:80|40000|TARGET|11041|EXTEND";
private String userDN = null;
/**
* Default Constructor
*/
public EditNetletRuleUserProfileViewBean() {
super(PAGE_NAME);
setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
registerChildren();
}
public EditNetletRuleUserProfileViewBean(String pageName) {
super(pageName);
registerChildren();
}
/**
* Creates the child view objects for this viewbean.
*
* @param name
* the name of the child view object to be created.
* @return the child view object.
*/
protected View createChild(String name) {
getModelMgr();
if (name.equals(PAGE_TITLE)) {
return new StaticTextField(this, PAGE_TITLE, modelManager
.getString("HTMLPage.title"));
} else if (name.equals(PAGE_DESC)) {
return new StaticTextField(this, PAGE_DESC, "");
} else if (name.equals(PAGE_DESC_HREF)) {
return new HREF(this, PAGE_DESC_HREF, "");
} else if (name.equals(PAGE_DESC_ACTION)) {
return new StaticTextField(this, PAGE_DESC_ACTION, modelManager
.getString("editrule.pagetitle"));
} else if (name.equals(CHILD_RULENAME_LBL)) {
return new StaticTextField(this, CHILD_RULENAME_LBL, modelManager
.getString("rulename.label"));
} else if (name.equals(CHILD_RULENAME)) {
return new TextField(this, CHILD_RULENAME, "");
} else if (name.equals(CHILD_ALGORITHMS_LBL)) {
return new StaticTextField(this, CHILD_ALGORITHMS_LBL, modelManager
.getString("algorithms.label"));
} else if (name.equals(CHILD_ALGORITHMS)) {
return new ListBox(this, CHILD_ALGORITHMS, "");
} else if (name.equals(CHILD_ALGO_DEFAULT)) {
return new StaticTextField(this, CHILD_ALGO_DEFAULT, modelManager
.getString("algorithm.default"));
} else if (name.equals(CHILD_ALGO_OTHER)) {
return new StaticTextField(this, CHILD_ALGO_OTHER, modelManager
.getString("algorithm.other"));
} else if (name.equals(CHILD_URL_LBL)) {
return new StaticTextField(this, CHILD_URL_LBL, modelManager
.getString("url.label"));
} else if (name.equals(CHILD_URL)) {
return new TextField(this, CHILD_URL, "");
} else if (name.equals(CHILD_DOWNLOADAPPLET_LBL)) {
return new StaticTextField(
this,
CHILD_DOWNLOADAPPLET_LBL,
modelManager.getString("downloadapplet.label"));
} else if (name.equals(CHILD_DOWNLOADAPPLET_CB)) {
return new CheckBox(
this,
CHILD_DOWNLOADAPPLET_CB,
"true",
"false",
false);
} else if (name.equals(CHILD_DOWNLOADAPPLET_NAME)) {
return new TextField(this, CHILD_DOWNLOADAPPLET_NAME, "");
} else if (name.equals(CHILD_EXTEND_LBL)) {
return new StaticTextField(this, CHILD_EXTEND_LBL, modelManager
.getString("extend.label"));
} else if (name.equals(CHILD_EXTEND)) {
return new CheckBox(this, CHILD_EXTEND, "true", "false", false);
} else if (name.equals(CHILD_PHPLIST_LBL)) {
return new StaticTextField(this, CHILD_PHPLIST_LBL, modelManager
.getString("phplist.label"));
} else if (name.equals(CHILD_PHPLIST)) {
return new ListBox(this, CHILD_PHPLIST, "");
} else if (name.equals(CHILD_CLIENTPORT_LBL)) {
return new StaticTextField(this, CHILD_CLIENTPORT_LBL, modelManager
.getString("clientport.label"));
} else if (name.equals(CHILD_CLIENTPORT)) {
return new TextField(this, CHILD_CLIENTPORT, "");
} else if (name.equals(CHILD_CLIENTPORT_LBL)) {
return new StaticTextField(this, CHILD_CLIENTPORT_LBL, modelManager
.getString("clientport.label"));
} else if (name.equals(CHILD_CLIENTPORT)) {
return new TextField(this, CHILD_CLIENTPORT, "");
} else if (name.equals(CHILD_TARGETHOST_LBL)) {
return new StaticTextField(this, CHILD_TARGETHOST_LBL, modelManager
.getString("targethost.label"));
} else if (name.equals(CHILD_TARGETHOST)) {
return new TextField(this, CHILD_TARGETHOST, "");
} else if (name.equals(CHILD_TARGETPORT_LBL)) {
return new StaticTextField(this, CHILD_TARGETPORT_LBL, modelManager
.getString("targetport.label"));
} else if (name.equals(CHILD_TARGETPORT)) {
return new TextField(this, CHILD_TARGETPORT, "");
} else if (name.equals(CHILD_SELECTED_ALGOS)) {
return new HiddenField(this, CHILD_SELECTED_ALGOS, "");
} else if (name.equals(CHILD_RULE_INDEX)) {
return new HiddenField(this, CHILD_RULE_INDEX, "");
} else if (name.equals(CHILD_SAVE_BTN)) {
return new IPlanetButton(this, CHILD_SAVE_BTN, modelManager
.getString("ok.button"));
} else if (name.equals(CHILD_CANCEL_BTN)) {
return new IPlanetButton(this, CHILD_CANCEL_BTN, modelManager
.getString("cancel.button"));
} else if (name.equals(CHILD_REMOVE_BTN)) {
return new StaticTextField(this, CHILD_REMOVE_BTN, modelManager
.getString("remove.button"));
} else if (name.equals(CHILD_ADDTOLIST_BTN)) {
return new StaticTextField(this, CHILD_ADDTOLIST_BTN, modelManager
.getString("addtolist.button"));
} else if (name.equals(CHILD_ERRORMSGS)) {
return new StaticTextField(this, CHILD_ERRORMSGS, "");
} else {
return super.createChild(name);
}
}
/**
* To register all the child view objects and their classes.
*/
protected void registerChildren() {
registerChild(PAGE_TITLE, StaticTextField.class);
registerChild(PAGE_DESC, StaticTextField.class);
registerChild(PAGE_DESC_HREF, HREF.class);
registerChild(PAGE_DESC_ACTION, StaticTextField.class);
registerChild(CHILD_RULENAME_LBL, StaticTextField.class);
registerChild(CHILD_RULENAME, TextField.class);
registerChild(CHILD_ALGORITHMS_LBL, StaticTextField.class);
registerChild(CHILD_ALGO_DEFAULT, StaticTextField.class);
registerChild(CHILD_ALGO_OTHER, StaticTextField.class);
registerChild(CHILD_ALGORITHMS, ListBox.class);
registerChild(CHILD_URL_LBL, StaticTextField.class);
registerChild(CHILD_URL, TextField.class);
registerChild(CHILD_DOWNLOADAPPLET_LBL, StaticTextField.class);
registerChild(CHILD_DOWNLOADAPPLET_CB, CheckBox.class);
registerChild(CHILD_DOWNLOADAPPLET_NAME, TextField.class);
registerChild(CHILD_EXTEND_LBL, StaticTextField.class);
registerChild(CHILD_EXTEND, CheckBox.class);
registerChild(CHILD_PHPLIST_LBL, StaticTextField.class);
registerChild(CHILD_PHPLIST, ListBox.class);
registerChild(CHILD_CLIENTPORT_LBL, StaticTextField.class);
registerChild(CHILD_CLIENTPORT, TextField.class);
registerChild(CHILD_TARGETHOST_LBL, StaticTextField.class);
registerChild(CHILD_TARGETHOST, TextField.class);
registerChild(CHILD_TARGETPORT_LBL, StaticTextField.class);
registerChild(CHILD_TARGETPORT, TextField.class);
registerChild(CHILD_SELECTED_ALGOS, HiddenField.class);
registerChild(CHILD_RULE_INDEX, HiddenField.class);
registerChild(CHILD_ERRORMSGS, StaticTextField.class);
registerChild(CHILD_SAVE_BTN, IPlanetButton.class);
registerChild(CHILD_CANCEL_BTN, IPlanetButton.class);
registerChild(CHILD_REMOVE_BTN, StaticTextField.class);
registerChild(CHILD_ADDTOLIST_BTN, StaticTextField.class);
}
/**
* Initialize display field values, which require backend data.
*/
public void beginDisplay(DisplayEvent event) throws ModelControlException {
getModel();
setChildValues(model);
Set s = model.getNetletRules();
netletRules = new Vector(s);
currentRow = modelManager.getCurrentNetletRulesRow();
setDisplayFieldValue(PAGE_DESC, model.getServiceDescription());
setDisplayFieldValue(CHILD_ERRORMSGS, getErrorMessages());
setAlgorithmOptions(model);
String currentRule = null;
if (currentRow == -1) { // Adding new rule
currentRule = SAMPLE_RULE;
setDisplayFieldValue(PAGE_DESC_ACTION, modelManager
.getString("addrule.pagetitle"));
} else { // Editing an existing rule
currentRule = (String) netletRules.get(currentRow);
setDisplayFieldValue(PAGE_DESC_ACTION, modelManager
.getString("editrule.pagetitle"));
}
setDisplayFieldValue(CHILD_RULE_INDEX, currentRow);
if (currentRule.endsWith("EXTEND")) {
currentRule = currentRule.substring(
0,
currentRule.lastIndexOf("EXTEND")).trim();
setDisplayFieldValue(CHILD_EXTEND, "true");
} else {
setDisplayFieldValue(CHILD_EXTEND, "false");
}
StringTokenizer st = new StringTokenizer(currentRule, RULE_DELIM);
String tmp = null;
try {
tmp = st.nextToken();
setDisplayFieldValue(CHILD_SELECTED_ALGOS, tmp); // Set the
// hidden field
// value
// required for
// JS
// to select appropriate algorithms for this rule
tmp = (new StringTokenizer(tmp, ALGO_DELIM)).nextToken();
setDisplayFieldValue(CHILD_RULENAME, tmp);
tmp = st.nextToken();
setDisplayFieldValue(CHILD_URL, tmp);
tmp = st.nextToken();
if (tmp.equalsIgnoreCase("false")) {
setDisplayFieldValue(CHILD_DOWNLOADAPPLET_CB, "false");
} else if (tmp.equalsIgnoreCase("true")) {
setDisplayFieldValue(CHILD_DOWNLOADAPPLET_CB, "true");
} else {
setDisplayFieldValue(CHILD_DOWNLOADAPPLET_CB, "true");
setDisplayFieldValue(CHILD_DOWNLOADAPPLET_NAME, tmp);
}
OptionList optList = new OptionList();
ListBox lb = (ListBox) getChild(CHILD_PHPLIST);
String phpentry = null;
while (st.hasMoreTokens()) {
phpentry = st.nextToken();
phpentry += " " + st.nextToken();
phpentry += " " + st.nextToken();
optList.add(phpentry, phpentry);
}
optList.add("_______________________________________", "");
lb.setOptions(optList);
} catch (NoSuchElementException nsee) {
NetletAdminModelManager.debugError("Error parsing netlet rules "
+ nsee);
}
}
/**
* Returns true if Netlet attributes can be modified by the current user,
* false otherwise.
*/
public boolean beginNetletRulesBtnBlockDisplay(ChildDisplayEvent event) {
getModel();
return !model.isReadOnly("sunPortalNetletRules");
}
/**
* Sets the default algotithms for Netlet rule.
*/
public void setAlgorithmOptions(NetletAdminUserProfileModelImpl m) {
OptionList optList = new OptionList();
String[] ciphers = NetletConstants.NETLET_CIPHERS;
for (int i = 0; i < ciphers.length; i++) {
String option = ciphers[i];
optList.add(option, option);
}
ListBox lb = (ListBox) getChild(CHILD_ALGORITHMS);
lb.setOptions(optList);
}
/**
* Creates a new NetletAdminServiceModel and returns the same if the model
* is not already been created.
*/
public NetletAdminUserProfileModelImpl getModel() {
if (model == null) {
HttpServletRequest request = getRequestContext().getRequest();
model = new NetletAdminUserProfileModelImpl(
request,
getPageSessionAttributes());
model.initModel(getUserDN());
}
return model;
}
/**
* Creates a new NetletAdminModelManager and returns the same, if the model
* is not already been created.
*/
public NetletAdminModelManager getModelMgr() {
if (modelManager == null) {
modelManager = (NetletAdminModelManager) getRequestContext()
.getModelManager();
}
return modelManager;
}
/**
* Returns the current User DN.
*/
public String getUserDN() {
if (userDN == null) {
Map pageSessAttrs = getPageSessionAttributes();
userDN = (String) pageSessAttrs
.get("com-iplanet-am-admin-user-current-object");
}
return userDN;
}
/**
* Tests whether the given rule name is already in the list of Netlet rules. @ Returns
* true if the rule name is duplicate, false otherwise
*/
public boolean isDuplicate(String ruleName) {
if (netletRules != null && ruleName != null) {
for (int i = 0; i < netletRules.size(); i++) {
if (i == currentRow) {
continue;
}
StringTokenizer st1 = new StringTokenizer((String) netletRules
.get(i), RULE_DELIM);
String str2 = null;
if (st1.hasMoreTokens()) {
str2 = st1.nextToken();
st1 = new StringTokenizer(str2, ALGO_DELIM);
if (st1.hasMoreTokens()) {
str2 = st1.nextToken();
if (ruleName.equals(str2)) {
return true;
}
}
}
}
}
return false;
}
/**
* Returns the vector of all configured client ports.
*/
private Vector getClientPorts() {
Vector clientPorts = new Vector();
if (netletRules != null) {
for (int i = 0; i < netletRules.size(); ++i) {
if (i == currentRow) {
continue;
}
String nr = (String) netletRules.get(i);
if (nr.endsWith("EXTEND"))
nr = nr.substring(0, nr.lastIndexOf("|"));
StringTokenizer tok = new StringTokenizer(nr, "|");
try {
String func = (String) tok.nextElement();
String tmp = (String) tok.nextElement(); // url
tmp = (String) tok.nextElement(); // loopback
while (tok.hasMoreElements()) {
tmp = (String) tok.nextElement(); // local port
clientPorts.addElement(tmp);
tmp = (String) tok.nextElement(); // dest host
tmp = (String) tok.nextElement(); // dest port
}
} catch (NoSuchElementException nsee) {
continue; // skip non-parsable rules
}
}
}
return clientPorts;
}
/**
* Tests whether the given client port is already in the list of Netlet
* rules. @ Returns true if the client port is duplicate, false otherwise 8 @ Returns
* the StringBuffer with the list of client ports which are in use.
*/
public boolean isClientPortDuplicate(StringBuffer result) {
boolean duplicateFound = false;
int indexOfDuplicate = 0;
Vector clientPorts = getClientPorts();
ListBox lb = (ListBox) getDisplayField(CHILD_PHPLIST);
Object[] objValues = (Object[]) lb.getValues();
if ((objValues != null)) {
int size = objValues.length;
for (int i = 0; i < size && !duplicateFound; i++) {
String phpentry = (String) objValues[i];
StringTokenizer tok = new StringTokenizer(phpentry, " ");
try {
String tmp = tok.nextToken();
if (clientPorts.contains(tmp)) {
duplicateFound = true;
indexOfDuplicate = clientPorts.indexOf(tmp);
}
} catch (NoSuchElementException nsee) {
} catch (NumberFormatException nfe) {
}
}
}
if (duplicateFound) {
result.append("<ul>");
for (int i = 0; i < clientPorts.size(); ++i) {
result.append("<li>");
if (i == indexOfDuplicate) {
result.append("<font color=red>")
.append(clientPorts.get(i)).append("</font>");
} else {
result.append(clientPorts.get(i));
}
result.append("</li>");
}
result.append("</ul>");
}
return duplicateFound;
}
/**
* Appends the selected algorithms to the Netlet rule buffer.
*/
public void appendAlgorithm(StringBuffer nrBuffer) {
ListBox lb = (ListBox) getDisplayField(CHILD_ALGORITHMS);
Object[] objValues = (Object[]) lb.getValues();
if (objValues != null) {
int size = objValues.length;
if (size > 1) {
nrBuffer.append(ALGO_DELIM + "ALGO");
}
boolean firstAlgo = true;
for (int i = 0; i < size; i++) {
if ((objValues[i] != null)
&& (((String) objValues[i]).trim().length() != 0)) {
if (firstAlgo) {
firstAlgo = false;
nrBuffer.append(ALGO_DELIM + (String) objValues[i]);
} else {
nrBuffer.append("+" + (String) objValues[i]);
}
}
}
}
}
/**
* Appends the "Download Applet" field value to the netlet rule.
*/
public void appendDownloadApplet(StringBuffer nrBuffer) {
String str1 = (String) getDisplayFieldValue(CHILD_DOWNLOADAPPLET_CB);
if (str1.equals("false")) {
nrBuffer.append(RULE_DELIM + str1);
} else {
str1 = (String) getDisplayFieldValue(CHILD_DOWNLOADAPPLET_NAME);
if ((str1 == null) || (str1.trim().length() == 0)) {
nrBuffer.append(RULE_DELIM + "true");
} else {
StringTokenizer tok = new StringTokenizer(str1, ":");
StringBuffer sb = new StringBuffer();
try {
String tmp = tok.nextToken();
int port = Integer.parseInt(tmp);
sb.append(tmp);
sb.append(":" + tok.nextToken());
tmp = tok.nextToken();
port = Integer.parseInt(tmp);
sb.append(":" + tmp);
nrBuffer.append(RULE_DELIM + sb.toString());
} catch (NoSuchElementException nse) {
nrBuffer.append(RULE_DELIM + "true");
} catch (NumberFormatException nfe) {
nrBuffer.append(RULE_DELIM + "true");
}
}
}
}
/**
* Appends the Port-Host-Port list to the rule. @ Returns true on success,
* false if error occurs.
*/
public boolean appendPortHostPort(StringBuffer nrBuffer) {
ListBox lb = (ListBox) getDisplayField(CHILD_PHPLIST);
Object[] objValues = (Object[]) lb.getValues();
if ((objValues == null) || (objValues.length == 0)) {
return false;
} else {
int size = objValues.length;
boolean atleastOne = false;
for (int i = 0; i < size; i++) {
String phpentry = (String) objValues[i];
StringTokenizer tok = new StringTokenizer(phpentry, " ");
StringBuffer sb = new StringBuffer();
try {
String tmp = tok.nextToken();
int port = Integer.parseInt(tmp);
sb.append(tmp);
sb.append(RULE_DELIM + tok.nextToken());
sb.append(RULE_DELIM + tok.nextToken());
nrBuffer.append(RULE_DELIM + sb.toString());
atleastOne = true;
} catch (NoSuchElementException nsee) {
} catch (NumberFormatException nfe) {
}
}
if (!atleastOne) {
return false;
}
}
return true;
}
/**
* Handles Save button request in EditNetletRule Page.
*/
public void handleSaveButtonRequest(RequestInvocationEvent event)
throws ModelControlException {
/*
* Get all the display field values and store it to the backend
*/
getModel();
Set s = model.getNetletRules();
netletRules = new Vector(s);
String currRow = (String) getDisplayFieldValue(CHILD_RULE_INDEX);
try {
currentRow = Integer.parseInt(currRow);
} catch (NumberFormatException nfe) {
currentRow = -1;
NetletAdminModelManager.debugError("Error getting rule index : "
+ nfe);
}
StringBuffer nrBuffer = new StringBuffer();
String newRule = null;
Set newRuleSet = null;
Map newMap = null;
String str1 = (String) getDisplayFieldValue(CHILD_RULENAME);
/**
* Test whether the rule name is null or empty.
*/
if ((str1 == null) || (str1.trim().length() == 0)) {
redirectToMsgVB("invalidrule.title", "rulename.error", null);
return;
}
/**
* Test for duplicate rulenames when adding a new rule
*/
if (isDuplicate(str1)) {
redirectToMsgVB(
"invalidrule.title",
"duplicaterulename.error",
null);
return;
}
nrBuffer.append(str1);
/**
* Append the selected algorithms to the rule.
*/
appendAlgorithm(nrBuffer);
/**
* Append the URL to the rule.
*/
str1 = (String) getDisplayFieldValue(CHILD_URL);
if ((str1 == null) || (str1.trim().length() == 0)) {
str1 = "null";
}
nrBuffer.append(RULE_DELIM + str1);
/**
* Append "Download applet" field value to the rule.
*/
appendDownloadApplet(nrBuffer);
/**
* Test for duplicate client ports when adding a new Netlet rule
*/
StringBuffer sb = new StringBuffer();
if (isClientPortDuplicate(sb)) {
redirectToMsgVB(
"invalidrule.title",
"duplicateclientport.error",
new Object[] { sb });
return;
}
/**
* Append the port-host-port list to the rule.
*/
if (!appendPortHostPort(nrBuffer)) {
redirectToMsgVB("invalidrule.title", "phplist.error", null);
return;
}
/**
* Append "Extend Session" field value to the Netlet rule.
*/
str1 = (String) getDisplayFieldValue(CHILD_EXTEND);
if (str1.equals("true")) {
nrBuffer.append(RULE_DELIM + "EXTEND");
}
/**
* Convert Netlet rule to String object and store it to the backend.
*/
newRule = nrBuffer.toString();
NetletAdminModelManager.debugMessage("newRule = " + newRule);
if (netletRules == null) {
netletRules = new Vector();
}
if (currentRow == -1) { // New rule
netletRules.add(netletRules.size(), newRule);
} else {
netletRules.set(currentRow, newRule);
}
newRuleSet = new HashSet(netletRules);
newMap = new HashMap();
newMap.put("sunPortalNetletRules", newRuleSet);
boolean success = model.store(newMap);
/**
* Forward the request to the NetletAdminServiceViewBean
*/
redirectToNASURL();
}
/**
* Handles the Cancel button request.
*/
public void handleCancelButtonRequest(RequestInvocationEvent event)
throws ModelControlException {
redirectToNASURL();
}
/**
* Handles the page title HREF link request.
*/
public void handleServiceDescHrefRequest(RequestInvocationEvent event)
throws ModelControlException {
redirectToNASURL();
}
/**
* Passes the current page session Map to the another view bean.
*/
public void passPgSessionMap(ViewBean other) {
Map attributes = getPageSessionAttributes();
if ((attributes != null) && (attributes.size() > 0)) {
Iterator iter = attributes.keySet().iterator();
while (iter.hasNext()) {
String key = (String) iter.next();
other.setPageSessionAttribute(key, (Serializable) attributes
.get(key));
}
}
}
/**
* Redirects the Request to NetletAdminServiceViewBean.
*/
public void redirectToNASURL() {
NetletAdminUserProfileViewBean vb = (NetletAdminUserProfileViewBean) getViewBean(NetletAdminUserProfileViewBean.class);
passPgSessionMap(vb);
vb.forwardTo(getRequestContext());
}
/**
* Redirects request to Message view bean.
*/
public void redirectToMsgVB(String title, String msgKey, Object objs[]) {
AMMessageViewBean msgVB = (AMMessageViewBean) getViewBean(com.iplanet.am.console.base.AMMessageViewBean.class);
msgVB.setMessageType(MessageBox.TYPE_WARNING);
msgVB.setTitle(modelManager.getString(title));
if (objs != null) {
msgVB.setMessage(MessageFormat.format(modelManager
.getString(msgKey), objs));
} else {
msgVB.setMessage(modelManager.getString(msgKey));
}
String nasURL = getModuleURL()
+ "/"
+ NetletAdminUserProfileViewBean.PAGE_NAME;
nasURL = AMViewBeanUtils.appendPgSession(
nasURL,
getPageSessionAttributes());
msgVB.addButton(modelManager.getString("ok.button"), nasURL);
msgVB.forwardTo(getRequestContext());
}
/**
* Returns localized JavaScript error messages.
*/
private String getErrorMessages() {
getModelMgr();
StringBuffer sb = new StringBuffer();
sb.append("errorMessages['emptyFields'] = '"
+ modelManager.getString("emptyFields")
+ "';\n");
sb.append("errorMessages['invalidclientport'] = '"
+ modelManager.getString("invalidclientport")
+ "';\n");
sb.append("errorMessages['invalidtargethost'] = '"
+ modelManager.getString("invalidtargethost")
+ "';\n");
sb.append("errorMessages['invalidtargetport'] = '"
+ modelManager.getString("invalidtargetport")
+ "';\n");
sb.append("errorMessages['dynamictargetport'] = '"
+ modelManager.getString("dynamictargetport")
+ "';\n");
sb.append("errorMessages['targetportlist'] = '"
+ modelManager.getString("targetportlist")
+ "';\n");
sb.append("errorMessages['duplicatetargets'] = '"
+ modelManager.getString("duplicatetargets")
+ "';\n");
sb.append("errorMessages['duplicateclientport'] = '"
+ modelManager.getString("duplicateclientport")
+ "';");
return sb.toString();
}
}
|