001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.search.admin;
007:
008: import java.io.IOException;
009: import java.net.URL;
010: import java.util.logging.Logger;
011: import java.util.logging.Level;
012:
013: import com.iplanet.jato.view.RequestHandlingTiledViewBase;
014: import com.iplanet.jato.view.View;
015: import com.iplanet.jato.view.ViewBean;
016: import com.iplanet.jato.view.ViewBeanBase;
017: import com.iplanet.jato.view.TiledView;
018: import com.iplanet.jato.RequestHandler;
019: import com.iplanet.jato.model.*;
020: import com.iplanet.jato.view.event.DisplayEvent;
021: import com.iplanet.jato.view.event.RequestInvocationEvent;
022: import com.iplanet.jato.view.event.TiledViewRequestInvocationEvent;
023: import com.iplanet.jato.view.event.ChildDisplayEvent;
024: import com.iplanet.jato.view.html.StaticTextField;
025: import com.iplanet.jato.view.html.ComboBox;
026: import com.iplanet.jato.view.html.TextField;
027: import com.iplanet.jato.view.html.OptionList;
028: import com.iplanet.jato.view.html.CheckBox;
029: import com.iplanet.jato.view.html.HREF;
030:
031: import com.iplanet.jato.model.DatasetModel;
032: import javax.servlet.http.HttpServletRequest;
033: import javax.servlet.http.HttpServletResponse;
034:
035: import com.iplanet.am.console.components.view.html.IPlanetButton;
036:
037: import com.sun.portal.search.admin.model.ServerGroupListModel;
038: import com.sun.portal.search.robot.FilterRuleset;
039: import com.sun.portal.log.common.PortalLogger;
040:
041: /**
042: * This view uses model of type ServerGroupListModel to display list of Servers
043: * in a tiled view
044: */
045: public class ServerGroupListView extends RequestHandlingTiledViewBase
046: implements TiledView, RequestHandler {
047: public static final String NAME_TEXT = "ServerAlias";
048: public static final String VERIFIED_TEXT = "VerifiedText";
049: public static final String VERIFIEDCOLOR_TEXT = "VerifiedColor";
050: public static final String REALNAME_TEXT = "RealNameText";
051: public static final String TYPE_COMBO = "TypeCombo";
052: public static final String PORT_TEXT = "ServerPort";
053: public static final String DEL_CHECKBOX = "Delete";
054: public static final String DEL_SERVER_BUTTON = "DelServer";
055: public String rulesetID = null;
056:
057: // Create a Logger for this class
058: private static Logger debugLogger = PortalLogger
059: .getLogger(ServerGroupListView.class);
060:
061: public ServerGroupListView(View parent, String name) {
062: super (parent, name);
063: setPrimaryModelClass(ServerGroupListModel.class);
064: registerChildren();
065: }
066:
067: protected void registerChildren() {
068: registerChild(NAME_TEXT, TextField.class);
069: registerChild(VERIFIED_TEXT, StaticTextField.class);
070: registerChild(VERIFIEDCOLOR_TEXT, StaticTextField.class);
071: registerChild(REALNAME_TEXT, StaticTextField.class);
072: registerChild(TYPE_COMBO, ComboBox.class);
073: registerChild(PORT_TEXT, TextField.class);
074: registerChild(DEL_CHECKBOX, CheckBox.class);
075: registerChild(DEL_SERVER_BUTTON, HREF.class);
076: }
077:
078: protected View createChild(String name) {
079: CSViewBeanBase pvb = (CSViewBeanBase) getParentViewBean();
080: if (name.equals(NAME_TEXT)) {
081: return new TextField(this , getModel(), NAME_TEXT,
082: ServerGroupListModel.FIELD_HOST, "", null);
083: }
084: if (name.equals(VERIFIED_TEXT)) {
085: //return new StaticTextField(this, getModel(), VERIFIED_TEXT, ServerGroupListModel.FIELD_VERIFIED_TEXT, "", null);
086: return new StaticTextField(this , VERIFIED_TEXT, "");
087: }
088: if (name.equals(VERIFIEDCOLOR_TEXT)) {
089: return new StaticTextField(this , VERIFIEDCOLOR_TEXT,
090: "#009900");
091: }
092: if (name.equals(REALNAME_TEXT)) {
093: return new StaticTextField(this , REALNAME_TEXT, "");
094: }
095: if (name.equals(TYPE_COMBO)) {
096: ComboBox child = new ComboBox(this , getModel(), TYPE_COMBO,
097: ServerGroupListModel.FIELD_PROTOCOL, "", null);
098: OptionList protocolOptions = new OptionList(pvb
099: .getLocalizedStringArray("site.protocols.label",
100: ","), FilterRuleset.ProtocolTypes);
101: child.setOptions(protocolOptions);
102: return child;
103: }
104: if (name.equals(PORT_TEXT)) {
105: return new TextField(this , getModel(), PORT_TEXT,
106: ServerGroupListModel.FIELD_PORT, "", null);
107: }
108: if (name.equals(DEL_CHECKBOX)) {
109: return new CheckBox(this , getModel(), DEL_CHECKBOX,
110: ServerGroupListModel.FIELD_DELETE, "true", "false",
111: false, null);
112: }
113: if (name.equals(DEL_SERVER_BUTTON)) {
114: return new HREF(this , DEL_SERVER_BUTTON, "");
115: }
116: throw new IllegalArgumentException("Invalid child name: "
117: + name);
118: }
119:
120: /**
121: *
122: *
123: */
124: public void beginDisplay(DisplayEvent event)
125: throws ModelControlException {
126: // Ensure the primary model is non-null; if null, it would cause
127: // havoc with the various methods dependent on the primary model
128: ServerGroupListModel model = (ServerGroupListModel) getPrimaryModel();
129: if (model == null) {
130: throw new ModelControlException("Primary model is null");
131: }
132:
133: // The model will be executed automatically here by the base class
134: super .beginDisplay(event);
135:
136: resetTileIndex();
137: }
138:
139: public boolean beginDelServerDisplay(ChildDisplayEvent event)
140: throws ModelControlException {
141: return (getModel().getSize() > 1);
142: }
143:
144: /**
145: *
146: *
147: */
148: public ServerGroupListModel getModel() {
149: return (ServerGroupListModel) getRequestContext()
150: .getModelManager().getModel(ServerGroupListModel.class);
151: }
152:
153: /**
154: *
155: *
156: */
157: public Model[] getWebActionModels(int modelType) {
158: // Mark the BasicCustomModel instance we're bound to as auto-retrieving.
159: // This means it will automatically be executed via its retrieve()
160: // method when the tiled view begins display.
161: ServerGroupListModel model = getModel();
162:
163: switch (modelType) {
164: case MODEL_TYPE_RETRIEVE:
165: debugLogger.finer("PSSH_CSPSA0036");
166: if (this .getParentViewBean().getPageSessionAttribute(
167: "retrieved") == null) {
168: // first time do retrieve
169: model.setID(this .rulesetID);
170: }
171: return new Model[] { model };
172: case MODEL_TYPE_UPDATE:
173: debugLogger.finer("PSSH_CSPSA0037");
174: model.setID(this .rulesetID);
175: return new Model[] { model };
176: case MODEL_TYPE_INSERT:
177: debugLogger.finer("PSSH_CSPSA0038");
178: return new Model[] { model };
179: case MODEL_TYPE_DELETE:
180: debugLogger.finer("PSSH_CSPSA0039");
181: return new Model[] { model };
182: }
183:
184: return new Model[0];
185: }
186:
187: public boolean nextTile() throws ModelControlException {
188: boolean movedToRow = super .nextTile();
189: CSViewBeanBase pvb = (CSViewBeanBase) getParentViewBean();
190: if (movedToRow) {
191: // Put row specific logic here
192: int index = getTileIndex();
193: String server = getDisplayFieldStringValue(NAME_TEXT);
194: if (server.trim().length() > 0) {
195: FilterSimulator frsim = new FilterSimulator();
196: String root = CSConfig.getServerRoot();
197: try {
198: String cname = frsim.getHostByName(root, server);
199: setDisplayFieldValue(VERIFIED_TEXT, pvb
200: .getLocalizedString("site.verified"));
201: setDisplayFieldValue(REALNAME_TEXT, cname);
202: } catch (Exception e) {
203: setDisplayFieldValue(VERIFIED_TEXT, e.getMessage());
204: setDisplayFieldValue(VERIFIEDCOLOR_TEXT, "RED");
205: setDisplayFieldValue(REALNAME_TEXT, "");
206: }
207: } else {
208: setDisplayFieldValue(VERIFIED_TEXT, "");
209: setDisplayFieldValue(REALNAME_TEXT, "");
210: }
211: }
212: return movedToRow;
213: }
214:
215: public void handleDelServerRequest(RequestInvocationEvent event)
216: throws ModelControlException {
217: getParentViewBean()
218: .setPageSessionAttribute("retrieved", "true");
219: ServerGroupListModel model = getModel();
220: TiledViewRequestInvocationEvent tiledEvent = (TiledViewRequestInvocationEvent) event;
221: int selRow = tiledEvent.getTileNumber();
222: model.setDelIndex(selRow);
223: try {
224: ModelExecutionContext modExe = new ModelExecutionContextBase(
225: ModelExecutionContext.OPERATION_DELETE);
226: executeAutoDeletingModels(modExe);
227: } catch (ModelControlException e) {
228: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
229: .getMessage());
230: }
231:
232: ViewBean viewBean = getParentViewBean();
233: viewBean.forwardTo(getRequestContext());
234: }
235:
236: }
|