source: trunk/gsdl3/src/java/org/greenstone/gsdl3/service/AbstractGS3DocumentRetrieve.java@ 9000

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

added indexStem info into configure

  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
Line 
1/*
2 * AbstractGS3DocumentRetrieve.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 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19package org.greenstone.gsdl3.service;
20
21// Greenstone classes
22import org.greenstone.gsdl3.util.GSXML;
23import org.greenstone.gsdl3.util.GSFile;
24import org.greenstone.gsdl3.util.GS3OID;
25import org.greenstone.gsdl3.util.MacroResolver;
26import org.greenstone.gsdl3.util.GS2MacroResolver;
27import org.greenstone.gsdl3.util.GSConstants;
28import org.greenstone.gsdl3.util.SQLQuery;
29
30// XML classes
31import org.w3c.dom.Document;
32import org.w3c.dom.Element;
33import org.w3c.dom.NodeList;
34
35// General Java classes
36import java.io.File;
37import java.util.StringTokenizer;
38import java.util.Vector;
39import java.util.Set;
40import java.util.Iterator;
41import java.util.ArrayList;
42
43/** Implements the generic retrieval and classifier services for GS3
44 * collections.
45 *
46 * @author <a href="mailto:[email protected]">Katherine Don</a>
47 * @author <a href="mailto:[email protected]">Michael Dewsnip</a>
48 */
49
50public abstract class AbstractGS3DocumentRetrieve
51 extends AbstractDocumentRetrieve {
52 protected static final String INDEX_STEM_ELEM = "indexStem";
53
54 protected SQLQuery database = null;
55 protected String index_stem = null;
56
57
58 /** constructor */
59 protected AbstractGS3DocumentRetrieve()
60 {
61 this.database = new SQLQuery();
62 // set up a macro resolver
63 }
64
65
66 /** configure this service */
67 public boolean configure(Element info, Element extra_info)
68 {
69
70 System.out.println("Configuring AbstractGS3DocumentRetrieve...");
71
72 // the index stem is either specified in the config file or is "index"
73 Element index_stem_elem = (Element) GSXML.getChildByTagName(info, INDEX_STEM_ELEM);
74 if (index_stem_elem != null) {
75 this.index_stem = index_stem_elem.getAttribute(GSXML.NAME_ATT);
76 }
77 if (this.index_stem == null || this.index_stem.equals("")) {
78 System.err.println("GS3MGRetrieve.configure(): indexStem element not found, stem will default to 'index'");
79 this.index_stem = "index";
80 }
81
82 // open the database for querying
83 // the database name is a combination of site name and collection name
84
85 // check that site_home is set
86 if (this.site_home == null || this.site_home.equals("")) {
87 System.err.println("GS3Retrieve Error: site_home is not set, so cannot work out the site name and cannot determine the database name");
88 return false;
89 }
90 String site_name = this.site_home.substring(this.site_home.lastIndexOf(File.separator)+1);
91 if (site_name.equals("")) {
92 System.err.println("GS3Retrieve Error: Cannot extract the site name from site home: "+this.site_home);
93 return false;
94 }
95
96 if (!database.setDatabase(site_name+"_"+this.cluster_name)) {
97 System.err.println("GS3Retrieve Error: Could not open SQL database!");
98 return false;
99 }
100
101 return super.configure(info, extra_info);
102
103 }
104
105 /** if id ends in .fc, .pc etc, then translate it to the correct id */
106 protected String translateId(String node_id) {
107 // should really use a sql query
108 return GS3OID.translateOID(node_id);
109 }
110
111 /** if an id is not a greenstone id (an external id) then translate
112 it to a greenstone one*/
113 protected String translateExternalId(String node_id){
114 // dont have this yet
115 return node_id;
116 }
117
118 /** returns the id of the root node of the document containing node node_id. . may be the same as node_id */
119 protected String getRootId(String node_id) {
120 return GS3OID.getTop(node_id);
121 }
122
123 /** returns a list of the child ids in order, null if no children */
124 protected ArrayList getChildrenIds(String node_id) {
125 System.err.println("get children ids for "+node_id);
126 if (GS3OID.isDocTop(node_id)) { // hack
127 node_id = GS3OID.createOID(node_id, "1");
128 }
129 System.err.println("new node id="+node_id);
130 ArrayList documents = database.getDocumentChildren(node_id);
131 if (documents == null || documents.size()==0) {
132 return null;
133 }
134 return documents;
135 }
136
137 /** returns the node id of the parent node, null if no parent */
138 protected String getParentId(String node_id){
139 String parent = GS3OID.getParent(node_id);
140 if (parent.equals(node_id)) {
141 return null;
142 }
143 return parent;
144 }
145
146 /** get the metadata for the classifier node node_id
147 * returns a metadataList element:
148 * <metadataList><metadata name="xxx">value</metadata></metadataList>
149 */
150 // assumes only one value per metadata
151 protected Element getMetadataList(String node_id, boolean all_metadata,
152 ArrayList metadata_names) {
153 Element metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
154
155 if (all_metadata) {
156 // TODO
157
158
159 } else {
160 for (int m = 0; m < metadata_names.size(); m++) {
161 String metadata = (String) metadata_names.get(m);
162 String value = null;
163 value = database.getDocumentMetadata(node_id, metadata);
164 if (value != null) {
165 System.out.println("found value "+value);
166 GSXML.addMetadata(this.doc, metadata_list, metadata, value);
167 }
168 }
169 }
170
171 return metadata_list;
172 }
173
174 /** returns the structural information asked for.
175 * info_type may be one of
176 * INFO_NUM_SIBS, INFO_NUM_CHILDREN, INFO_SIB_POS
177 */
178 protected String getStructureInfo(String doc_id, String info_type) {
179 return null; // not implemented yet
180 }
181
182
183 /** returns the document type of the doc that the specified node
184 belongs to. should be one of
185 GSXML.DOC_TYPE_SIMPLE,
186 GSXML.DOC_TYPE_PAGED,
187 GSXML.DOC_TYPE_HIERARCHY
188 */
189 protected String getDocType(String node_id) {
190 boolean hierarchical = false;
191 if (!GS3OID.isDocTop(node_id) || database.isHierarchicalDocument(node_id) ) {
192 hierarchical = true;
193 }
194 // what about paged???
195 if (!hierarchical) {
196 // a simple document
197 return GSXML.DOC_TYPE_SIMPLE;
198 } else {
199 // a hierarchical doc
200 return GSXML.DOC_TYPE_HIERARCHY;
201 }
202 // don't have paged yet.
203 }
204
205 protected String resolveRelativeLinks(String doc_content, String doc_id) {
206
207 String http_path = this.site_http_address + "/collect/"+this.cluster_name;
208 doc_content = doc_content.replaceAll("_httpcollection_", http_path);
209 return doc_content;
210
211 }
212
213 /** returns the content of a node
214 * should return a nodeContent element:
215 * <nodeContent>text content or other elements</nodeContent>
216 */
217 abstract protected Element getNodeContent(String doc_id);
218
219}
Note: See TracBrowser for help on using the repository browser.