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.util.Iterator;
020: import java.util.Map;
021: import java.util.Set;
022: import java.util.StringTokenizer;
023: import java.util.Vector;
024:
025: import com.iplanet.jato.RequestHandler;
026: import com.iplanet.jato.model.DatasetModel;
027: import com.iplanet.jato.model.ModelControlException;
028: import com.iplanet.jato.util.Encoder;
029: import com.iplanet.jato.view.RequestHandlingTiledViewBase;
030: import com.iplanet.jato.view.TiledView;
031: import com.iplanet.jato.view.View;
032: import com.iplanet.jato.view.ViewBean;
033: import com.iplanet.jato.view.event.DisplayEvent;
034: import com.iplanet.jato.view.event.RequestInvocationEvent;
035: import com.iplanet.jato.view.event.TiledViewRequestInvocationEvent;
036: import com.iplanet.jato.view.html.CheckBox;
037: import com.iplanet.jato.view.html.HREF;
038: import com.iplanet.jato.view.html.HiddenField;
039: import com.iplanet.jato.view.html.StaticTextField;
040: import com.sun.portal.netlet.admin.model.NetletAdminUserProfileModelImpl;
041:
042: public class NetletRulesUserProfileTiledView extends
043: RequestHandlingTiledViewBase implements TiledView,
044: RequestHandler {
045: public static final String CHILD_CB_SELECT_RULE = "cbSelectRule";
046: public static final String CHILD_HREF_EDIT_RULE = "hrefEditRule";
047: public static final String CHILD_HREF_TEXT = "hrefText";
048: public static final String CHILD_RULE_NAME = "ruleName";
049: public static final String CHILD_EDIT_LABEL = "editLabel";
050:
051: private NetletAdminUserProfileModelImpl model = null;
052: private NetletAdminModelManager modelManager = null;
053: private Vector netletRules = null;
054:
055: /* the maximum number of tiles per page */
056: private static final int MAX_DISPLAY_TILES = 100;
057:
058: /**
059: * Default constructor.
060: * @param parent the parent view of this tileview.
061: * @param name the name of this tileview.
062: */
063: public NetletRulesUserProfileTiledView(View parent, String name) {
064: super (parent, name);
065: setMaxDisplayTiles(MAX_DISPLAY_TILES);
066: setPrimaryModel((DatasetModel) getDefaultModel());
067: registerChildren();
068: }
069:
070: /**
071: * Register the child objects of the tileview.
072: */
073: protected void registerChildren() {
074: registerChild(CHILD_CB_SELECT_RULE, CheckBox.class);
075: registerChild(CHILD_HREF_EDIT_RULE, HREF.class);
076: registerChild(CHILD_HREF_TEXT, StaticTextField.class);
077: registerChild(CHILD_RULE_NAME, HiddenField.class);
078: registerChild(CHILD_EDIT_LABEL, StaticTextField.class);
079: }
080:
081: /**
082: * Creates and return the child view objects for the specified name.
083: * @param name the child view name.
084: * @return the child view object that corresponds to the given name.
085: */
086: protected View createChild(String name) {
087: getModel();
088: getModelMgr();
089: if (name.equals(CHILD_CB_SELECT_RULE)) {
090: return new CheckBox(this , CHILD_CB_SELECT_RULE, "true",
091: "false", false);
092: } else if (name.equals(CHILD_HREF_EDIT_RULE)) {
093: return new HREF(this , CHILD_HREF_EDIT_RULE, "");
094: } else if (name.equals(CHILD_HREF_TEXT)) {
095: return new StaticTextField(this , CHILD_HREF_EDIT_RULE, "");
096: } else if (name.equals(CHILD_RULE_NAME)) {
097: return new HiddenField(this , CHILD_RULE_NAME, "");
098: } else if (name.equals(CHILD_EDIT_LABEL)) {
099: String editLbl = modelManager.getString("edit.label");
100: if (model.isReadOnly("sunPortalNetletRules")) {
101: editLbl = modelManager.getString("view.label");
102: }
103: return new StaticTextField(this , CHILD_EDIT_LABEL, editLbl);
104: } else {
105: throw new IllegalArgumentException(name);
106: }
107: }
108:
109: public void beginDisplay(DisplayEvent event)
110: throws ModelControlException {
111: getModel(); // Get the admin model manager and model.
112: Set s = model.getNetletRules();
113: netletRules = new Vector(s);
114: getPrimaryModel().setSize(netletRules.size());
115: resetTileIndex();
116: }
117:
118: protected NetletAdminUserProfileModelImpl getModel() {
119: if (model == null) {
120: NetletAdminUserProfileViewBean viewBean = (NetletAdminUserProfileViewBean) getParentViewBean();
121: model = (NetletAdminUserProfileModelImpl) viewBean
122: .getModel();
123: model.initModel(viewBean.getUserDN());
124: }
125: return model;
126: }
127:
128: public NetletAdminModelManager getModelMgr() {
129: if (modelManager == null) {
130: modelManager = (NetletAdminModelManager) getRequestContext()
131: .getModelManager();
132: }
133: return modelManager;
134: }
135:
136: public boolean nextTile() throws ModelControlException {
137: boolean movedToRow = super .nextTile();
138: if (movedToRow) {
139: if (netletRules == null) {
140: getModel(); // Get the admin model manager and model.
141: Set s = model.getNetletRules();
142: netletRules = new Vector(s);
143: }
144: // getPrimaryModel().setLocation(getTileIndex());
145: if (netletRules != null) {
146: String nr = (String) netletRules.get(getTileIndex());
147: StringTokenizer tok = new StringTokenizer(nr,
148: EditNetletRuleViewBean.RULE_DELIM);
149: if (tok.hasMoreElements()) {
150: tok = new StringTokenizer(tok.nextToken(),
151: EditNetletRuleViewBean.ALGO_DELIM);
152: }
153: if (tok.hasMoreElements()) {
154: String ruleName = tok.nextToken();
155: setDisplayFieldValue(CHILD_HREF_TEXT, ruleName);
156: setDisplayFieldValue(CHILD_RULE_NAME, ruleName);
157: }
158: }
159: }
160: return movedToRow;
161: }
162:
163: /**
164: * Handles the event to edit a given ruleset.
165: * @param event the event to edit a given ruleset.
166: * @exception throws ModelControlException when error(s) occurred.
167: */
168: public void handleHrefEditRuleRequest(RequestInvocationEvent event)
169: throws ModelControlException {
170: /* Forward to the edit rule viewbean. */
171: getModelMgr();
172: modelManager
173: .setCurrentNetletRulesRow(((TiledViewRequestInvocationEvent) event)
174: .getTileNumber());
175: EditNetletRuleUserProfileViewBean vb = (EditNetletRuleUserProfileViewBean) getViewBean(EditNetletRuleUserProfileViewBean.class);
176: passPgSessionMap(vb);
177: vb.forwardTo(getRequestContext());
178: }
179:
180: /*
181: * Returns the netletRules vector
182: * Called by NetletAdminServiceViewBean when DELETE button of
183: * netlet rules is clicked
184: */
185: public Vector getNetletRules() {
186: if (netletRules == null) {
187: getModel(); // Get the admin model manager and model.
188: Set s = model.getNetletRules();
189: netletRules = new Vector(s);
190: }
191: return netletRules;
192: }
193:
194: public int getNetletRulesCount() {
195: Vector nrs = getNetletRules();
196: if (nrs != null) {
197: return nrs.size();
198: }
199: return 0;
200: }
201:
202: /*
203: * Gets the pageSessionAttributes map from the parent viewBean (NetletAdminServicViewBean)
204: * and sets these attributes for the other viewBean
205: */
206: public Map getPageSessionAttributes() {
207: NetletAdminUserProfileViewBean viewBean = (NetletAdminUserProfileViewBean) getParentViewBean();
208: String attrs = viewBean.getPageSessionAttributeString();
209: Map attributes = null;
210: if (attrs != null) {
211: try {
212: attributes = (Map) Encoder.deserialize(Encoder
213: .decodeHttp64(attrs), false);
214: } catch (Exception ex) {
215: attributes = null;
216: }
217: }
218: return attributes;
219: }
220:
221: public void passPgSessionMap(ViewBean other) {
222: Map attributes = getPageSessionAttributes();
223: if ((attributes != null) && (attributes.size() > 0)) {
224: Iterator iter = attributes.keySet().iterator();
225: while (iter.hasNext()) {
226: String key = (String) iter.next();
227: other.setPageSessionAttribute(key,
228: (Serializable) attributes.get(key));
229: }
230: }
231: }
232: }
|