Changeset 22308


Ignore:
Timestamp:
2010-06-26T19:11:44+12:00 (11 years ago)
Author:
ak19
Message:

Implemented and tested Browse structure retrieve for 'siblings'.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • other-projects/gs3-webservices-java-client/trunk/src/GS3Fedora/org/greenstone/fedora/services/FedoraGS3Connection.java

    r22302 r22308  
    17831783     * @param classifierID - the ID of the (sub)classifier. Can be CL1, CL1.x, where x is
    17841784     * a letter.
    1785      * @param structure - the requested browse substructure. Can be any combination
    1786      * of ancestors, parent, siblings, children, descendants. siblings not yet implemented.
     1785     * @param structure - the requested browse substructure. Can be any combination of
     1786     * ancestors, parent, siblings, children, descendants. 'siblings' not yet implemented.
    17871787     * @param info - the requested structural info. Can be numSiblings, siblingPosition,
    17881788     * numChildren.
     
    17951795    FedoraGS3RunException ex = null; //any RemoteException or UnsupportedEncodingException
    17961796
    1797     // TODO
    1798     if(structure.indexOf("siblings") != -1) {
    1799         LOG.error("Structure: siblings. Not yet implemented\n");
    1800     }
    1801 
    18021797    if(structure.indexOf("entire") != -1) {
    18031798        structure = structure + "ancestors|descendants";
     
    18251820        nodeStructure.appendChild(root);
    18261821        if(structure.indexOf("descendants") != -1) {
    1827         getTitlesByLetterStructure(collectionName, root, classifierID, true);
     1822        getTitlesByLetterStructure(collectionName, root, classifierID, true, null);
    18281823        } else if(structure.indexOf("children") != -1) {
    1829         getTitlesByLetterStructure(collectionName, root, classifierID, false);
     1824        getTitlesByLetterStructure(collectionName, root, classifierID, false, null);
    18301825        }
     1826        // nothing to be done for siblings
    18311827    }
    18321828    else if(firstLevel == secondLevel) { // CL1.x, where x is a number
    18331829       
    1834         if(structure.indexOf("parent") != -1 || structure.indexOf("ancestors") != -1) {
     1830        if(structure.indexOf("parent") != -1
     1831           || structure.indexOf("ancestors") != -1
     1832           || structure.indexOf("siblings") != -1) {
    18351833        String toplevelID = classifierID.substring(0, firstLevel);
    18361834        Element toplevelNode = doc.createElement(GSXML.CLASS_NODE_ELEM);
     
    18421840        classifierNodeList.appendChild(toplevelNode);
    18431841        toplevelNode.appendChild(nodeStructure);       
    1844            
    18451842        nodeStructure.appendChild(node);
    1846         node.appendChild(classNode);
     1843
     1844        if(structure.indexOf("siblings") != -1) { // get the children of the parents too
     1845            getTitlesByLetterStructure(collectionName, node, toplevelID, false, classNode);
     1846            // pass the requested node (classNode) so that it is attached in the correct
     1847            // location among its siblings, and to ensure that it is not recreated.
     1848            // getTitlesByLetterStructure() will append classNode to node
     1849        } else {
     1850            node.appendChild(classNode);
     1851        }
    18471852        } else {
    18481853        Element node = (Element)classNode.cloneNode(true);
     
    19261931     * @param getDescendants - if true, get descendants of any documents found, otherwise
    19271932     * get just the children.
     1933     * @param wantedSibling - the node (already created) whose siblings are requested. We
     1934     * need to make sure not to recreate this node when creating its sibling nodes.
    19281935     * @return the given classifierNode, with the CL.x subclassifiers for the letters of
    19291936     * the alphabet that are represented in the document titles.
    19301937     */
    19311938    public Element getTitlesByLetterStructure(String collectionName, Element classifierNode,
    1932                            String classifierID, boolean getDescendants)
    1933     {
     1939                          String classifierID, boolean getDescendants,
     1940                          Element wantedSibling)
     1941    {   
     1942    String ID = "";
     1943    if(wantedSibling != null) { // the pre-created classifier node whose siblings were requested
     1944        ID = wantedSibling.getAttribute(GSXML.NODE_ID_ATT);
     1945    }
     1946   
    19341947    Document doc = classifierNode.getOwnerDocument();
    19351948    FedoraGS3RunException ex = null; // any RemoteException or UnsupportedEncodingException
     
    19461959            continue; // skip letters that don't have any kids
    19471960        }
    1948        
    1949         // <classifierNode nodeID="CL1.x">
    1950         Element subClassifier = doc.createElement(GSXML.CLASS_NODE_ELEM);
    1951         Attr attribute = doc.createAttribute(GSXML.NODE_ID_ATT);
    1952         attribute.setValue(classifierID+"."+count);
    1953         subClassifier.setAttributeNode(attribute);
    1954         classifierNode.appendChild(subClassifier);
     1961        Element subClassifier = null;
     1962        if(wantedSibling != null && ID.equals(classifierID+"."+count)) {
     1963                // already have the requested node, don't recreate it
     1964            subClassifier = wantedSibling;
     1965        } else {
     1966            // <classifierNode nodeID="CL1.x">
     1967            subClassifier = doc.createElement(GSXML.CLASS_NODE_ELEM);
     1968            Attr attribute = doc.createAttribute(GSXML.NODE_ID_ATT);
     1969            attribute.setValue(classifierID+"."+count);
     1970            subClassifier.setAttributeNode(attribute);
     1971        }
     1972        classifierNode.appendChild(subClassifier); // either way, append the subClassifier node
    19551973       
    19561974        if(getDescendants) { // get the documents
Note: See TracChangeset for help on using the changeset viewer.