Ignore:
Timestamp:
2023-08-17T11:40:41+12:00 (10 months ago)
Author:
kjdon
Message:

when we have HLists we always want to get all the siblings along the HList, not just only when the top level classifier node is an HList. As we could have HList inside a VList

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/GS2BrowseAction.java

    r37958 r37959  
    214214
    215215        // cl_structure is the classifier structure containing ancestors and children of current node.
    216         // this test means that we won't do the right thing if we happened to have an HList inside a VList. Should really be testing to see if any nodes are HLists...
    217         if (cl_structure.getAttribute(GSXML.CHILD_TYPE_ATT).equals(GSXML.HLIST))
    218         {
    219      
    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)) {
    224            
    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"))
     216
     217        //If we have a horizontal classifier and we have had the top-level node requested (e.g. CL1, CL2 etc.)
     218        //then we want to get the children of the first classifier node (e.g. the children of CL2.1)
     219        if (OID.isTop(classifier_node) && cl_structure.getAttribute(GSXML.CHILD_TYPE_ATT).equals(GSXML.HLIST)) {
     220            boolean firstChildIsClassifierNode = false;
     221            NodeList classifierChildrenNodes = GSXML.getChildrenByTagName(cl_structure, GSXML.CLASS_NODE_ELEM);
     222            for (int i = 0; i < classifierChildrenNodes.getLength(); i++)
     223            {
     224                Element currentChild = (Element) classifierChildrenNodes.item(i);
     225                if (currentChild.getAttribute(GSXML.NODE_ID_ATT).endsWith(".1"))
     226                {
     227                    firstChildIsClassifierNode = true;
     228                }
     229            }
     230
     231            if (firstChildIsClassifierNode)
     232            {
     233                // get the children of the first child
     234                Element childStructure = getClassifierChildrenFromID(doc, classifier_node + ".1", request, collection, service_name);
     235
     236                // and now insert it into the structure we already have
     237                NodeList nodesToSearch = cl_structure.getElementsByTagName(GSXML.CLASS_NODE_ELEM);
     238                for (int i = 0; i < nodesToSearch.getLength(); i++)
     239                {
     240                    Element currentElem = (Element) nodesToSearch.item(i);
     241                    if (currentElem.getAttribute(GSXML.NODE_ID_ATT).equals(classifier_node + ".1"))
     242                    {
     243                        Element parent = (Element) currentElem.getParentNode();
     244                        parent.insertBefore(cl_struct_doc.importNode(childStructure, true), currentElem);
     245                        parent.removeChild(currentElem);
     246                        break;
     247                    }
     248                }
     249            }
     250        } // if OID.isTop(classifier_node) && we are an HList
     251        //If we have a horizontal classifier and we have NOT had the top-level node requested then we need to
     252        //make sure we get the full list of top-level children to display (e.g. if the user has requested
     253        //CL2.1.1 we also need to make sure we have CL2.2, CL2.3, CL2.4 etc.)
     254        else
     255            {
     256            // we need to get siblings of any HList nodes so the HLists remain expanded in the display
     257            // start at the bottom (the specified element) and work up teh list of parents expanding any that have hlists
     258            NodeList elems = GSXML.getNamedElements(cl_structure, GSXML.CLASS_NODE_ELEM, GSXML.NODE_ID_ATT, classifier_node);
     259            Element current_node = null;
     260            String current_id = classifier_node;
     261            if (elems != null) {
     262                // there should only be one node in the list
     263                current_node = (Element)elems.item(0);
     264            }
     265            if (current_node != null) {
     266                if (current_node.getAttribute(GSXML.CHILD_TYPE_ATT).equals(GSXML.HLIST)) {
     267
     268                        boolean firstChildIsClassifierNode = false;
     269                NodeList classifierChildrenNodes = GSXML.getChildrenByTagName(current_node, GSXML.CLASS_NODE_ELEM);
     270                for (int i = 0; i < classifierChildrenNodes.getLength(); i++)
    231271                    {
    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"))
     272
     273                    Element currentChild = (Element) classifierChildrenNodes.item(i);
     274               
     275                    if (currentChild.getAttribute(GSXML.NODE_ID_ATT).endsWith(".1"))
    247276                        {
    248                         Element parent = (Element) currentElem.getParentNode();
    249                         parent.insertBefore(cl_struct_doc.importNode(childStructure, true), currentElem);
    250                         parent.removeChild(currentElem);
     277                        firstChildIsClassifierNode = true;
    251278                        break;
    252279                        }
    253280                    }
    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;
     281
     282                if (firstChildIsClassifierNode)
     283                    {
     284
     285                    // get the children of the first child
     286                    Element childStructure = getClassifierChildrenFromID(doc, classifier_node + ".1", request, collection, service_name);
     287
     288                    // and now insert it into the structure we already have
     289                    NodeList nodesToSearch = cl_structure.getElementsByTagName(GSXML.CLASS_NODE_ELEM);
     290                    for (int i = 0; i < nodesToSearch.getLength(); i++)
     291                        {
     292                        Element currentElem = (Element) nodesToSearch.item(i);
     293                        if (currentElem.getAttribute(GSXML.NODE_ID_ATT).equals(classifier_node + ".1"))
     294                            {
     295                            Element parent = (Element) currentElem.getParentNode();
     296                            parent.insertBefore(cl_struct_doc.importNode(childStructure, true), currentElem);
     297                            parent.removeChild(currentElem);
     298                            break;
     299                            }
    294300                        }
     301                    }
     302                //**
     303                } // current_node is an HList
     304                Element parent_node = (Element)current_node.getParentNode();
     305                while(parent_node != null && parent_node.getNodeName().equals(GSXML.CLASS_NODE_ELEM)) {
     306       
     307                if (((Element)parent_node).getAttribute(GSXML.CHILD_TYPE_ATT).equals(GSXML.HLIST)) {
     308                    // get the children of the parent
     309                    Element new_parent_elem = getClassifierChildrenFromID(cl_struct_doc, parent_node.getAttribute(GSXML.NODE_ID_ATT), request, collection, service_name);
     310
     311                    // put current node into this new structure
     312                    Element to_be_replaced = GSXML.getNamedElement(new_parent_elem, GSXML.CLASS_NODE_ELEM, GSXML.NODE_ID_ATT, current_id);
     313                    if (to_be_replaced != null) {
     314                    new_parent_elem.insertBefore(current_node, to_be_replaced);
     315                    new_parent_elem.removeChild(to_be_replaced);
     316                   
     317                   
     318                    if (OID.isTop(parent_node.getAttribute(GSXML.NODE_ID_ATT))) {
     319                       
     320                        // we can't go up any further.
     321                        cl_structure = new_parent_elem;
     322                        parent_node = null;
     323                       
    295324                    } else {
    296                         // something went wrong, we'll stop this
    297                         parent_node = null;
     325                        Element next_parent = (Element)parent_node.getParentNode();
     326                        next_parent.insertBefore(new_parent_elem, parent_node );
     327                        next_parent.removeChild(parent_node);
     328                        current_node = new_parent_elem;
     329                        current_id = current_node.getAttribute(GSXML.NODE_ID_ATT);
     330                        parent_node = next_parent;
    298331                    }
    299332                    } else {
    300                     current_node = parent_node;
    301                     current_id = current_node.getAttribute(GSXML.NODE_ID_ATT);
    302                     parent_node = (Element)current_node.getParentNode();
     333                    // something went wrong, we'll stop this
     334                    parent_node = null;
    303335                    }
    304                 }
    305                 } // if current_node != null
    306              
    307             }
    308         }
    309 
    310         Element page_classifier = null;
     336                } // end of if HList
     337                else {
     338                    current_node = parent_node;
     339                    current_id = current_node.getAttribute(GSXML.NODE_ID_ATT);
     340                    parent_node = (Element)current_node.getParentNode();
     341                }
     342
     343                } // while parent != null
     344            } // if current_node != null
     345            } // end of else
     346   
     347
     348          Element page_classifier = null;
    311349        // add the single classifier node as the page classifier
    312350        page_classifier = GSXML.duplicateWithNewName(doc, cl_structure, GSXML.CLASSIFIER_ELEM, true);
     
    434472        logger.debug("(GS2BrowseAction) Page:\n" + this.converter.getPrettyString(page_response));
    435473        return page_response;
    436     }
     474            }
    437475
    438476    private Element getClassifierChildrenFromID(Document doc, String id, Element request, String collection, String service_name)
Note: See TracChangeset for help on using the changeset viewer.