source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/SimpleDocumentDatabase.java@ 24395

Last change on this file since 24395 was 24395, checked in by davidb, 13 years ago

Through the audioDB extension we now support a form of content-based audio/music searching. Existing Search services have been restructured to reflect this generalization in our Service inheritance hierarchy for searching. Basically, what used to be thought of as a search service implied a *text* search service. This batch of commits relate to supporting 'util' classes

File size: 4.5 KB
Line 
1/*
2 * SimpleDocumentDatabase.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.util;
19
20// Greenstone classes
21import org.greenstone.gsdl3.util.OID;
22import org.greenstone.gsdl3.util.DBInfo;
23import org.greenstone.gsdl3.util.GSXML;
24import org.greenstone.gsdl3.util.SimpleCollectionDatabase;
25import org.greenstone.gsdl3.util.GSFile;
26
27// XML classes
28import org.w3c.dom.Document;
29import org.w3c.dom.Element;
30import org.w3c.dom.NodeList;
31
32// java
33import java.util.Vector;
34import java.util.ArrayList;
35import java.util.HashMap;
36import java.util.Map;
37import java.util.Set;
38import java.util.Iterator;
39import java.io.File;
40
41import org.apache.log4j.*;
42
43public class SimpleDocumentDatabase extends AbstractSimpleDocument
44{
45 // collection database
46 protected SimpleCollectionDatabase coll_db = null;
47
48 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.SimpleDocumentDatabase.class.getName());
49
50
51 /** constructor */
52 public SimpleDocumentDatabase(Document doc,
53 String database_type, String site_home,
54 String cluster_name, String index_stem)
55 {
56 super(doc);
57
58 coll_db = new SimpleCollectionDatabase(database_type);
59 if (!coll_db.databaseOK()) {
60 logger.error("Couldn't create the collection database of type "+database_type);
61 }
62
63 // Open database for querying
64 String coll_db_file = GSFile.collectionDatabaseFile(site_home, cluster_name, index_stem, database_type);
65 if (!this.coll_db.openDatabase(coll_db_file, SimpleCollectionDatabase.READ)) {
66 logger.error("Could not open collection database!");
67 coll_db = null;
68 }
69 }
70
71 public boolean isValid()
72 {
73 return (coll_db != null);
74 }
75
76 public void cleanUp() {
77 this.coll_db.closeDatabase();
78 }
79
80
81 public DBInfo getInfo(String main_key) {
82 if (this.coll_db==null) {
83 // Most likely cause is that this installation of Greenstone3 has not
84 // been compiled with support for this database type
85 return null;
86 }
87
88 return coll_db.getInfo(main_key);
89 }
90
91
92 /** returns the document type of the doc that the specified node
93 belongs to. should be one of
94 GSXML.DOC_TYPE_SIMPLE,
95 GSXML.DOC_TYPE_PAGED,
96 GSXML.DOC_TYPE_HIERARCHY
97 */
98 public String getDocType(String node_id){
99 DBInfo info = this.coll_db.getInfo(node_id);
100 if (info == null) {
101 return GSXML.DOC_TYPE_SIMPLE;
102 }
103 String doc_type = info.getInfo("doctype");
104 if (!doc_type.equals("")&&!doc_type.equals("doc")) {
105 return doc_type;
106 }
107
108 String top_id = OID.getTop(node_id);
109 boolean is_top = (top_id.equals(node_id) ? true : false);
110
111 String children = info.getInfo("contains");
112 boolean is_leaf = (children.equals("") ? true : false);
113
114 if (is_top && is_leaf) { // a single section document
115 return GSXML.DOC_TYPE_SIMPLE;
116 }
117
118 // now we just check the top node
119 if (!is_top) { // we need to look at the top info
120 info = this.coll_db.getInfo(top_id);
121 }
122 if (info == null) {
123 return GSXML.DOC_TYPE_HIERARCHY;
124 }
125
126 String childtype = info.getInfo("childtype");
127 if (childtype.equals("Paged")) {
128 return GSXML.DOC_TYPE_PAGED;
129 }
130 return GSXML.DOC_TYPE_HIERARCHY;
131
132 }
133
134 /** returns true if the node has child nodes */
135 public boolean hasChildren(String node_id){
136 DBInfo info = this.coll_db.getInfo(node_id);
137 if (info == null) {
138 return false;
139 }
140 String contains = info.getInfo("contains");
141 if (contains.equals("")) {
142 return false;
143 }
144 return true;
145 }
146
147 /** returns true if the node has a parent */
148 public boolean hasParent(String node_id){
149 String parent = OID.getParent(node_id);
150 if (parent.equals(node_id)) {
151 return false;
152 }
153 return true;
154 }
155
156 /** convert indexer internal id to Greenstone oid */
157 public String internalNum2OID(long docnum)
158 {
159 return this.coll_db.docnum2OID(docnum);
160 }
161
162 public String internalNum2OID(String docnum)
163 {
164 return this.coll_db.docnum2OID(docnum);
165 }
166
167}
168
169
Note: See TracBrowser for help on using the repository browser.