1 | /*
|
---|
2 | * GS2MGSearch.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 | */
|
---|
18 | package org.greenstone.gsdl3.service;
|
---|
19 |
|
---|
20 |
|
---|
21 | // Greenstone classes
|
---|
22 | import org.greenstone.gsdl3.util.*;
|
---|
23 |
|
---|
24 | // XML classes
|
---|
25 | import org.w3c.dom.Document;
|
---|
26 | import org.w3c.dom.Element;
|
---|
27 | import 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 |
|
---|
35 | public class GS2MGSearch
|
---|
36 | extends AbstractMGSearch
|
---|
37 | {
|
---|
38 | protected GDBMWrapper gdbm_src = null;
|
---|
39 |
|
---|
40 | /** constructor */
|
---|
41 | public GS2MGSearch()
|
---|
42 | {
|
---|
43 | this.gdbm_src = new GDBMWrapper();
|
---|
44 | }
|
---|
45 | public void cleanUp() {
|
---|
46 | super.cleanUp();
|
---|
47 | this.gdbm_src.closeDatabase();
|
---|
48 | }
|
---|
49 |
|
---|
50 | /** configure this service */
|
---|
51 | public boolean configure(Element info, Element extra_info)
|
---|
52 | {
|
---|
53 |
|
---|
54 | // Open GDBM database for querying
|
---|
55 | String gdbm_db_file = GSFile.GDBMDatabaseFile(this.site_home, this.cluster_name);
|
---|
56 | if (!this.gdbm_src.openDatabase(gdbm_db_file, GDBMWrapper.READER)) {
|
---|
57 | System.err.println("Error: Could not open GDBM database!");
|
---|
58 | return false;
|
---|
59 | }
|
---|
60 | return super.configure(info, extra_info);
|
---|
61 | }
|
---|
62 | /** returns the document type of the doc that the specified node
|
---|
63 | belongs to. should be one of
|
---|
64 | GSXML.DOC_TYPE_SIMPLE,
|
---|
65 | GSXML.DOC_TYPE_PAGED,
|
---|
66 | GSXML.DOC_TYPE_HIERARCHY
|
---|
67 | */
|
---|
68 | protected String getDocType(String node_id){
|
---|
69 | DBInfo info = this.gdbm_src.getInfo(node_id);
|
---|
70 | if (info == null) {
|
---|
71 | return GSXML.DOC_TYPE_SIMPLE;
|
---|
72 | }
|
---|
73 | String doc_type = info.getInfo("doctype");
|
---|
74 | if (!doc_type.equals("")&&!doc_type.equals("doc")) {
|
---|
75 | return doc_type;
|
---|
76 | }
|
---|
77 |
|
---|
78 | String top_id = OID.getTop(node_id);
|
---|
79 | boolean is_top = (top_id.equals(node_id) ? true : false);
|
---|
80 |
|
---|
81 | String children = info.getInfo("contains");
|
---|
82 | boolean is_leaf = (children.equals("") ? true : false);
|
---|
83 |
|
---|
84 | if (is_top && is_leaf) { // a single section document
|
---|
85 | return GSXML.DOC_TYPE_SIMPLE;
|
---|
86 | }
|
---|
87 |
|
---|
88 | // now we just check the top node
|
---|
89 | if (!is_top) { // we need to look at the top info
|
---|
90 | info = this.gdbm_src.getInfo(top_id);
|
---|
91 | }
|
---|
92 | if (info == null) {
|
---|
93 | return GSXML.DOC_TYPE_HIERARCHY;
|
---|
94 | }
|
---|
95 |
|
---|
96 | String childtype = info.getInfo("childtype");
|
---|
97 | if (childtype.equals("Paged")) {
|
---|
98 | return GSXML.DOC_TYPE_PAGED;
|
---|
99 | }
|
---|
100 | return GSXML.DOC_TYPE_HIERARCHY;
|
---|
101 |
|
---|
102 | }
|
---|
103 |
|
---|
104 | /** returns true if the node has child nodes */
|
---|
105 | protected boolean hasChildren(String node_id){
|
---|
106 | DBInfo info = this.gdbm_src.getInfo(node_id);
|
---|
107 | if (info == null) {
|
---|
108 | return false;
|
---|
109 | }
|
---|
110 | String contains = info.getInfo("contains");
|
---|
111 | if (contains.equals("")) {
|
---|
112 | return false;
|
---|
113 | }
|
---|
114 | return true;
|
---|
115 | }
|
---|
116 |
|
---|
117 | /** returns true if the node has a parent */
|
---|
118 | protected boolean hasParent(String node_id){
|
---|
119 | String parent = OID.getParent(node_id);
|
---|
120 | if (parent.equals(node_id)) {
|
---|
121 | return false;
|
---|
122 | }
|
---|
123 | return true;
|
---|
124 | }
|
---|
125 |
|
---|
126 | /** convert MG internal id to Greenstone oid */
|
---|
127 | protected String MGNum2OID(long docnum)
|
---|
128 | {
|
---|
129 | return this.gdbm_src.docnum2OID(docnum);
|
---|
130 |
|
---|
131 | }
|
---|
132 |
|
---|
133 | }
|
---|
134 |
|
---|
135 |
|
---|