source: trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3Browse.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: 5.7 KB
Line 
1/*
2 * GS3Browse.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 * 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.GS3OID;
23import org.greenstone.gsdl3.util.GSXML;
24import org.greenstone.gsdl3.util.GSFile;
25import org.greenstone.gsdl3.util.SQLQuery;
26
27// XML classes
28import org.w3c.dom.Document;
29import org.w3c.dom.Element;
30import org.w3c.dom.NodeList;
31
32// General Java classes
33import java.util.ArrayList;
34import java.util.StringTokenizer;
35import java.io.File;
36
37/** Greenstone 3 collection classifier service
38 *
39 * @author <a href="mailto:[email protected]">Katherine Don</a>
40 */
41public class GS3Browse
42 extends AbstractBrowse
43{
44
45 protected SQLQuery database = null;
46
47 /** constructor */
48 public GS3Browse()
49 {
50 this.database = new SQLQuery();
51
52 }
53
54 public void cleanUp() {
55 super.cleanUp();
56 this.database.closeConnection();
57 }
58
59 public boolean configure(Element info, Element extra_info)
60 {
61 System.err.println("Configuring GS3Browse...");
62
63 // open the database for querying
64 // the database name is a combination of site name and collection name
65
66 // check that site_home is set
67 if (this.site_home == null || this.site_home.equals("")) {
68 System.err.println("GS3Retrieve Error: site_home is not set, so cannot work out the site name and cannot determine the database name");
69 return false;
70 }
71 String site_name = this.site_home.substring(this.site_home.lastIndexOf(File.separator)+1);
72 if (site_name.equals("")) {
73 System.err.println("GS3Retrieve Error: Cannot extract the site name from site home: "+this.site_home);
74 return false;
75 }
76 if (!database.setDatabase(site_name+"_"+this.cluster_name)) {
77 System.err.println("GS3Retrieve Error: Could not open SQL database!");
78 return false;
79 }
80
81 // generic configure
82 return super.configure(info, extra_info);
83 }
84
85 /** if id ends in .fc, .pc etc, then translate it to the correct id */
86 protected String translateId(String node_id) {
87 // should really use a sql query
88 return GS3OID.translateOID(node_id);
89 }
90
91 /** returns the document type of the doc that the specified node
92 belongs to. should be one of
93 GSXML.DOC_TYPE_SIMPLE,
94 GSXML.DOC_TYPE_PAGED,
95 GSXML.DOC_TYPE_HIERARCHY
96 */
97 protected String getDocType(String node_id) {
98 boolean hierarchical = false;
99 if (!GS3OID.isDocTop(node_id) || database.isHierarchicalDocument(node_id) ) {
100 hierarchical = true;
101 }
102 // what about paged???
103 if (!hierarchical) {
104 // a simple document
105 return GSXML.DOC_TYPE_SIMPLE;
106 } else {
107 // a hierarchical doc
108 return GSXML.DOC_TYPE_HIERARCHY;
109 }
110 // don't have paged yet.
111 }
112
113 /** returns the id of the root node of the document containing node
114 * node_id. . may be the same as node_id */
115 protected String getRootId(String node_id) {
116 return GS3OID.getDocID(node_id);
117 }
118
119 /** returns a list of the child ids in order, null if no children */
120 protected ArrayList getChildrenIds(String node_id) {
121 ArrayList documents = database.getClassifierDocChildren(node_id);
122 if (documents == null) {
123 documents = new ArrayList();
124 }
125 ArrayList children = database.getClassifierChildren(node_id);
126 if (children != null) {
127 documents.addAll(children);
128 }
129 if (documents.size()==0) {
130 return null;
131 }
132 return documents;
133 }
134
135 /** returns the node id of the parent node, null if no parent */
136 protected String getParentId(String node_id){
137 String parent = GS3OID.getParent(node_id);
138 if (parent.equals(node_id)) {
139 return null;
140 }
141 return parent;
142 }
143
144 /** get the metadata for the classifier node node_id
145 * returns a metadataList element:
146 * <metadataList><metadata name="xxx">value</metadata></metadataList>
147 * if all_metadata is true, returns all available metadata, otherwise just
148 * returns requested metadata
149 */
150 // assumes only one value per metadata
151 protected Element getMetadataList(String node_id, boolean all_metadata, ArrayList metadata_names) {
152 Element metadata_list = this.doc.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
153
154 if (all_metadata) {
155 // TODO
156
157
158 } else {
159 for (int m = 0; m < metadata_names.size(); m++) {
160 String metadata = (String) metadata_names.get(m);
161 String value = null;
162 value = database.getClassifierMetadata(node_id, metadata);
163 if (value != null) {
164 System.out.println("found value "+value);
165 GSXML.addMetadata(this.doc, metadata_list, metadata, value);
166 }
167 }
168 }
169
170 return metadata_list;
171 }
172
173 /** returns the structural information asked for.
174 * info_type may be one of
175 * INFO_NUM_SIBS, INFO_NUM_CHILDREN, INFO_SIB_POS
176 */
177 protected String getStructureInfo(String doc_id, String info_type) {
178 return null;
179 }
180
181 /** returns true if the id refers to a document (rather than
182 * a classifier node)
183 */
184 protected boolean isDocumentId(String node_id){
185 if (node_id.startsWith("CL")) {
186 return false;
187 }
188 return true;
189 }
190
191}
Note: See TracBrowser for help on using the repository browser.