source: trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGPPSearch.java@ 10651

Last change on this file since 10651 was 10651, checked in by kjdon, 19 years ago

made all index/gdbm db paths use indexstem instead of cluster_name

  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1/*
2 * GS2MGPPSearch.java
3 * Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18package org.greenstone.gsdl3.service;
19
20
21// Greenstone classes
22import org.greenstone.gsdl3.util.*;
23
24// XML classes
25import org.w3c.dom.Document;
26import org.w3c.dom.Element;
27import org.w3c.dom.NodeList;
28
29/**
30 *
31 * @author <a href="mailto:[email protected]">Katherine Don</a>
32 * @author <a href="mailto:[email protected]">Michael Dewsnip</a>
33 */
34
35public class GS2MGPPSearch
36 extends AbstractMGPPSearch
37{
38 protected GDBMWrapper gdbm_src = null;
39 protected String index_stem = null;
40
41 /** constructor */
42 public GS2MGPPSearch()
43 {
44 this.gdbm_src = new GDBMWrapper();
45 }
46
47 public void cleanUp() {
48 super.cleanUp();
49 this.gdbm_src.closeDatabase();
50 }
51
52 /** configure this service */
53 public boolean configure(Element info, Element extra_info)
54 {
55 if (!super.configure(info, extra_info)){
56 return false;
57 }
58
59 // Open GDBM database for querying
60 String gdbm_db_file = GSFile.GDBMDatabaseFile(this.site_home, this.cluster_name, this.index_stem);
61 if (!this.gdbm_src.openDatabase(gdbm_db_file, GDBMWrapper.READER)) {
62 System.err.println("Error: Could not open GDBM database!");
63 return false;
64 }
65 return true;
66 }
67 /** returns the document type of the doc that the specified node
68 belongs to. should be one of
69 GSXML.DOC_TYPE_SIMPLE,
70 GSXML.DOC_TYPE_PAGED,
71 GSXML.DOC_TYPE_HIERARCHY
72 */
73 protected String getDocType(String node_id){
74 DBInfo info = this.gdbm_src.getInfo(node_id);
75 if (info == null) {
76 return GSXML.DOC_TYPE_SIMPLE;
77 }
78 String doc_type = info.getInfo("doctype");
79 if (!doc_type.equals("")&&!doc_type.equals("doc")) {
80 return doc_type;
81 }
82
83 String top_id = OID.getTop(node_id);
84 boolean is_top = (top_id.equals(node_id) ? true : false);
85
86 String children = info.getInfo("contains");
87 boolean is_leaf = (children.equals("") ? true : false);
88
89 if (is_top && is_leaf) { // a single section document
90 return GSXML.DOC_TYPE_SIMPLE;
91 }
92
93 // now we just check the top node
94 if (!is_top) { // we need to look at the top info
95 info = this.gdbm_src.getInfo(top_id);
96 }
97 if (info == null) {
98 return GSXML.DOC_TYPE_HIERARCHY;
99 }
100
101 String childtype = info.getInfo("childtype");
102 if (childtype.equals("Paged")) {
103 return GSXML.DOC_TYPE_PAGED;
104 }
105 return GSXML.DOC_TYPE_HIERARCHY;
106
107 }
108
109 /** returns true if the node has child nodes */
110 protected boolean hasChildren(String node_id){
111 DBInfo info = this.gdbm_src.getInfo(node_id);
112 if (info == null) {
113 return false;
114 }
115 String contains = info.getInfo("contains");
116 if (contains.equals("")) {
117 return false;
118 }
119 return true;
120 }
121
122 /** returns true if the node has a parent */
123 protected boolean hasParent(String node_id){
124 String parent = OID.getParent(node_id);
125 if (parent.equals(node_id)) {
126 return false;
127 }
128 return true;
129 }
130
131 /** convert MGPP internal id to Greenstone oid */
132 protected String MGPPNum2OID(long docnum)
133 {
134 return this.gdbm_src.docnum2OID(docnum);
135
136 }
137
138}
139
140
Note: See TracBrowser for help on using the repository browser.