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.io.Serializable;
020: import java.util.HashSet;
021: import java.util.HashMap;
022: import java.util.Iterator;
023: import java.util.List;
024: import java.util.Map;
025: import java.util.Set;
026:
027: // Servlet classes
028: import javax.servlet.http.HttpServletRequest;
029: import javax.servlet.http.HttpServletResponse;
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.ViewBean;
035: import com.iplanet.jato.view.event.ChildDisplayEvent;
036: import com.iplanet.jato.view.event.DisplayEvent;
037: import com.iplanet.jato.view.event.RequestInvocationEvent;
038: import com.iplanet.jato.view.html.HREF;
039: import com.iplanet.jato.view.html.StaticTextField;
040:
041: // iDS/AME classes
042: import com.iplanet.am.console.components.view.html.DynamicGUI;
043: import com.iplanet.am.console.components.view.html.IPlanetButton;
044: import com.iplanet.am.console.components.view.html.MessageBox;
045: import com.iplanet.am.console.base.AMViewBeanBase;
046: import com.iplanet.am.console.base.AMViewBeanUtils;
047: import com.iplanet.am.console.base.model.AMConsoleException; //import com.iplanet.am.console.user.UMUserProfileViewBean;
048: import com.iplanet.am.console.user.model.UMUserProfileModel;
049:
050: // NetFile admin console classes
051: import com.sun.portal.netfile.admin.model.NetFileUserProfileModelImpl;
052:
053: public class NetFileUserProfileViewBeanBase extends AMViewBeanBase {
054:
055: public static final String PAGE_DESCRIPTION = "serviceDescription";
056: public static final String USER_DATA_VIEW = "UserDataView";
057: public static final String CHILD_CC_MSGBOX = "ccMessageBox";
058: public static final String CHILD_NETFILE_ATTRSFOR = "NetFileAttrsFor";
059: public static final String CHILD_USERID = "userID";
060: public static final String SAVE_BTN = "saveButton";
061: public static final String RESET_BTN = "resetButton";
062: public static final String TITLE_HTML_PAGE = "titleHtmlPage";
063: public static final String CHILD_HREF_PROPS_ONE = "hrefPropsOne";
064: public static final String CHILD_HREF_PROPS_ONE_TWO = "hrefPropsOneDotTwo";
065: public static final String CHILD_HREF_PROPS_TWO = "hrefPropsTwo";
066: public static final String CHILD_HREF_PROPS_THREE = "hrefPropsThree";
067: public static final String CHILD_HREF_PROPS_FOUR = "hrefPropsFour";
068: public static final String CHILD_HREF_PROPS_FOUR_TWO = "hrefPropsFourDotTwo";
069: public static final String CHILD_HREF_PROPS_FOUR_THREE = "hrefPropsFourDotThree";
070: public static final String CHILD_TEXT_PROPS_ONE = "propsOneText";
071: public static final String CHILD_TEXT_PROPS_ONE_ONE = "propsOneDotOneText";
072: public static final String CHILD_TEXT_PROPS_ONE_TWO = "propsOneDotTwoText";
073: public static final String CHILD_TEXT_PROPS_TWO = "propsTwoText";
074: public static final String CHILD_TEXT_PROPS_THREE = "propsThreeText";
075: public static final String CHILD_TEXT_PROPS_FOUR = "propsFourText";
076: public static final String CHILD_TEXT_PROPS_FOUR_ONE = "propsFourDotOneText";
077: public static final String CHILD_TEXT_PROPS_FOUR_TWO = "propsFourDotTwoText";
078: public static final String CHILD_TEXT_PROPS_FOUR_THREE = "propsFourDotThreeText";
079:
080: public static final String JAVA2_ONLY = "java2OnlyNote";
081:
082: protected String serviceName = null;
083: protected NetFileAdminModelManager modelManager = null;
084: //protected UMUserProfileModel model = null;
085: protected NetFileUserProfileModelImpl model = null;
086:
087: protected String userDN = null;
088: /** name-values map*/
089: protected Map attrValues = null;
090: /** name-status map*/
091: protected Map attrStatus = null;
092:
093: public NetFileUserProfileViewBeanBase(String pageName,
094: String defaultDisplayURL) {
095: super (pageName);
096: setDefaultDisplayURL(defaultDisplayURL);
097: }
098:
099: protected void registerChildren() {
100: registerChild(PAGE_DESCRIPTION, StaticTextField.class);
101: registerChild(CHILD_CC_MSGBOX, MessageBox.class);
102: registerChild(CHILD_NETFILE_ATTRSFOR, StaticTextField.class);
103: registerChild(CHILD_USERID, StaticTextField.class);
104: registerChild(SAVE_BTN, IPlanetButton.class);
105: registerChild(RESET_BTN, IPlanetButton.class);
106: registerChild(TITLE_HTML_PAGE, StaticTextField.class);
107: registerChild(CHILD_HREF_PROPS_ONE, HREF.class);
108: registerChild(CHILD_HREF_PROPS_ONE_TWO, HREF.class);
109: registerChild(CHILD_HREF_PROPS_TWO, HREF.class);
110: registerChild(CHILD_HREF_PROPS_THREE, HREF.class);
111: registerChild(CHILD_HREF_PROPS_FOUR, HREF.class);
112: registerChild(CHILD_HREF_PROPS_FOUR_TWO, HREF.class);
113: registerChild(CHILD_HREF_PROPS_FOUR_THREE, HREF.class);
114: registerChild(CHILD_TEXT_PROPS_ONE, StaticTextField.class);
115: registerChild(CHILD_TEXT_PROPS_ONE_ONE, StaticTextField.class);
116: registerChild(CHILD_TEXT_PROPS_ONE_TWO, StaticTextField.class);
117: registerChild(CHILD_TEXT_PROPS_TWO, StaticTextField.class);
118: registerChild(CHILD_TEXT_PROPS_THREE, StaticTextField.class);
119: registerChild(CHILD_TEXT_PROPS_FOUR, StaticTextField.class);
120: registerChild(CHILD_TEXT_PROPS_FOUR_ONE, StaticTextField.class);
121: registerChild(CHILD_TEXT_PROPS_FOUR_TWO, StaticTextField.class);
122: registerChild(CHILD_TEXT_PROPS_FOUR_THREE,
123: StaticTextField.class);
124:
125: }
126:
127: protected View createChild(String name) {
128: getNetFileModelMgr();
129: NetFileUserProfileModelImpl m = (NetFileUserProfileModelImpl) getModel();
130: //m.initModel(getUserDN());
131: View child = null;
132:
133: if (name.equals(PAGE_DESCRIPTION)) {
134: child = new StaticTextField(this , PAGE_DESCRIPTION, "");
135: } else if (name.equals(CHILD_CC_MSGBOX)) {
136: child = new MessageBox(this , CHILD_CC_MSGBOX, "");
137: } else if (name.equals(CHILD_USERID)) {
138: child = new StaticTextField(this , CHILD_USERID, "");
139: } else if (name.equals(SAVE_BTN)) {
140: child = new IPlanetButton(this , SAVE_BTN, "");
141: } else if (name.equals(RESET_BTN)) {
142: child = new IPlanetButton(this , RESET_BTN, "");
143: } else if (name.equals(TITLE_HTML_PAGE)) {
144: child = new StaticTextField(this , TITLE_HTML_PAGE,
145: modelManager.getString("netfile.admin.title"));
146: } else if (name.equals(CHILD_HREF_PROPS_ONE)) {
147: child = new HREF(this , CHILD_HREF_PROPS_ONE, "");
148: } else if (name.equals(CHILD_HREF_PROPS_ONE_TWO)) {
149: child = new HREF(this , CHILD_HREF_PROPS_ONE_TWO, "");
150: } else if (name.equals(CHILD_HREF_PROPS_TWO)) {
151: child = new HREF(this , CHILD_HREF_PROPS_TWO, "");
152: } else if (name.equals(CHILD_HREF_PROPS_THREE)) {
153: child = new HREF(this , CHILD_HREF_PROPS_THREE, "");
154: } else if (name.equals(CHILD_HREF_PROPS_FOUR)) {
155: child = new HREF(this , CHILD_HREF_PROPS_FOUR, "");
156: } else if (name.equals(CHILD_HREF_PROPS_FOUR_TWO)) {
157: child = new HREF(this , CHILD_HREF_PROPS_FOUR_TWO, "");
158: } else if (name.equals(CHILD_HREF_PROPS_FOUR_THREE)) {
159: child = new HREF(this , CHILD_HREF_PROPS_FOUR_THREE, "");
160: } else if (name.equals(CHILD_TEXT_PROPS_ONE)) {
161: child = new StaticTextField(this , CHILD_TEXT_PROPS_ONE,
162: modelManager.getString("props.total.one"));
163: } else if (name.equals(CHILD_TEXT_PROPS_ONE_ONE)) {
164: child = new StaticTextField(this , CHILD_TEXT_PROPS_ONE_ONE,
165: modelManager.getString("props.total.one.one"));
166: } else if (name.equals(CHILD_TEXT_PROPS_ONE_TWO)) {
167: child = new StaticTextField(this , CHILD_TEXT_PROPS_ONE_TWO,
168: modelManager.getString("props.total.one.two"));
169: } else if (name.equals(CHILD_TEXT_PROPS_TWO)) {
170: child = new StaticTextField(this , CHILD_TEXT_PROPS_TWO,
171: modelManager.getString("props.total.two"));
172: } else if (name.equals(CHILD_TEXT_PROPS_THREE)) {
173: child = new StaticTextField(this , CHILD_TEXT_PROPS_THREE,
174: modelManager.getString("props.total.three"));
175: } else if (name.equals(CHILD_TEXT_PROPS_FOUR)) {
176: child = new StaticTextField(this , CHILD_TEXT_PROPS_FOUR,
177: modelManager.getString("props.total.four"));
178: } else if (name.equals(CHILD_TEXT_PROPS_FOUR_ONE)) {
179: child = new StaticTextField(this ,
180: CHILD_TEXT_PROPS_FOUR_ONE, modelManager
181: .getString("props.total.four.one"));
182: } else if (name.equals(CHILD_TEXT_PROPS_FOUR_TWO)) {
183: child = new StaticTextField(this ,
184: CHILD_TEXT_PROPS_FOUR_TWO, modelManager
185: .getString("props.total.four.two"));
186: } else if (name.equals(CHILD_TEXT_PROPS_FOUR_THREE)) {
187: child = new StaticTextField(this ,
188: CHILD_TEXT_PROPS_FOUR_THREE, modelManager
189: .getString("props.total.four.three"));
190: } else {
191: child = super .createChild(name);
192: }
193: return child;
194: }
195:
196: public void beginDisplay(DisplayEvent event)
197: throws ModelControlException {
198: getNetFileModelMgr();
199: NetFileUserProfileModelImpl m = (NetFileUserProfileModelImpl) getModel();
200: setChildValues(model);
201: //m.initModel(getUserDN());
202: setDisplayFieldValue(PAGE_DESCRIPTION, m
203: .getServiceDescription());
204: setDisplayFieldValue(SAVE_BTN, modelManager
205: .getString("save.button"));
206: setDisplayFieldValue(RESET_BTN, modelManager
207: .getString("reset.button"));
208: setDisplayFieldValue(CHILD_USERID, m.getUserID());
209: }
210:
211: public void handleSaveButtonRequest(RequestInvocationEvent event)
212: throws ModelControlException {
213: NetFileUserProfileModelImpl m = (NetFileUserProfileModelImpl) getModel();
214: m.initModel(getUserDN());
215: try {
216: processAttributes();
217: int size = attrValues.size();
218: Map userOnlyAttrs = new HashMap(size);
219: Map customizedAttrs = new HashMap(size);
220: Set inheritedAttrs = new HashSet(size);
221: Set nameSet = attrStatus.keySet();
222: Iterator nameIter = nameSet.iterator();
223: while (nameIter.hasNext()) {
224: String attrName = (String) nameIter.next();
225: Set values = (Set) attrValues.get(attrName);
226: String status = (String) attrStatus.get(attrName);
227: if (!m.isReadOnly(attrName)
228: && (status == null || status.trim().length() == 0)) {
229: userOnlyAttrs.put(attrName, values);
230: } else if (!m.isReadOnly(attrName)
231: && status.equals(m.getCustomizeValue())) {
232: customizedAttrs.put(attrName, values);
233: } else if (!m.isReadOnly(attrName)
234: && status.equals(m.getInheritValue())) {
235: inheritedAttrs.add(attrName);
236: }
237: }
238: m.storeAttributes(userOnlyAttrs, customizedAttrs,
239: inheritedAttrs);
240: } catch (AMConsoleException ace) {
241: }
242: forwardTo();
243: }
244:
245: public void handleResetButtonRequest(RequestInvocationEvent event)
246: throws ModelControlException {
247: forwardTo();
248: }
249:
250: public boolean beginUserLevelBlockDisplay(ChildDisplayEvent event) {
251: NetFileUserProfileModelImpl m = (NetFileUserProfileModelImpl) getModel();
252: //m.initModel(getUserDN());
253: return (m.getSize() != 0);
254: }
255:
256: public void handleHrefPropsOneRequest(RequestInvocationEvent event)
257: throws ModelControlException {
258: NetFileTotalOneUserProfileViewBean vb = (NetFileTotalOneUserProfileViewBean) getViewBean(NetFileTotalOneUserProfileViewBean.class);
259: passPgSessionMap(vb);
260: vb.forwardTo(getRequestContext());
261: }
262:
263: public void handleHrefPropsOneDotTwoRequest(
264: RequestInvocationEvent event) throws ModelControlException {
265: NetFileTotalOneDotTwoUserProfileViewBean vb = (NetFileTotalOneDotTwoUserProfileViewBean) getViewBean(NetFileTotalOneDotTwoUserProfileViewBean.class);
266: passPgSessionMap(vb);
267: vb.forwardTo(getRequestContext());
268: }
269:
270: public void handleHrefPropsTwoRequest(RequestInvocationEvent event)
271: throws ModelControlException {
272: NetFileTotalTwoUserProfileViewBean vb = (NetFileTotalTwoUserProfileViewBean) getViewBean(NetFileTotalTwoUserProfileViewBean.class);
273: passPgSessionMap(vb);
274: vb.forwardTo(getRequestContext());
275: }
276:
277: public void handleHrefPropsThreeRequest(RequestInvocationEvent event)
278: throws ModelControlException {
279: NetFileTotalThreeUserProfileViewBean vb = (NetFileTotalThreeUserProfileViewBean) getViewBean(NetFileTotalThreeUserProfileViewBean.class);
280: passPgSessionMap(vb);
281: vb.forwardTo(getRequestContext());
282: }
283:
284: public void handleHrefPropsFourRequest(RequestInvocationEvent event)
285: throws ModelControlException {
286: NetFileTotalFourUserProfileViewBean vb = (NetFileTotalFourUserProfileViewBean) getViewBean(NetFileTotalFourUserProfileViewBean.class);
287: passPgSessionMap(vb);
288: vb.forwardTo(getRequestContext());
289: }
290:
291: public void handleHrefPropsFourDotTwoRequest(
292: RequestInvocationEvent event) throws ModelControlException {
293: NetFileTotalFourDotTwoUserProfileViewBean vb = (NetFileTotalFourDotTwoUserProfileViewBean) getViewBean(NetFileTotalFourDotTwoUserProfileViewBean.class);
294: passPgSessionMap(vb);
295: vb.forwardTo(getRequestContext());
296: }
297:
298: public void handleHrefPropsFourDotThreeRequest(
299: RequestInvocationEvent event) throws ModelControlException {
300: NetFileTotalFourDotThreeUserProfileViewBean vb = (NetFileTotalFourDotThreeUserProfileViewBean) getViewBean(NetFileTotalFourDotThreeUserProfileViewBean.class);
301: passPgSessionMap(vb);
302: vb.forwardTo(getRequestContext());
303: }
304:
305: public void passPgSessionMap(ViewBean other) {
306: Map attributes = getPageSessionAttributes();
307: if ((attributes != null) && (attributes.size() > 0)) {
308: Iterator iter = attributes.keySet().iterator();
309: while (iter.hasNext()) {
310: String key = (String) iter.next();
311: other.setPageSessionAttribute(key,
312: (Serializable) attributes.get(key));
313: }
314: }
315: }
316:
317: public UMUserProfileModel getModel() {
318: HttpServletRequest request = getRequestContext().getRequest();
319: return this .getModel(request, true);
320: }
321:
322: public UMUserProfileModel getModel(HttpServletRequest request,
323: boolean retrieve) {
324: if (model == null) {
325: model = new NetFileUserProfileModelImpl(request,
326: getPageSessionAttributes());
327: model.initModel(getUserDN());
328: }
329: return model;
330: }
331:
332: public NetFileAdminModelManager getNetFileModelMgr() {
333: if (modelManager == null) {
334: modelManager = (NetFileAdminModelManager) getRequestContext()
335: .getModelManager();
336: }
337: return modelManager;
338: }
339:
340: public void processAttributes() throws AMConsoleException {
341: if (attrValues == null) {
342: attrValues = new HashMap();
343: }
344: if (attrStatus == null) {
345: attrStatus = new HashMap();
346: }
347: NetFileUserProfileViewBase view = (NetFileUserProfileViewBase) getChild(USER_DATA_VIEW);
348: List dynComps = view.getDynamicCompList();
349: if (dynComps != null && !dynComps.isEmpty()) {
350: Iterator it = dynComps.iterator();
351: while (it.hasNext()) {
352: DynamicGUI dGui = (DynamicGUI) it.next();
353: if (dGui != null) {
354: attrValues.put(dGui.getName(), dGui.getValues());
355: attrStatus.put(dGui.getName(), dGui
356: .getStatusValue());
357: }
358: }
359: }
360: }
361:
362: public String getUserDN() {
363: if (userDN == null) {
364: Map pageSessAttrs = getPageSessionAttributes();
365: userDN = (String) pageSessAttrs
366: .get("com-iplanet-am-admin-user-current-object");
367: }
368: return userDN;
369: }
370:
371: public void redirectToPage(String pageName) {
372: String nasURL = getModuleURL() + "/" + pageName;
373: nasURL = AMViewBeanUtils.appendPgSession(nasURL,
374: getPageSessionAttributes());
375: HttpServletResponse response = getRequestContext()
376: .getResponse();
377: try {
378: response.sendRedirect(nasURL);
379: } catch (IOException ioe) {
380: forwardTo();
381: }
382: }
383:
384: public void setChildValues(UMUserProfileModel model) {
385: super.setChildValues(model);
386: }
387: }
|