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.net.URL;
009: import java.io.*;
010: import java.util.logging.Logger;
011: import java.util.logging.Level;
012:
013: import com.sun.portal.search.admin.CSViewBeanBase;
014:
015: import javax.servlet.http.HttpServletRequest;
016: import javax.servlet.http.HttpServletResponse;
017:
018: import com.iplanet.jato.RequestContext;
019:
020: import com.iplanet.jato.view.event.DisplayEvent;
021: import com.iplanet.jato.view.event.ChildDisplayEvent;
022: import com.iplanet.jato.view.event.RequestInvocationEvent;
023:
024: import com.iplanet.jato.view.html.StaticTextField;
025: import com.iplanet.jato.view.html.TextField;
026: import com.iplanet.jato.view.html.CheckBox;
027: import com.iplanet.jato.view.html.Button;
028: import com.iplanet.jato.view.html.ComboBox;
029: import com.iplanet.jato.view.html.RadioButtonGroup;
030: import com.iplanet.jato.view.html.HiddenField;
031:
032: import com.iplanet.jato.view.html.Option;
033: import com.iplanet.jato.view.html.OptionList;
034:
035: import com.iplanet.jato.view.View;
036: import com.iplanet.jato.view.ViewBean;
037: import com.iplanet.jato.view.ViewBeanBase;
038:
039: import com.iplanet.jato.ViewBeanManager;
040:
041: import com.iplanet.jato.model.*;
042:
043: import com.iplanet.am.console.components.view.html.MessageBox;
044: import com.iplanet.am.console.components.view.html.IPlanetButton;
045:
046: import com.sun.portal.search.admin.resources.SearchResource;
047: import com.sun.portal.log.common.PortalLogger;
048:
049: /**
050: * iPS admin console view bean: TODO
051: */
052: public class SchemaListViewBean extends CSViewBeanBase {
053: public static final String DEFAULT_DISPLAY_URL = "/ps/searchadmin/SchemaList.jsp";
054: public static final String PAGE_NAME = "SchemaList";
055: public static final String SCHEMALIST_VIEW = "SchemaListView";
056: public static final String NEW_BUTTON = "NewButton";
057: public static final String RESTORE_BUTTON = "RestoreButton";
058: public static final String RESTORE_OK_BUTTON = "RestoreOKButton";
059: public static final String RESTORE_CANCEL_BUTTON = "RestoreCancelButton";
060: public static final String DELETE_BUTTON = "DeleteButton";
061: public static final String RESET_BUTTON = "ResetButton";
062: public static final String INTERNAL_CHECKBOX = "ShowInternal";
063:
064: private static final int RESTORE_ACTION = 1;
065:
066: private int pageStatus = 0;
067:
068: // Create a Logger for this class
069: private static Logger debugLogger = PortalLogger
070: .getLogger(SchemaListViewBean.class);
071:
072: //Message Box
073: //public static final String CHILD_ERROR_MSG_BOX = "errorMsgBox";
074: //public static final String CHILD_WARNING_MSG_BOX = "warningMsgBox";
075:
076: /**
077: * constructor
078: *
079: * @param PageName of this view bean
080: * @param displayURL default display URL
081: */
082: public SchemaListViewBean() {
083: super (PAGE_NAME);
084: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
085: registerChildren();
086: }
087:
088: /**
089: * register child component
090: */
091: protected void registerChildren() {
092: registerChild(SCHEMALIST_VIEW, SchemaListView.class);
093: registerChild(NEW_BUTTON, IPlanetButton.class);
094: registerChild(RESTORE_BUTTON, IPlanetButton.class);
095: registerChild(RESTORE_OK_BUTTON, IPlanetButton.class);
096: registerChild(RESTORE_CANCEL_BUTTON, IPlanetButton.class);
097: registerChild(DELETE_BUTTON, IPlanetButton.class);
098: registerChild(RESET_BUTTON, IPlanetButton.class);
099: registerChild(INTERNAL_CHECKBOX, CheckBox.class);
100:
101: }
102:
103: /**
104: * create child component
105: *
106: * @param name of component
107: * @return child component
108: */
109: protected View createChild(String name) {
110:
111: View Headerchild = super .createChild(name);
112: if (Headerchild != null)
113: return Headerchild;
114: if (name.equals(SCHEMALIST_VIEW)) {
115: return new SchemaListView(this , SCHEMALIST_VIEW);
116: }
117: if (name.equals(NEW_BUTTON)) {
118: return new IPlanetButton(this , NEW_BUTTON, "");
119: }
120: if (name.equals(RESTORE_BUTTON)) {
121: return new IPlanetButton(this , RESTORE_BUTTON, "");
122: }
123: if (name.equals(RESTORE_OK_BUTTON)) {
124: return new IPlanetButton(this , RESTORE_OK_BUTTON, "");
125: }
126: if (name.equals(RESTORE_CANCEL_BUTTON)) {
127: return new IPlanetButton(this , RESTORE_CANCEL_BUTTON, "");
128: }
129: if (name.equals(DELETE_BUTTON)) {
130: return new IPlanetButton(this , DELETE_BUTTON, "");
131: }
132: if (name.equals(RESET_BUTTON)) {
133: return new IPlanetButton(this , RESET_BUTTON, "");
134: }
135: if (name.equals(INTERNAL_CHECKBOX)) {
136: return new CheckBox(this , INTERNAL_CHECKBOX, "true",
137: "false", false);
138: }
139: throw new IllegalArgumentException("Invalid child name ["
140: + name + "]");
141: }
142:
143: public boolean beginRestoreSectionDisplay(ChildDisplayEvent event) {
144: return (pageStatus == RESTORE_ACTION);
145: }
146:
147: public boolean beginSchemaListSectionDisplay(ChildDisplayEvent event) {
148: return (pageStatus != RESTORE_ACTION);
149: }
150:
151: /** begin displaying page. we set the required information
152: *
153: * @param event display event
154: * @throws ModelControlException if problem access value of component
155: */
156: public void beginDisplay(DisplayEvent event) {
157: // Get request attributes and store them as Page Session Attributes
158: setPageEncoding();
159: setDisplayFieldValue(RESET_BUTTON,
160: getLocalizedString("reset.text"));
161: setDisplayFieldValue(NEW_BUTTON, getLocalizedString("new.text"));
162: setDisplayFieldValue(DELETE_BUTTON,
163: getLocalizedString("delete.text"));
164: setDisplayFieldValue(RESTORE_BUTTON,
165: getLocalizedString("schema.restore.button"));
166: setDisplayFieldValue(RESTORE_OK_BUTTON,
167: getLocalizedString("ok.text"));
168: setDisplayFieldValue(RESTORE_CANCEL_BUTTON,
169: getLocalizedString("cancel.text"));
170: if (pageStatus == RESTORE_ACTION) {
171: addMessageBoxButton(getLocalizedString("ok.text"),
172: "SchemaList?SchemaList.RestoreOKButton=ok");
173: addMessageBoxButton(getLocalizedString("cancel.text"),
174: "SchemaList");
175: }
176:
177: boolean showInternal = getDisplayFieldBooleanValue(INTERNAL_CHECKBOX);
178: SchemaListView list = (SchemaListView) getChild(SCHEMALIST_VIEW);
179: list.getModel().showInternal = showInternal;
180: // checking for error message
181: /*String msg = getMsg("ErrorMsg");
182: MessageBox msgBox = (MessageBox) getChild(CHILD_ERROR_MSG_BOX);
183: if (msg != null) {
184: msgBox.setType(MessageBox.TYPE_ERROR);
185: msgBox.setMessage(msg);
186: msgBox.setEnabled(true);
187: } else {
188: msgBox.setEnabled(false);
189: }
190: // checking for error message
191: msg = getMsg("WarningMsg");
192: msgBox = (MessageBox) getChild(CHILD_WARNING_MSG_BOX);
193: if (msg != null) {
194: msgBox.setType(MessageBox.TYPE_WARNING);
195: msgBox.setMessage(msg);
196: msgBox.setEnabled(true);
197: } else {
198: msgBox.setEnabled(false);
199: }*/
200:
201: }
202:
203: public void handleResetButtonRequest(RequestInvocationEvent event)
204: throws ModelControlException {
205: //SchemaListView child = (SchemaListView) getChild(SCHEMALIST_VIEW);
206: //child.reset();
207: clearPageSessionAttributes();
208: forwardTo();
209: }
210:
211: public void handleDeleteButtonRequest(RequestInvocationEvent event) {
212: SchemaListView child = (SchemaListView) getChild(SCHEMALIST_VIEW);
213: try {
214: ModelExecutionContext modExe = new ModelExecutionContextBase(
215: ModelExecutionContext.OPERATION_DELETE);
216: child.executeAutoDeletingModels(modExe);
217: } catch (ModelControlException e) {
218: debugLogger.log(Level.INFO, "PSSH_CSPSA0010", e
219: .getMessage());
220: }
221: //setPageSessionAttribute("WarningMsg", getLocalizedString("schema.save-modifications"));
222: forwardTo();
223: }
224:
225: public void handleRestoreButtonRequest(RequestInvocationEvent event) {
226: pageStatus = RESTORE_ACTION;
227: warningMessage = getLocalizedString("schema.restore.warning");
228: forwardTo();
229: }
230:
231: public void handleRestoreOKButtonRequest(
232: RequestInvocationEvent event) {
233: try {
234: String binPath = CSConfig.getBinPath();
235: if (binPath != null) {
236: int end = binPath.lastIndexOf("bin");
237: if (end > 0) {
238: String defaultSchemaPath = binPath
239: .substring(0, end)
240: + "samples/schema/document.soif";
241: String schemaPath = CSConfig.getServerRoot()
242: + "/config/schema.rdm";
243: debugLogger.log(Level.FINER, "PSSH_CSPSA0108",
244: new String[] { defaultSchemaPath,
245: schemaPath });
246: FileInputStream fis = new FileInputStream(
247: defaultSchemaPath);
248: FileOutputStream fos = new FileOutputStream(
249: schemaPath);
250: byte[] buf = new byte[1024];
251: int i = 0;
252: while ((i = fis.read(buf)) != -1) {
253: fos.write(buf, 0, i);
254: }
255: fis.close();
256: fos.close();
257: infoMessage = getLocalizedString("schema.restore.success");
258: forwardTo();
259: return;
260: }
261: }
262: } catch (Exception e) {
263: }
264:
265: errorMessage = getLocalizedString("schema.restore.error");
266: forwardTo();
267: }
268:
269: public void handleRestoreCancelButtonRequest(
270: RequestInvocationEvent event) {
271: forwardTo();
272: }
273:
274: /* public void handleNewButtonRequest(RequestInvocationEvent event) throws ModelControlException
275: {
276: CSDebug.logln("handleNewButtonRequest");
277: SchemaListView child = (SchemaListView) getChild(SCHEMALIST_VIEW);
278: try {
279: ModelExecutionContext modExe = new ModelExecutionContextBase(ModelExecutionContext.OPERATION_INSERT);
280: child.executeAutoInsertingModels(modExe);
281: } catch (ModelControlException e) {
282: CSDebug.logln(e.getClass().getName() + ":" + e.getMessage());
283: }
284: setPageSessionAttribute("WarningMsg", getLocalizedString("schema.save-modifications"));
285: forwardTo();
286: }*/
287:
288: /*private String getMsg(String msgType) {
289: String msg = (String) getPageSessionAttribute(msgType);
290: removePageSessionAttribute(msgType);
291: return msg;
292: }*/
293: }
|