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.util.Set;
009: import java.util.List;
010: import java.util.Iterator;
011: import java.util.logging.Logger;
012: import java.util.logging.Level;
013: import java.io.*;
014:
015: import javax.servlet.http.HttpServletRequest;
016:
017: import com.iplanet.jato.RequestContext;
018:
019: import com.iplanet.jato.view.event.DisplayEvent;
020: import com.iplanet.jato.view.event.RequestInvocationEvent;
021:
022: import com.iplanet.jato.view.html.StaticTextField;
023: import com.iplanet.jato.view.html.TextField;
024: import com.iplanet.jato.view.html.CheckBox;
025: import com.iplanet.jato.view.html.Button;
026: import com.iplanet.jato.view.html.ComboBox;
027: import com.iplanet.jato.view.html.Option;
028: import com.iplanet.jato.view.html.OptionList;
029:
030: import com.iplanet.jato.view.View;
031: import com.iplanet.jato.view.ContainerView;
032: import com.iplanet.jato.RequestHandler;
033: import com.iplanet.jato.view.RequestHandlingViewBase;
034: import com.iplanet.jato.view.ViewBean;
035: import com.iplanet.jato.view.ViewBeanBase;
036:
037: import com.iplanet.jato.ViewBeanManager;
038:
039: import com.iplanet.jato.model.ModelControlException;
040:
041: import com.iplanet.am.console.components.view.html.IPlanetButton;
042:
043: import com.sun.portal.search.admin.resources.SearchResource;
044: import com.sun.portal.search.admin.model.CSServiceModel;
045: import com.sun.portal.search.admin.model.CSServiceModelImpl;
046: import com.sun.portal.search.util.SearchConfig;
047: import com.sun.portal.log.common.PortalLogger;
048:
049: /**
050: * iPS admin console view bean: TODO
051: */
052: public class HeaderView extends RequestHandlingViewBase implements
053: ContainerView, RequestHandler {
054: public static final String DEFAULT_DISPLAY_URL = "/ps/searchadmin/Header.jsp";
055: public static final String PAGE_NAME = "Header";
056: public static final String INSTANCE_LIST = "InstanceList";
057: public static final String SELECTED_SUBMIT = "InstanceSubmit";
058: public static final String MENU_LIST = "MenuList";
059: public static final String TAB_PANEL = "TabMenu";
060: private CSServiceModel model = null;
061:
062: // Create a logger for this class
063: private static Logger debugLogger = PortalLogger
064: .getLogger(HeaderView.class);
065:
066: /**
067: * constructor
068: *
069: * @param PageName of this view bean
070: * @param displayURL default display URL
071: */
072: public HeaderView(View parent, String name) {
073: super (parent, name);
074: registerChildren();
075: }
076:
077: /**
078: * register child component
079: */
080: protected void registerChildren() {
081: registerChild(INSTANCE_LIST, ComboBox.class);
082: //registerChild(MENU_LIST, MenuListView.class);
083: registerChild(SELECTED_SUBMIT, IPlanetButton.class);
084: //registerChild(TAB_PANEL, TabPanelView.class);
085: }
086:
087: /**
088: * create child component
089: *
090: * @param name of component
091: * @return child component
092: */
093: protected View createChild(String name) {
094:
095: if (name.equals(INSTANCE_LIST)) {
096: return new ComboBox(this , INSTANCE_LIST, "");
097: }
098: if (name.equals(SELECTED_SUBMIT)) {
099: return new Button(this , SELECTED_SUBMIT, "");
100: }
101: throw new IllegalArgumentException("Invalid child name ["
102: + name + "]");
103: }
104:
105: /** begin displaying page. we set the required information
106: *
107: * @param event display event
108: * @throws ModelControlException if problem access value of component
109: */
110: public void beginDisplay(DisplayEvent event)
111: throws ModelControlException {
112: CSServiceModel m = getModel();
113:
114: // Get request attributes and store them as Page Session Attributes
115: RequestContext rc = getRequestContext();
116: HttpServletRequest req = rc.getRequest();
117: String server = req.getServerName();
118: int port = req.getServerPort();
119:
120: String currInst = (req.isSecure() ? "https" : "http") + "://"
121: + server + ":" + port + req.getContextPath();
122: debugLogger.log(Level.FINER, "PSSH_CSPSA0042", currInst);
123: ComboBox instance = (ComboBox) getChild(INSTANCE_LIST);
124: //instance.setLabelForNoneSelected("---------------------------");
125: instance.setLabelForNoneSelected(" ");
126: if (instance != null) {
127: if (m != null) {
128: Set instances = m.getInstances();
129: if (instances != null) {
130: OptionList options = new OptionList();
131: Iterator items = instances.iterator();
132: while (items.hasNext()) {
133: String value = (String) items.next();
134: options.add(value, value);
135: }
136: instance.setOptions(options);
137: }
138: }
139: instance.setMultiSelect(false);
140: instance.setValue(currInst);
141: }
142: }
143:
144: /**
145: * Creates the model instance.
146: *
147: * @returns Instance of model
148: */
149: public CSServiceModel getModel() {
150: if (model == null) {
151: model = new CSServiceModelImpl(getRequestContext()
152: .getRequest(), "searchadminmsgs");
153: // "amAdminServiceMsgs");
154: if (model == null) {
155: /* TOFIX: Handle this case by displaying an error page.
156: * This should actually be done by making the SMDataModelImpl
157: * throw an exception and catching it.
158: */
159: } else {
160: model.process();
161: }
162: }
163: return model;
164: }
165:
166: /**
167: * handles invocation of view bean
168: *
169: * @param event request invocation event
170: */
171: public void handleInstanceSubmitRequest(RequestInvocationEvent event) {
172: String url = (String) getDisplayFieldValue(INSTANCE_LIST)
173: + "/searchadmin/";
174: debugLogger.log(Level.FINER, "PSSH_CSPSA0043", url);
175: try {
176: getRequestContext().getResponse().sendRedirect(url);
177: } catch (IOException e) {
178: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
179: .getMessage());
180: }
181: }
182:
183: }
|