Changeset 15787 for greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2DocumentRetrieve.java
- Timestamp:
- 2008-05-29T13:29:54+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
greenstone3/branches/customizingGreenstone3/src/java/org/greenstone/gsdl3/service/AbstractGS2DocumentRetrieve.java
r14527 r15787 27 27 import org.greenstone.gsdl3.util.GS2MacroResolver; 28 28 import org.greenstone.gsdl3.util.GSConstants; 29 import org.greenstone.gsdl3.util. GDBMWrapper;29 import org.greenstone.gsdl3.util.SimpleCollectionDatabase; 30 30 import org.greenstone.gsdl3.util.DBInfo; 31 31 // XML classes … … 59 59 protected String index_stem = null; 60 60 61 protected GDBMWrapper gdbm_src= null;61 protected SimpleCollectionDatabase coll_db = null; 62 62 63 63 … … 65 65 protected AbstractGS2DocumentRetrieve() 66 66 { 67 this.gdbm_src = new GDBMWrapper(); 68 this.macro_resolver = new GS2MacroResolver(this.gdbm_src); 67 this.macro_resolver = new GS2MacroResolver(); 69 68 } 70 69 71 70 public void cleanUp() { 72 73 this.gdbm_src.closeDatabase();71 super.cleanUp(); 72 this.coll_db.closeDatabase(); 74 73 } 75 74 /** configure this service */ … … 93 92 } 94 93 95 // Open GDBM database for querying 96 String gdbm_db_file = GSFile.GDBMDatabaseFile(this.site_home, this.cluster_name, this.index_stem); 97 if (!this.gdbm_src.openDatabase(gdbm_db_file, GDBMWrapper.READER)) { 98 logger.error("Could not open GDBM database!"); 94 // find out what kind of database we have 95 Element database_type_elem = (Element) GSXML.getChildByTagName(info, GSXML.DATABASE_TYPE_ELEM); 96 String database_type = null; 97 if (database_type_elem != null) { 98 database_type = database_type_elem.getAttribute(GSXML.NAME_ATT); 99 } 100 if (database_type == null || database_type.equals("")) { 101 database_type = "gdbm"; // the default 102 } 103 coll_db = new SimpleCollectionDatabase(database_type); 104 if (coll_db == null) { 105 logger.error("Couldn't create the collection database of type "+database_type); 106 return false; 107 } 108 109 // Open database for querying 110 String coll_db_file = GSFile.collectionDatabaseFile(this.site_home, this.cluster_name, this.index_stem, database_type); 111 if (!this.coll_db.openDatabase(coll_db_file, SimpleCollectionDatabase.READ)) { 112 logger.error("Could not open collection database!"); 99 113 return false; 100 114 } 115 116 // we need to set the database for our GS2 macro resolver 117 GS2MacroResolver gs2_macro_resolver = (GS2MacroResolver)this.macro_resolver; 118 gs2_macro_resolver.setDB(this.coll_db); 101 119 102 120 return true; … … 105 123 /** if id ends in .fc, .pc etc, then translate it to the correct id */ 106 124 protected String translateId(String node_id) { 107 return this. gdbm_src.translateOID(node_id);125 return this.coll_db.translateOID(node_id); 108 126 } 109 127 … … 111 129 it to a greenstone one*/ 112 130 protected String translateExternalId(String node_id){ 113 return this. gdbm_src.externalId2OID(node_id);131 return this.coll_db.externalId2OID(node_id); 114 132 } 115 133 … … 120 138 /** returns a list of the child ids in order, null if no children */ 121 139 protected ArrayList getChildrenIds(String node_id) { 122 DBInfo info = this. gdbm_src.getInfo(node_id);140 DBInfo info = this.coll_db.getInfo(node_id); 123 141 if (info == null) { 124 142 return null; … … 156 174 throws GSException { 157 175 Element metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER); 158 DBInfo info = this. gdbm_src.getInfo(node_id);176 DBInfo info = this.coll_db.getInfo(node_id); 159 177 if (info == null) { 160 178 return null; … … 211 229 } 212 230 213 DBInfo info = this. gdbm_src.getInfo(parent_id);231 DBInfo info = this.coll_db.getInfo(parent_id); 214 232 if (info==null) { 215 233 return "-1"; … … 235 253 236 254 protected int getNumChildren(String node_id) { 237 DBInfo info = this. gdbm_src.getInfo(node_id);255 DBInfo info = this.coll_db.getInfo(node_id); 238 256 if (info == null) { 239 257 return 0; … … 254 272 */ 255 273 protected String getDocType(String node_id) { 256 DBInfo info = this. gdbm_src.getInfo(node_id);274 DBInfo info = this.coll_db.getInfo(node_id); 257 275 if (info == null) { 258 276 return GSXML.DOC_TYPE_SIMPLE; … … 275 293 // now we just check the top node 276 294 if (!is_top) { // we need to look at the top info 277 info = this. gdbm_src.getInfo(top_id);295 info = this.coll_db.getInfo(top_id); 278 296 } 279 297 if (info == null) { … … 337 355 338 356 // now check for relational info 339 if (temp.equals("parent") || temp.equals("root") || temp.equals( "ancestors")) { // "current" "siblings" "children" "descend ents"357 if (temp.equals("parent") || temp.equals("root") || temp.equals( "ancestors")) { // "current" "siblings" "children" "descendants" 340 358 relation = temp; 341 359 pos = metadata.indexOf(GSConstants.META_RELATION_SEP); … … 370 388 relation_info = info; 371 389 } else { 372 relation_info = this. gdbm_src.getInfo(relation_id);390 relation_info = this.coll_db.getInfo(relation_id); 373 391 } 374 392 if (relation_info == null) { … … 405 423 relation_id = OID.getParent(current_id); 406 424 while (!relation_id.equals(current_id)) { 407 relation_info = this. gdbm_src.getInfo(relation_id);425 relation_info = this.coll_db.getInfo(relation_id); 408 426 if (relation_info == null) return result.toString(); 409 427 if (!multiple) { … … 427 445 428 446 429 /** needs to get info from gdbmdatabase - if the calling code gets it already it may pay to pass it in instead */447 /** needs to get info from collection database - if the calling code gets it already it may pay to pass it in instead */ 430 448 protected String resolveTextMacros(String doc_content, String doc_id, String lang) 431 449 { … … 452 470 value="-1"; 453 471 } else { 454 DBInfo info = this. gdbm_src.getInfo(parent_id);472 DBInfo info = this.coll_db.getInfo(parent_id); 455 473 if (info==null) { 456 474 value ="-1"; … … 478 496 479 497 protected String getHrefOID(String href_url){ 480 return this. gdbm_src.docnum2OID(href_url);498 return this.coll_db.docnum2OID(href_url); 481 499 } 482 500
Note:
See TracChangeset
for help on using the changeset viewer.