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