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: Anurag Gupta
014: */package com.sun.portal.netfile.admin;
015:
016: // JDK classes
017: import java.util.HashSet;
018: import com.sun.portal.log.common.PortalLogger;
019: import java.util.HashMap;
020: import java.util.Iterator;
021: import java.util.List;
022: import java.util.LinkedList;
023: import java.util.Map;
024: import java.util.Set;
025: import java.util.StringTokenizer;
026: import java.util.Vector;
027: import java.security.AccessController;
028:
029: import com.sun.identity.security.EncryptAction;
030:
031: // iPlanet JATO classes
032: import com.iplanet.jato.model.ModelControlException;
033: import com.iplanet.jato.view.View;
034: import com.iplanet.jato.view.event.ChildDisplayEvent;
035: import com.iplanet.jato.view.event.DisplayEvent;
036: import com.iplanet.jato.view.event.RequestInvocationEvent;
037: import com.iplanet.jato.view.html.ComboBox;
038: import com.iplanet.jato.view.html.HiddenField;
039: import com.iplanet.jato.view.html.OptionList;
040: import com.iplanet.jato.view.html.ListBox;
041: import com.iplanet.jato.view.html.StaticTextField;
042:
043: // iDS/AME classes
044: import com.iplanet.am.console.components.view.html.IPlanetButton;
045: import com.iplanet.am.console.components.view.html.MessageBox;
046: import com.iplanet.am.console.base.model.AMConsoleException;
047:
048: // NetFile admin console classes
049: import com.sun.portal.netfile.admin.model.NetFileUserProfileModelImpl;
050:
051: public class NetFileTotalOneUserProfileViewBean extends
052: NetFileUserProfileViewBeanBase implements
053: NetFileHostTypeConstants, NetFileEncodingTypeConstants {
054:
055: public static final String PAGE_NAME = "NetFileTotalOneUserProfile";
056: public static final String DEFAULT_DISPLAY_URL = "/ps/netfileadmin/NetFileTotalOneUserProfile.jsp";
057: public static final String CHILD_OSCHARSET_LBL = "osCharSetLabel";
058: public static final String CHILD_OSCHARSET = "osCharSet";
059: public static final String OSCHARSET_STATUS = "osCharSetStatus";
060: public static final String CHILD_HOSTORDER_LBL = "hostorderLabel";
061: public static final String CHILD_HOSTORDER = "hostorder";
062: public static final String CHILD_MOVEUP_BTN = "moveupButton";
063: public static final String CHILD_MOVEDOWN_BTN = "movedownButton";
064: public static final String HOSTORDER_STATUS = "hostorderStatus";
065: public static final String CHILD_TILEDVIEW = "NetFileHostsTiledView";
066: public static final String CHILD_NAME_LABEL = "nameLabel";
067: public static final String CHILD_ACTION_LABEL = "actionLabel";
068: public static final String NETFILE_HOSTS_LABEL = "netFileHostsLabel";
069: public static final String NETFILE_HOSTS_STATUS = "hostsStatus";
070: public static final String ADD_NETFILE_HOST_BTN = "addhostButton";
071: public static final String DELETE_NETFILE_HOST_BTN = "delhostsButton";
072: public static final String NETFILE_HOSTS_COUNT = "netFileHostsCount";
073: public static final String NO_HOST_SELECTION = "noHostSelection";
074: public static final String CONFIRM_HOST_DELETE = "confirmHostDelete";
075: public static final String ATTR_OSCHARSET = "sunPortalNetFileOSCharSet";
076: public static final String ATTR_HOST_ORDER = "sunPortalNetFileHostDetectOrder";
077: public static final String ATTR_COMMON_HOST = "sunPortalNetFileCommonHostData";
078:
079: public NetFileTotalOneUserProfileViewBean() {
080: super (PAGE_NAME, DEFAULT_DISPLAY_URL);
081: registerChildren();
082: }
083:
084: public NetFileTotalOneUserProfileViewBean(String pageName) {
085: super (pageName, DEFAULT_DISPLAY_URL);
086: registerChildren();
087: }
088:
089: protected void registerChildren() {
090: super .registerChildren();
091: registerChild(USER_DATA_VIEW,
092: NetFileTotalOneUserProfileView.class);
093: registerChild(CHILD_OSCHARSET_LBL, StaticTextField.class);
094: registerChild(CHILD_OSCHARSET, ComboBox.class);
095: registerChild(OSCHARSET_STATUS, ComboBox.class);
096: registerChild(CHILD_HOSTORDER_LBL, StaticTextField.class);
097: registerChild(CHILD_HOSTORDER, ListBox.class);
098: registerChild(CHILD_MOVEUP_BTN, IPlanetButton.class);
099: registerChild(CHILD_MOVEDOWN_BTN, IPlanetButton.class);
100: registerChild(HOSTORDER_STATUS, ComboBox.class);
101: registerChild(CHILD_TILEDVIEW,
102: NetFileHostsUserProfileTiledView.class);
103: registerChild(CHILD_NAME_LABEL, StaticTextField.class);
104: registerChild(CHILD_ACTION_LABEL, StaticTextField.class);
105: registerChild(NETFILE_HOSTS_LABEL, StaticTextField.class);
106: registerChild(NETFILE_HOSTS_STATUS, ComboBox.class);
107: registerChild(ADD_NETFILE_HOST_BTN, IPlanetButton.class);
108: registerChild(DELETE_NETFILE_HOST_BTN, IPlanetButton.class);
109: registerChild(NETFILE_HOSTS_COUNT, HiddenField.class);
110: registerChild(NO_HOST_SELECTION, StaticTextField.class);
111: registerChild(CONFIRM_HOST_DELETE, StaticTextField.class);
112: registerChild(JAVA2_ONLY, StaticTextField.class);
113: }
114:
115: protected View createChild(String name) {
116: getNetFileModelMgr();
117: NetFileUserProfileModelImpl m = (NetFileUserProfileModelImpl) getModel();
118: m.initModel(getUserDN());
119: View child = null;
120:
121: if (name.equals(CHILD_NETFILE_ATTRSFOR)) {
122: child = new StaticTextField(this , CHILD_NETFILE_ATTRSFOR,
123: modelManager.getString("props.total.one")
124: + " "
125: + modelManager.getString("for.label")
126: + " "
127: + modelManager
128: .getString("props.total.one.one")
129: + " " + modelManager.getString("for.label")
130: + " :");
131: } else if (name.equals(USER_DATA_VIEW)) {
132: child = new NetFileTotalOneUserProfileView(this ,
133: USER_DATA_VIEW);
134: } else if (name.equals(CHILD_OSCHARSET_LBL)) {
135: child = new StaticTextField(this , CHILD_OSCHARSET_LBL, m
136: .getAttrLabel(ATTR_OSCHARSET));
137: } else if (name.equals(CHILD_OSCHARSET)) {
138: child = new ComboBox(this , CHILD_OSCHARSET, "");
139: } else if (name.equals(OSCHARSET_STATUS)) {
140: child = new ComboBox(this , OSCHARSET_STATUS, "");
141: } else if (name.equals(CHILD_HOSTORDER_LBL)) {
142: child = new StaticTextField(this , CHILD_HOSTORDER_LBL, m
143: .getAttrLabel(ATTR_HOST_ORDER));
144: } else if (name.equals(CHILD_HOSTORDER)) {
145: child = new ListBox(this , CHILD_HOSTORDER, "");
146: } else if (name.equals(CHILD_MOVEUP_BTN)) {
147: child = new IPlanetButton(this , CHILD_MOVEUP_BTN,
148: modelManager.getString("moveup.button"));
149: } else if (name.equals(CHILD_MOVEDOWN_BTN)) {
150: child = new IPlanetButton(this , CHILD_MOVEDOWN_BTN,
151: modelManager.getString("movedown.button"));
152: } else if (name.equals(HOSTORDER_STATUS)) {
153: child = new ComboBox(this , HOSTORDER_STATUS, "");
154: } else if (name.equals(CHILD_TILEDVIEW)) {
155: child = new NetFileHostsUserProfileTiledView(this ,
156: CHILD_TILEDVIEW);
157: } else if (name.equals(CHILD_NAME_LABEL)) {
158: child = new StaticTextField(this , CHILD_NAME_LABEL,
159: modelManager.getString("name.label"));
160: } else if (name.equals(CHILD_ACTION_LABEL)) {
161: child = new StaticTextField(this , CHILD_ACTION_LABEL,
162: modelManager.getString("action.label"));
163: } else if (name.equals(NETFILE_HOSTS_LABEL)) {
164: int netfilehostsIndex = m.getNetFileHostsIndex();
165: m.setCurrentRow(netfilehostsIndex);
166: child = new StaticTextField(this , NETFILE_HOSTS_LABEL, m
167: .getAttrLabel()
168: + ":");
169: } else if (name.equals(NETFILE_HOSTS_STATUS)) {
170: child = new ComboBox(this , NETFILE_HOSTS_STATUS, "");
171: } else if (name.equals(NETFILE_HOSTS_COUNT)) {
172: child = new HiddenField(this , NETFILE_HOSTS_COUNT, "");
173: } else if (name.equals(NO_HOST_SELECTION)) {
174: child = new StaticTextField(this , NO_HOST_SELECTION,
175: modelManager.getString("nohostselection"));
176: } else if (name.equals(CONFIRM_HOST_DELETE)) {
177: child = new StaticTextField(this , CONFIRM_HOST_DELETE,
178: modelManager.getString("confirmhostdelete"));
179: } else if (name.equals(ADD_NETFILE_HOST_BTN)) {
180: child = new IPlanetButton(this , ADD_NETFILE_HOST_BTN,
181: modelManager.getString("add.button"));
182: } else if (name.equals(DELETE_NETFILE_HOST_BTN)) {
183: child = new IPlanetButton(this , DELETE_NETFILE_HOST_BTN,
184: modelManager.getString("delete.button"));
185: } else if (name.equals(JAVA2_ONLY)) {
186: child = new StaticTextField(this , JAVA2_ONLY, modelManager
187: .getString("java2Only"));
188: } else {
189: child = super .createChild(name);
190: }
191: return child;
192: }
193:
194: public ComboBox setOSCharSetOptions() {
195: OptionList optList = new OptionList();
196: String tmp;
197: for (int count = 0; count < encodingTypeOptionList.length; count++) {
198: tmp = modelManager.getString("encoding_"
199: + encodingTypeOptionList[count]);
200: optList.add(tmp, tmp);
201: }
202: ComboBox cb = (ComboBox) getDisplayField(CHILD_OSCHARSET);
203: cb.setOptions(optList);
204: return cb;
205: }
206:
207: public void beginDisplay(DisplayEvent event)
208: throws ModelControlException {
209: getNetFileModelMgr();
210: NetFileUserProfileModelImpl m = (NetFileUserProfileModelImpl) getModel();
211: setChildValues(model);
212: m.initModel(getUserDN());
213: setDisplayFieldValue(PAGE_DESCRIPTION, m
214: .getServiceDescription());
215: setDisplayFieldValue(SAVE_BTN, modelManager
216: .getString("save.button"));
217: setDisplayFieldValue(RESET_BTN, modelManager
218: .getString("reset.button"));
219: setDisplayFieldValue(CHILD_USERID, m.getUserID());
220:
221: ComboBox osCharSetCB = setOSCharSetOptions();
222: Set valueSet = m.getAttrValues(ATTR_OSCHARSET);
223: String value = null;
224: if (valueSet != null && valueSet.iterator().hasNext()) {
225: value = (String) valueSet.iterator().next();
226: }
227: value = modelManager.getString(value);
228: osCharSetCB.setValue(value);
229:
230: valueSet = m.getAttrValues(ATTR_HOST_ORDER);
231: if (valueSet != null && valueSet.iterator().hasNext()) {
232: value = (String) valueSet.iterator().next();
233: }
234: OptionList optList = new OptionList();
235: ListBox lb = (ListBox) getChild(CHILD_HOSTORDER);
236: StringTokenizer st = new StringTokenizer(value);
237: String tmp;
238: while (st.hasMoreTokens()) {
239: tmp = st.nextToken();
240: optList.add(modelManager.getString("hostType." + tmp), tmp);
241: }
242: lb.setOptions(optList);
243: if (!m.isReadOnly(ATTR_OSCHARSET)) {
244: setStatusOptions(m, OSCHARSET_STATUS);
245: }
246: if (!m.isReadOnly(ATTR_HOST_ORDER)) {
247: setStatusOptions(m, HOSTORDER_STATUS);
248: }
249: if (!m.isReadOnly(ATTR_COMMON_HOST)) {
250: setStatusOptions(m, NETFILE_HOSTS_STATUS);
251: }
252:
253: setDisplayFieldValue(NETFILE_HOSTS_COUNT, m
254: .getNetFileHostsCount());
255: }
256:
257: public void handleSaveButtonRequest(RequestInvocationEvent event)
258: throws ModelControlException {
259: NetFileUserProfileModelImpl m = (NetFileUserProfileModelImpl) getModel();
260: m.initModel(getUserDN());
261: getNetFileModelMgr();
262: try {
263: processAttributes();
264: int size = attrValues.size();
265: Map userOnlyAttrs = new HashMap(size);
266: Map customizedAttrs = new HashMap(size);
267: Set inheritedAttrs = new HashSet(size);
268: Set nameSet = attrStatus.keySet();
269: Iterator nameIter = nameSet.iterator();
270: while (nameIter.hasNext()) {
271: String attrName = (String) nameIter.next();
272: Set values = (Set) attrValues.get(attrName);
273: String status = (String) attrStatus.get(attrName);
274: if (!m.isReadOnly(attrName)
275: && (status == null || status.trim().length() == 0)) {
276: userOnlyAttrs.put(attrName, values);
277: } else if (!m.isReadOnly(attrName)
278: && status.equals(m.getCustomizeValue())) {
279: customizedAttrs.put(attrName, values);
280: } else if (!m.isReadOnly(attrName)
281: && status.equals(m.getInheritValue())) {
282: inheritedAttrs.add(attrName);
283: } else if (!m.isReadOnly(attrName)
284: && status.equals(m.getSkipValue())) {
285: userOnlyAttrs.put(attrName, values);
286: }
287: }
288:
289: String netFileOsCharSetStatus = (String) getDisplayFieldValue(OSCHARSET_STATUS);
290: if (netFileOsCharSetStatus.equals(m.getCustomizeValue())) {
291: ComboBox cb = (ComboBox) getDisplayField(CHILD_OSCHARSET);
292: String osCharSetValue = (String) (cb.getValue());
293: String tmp;
294: for (int count = 0; count < encodingTypeOptionList.length; count++) {
295: tmp = modelManager.getString("encoding_"
296: + encodingTypeOptionList[count]);
297: if (osCharSetValue.equals(tmp)) {
298: //osCharSetValue = encodingTypeOptionList[count];
299: break;
300: }
301: }
302: Vector osCharSetVector = new Vector(1);
303: osCharSetVector.add(osCharSetValue);
304: HashSet osCharSet = new HashSet(osCharSetVector);
305: customizedAttrs.put(ATTR_OSCHARSET, osCharSet);
306: } else if (netFileOsCharSetStatus.equals(m
307: .getInheritValue())) {
308: inheritedAttrs.add(ATTR_OSCHARSET);
309: }
310:
311: String netFileHostOrderStatus = (String) getDisplayFieldValue(HOSTORDER_STATUS);
312: if (netFileHostOrderStatus.equals(m.getCustomizeValue())) {
313: ListBox lb = (ListBox) getDisplayField(CHILD_HOSTORDER);
314: Object[] objValues = (Object[]) lb.getValues();
315: StringBuffer sb = new StringBuffer();
316: String tmp;
317: /*
318: int tmpInt;
319: OptionList optList = new OptionList();
320: for (int count = 0; count < hostTypeOptionList.length; count++) {
321: tmp = modelManager.getString("hostType." + hostTypeOptionList[count]);
322: optList.add(hostTypeOptionList[count], tmp);
323: }
324: */
325: for (int count = 0; count < objValues.length; count++) {
326: tmp = objValues[count].toString();
327: //tmp = optList.getValueLabel(tmp);
328: sb.append(tmp + "\n");
329: }
330: String hostOrderValue = sb.toString();
331: hostOrderValue = hostOrderValue.substring(0,
332: hostOrderValue.lastIndexOf("\n"));
333: Vector hostOrderValueVector = new Vector(1);
334: hostOrderValueVector.add(hostOrderValue);
335: HashSet hostOrderValueSet = new HashSet(
336: hostOrderValueVector);
337: customizedAttrs.put(ATTR_HOST_ORDER, hostOrderValueSet);
338: } else if (netFileHostOrderStatus.equals(m
339: .getInheritValue())) {
340: inheritedAttrs.add(ATTR_HOST_ORDER);
341: }
342:
343: String netFileHostsStatus = (String) getDisplayFieldValue(NETFILE_HOSTS_STATUS);
344: //functionality is same for both inherit and ignore cases
345: if (netFileHostsStatus.equals(m.getInheritValue())
346: || netFileHostsStatus.equals(m.getSkipValue())) {
347: inheritedAttrs.add(ATTR_COMMON_HOST);
348: }
349: m.storeAttributes(userOnlyAttrs, customizedAttrs,
350: inheritedAttrs);
351: } catch (AMConsoleException ace) {
352: }
353: forwardTo();
354: }
355:
356: public boolean beginNetFileHostsStatusDisplay(
357: ChildDisplayEvent event) {
358: NetFileUserProfileModelImpl m = (NetFileUserProfileModelImpl) getModel();
359: m.initModel(getUserDN());
360: return !m.isReadOnly(ATTR_COMMON_HOST);
361: }
362:
363: public boolean beginNetFileHostsBtnBlockDisplay(
364: ChildDisplayEvent event) {
365: NetFileUserProfileModelImpl m = (NetFileUserProfileModelImpl) getModel();
366: m.initModel(getUserDN());
367: return !m.isReadOnly(ATTR_COMMON_HOST);
368: }
369:
370: public NetFileHostsUserProfileTiledView getNetFileHostsUserProfileTiledView() {
371: return (NetFileHostsUserProfileTiledView) getChild(CHILD_TILEDVIEW);
372: }
373:
374: public void handleAddhostButtonRequest(RequestInvocationEvent event)
375: throws ModelControlException {
376: getNetFileModelMgr();
377: modelManager.setCurrentNetFileHostsRow(-1);
378: NetFileHostsUserProfileViewBean vb = (NetFileHostsUserProfileViewBean) getViewBean(NetFileHostsUserProfileViewBean.class);
379: passPgSessionMap(vb);
380: vb.forwardTo(getRequestContext());
381: }
382:
383: public void handleDelhostsButtonRequest(RequestInvocationEvent event)
384: throws ModelControlException {
385: NetFileHostsUserProfileTiledView tileView = getNetFileHostsUserProfileTiledView();
386: tileView.getPrimaryModel().setSize(
387: tileView.getNetFileHostsCount());
388: List selections = new LinkedList();
389: while (tileView.nextTile()) {
390: String value = (String) tileView
391: .getDisplayFieldValue(NetFileHostsUserProfileTiledView.CHILD_CB_SELECT_HOST);
392: if (value.equals("true")) {
393: value = (String) tileView
394: .getDisplayFieldValue(NetFileHostsUserProfileTiledView.CHILD_HREF_TEXT);
395: selections.add(value);
396: }
397: }
398:
399: if (selections.size() == 0) {
400: getNetFileModelMgr();
401: MessageBox msgBox = (MessageBox) getDisplayField(CHILD_CC_MSGBOX);
402: msgBox.setTitle(modelManager
403: .getString("noselectionmsgbox.title"));
404: msgBox
405: .setMessage(modelManager
406: .getString("nohostselection"));
407: msgBox.setType(MessageBox.TYPE_ERROR);
408: msgBox.setVisible(true);
409: /* Redisplay the page with the error */
410: forwardTo();
411: return;
412: } else if (selections.size() > 0) {
413: Vector netFileHosts = tileView.getNetFileHosts();
414: int nhSize = netFileHosts.size();
415: if (netFileHosts != null) {
416: for (int i = 0; i < selections.size(); i++) {
417: for (int j = 0; j < netFileHosts.size(); j++) {
418: StringTokenizer st1 = new StringTokenizer(
419: (String) netFileHosts.get(j),
420: NetFileHostsViewBean.HOST_DELIM);
421: if (st1.hasMoreTokens()) {
422: String hostname = st1.nextToken();
423: hostname = hostname
424: .substring(NetFileHostsViewBean.hostListStrHost
425: .length());
426: if (hostname.equals(selections.get(i))) {
427: netFileHosts.remove(j);
428: --j;
429: }
430: }
431: }
432: }
433: }
434: Set newHostSet = new HashSet();
435: if (!netFileHosts.isEmpty()) {
436: Iterator hosts = netFileHosts.iterator();
437: while (hosts.hasNext())
438: newHostSet.add((String) AccessController
439: .doPrivileged(new EncryptAction(
440: (String) hosts.next())));
441: }
442:
443: Map newMap = new HashMap();
444: newMap.put(ATTR_COMMON_HOST, newHostSet);
445: NetFileUserProfileModelImpl m = (NetFileUserProfileModelImpl) getModel();
446: m.initModel(getUserDN());
447: boolean success = m.store(newMap);
448: //redirectToPage(NetFileUserProfileViewBeanBase.PAGE_NAME);
449: forwardTo();
450: }
451: }
452:
453: private void setStatusOptions(NetFileUserProfileModelImpl model,
454: String attrStatus) {
455: OptionList optionList = new OptionList();
456: optionList.add(model.getCustomizeLabel(), model
457: .getCustomizeValue());
458: optionList
459: .add(model.getInheritLabel(), model.getInheritValue());
460: optionList.add(model.getSkipLabel(), model.getSkipValue());
461: ComboBox cb = (ComboBox) getChild(attrStatus);
462: cb.setOptions(optionList);
463: cb.setValue(model.getSkipValue());
464: }
465:
466: }
|