source: branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGPPSearch.java@ 9529

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

changed the location of the GDBMWrapper and DBInfo classes, so had to change some of the import statements

  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 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
40 /** constructor */
41 public GS2MGPPSearch()
42 {
43 this.gdbm_src = new GDBMWrapper();
44 }
45
46 /** configure this service */
47 public boolean configure(Element info, Element extra_info)
48 {
49
50 // Open GDBM database for querying
51 String gdbm_db_file = GSFile.GDBMDatabaseFile(this.site_home, this.cluster_name);
52 if (!this.gdbm_src.openDatabase(gdbm_db_file, GDBMWrapper.READER)) {
53 System.err.println("Error: Could not open GDBM database!");
54 return false;
55 }
56 return super.configure(info, extra_info);
57 }
58 /** returns the document type of the doc that the specified node
59 belongs to. should be one of
60 GSXML.DOC_TYPE_SIMPLE,
61 GSXML.DOC_TYPE_PAGED,
62 GSXML.DOC_TYPE_HIERARCHY
63 */
64 protected String getDocType(String node_id){
65 DBInfo info = this.gdbm_src.getInfo(node_id);
66 if (info == null) {
67 return GSXML.DOC_TYPE_SIMPLE;
68 }
69 String doc_type = info.getInfo("doctype");
70 if (!doc_type.equals("")&&!doc_type.equals("doc")) {
71 return doc_type;
72 }
73
74 String top_id = OID.getTop(node_id);
75 boolean is_top = (top_id.equals(node_id) ? true : false);
76
77 String children = info.getInfo("contains");
78 boolean is_leaf = (children.equals("") ? true : false);
79
80 if (is_top && is_leaf) { // a single section document
81 return GSXML.DOC_TYPE_SIMPLE;
82 }
83
84 // now we just check the top node
85 if (!is_top) { // we need to look at the top info
86 info = this.gdbm_src.getInfo(top_id);
87 }
88 if (info == null) {
89 return GSXML.DOC_TYPE_HIERARCHY;
90 }
91
92 String childtype = info.getInfo("childtype");
93 if (childtype.equals("Paged")) {
94 return GSXML.DOC_TYPE_PAGED;
95 }
96 return GSXML.DOC_TYPE_HIERARCHY;
97
98 }
99
100 /** returns true if the node has child nodes */
101 protected boolean hasChildren(String node_id){
102 DBInfo info = this.gdbm_src.getInfo(node_id);
103 if (info == null) {
104 return false;
105 }
106 String contains = info.getInfo("contains");
107 if (contains.equals("")) {
108 return false;
109 }
110 return true;
111 }
112
113 /** returns true if the node has a parent */
114 protected boolean hasParent(String node_id){
115 String parent = OID.getParent(node_id);
116 if (parent.equals(node_id)) {
117 return false;
118 }
119 return true;
120 }
121
122 /** convert MGPP internal id to Greenstone oid */
123 protected String MGPPNum2OID(long docnum)
124 {
125 return this.gdbm_src.docnum2OID(docnum);
126
127 }
128
129}
130
131
Note: See TracBrowser for help on using the repository browser.