Ignore:
Timestamp:
2008-05-29T13:29:54+12:00 (16 years ago)
Author:
oranfry
Message:

updating from trunk: brought in trunk changes from r15191 to r15785

File:
1 edited

Legend:

Unmodified
Added
Removed
  • greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/service/GS2Browse.java

    r13962 r15787  
    2525import org.greenstone.gsdl3.util.MacroResolver;
    2626import org.greenstone.gsdl3.util.GS2MacroResolver;
    27 import org.greenstone.gsdl3.util.GDBMWrapper;
     27import org.greenstone.gsdl3.util.SimpleCollectionDatabase;
    2828import org.greenstone.gsdl3.util.DBInfo;
    2929// XML classes
     
    5252     static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.GS2Browse.class.getName());
    5353
    54     protected GDBMWrapper gdbm_src = null;
     54    protected SimpleCollectionDatabase coll_db = null;
    5555
    5656    public GS2Browse()
    5757    {
    58     this.gdbm_src = new GDBMWrapper();
    59     this.macro_resolver = new GS2MacroResolver(this.gdbm_src);
    6058    }
    6159
    6260    public void cleanUp() {
    6361    super.cleanUp();
    64     this.gdbm_src.closeDatabase();
     62    this.coll_db.closeDatabase();
    6563    }
    6664
     
    8280    }
    8381   
    84     // Open GDBM database for querying
    85     String gdbm_db_file = GSFile.GDBMDatabaseFile(this.site_home, this.cluster_name, index_stem);
    86     if (!this.gdbm_src.openDatabase(gdbm_db_file, GDBMWrapper.READER)) {
    87         logger.error("Could not open GDBM database!");
     82    // find out what kind of database we have
     83    Element database_type_elem = (Element) GSXML.getChildByTagName(info, GSXML.DATABASE_TYPE_ELEM);
     84    String database_type = null;
     85    if (database_type_elem != null) {
     86      database_type = database_type_elem.getAttribute(GSXML.NAME_ATT);
     87    }
     88    if (database_type == null || database_type.equals("")) {
     89      database_type = "gdbm"; // the default
     90    }
     91    coll_db = new SimpleCollectionDatabase(database_type);
     92    if (coll_db == null) {
     93      logger.error("Couldn't create the collection database of type "+database_type);
     94      return false;
     95    }
     96   
     97    // Open database for querying
     98    String coll_db_file = GSFile.collectionDatabaseFile(this.site_home, this.cluster_name, index_stem, database_type);
     99    if (!this.coll_db.openDatabase(coll_db_file, SimpleCollectionDatabase.READ)) {
     100        logger.error("Could not open collection database!");
    88101        return false;
    89102    }
     103    this.macro_resolver = new GS2MacroResolver(this.coll_db);
    90104    return true;
    91105    }
     
    93107    /** if id ends in .fc, .pc etc, then translate it to the correct id */
    94108    protected String translateId(String node_id) {
    95     return this.gdbm_src.translateOID(node_id);
     109    return this.coll_db.translateOID(node_id);
    96110    }
    97111
     
    103117    */
    104118    protected String getDocType(String node_id) {
    105     DBInfo info = this.gdbm_src.getInfo(node_id);
     119    DBInfo info = this.coll_db.getInfo(node_id);
    106120    if (info == null) {
    107121        return GSXML.DOC_TYPE_SIMPLE;
     
    124138    // now we just check the top node
    125139    if (!is_top) { // we need to look at the top info
    126         info = this.gdbm_src.getInfo(top_id);
     140        info = this.coll_db.getInfo(top_id);
    127141    }
    128142    if (info == null) {
     
    144158    /** returns a list of the child ids in order, null if no children */
    145159    protected ArrayList getChildrenIds(String node_id) {
    146     DBInfo info = this.gdbm_src.getInfo(node_id);
     160    DBInfo info = this.coll_db.getInfo(node_id);
    147161    if (info == null) {
    148162        return null;
     
    170184
    171185    protected String getMetadata(String node_id, String key){
    172     DBInfo info = this.gdbm_src.getInfo(node_id);
     186    DBInfo info = this.coll_db.getInfo(node_id);
    173187    if (info == null) {
    174188        return "";
     
    200214    String lang = "en";
    201215    Element metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
    202     DBInfo info = this.gdbm_src.getInfo(node_id);
     216    DBInfo info = this.coll_db.getInfo(node_id);
    203217    if (info == null) {
    204218        return null;
     
    251265        }
    252266       
    253         DBInfo info = this.gdbm_src.getInfo(parent_id);
     267        DBInfo info = this.coll_db.getInfo(parent_id);
    254268        if (info==null) {
    255269        return "-1";
     
    275289
    276290    protected int getNumChildren(String node_id) {
    277     DBInfo info = this.gdbm_src.getInfo(node_id);
     291    DBInfo info = this.coll_db.getInfo(node_id);
    278292    if (info == null) {
    279293        return 0;
Note: See TracChangeset for help on using the changeset viewer.