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.io.IOException;
018: import com.sun.portal.log.common.PortalLogger;
019: import java.util.HashMap;
020: import java.util.HashSet;
021: import java.util.Iterator;
022: import java.util.LinkedList;
023: import java.util.List;
024: import java.util.Map;
025: import java.util.Set;
026: import java.util.Vector;
027: import java.util.StringTokenizer;
028: import java.security.AccessController;
029:
030: // Servlet classes
031: import javax.servlet.http.HttpServletResponse;
032:
033: import com.sun.identity.security.EncryptAction;
034:
035: // iPlanet JATO classes
036: import com.iplanet.jato.model.ModelControlException;
037: import com.iplanet.jato.view.View;
038: import com.iplanet.jato.view.event.DisplayEvent;
039: import com.iplanet.jato.view.event.ChildDisplayEvent;
040: import com.iplanet.jato.view.event.RequestInvocationEvent;
041: import com.iplanet.jato.view.html.ComboBox;
042: import com.iplanet.jato.view.html.HiddenField;
043: import com.iplanet.jato.view.html.ListBox;
044: import com.iplanet.jato.view.html.OptionList;
045: import com.iplanet.jato.view.html.StaticTextField;
046:
047: // iDS/AME classes
048: import com.iplanet.am.console.base.model.AMAdminConstants;
049: import com.iplanet.am.console.base.model.AMConsoleException;
050: import com.iplanet.am.console.components.view.html.DynamicGUI;
051: import com.iplanet.am.console.components.view.html.IPlanetButton;
052: import com.iplanet.am.console.components.view.html.MessageBox;
053: import com.iplanet.sso.SSOException;
054:
055: // NetFile admin console classes
056: import com.sun.portal.netfile.admin.model.NetFileModel;
057:
058: public class NetFileTotalOneViewBean extends NetFileViewBeanBase
059: implements NetFileAdminService, AMAdminConstants,
060: NetFileHostTypeConstants, NetFileEncodingTypeConstants {
061:
062: public static final String PAGE_NAME = "NetFileTotalOne";
063: public static final String DEFAULT_DISPLAY_URL = "/ps/netfileadmin/NetFileTotalOne.jsp";
064: public static final String PAGE_LABEL = "lblTotalOne";
065: public static final String CHILD_OSCHARSET_LBL = "osCharSetLabel";
066: public static final String CHILD_OSCHARSET = "osCharSet";
067: public static final String CHILD_HOSTORDER_LBL = "hostorderLabel";
068: public static final String CHILD_HOSTORDER = "hostorder";
069: public static final String CHILD_MOVEUP_BTN = "moveupButton";
070: public static final String CHILD_MOVEDOWN_BTN = "movedownButton";
071: public static final String CHILD_TILEDVIEW = "NetFileHostsTiledView";
072: public static final String CHILD_NAME_LABEL = "nameLabel";
073: public static final String CHILD_NOCOMMONHOSTS_LABEL = "noCommonHostsLabel";
074: public static final String CHILD_ACTION_LABEL = "actionLabel";
075: public static final String NETFILE_HOSTS_LABEL = "netFileHostsLabel";
076: public static final String ADD_NETFILEHOST_BTN = "addhostButton";
077: public static final String DELETE_NETFILEHOSTS_BTN = "delhostsButton";
078: public static final String NETFILE_HOSTS_COUNT = "netFileHostsCount";
079: public static final String NO_HOST_SELECTION = "noHostSelection";
080: public static final String CONFIRM_HOST_DELETE = "confirmHostDelete";
081:
082: public static final String ATTR_OSCHARSET = "sunPortalNetFileOSCharSet";
083: public static final String ATTR_HOST_ORDER = "sunPortalNetFileHostDetectOrder";
084: public static final String ATTR_COMMON_HOST = "sunPortalNetFileCommonHostData";
085:
086: public NetFileTotalOneViewBean(String pageName) {
087: super (pageName);
088: registerChildren();
089: }
090:
091: public NetFileTotalOneViewBean() {
092: super (PAGE_NAME);
093: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
094: registerChildren();
095: }
096:
097: protected void registerChildren() {
098: super .registerChildren();
099: registerChild(GLOBAL_DATA_VIEW, NetFileTotalOneView.class);
100: registerChild(ORG_DATA_VIEW, NetFileTotalOneView.class);
101: registerChild(DYNAMIC_DATA_VIEW, NetFileTotalOneView.class);
102: registerChild(PAGE_LABEL, StaticTextField.class);
103: registerChild(CHILD_OSCHARSET_LBL, StaticTextField.class);
104: registerChild(CHILD_OSCHARSET, ComboBox.class);
105: registerChild(CHILD_HOSTORDER_LBL, StaticTextField.class);
106: registerChild(CHILD_HOSTORDER, ListBox.class);
107: registerChild(CHILD_MOVEUP_BTN, IPlanetButton.class);
108: registerChild(CHILD_MOVEDOWN_BTN, IPlanetButton.class);
109: registerChild(CHILD_TILEDVIEW, NetFileHostsTiledView.class);
110: registerChild(CHILD_NAME_LABEL, StaticTextField.class);
111: registerChild(CHILD_NOCOMMONHOSTS_LABEL, StaticTextField.class);
112: registerChild(CHILD_ACTION_LABEL, StaticTextField.class);
113: registerChild(NETFILE_HOSTS_LABEL, StaticTextField.class);
114: registerChild(ADD_NETFILEHOST_BTN, IPlanetButton.class);
115: registerChild(DELETE_NETFILEHOSTS_BTN, IPlanetButton.class);
116: registerChild(NETFILE_HOSTS_COUNT, HiddenField.class);
117: registerChild(NO_HOST_SELECTION, StaticTextField.class);
118: registerChild(CONFIRM_HOST_DELETE, StaticTextField.class);
119: registerChild(JAVA2_ONLY, StaticTextField.class);
120: }
121:
122: /**
123: * creates child view/component
124: *
125: * @param name of view/component
126: * @return child view/component
127: */
128: protected View createChild(String name) {
129: getNetFileModelMgr();
130: View child = null;
131: int viewType = NetFileModel.DYNAMIC_TYPE;
132:
133: if (name.equals(GLOBAL_DATA_VIEW)) {
134: child = new NetFileTotalOneView(this , GLOBAL_DATA_VIEW,
135: NetFileModel.GLOBAL_TYPE);
136: } else if (name.equals(ORG_DATA_VIEW)) {
137: child = new NetFileTotalOneView(this , ORG_DATA_VIEW,
138: NetFileModel.ORG_TYPE);
139: } else if (name.equals(DYNAMIC_DATA_VIEW)) {
140: child = new NetFileTotalOneView(this , DYNAMIC_DATA_VIEW,
141: NetFileModel.DYNAMIC_TYPE);
142: } else if (name.equals(PAGE_LABEL)) {
143: child = new StaticTextField(this , PAGE_LABEL, modelManager
144: .getString("props.total.one.one")
145: + " "
146: + modelManager.getString("for.label")
147: + " "
148: + modelManager.getString("props.total.one"));
149: } else if (name.equals(CHILD_OSCHARSET_LBL)) {
150: model.setCurrentRow(viewType, model
151: .getNetFileAttributeIndex(ATTR_OSCHARSET));
152: child = new StaticTextField(this , CHILD_OSCHARSET_LBL,
153: model.getDynamicGUI().getLabel());
154: } else if (name.equals(CHILD_OSCHARSET)) {
155: child = new ComboBox(this , CHILD_OSCHARSET, "");
156: } else if (name.equals(CHILD_HOSTORDER_LBL)) {
157: model.setCurrentRow(viewType, model
158: .getNetFileAttributeIndex(ATTR_HOST_ORDER));
159: child = new StaticTextField(this , CHILD_HOSTORDER_LBL,
160: model.getDynamicGUI().getLabel());
161: } else if (name.equals(CHILD_HOSTORDER)) {
162: child = new ListBox(this , CHILD_HOSTORDER, "");
163: } else if (name.equals(CHILD_MOVEUP_BTN)) {
164: child = new IPlanetButton(this , CHILD_MOVEUP_BTN,
165: modelManager.getString("moveup.button"));
166: } else if (name.equals(CHILD_MOVEDOWN_BTN)) {
167: child = new IPlanetButton(this , CHILD_MOVEDOWN_BTN,
168: modelManager.getString("movedown.button"));
169: } else if (name.equals(CHILD_TILEDVIEW)) {
170: child = new NetFileHostsTiledView(this , CHILD_TILEDVIEW);
171: } else if (name.equals(CHILD_NAME_LABEL)) {
172: child = new StaticTextField(this , CHILD_NAME_LABEL,
173: modelManager.getString("name.label"));
174: } else if (name.equals(CHILD_NOCOMMONHOSTS_LABEL)) {
175: child = new StaticTextField(this ,
176: CHILD_NOCOMMONHOSTS_LABEL, modelManager
177: .getString("nocommonhosts.label"));
178: } else if (name.equals(CHILD_ACTION_LABEL)) {
179: child = new StaticTextField(this , CHILD_ACTION_LABEL,
180: modelManager.getString("action.label"));
181: } else if (name.equals(NETFILE_HOSTS_LABEL)) {
182: int netfilehostsIndex = model.getNetFileHostsIndex();
183: model.setCurrentRow(NetFileModel.DYNAMIC_TYPE,
184: netfilehostsIndex);
185: child = new StaticTextField(this , NETFILE_HOSTS_LABEL,
186: model.getDynamicGUI().getLabel() + ":");
187: } else if (name.equals(ADD_NETFILEHOST_BTN)) {
188: child = new IPlanetButton(this , ADD_NETFILEHOST_BTN,
189: modelManager.getString("new.button"));
190: } else if (name.equals(DELETE_NETFILEHOSTS_BTN)) {
191: child = new IPlanetButton(this , DELETE_NETFILEHOSTS_BTN,
192: modelManager.getString("delete.button"));
193: } else if (name.equals(NETFILE_HOSTS_COUNT)) {
194: child = new HiddenField(this , NETFILE_HOSTS_COUNT, "");
195: } else if (name.equals(NO_HOST_SELECTION)) {
196: child = new StaticTextField(this , NO_HOST_SELECTION,
197: modelManager.getString("nohostselection"));
198: } else if (name.equals(CONFIRM_HOST_DELETE)) {
199: child = new StaticTextField(this , CONFIRM_HOST_DELETE,
200: modelManager.getString("confirmhostdelete"));
201: } else if (name.equals(JAVA2_ONLY)) {
202: child = new StaticTextField(this , JAVA2_ONLY, modelManager
203: .getString("java2Only"));
204: } else {
205: child = super .createChild(name);
206: }
207: return child;
208: }
209:
210: public boolean beginNoCommonHostsBlockDisplay(
211: ChildDisplayEvent event) {
212: return getModel().getNetFileHostsCount() == 0 ? true : false;
213: }
214:
215: public ComboBox setOSCharSetOptions() {
216: OptionList optList = new OptionList();
217: String tmp;
218: for (int count = 0; count < encodingTypeOptionList.length; count++) {
219: tmp = modelManager.getString("encoding_"
220: + encodingTypeOptionList[count]);
221: optList.add(tmp, tmp);
222: }
223: ComboBox cb = (ComboBox) getDisplayField(CHILD_OSCHARSET);
224: cb.setOptions(optList);
225: return cb;
226: }
227:
228: public void beginDisplay(DisplayEvent event)
229: throws ModelControlException {
230: getModel();
231: setChildValues(model);
232: model.process();
233: getNetFileModelMgr();
234: setDisplayFieldValue(PAGE_DESCRIPTION, model
235: .getServiceDisplayName());
236: setDisplayFieldValue(GLOBAL_LABEL, modelManager
237: .getString("global"));
238: setDisplayFieldValue(ORG_LABEL, modelManager
239: .getString("organization"));
240: setDisplayFieldValue(DYNAMIC_LABEL, modelManager
241: .getString("dynamic"));
242: setDisplayFieldValue(SUBMIT_BTN, modelManager
243: .getString("save.button"));
244: setDisplayFieldValue(RESET_BTN, modelManager
245: .getString("reset.button"));
246: setDisplayFieldValue(DELETE_BUTTON, modelManager
247: .getString("delete.button"));
248: setDisplayFieldValue(NETFILE_HOSTS_COUNT, model
249: .getNetFileHostsCount());
250: setDisplayFieldValue(HELP_DOC_URL, modelManager
251: .getString(NetFileAdminService.SRA_BASE_HLP_URL));
252: setDisplayFieldValue(HELP_ANCHOR_TAG, model
253: .getHelpUrl(modelManager
254: .getString(NetFileAdminService.SRA_NF_HLP_URL)));
255:
256: if (model != null) {
257: if (model.hasTemplate() || model.hasSchema()) {
258: int viewType = NetFileModel.DYNAMIC_TYPE;
259: ComboBox osCharSetCB = setOSCharSetOptions();
260: model.setCurrentRow(viewType, model
261: .getNetFileAttributeIndex(ATTR_OSCHARSET));
262: Set valueSet = model.getAttrValues();
263: String value = null;
264: if (valueSet != null && valueSet.iterator().hasNext()) {
265: value = (String) valueSet.iterator().next();
266: }
267: if (value != null && value.trim().length() != 0) {
268: value = modelManager.getString(value);
269: osCharSetCB.setValue(value);
270: }
271:
272: model.setCurrentRow(viewType, model
273: .getNetFileAttributeIndex(ATTR_HOST_ORDER));
274: valueSet = model.getAttrValues();
275: if (valueSet != null && valueSet.iterator().hasNext()) {
276: value = (String) valueSet.iterator().next();
277: }
278: OptionList optList = new OptionList();
279: ListBox lb = (ListBox) getChild(CHILD_HOSTORDER);
280:
281: if (value != null && value.trim().length() != 0) {
282: StringTokenizer st = new StringTokenizer(value);
283: String str1;
284: while (st.hasMoreTokens()) {
285: str1 = st.nextToken();
286: //tmp = modelManager.getString("hostType." + tmp);
287: optList.add(modelManager.getString("hostType."
288: + str1), str1);
289: }
290: lb.setOptions(optList);
291: }
292: }
293: }
294: }
295:
296: public void handleSubmitButtonRequest(RequestInvocationEvent event)
297: throws ModelControlException, SSOException {
298: getModel();
299: NetFileTotalOneView view = null;
300: view = (NetFileTotalOneView) getChild(GLOBAL_DATA_VIEW);
301: if (view != null) {
302: store(view, NetFileModel.GLOBAL_TYPE);
303: }
304: view = (NetFileTotalOneView) getChild(ORG_DATA_VIEW);
305: if (view != null) {
306: store(view, NetFileModel.ORG_TYPE);
307: }
308: view = (NetFileTotalOneView) getChild(DYNAMIC_DATA_VIEW);
309: if (view != null) {
310: store(view, NetFileModel.DYNAMIC_TYPE);
311: }
312: /*
313: String nasURL = getNetFileAdminServiceURL();
314: HttpServletResponse response = getRequestContext().getResponse();
315: try {
316: response.sendRedirect(nasURL);
317: } catch(IOException ioe) {
318: forwardTo();
319: }
320: */
321: showPropertiesSavedMessageBox();
322: forwardTo();
323: }
324:
325: public NetFileHostsTiledView getNetFileHostsTiledView() {
326: return (NetFileHostsTiledView) getChild(CHILD_TILEDVIEW);
327: }
328:
329: public void handleAddhostButtonRequest(RequestInvocationEvent event)
330: throws ModelControlException {
331: modelManager.setCurrentNetFileHostsRow(-1);
332: NetFileHostsViewBean vb = (NetFileHostsViewBean) getViewBean(NetFileHostsViewBean.class);
333: passPgSessionMap(vb);
334: vb.forwardTo(getRequestContext());
335: }
336:
337: public void handleDelhostsButtonRequest(RequestInvocationEvent event)
338: throws ModelControlException {
339: NetFileHostsTiledView tileView = getNetFileHostsTiledView();
340: tileView.getPrimaryModel().setSize(
341: tileView.getNetFileHostsCount());
342: List selections = new LinkedList();
343: while (tileView.nextTile()) {
344: String value = (String) tileView
345: .getDisplayFieldValue(NetFileHostsTiledView.CHILD_CB_SELECT_HOST);
346: if (value.equals("true")) {
347: value = (String) tileView
348: .getDisplayFieldValue(NetFileHostsTiledView.CHILD_HREF_TEXT);
349: selections.add(value);
350: }
351: }
352:
353: if (selections.size() == 0) {
354: getNetFileModelMgr();
355: MessageBox msgBox = (MessageBox) getDisplayField(CHILD_CC_MSGBOX);
356: msgBox.setTitle(modelManager
357: .getString("noselectionmsgbox.title"));
358: msgBox
359: .setMessage(modelManager
360: .getString("nohostselection"));
361: msgBox.setType(MessageBox.TYPE_ERROR);
362: msgBox.setVisible(true);
363: /* Redisplay the page with the error */
364: forwardTo();
365: return;
366: } else if (selections.size() > 0) {
367: Vector netFileHosts = tileView.getNetFileHosts();
368: int nhSize = netFileHosts.size();
369: if (netFileHosts != null) {
370: for (int i = 0; i < selections.size(); i++) {
371: for (int j = 0; j < netFileHosts.size(); j++) {
372: StringTokenizer st1 = new StringTokenizer(
373: (String) netFileHosts.get(j),
374: NetFileHostsViewBean.HOST_DELIM);
375: if (st1.hasMoreTokens()) {
376: String hostname = st1.nextToken();
377: hostname = hostname
378: .substring(NetFileHostsViewBean.hostListStrHost
379: .length());
380: if (hostname.equals(selections.get(i))) {
381: netFileHosts.remove(j);
382: --j;
383: }
384: }
385: }
386: }
387: }
388: Set newHostSet = new HashSet();
389: if (!netFileHosts.isEmpty()) {
390: Iterator hosts = netFileHosts.iterator();
391: while (hosts.hasNext())
392: newHostSet.add((String) AccessController
393: .doPrivileged(new EncryptAction(
394: (String) hosts.next())));
395: }
396:
397: Map newMap = new HashMap();
398: newMap.put(ATTR_COMMON_HOST, newHostSet);
399: getModel();
400: model.store(NetFileModel.DYNAMIC_TYPE, newMap);
401: String nasURL = getNetFileAdminServiceURL();
402: HttpServletResponse response = getRequestContext()
403: .getResponse();
404: try {
405: response.sendRedirect(nasURL);
406: } catch (IOException ioe) {
407: forwardTo();
408: }
409: }
410: }
411:
412: private void store(NetFileTotalOneView view, int type)
413: throws SSOException {
414: NetFileModel m = getModel();
415: getNetFileModelMgr();
416: m.process();
417: Map map = new HashMap(10);
418: List dynComps = view.getDynamicCompList();
419:
420: if (dynComps != null && !dynComps.isEmpty()) {
421: Iterator it = dynComps.iterator();
422: while (it.hasNext()) {
423: DynamicGUI dGui = (DynamicGUI) it.next();
424: if (dGui != null) {
425: Set dgValues = dGui.getValues();
426: if (dGui.getSyntax() == DynamicGUI.SYNTAX_DATE) {
427: try {
428: dgValues = m
429: .getDateInDefaultLocale(dgValues);
430: } catch (AMConsoleException ace) {
431: NetFileAdminModelManager
432: .debugError("Error in converting value to default locale : "
433: + ace);
434: // showMessage(MessageBox.TYPE_ERROR,
435: // m.getErrorTitle(),
436: // ace.getMessage());
437: continue;
438: }
439: }
440: map.put(dGui.getName(), dgValues);
441: }
442: }
443: }
444: if (type == NetFileModel.DYNAMIC_TYPE) {
445: ComboBox cb = (ComboBox) getDisplayField(CHILD_OSCHARSET);
446: String value = (String) (cb.getValue());
447: String tmp;
448: for (int count = 0; count < encodingTypeOptionList.length; count++) {
449: tmp = modelManager.getString("encoding_"
450: + encodingTypeOptionList[count]);
451: if (value.equals(tmp)) {
452: //value = encodingTypeOptionList[count];
453: break;
454: }
455: }
456: Vector valueVector = new Vector(1);
457: valueVector.add(value);
458: HashSet valueSet = new HashSet(valueVector);
459: map.put(ATTR_OSCHARSET, valueSet);
460:
461: ListBox lb = (ListBox) getDisplayField(CHILD_HOSTORDER);
462: Object[] objValues = (Object[]) lb.getValues();
463: StringBuffer sb = new StringBuffer();
464: /*
465: int tmpInt;
466: OptionList optList = new OptionList();
467: for (int count = 0; count < hostTypeOptionList.length; count++) {
468: tmp = modelManager.getString("hostType." + hostTypeOptionList[count]);
469: optList.add(hostTypeOptionList[count], tmp);
470: }
471: */
472: for (int count = 0; count < objValues.length; count++) {
473: tmp = objValues[count].toString();
474: //tmp = optList.getValueLabel(tmp);
475: sb.append(tmp + "\n");
476: }
477: value = sb.toString();
478: value = value.substring(0, value.lastIndexOf("\n"));
479: valueVector = new Vector(1);
480: valueVector.add(value);
481: valueSet = new HashSet(valueVector);
482: map.put(ATTR_HOST_ORDER, valueSet);
483:
484: String priority = (String) getDisplayFieldValue(PRIORITY_COMBOBOX);
485: if (!"".equals(priority))
486: map.put("priority", priority);
487: }
488:
489: if (!map.isEmpty()) {
490: m.store(type, map);
491: }
492: }
493:
494: }
|