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.*;
011: import java.text.*;
012:
013: import com.sun.portal.search.admin.CSViewBeanBase;
014: import com.sun.portal.search.admin.cli.RunImportAgent;
015: import com.sun.portal.search.robot.FilterLog;
016:
017: import javax.servlet.http.HttpServletRequest;
018: import javax.servlet.http.HttpServletResponse;
019:
020: import com.iplanet.jato.RequestContext;
021:
022: import com.iplanet.jato.view.event.DisplayEvent;
023: import com.iplanet.jato.view.event.ChildDisplayEvent;
024: import com.iplanet.jato.view.event.RequestInvocationEvent;
025:
026: import com.iplanet.jato.view.html.StaticTextField;
027: import com.iplanet.jato.view.html.TextField;
028: import com.iplanet.jato.view.html.CheckBox;
029: import com.iplanet.jato.view.html.Button;
030: import com.iplanet.jato.view.html.ComboBox;
031: import com.iplanet.jato.view.html.RadioButtonGroup;
032:
033: import com.iplanet.jato.view.html.Option;
034: import com.iplanet.jato.view.html.OptionList;
035:
036: import com.iplanet.jato.view.View;
037: import com.iplanet.jato.view.ViewBean;
038: import com.iplanet.jato.view.ViewBeanBase;
039:
040: import com.iplanet.jato.ViewBeanManager;
041:
042: import com.iplanet.jato.model.*;
043:
044: import com.iplanet.am.console.components.view.html.IPlanetButton;
045:
046: /**
047: * iPS admin console view bean: TODO
048: */
049: public class ExcludedURLsViewBean extends CSViewBeanBase {
050: public static final String DEFAULT_DISPLAY_URL = "/ps/searchadmin/ExcludedURLs.jsp";
051: public static final String PAGE_NAME = "ExcludedURLs";
052:
053: public static final String RUN_LIST = "RunList";
054: public static final String VIEW_BUTTON = "ViewButton";
055:
056: public static final String REASON_LIST = "ReasonList";
057: public static final String TOTAL_TEXT = "Total";
058:
059: public static final String URLLISTSECTION_CONTENT = "URLListSection";
060: public static final String REASONSECTION_CONTENT = "ReasonSection";
061: public static final String EVERRUN_CONTENT = "EverRun";
062: public static final String NEVERRUN_CONTENT = "NeverRun";
063:
064: //page session attribute name
065: public static final String SELECTED_DATE = "selectedDate";
066: public static final String SELECTED_REASON = "selectedReason";
067:
068: public static final String REASON_TEXT = "Reason";
069: public static final String REASON_SUBTOTAL = "SubTotal";
070: public static final String REASON_DESC = "ReasonDesc";
071: public static final String FILTERED_LIST = "FilteredList";
072:
073: // public static final String RESET_BUTTON = "ResetButton";
074: private FilterLog flog = null;
075: private boolean everrun = false;
076: private String selectedDate = null;
077: private String selectedReason = null;
078:
079: /**
080: * constructor
081: *
082: * @param PageName of this view bean
083: * @param displayURL default display URL
084: */
085: public ExcludedURLsViewBean() {
086: super (PAGE_NAME);
087: setDefaultDisplayURL(DEFAULT_DISPLAY_URL);
088: registerChildren();
089: }
090:
091: /**
092: * register child component
093: */
094: protected void registerChildren() {
095: registerChild(RUN_LIST, ComboBox.class);
096: registerChild(VIEW_BUTTON, IPlanetButton.class);
097: registerChild(REASON_LIST, ExReasonListView.class);
098: registerChild(TOTAL_TEXT, StaticTextField.class);
099: registerChild(REASON_TEXT, StaticTextField.class);
100: registerChild(REASON_DESC, StaticTextField.class);
101: registerChild(REASON_SUBTOTAL, StaticTextField.class);
102: registerChild(FILTERED_LIST, ExURLListView.class);
103: }
104:
105: /**
106: * create child component
107: *
108: * @param name of component
109: * @return child component
110: */
111: protected View createChild(String name) {
112: View Headerchild = super .createChild(name);
113: if (Headerchild != null)
114: return Headerchild;
115: if (name.equals(RUN_LIST)) {
116: ComboBox child = new ComboBox(this , RUN_LIST, "");
117: return child;
118: }
119: if (name.equals(VIEW_BUTTON)) {
120: return new IPlanetButton(this , VIEW_BUTTON, "");
121: }
122: if (name.equals(REASON_LIST)) {
123: return new ExReasonListView(this , REASON_LIST);
124: }
125: if (name.equals(TOTAL_TEXT)) {
126: return new StaticTextField(this , TOTAL_TEXT, "");
127: }
128: if (name.equals(REASON_TEXT)) {
129: return new StaticTextField(this , REASON_TEXT, "");
130: }
131: if (name.equals(REASON_DESC)) {
132: return new StaticTextField(this , REASON_DESC, "");
133: }
134: if (name.equals(REASON_SUBTOTAL)) {
135: return new StaticTextField(this , REASON_SUBTOTAL, "0");
136: }
137: if (name.equals(FILTERED_LIST)) {
138: return new ExURLListView(this , FILTERED_LIST);
139: }
140:
141: throw new IllegalArgumentException("Invalid child name ["
142: + name + "]");
143: }
144:
145: /** begin displaying page. we set the required information
146: *
147: * @param event display event
148: * @throws ModelControlException if problem access value of component
149: */
150: public void beginDisplay(DisplayEvent event) {
151: setPageEncoding();
152: setDisplayFieldValue(VIEW_BUTTON,
153: getLocalizedString("view.selected"));
154:
155: selectedDate = (String) getPageSessionAttribute(SELECTED_DATE);
156: String file = CSConfig.getServerRoot() + File.separator
157: + "logs" + File.separator + "filter.log";
158: ExReasonListView child = (ExReasonListView) getChild(REASON_LIST);
159: int reasonIndex = child.getSelectedIndex();
160: if (selectedDate != null) {
161: if (reasonIndex >= 0) {
162: flog = new FilterLog(file, selectedDate, reasonIndex);
163: setDisplayFieldValue(REASON_TEXT, flog
164: .getReasonByIndex(reasonIndex));
165: setDisplayFieldValue(REASON_SUBTOTAL, flog
166: .getFilteredURL().size());
167: } else {
168: flog = new FilterLog(file, selectedDate);
169: }
170: setDisplayFieldValue(TOTAL_TEXT, flog.getTotal());
171: } else {
172: flog = new FilterLog(file);
173: }
174:
175: ComboBox runlist = (ComboBox) getChild(RUN_LIST);
176: Object[] date = flog.getRunArray();
177: DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG,
178: DateFormat.LONG, getUserLocale());
179: if (date.length > 0) {
180: everrun = true;
181: int last_index = 0;
182: OptionList opList = new OptionList();
183: for (int i = 0; i < date.length; i++) {
184: opList.add(df.format((Date) date[i]), FilterLog.df
185: .format((Date) date[i]));
186: last_index = i;
187: }
188: runlist.setOptions(opList);
189: if (selectedDate != null) {
190: runlist.setValue(selectedDate);
191: } else {
192: runlist.setValue(FilterLog.df
193: .format((Date) date[last_index]));
194: }
195: }
196:
197: }
198:
199: public boolean beginNeverRunDisplay(ChildDisplayEvent event) {
200: return (!everrun);
201: }
202:
203: public boolean beginEverRunDisplay(ChildDisplayEvent event) {
204: return (everrun);
205: }
206:
207: public boolean beginReasonSectionDisplay(ChildDisplayEvent event) {
208: return (selectedDate != null);
209: }
210:
211: public boolean beginURLListSectionDisplay(ChildDisplayEvent event) {
212: ExReasonListView child = (ExReasonListView) getChild(REASON_LIST);
213: return child.getSelectedIndex() >= 0;
214: }
215:
216: public void handleViewButtonRequest(RequestInvocationEvent event) {
217: String date = getDisplayFieldStringValue(RUN_LIST);
218: if (date != null && date.length() > 0) {
219: clearPageSessionAttributes();
220: setPageSessionAttribute(SELECTED_DATE, date);
221: }
222: forwardTo();
223: }
224:
225: protected void setSelectedReason(String reason) {
226: selectedReason = reason;
227: }
228:
229: protected String getSelectedReason() {
230: return selectedReason;
231: }
232:
233: public FilterLog getFilterLog() {
234: return flog;
235: }
236:
237: }
|