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.log.common.PortalLogger;
017:
018: /**
019: * Interface to be used by the AMIndentedListView class to call methods on the
020: * AMIndentedListModelImpl or its derivatives.
021: *
022: */
023: public class URLListModel extends DefaultModel implements DatasetModel,
024: RetrievingModel {
025:
026: static public final String FIELD_ENABLE = "enable";
027: static public final String FIELD_STARTPOINT = "startpoint";
028: static public final String FIELD_DEPTH = "depth";
029: static public final String FIELD_SITENAME = "sitename";
030: static public final String FIELD_SITEID = "siteid";
031: boolean first_time = false;
032:
033: // Create a Logger for this class
034: private static Logger debugLogger = PortalLogger
035: .getLogger(URLListModel.class);
036:
037: /**
038: * @param req The HttpServletRequest object passed to the super class.
039: * @param rbName The name of the resource bundle.
040: */
041: public URLListModel() {
042: super ();
043: }
044:
045: /**
046: *
047: *
048: */
049: public Object execute(ModelExecutionContext context)
050: throws ModelControlException {
051: String operationName = null;
052: if (context != null)
053: operationName = context.getOperationName();
054: else
055: operationName = ModelExecutionContext.OPERATION_RETRIEVE;
056:
057: Object result = null;
058: if (operationName
059: .equals(ModelExecutionContext.OPERATION_RETRIEVE)) {
060: result = retrieve(context);
061: }
062:
063: return result;
064: }
065:
066: /**
067: *
068: *
069: */
070: public Object retrieve(ModelExecutionContext context)
071: throws ModelControlException {
072:
073: // Perform a dummy retrieve operation. We ignore the
074: // execution context for now.
075: if (last()) // don't fetch
076: {
077: String url = (String) this .getValue(FIELD_STARTPOINT);
078: if (url.trim().length() > 0) {
079: appendRow();
080: setValue(this .FIELD_ENABLE, "Yes");
081: setValue(this .FIELD_STARTPOINT, "");
082: setValue(this .FIELD_DEPTH, "unlimited");
083: setValue(this .FIELD_SITENAME, "");
084: setValue(this .FIELD_SITEID, "");
085: }
086: return null;
087: }
088: clear();
089: RobotConfig rc = CSConfig.getRobotConfig();
090: int size = rc.numRuleset();
091: debugLogger.log(Level.FINER, "PSSH_CSPSAM0054", Integer
092: .toString(size));
093: for (int i = 0; i < size; i++) {
094: FilterRuleset frs = rc.GetRuleSet(i);
095: if (!frs.isEnabled())
096: continue;
097: int numOfSP = frs.numOfStartingPoints();
098: for (int j = 0; j < numOfSP; j++) {
099: String sp = frs.getStartingPointByIndex(j);
100: StringTokenizer st = new StringTokenizer(sp);
101: String url = null;
102: int depth = -1;
103: for (int t = 0; st.hasMoreTokens() && t < 2; t++) {
104: String token = st.nextToken();
105: if (t == 0) {
106: url = token;
107: } else {
108: depth = Integer.parseInt(token.substring(6));
109: }
110: }
111: appendRow();
112: setValue(this .FIELD_ENABLE, frs.isEnabled() ? "Yes"
113: : "No");
114: setValue(this .FIELD_STARTPOINT, url);
115: setValue(this .FIELD_DEPTH, depth == -1 ? "unlimited"
116: : Integer.toString(depth));
117: setValue(this .FIELD_SITENAME, frs.nickname);
118: setValue(this .FIELD_SITEID, frs.id);
119: }
120: }
121: // an empty row
122:
123: appendRow();
124: setValue(this .FIELD_ENABLE, "Yes");
125: setValue(this .FIELD_STARTPOINT, "");
126: setValue(this .FIELD_DEPTH, "unlimited");
127: setValue(this .FIELD_SITENAME, "");
128: setValue(this .FIELD_SITEID, "");
129:
130: // Nothing useful to return
131: return null;
132: }
133:
134: public String[] getData() {
135: try {
136: int n = getSize();
137: String data[] = new String[n];
138: int i = 0;
139: beforeFirst();
140: while (this .next()) {
141: String url = (String) this .getValue(FIELD_STARTPOINT);
142: if (url.trim().length() > 0)
143: data[i++] = url;
144: }
145: if (i < 1)
146: return null;
147:
148: String[] tmp = new String[i];
149: System.arraycopy(data, 0, tmp, 0, i);
150: return tmp;
151: } catch (Exception e) {
152: return null;
153: }
154: }
155: }
|