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.*;
010: import java.util.logging.Logger;
011: import java.util.logging.Level;
012: import java.io.*;
013: import java.text.*;
014:
015: import com.sun.portal.search.admin.CSConfig;
016: import com.sun.portal.search.admin.resources.SearchResource;
017: import com.sun.portal.search.soif.*;
018: import com.sun.portal.search.rdm.RDM;
019: import com.sun.portal.search.admin.util.DBUtil;
020: import com.sun.portal.log.common.PortalLogger;
021:
022: import com.iplanet.jato.model.*;
023:
024: /**
025: * This class supports the DatabaseListView by providing the data in the
026: * format expected by the view.
027: */
028: public class DatabaseListModel extends DefaultModel implements
029: DatasetModel, RetrievingModel, DeletingModel {
030: public static final String FIELD_NAME = "Name";
031: public static final String FIELD_RDCOUNT = "RDCount";
032: public static final String FIELD_SELECT = "Select";
033: public static final String FIELD_TITLE = "Title";
034: public static final String FIELD_DESC = RDM.A_RDM_DESC;
035:
036: public Locale userLocale = Locale.getDefault();
037:
038: // Create a Logger for this class
039: private static Logger debugLogger = PortalLogger
040: .getLogger(DatabaseListModel.class);
041:
042: public DatabaseListModel() {
043: super ();
044:
045: }
046:
047: public DatabaseListModel(String name) {
048: super (name);
049: }
050:
051: // Model execution methods
052: ////////////////////////////////////////////////////////////////////////////////
053:
054: /**
055: *
056: *
057: */
058: public Object execute(ModelExecutionContext context)
059: throws ModelControlException {
060: String operationName = null;
061: if (context != null)
062: operationName = context.getOperationName();
063: else
064: operationName = ModelExecutionContext.OPERATION_RETRIEVE;
065:
066: Object result = null;
067: if (operationName
068: .equals(ModelExecutionContext.OPERATION_RETRIEVE)) {
069: result = retrieve(context);
070: }
071:
072: return result;
073: }
074:
075: /**
076: *
077: *
078: */
079: public String[] getSelectDBs() throws ModelControlException {
080: ArrayList sels = new ArrayList();
081: beforeFirst();
082: while (next()) {
083: String isSelected = (String) getValue(this .FIELD_SELECT);
084: if (isSelected != null && isSelected.compareTo("true") == 0) {
085: String name = (String) getValue(this .FIELD_NAME);
086: sels.add(name);
087: }
088: }
089: return (String[]) sels.toArray(new String[0]);
090: }
091:
092: public Object delete(ModelExecutionContext context)
093: throws ModelControlException {
094: /* Not Supportted yet*/
095: /*
096: beforeFirst();
097: while(next()) {
098: String isDelete = (String) getValue(this.FIELD_SELECT);
099: if (isDelete != null && isDelete.compareTo("true")==0) {
100: String name = (String) getValue(this.FIELD_NAME);
101: deleteDB(name);
102: }
103: }*/
104: return null;
105: }
106:
107: /**
108: *
109: *
110: */
111: public Object retrieve(ModelExecutionContext context)
112: throws ModelControlException {
113:
114: NumberFormat nf = NumberFormat.getInstance(userLocale);
115: clear();
116: try {
117: List dbs = DBUtil.getDBList(CSConfig.getServerRoot());
118: for (int i = 0; i < dbs.size(); i++) {
119: appendRow();
120: SOIF s = (SOIF) dbs.get(i);
121: debugLogger.log(Level.FINER, "PSSH_CSPSAM0013", s
122: .toString());
123: setValue(FIELD_NAME, s.getURL());
124: setValue(FIELD_DESC, s.getValue(FIELD_DESC));
125: setValue(FIELD_TITLE, s.getValue(FIELD_TITLE));
126: //int count = DBUtil.getRDCount(CSConfig.getServerRoot(), s.getURL());
127: //setValue(FIELD_RDCOUNT, nf.format(count));
128: }
129: } catch (Exception e) {
130: debugLogger.log(Level.INFO, "PSSH_CSPSAM0012", e
131: .getMessage());
132: }
133:
134: beforeFirst();
135: // Nothing useful to return
136: return null;
137: }
138: }
|