[4258] | 1 | package org.greenstone.gsdl3.core;
|
---|
| 2 |
|
---|
| 3 | import org.greenstone.gsdl3.util.*;
|
---|
| 4 | import org.greenstone.gsdl3.action.*;
|
---|
| 5 | // XML classes
|
---|
[24974] | 6 | import org.w3c.dom.Node;
|
---|
| 7 | import org.w3c.dom.NodeList;
|
---|
| 8 | import org.w3c.dom.Document;
|
---|
| 9 | import org.w3c.dom.Element;
|
---|
[4258] | 10 |
|
---|
| 11 | // other java classes
|
---|
| 12 | import java.io.File;
|
---|
| 13 | import java.util.HashMap;
|
---|
| 14 | import java.util.Enumeration;
|
---|
| 15 |
|
---|
[13124] | 16 | import org.apache.log4j.*;
|
---|
| 17 |
|
---|
[24974] | 18 | /** The default greenstone receptionist - needs some extra info for each page */
|
---|
| 19 | public class DefaultReceptionist extends TransformingReceptionist
|
---|
| 20 | {
|
---|
[13124] | 21 |
|
---|
[23814] | 22 | static Logger logger = Logger.getLogger(org.greenstone.gsdl3.core.DefaultReceptionist.class.getName());
|
---|
[24974] | 23 |
|
---|
| 24 | /**
|
---|
| 25 | * add in the collection description to the page, then for each service, add
|
---|
| 26 | * in the service description
|
---|
| 27 | */
|
---|
| 28 | protected void addExtraInfo(Element page)
|
---|
| 29 | {
|
---|
[23814] | 30 | super.addExtraInfo(page);
|
---|
[28966] | 31 | // the document for the page
|
---|
| 32 | Document doc = page.getOwnerDocument();
|
---|
| 33 | // a new document to create messages to send to MR
|
---|
| 34 | Document msg_doc = XMLConverter.newDOM();
|
---|
[24974] | 35 | Element page_request = (Element) GSXML.getChildByTagName(page, GSXML.PAGE_REQUEST_ELEM);
|
---|
[23814] | 36 | // if it is a system request, then we don't bother with this.
|
---|
| 37 | String action = page_request.getAttribute(GSXML.ACTION_ATT);
|
---|
[24974] | 38 | if (action.equals("s"))
|
---|
| 39 | {
|
---|
[23814] | 40 | logger.error("HACK: don't ask for coll info if system action");
|
---|
| 41 | return;
|
---|
| 42 | }
|
---|
[24974] | 43 | logger.debug("add extra info, page request=" + this.converter.getString(page_request));
|
---|
[23814] | 44 | // is a collection defined?
|
---|
[24974] | 45 | Element param_list = (Element) GSXML.getChildByTagName(page_request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 46 | if (param_list == null)
|
---|
| 47 | { // must be the original home page
|
---|
[23814] | 48 | logger.debug(" no param list, assuming home page");
|
---|
| 49 | return;
|
---|
| 50 | }
|
---|
| 51 | Element coll_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, GSParams.COLLECTION);
|
---|
[24974] | 52 | if (coll_param == null)
|
---|
| 53 | {
|
---|
[23814] | 54 | logger.debug(" coll param is null, returning");
|
---|
| 55 | return;
|
---|
| 56 | }
|
---|
[5127] | 57 |
|
---|
[23814] | 58 | // see if the collection/cluster element is already there
|
---|
| 59 | String coll_name = coll_param.getAttribute(GSXML.VALUE_ATT);
|
---|
[24993] | 60 | UserContext userContext = new UserContext(page_request);
|
---|
[24974] | 61 |
|
---|
| 62 | if (coll_name.equals(""))
|
---|
| 63 | {
|
---|
[23968] | 64 | Element pc_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, "p.c");
|
---|
[24974] | 65 | if (pc_param != null)
|
---|
[23968] | 66 | {
|
---|
| 67 | coll_name = pc_param.getAttribute(GSXML.VALUE_ATT);
|
---|
| 68 | }
|
---|
[23814] | 69 | }
|
---|
[24974] | 70 |
|
---|
[23814] | 71 | boolean get_service_description = false;
|
---|
[24974] | 72 | Element page_response = (Element) GSXML.getChildByTagName(page, GSXML.PAGE_RESPONSE_ELEM);
|
---|
| 73 | if (this.language_list != null)
|
---|
| 74 | {
|
---|
[28966] | 75 | page_response.appendChild(doc.importNode(this.language_list, true));
|
---|
[23814] | 76 | }
|
---|
[24974] | 77 | Element coll_description = (Element) GSXML.getChildByTagName(page_response, GSXML.COLLECTION_ELEM);
|
---|
| 78 | if (coll_description == null)
|
---|
| 79 | {
|
---|
[23814] | 80 | // try cluster
|
---|
[24974] | 81 | coll_description = (Element) GSXML.getChildByTagName(page_response, GSXML.CLUSTER_ELEM);
|
---|
[23814] | 82 | }
|
---|
[24974] | 83 | if (coll_description == null)
|
---|
| 84 | {
|
---|
[28966] | 85 | logger.debug("getting the coll description");
|
---|
| 86 | // we dont have one yet - get it
|
---|
[24974] | 87 |
|
---|
[28966] | 88 | Element coll_about_message = msg_doc.createElement(GSXML.MESSAGE_ELEM);
|
---|
| 89 | Element coll_about_request = GSXML.createBasicRequest(msg_doc, GSXML.REQUEST_TYPE_DESCRIBE, coll_name, userContext);
|
---|
[23814] | 90 | coll_about_message.appendChild(coll_about_request);
|
---|
[24974] | 91 |
|
---|
[23814] | 92 | Node coll_about_response_message = this.mr.process(coll_about_message);
|
---|
[24974] | 93 | Element coll_about_response = (Element) GSXML.getChildByTagName(coll_about_response_message, GSXML.RESPONSE_ELEM);
|
---|
| 94 | if (coll_about_response == null)
|
---|
| 95 | {
|
---|
[23814] | 96 | return;
|
---|
| 97 | }
|
---|
[24974] | 98 | coll_description = (Element) GSXML.getChildByTagName(coll_about_response, GSXML.COLLECTION_ELEM);
|
---|
| 99 | if (coll_description == null)
|
---|
| 100 | { // may be a cluster
|
---|
| 101 | coll_description = (Element) GSXML.getChildByTagName(coll_about_response, GSXML.CLUSTER_ELEM);
|
---|
[23814] | 102 | }
|
---|
[24974] | 103 |
|
---|
| 104 | if (coll_description == null)
|
---|
| 105 | {
|
---|
[23814] | 106 | logger.error(" no collection description, returning");
|
---|
| 107 | return;
|
---|
| 108 | }
|
---|
| 109 | // have found one, append it to the page response
|
---|
[28966] | 110 | coll_description = (Element) doc.importNode(coll_description, true);
|
---|
[23814] | 111 | page_response.appendChild(coll_description);
|
---|
| 112 | get_service_description = true;
|
---|
| 113 | }
|
---|
[28966] | 114 |
|
---|
[5127] | 115 |
|
---|
[23814] | 116 | // have got a coll description
|
---|
| 117 | // now get the dispay info for the services
|
---|
[24974] | 118 | Element service_list = (Element) GSXML.getChildByTagName(coll_description, GSXML.SERVICE_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 119 | if (service_list == null)
|
---|
| 120 | {
|
---|
[23814] | 121 | logger.error(" no service list, returning");
|
---|
| 122 | // something weird has gone wrong
|
---|
| 123 | return;
|
---|
| 124 | }
|
---|
[5113] | 125 |
|
---|
[23814] | 126 | NodeList services = service_list.getElementsByTagName(GSXML.SERVICE_ELEM);
|
---|
[24974] | 127 | if (services.getLength() == 0)
|
---|
| 128 | {
|
---|
| 129 | logger.error("DefaultReceoptionist: no services found for colllection/cluster " + coll_name);
|
---|
[23814] | 130 | return;
|
---|
| 131 | }
|
---|
| 132 | // check one service for display items
|
---|
[24974] | 133 | if (!get_service_description)
|
---|
| 134 | {
|
---|
[23814] | 135 | // we dont know yet if we need to get these
|
---|
[24974] | 136 | int i = 1;
|
---|
| 137 | Element test_s = (Element) services.item(0);
|
---|
| 138 | while (i < services.getLength() && (test_s.getAttribute(GSXML.TYPE_ATT).equals(GSXML.SERVICE_TYPE_RETRIEVE) || test_s.getAttribute(GSXML.TYPE_ATT).equals(GSXML.SERVICE_TYPE_OAI)))
|
---|
| 139 | {
|
---|
| 140 | test_s = (Element) services.item(i);
|
---|
| 141 | i++;
|
---|
[23814] | 142 | }
|
---|
[24974] | 143 | if (i == services.getLength())
|
---|
| 144 | {
|
---|
[23814] | 145 | // we have only found retrieve or oai services, so dont need descripitons anyway
|
---|
| 146 | return;
|
---|
| 147 | }
|
---|
[24974] | 148 | if (GSXML.getChildByTagName(test_s, GSXML.DISPLAY_TEXT_ELEM) != null)
|
---|
| 149 | {
|
---|
[23814] | 150 | // have got descriptions already,
|
---|
| 151 | return;
|
---|
| 152 | }
|
---|
| 153 | }
|
---|
[5127] | 154 |
|
---|
[23814] | 155 | // if get here, we need to get the service descriptions
|
---|
[24974] | 156 |
|
---|
[23814] | 157 | // we will send all the requests in a single message
|
---|
[28966] | 158 | Element info_message = msg_doc.createElement(GSXML.MESSAGE_ELEM);
|
---|
[24974] | 159 | for (int i = 0; i < services.getLength(); i++)
|
---|
| 160 | {
|
---|
| 161 | Element c = (Element) services.item(i);
|
---|
[23814] | 162 | String name = c.getAttribute(GSXML.NAME_ATT);
|
---|
| 163 | String address = GSPath.appendLink(coll_name, name);
|
---|
[28966] | 164 | Element info_request = GSXML.createBasicRequest(msg_doc, GSXML.REQUEST_TYPE_DESCRIBE, address, userContext);
|
---|
[23814] | 165 | //Element req_param_list = this.doc.createElement(GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
|
---|
| 166 | //req_param_list.appendChild(GSXML.createParameter(this.doc, GSXML.SUBSET_PARAM, GSXML.DISPLAY_TEXT_ELEM+GSXML.LIST_MODIFIER));
|
---|
| 167 | //info_request.appendChild(req_param_list);
|
---|
| 168 | info_message.appendChild(info_request);
|
---|
[24974] | 169 |
|
---|
[23814] | 170 | }
|
---|
[5113] | 171 |
|
---|
[24974] | 172 | Element info_response = (Element) this.mr.process(info_message);
|
---|
[5113] | 173 |
|
---|
[23814] | 174 | NodeList service_responses = info_response.getElementsByTagName(GSXML.RESPONSE_ELEM);
|
---|
| 175 | // check that have same number of responses as collections
|
---|
[24974] | 176 | if (services.getLength() != service_responses.getLength())
|
---|
| 177 | {
|
---|
[23814] | 178 | logger.error(" didn't get a response for each service - somethings gone wrong!");
|
---|
| 179 | // for now, dont use the metadata
|
---|
[24974] | 180 | }
|
---|
| 181 | else
|
---|
| 182 | {
|
---|
| 183 | for (int i = 0; i < services.getLength(); i++)
|
---|
| 184 | {
|
---|
| 185 | Element c1 = (Element) services.item(i);
|
---|
| 186 | Element c2 = (Element) GSXML.getChildByTagName((Element) service_responses.item(i), GSXML.SERVICE_ELEM);
|
---|
| 187 | if (c1 != null && c2 != null && c1.getAttribute(GSXML.NAME_ATT).equals(c2.getAttribute(GSXML.NAME_ATT)))
|
---|
| 188 | {
|
---|
[23814] | 189 | //add the service data into the original response
|
---|
| 190 | GSXML.mergeElements(c1, c2);
|
---|
[24974] | 191 | }
|
---|
| 192 | else
|
---|
| 193 | {
|
---|
[23814] | 194 | logger.debug(" response does not correspond to request!");
|
---|
[24974] | 195 | }
|
---|
| 196 |
|
---|
[23814] | 197 | }
|
---|
| 198 | }
|
---|
[5113] | 199 | }
|
---|
[4258] | 200 | }
|
---|