source: trunk/gsdl3/src/java/org/greenstone/gsdl3/core/NZDLReceptionist.java@ 6677

Last change on this file since 6677 was 6677, checked in by nzdl, 20 years ago

now gets the query service description if on the about page

  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1package org.greenstone.gsdl3.core;
2
3import org.greenstone.gsdl3.util.*;
4import org.greenstone.gsdl3.action.*;
5// XML classes
6import org.w3c.dom.Node;
7import org.w3c.dom.NodeList;
8import org.w3c.dom.Document;
9import org.w3c.dom.Element;
10
11// other java classes
12import java.io.File;
13import java.util.HashMap;
14import java.util.Enumeration;
15
16/**
17 * This is a new version of the Receptionist for the NZDL interface
18 * the interface requires a lot more info for each page
19 * @see DefaultReceptionist
20 */
21public class NZDLReceptionist extends DefaultReceptionist {
22
23 protected void addExtraInfo(Element page) {
24 ///ystem.out.println("the page before adding extra info is");
25 ///ystem.out.println(this.converter.getPrettyString(page));
26
27 super.addExtraInfo(page);
28
29 // this gets the collection info
30 Element page_response = (Element)GSXML.getChildByTagName(page, GSXML.PAGE_RESPONSE_ELEM);
31 Element page_request = (Element)GSXML.getChildByTagName(page, GSXML.PAGE_REQUEST_ELEM);
32 Element collection_info = (Element)GSXML.getChildByTagName(page_response, GSXML.COLLECTION_ELEM);
33 if (collection_info== null) {
34 return;
35 }
36
37 String collection = collection_info.getAttribute("name"); // should we take this from the request instead??
38 // look through services and see if classifier one is present - need to
39 // get the list of classifiers
40 Element service_list = (Element)GSXML.getChildByTagName(collection_info, GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER);
41 if (service_list == null) {
42 // something weird has gone wrong
43 return;
44 }
45
46 Element info_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
47 String lang = page.getAttribute(GSXML.LANG_ATT);
48
49 boolean do_classifier = false;
50 boolean do_query = false;
51 Element classifier_service = GSXML.getNamedElement(service_list, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, "ClassifierBrowse");
52 Element query_service = GSXML.getNamedElement(service_list, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, "TextQuery");
53 if (classifier_service != null) {
54 do_classifier = true;
55 // find the list of classifiers
56
57 String to = GSPath.appendLink(collection, "ClassifierBrowse");
58 Element info_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, lang, "");
59 info_message.appendChild(info_request);
60 }
61
62 String action = page_request.getAttribute(GSXML.ACTION_ATT);
63 String subaction = page_request.getAttribute(GSXML.SUBACTION_ATT);
64
65 if (query_service != null && action.equals("p") && subaction.equals("about")) {
66 do_query = true;
67 // get the full description
68 String to = GSPath.appendLink(collection, "TextQuery");
69 Element query_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, lang, "");
70 info_message.appendChild(query_request);
71
72 }
73
74 Element info_resp_message = (Element) this.mr.process(info_message);
75 Element info_response = (Element) GSXML.getChildByTagName(info_resp_message, GSXML.RESPONSE_ELEM);
76 // String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.SERVICE_ELEM);
77 if (do_classifier) {
78 Element classifier_service_info = (Element)GSXML.getNamedElement(info_response, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, "CLassifierBrowse");
79 if (classifier_service_info != null) {
80 service_list.replaceChild(this.doc.importNode(classifier_service_info, true), classifier_service);
81 }
82 }
83 if (do_query) {
84 Element query_service_info = (Element)GSXML.getNamedElement(info_response, GSXML.SERVICE_ELEM, GSXML.NAME_ATT, "TextQuery");
85 if (query_service_info != null) {
86 service_list.replaceChild(this.doc.importNode(query_service_info, true), query_service);
87 }
88 }
89 ///ystem.out.println("the final page before transforming is");
90 ///ystem.out.println(this.converter.getPrettyString(page));
91 return;
92 }
93
94}
95
Note: See TracBrowser for help on using the repository browser.