[4855] | 1 | package org.greenstone.gsdl3.action;
|
---|
| 2 |
|
---|
[25861] | 3 | import java.io.Serializable;
|
---|
[4855] | 4 | import java.util.HashMap;
|
---|
| 5 | import java.util.HashSet;
|
---|
| 6 |
|
---|
[25861] | 7 | import org.apache.log4j.Logger;
|
---|
| 8 | import org.greenstone.gsdl3.util.GSParams;
|
---|
| 9 | import org.greenstone.gsdl3.util.GSPath;
|
---|
| 10 | import org.greenstone.gsdl3.util.GSXML;
|
---|
| 11 | import org.greenstone.gsdl3.util.OID;
|
---|
| 12 | import org.greenstone.gsdl3.util.UserContext;
|
---|
| 13 | import org.w3c.dom.Element;
|
---|
| 14 | import org.w3c.dom.Node;
|
---|
| 15 | import org.w3c.dom.NodeList;
|
---|
[13124] | 16 |
|
---|
[4855] | 17 | /** action for GS2 style classifier browsing */
|
---|
[24990] | 18 | public class GS2BrowseAction extends Action
|
---|
| 19 | {
|
---|
[13124] | 20 |
|
---|
[24990] | 21 | public static final String CLASSIFIER_ARG = "cl";
|
---|
[13124] | 22 |
|
---|
[24990] | 23 | static Logger logger = Logger.getLogger(org.greenstone.gsdl3.action.GS2BrowseAction.class.getName());
|
---|
[4855] | 24 |
|
---|
[24990] | 25 | /** process the request */
|
---|
| 26 | public Node process(Node message_node)
|
---|
| 27 | {
|
---|
[16688] | 28 |
|
---|
[24990] | 29 | Element message = this.converter.nodeToElement(message_node);
|
---|
[4855] | 30 |
|
---|
[24990] | 31 | // get the request - assume only one
|
---|
| 32 | Element request = (Element) GSXML.getChildByTagName(message, GSXML.REQUEST_ELEM);
|
---|
[4855] | 33 |
|
---|
[24990] | 34 | // the result
|
---|
| 35 | Element result = this.doc.createElement(GSXML.MESSAGE_ELEM);
|
---|
| 36 | Element response = classifierBrowse(request);
|
---|
| 37 | result.appendChild(response);
|
---|
| 38 | return result;
|
---|
| 39 | }
|
---|
[4855] | 40 |
|
---|
[24990] | 41 | protected Element classifierBrowse(Element request)
|
---|
| 42 | {
|
---|
[4855] | 43 |
|
---|
[24990] | 44 | Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM);
|
---|
[4855] | 45 |
|
---|
[24990] | 46 | // extract the params from the cgi-request, and check that we have a coll specified
|
---|
| 47 | Element cgi_paramList = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
|
---|
[25635] | 48 | HashMap<String, Serializable> params = GSXML.extractParams(cgi_paramList, false);
|
---|
[4855] | 49 |
|
---|
[24990] | 50 | String service_name = (String) params.get(GSParams.SERVICE);
|
---|
| 51 | String collection = (String) params.get(GSParams.COLLECTION);
|
---|
| 52 | if (collection == null || collection.equals(""))
|
---|
| 53 | {
|
---|
| 54 | logger.error("classifierBrowse, need to specify a collection!");
|
---|
| 55 | return page_response;
|
---|
| 56 | }
|
---|
[19984] | 57 |
|
---|
[24993] | 58 | UserContext userContext = new UserContext(request);
|
---|
[24990] | 59 | String to = GSPath.appendLink(collection, service_name);
|
---|
[6165] | 60 |
|
---|
[24990] | 61 | // the first part of the response is the service description
|
---|
| 62 | // for now get this again from the service.
|
---|
| 63 | // this should be cached somehow later on.
|
---|
[4855] | 64 |
|
---|
[24990] | 65 | Element info_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
|
---|
[24993] | 66 | Element info_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_DESCRIBE, to, userContext);
|
---|
[24990] | 67 | info_message.appendChild(info_request);
|
---|
[8575] | 68 |
|
---|
[24990] | 69 | // also get the format stuff now if there is some
|
---|
[24993] | 70 | Element format_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_FORMAT, to, userContext);
|
---|
[24990] | 71 | info_message.appendChild(format_request);
|
---|
| 72 | // process the requests
|
---|
[4855] | 73 |
|
---|
[24990] | 74 | Element info_response = (Element) this.mr.process(info_message);
|
---|
[4855] | 75 |
|
---|
[24990] | 76 | // the two responses
|
---|
| 77 | NodeList responses = info_response.getElementsByTagName(GSXML.RESPONSE_ELEM);
|
---|
| 78 | Element service_response = (Element) responses.item(0);
|
---|
| 79 | Element format_response = (Element) responses.item(1);
|
---|
[4855] | 80 |
|
---|
[24990] | 81 | Element service_description = (Element) GSXML.getChildByTagName(service_response, GSXML.SERVICE_ELEM);
|
---|
| 82 | page_response.appendChild(this.doc.importNode(service_description, true));
|
---|
[4855] | 83 |
|
---|
[24990] | 84 | //append site metadata
|
---|
[24993] | 85 | addSiteMetadata(page_response, userContext);
|
---|
[25128] | 86 | addInterfaceOptions(page_response);
|
---|
[4855] | 87 |
|
---|
[24990] | 88 | // if rt=d, then we are just displaying the service
|
---|
| 89 | String request_type = (String) params.get(GSParams.REQUEST_TYPE);
|
---|
| 90 | if (request_type.equals("d"))
|
---|
| 91 | {
|
---|
| 92 | //return the page that we have so far
|
---|
| 93 | return page_response;
|
---|
| 94 | }
|
---|
[4855] | 95 |
|
---|
[24990] | 96 | // get the node that the user has clicked on
|
---|
| 97 | String classifier_node = (String) params.get(CLASSIFIER_ARG);
|
---|
[4855] | 98 |
|
---|
[24990] | 99 | // if the node is not defined, return the page that we have so far
|
---|
| 100 | if (classifier_node == null || classifier_node.equals(""))
|
---|
| 101 | {
|
---|
| 102 | return page_response;
|
---|
| 103 | }
|
---|
[4855] | 104 |
|
---|
[24990] | 105 | // the id of the classifier is the top id of the selected node
|
---|
| 106 | String top_id = OID.getTop(classifier_node);
|
---|
[25635] | 107 | HashSet<String> doc_meta_names = new HashSet<String>();
|
---|
| 108 | HashSet<String> class_meta_names = new HashSet<String>();
|
---|
[24990] | 109 | // add in the defaults
|
---|
| 110 | doc_meta_names.add("Title");
|
---|
| 111 | class_meta_names.add("Title");
|
---|
[13568] | 112 |
|
---|
[24990] | 113 | // add the format info into the response
|
---|
| 114 | Element format_elem = (Element) GSXML.getChildByTagName(format_response, GSXML.FORMAT_ELEM);
|
---|
| 115 | if (format_elem != null)
|
---|
| 116 | {
|
---|
[13568] | 117 |
|
---|
[24990] | 118 | // find the one for the classifier we are in
|
---|
| 119 | Element this_format = GSXML.getNamedElement(format_elem, GSXML.CLASSIFIER_ELEM, GSXML.NAME_ATT, top_id);
|
---|
| 120 | if (this_format == null)
|
---|
| 121 | {
|
---|
| 122 | this_format = (Element) GSXML.getChildByTagName(format_elem, GSXML.DEFAULT_ELEM);
|
---|
| 123 | }
|
---|
[13568] | 124 |
|
---|
[24990] | 125 | if (this_format != null)
|
---|
| 126 | {
|
---|
| 127 | Element new_format = GSXML.duplicateWithNewName(this.doc, this_format, GSXML.FORMAT_ELEM, false);
|
---|
| 128 | extractMetadataNames(new_format, doc_meta_names, class_meta_names);
|
---|
| 129 | // set the format type
|
---|
| 130 | new_format.setAttribute(GSXML.TYPE_ATT, "browse");
|
---|
| 131 |
|
---|
| 132 | page_response.appendChild(new_format);
|
---|
| 133 | }
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | // find out if this classifier is horizontal at top
|
---|
| 137 | Element class_list = (Element) GSXML.getChildByTagName(service_description, GSXML.CLASSIFIER_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 138 | Element this_classifier = GSXML.getNamedElement(class_list, GSXML.CLASSIFIER_ELEM, GSXML.NAME_ATT, top_id);
|
---|
| 139 |
|
---|
| 140 | // get the browse structure for the selected node
|
---|
| 141 | Element classify_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
|
---|
[24993] | 142 | Element classify_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
|
---|
[24990] | 143 | classify_message.appendChild(classify_request);
|
---|
| 144 |
|
---|
| 145 | //Create a parameter list to specify the required structure information
|
---|
| 146 | // for now, always get ancestors and children
|
---|
| 147 | Element param_list = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 148 | classify_request.appendChild(param_list);
|
---|
| 149 | Element param = this.doc.createElement(GSXML.PARAM_ELEM);
|
---|
| 150 | param_list.appendChild(param);
|
---|
| 151 | param.setAttribute(GSXML.NAME_ATT, "structure");
|
---|
| 152 | param.setAttribute(GSXML.VALUE_ATT, "ancestors");
|
---|
| 153 | param = this.doc.createElement(GSXML.PARAM_ELEM);
|
---|
| 154 | param_list.appendChild(param);
|
---|
| 155 | param.setAttribute(GSXML.NAME_ATT, "structure");
|
---|
| 156 | param.setAttribute(GSXML.VALUE_ATT, "children");
|
---|
| 157 |
|
---|
| 158 | // put the classifier node into a classifier node list
|
---|
| 159 | Element classifier_list = this.doc.createElement(GSXML.CLASS_NODE_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 160 | Element classifier = this.doc.createElement(GSXML.CLASS_NODE_ELEM);
|
---|
| 161 | classifier.setAttribute(GSXML.NODE_ID_ATT, classifier_node);
|
---|
| 162 | classifier_list.appendChild(classifier);
|
---|
| 163 | classify_request.appendChild(classifier_list);
|
---|
| 164 |
|
---|
| 165 | // process the request
|
---|
| 166 | Element classify_response = (Element) this.mr.process(classify_message);
|
---|
[25693] | 167 |
|
---|
[24990] | 168 | String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.CLASS_NODE_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 169 | Element class_node_list = (Element) GSXML.getNodeByPath(classify_response, path);
|
---|
| 170 |
|
---|
| 171 | path = GSPath.appendLink(GSXML.CLASS_NODE_ELEM, GSXML.NODE_STRUCTURE_ELEM);
|
---|
| 172 | // assume that we always get back the top level CL1 node - this becomes the page_classifier node
|
---|
| 173 | path = GSPath.appendLink(path, GSXML.CLASS_NODE_ELEM);
|
---|
| 174 | Element cl_structure = (Element) GSXML.getNodeByPath(class_node_list, path);
|
---|
| 175 | if (cl_structure == null)
|
---|
| 176 | {
|
---|
| 177 | logger.error("classifier structure request returned no structure");
|
---|
| 178 | return page_response;
|
---|
| 179 | }
|
---|
| 180 |
|
---|
[25693] | 181 | //If the user is viewing a horizontal classifier then we need to get extra information
|
---|
| 182 | if (cl_structure.getAttribute(GSXML.CHILD_TYPE_ATT).equals(GSXML.HLIST))
|
---|
[24990] | 183 | {
|
---|
[25693] | 184 | //If we have a horizontal classifier and we have had the top-level node requested (e.g. CL1, CL2 etc.)
|
---|
| 185 | //then we want to get the children of the first classifier node (e.g. the children of CL2.1)
|
---|
| 186 | if (OID.isTop(classifier_node))
|
---|
[24990] | 187 | {
|
---|
[25693] | 188 | boolean firstChildIsClassifierNode = false;
|
---|
| 189 | NodeList classifierChildrenNodes = GSXML.getChildrenByTagName(cl_structure, GSXML.CLASS_NODE_ELEM);
|
---|
| 190 | for (int i = 0; i < classifierChildrenNodes.getLength(); i++)
|
---|
| 191 | {
|
---|
| 192 | Element currentChild = (Element) classifierChildrenNodes.item(i);
|
---|
| 193 | if (currentChild.getAttribute(GSXML.NODE_ID_ATT).endsWith(".1"))
|
---|
| 194 | {
|
---|
| 195 | firstChildIsClassifierNode = true;
|
---|
| 196 | }
|
---|
| 197 | }
|
---|
[24990] | 198 |
|
---|
[25693] | 199 | if (firstChildIsClassifierNode)
|
---|
| 200 | {
|
---|
| 201 | Element childStructure = getClassifierStructureFromID(classifier_node + ".1", request, collection, service_name);
|
---|
| 202 |
|
---|
| 203 | Element replacementElem = null;
|
---|
| 204 | NodeList childClassifierNodes = childStructure.getElementsByTagName(GSXML.CLASS_NODE_ELEM);
|
---|
| 205 | for (int i = 0; i < childClassifierNodes.getLength(); i++)
|
---|
| 206 | {
|
---|
| 207 | Element currentElem = (Element) childClassifierNodes.item(i);
|
---|
| 208 | if (currentElem.getAttribute(GSXML.NODE_ID_ATT).equals(classifier_node + ".1"))
|
---|
| 209 | {
|
---|
| 210 | replacementElem = currentElem;
|
---|
| 211 | break;
|
---|
| 212 | }
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 | NodeList nodesToSearch = cl_structure.getElementsByTagName(GSXML.CLASS_NODE_ELEM);
|
---|
| 216 | for (int i = 0; i < nodesToSearch.getLength(); i++)
|
---|
| 217 | {
|
---|
| 218 | Element currentElem = (Element) nodesToSearch.item(i);
|
---|
| 219 | if (currentElem.getAttribute(GSXML.NODE_ID_ATT).equals(classifier_node + ".1"))
|
---|
| 220 | {
|
---|
| 221 | Element parent = (Element) currentElem.getParentNode();
|
---|
| 222 | parent.insertBefore(replacementElem, currentElem);
|
---|
| 223 | parent.removeChild(currentElem);
|
---|
| 224 | break;
|
---|
| 225 | }
|
---|
| 226 | }
|
---|
| 227 | }
|
---|
[24990] | 228 | }
|
---|
[25693] | 229 | //If we have a horizontal classifier and we have NOT had the top-level node requested then we need to
|
---|
| 230 | //make sure we get the full list of top-level children to display (e.g. if the user has requested
|
---|
| 231 | //CL2.1.1 we also need to make sure we have CL2.2, CL2.3, CL2.4 etc.)
|
---|
[24990] | 232 | else
|
---|
| 233 | {
|
---|
[25693] | 234 | Element childStructure = getClassifierStructureFromID(OID.getTop(classifier_node), request, collection, service_name);
|
---|
| 235 |
|
---|
| 236 | String[] idParts = classifier_node.split("\\.");
|
---|
| 237 | String idToSearchFor = idParts[0] + "." + idParts[1];
|
---|
| 238 |
|
---|
| 239 | Element replacementElem = null;
|
---|
| 240 | NodeList childClassifierNodes = cl_structure.getElementsByTagName(GSXML.CLASS_NODE_ELEM);
|
---|
| 241 | for (int i = 0; i < childClassifierNodes.getLength(); i++)
|
---|
| 242 | {
|
---|
| 243 | Element currentElem = (Element) childClassifierNodes.item(i);
|
---|
| 244 | if (currentElem.getAttribute(GSXML.NODE_ID_ATT).equals(idToSearchFor))
|
---|
| 245 | {
|
---|
| 246 | replacementElem = currentElem;
|
---|
| 247 | break;
|
---|
| 248 | }
|
---|
| 249 | }
|
---|
| 250 |
|
---|
| 251 | if (replacementElem != null)
|
---|
| 252 | {
|
---|
| 253 | NodeList nodesToSearch = childStructure.getElementsByTagName(GSXML.CLASS_NODE_ELEM);
|
---|
| 254 | for (int i = 0; i < nodesToSearch.getLength(); i++)
|
---|
| 255 | {
|
---|
| 256 | Element currentElem = (Element) nodesToSearch.item(i);
|
---|
| 257 | if (currentElem.getAttribute(GSXML.NODE_ID_ATT).equals(idToSearchFor))
|
---|
| 258 | {
|
---|
| 259 | Element parent = (Element) currentElem.getParentNode();
|
---|
| 260 | parent.insertBefore(replacementElem, currentElem);
|
---|
| 261 | parent.removeChild(currentElem);
|
---|
| 262 | break;
|
---|
| 263 | }
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 | cl_structure = childStructure;
|
---|
| 267 | }
|
---|
[24990] | 268 | }
|
---|
[25693] | 269 | }
|
---|
[24990] | 270 |
|
---|
[25693] | 271 | Element page_classifier = null;
|
---|
| 272 | // add the single classifier node as the page classifier
|
---|
| 273 | page_classifier = GSXML.duplicateWithNewName(this.doc, cl_structure, GSXML.CLASSIFIER_ELEM, true);
|
---|
| 274 | page_response.appendChild(page_classifier);
|
---|
| 275 | page_classifier.setAttribute(GSXML.NAME_ATT, top_id);
|
---|
| 276 |
|
---|
[24990] | 277 | // get the metadata for each classifier node,
|
---|
| 278 | // then for each document node
|
---|
| 279 |
|
---|
| 280 | Element metadata_message = this.doc.createElement(GSXML.MESSAGE_ELEM);
|
---|
| 281 |
|
---|
| 282 | boolean did_classifier = false;
|
---|
| 283 | boolean did_documents = false;
|
---|
| 284 |
|
---|
| 285 | // if there are classifier nodes
|
---|
| 286 | // create a metadata request for the classifier, and add it to
|
---|
| 287 | // the the message
|
---|
| 288 | NodeList cl_nodes = page_classifier.getElementsByTagName(GSXML.CLASS_NODE_ELEM);
|
---|
| 289 |
|
---|
| 290 | if (cl_nodes.getLength() > 0)
|
---|
| 291 | {
|
---|
| 292 | did_classifier = true;
|
---|
[24993] | 293 | Element cl_meta_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to + "MetadataRetrieve", userContext);
|
---|
[24990] | 294 | metadata_message.appendChild(cl_meta_request);
|
---|
| 295 |
|
---|
| 296 | Element new_cl_nodes_list = this.doc.createElement(GSXML.CLASS_NODE_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 297 | cl_meta_request.appendChild(new_cl_nodes_list);
|
---|
| 298 |
|
---|
| 299 | for (int c = 0; c < cl_nodes.getLength(); c++)
|
---|
| 300 | {
|
---|
| 301 |
|
---|
| 302 | Element cl = this.doc.createElement(GSXML.CLASS_NODE_ELEM);
|
---|
| 303 | cl.setAttribute(GSXML.NODE_ID_ATT, ((Element) cl_nodes.item(c)).getAttribute(GSXML.NODE_ID_ATT));
|
---|
| 304 | new_cl_nodes_list.appendChild(cl);
|
---|
| 305 | }
|
---|
| 306 |
|
---|
| 307 | // create and add in the param list - for now get all the metadata
|
---|
| 308 | // should be based on info sent in from the recept, and the
|
---|
| 309 | // format stuff
|
---|
| 310 | Element cl_param_list = createMetadataParamList(class_meta_names);
|
---|
| 311 | cl_meta_request.appendChild(cl_param_list);
|
---|
| 312 |
|
---|
| 313 | }
|
---|
| 314 |
|
---|
| 315 | // if there are document nodes in the classification (happens
|
---|
| 316 | // sometimes), create a second request for document metadata and
|
---|
| 317 | // append to the message
|
---|
| 318 | NodeList doc_nodes = page_classifier.getElementsByTagName(GSXML.DOC_NODE_ELEM);
|
---|
| 319 | if (doc_nodes.getLength() > 0)
|
---|
| 320 | {
|
---|
| 321 | did_documents = true;
|
---|
[24993] | 322 | Element doc_meta_request = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, GSPath.appendLink(collection, "DocumentMetadataRetrieve"), userContext);
|
---|
[24990] | 323 | metadata_message.appendChild(doc_meta_request);
|
---|
| 324 |
|
---|
| 325 | Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 326 | doc_meta_request.appendChild(doc_list);
|
---|
| 327 |
|
---|
| 328 | for (int c = 0; c < doc_nodes.getLength(); c++)
|
---|
| 329 | {
|
---|
| 330 |
|
---|
| 331 | Element d = this.doc.createElement(GSXML.DOC_NODE_ELEM);
|
---|
| 332 | d.setAttribute(GSXML.NODE_ID_ATT, ((Element) doc_nodes.item(c)).getAttribute(GSXML.NODE_ID_ATT));
|
---|
| 333 | doc_list.appendChild(d);
|
---|
| 334 | }
|
---|
| 335 |
|
---|
| 336 | // create and add in the param list - add all for now
|
---|
| 337 | Element doc_param_list = createMetadataParamList(doc_meta_names);
|
---|
| 338 | doc_meta_request.appendChild(doc_param_list);
|
---|
| 339 |
|
---|
| 340 | }
|
---|
| 341 |
|
---|
| 342 | // process the metadata requests
|
---|
| 343 | Element metadata_response = (Element) this.mr.process(metadata_message);
|
---|
| 344 | if (did_classifier)
|
---|
| 345 | {
|
---|
| 346 | // the classifier one will be the first response
|
---|
| 347 | // add the metadata lists for each node back into the
|
---|
| 348 | // page_classifier nodes
|
---|
| 349 | path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.CLASS_NODE_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 350 | Node pathNode = GSXML.getNodeByPath(metadata_response, path);
|
---|
| 351 | if (pathNode == null)
|
---|
| 352 | {
|
---|
| 353 | return page_response;
|
---|
| 354 | }
|
---|
| 355 | //NodeList meta_response_cls = (Element)pathNode.getChildNodes(); // can't handle empty elements from converting formatted strings (with empty newlines) into XML
|
---|
| 356 | NodeList meta_response_cls = ((Element) pathNode).getElementsByTagName(GSXML.CLASS_NODE_ELEM);
|
---|
| 357 | for (int i = 0; i < cl_nodes.getLength(); i++)
|
---|
| 358 | {
|
---|
| 359 | GSXML.mergeMetadataLists(cl_nodes.item(i), meta_response_cls.item(i));
|
---|
| 360 | }
|
---|
| 361 | }
|
---|
| 362 |
|
---|
| 363 | if (did_documents)
|
---|
| 364 | {
|
---|
| 365 | NodeList meta_response_docs = null;
|
---|
| 366 | if (!did_classifier)
|
---|
| 367 | {
|
---|
| 368 | // its the first response
|
---|
| 369 | path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 370 | Node pathNode = GSXML.getNodeByPath(metadata_response, path);
|
---|
| 371 | if (pathNode == null)
|
---|
| 372 | {
|
---|
| 373 | return page_response;
|
---|
| 374 | }
|
---|
| 375 |
|
---|
| 376 | meta_response_docs = pathNode.getChildNodes();
|
---|
| 377 |
|
---|
| 378 | }
|
---|
| 379 | else
|
---|
| 380 | { // its the second response
|
---|
| 381 | Node nodes = GSXML.getChildByTagName(metadata_response.getElementsByTagName(GSXML.RESPONSE_ELEM).item(1), GSXML.DOC_NODE_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 382 | if (nodes == null)
|
---|
| 383 | {
|
---|
| 384 | return page_response;
|
---|
| 385 | }
|
---|
| 386 | meta_response_docs = nodes.getChildNodes();
|
---|
| 387 | }
|
---|
| 388 |
|
---|
| 389 | for (int i = 0; i < doc_nodes.getLength(); i++)
|
---|
| 390 | {
|
---|
| 391 | GSXML.mergeMetadataLists(doc_nodes.item(i), meta_response_docs.item(i));
|
---|
| 392 | }
|
---|
| 393 | }
|
---|
| 394 |
|
---|
| 395 | logger.debug("(GS2BrowseAction) Page:\n" + this.converter.getPrettyString(page_response));
|
---|
| 396 | return page_response;
|
---|
[4855] | 397 | }
|
---|
| 398 |
|
---|
[25693] | 399 | private Element getClassifierStructureFromID(String id, Element request, String collection, String service_name)
|
---|
| 400 | {
|
---|
| 401 | UserContext userContext = new UserContext(request);
|
---|
| 402 | String to = GSPath.appendLink(collection, service_name);
|
---|
| 403 |
|
---|
| 404 | Element firstClassifierNodeChildrenMessage = this.doc.createElement(GSXML.MESSAGE_ELEM);
|
---|
| 405 | Element firstClassifierNodeChildrenRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext);
|
---|
| 406 | firstClassifierNodeChildrenMessage.appendChild(firstClassifierNodeChildrenRequest);
|
---|
| 407 |
|
---|
| 408 | Element paramList = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 409 | firstClassifierNodeChildrenRequest.appendChild(paramList);
|
---|
| 410 |
|
---|
| 411 | Element ancestorParam = this.doc.createElement(GSXML.PARAM_ELEM);
|
---|
| 412 | paramList.appendChild(ancestorParam);
|
---|
| 413 | ancestorParam.setAttribute(GSXML.NAME_ATT, "structure");
|
---|
| 414 | ancestorParam.setAttribute(GSXML.VALUE_ATT, "ancestors");
|
---|
| 415 |
|
---|
| 416 | Element childrenParam = this.doc.createElement(GSXML.PARAM_ELEM);
|
---|
| 417 | paramList.appendChild(childrenParam);
|
---|
| 418 | childrenParam.setAttribute(GSXML.NAME_ATT, "structure");
|
---|
| 419 | childrenParam.setAttribute(GSXML.VALUE_ATT, "children");
|
---|
| 420 |
|
---|
| 421 | Element classifierToGetList = this.doc.createElement(GSXML.CLASS_NODE_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 422 | Element classifierToGet = this.doc.createElement(GSXML.CLASS_NODE_ELEM);
|
---|
| 423 | classifierToGet.setAttribute(GSXML.NODE_ID_ATT, id);
|
---|
| 424 | classifierToGetList.appendChild(classifierToGet);
|
---|
| 425 | firstClassifierNodeChildrenRequest.appendChild(classifierToGetList);
|
---|
| 426 |
|
---|
| 427 | Element firstClassifierNodeChildrenResponse = (Element) this.mr.process(firstClassifierNodeChildrenMessage);
|
---|
| 428 |
|
---|
| 429 | String nsPath = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.CLASS_NODE_ELEM + GSXML.LIST_MODIFIER);
|
---|
| 430 | Element topClassifierNode = (Element) GSXML.getNodeByPath(firstClassifierNodeChildrenResponse, nsPath);
|
---|
| 431 | nsPath = GSPath.appendLink(GSXML.CLASS_NODE_ELEM, GSXML.NODE_STRUCTURE_ELEM);
|
---|
| 432 | nsPath = GSPath.appendLink(nsPath, GSXML.CLASS_NODE_ELEM);
|
---|
| 433 | Element childStructure = (Element) GSXML.getNodeByPath(topClassifierNode, nsPath);
|
---|
| 434 |
|
---|
| 435 | return childStructure;
|
---|
| 436 | }
|
---|
| 437 |
|
---|
[25635] | 438 | protected void extractMetadataNames(Element new_format, HashSet<String> doc_meta_names, HashSet<String> class_meta_names)
|
---|
[24990] | 439 | {
|
---|
| 440 | NodeList templates = new_format.getElementsByTagName("gsf:template");
|
---|
| 441 | for (int i = 0; i < templates.getLength(); i++)
|
---|
| 442 | {
|
---|
| 443 | Element template = (Element) templates.item(i);
|
---|
| 444 | String match = template.getAttribute("match");
|
---|
[25793] | 445 | if (match.startsWith("documentNode"))
|
---|
[24990] | 446 | {
|
---|
| 447 | getRequiredMetadataNames(template, doc_meta_names);
|
---|
| 448 | }
|
---|
[25793] | 449 | else if (match.startsWith("classifierNode")) // not match.equals, as we want to match nodes like: classifierNode[@classifierStyle = 'VList']
|
---|
[24990] | 450 | {
|
---|
| 451 | getRequiredMetadataNames(template, class_meta_names);
|
---|
| 452 | }
|
---|
| 453 | }
|
---|
[4855] | 454 | }
|
---|
| 455 |
|
---|
| 456 | }
|
---|