Changeset 8828


Ignore:
Timestamp:
2004-12-16T15:27:06+13:00 (19 years ago)
Author:
kjdon
Message:

checking a lot more for null results from database, so hopefully wont crap out if we ask for a document that doesn't exist

Location:
trunk/gsdl3/src/java/org/greenstone/gsdl3/service
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGRetrieve.java

    r8674 r8828  
    122122    for (int i = 0; i < doc_ids.length; i++) {
    123123        String doc_id = doc_ids[i];
     124        // Create the document node
     125        Element doc = this.doc.createElement(GSXML.DOC_NODE_ELEM);
     126        doc.setAttribute(GSXML.NODE_ID_ATT, doc_id);
     127        doc_list.appendChild(doc);
     128       
    124129        System.err.println("doc id= "+doc_id);
    125130        if (extlink) {
     
    131136        } else {
    132137            doc_id = this.gdbm_src.extlink2OID(doc_id);
    133 
    134138        }
     139        if (doc_id == null) {
     140            System.err.println("extlink "+doc_id +" couldn't be converted to proper id");
     141            continue;
     142        }
     143        doc.setAttribute(GSXML.NODE_ID_ATT, doc_id); // reset the att cos it may have changed
     144           
    135145        }
    136146        else if (OID.needsTranslating(doc_id)) {
    137147        doc_id = this.gdbm_src.translateOID(doc_id);
     148        doc.setAttribute(GSXML.NODE_ID_ATT, doc_id); // reset the att cos it may have changed
    138149        }
    139         System.err.println("remaining dco id = "+doc_id);
     150       
     151        System.err.println("remaining doc id = "+doc_id);
    140152        long doc_num = this.gdbm_src.OID2Docnum(doc_id);
    141 
     153        if (doc_num == -1) {
     154        System.err.println("OID "+doc_id +" couldn't be converted to mg num");
     155        continue;
     156        }
    142157        String doc_content = this.mg_src.getDocument(basedir, textdir, doc_num);
    143         // Create the  text node
    144         Element doc = this.doc.createElement(GSXML.DOC_NODE_ELEM);
    145         doc.setAttribute(GSXML.NODE_ID_ATT, doc_id);
    146         doc_list.appendChild(doc);
    147158       
    148159        if (doc_content!=null) {
     
    151162        //System.err.println("doc content "+doc_content);
    152163        doc_content = doc_content.replaceAll("\u0002|\u0003", "");
     164        System.err.println("replaced ctrl b");
    153165        // replace _httpimg_ with the correct address
    154166        doc_content = resolveTextMacros(doc_content, doc_id, lang);
     167        System.err.println("resolved text macros");
    155168        GSXML.addDocText(this.doc, doc, doc_content);
     169        System.err.println("added text");
    156170        } else {
    157171        System.err.println("the doc content was null, not getting that section\n");
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2Retrieve.java

    r8823 r8828  
    379379     * child is true is it definitely is a child of something - just for efficiency purposes */
    380380    protected Element createDocNode(String node_id, boolean parent, boolean child) {
     381   
    381382    // create this here or pass it in?
    382383    DBInfo info = this.gdbm_src.getInfo(node_id);
     
    410411    }
    411412 
     413    if (info==null) {
     414        node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
     415        node.setAttribute(GSXML.NODE_ID_ATT, node_id);
     416        return node;
     417    }
    412418    String top_id = OID.getTop(node_id);
    413419    boolean is_top = (top_id.equals(node_id) ? true : false);
     
    436442            info = this.gdbm_src.getInfo(top_id);
    437443        }
    438        
    439         String childtype = info.getInfo("childtype");
    440         if (childtype.equals("Paged")) {
    441             node.setAttribute(GSXML.DOC_TYPE_ATT, "paged");
    442         } else {
    443             node.setAttribute(GSXML.DOC_TYPE_ATT, "hierarchy");
     444        if (info != null) {
     445            String childtype = info.getInfo("childtype");
     446            if (childtype.equals("Paged")) {
     447            node.setAttribute(GSXML.DOC_TYPE_ATT, "paged");
     448            } else {
     449            node.setAttribute(GSXML.DOC_TYPE_ATT, "hierarchy");
     450            }
    444451        }
    445452        }
     
    481488    {
    482489    DBInfo info = this.gdbm_src.getInfo(doc_id);
     490    if (info == null) {
     491        return;
     492    }
    483493    String contains = info.getInfo("contains");
    484494
     
    525535    {
    526536    DBInfo info = this.gdbm_src.getInfo(oid);
     537    if (info == null) {
     538        return true; // or should it be false?
     539    }
    527540    String children = info.getInfo("contains");
    528541    return (children.equals(""));
     
    639652                                GSXML.NODE_ID_ATT);
    640653    for (int i = 0; i < doc_ids.length; i++) {
    641         String doc_id = doc_ids[i];
    642        
    643         if (OID.needsTranslating(doc_id)) {
    644         doc_id = this.gdbm_src.translateOID(doc_id);
    645         }
    646 
    647654        // Add the document to the list
    648655        Element doc = this.doc.createElement(node_name);
    649656        doc_list.appendChild(doc);
     657
     658        String doc_id = doc_ids[i];
    650659        doc.setAttribute(GSXML.NODE_ID_ATT, doc_id);
    651 
     660       
     661        if (OID.needsTranslating(doc_id)) {
     662        doc_id = this.gdbm_src.translateOID(doc_id);
     663        if (doc_id == null) {
     664            continue;
     665        }
     666        doc.setAttribute(GSXML.NODE_ID_ATT, doc_id);
     667        }
    652668       
    653669        if (want_info) {
     
    798814        Element request_node = (Element) request_nodes.item(i);
    799815        String node_id = request_node.getAttribute(GSXML.NODE_ID_ATT);
     816       
     817        // Add the document to the results list
     818        Element new_node = (Element)this.doc.importNode(request_node, false);
     819        node_list.appendChild(new_node);
    800820
    801821        if (extlink) {
     
    812832        node_id = this.gdbm_src.translateOID(node_id);
    813833        }
    814 
    815         // Add the document to the list
    816         Element new_node = (Element)this.doc.importNode(request_node, false);
    817         node_list.appendChild(new_node);
     834        if (node_id == null) {
     835        continue;
     836        }
    818837
    819838        // Add the requested metadata information
     
    968987    protected String resolveTextMacros(String doc_content, String doc_id, String lang)
    969988    {
    970     String top_doc_id = OID.getTop(doc_id);
    971     DBInfo info = this.gdbm_src.getInfo(top_doc_id);
    972     String archivedir = info.getInfo("archivedir");
    973     String image_dir  = this.site_http_address + "/collect/"+this.cluster_name+"/index/assoc/"+archivedir;
    974    
    975     // Resolve all "_httpdocimg_"s
    976     doc_content = doc_content.replaceAll("_httpdocimg_", image_dir);
     989    DBInfo info = null;
     990    if (doc_content.indexOf("_httpdocimg_")!=-1) {
     991        String top_doc_id = OID.getTop(doc_id);
     992        info = this.gdbm_src.getInfo(top_doc_id);
     993        if (info == null) {
     994        // perhaps we had per.iods in the ids - just try the current id
     995        top_doc_id = doc_id;
     996        info = this.gdbm_src.getInfo(top_doc_id);
     997        }
     998        if (info != null) {
     999        String archivedir = info.getInfo("archivedir");
     1000        String image_dir  = this.site_http_address + "/collect/"+this.cluster_name+"/index/assoc/"+archivedir;
     1001       
     1002        // Resolve all "_httpdocimg_"s
     1003        doc_content = doc_content.replaceAll("_httpdocimg_", image_dir);
     1004        }
     1005    }
    9771006    // resolve any collection specific macros
    978     doc_content = macro_resolver.resolve(doc_content, lang, GS2MacroResolver.SCOPE_TEXT, top_doc_id, info);
     1007    doc_content = macro_resolver.resolve(doc_content, lang, GS2MacroResolver.SCOPE_TEXT, doc_id, info);
    9791008    return doc_content;
    9801009    }
     
    9981027        } else {
    9991028        DBInfo info = this.gdbm_src.getInfo(parent_id);
    1000         String contains = info.getInfo("contains");
    1001         contains = contains.replaceAll("\"", parent_id);
    1002         String [] children = contains.split(";");
    1003         for (int i=0;i<children.length;i++) {
    1004             String child_id = children[i];
    1005             if (child_id.equals(doc_id)) {
    1006             value = String.valueOf(i+1); // make it from 1 to length
    1007             break;
     1029        if (info==null) {
     1030            value ="-1";
     1031        } else {
     1032            String contains = info.getInfo("contains");
     1033            contains = contains.replaceAll("\"", parent_id);
     1034            String [] children = contains.split(";");
     1035            for (int i=0;i<children.length;i++) {
     1036            String child_id = children[i];
     1037            if (child_id.equals(doc_id)) {
     1038                value = String.valueOf(i+1); // make it from 1 to length
     1039                break;
     1040            }
    10081041            }
    10091042        }
     
    10201053    protected int getNumChildren(String doc_id) {
    10211054    DBInfo info = this.gdbm_src.getInfo(doc_id);
     1055    if (info == null) {
     1056        return 0;
     1057    }
    10221058    String contains = info.getInfo("contains");
    10231059    if (contains.equals("")) {
Note: See TracChangeset for help on using the changeset viewer.