source: trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3MGPPSearch.java@ 9874

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

merged from branch ant-install-branch: merge 1

  • 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
63 // get the base prefix
64 Element def = (Element) GSXML.getChildByTagName(info, "baseIndexPrefix");
65 if (def != null) {
66 this.base_index_prefix = def.getAttribute(GSXML.NAME_ATT);
67 }
68 if (this.base_index_prefix == null || this.base_index_prefix.equals("")) {
69 System.err.println("Error: base index prefix not specified!");
70 return false;
71 }
72 String site_name = this.site_home.substring(this.site_home.lastIndexOf(File.separator)+1);
73 if (site_name.equals("")) {
74 System.err.println("GS3Search Error: Cannot extract the site name from site home: "+this.site_home);
75 return false;
76 }
77 if (!database.setDatabase(site_name+"_"+this.cluster_name)) {
78 System.err.println("GS3Search Error: Could not open SQL database!");
79 return false;
80 }
81
82 return super.configure(info, extra_info);
83 }
84 /** returns the document type of the doc that the specified node
85 belongs to. should be one of
86 GSXML.DOC_TYPE_SIMPLE,
87 GSXML.DOC_TYPE_PAGED,
88 GSXML.DOC_TYPE_HIERARCHY
89 */
90 protected String getDocType(String node_id){
91 boolean hierarchical = false;
92 if (!GS3OID.isDocTop(node_id) || database.isHierarchicalDocument(node_id) ) {
93 hierarchical = true;
94 }
95 // what about paged???
96 if (!hierarchical) {
97 // a simple document
98 return GSXML.DOC_TYPE_SIMPLE;
99 } else {
100 // a hierarchical doc
101 return GSXML.DOC_TYPE_HIERARCHY;
102 }
103 // don't have paged yet.
104
105 }
106
107 /** returns true if the node has child nodes */
108 protected boolean hasChildren(String node_id){
109 return database.documentHasChildren(node_id);
110 }
111
112 /** returns true if the node has a parent */
113 protected boolean hasParent(String node_id){
114 String parent = GS3OID.getParent(node_id);
115 if (parent.equals(node_id)) {
116 return false;
117 }
118 return true;
119 }
120
121 /** convert MGPP internal id to Greenstone oid */
122 protected String MGPPNum2OID(long docnum)
123 {
124 String mg_id = this.base_index_prefix+"."+docnum;
125 String doc_id = database.MGNum2OID(mg_id);
126 // hack !!!
127 if (doc_id.endsWith("-All")) {
128 // get rid of the All bit
129 doc_id = doc_id.substring(0,doc_id.length()-4);
130 //doc_id=doc_id.replaceAll("All","1");
131 }
132 return doc_id;
133
134 }
135
136}
137
138
Note: See TracBrowser for help on using the repository browser.