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