Changeset 37958 for main/trunk/greenstone3/src/java
- Timestamp:
- 2023-08-17T11:06:29+12:00 (9 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/GS2BrowseAction.java
r37901 r37958 218 218 { 219 219 220 //If we have a horizontal classifier and we have had the top-level node requested (e.g. CL1, CL2 etc.) 221 //then we want to get the children of the first classifier node (e.g. the children of CL2.1) 222 if (OID.isTop(classifier_node)) { 220 221 //If we have a horizontal classifier and we have had the top-level node requested (e.g. CL1, CL2 etc.) 222 //then we want to get the children of the first classifier node (e.g. the children of CL2.1) 223 if (OID.isTop(classifier_node)) { 223 224 224 boolean firstChildIsClassifierNode = false; 225 NodeList classifierChildrenNodes = GSXML.getChildrenByTagName(cl_structure, GSXML.CLASS_NODE_ELEM); 226 for (int i = 0; i < classifierChildrenNodes.getLength(); i++) 227 { 228 Element currentChild = (Element) classifierChildrenNodes.item(i); 229 if (currentChild.getAttribute(GSXML.NODE_ID_ATT).endsWith(".1")) 230 { 231 firstChildIsClassifierNode = true; 225 boolean firstChildIsClassifierNode = false; 226 NodeList classifierChildrenNodes = GSXML.getChildrenByTagName(cl_structure, GSXML.CLASS_NODE_ELEM); 227 for (int i = 0; i < classifierChildrenNodes.getLength(); i++) 228 { 229 Element currentChild = (Element) classifierChildrenNodes.item(i); 230 if (currentChild.getAttribute(GSXML.NODE_ID_ATT).endsWith(".1")) 231 { 232 firstChildIsClassifierNode = true; 233 } 234 } 235 236 if (firstChildIsClassifierNode) 237 { 238 // get the children of the first child 239 Element childStructure = getClassifierChildrenFromID(doc, classifier_node + ".1", request, collection, service_name); 240 241 // and now insert it into the structure we already have 242 NodeList nodesToSearch = cl_structure.getElementsByTagName(GSXML.CLASS_NODE_ELEM); 243 for (int i = 0; i < nodesToSearch.getLength(); i++) 244 { 245 Element currentElem = (Element) nodesToSearch.item(i); 246 if (currentElem.getAttribute(GSXML.NODE_ID_ATT).equals(classifier_node + ".1")) 247 { 248 Element parent = (Element) currentElem.getParentNode(); 249 parent.insertBefore(cl_struct_doc.importNode(childStructure, true), currentElem); 250 parent.removeChild(currentElem); 251 break; 252 } 253 } 254 } 255 } // if OID.isTop(classifier_node) 256 //If we have a horizontal classifier and we have NOT had the top-level node requested then we need to 257 //make sure we get the full list of top-level children to display (e.g. if the user has requested 258 //CL2.1.1 we also need to make sure we have CL2.2, CL2.3, CL2.4 etc.) 259 else 260 { 261 // we need to get siblings of any HList nodes so the HLists remain expanded in the display 262 // start at the bottom (the specified element) and work up teh list of parents expanding any that have hlists 263 NodeList elems = GSXML.getNamedElements(cl_structure, GSXML.CLASS_NODE_ELEM, GSXML.NODE_ID_ATT, classifier_node); 264 Element current_node = null; 265 String current_id = classifier_node; 266 if (elems != null) { 267 // there should only be one node in the list 268 current_node = (Element)elems.item(0); 269 } 270 if (current_node != null) { 271 Element parent_node = (Element)current_node.getParentNode(); 272 while(parent_node != null && parent_node.getNodeName().equals(GSXML.CLASS_NODE_ELEM)) { 273 if (((Element)parent_node).getAttribute(GSXML.CHILD_TYPE_ATT).equals(GSXML.HLIST)) { 274 // get the children of the parent 275 Element new_parent_elem = getClassifierChildrenFromID(cl_struct_doc, parent_node.getAttribute(GSXML.NODE_ID_ATT), request, collection, service_name); 276 277 // put current node into this new structure 278 Element to_be_replaced = GSXML.getNamedElement(new_parent_elem, GSXML.CLASS_NODE_ELEM, GSXML.NODE_ID_ATT, current_id); 279 if (to_be_replaced != null) { 280 new_parent_elem.insertBefore(current_node, to_be_replaced); 281 new_parent_elem.removeChild(to_be_replaced); 282 if (OID.isTop(parent_node.getAttribute(GSXML.NODE_ID_ATT))) { 283 // we can't go up any further. 284 cl_structure = new_parent_elem; 285 parent_node = null; 286 287 } else { 288 Element next_parent = (Element)parent_node.getParentNode(); 289 next_parent.insertBefore(new_parent_elem, parent_node ); 290 next_parent.removeChild(parent_node); 291 current_node = new_parent_elem; 292 current_id = current_node.getAttribute(GSXML.NODE_ID_ATT); 293 parent_node = next_parent; 294 } 295 } else { 296 // something went wrong, we'll stop this 297 parent_node = null; 232 298 } 299 } else { 300 current_node = parent_node; 301 current_id = current_node.getAttribute(GSXML.NODE_ID_ATT); 302 parent_node = (Element)current_node.getParentNode(); 303 } 233 304 } 234 235 if (firstChildIsClassifierNode) 236 { 237 // get the children of the first child 238 Element childStructure = getClassifierChildrenFromID(doc, classifier_node + ".1", request, collection, service_name); 239 240 // and now insert it into the structure we already have 241 NodeList nodesToSearch = cl_structure.getElementsByTagName(GSXML.CLASS_NODE_ELEM); 242 for (int i = 0; i < nodesToSearch.getLength(); i++) 243 { 244 Element currentElem = (Element) nodesToSearch.item(i); 245 if (currentElem.getAttribute(GSXML.NODE_ID_ATT).equals(classifier_node + ".1")) 246 { 247 Element parent = (Element) currentElem.getParentNode(); 248 parent.insertBefore(cl_struct_doc.importNode(childStructure, true), currentElem); 249 parent.removeChild(currentElem); 250 break; 251 } 252 } 253 } 254 } // if OID.isTop(classifier_node) 255 //If we have a horizontal classifier and we have NOT had the top-level node requested then we need to 256 //make sure we get the full list of top-level children to display (e.g. if the user has requested 257 //CL2.1.1 we also need to make sure we have CL2.2, CL2.3, CL2.4 etc.) 258 else 259 { 260 // we need to get siblings of any HList nodes so the HLists remain expanded in the display 261 // start at the bottom (the specified element) and work up teh list of parents expanding any that have hlists 262 NodeList elems = GSXML.getNamedElements(cl_structure, GSXML.CLASS_NODE_ELEM, GSXML.NODE_ID_ATT, classifier_node); 263 Element current_node = null; 264 String current_id = classifier_node; 265 if (elems != null) { 266 // there should only be one node in the list 267 current_node = (Element)elems.item(0); 268 } 269 if (current_node != null) { 270 Element parent_node = (Element)current_node.getParentNode(); 271 while(parent_node != null && parent_node.getNodeName().equals(GSXML.CLASS_NODE_ELEM)) { 272 if (((Element)parent_node).getAttribute(GSXML.CHILD_TYPE_ATT).equals(GSXML.HLIST)) { 273 // get the children of the parent 274 Element new_parent_elem = getClassifierChildrenFromID(cl_struct_doc, parent_node.getAttribute(GSXML.NODE_ID_ATT), request, collection, service_name); 275 276 // put current node into this new structure 277 Element to_be_replaced = GSXML.getNamedElement(new_parent_elem, GSXML.CLASS_NODE_ELEM, GSXML.NODE_ID_ATT, current_id); 278 if (to_be_replaced != null) { 279 new_parent_elem.insertBefore(current_node, to_be_replaced); 280 new_parent_elem.removeChild(to_be_replaced); 281 if (OID.isTop(parent_node.getAttribute(GSXML.NODE_ID_ATT))) { 282 // we can't go up any further. 283 cl_structure = new_parent_elem; 284 parent_node = null; 285 286 } else { 287 Element next_parent = (Element)parent_node.getParentNode(); 288 next_parent.insertBefore(new_parent_elem, parent_node ); 289 next_parent.removeChild(parent_node); 290 current_node = new_parent_elem; 291 current_id = current_node.getAttribute(GSXML.NODE_ID_ATT); 292 parent_node = next_parent; 293 } 294 } else { 295 // something went wrong, we'll stop this 296 parent_node = null; 297 } 298 } else { 299 current_node = parent_node; 300 current_id = current_node.getAttribute(GSXML.NODE_ID_ATT); 301 parent_node = (Element)current_node.getParentNode(); 302 } 303 } 304 } // if current_node != null 305 } // if current_node != null 305 306 306 307 } 307 308 } 308 309
Note:
See TracChangeset
for help on using the changeset viewer.