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:
014: import com.sun.portal.search.admin.CSConfig;
015: import com.sun.portal.search.robot.*;
016: import com.sun.portal.search.admin.resources.SearchResource;
017: import com.sun.portal.log.common.PortalLogger;
018:
019: /**
020: * Interface to be used by the AMIndentedListView class to call methods on the
021: * AMIndentedListModelImpl or its derivatives.
022: *
023: */
024: public class StartPointsListModel extends DefaultModel implements
025: DatasetModel, RetrievingModel {
026:
027: static public final String FIELD_ENABLE = "enable";
028: static public final String FIELD_STARTPOINT = "startpoint";
029: static public final String FIELD_DEPTH = "depth";
030: static public final String FIELD_SITENAME = "sitename";
031: static public final String FIELD_SITEID = "siteid";
032: public Locale userLocale = Locale.getDefault();
033:
034: // Create a Logger for this class
035: private static Logger debugLogger = PortalLogger
036: .getLogger(StartPointsListModel.class);
037:
038: /**
039: * @param req The HttpServletRequest object passed to the super class.
040: * @param rbName The name of the resource bundle.
041: */
042: public StartPointsListModel() {
043: super ();
044: }
045:
046: /**
047: *
048: *
049: */
050: public Object execute(ModelExecutionContext context)
051: throws ModelControlException {
052: String operationName = null;
053: if (context != null)
054: operationName = context.getOperationName();
055: else
056: operationName = ModelExecutionContext.OPERATION_RETRIEVE;
057:
058: Object result = null;
059: if (operationName
060: .equals(ModelExecutionContext.OPERATION_RETRIEVE)) {
061: result = retrieve(context);
062: }
063:
064: return result;
065: }
066:
067: /**
068: *
069: *
070: */
071: public Object retrieve(ModelExecutionContext context)
072: throws ModelControlException {
073: // Perform a dummy retrieve operation. We ignore the
074: // execution context for now.
075: clear();
076: RobotConfig rc = CSConfig.getRobotConfig();
077: int size = rc.numRuleset();
078: debugLogger.log(Level.FINER, "PSSH_CSPSAM0054", Integer
079: .toString(size));
080: for (int i = 0; i < size; i++) {
081: FilterRuleset frs = rc.GetRuleSet(i);
082: int numOfSP = frs.numOfStartingPoints();
083: for (int j = 0; j < numOfSP; j++) {
084: String sp = frs.getStartingPointByIndex(j);
085: StringTokenizer st = new StringTokenizer(sp);
086: String url = null;
087: int depth = -1;
088: for (int t = 0; st.hasMoreTokens() && t < 2; t++) {
089: String token = st.nextToken();
090: if (t == 0) {
091: url = token;
092: } else {
093: depth = Integer.parseInt(token.substring(6));
094: }
095: }
096: appendRow();
097: setValue(
098: this .FIELD_ENABLE,
099: frs.isEnabled() ? getLocalizedString("robot.sp.yes")
100: : getLocalizedString("robot.sp.no"));
101: setValue(this .FIELD_STARTPOINT, url);
102: setValue(
103: this .FIELD_DEPTH,
104: depth == -1 ? getLocalizedString("robot.sp.unlimited")
105: : Integer.toString(depth));
106: setValue(this .FIELD_SITENAME, frs.nickname);
107: setValue(this .FIELD_SITEID, frs.id);
108: }
109: }
110:
111: // Nothing useful to return
112: return null;
113: }
114:
115: public String getLocalizedString(String key) {
116: return SearchResource.geti18nString(key, userLocale);
117: }
118: }
|