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 javax.servlet.http.HttpServletRequest;
015:
016: import com.iplanet.jato.model.*;
017: import com.sun.portal.search.admin.CSConfig;
018: import com.sun.portal.search.robot.*;
019:
020: /**
021: * This class supports the MenuListView by providing the data in the
022: * format expected by the view.
023: */
024: public class SitesListModel extends DefaultModel implements
025: DatasetModel, RetrievingModel, UpdatingModel, DeletingModel {
026: private RobotConfig rc = null;
027: public static final String FIELD_ENABLE = "Enable";
028: public static final String FIELD_SITEID = "SiteID";
029: public static final String FIELD_TYPEIMAGE = "TypeImage";
030: public static final String FIELD_NICKNAME = "NickName";
031: public static final String FIELD_DELETE = "Delete";
032: public static final String ENABLE_VALUES[] = { "true", "false" };
033: static String SECURE_SERVER_IMAGE = "../ps/searchadmin/images/key_on.gif";
034: static String OPEN_SERVER_IMAGE = "../ps/searchadmin/images/key_off.gif";
035: static String DOMAIN_IMAGE = "../ps/searchadmin/images/domain.gif";
036: static String FILE_IMAGE = "../ps/searchadmin/images/file.gif";
037: static String BLANK_IMAGE = "../ps/searchadmin/images/blank.gif";
038:
039: /**
040: * @param req The HttpServletRequest object passed to the super class.
041: * @param rbName The name of the resource bundle.
042: */
043: public SitesListModel() {
044: super ();
045: rc = CSConfig.getRobotConfig();
046:
047: }
048:
049: public String getImage(FilterRuleset frs) {
050: if (frs != null) {
051: if (frs.getType() == FilterRuleset.TYPE_SERVERS) {
052: if (frs.numOfServers() == 1) {
053: if (frs.getServerByIndex(0).startsWith("https"))
054: return SECURE_SERVER_IMAGE;
055: else if (frs.getServerByIndex(0).startsWith("file"))
056: return FILE_IMAGE;
057: else
058: return OPEN_SERVER_IMAGE;
059: }
060: }
061: return DOMAIN_IMAGE;
062: }
063: return BLANK_IMAGE;
064: }
065:
066: public boolean delRuleset(String id) {
067: return rc.delRuleset(id);
068:
069: }
070:
071: // Model execution methods
072: ////////////////////////////////////////////////////////////////////////////////
073:
074: /**
075: *
076: *
077: */
078: public Object execute(ModelExecutionContext context)
079: throws ModelControlException {
080: String operationName = null;
081: if (context != null)
082: operationName = context.getOperationName();
083: else
084: operationName = ModelExecutionContext.OPERATION_RETRIEVE;
085:
086: Object result = null;
087: if (operationName
088: .equals(ModelExecutionContext.OPERATION_RETRIEVE)) {
089: result = retrieve(context);
090: }
091:
092: return result;
093: }
094:
095: /**
096: *
097: *
098: */
099: public Object update(ModelExecutionContext context)
100: throws ModelControlException {
101: beforeFirst();
102: while (next()) {
103: FilterRuleset frs = rc.GetRuleSet(getLocation());
104: if (frs != null) {
105: String enable = (String) getValue(FIELD_ENABLE);
106: frs.setEnabled(enable.compareTo(ENABLE_VALUES[0]) == 0);
107: }
108: }
109: rc.updateFile();
110: return null;
111: }
112:
113: /**
114: *
115: *
116: */
117: public Object delete(ModelExecutionContext context)
118: throws ModelControlException {
119: beforeFirst();
120: String[] ids = new String[getSize()]; //record ruleset id
121: while (next()) {
122: int index = getLocation();
123: String isDelete = (String) getValue(FIELD_DELETE);
124: ids[index] = null;
125: if (isDelete.compareTo("true") == 0) {
126:
127: FilterRuleset frs = rc.GetRuleSet(index);
128: if (frs != null) {
129: ids[index] = frs.id;
130: }
131: }
132: }
133:
134: for (int i = 0; i < ids.length; i++) {
135: if (ids[i] != null) {
136: rc.delRuleset(ids[i]);
137: }
138: }
139: rc.updateFile();
140: return null;
141: }
142:
143: /**
144: *
145: *
146: */
147: public Object retrieve(ModelExecutionContext context)
148: throws ModelControlException {
149:
150: // Perform a dummy retrieve operation. We ignore the
151: // execution context for now.
152: clear();
153: int n = rc.numRuleset();
154:
155: for (int i = 0; i < n; i++) {
156: FilterRuleset frs = rc.GetRuleSet(i);
157: if (frs != null) {
158: appendRow();
159: setValue(FIELD_ENABLE,
160: frs.isEnabled() ? ENABLE_VALUES[0]
161: : ENABLE_VALUES[1]);
162: setValue(FIELD_TYPEIMAGE, getImage(frs));
163: setValue(FIELD_SITEID, frs.id);
164: setValue(FIELD_NICKNAME, frs.nickname);
165: setValue(FIELD_DELETE, "false");
166: }
167: }
168: beforeFirst();
169:
170: // Nothing useful to return
171: return null;
172: }
173:
174: }
|