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

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

ServiceModule renamed to ServicesImpl, each class renamed to xxxServices eg
MGPPGDBMService --> MGPPGDBMServices, cos its a collection of services :-)

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