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.net.*;
015: import javax.servlet.http.HttpServletRequest;
016:
017: import com.iplanet.jato.model.*;
018: import com.iplanet.jato.view.html.OptionList;
019: import com.sun.portal.search.admin.CSConfig;
020: import com.sun.portal.search.robot.FilterRuleset;
021:
022: /**
023: * This class supports the MenuListView by providing the data in the
024: * format expected by the view.
025: */
026: public class DomainGroupListModel extends DefaultModel implements
027: DatasetModel, RetrievingModel, UpdatingModel, InsertingModel,
028: DeletingModel {
029: private String rulesetID = null;
030: private int delIndex = -1;
031: public static final String FIELD_DOMAIN = "DomainAlias";
032: public static final String FIELD_VERIFIED_TEXT = "VerifiedText";
033: public static final String FIELD_DELETE = "Delete";
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 DomainGroupListModel() {
040: super ();
041: }
042:
043: public void setID(String id) {
044: this .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_DOMAIN) == 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.removeDomains();
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 domain = (String) getValue(FIELD_DOMAIN);
115: if (domain != null && domain.trim().length() > 0) {
116: frs.addDomain(domain.trim());
117: }
118: }
119: }
120: return null;
121: }
122:
123: /**
124: *
125: *
126: */
127: public Object insert(ModelExecutionContext context)
128: throws ModelControlException {
129: removeNullList();
130: this .appendRow();
131: return null;
132: }
133:
134: /**
135: *
136: *
137: */
138: public Object delete(ModelExecutionContext context)
139: throws ModelControlException {
140: removeNullList();
141: if (delIndex != -1) {
142: getCurrentContext().getValueList().remove(delIndex);
143: return null;
144: }
145:
146: ArrayList delObjs = new ArrayList();
147: beforeFirst();
148: while (next()) {
149: String isDelete = (String) getValue(this .FIELD_DELETE);
150: if (isDelete != null && isDelete.compareTo("true") == 0) {
151: int index = getRowIndex();
152: delObjs.add(getCurrentContext().getValueList().get(
153: index));
154: }
155: }
156: for (int i = 0; i < delObjs.size(); i++) {
157: getCurrentContext().getValueList().remove(delObjs.get(i));
158: }
159: return null;
160: }
161:
162: /**
163: *
164: *
165: */
166: public Object retrieve(ModelExecutionContext context)
167: throws ModelControlException {
168:
169: // Perform a dummy retrieve operation. We ignore the
170: // execution context for now.
171: FilterRuleset frs = null;
172: if (rulesetID != null) {
173: frs = CSConfig.getRobotConfig().GetRuleSet(rulesetID);
174: }
175: if (frs != null) {
176: clear();
177: int n = frs.numOfDomains();
178: for (int i = 0; i < n; i++) {
179: String domain = frs.getDomainByIndex(i);
180: if (domain != null) {
181: appendRow();
182: setValue(FIELD_DOMAIN, frs.getDomainByIndex(i));
183: // XXX need a function to get verified text here
184: setValue(FIELD_VERIFIED_TEXT, frs
185: .getDomainByIndex(i));
186: setValue(FIELD_DELETE, "false");
187: }
188: }
189: }
190: beforeFirst();
191:
192: // Nothing useful to return
193: return null;
194: }
195:
196: }
|