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

Last change on this file since 5402 was 5402, checked in by kjdon, 21 years ago

tidying up println stuff

  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 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 * @see WebReceptionist
18 */
19public class DefaultReceptionist extends TransformingReceptionist {
20
21 protected void addExtraInfo(Element page) {
22 // we want to add in the collection description for each page - cos
23 // our default xslt needs this.
24 super.addExtraInfo(page);
25
26 Element page_request = (Element)GSXML.getChildByTagName(page, GSXML.PAGE_REQUEST_ELEM);
27 ///ystem.out.println("add extra info, page request="+this.converter.getString(page_request));
28 // is a collection defined?
29 Element param_list = (Element)GSXML.getChildByTagName(page_request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
30 if (param_list==null) { // must be the original home page
31 ///ystem.out.println("DefaultReceptionist: no param list, assuming home page");
32 return;
33 }
34 Element coll_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GSParams.COLLECTION);
35 if (coll_param == null) {
36 ///ystem.out.println("DefaultReceptionist: coll param is null, returning");
37 return;
38 }
39
40 // see if the collection/cluster element is already there
41 String coll_name = coll_param.getAttribute(GSXML.VALUE_ATT);
42 String lang = page_request.getAttribute(GSXML.LANG_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);
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 // check one service for display items
89 if (!get_service_description) {
90 // we dont know yet if we need to get these
91 int i=1;
92 Element test_s = (Element)services.item(0);
93 while (i<services.getLength() && test_s.getAttribute(GSXML.TYPE_ATT).equals(GSXML.SERVICE_TYPE_RETRIEVE)) {
94 test_s = (Element)services.item(i); i++;
95 }
96 if (i==services.getLength()) {
97 // we have only found retrieve services, so dont need descripitons anyway
98 return;
99 }
100 if (GSXML.getChildByTagName(test_s, GSXML.DISPLAY_TEXT_ELEM) !=null) {
101 // have got descriptions already,
102 return;
103 }
104 }
105
106 // if get here, we need to get the service descriptions
107 ///ystem.out.println("getting services description");
108
109 // we will send all the requests in a single message
110 Element info_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
111 for (int i=0; i<services.getLength(); i++) {
112 Element c = (Element)services.item(i);
113 String name = c.getAttribute(GSXML.NAME_ATT);
114 String address = GSPath.appendLink(coll_name, name);
115 Element info_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, address, lang);
116 Element req_param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
117 req_param_list.appendChild(GSXML.createParameter(this.doc, GSXML.SUBSET_PARAM, GSXML.DISPLAY_TEXT_ELEM));
118 info_request.appendChild(req_param_list);
119 info_message.appendChild(info_request);
120
121 }
122
123 Element info_response = (Element)this.mr.process(info_message);
124
125 NodeList service_responses = info_response.getElementsByTagName(GSXML.RESPONSE_ELEM);
126 // check that have same number of responses as collections
127 if (services.getLength() != service_responses.getLength()) {
128 System.err.println("DefaultReceptionist Error: didn't get a response for each service - somethings gone wrong!");
129 // for now, dont use the metadata
130 } else {
131 for (int i=0; i<services.getLength(); i++) {
132 Element c1 = (Element)services.item(i);
133 Element c2 = (Element)GSXML.getChildByTagName((Element)service_responses.item(i), GSXML.SERVICE_ELEM);
134 if (c1.getAttribute(GSXML.NAME_ATT).equals(c2.getAttribute(GSXML.NAME_ATT))) {
135 //add the service data into the original response
136 GSXML.mergeElements(c1, c2);
137 } else {
138 System.err.println("DefaultReceptionist Error: response does not correspond to request!");
139 }
140
141 }
142 }
143
144 }
145}
146
Note: See TracBrowser for help on using the repository browser.