source: trunk/greenstone3-extensions/gs3build/src/org/greenstone/gsdl3/service/GS3MGPPSearch.java@ 13242

Last change on this file since 13242 was 12188, checked in by kjdon, 18 years ago

Initial revision

  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
1/*
2 * GS3MGPPSearch.java
3 * Copyright (C) 2005 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// Greenstone classes
21import org.greenstone.mg.*;
22import org.greenstone.gsdl3.util.GSXML;
23import org.greenstone.gsdl3.util.GS3OID;
24import org.greenstone.gsdl3.util.SQLQuery;
25
26// XML classes
27import org.w3c.dom.Document;
28import org.w3c.dom.Element;
29import org.w3c.dom.NodeList;
30
31// java classes
32import java.io.File;
33
34
35/**
36 *
37 * @author <a href="mailto:[email protected]">Katherine Don</a>
38 */
39
40public class GS3MGPPSearch
41 extends AbstractMGPPSearch
42{
43 protected SQLQuery database = null;
44 /** the base index prefix */
45 protected String base_index_prefix = null;
46
47
48 /** constructor */
49 public GS3MGPPSearch()
50 {
51 this.database = new SQLQuery();
52 }
53
54 public void cleanUp() {
55 super.cleanUp();
56 this.database.closeConnection();
57 }
58
59 /** configure this service */
60 public boolean configure(Element info, Element extra_info)
61 {
62 if (!super.configure(info, extra_info)){
63 return false;
64 }
65
66 // get the base prefix
67 Element def = (Element) GSXML.getChildByTagName(info, "baseIndexPrefix");
68 if (def != null) {
69 this.base_index_prefix = def.getAttribute(GSXML.NAME_ATT);
70 }
71 if (this.base_index_prefix == null || this.base_index_prefix.equals("")) {
72 System.err.println("Error: base index prefix not specified!");
73 return false;
74 }
75 String site_name = this.site_home.substring(this.site_home.lastIndexOf(File.separator)+1);
76 if (site_name.equals("")) {
77 System.err.println("GS3Search Error: Cannot extract the site name from site home: "+this.site_home);
78 return false;
79 }
80 if (!database.setDatabase(site_name+"_"+this.cluster_name)) {
81 System.err.println("GS3Search Error: Could not open SQL database!");
82 return false;
83 }
84
85 return true;
86 }
87 /** returns the document type of the doc that the specified node
88 belongs to. should be one of
89 GSXML.DOC_TYPE_SIMPLE,
90 GSXML.DOC_TYPE_PAGED,
91 GSXML.DOC_TYPE_HIERARCHY
92 */
93 protected String getDocType(String node_id){
94 boolean hierarchical = false;
95 if (!GS3OID.isDocTop(node_id) || database.isHierarchicalDocument(node_id) ) {
96 hierarchical = true;
97 }
98 // what about paged???
99 if (!hierarchical) {
100 // a simple document
101 return GSXML.DOC_TYPE_SIMPLE;
102 } else {
103 // a hierarchical doc
104 return GSXML.DOC_TYPE_HIERARCHY;
105 }
106 // don't have paged yet.
107
108 }
109
110 /** returns true if the node has child nodes */
111 protected boolean hasChildren(String node_id){
112 return database.documentHasChildren(node_id);
113 }
114
115 /** returns true if the node has a parent */
116 protected boolean hasParent(String node_id){
117 String parent = GS3OID.getParent(node_id);
118 if (parent.equals(node_id)) {
119 return false;
120 }
121 return true;
122 }
123
124 /** convert MGPP internal id to Greenstone oid */
125 protected String MGPPNum2OID(long docnum)
126 {
127 String mg_id = this.base_index_prefix+"."+docnum;
128 String doc_id = database.MGNum2OID(mg_id);
129 // hack !!!
130 if (doc_id.endsWith("-All")) {
131 // get rid of the All bit
132 doc_id = doc_id.substring(0,doc_id.length()-4);
133 //doc_id=doc_id.replaceAll("All","1");
134 }
135 return doc_id;
136
137 }
138
139}
140
141
Note: See TracBrowser for help on using the repository browser.