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.Serializable;
018: import com.sun.portal.log.common.PortalLogger;
019: import java.util.Vector;
020: import java.util.Iterator;
021: import java.util.Map;
022: import java.util.Set;
023: import java.util.StringTokenizer;
024:
025: // Servlet classes
026: import javax.servlet.http.HttpServletRequest;
027:
028: // iPlanet JATO classes
029: import com.iplanet.jato.RequestHandler;
030: import com.iplanet.jato.model.DatasetModel;
031: import com.iplanet.jato.model.ModelControlException;
032: import com.iplanet.jato.util.Encoder;
033: import com.iplanet.jato.view.View;
034: import com.iplanet.jato.view.ViewBean;
035: import com.iplanet.jato.view.RequestHandlingTiledViewBase;
036: import com.iplanet.jato.view.TiledView;
037: import com.iplanet.jato.view.event.DisplayEvent;
038: import com.iplanet.jato.view.event.RequestInvocationEvent;
039: import com.iplanet.jato.view.event.TiledViewRequestInvocationEvent;
040: import com.iplanet.jato.view.html.CheckBox;
041: import com.iplanet.jato.view.html.HiddenField;
042: import com.iplanet.jato.view.html.HREF;
043: import com.iplanet.jato.view.html.StaticTextField;
044:
045: // NetFile admin console classes
046: import com.sun.portal.netfile.admin.model.NetFileModel;
047: import com.sun.portal.netfile.admin.model.NetFileModelImpl;
048:
049: public class NetFileHostsTiledView extends RequestHandlingTiledViewBase
050: implements TiledView, RequestHandler {
051: public static final String CHILD_CB_SELECT_HOST = "cbSelectHost";
052: public static final String CHILD_HREF_EDIT_HOST = "hrefEditHost";
053: public static final String CHILD_HREF_TEXT = "hrefText";
054: public static final String CHILD_HOST_NAME = "hostName";
055: public static final String CHILD_EDIT_LABEL = "editLabel";
056:
057: private NetFileModel model = null;
058: private NetFileAdminModelManager modelManager = null;
059: private Vector netFileHosts = null;
060:
061: /* the maximum number of tiles per page */
062: private static final int MAX_DISPLAY_TILES = 100;
063:
064: /**
065: * Default constructor.
066: * @param parent the parent view of this tileview.
067: * @param name the name of this tileview.
068: */
069: public NetFileHostsTiledView(View parent, String name) {
070: super (parent, name);
071: setMaxDisplayTiles(MAX_DISPLAY_TILES);
072: setPrimaryModel((DatasetModel) getDefaultModel());
073: registerChildren();
074: }
075:
076: /**
077: * Register the child objects of the tileview.
078: */
079: protected void registerChildren() {
080: registerChild(CHILD_CB_SELECT_HOST, CheckBox.class);
081: registerChild(CHILD_HREF_EDIT_HOST, HREF.class);
082: registerChild(CHILD_HREF_TEXT, StaticTextField.class);
083: registerChild(CHILD_HOST_NAME, HiddenField.class);
084: registerChild(CHILD_EDIT_LABEL, StaticTextField.class);
085: }
086:
087: /**
088: * Creates and return the child view objects for the specified name.
089: * @param name the child view name.
090: * @return the child view object that corresponds to the given name.
091: */
092: protected View createChild(String name) {
093: getModelMgr();
094: if (name.equals(CHILD_CB_SELECT_HOST)) {
095: return new CheckBox(this , CHILD_CB_SELECT_HOST, "true",
096: "false", false);
097: } else if (name.equals(CHILD_HREF_EDIT_HOST)) {
098: return new HREF(this , CHILD_HREF_EDIT_HOST, "");
099: } else if (name.equals(CHILD_HREF_TEXT)) {
100: return new StaticTextField(this , CHILD_HREF_EDIT_HOST, "");
101: } else if (name.equals(CHILD_HOST_NAME)) {
102: return new HiddenField(this , CHILD_HOST_NAME, "");
103: } else if (name.equals(CHILD_EDIT_LABEL)) {
104: return new StaticTextField(this , CHILD_EDIT_LABEL,
105: modelManager.getString("edit.label"));
106: } else {
107: throw new IllegalArgumentException(name);
108: }
109: }
110:
111: public void beginDisplay(DisplayEvent event)
112: throws ModelControlException {
113: getModel(); // Get the admin model manager and model.
114: model.process();
115: Set s = model.getNetFileHosts();
116: netFileHosts = new Vector(s);
117: getPrimaryModel().setSize(netFileHosts.size());
118: }
119:
120: protected NetFileModel getModel() {
121: if (model == null) {
122: HttpServletRequest req = getRequestContext().getRequest();
123: model = new NetFileModelImpl(req, "srapNetFileAdminMsgs",
124: getPageSessionAttributes(), getServiceName(),
125: isTemplate());
126: }
127: return model;
128: }
129:
130: public NetFileAdminModelManager getModelMgr() {
131: if (modelManager == null) {
132: modelManager = (NetFileAdminModelManager) getRequestContext()
133: .getModelManager();
134: }
135: return modelManager;
136: }
137:
138: public boolean nextTile() throws ModelControlException {
139: boolean movedToRow = super .nextTile();
140: if (movedToRow) {
141: if (netFileHosts == null) {
142: getModel(); // Get the admin model manager and model.
143: model.process();
144: Set s = model.getNetFileHosts();
145: netFileHosts = new Vector(s);
146: }
147: // getPrimaryModel().setLocation(getTileIndex());
148: if (netFileHosts != null) {
149: String nr = (String) netFileHosts.get(getTileIndex());
150: StringTokenizer tok = new StringTokenizer(nr,
151: NetFileHostsViewBean.HOST_DELIM);
152: if (tok.hasMoreElements()) {
153: String hostName = tok.nextToken();
154: hostName = hostName
155: .substring(NetFileHostsViewBean.hostListStrHost
156: .length());
157: setDisplayFieldValue(CHILD_HREF_TEXT, hostName);
158: setDisplayFieldValue(CHILD_HOST_NAME, hostName);
159: }
160: }
161: }
162: return movedToRow;
163: }
164:
165: /**
166: * Handles the event to edit a given host.
167: * @param event the event to edit a given host.
168: * @exception throws ModelControlException when error(s) occurred.
169: */
170: public void handleHrefEditHostRequest(RequestInvocationEvent event)
171: throws ModelControlException {
172: /* Forward to the edit host viewbean. */
173: getModelMgr();
174: modelManager
175: .setCurrentNetFileHostsRow(((TiledViewRequestInvocationEvent) event)
176: .getTileNumber());
177: NetFileHostsViewBean vb = (NetFileHostsViewBean) getViewBean(NetFileHostsViewBean.class);
178: passPgSessionMap(vb);
179: vb.forwardTo(getRequestContext());
180: }
181:
182: /*
183: * Returns the netFileHosts vector
184: */
185: public Vector getNetFileHosts() {
186: if (netFileHosts == null) {
187: getModel(); // Get the admin model manager and model.
188: model.process();
189: Set s = model.getNetFileHosts();
190: netFileHosts = new Vector(s);
191: }
192: return netFileHosts;
193: }
194:
195: public int getNetFileHostsCount() {
196: Vector nrs = getNetFileHosts();
197: if (nrs != null) {
198: return nrs.size();
199: }
200: return 0;
201: }
202:
203: /*
204: * Gets the pageSessionAttributes map from the parent viewBean
205: * and sets these attributes for the other viewBean
206: */
207: public Map getPageSessionAttributes() {
208: NetFileTotalOneViewBean viewBean = (NetFileTotalOneViewBean) getParentViewBean();
209: String attrs = viewBean.getPageSessionAttributeString();
210: Map attributes = null;
211: if (attrs != null) {
212: try {
213: attributes = (Map) Encoder.deserialize(Encoder
214: .decodeHttp64(attrs), false);
215: } catch (Exception ex) {
216: attributes = null;
217: }
218: }
219: return attributes;
220: }
221:
222: public boolean isTemplate() {
223: Map attributes = getPageSessionAttributes();
224: String template = null;
225: if (attributes != null) {
226: template = (String) attributes
227: .get(NetFileTotalOneViewBean.TEMPLATE_ATTR);
228: }
229: if (template != null && template.equals("true")) {
230: return true;
231: } else {
232: return false;
233: }
234: }
235:
236: public String getServiceName() {
237: Map attributes = getPageSessionAttributes();
238: String svcName = null;
239: if (attributes != null)
240: svcName = (String) attributes
241: .get(NetFileTotalOneViewBean.SVC_NAME_ATTR);
242: return svcName;
243: }
244:
245: public void passPgSessionMap(ViewBean other) {
246: Map attributes = getPageSessionAttributes();
247: if ((attributes != null) && (attributes.size() > 0)) {
248: Iterator iter = attributes.keySet().iterator();
249: while (iter.hasNext()) {
250: String key = (String) iter.next();
251: other.setPageSessionAttribute(key,
252: (Serializable) attributes.get(key));
253: }
254: }
255: }
256: }
|