source: trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2Browse.java@ 3649

Last change on this file since 3649 was 3649, checked in by kjdon, 21 years ago

tidy up of services. MGPPGDBMServices replaced with GS2MGPPSearch and GS2MGPPRetrieve. MGGDBMServices replaced with GS2MGSearch and GS2MGRetrieve. GSDL2ClassifierServices replaced with GS2Browse. PerlBuildServices replaced with GS2Construct. ServicesImpl replaced with ServiceRack.

  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 KB
Line 
1/*
2 * GS2Browse.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
21import org.greenstone.gdbm.*;
22import org.greenstone.gsdl3.util.*;
23
24import org.w3c.dom.Document;
25import org.w3c.dom.Node;
26import org.w3c.dom.Text;
27import org.w3c.dom.Element;
28import org.w3c.dom.NodeList;
29/**
30 * A ServicesImpl class for GSDL2-style Classifiers
31 *
32 * @author <a href="mailto:[email protected]">Katherine Don</a>
33 * @version $Revision: 3649 $
34 */
35public class GS2Browse
36 extends ServiceRack {
37
38 // the services on offer
39 private static final String CLASSIFIER_SERVICE = "ClassifierBrowse";
40
41 /** gdbm wrapper */
42 private GDBMWrapper gdbm_src_=null;
43
44 public GS2Browse() {
45 gdbm_src_ = new GDBMWrapper();
46
47 }
48
49 /** creates a display element containing all the text strings needed to display the service page, in the language specified */
50 protected Element createServiceDisplay(String service, String lang) {
51 Element display = doc_.createElement(GSXML.DISPLAY_ELEM);
52 display.appendChild(GSXML.createTextElement(doc_, GSXML.DISPLAY_NAME_ELEM, getTextString(service+".name", lang)));
53 display.appendChild(GSXML.createTextElement(doc_, GSXML.DISPLAY_SUBMIT_ELEM, getTextString(service+".submit", lang)));
54
55 Element param;
56
57 return display;
58
59 }
60
61 /** processes the request */
62 protected Element processClassifierBrowse(Element request) {
63
64 // the response element
65 Element result = doc_.createElement(GSXML.RESPONSE_ELEM);
66 String from = GSPath.appendLink(cluster_name_, CLASSIFIER_SERVICE);
67 result.setAttribute(GSXML.FROM_ATT, from);
68 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY);
69 Element result_content = doc_.createElement(GSXML.CONTENT_ELEM);
70 result.appendChild(result_content);
71
72 // get the classifier name out of request content - assume only one for now
73 String path = GSXML.CONTENT_ELEM;
74 path = GSPath.appendLink(path, GSXML.DOCUMENT_ELEM+GSXML.LIST_MODIFIER);
75 path = GSPath.appendLink(path, GSXML.DOCUMENT_ELEM);
76
77 Element elem = (Element)GSXML.getNodeByPath(request, path);
78 String elem_name = elem.getAttribute(GSXML.NAME_ATT);
79
80 if (OID.needsTranslating(elem_name)) {
81 elem_name = gdbm_src_.translateOID(elem_name);
82 }
83 // get the info from gdbm db
84 DBInfo info = gdbm_src_.getInfo(elem_name);
85
86 // build up the XML
87 Element classifier = doc_.createElement(GSXML.CLASSIFIER_ELEM);
88
89 String classifier_name = OID.getTop(elem_name);
90 classifier.setAttribute(GSXML.NAME_ATT, classifier_name);
91 result_content.appendChild(classifier);
92 DBInfo top_info;
93
94 if (elem_name.equals(classifier_name)) {
95 top_info = info;
96 } else {
97 top_info = gdbm_src_.getInfo(classifier_name);
98 }
99
100 // a substitute template - should be read from config file
101 //String extra = "<stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template match='document' priority='3'><xsl:param name='collName'>coll-name</xsl:param><xsl:variable name='library' select='ancestor::page/config/library_name'/><td><a href='{$library}?a=r&amp;c={$collName}&amp;r={@name}'><img src='interfaces/default/images/book.gif' width='18' height='11' border='0'/></a></td><td>***</td><td><xsl:value-of select='metadataList/metadata[@name=\"Title\"]'/></td></xsl:template></stylesheet>";
102 //Element extra_doc = converter_.getDOM(extra).getDocumentElement();
103 //result.appendChild(doc_.importNode(extra_doc, true));
104
105 // get the classifier attributes
106 String type = top_info.getInfo("childtype");
107 if (type.equals("VList")) {
108
109 classifier.setAttribute("type", "vertical");
110 classifier.setAttribute("interleave", "true");
111 classifier.setAttribute("link", "icon");
112 }
113 else if (type.equals("HList")){
114 classifier.setAttribute("type", "horizontal");
115 classifier.setAttribute("interleave", "false");
116 classifier.setAttribute("link", "name");
117 } else {
118 System.out.println("unknown type!!! check this");
119 classifier.setAttribute("type", "vertical");
120 classifier.setAttribute("interleave", "true");
121 classifier.setAttribute("link", "icon");
122 }
123
124 Element this_node;
125 if (elem_name.equals(classifier_name)) {
126 this_node = classifier;
127 } else { // have to build up the parents
128 // the current node
129 this_node = doc_.createElement("node");
130 this_node.setAttribute("name", elem_name);
131 type = info.getInfo("childtype");
132 if (type.equals("VList")) {
133 this_node.setAttribute("type", "vertical");
134 } else {
135 this_node.setAttribute("type", "horzizontal");
136 }
137 String title = info.getInfo("Title");
138 Element meta_list = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
139 GSXML.addMetadata(doc_, meta_list, "Title", title);
140 this_node.appendChild(meta_list);
141
142 // the parents
143 String middle_name = OID.getParent(elem_name);
144 Element middle_node = this_node;
145 while (!middle_name.equals(classifier_name)) {
146 // add in a new node
147 Element temp_node = doc_.createElement("node");
148 temp_node.setAttribute("name", middle_name);
149
150 DBInfo i = gdbm_src_.getInfo(middle_name);
151 type = i.getInfo("childtype");
152 if (type.equals("VList")) {
153 temp_node.setAttribute("type", "vertical");
154 } else {
155 temp_node.setAttribute("type", "horzizontal");
156 }
157 title = i.getInfo("Title");
158 meta_list = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
159 GSXML.addMetadata(doc_, meta_list, "Title", title);
160 temp_node.appendChild(meta_list);
161
162 // link into the tree
163 temp_node.appendChild(middle_node);
164 middle_node = temp_node;
165 middle_name = OID.getParent(middle_name);
166 }
167 classifier.appendChild(middle_node);
168 }
169 // get the child nodes
170 String contains = info.getInfo("contains");
171 // replace the " with parent name
172 contains = OID.translateParent(contains, elem_name);
173 String [] children = contains.split(";");
174 for (int i=0; i<children.length; i++) {
175 String child = children[i];
176 DBInfo child_info = gdbm_src_.getInfo(child);
177 String title = child_info.getInfo("Title");
178 Element node;
179 // should have a type here, not rely on HASH ids
180 if (child.startsWith("HASH")) {
181 // a document
182 node = doc_.createElement(GSXML.DOCUMENT_ELEM);
183 } else { // a node in the classification
184 node = doc_.createElement("node");
185
186 }
187
188 node.setAttribute(GSXML.NAME_ATT, child);
189 Element meta_list = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
190 GSXML.addMetadata(doc_, meta_list, "Title", title);
191 node.appendChild(meta_list);
192 this_node.appendChild(node);
193
194 }
195
196 return result;
197
198 }
199
200
201 /** configure this service */
202 public boolean configure(Element info) {
203
204 System.out.println("configuring GS2Browse");
205
206 Element e = null;
207 // these entries should reflect the build config file - some services may not be available depending on how the colleciton was built.
208 // set up short_service_info_ - for now just has name and type
209 e = doc_.createElement(GSXML.SERVICE_ELEM);
210 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
211 e.setAttribute(GSXML.NAME_ATT, CLASSIFIER_SERVICE);
212 short_service_info_.appendChild(e);
213
214 // set up service_info_map_ - for now, just has the same elements as above
215 // should have full details about each service incl params lists etc.
216 e = doc_.createElement(GSXML.SERVICE_ELEM);
217 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
218 e.setAttribute(GSXML.NAME_ATT, CLASSIFIER_SERVICE);
219
220 // get the classifier list out of the service info
221 Node classList = GSXML.getChildByTagName(info, GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER);
222 e.appendChild(doc_.importNode(classList, true));
223
224 service_info_map_.put(CLASSIFIER_SERVICE, e);
225
226 if (gdbm_src_.openDatabase(GSFile.GDBMDatabaseFile(site_home_, cluster_name_), GDBMWrapper.READER)) {
227 return true;
228 }
229 else {
230 System.err.println("couldn't open gdbm database!");
231 return false;
232 }
233
234 }
235
236
237}
238
239
Note: See TracBrowser for help on using the repository browser.