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.Locale;
014: import java.util.ArrayList;
015: import java.util.logging.Logger;
016: import java.util.logging.Level;
017: import javax.servlet.http.HttpServletRequest;
018:
019: import com.sun.portal.search.admin.CSConfig;
020: import com.sun.portal.search.admin.ImportConfig;
021: import com.sun.portal.search.admin.resources.SearchResource;
022: import com.sun.portal.log.common.PortalLogger;
023:
024: import com.iplanet.jato.model.*;
025:
026: /**
027: * This class supports the MenuListView by providing the data in the
028: * format expected by the view.
029: */
030: public class ImportListModel extends DefaultModel implements
031: DatasetModel, RetrievingModel, UpdatingModel, DeletingModel {
032: public static final String FIELD_ENABLE = "FieldEnable";
033: public static final String FIELD_ID = "FieldID";
034: public static final String FIELD_IMAGE = "FieldImage";
035: public static final String FIELD_TYPE = "FieldType";
036: public static final String FIELD_NAME = "FieldName";
037: public static final String FIELD_DELETE = "Delete";
038: public static final String ENABLE_VALUES[] = { "true", "false" };
039: public Locale userLocale = Locale.getDefault();
040:
041: // Create a Logger for this class
042: private static Logger debugLogger = PortalLogger
043: .getLogger(ImportListModel.class);
044:
045: /**
046: * @param req The HttpServletRequest object passed to the super class.
047: * @param rbName The name of the resource bundle.
048: */
049: public ImportListModel() {
050: super ();
051: //rc = CSConfig.getRobotConfig();
052:
053: }
054:
055: public ImportListModel(String name) {
056: super (name);
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: }
079:
080: return result;
081: }
082:
083: /**
084: *
085: *
086: */
087: public Object update(ModelExecutionContext context)
088: throws ModelControlException {
089: beforeFirst();
090: while (this .next()) {
091: String enable = (String) this .getValue(FIELD_ENABLE);
092: ImportConfig imp = ImportConfig
093: .getImportConfigByIndex(getLocation());
094: if (imp != null) {
095: imp.setValue(ImportConfig.ENABLE, enable);
096: }
097: }
098: ImportConfig.updateFile();
099: return null;
100: }
101:
102: /**
103: *
104: *
105: */
106: public Object delete(ModelExecutionContext context)
107: throws ModelControlException {
108: beforeFirst();
109: int numImport = ImportConfig.numOfImportConfig();
110: if (numImport == 0) {
111: return null;
112: }
113: String[] ids = new String[numImport]; //record ruleset id
114: while (next()) {
115: int index = getLocation();
116: String isDelete = (String) getValue(FIELD_DELETE);
117: ids[index] = null;
118: if (isDelete.compareTo("true") == 0) {
119: ImportConfig imp = ImportConfig
120: .getImportConfigByIndex(index);
121: if (imp != null) {
122: ids[index] = imp.getID();
123: debugLogger.log(Level.FINER, "PSSH_CSPSAM0027",
124: ids[index]);
125: }
126: }
127: }
128:
129: for (int i = 0; i < ids.length; i++) {
130: if (ids[i] != null) {
131: ImportConfig.DeleteImportConfigByID(ids[i]);
132: }
133: }
134: ImportConfig.updateFile();
135: return null;
136: }
137:
138: /**
139: *
140: *
141: */
142: public Object retrieve(ModelExecutionContext context)
143: throws ModelControlException {
144: // Perform a dummy retrieve operation. We ignore the
145: // execution context for now.
146: clear();
147:
148: for (int i = 0; i < ImportConfig.numOfImportConfig(); i++) {
149: ImportConfig imp = ImportConfig.getImportConfigByIndex(i);
150: appendRow();
151: setValue(FIELD_ID, imp.getValue(ImportConfig.ID));
152: setValue(FIELD_ENABLE, imp.getValue(ImportConfig.ENABLE));
153: String csid = imp.getValue(ImportConfig.CSID);
154: String nickname = imp.getValue(ImportConfig.NICKNAME);
155: if (csid != null) {
156: if (nickname == null) {
157: nickname = csid;
158: }
159: setValue(FIELD_NAME, nickname);
160: int hoststart = nickname.indexOf("://");
161: if (hoststart > 0) {
162: int hostend = nickname.indexOf('/', hoststart + 3);
163: if (hostend > 0) {
164: setValue(FIELD_NAME, SearchResource
165: .geti18nString("search.server",
166: userLocale)
167: + ":"
168: + nickname.substring(hoststart + 3,
169: hostend)
170: + " ["
171: + nickname.substring(hostend + 1) + "]");
172: }
173: }
174:
175: if (imp.getValue(ImportConfig.IS_SSL) == "true") {
176: setValue(FIELD_IMAGE,
177: "../ps/searchadmin/images/key_on.gif");
178: } else {
179: setValue(FIELD_IMAGE,
180: "../ps/searchadmin/images/key_off.gif");
181: }
182: } else {
183: String file = imp.getValue(ImportConfig.SRCFILE);
184: if (file != null) {
185: setValue(FIELD_NAME, nickname == null ? file
186: : nickname);
187: }
188: setValue(FIELD_IMAGE,
189: "../ps/searchadmin/images/file.gif");
190: }
191: setValue(FIELD_DELETE, "false");
192:
193: }
194: beforeFirst();
195:
196: // Nothing useful to return
197: return null;
198: }
199:
200: }
|