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

Last change on this file since 13270 was 13270, checked in by shaoqun, 17 years ago

replace Category class which is deprecated with Logger class

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