source: trunk/gsdl3/src/java/org/greenstone/gsdl3/core/DefaultReceptionist.java@ 7825

Last change on this file since 7825 was 7825, checked in by kjdon, 20 years ago

describe subset param displayItem should be displayItemList to be consistent

  • Property svn:keywords set to Author Date Id Revision
File size: 6.1 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/** The default greenstone receptionist - needs some extra info for each page
17 */
18public class DefaultReceptionist extends TransformingReceptionist {
19
20 protected void addExtraInfo(Element page) {
21 // we want to add in the collection description for each page - cos
22 // our default xslt needs this.
23 super.addExtraInfo(page);
24
25 Element page_request = (Element)GSXML.getChildByTagName(page, GSXML.PAGE_REQUEST_ELEM);
26 ///ystem.out.println("add extra info, page request="+this.converter.getString(page_request));
27 // is a collection defined?
28 Element param_list = (Element)GSXML.getChildByTagName(page_request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
29 if (param_list==null) { // must be the original home page
30 ///ystem.out.println("DefaultReceptionist: no param list, assuming home page");
31 return;
32 }
33 Element coll_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GSParams.COLLECTION);
34 if (coll_param == null) {
35 ///ystem.out.println("DefaultReceptionist: coll param is null, returning");
36 return;
37 }
38
39 // see if the collection/cluster element is already there
40 String coll_name = coll_param.getAttribute(GSXML.VALUE_ATT);
41 String lang = page_request.getAttribute(GSXML.LANG_ATT);
42 String uid = page_request.getAttribute(GSXML.USER_ID_ATT);
43
44 boolean get_service_description = false;
45 Element page_response = (Element)GSXML.getChildByTagName(page, GSXML.PAGE_RESPONSE_ELEM);
46 if (this.language_list != null) {
47 page_response.appendChild(this.language_list);
48 }
49 Element coll_description = (Element)GSXML.getChildByTagName(page_response, GSXML.COLLECTION_ELEM);
50 if (coll_description == null) {
51 // try cluster
52 coll_description = (Element)GSXML.getChildByTagName(page_response, GSXML.CLUSTER_ELEM);
53 }
54 if (coll_description == null) {
55 // we dont have one yet - get it
56 Element coll_about_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
57 Element coll_about_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, coll_name, lang, uid);
58 coll_about_message.appendChild(coll_about_request);
59
60 Element coll_about_response_message = this.mr.process(coll_about_message);
61 Element coll_about_response = (Element)GSXML.getChildByTagName(coll_about_response_message, GSXML.RESPONSE_ELEM);
62 coll_description = (Element)GSXML.getChildByTagName(coll_about_response, GSXML.COLLECTION_ELEM);
63 if (coll_description==null) { // may be a cluster
64 coll_description = (Element)GSXML.getChildByTagName(coll_about_response, GSXML.CLUSTER_ELEM);
65 }
66
67 if (coll_description == null) {
68 System.err.println("DefaultReceptionist: no collection description, returning");
69 return;
70 }
71 // have found one, append it to the page response
72 coll_description = (Element)this.doc.importNode(coll_description, true);
73 page_response.appendChild(coll_description);
74 get_service_description = true;
75 }
76
77 // have got a coll description
78
79 // now get the dispay info for the services
80 Element service_list = (Element)GSXML.getChildByTagName(coll_description, GSXML.SERVICE_ELEM+GSXML.LIST_MODIFIER);
81 if (service_list == null) {
82 System.err.println("DefaultReceptionist: no service list, returning");
83 // something weird has gone wrong
84 return;
85 }
86
87 NodeList services = service_list.getElementsByTagName(GSXML.SERVICE_ELEM);
88 if (services.getLength()==0) {
89 System.err.println("DefaultReceoptionist: no services found for colllection/cluster "+ coll_name);
90 return;
91 }
92 // check one service for display items
93 if (!get_service_description) {
94 // we dont know yet if we need to get these
95 int i=1;
96 Element test_s = (Element)services.item(0);
97 while (i<services.getLength() && test_s.getAttribute(GSXML.TYPE_ATT).equals(GSXML.SERVICE_TYPE_RETRIEVE)) {
98 test_s = (Element)services.item(i); i++;
99 }
100 if (i==services.getLength()) {
101 // we have only found retrieve services, so dont need descripitons anyway
102 return;
103 }
104 if (GSXML.getChildByTagName(test_s, GSXML.DISPLAY_TEXT_ELEM) !=null) {
105 // have got descriptions already,
106 return;
107 }
108 }
109
110 // if get here, we need to get the service descriptions
111 ///ystem.out.println("getting services description");
112
113 // we will send all the requests in a single message
114 Element info_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
115 for (int i=0; i<services.getLength(); i++) {
116 Element c = (Element)services.item(i);
117 String name = c.getAttribute(GSXML.NAME_ATT);
118 String address = GSPath.appendLink(coll_name, name);
119 Element info_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, address, lang, uid);
120 Element req_param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
121 req_param_list.appendChild(GSXML.createParameter(this.doc, GSXML.SUBSET_PARAM, GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER));
122 info_request.appendChild(req_param_list);
123 info_message.appendChild(info_request);
124
125 }
126
127 Element info_response = (Element)this.mr.process(info_message);
128
129 NodeList service_responses = info_response.getElementsByTagName(GSXML.RESPONSE_ELEM);
130 // check that have same number of responses as collections
131 if (services.getLength() != service_responses.getLength()) {
132 System.err.println("DefaultReceptionist Error: didn't get a response for each service - somethings gone wrong!");
133 // for now, dont use the metadata
134 } else {
135 for (int i=0; i<services.getLength(); i++) {
136 Element c1 = (Element)services.item(i);
137 Element c2 = (Element)GSXML.getChildByTagName((Element)service_responses.item(i), GSXML.SERVICE_ELEM);
138 if (c1.getAttribute(GSXML.NAME_ATT).equals(c2.getAttribute(GSXML.NAME_ATT))) {
139 //add the service data into the original response
140 GSXML.mergeElements(c1, c2);
141 } else {
142 System.err.println("DefaultReceptionist Error: response does not correspond to request!");
143 }
144
145 }
146 }
147
148 }
149}
150
Note: See TracBrowser for help on using the repository browser.