source: trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GSDL2ClassifierServices.java@ 3512

Last change on this file since 3512 was 3512, checked in by kjdon, 22 years ago

all modules now talk the same messages; all xml elems and atts have been made constants and moved to GSXML.java; SOAPCommunicator can be used outside a MessageRouter

  • Property svn:keywords set to Author Date Id Revision
File size: 8.3 KB
Line 
1/*
2 * GSDL2ClassifierServices.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: 3512 $
34 */
35public class GSDL2ClassifierServices
36 extends ServicesImpl {
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 GSDL2ClassifierServices() {
45 gdbm_src_ = new GDBMWrapper();
46
47 }
48
49 /** processes the request */
50 protected Element processService(String name, Element request) {
51
52 if (!name.equals(CLASSIFIER_SERVICE)) {
53 System.err.println("GSDL2ClassifierServices:should never get here. service type wrong:"+name);
54 return null;
55 }
56 // the response element
57 Element result = doc_.createElement(GSXML.RESPONSE_ELEM);
58 String from = GSPath.appendLink(cluster_name_, CLASSIFIER_SERVICE);
59 result.setAttribute(GSXML.FROM_ATT, from);
60 result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_QUERY);
61 Element result_content = doc_.createElement(GSXML.CONTENT_ELEM);
62 result.appendChild(result_content);
63
64 // get the classifier name out of request content - assume only one for now
65 String path = GSXML.CONTENT_ELEM;
66 path = GSPath.appendLink(path, GSXML.RESOURCE_ELEM+GSXML.LIST_MODIFIER);
67 path = GSPath.appendLink(path, GSXML.RESOURCE_ELEM);
68
69 Element elem = (Element)GSXML.getNodeByPath(request, path);
70 String elem_name = elem.getAttribute(GSXML.NAME_ATT);
71 System.out.println("elem name="+elem_name);
72
73 if (OID.needsTranslating(elem_name)) {
74 System.out.println("translating oid");
75 elem_name = gdbm_src_.translateOID(elem_name);
76 }
77 // get the info from gdbm db
78 DBInfo info = gdbm_src_.getInfo(elem_name);
79
80 // build up the XML
81 Element classifier = doc_.createElement(GSXML.CLASSIFIER_ELEM);
82
83 String classifier_name = OID.getTop(elem_name);
84 classifier.setAttribute(GSXML.NAME_ATT, classifier_name);
85 result_content.appendChild(classifier);
86 DBInfo top_info;
87
88 if (elem_name.equals(classifier_name)) {
89 top_info = info;
90 } else {
91 top_info = gdbm_src_.getInfo(classifier_name);
92 }
93
94 // a substitute template - should be read from config file
95 //String extra = "<stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'><xsl:template match='resource' 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>";
96 //Element extra_doc = converter_.getDOM(extra).getDocumentElement();
97 //result.appendChild(doc_.importNode(extra_doc, true));
98
99 // get the classifier attributes
100 String type = top_info.getInfo("childtype");
101 if (type.equals("VList")) {
102
103 classifier.setAttribute("type", "vertical");
104 classifier.setAttribute("interleave", "true");
105 classifier.setAttribute("link", "icon");
106 }
107 else if (type.equals("HList")){
108 classifier.setAttribute("type", "horizontal");
109 classifier.setAttribute("interleave", "false");
110 classifier.setAttribute("link", "name");
111 } else {
112 System.out.println("unknown type!!! check this");
113 classifier.setAttribute("type", "vertical");
114 classifier.setAttribute("interleave", "true");
115 classifier.setAttribute("link", "icon");
116 }
117
118 Element this_node;
119 if (elem_name.equals(classifier_name)) {
120 this_node = classifier;
121 } else { // have to build up the parents
122 // the current node
123 this_node = doc_.createElement("node");
124 this_node.setAttribute("name", elem_name);
125 type = info.getInfo("childtype");
126 if (type.equals("VList")) {
127 this_node.setAttribute("type", "vertical");
128 } else {
129 this_node.setAttribute("type", "horzizontal");
130 }
131 String title = info.getInfo("Title");
132 Element meta_list = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
133 GSXML.addMetadata(doc_, meta_list, "Title", title);
134 this_node.appendChild(meta_list);
135
136 System.out.println("classifier_name="+classifier_name);
137 System.out.println("this name="+elem_name);
138 // the parents
139 String middle_name = OID.getParent(elem_name);
140 Element middle_node = this_node;
141 while (!middle_name.equals(classifier_name)) {
142 System.out.println("middle_name="+middle_name);
143 // add in a new node
144 Element temp_node = doc_.createElement("node");
145 temp_node.setAttribute("name", middle_name);
146
147 DBInfo i = gdbm_src_.getInfo(middle_name);
148 type = i.getInfo("childtype");
149 if (type.equals("VList")) {
150 temp_node.setAttribute("type", "vertical");
151 } else {
152 temp_node.setAttribute("type", "horzizontal");
153 }
154 title = i.getInfo("Title");
155 meta_list = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
156 GSXML.addMetadata(doc_, meta_list, "Title", title);
157 temp_node.appendChild(meta_list);
158
159 // link into the tree
160 temp_node.appendChild(middle_node);
161 middle_node = temp_node;
162 middle_name = OID.getParent(middle_name);
163 }
164 classifier.appendChild(middle_node);
165 }
166 // get the child nodes
167 String contains = info.getInfo("contains");
168 // replace the " with parent name
169 contains = OID.translateParent(contains, elem_name);
170 String [] children = contains.split(";");
171 for (int i=0; i<children.length; i++) {
172 String child = children[i];
173 DBInfo child_info = gdbm_src_.getInfo(child);
174 String title = child_info.getInfo("Title");
175 Element node;
176 if (child.startsWith("HASH")) {
177 // a resource
178 node = doc_.createElement(GSXML.RESOURCE_ELEM);
179 } else { // a node in the classification
180 node = doc_.createElement("node");
181
182 }
183
184 node.setAttribute(GSXML.NAME_ATT, child);
185 Element meta_list = doc_.createElement(GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
186 GSXML.addMetadata(doc_, meta_list, "Title", title);
187 node.appendChild(meta_list);
188 this_node.appendChild(node);
189
190 }
191
192 return result;
193
194 }
195
196
197 /** configure this service */
198 public boolean configure(Element info) {
199
200 System.out.println("configuring GSDL2ClassifierServices");
201
202 Element e = null;
203 // these entries should reflect the build config file - some services may not be available depending on how the colleciton was built.
204 // set up short_service_info_ - for now just has name and type
205 e = doc_.createElement(GSXML.SERVICE_ELEM);
206 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
207 e.setAttribute(GSXML.NAME_ATT, CLASSIFIER_SERVICE);
208 short_service_info_.appendChild(e);
209
210 // set up service_info_map_ - for now, just has the same elements as above
211 // should have full details about each service incl params lists etc.
212 e = doc_.createElement(GSXML.SERVICE_ELEM);
213 e.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_QUERY);
214 e.setAttribute(GSXML.NAME_ATT, CLASSIFIER_SERVICE);
215
216 // get the classifier list out of the service info
217 Node classList = GSXML.getChildByTagName(info, GSXML.CLASSIFIER_ELEM+GSXML.LIST_MODIFIER);
218 e.appendChild(doc_.importNode(classList, true));
219
220 service_info_map_.put(CLASSIFIER_SERVICE, e);
221
222 if (gdbm_src_.openDatabase(GSFile.GDBMDatabaseFile(site_home_, cluster_name_), GDBMWrapper.READER)) {
223 return true;
224 }
225 else {
226 System.err.println("couldn't open gdbm database!");
227 return false;
228 }
229
230 }
231
232
233}
234
235
Note: See TracBrowser for help on using the repository browser.