Ignore:
Timestamp:
2012-04-19T15:36:31+12:00 (12 years ago)
Author:
sjm84
Message:

Reformatting this file ahead of some changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/AbstractDocumentRetrieve.java

    r25354 r25428  
    7272
    7373    // means the id is not a greenstone id and needs translating
    74   //    protected static final String EXTID_PARAM = "ext";
     74    //  protected static final String EXTID_PARAM = "ext";
    7575
    7676    protected Element config_info = null; // the xml from the config file
     
    148148            macro_resolver.setSiteDetails(this.site_http_address, this.cluster_name, this.getLibraryName());
    149149            // set up the macro resolver
    150             Element replacement_elem = (Element) GSXML.getChildByTagName(extra_info, GSXML.REPLACE_ELEM+GSXML.LIST_MODIFIER);
     150            Element replacement_elem = (Element) GSXML.getChildByTagName(extra_info, GSXML.REPLACE_ELEM + GSXML.LIST_MODIFIER);
    151151            if (replacement_elem != null)
    152152            {
     
    154154            }
    155155            // look for any refs to global replace lists
    156             NodeList replace_refs_elems = extra_info.getElementsByTagName(GSXML.REPLACE_ELEM+GSXML.LIST_MODIFIER+GSXML.REF_MODIFIER);
     156            NodeList replace_refs_elems = extra_info.getElementsByTagName(GSXML.REPLACE_ELEM + GSXML.LIST_MODIFIER + GSXML.REF_MODIFIER);
    157157            for (int i = 0; i < replace_refs_elems.getLength(); i++)
    158158            {
     
    160160                if (!id.equals(""))
    161161                {
    162                     Element replace_list = GSXML.getNamedElement(this.router.config_info, GSXML.REPLACE_ELEM+GSXML.LIST_MODIFIER, "id", id);
     162                    Element replace_list = GSXML.getNamedElement(this.router.config_info, GSXML.REPLACE_ELEM + GSXML.LIST_MODIFIER, "id", id);
    163163                    if (replace_list != null)
    164164                    {
     
    222222                metadata_names_list.add(metadata);
    223223            }
    224            
     224
    225225            param = (Element) param.getNextSibling();
    226226        }
     
    260260            String node_id = request_node.getAttribute(GSXML.NODE_ID_ATT);
    261261            boolean is_href_id = false;
    262             if (node_id.equals("")) {
    263               node_id = getGreenstoneIdFromHref(request_node);
    264               if(node_id == null) {
    265                 // **** TODO, is this good enough???
    266                 request_node.setAttribute("external_link", "true");
    267                 continue;
    268               }
    269              
     262            if (node_id.equals(""))
     263            {
     264                node_id = getGreenstoneIdFromHref(request_node);
     265                if (node_id == null)
     266                {
     267                    // **** TODO, is this good enough???
     268                    request_node.setAttribute("external_link", "true");
     269                    continue;
     270                }
     271
    270272            }
    271273
     
    273275            if (idNeedsTranslating(node_id))
    274276            {
    275                 node_id = translateId(node_id);
    276             }
    277            
     277                node_id = translateId(node_id);
     278            }
     279
    278280            if (node_id == null)
    279281            {
     
    281283            }
    282284            try
    283               {
    284                 Element metadata_list = getMetadataList(node_id, all_metadata, metadata_names_list);
    285                 if(metadata_list != null)
    286                   {
    287                 request_node.appendChild(metadata_list);
    288                   }
    289               }
     285            {
     286                Element metadata_list = getMetadataList(node_id, all_metadata, metadata_names_list);
     287                if (metadata_list != null)
     288                {
     289                    request_node.appendChild(metadata_list);
     290                }
     291            }
    290292            catch (GSException e)
    291               {
    292                 GSXML.addError(this.doc, result, e.getMessage(), e.getType());
    293                 if (e.getType().equals(GSXML.ERROR_TYPE_SYSTEM))
    294                   {
    295                 // there is no point trying any others
    296                 return result;
    297                   }
    298               }
    299        
    300            
     293            {
     294                GSXML.addError(this.doc, result, e.getMessage(), e.getType());
     295                if (e.getType().equals(GSXML.ERROR_TYPE_SYSTEM))
     296                {
     297                    // there is no point trying any others
     298                    return result;
     299                }
     300            }
     301
    301302        } // for each doc node
    302303
     
    409410            String doc_id = doc.getAttribute(GSXML.NODE_ID_ATT);
    410411            boolean is_href_id = false;
    411             if (doc_id.equals("")) {
    412               doc_id = getGreenstoneIdFromHref(doc);
    413               if(doc_id == null) {
    414                 // **** TODO, is this good enough???
    415                 doc.setAttribute("external_link", "true");
    416                 continue;
    417               }
    418               doc.setAttribute(GSXML.NODE_ID_ATT, doc_id);
     412            if (doc_id.equals(""))
     413            {
     414                doc_id = getGreenstoneIdFromHref(doc);
     415                if (doc_id == null)
     416                {
     417                    // **** TODO, is this good enough???
     418                    doc.setAttribute("external_link", "true");
     419                    continue;
     420                }
     421                doc.setAttribute(GSXML.NODE_ID_ATT, doc_id);
    419422            }
    420423
    421424            if (idNeedsTranslating(doc_id))
    422               {
    423                 doc_id = translateId(doc_id);
    424                 doc.setAttribute(GSXML.NODE_ID_ATT, doc_id);
    425               }
     425            {
     426                doc_id = translateId(doc_id);
     427                doc.setAttribute(GSXML.NODE_ID_ATT, doc_id);
     428            }
    426429
    427430            if (doc_id == null)
    428               {
    429                 continue;
    430               }
    431 
    432                 if (want_info)
    433                 {
    434                     Element node_info_elem = this.doc.createElement("nodeStructureInfo");
    435                     doc.appendChild(node_info_elem);
    436 
    437                     for (int j = 0; j < info_types.size(); j++)
     431            {
     432                continue;
     433            }
     434
     435            if (want_info)
     436            {
     437                Element node_info_elem = this.doc.createElement("nodeStructureInfo");
     438                doc.appendChild(node_info_elem);
     439
     440                for (int j = 0; j < info_types.size(); j++)
     441                {
     442                    String info_type = (String) info_types.get(j);
     443                    String info_value = getStructureInfo(doc_id, info_type);
     444                    if (info_value != null)
    438445                    {
    439                         String info_type = (String) info_types.get(j);
    440                         String info_value = getStructureInfo(doc_id, info_type);
    441                         if (info_value != null)
    442                         {
    443                             Element info_elem = this.doc.createElement("info");
    444                             info_elem.setAttribute(GSXML.NAME_ATT, info_type);
    445                             info_elem.setAttribute(GSXML.VALUE_ATT, info_value);
    446                             node_info_elem.appendChild(info_elem);
    447                         }
     446                        Element info_elem = this.doc.createElement("info");
     447                        info_elem.setAttribute(GSXML.NAME_ATT, info_type);
     448                        info_elem.setAttribute(GSXML.VALUE_ATT, info_value);
     449                        node_info_elem.appendChild(info_elem);
    448450                    }
    449451                }
    450 
    451                 if (want_structure)
    452                 {
    453                     // all structure info goes into a nodeStructure elem
    454                     Element structure_elem = this.doc.createElement(GSXML.NODE_STRUCTURE_ELEM);
    455                     doc.appendChild(structure_elem);
    456 
    457                     if (want_entire_structure)
     452            }
     453
     454            if (want_structure)
     455            {
     456                // all structure info goes into a nodeStructure elem
     457                Element structure_elem = this.doc.createElement(GSXML.NODE_STRUCTURE_ELEM);
     458                doc.appendChild(structure_elem);
     459
     460                if (want_entire_structure)
     461                {
     462                    String root_id = getRootId(doc_id);
     463                    Element root_node = createDocNode(root_id); //, true, false);
     464                    addDescendants(root_node, root_id, true);
     465                    structure_elem.appendChild(root_node);
     466                    continue; // with the next document, we dont need to do any more here
     467                }
     468
     469                // Add the requested structure information
     470                Element base_node = createDocNode(doc_id); //, false, false);
     471
     472                //Ancestors: continually add parent nodes until the root is reached
     473                Element top_node = base_node; // the top node so far
     474                if (want_ancestors)
     475                {
     476                    String current_id = doc_id;
     477                    while (true)
    458478                    {
    459                         String root_id = getRootId(doc_id);
    460                         Element root_node = createDocNode(root_id); //, true, false);
    461                         addDescendants(root_node, root_id, true);
    462                         structure_elem.appendChild(root_node);
    463                         continue; // with the next document, we dont need to do any more here
     479                        String parent_id = getParentId(current_id);
     480                        //Element parent = getParent(current_id);
     481                        if (parent_id == null)
     482                            break; // no parent
     483                        Element parent_node = createDocNode(parent_id);
     484                        parent_node.appendChild(top_node);
     485                        current_id = parent_id;//.getAttribute(GSXML.NODE_ID_ATT);
     486                        top_node = parent_node;
    464487                    }
    465 
    466                     // Add the requested structure information
    467                     Element base_node = createDocNode(doc_id); //, false, false);
    468 
    469                     //Ancestors: continually add parent nodes until the root is reached
    470                     Element top_node = base_node; // the top node so far
    471                     if (want_ancestors)
     488                }
     489                // Parent: get the parent of the selected node
     490                else if (want_parent)
     491                {
     492                    String parent_id = getParentId(doc_id);
     493                    if (parent_id != null)
    472494                    {
    473                         String current_id = doc_id;
    474                         while (true)
    475                         {
    476                             String parent_id = getParentId(current_id);
    477                             //Element parent = getParent(current_id);
    478                             if (parent_id == null)
    479                                 break; // no parent
    480                             Element parent_node = createDocNode(parent_id);
    481                             parent_node.appendChild(top_node);
    482                             current_id = parent_id;//.getAttribute(GSXML.NODE_ID_ATT);
    483                             top_node = parent_node;
    484                         }
     495                        Element parent_node = createDocNode(parent_id);
     496                        parent_node.appendChild(base_node);
     497                        top_node = parent_node;
    485498                    }
    486                     // Parent: get the parent of the selected node
    487                     else if (want_parent)
     499                }
     500
     501                // now the top node is the root of the structure
     502                structure_elem.appendChild(top_node);
     503
     504                //Siblings: get the other descendants of the selected node's parent
     505                if (want_siblings)
     506                {
     507                    String parent_id = getParentId(doc_id);
     508                    if (parent_id != null)
    488509                    {
    489                         String parent_id = getParentId(doc_id);
    490                         if (parent_id != null)
    491                         {
    492                             Element parent_node = createDocNode(parent_id);
    493                             parent_node.appendChild(base_node);
    494                             top_node = parent_node;
    495                         }
     510                        // if parent == current id, then we are at the top
     511                        // and can't get siblings
     512                        Element parent_node = (Element) base_node.getParentNode(); // this may be the structure element if there has been no request for parents or ancestors
     513
     514                        // add siblings, - returns a pointer to the new current node
     515                        base_node = addSiblings(parent_node, parent_id, doc_id);
    496516                    }
    497517
    498                     // now the top node is the root of the structure
    499                     structure_elem.appendChild(top_node);
    500 
    501                     //Siblings: get the other descendants of the selected node's parent
    502                     if (want_siblings)
    503                     {
    504                         String parent_id = getParentId(doc_id);
    505                         if (parent_id != null)
    506                         {
    507                             // if parent == current id, then we are at the top
    508                             // and can't get siblings
    509                             Element parent_node = (Element) base_node.getParentNode(); // this may be the structure element if there has been no request for parents or ancestors
    510 
    511                             // add siblings, - returns a pointer to the new current node
    512                             base_node = addSiblings(parent_node, parent_id, doc_id);
    513                         }
    514 
    515                     }
    516 
    517                     // Children: get the descendants, but only one level deep
    518                     if (want_children)
    519                     {
    520                         addDescendants(base_node, doc_id, false);
    521                     }
    522                     // Descendants: recursively get every descendant
    523                     else if (want_descendants)
    524                     {
    525                         addDescendants(base_node, doc_id, true);
    526                     }
    527                 } // if want structure
    528 
    529                
     518                }
     519
     520                // Children: get the descendants, but only one level deep
     521                if (want_children)
     522                {
     523                    addDescendants(base_node, doc_id, false);
     524                }
     525                // Descendants: recursively get every descendant
     526                else if (want_descendants)
     527                {
     528                    addDescendants(base_node, doc_id, true);
     529                }
     530            } // if want structure
     531
    530532        } // for each doc
    531533        return result;
     
    583585            String node_id = request_node.getAttribute(GSXML.NODE_ID_ATT);
    584586            boolean is_href_id = false;
    585             if (node_id.equals("")) {
    586               node_id = getGreenstoneIdFromHref(request_node);
    587               if(node_id == null) {
    588                 // **** TODO, is this good enough???
    589                 request_node.setAttribute("external_link", "true");
    590                 continue;
    591               }
    592              
     587            if (node_id.equals(""))
     588            {
     589                node_id = getGreenstoneIdFromHref(request_node);
     590                if (node_id == null)
     591                {
     592                    // **** TODO, is this good enough???
     593                    request_node.setAttribute("external_link", "true");
     594                    continue;
     595                }
     596
    593597            }
    594598
     
    596600            if (idNeedsTranslating(node_id))
    597601            {
    598                 node_id = translateId(node_id);
    599             }
    600            
     602                node_id = translateId(node_id);
     603            }
     604
    601605            if (node_id == null)
    602606            {
     
    604608            }
    605609            try
    606               {
    607                 Element node_content = getNodeContent(node_id, lang);
    608                 request_node.appendChild(node_content);
    609               }
     610            {
     611                Element node_content = getNodeContent(node_id, lang);
     612                request_node.appendChild(node_content);
     613            }
    610614            catch (GSException e)
    611               {
    612                 GSXML.addError(this.doc, result, e.getMessage());
    613                 return result;
    614                
    615               }
     615            {
     616                GSXML.addError(this.doc, result, e.getMessage());
     617                return result;
     618
     619            }
    616620        } // for each node
    617621        return result;
     
    757761    }
    758762
    759   protected String getGreenstoneIdFromHref(Element doc_node)
    760   {
    761     String node_id = doc_node.getAttribute(GSXML.HREF_ID_ATT);
    762     node_id = translateExternalId(node_id);
    763     if (node_id == null) {
    764       return node_id;
    765     }
    766     // check for id modifiers
    767     String id_mods = doc_node.getAttribute(GSXML.ID_MOD_ATT);
    768     if (!id_mods.equals("")) {
    769       node_id = node_id+id_mods;
    770     }
    771     return node_id;
    772   }
     763    protected String getGreenstoneIdFromHref(Element doc_node)
     764    {
     765        String node_id = doc_node.getAttribute(GSXML.HREF_ID_ATT);
     766        node_id = translateExternalId(node_id);
     767        if (node_id == null)
     768        {
     769            return node_id;
     770        }
     771        // check for id modifiers
     772        String id_mods = doc_node.getAttribute(GSXML.ID_MOD_ATT);
     773        if (!id_mods.equals(""))
     774        {
     775            node_id = node_id + id_mods;
     776        }
     777        return node_id;
     778    }
     779
    773780    /**
    774781     * returns the document type of the doc that the specified node belongs to.
Note: See TracChangeset for help on using the changeset viewer.