Changeset 25693 for main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/GS2BrowseAction.java
- Timestamp:
- 2012-05-29T11:10:02+12:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/GS2BrowseAction.java
r25635 r25693 56 56 logger.error("classifierBrowse, need to specify a collection!"); 57 57 return page_response; 58 59 58 } 60 59 … … 140 139 Element class_list = (Element) GSXML.getChildByTagName(service_description, GSXML.CLASSIFIER_ELEM + GSXML.LIST_MODIFIER); 141 140 Element this_classifier = GSXML.getNamedElement(class_list, GSXML.CLASSIFIER_ELEM, GSXML.NAME_ATT, top_id); 142 boolean horizontal_at_top = false;143 if (!this_classifier.getAttribute("horizontalAtTop").equals(""))144 {145 horizontal_at_top = true;146 }147 if (top_id.equals(classifier_node) && horizontal_at_top)148 {149 // we have asked for a top node - if the first list is horizontal, we will select the first element of that list150 // this is a hack. also it craps out if the classifier really isn't horizontalAtTop. -151 classifier_node = classifier_node + ".1";152 153 }154 141 155 142 // get the browse structure for the selected node … … 178 165 classify_request.appendChild(classifier_list); 179 166 180 if (horizontal_at_top && !classifier_node.equals(top_id))181 {182 // also put the top id in, to get the persistant horizontal info183 classifier = this.doc.createElement(GSXML.CLASS_NODE_ELEM);184 classifier.setAttribute(GSXML.NODE_ID_ATT, top_id);185 classifier_list.appendChild(classifier);186 }187 167 // process the request 188 168 Element classify_response = (Element) this.mr.process(classify_message); 169 189 170 String path = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.CLASS_NODE_ELEM + GSXML.LIST_MODIFIER); 190 171 Element class_node_list = (Element) GSXML.getNodeByPath(classify_response, path); … … 200 181 } 201 182 183 //If the user is viewing a horizontal classifier then we need to get extra information 184 if (cl_structure.getAttribute(GSXML.CHILD_TYPE_ATT).equals(GSXML.HLIST)) 185 { 186 //If we have a horizontal classifier and we have had the top-level node requested (e.g. CL1, CL2 etc.) 187 //then we want to get the children of the first classifier node (e.g. the children of CL2.1) 188 if (OID.isTop(classifier_node)) 189 { 190 boolean firstChildIsClassifierNode = false; 191 NodeList classifierChildrenNodes = GSXML.getChildrenByTagName(cl_structure, GSXML.CLASS_NODE_ELEM); 192 for (int i = 0; i < classifierChildrenNodes.getLength(); i++) 193 { 194 Element currentChild = (Element) classifierChildrenNodes.item(i); 195 if (currentChild.getAttribute(GSXML.NODE_ID_ATT).endsWith(".1")) 196 { 197 firstChildIsClassifierNode = true; 198 } 199 } 200 201 if (firstChildIsClassifierNode) 202 { 203 Element childStructure = getClassifierStructureFromID(classifier_node + ".1", request, collection, service_name); 204 205 Element replacementElem = null; 206 NodeList childClassifierNodes = childStructure.getElementsByTagName(GSXML.CLASS_NODE_ELEM); 207 for (int i = 0; i < childClassifierNodes.getLength(); i++) 208 { 209 Element currentElem = (Element) childClassifierNodes.item(i); 210 if (currentElem.getAttribute(GSXML.NODE_ID_ATT).equals(classifier_node + ".1")) 211 { 212 replacementElem = currentElem; 213 break; 214 } 215 } 216 217 NodeList nodesToSearch = cl_structure.getElementsByTagName(GSXML.CLASS_NODE_ELEM); 218 for (int i = 0; i < nodesToSearch.getLength(); i++) 219 { 220 Element currentElem = (Element) nodesToSearch.item(i); 221 if (currentElem.getAttribute(GSXML.NODE_ID_ATT).equals(classifier_node + ".1")) 222 { 223 Element parent = (Element) currentElem.getParentNode(); 224 parent.insertBefore(replacementElem, currentElem); 225 parent.removeChild(currentElem); 226 break; 227 } 228 } 229 } 230 } 231 //If we have a horizontal classifier and we have NOT had the top-level node requested then we need to 232 //make sure we get the full list of top-level children to display (e.g. if the user has requested 233 //CL2.1.1 we also need to make sure we have CL2.2, CL2.3, CL2.4 etc.) 234 else 235 { 236 Element childStructure = getClassifierStructureFromID(OID.getTop(classifier_node), request, collection, service_name); 237 238 String[] idParts = classifier_node.split("\\."); 239 String idToSearchFor = idParts[0] + "." + idParts[1]; 240 241 Element replacementElem = null; 242 NodeList childClassifierNodes = cl_structure.getElementsByTagName(GSXML.CLASS_NODE_ELEM); 243 for (int i = 0; i < childClassifierNodes.getLength(); i++) 244 { 245 Element currentElem = (Element) childClassifierNodes.item(i); 246 if (currentElem.getAttribute(GSXML.NODE_ID_ATT).equals(idToSearchFor)) 247 { 248 replacementElem = currentElem; 249 break; 250 } 251 } 252 253 if (replacementElem != null) 254 { 255 NodeList nodesToSearch = childStructure.getElementsByTagName(GSXML.CLASS_NODE_ELEM); 256 for (int i = 0; i < nodesToSearch.getLength(); i++) 257 { 258 Element currentElem = (Element) nodesToSearch.item(i); 259 if (currentElem.getAttribute(GSXML.NODE_ID_ATT).equals(idToSearchFor)) 260 { 261 Element parent = (Element) currentElem.getParentNode(); 262 parent.insertBefore(replacementElem, currentElem); 263 parent.removeChild(currentElem); 264 break; 265 } 266 } 267 268 cl_structure = childStructure; 269 } 270 } 271 } 272 202 273 Element page_classifier = null; 203 if (horizontal_at_top && !classifier_node.equals(top_id)) 204 { 205 // get the info for the top node 206 Element top_node = GSXML.getNamedElement(class_node_list, GSXML.CLASS_NODE_ELEM, GSXML.NODE_ID_ATT, top_id); 207 if (top_node != null) 208 { 209 path = GSPath.appendLink(GSXML.NODE_STRUCTURE_ELEM, GSXML.CLASS_NODE_ELEM); 210 Element top_structure = (Element) GSXML.getNodeByPath(top_node, path); 211 // add this as the classifier elem 212 page_classifier = GSXML.duplicateWithNewName(this.doc, top_structure, GSXML.CLASSIFIER_ELEM, true); 213 page_response.appendChild(page_classifier); 214 // now replace the child with the structure from the other request 215 Element new_classifier = (Element) GSXML.getChildByTagName(cl_structure, GSXML.CLASS_NODE_ELEM); 216 String replace_name = new_classifier.getAttribute(GSXML.NODE_ID_ATT); 217 218 // find the appropriate child 219 Element old_classifier = GSXML.getNamedElement(page_classifier, GSXML.CLASS_NODE_ELEM, GSXML.NODE_ID_ATT, replace_name); 220 page_classifier.replaceChild(this.doc.importNode(new_classifier, true), old_classifier); 221 page_classifier.setAttribute(GSXML.NAME_ATT, top_id); 222 } 223 else 224 { 225 // add the single classifier node as the page classifier 226 page_classifier = GSXML.duplicateWithNewName(this.doc, cl_structure, GSXML.CLASSIFIER_ELEM, true); 227 page_response.appendChild(page_classifier); 228 page_classifier.setAttribute(GSXML.NAME_ATT, top_id); 229 } 230 231 } 232 else 233 { 234 // add the single classifier node as the page classifier 235 page_classifier = GSXML.duplicateWithNewName(this.doc, cl_structure, GSXML.CLASSIFIER_ELEM, true); 236 page_response.appendChild(page_classifier); 237 page_classifier.setAttribute(GSXML.NAME_ATT, top_id); 238 } 274 // add the single classifier node as the page classifier 275 page_classifier = GSXML.duplicateWithNewName(this.doc, cl_structure, GSXML.CLASSIFIER_ELEM, true); 276 page_response.appendChild(page_classifier); 277 page_classifier.setAttribute(GSXML.NAME_ATT, top_id); 278 239 279 // get the metadata for each classifier node, 240 280 // then for each document node … … 359 399 } 360 400 401 private Element getClassifierStructureFromID(String id, Element request, String collection, String service_name) 402 { 403 UserContext userContext = new UserContext(request); 404 String to = GSPath.appendLink(collection, service_name); 405 406 Element firstClassifierNodeChildrenMessage = this.doc.createElement(GSXML.MESSAGE_ELEM); 407 Element firstClassifierNodeChildrenRequest = GSXML.createBasicRequest(this.doc, GSXML.REQUEST_TYPE_PROCESS, to, userContext); 408 firstClassifierNodeChildrenMessage.appendChild(firstClassifierNodeChildrenRequest); 409 410 Element paramList = this.doc.createElement(GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER); 411 firstClassifierNodeChildrenRequest.appendChild(paramList); 412 413 Element ancestorParam = this.doc.createElement(GSXML.PARAM_ELEM); 414 paramList.appendChild(ancestorParam); 415 ancestorParam.setAttribute(GSXML.NAME_ATT, "structure"); 416 ancestorParam.setAttribute(GSXML.VALUE_ATT, "ancestors"); 417 418 Element childrenParam = this.doc.createElement(GSXML.PARAM_ELEM); 419 paramList.appendChild(childrenParam); 420 childrenParam.setAttribute(GSXML.NAME_ATT, "structure"); 421 childrenParam.setAttribute(GSXML.VALUE_ATT, "children"); 422 423 Element classifierToGetList = this.doc.createElement(GSXML.CLASS_NODE_ELEM + GSXML.LIST_MODIFIER); 424 Element classifierToGet = this.doc.createElement(GSXML.CLASS_NODE_ELEM); 425 classifierToGet.setAttribute(GSXML.NODE_ID_ATT, id); 426 classifierToGetList.appendChild(classifierToGet); 427 firstClassifierNodeChildrenRequest.appendChild(classifierToGetList); 428 429 Element firstClassifierNodeChildrenResponse = (Element) this.mr.process(firstClassifierNodeChildrenMessage); 430 431 String nsPath = GSPath.appendLink(GSXML.RESPONSE_ELEM, GSXML.CLASS_NODE_ELEM + GSXML.LIST_MODIFIER); 432 Element topClassifierNode = (Element) GSXML.getNodeByPath(firstClassifierNodeChildrenResponse, nsPath); 433 nsPath = GSPath.appendLink(GSXML.CLASS_NODE_ELEM, GSXML.NODE_STRUCTURE_ELEM); 434 nsPath = GSPath.appendLink(nsPath, GSXML.CLASS_NODE_ELEM); 435 Element childStructure = (Element) GSXML.getNodeByPath(topClassifierNode, nsPath); 436 437 return childStructure; 438 } 439 361 440 protected void extractMetadataNames(Element new_format, HashSet<String> doc_meta_names, HashSet<String> class_meta_names) 362 441 {
Note:
See TracChangeset
for help on using the changeset viewer.