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.model;
007:
008: import java.lang.*;
009: import java.util.Map;
010: import java.util.Set;
011: import java.util.Collections;
012: import java.util.List;
013: import java.util.ArrayList;
014: import java.util.logging.Logger;
015: import java.net.*;
016: import javax.servlet.http.HttpServletRequest;
017:
018: import com.iplanet.jato.model.*;
019: import com.iplanet.jato.view.html.OptionList;
020: import com.sun.portal.search.admin.CSConfig;
021: import com.sun.portal.search.robot.FilterRule;
022: import com.sun.portal.search.robot.StringFilter;
023: import com.sun.portal.log.common.PortalLogger;
024:
025: /**
026: * This class supports the MenuListView by providing the data in the
027: * format expected by the view.
028: */
029: public class StringFilterListModel extends DefaultModel implements
030: DatasetModel, RetrievingModel, UpdatingModel, InsertingModel,
031: DeletingModel {
032: private String ruleID = null;
033: private int delIndex = -1;
034: public static final String FIELD_FILTERSRC = "FilterSrc";
035: public static final String FIELD_FILTERBY = "FilterBy";
036: public static final String FIELD_PATTERN = "Pattern";
037: public static final String FIELD_DELETE = "Delete";
038:
039: // Create a Logger for this class
040: private static Logger debugLogger = PortalLogger
041: .getLogger(StringFilterListModel.class);
042:
043: /**
044: * @param req The HttpServletRequest object passed to the super class.
045: * @param rbName The name of the resource bundle.
046: */
047: public StringFilterListModel() {
048: super ();
049: }
050:
051: public void setID(String id) {
052: ruleID = id;
053: }
054:
055: public void setDelIndex(int index) {
056: delIndex = index;
057: }
058:
059: // Model execution methods
060: ////////////////////////////////////////////////////////////////////////////////
061:
062: /**
063: *
064: *
065: */
066: public Object execute(ModelExecutionContext context)
067: throws ModelControlException {
068: String operationName = null;
069: if (context != null)
070: operationName = context.getOperationName();
071: else
072: operationName = ModelExecutionContext.OPERATION_RETRIEVE;
073:
074: Object result = null;
075: if (operationName
076: .equals(ModelExecutionContext.OPERATION_RETRIEVE)) {
077: result = retrieve(context);
078: } else if (operationName
079: .equals(ModelExecutionContext.OPERATION_INSERT)) {
080: result = insert(context);
081: } else if (operationName
082: .equals(ModelExecutionContext.OPERATION_UPDATE)) {
083: result = update(context);
084: } else if (operationName
085: .equals(ModelExecutionContext.OPERATION_DELETE)) {
086: result = delete(context);
087: }
088:
089: return result;
090: }
091:
092: /*
093: * when tiledView has an checkBox field, it will leave a row with null in model
094: * after deleted all row.
095: *
096: */
097: private void removeNullList() throws ModelControlException {
098: if (getSize() == 1 && getValue(FIELD_PATTERN) == null) {
099: this .getCurrentContext().getValueList().clear();
100: }
101: }
102:
103: /**
104: *
105: *
106: */
107: public Object update(ModelExecutionContext context)
108: throws ModelControlException {
109: removeNullList();
110: beforeFirst();
111: FilterRule fr = null;
112: if (ruleID != null) {
113: fr = CSConfig.getRobotConfig().GetRule(ruleID);
114: }
115: if (fr != null) {
116: fr.removeAllFilter();
117: while (next()) {
118: //String isDelete = (String) getValue(this.FIELD_DELETE);
119: //if (isDelete != null && isDelete.compareTo("true")==0) {
120: // continue;
121: //}
122: String src = (String) getValue(FIELD_FILTERSRC);
123: String by = (String) getValue(FIELD_FILTERBY);
124: String p = (String) getValue(FIELD_PATTERN);
125: if (p != null && p.trim().length() > 0) {
126: fr.addFilter(src, by, p.trim());
127: }
128: }
129: }
130: return null;
131: }
132:
133: /**
134: *
135: *
136: */
137: public Object insert(ModelExecutionContext context)
138: throws ModelControlException {
139: removeNullList();
140:
141: appendRow();
142: setValue(FIELD_FILTERSRC, FilterRule.filter_srcs[0]);
143: setValue(FIELD_FILTERBY, FilterRule.filter_methods[0]);
144: setValue(FIELD_PATTERN, "");
145: return null;
146: }
147:
148: /**
149: *
150: *
151: */
152: public Object delete(ModelExecutionContext context)
153: throws ModelControlException {
154: removeNullList();
155: if (delIndex != -1) {
156: getCurrentContext().getValueList().remove(delIndex);
157: return null;
158: }
159:
160: ArrayList delObjs = new ArrayList();
161: beforeFirst();
162: while (next()) {
163: String isDelete = (String) getValue(this .FIELD_DELETE);
164: if (isDelete != null && isDelete.compareTo("true") == 0) {
165: int index = getRowIndex();
166: delObjs.add(getCurrentContext().getValueList().get(
167: index));
168: }
169: }
170: for (int i = 0; i < delObjs.size(); i++) {
171: getCurrentContext().getValueList().remove(delObjs.get(i));
172: }
173: return null;
174: }
175:
176: /**
177: *
178: *
179: */
180: public Object retrieve(ModelExecutionContext context)
181: throws ModelControlException {
182: // Perform a dummy retrieve operation. We ignore the
183: // execution context for now.
184: FilterRule fr = null;
185: if (ruleID != null) {
186: if (ruleID.compareTo("new") == 0) {
187: clear();
188: this .insert(context);
189: } else {
190: fr = CSConfig.getRobotConfig().GetRule(ruleID);
191: if (fr != null) {
192: clear();
193: int n = fr.numberOfStringFilters();
194: for (int i = 0; i < n; i++) {
195: StringFilter sf = (StringFilter) fr.filters
196: .get(i);
197: if (sf != null) {
198: appendRow();
199: setValue(FIELD_FILTERSRC, sf.directive);
200: setValue(FIELD_FILTERBY, FilterRule
201: .getMethodText(sf.method));
202: setValue(FIELD_PATTERN, sf.filter);
203: }
204: }
205: }
206: }
207:
208: } else {
209: debugLogger.finer("PSSH_CSPSAM0055");
210: }
211: beforeFirst();
212:
213: // Nothing useful to return
214: return null;
215: }
216:
217: }
|