Changeset 8959


Ignore:
Timestamp:
2005-02-04T11:48:14+13:00 (19 years ago)
Author:
kjdon
Message:

restructured the retrieval classes. split apart browsing and doc retrieval into two classes, inplemented an abstract base class for each which new services can inherit

Location:
trunk/gsdl3/src/java/org/greenstone/gsdl3/service
Files:
7 added
5 edited

Legend:

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

    r8955 r8959  
    11/*
    22 *    GS2MGPPRetrieve.java
    3  *    Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
     3 *    Copyright (C) 2005 New Zealand Digital Library, http://www.nzdl.org
    44 *
    55 *    This program is free software; you can redistribute it and/or modify
     
    1919package org.greenstone.gsdl3.service;
    2020
    21 
    2221// Greenstone classes
    2322import org.greenstone.mgpp.*;
    24 import org.greenstone.gsdl3.util.*;
     23import org.greenstone.gsdl3.util.GSFile;
     24import org.greenstone.gsdl3.util.GSXML;
    2525
    2626// XML classes
    27 import org.w3c.dom.Element;
     27import org.w3c.dom.Element;
     28import org.w3c.dom.Text;
    2829
    2930// General Java classes
    3031import java.io.File;
    3132
    32 
    33 /**
    34  * A ServiceRack class for retrieval in greenstone 2 MGPP collections
    35  *
    36  * @author <a href="mailto:[email protected]">Katherine Don</a>
    37  * @version $Revision$
    38  * @see ServiceRack
    39  */
    40 public class GS2MGPPRetrieve
    41     extends GS2Retrieve {
    42 
    43     // Parameters used
     33public class GS2MGPPRetrieve
     34    extends AbstractGS2DocumentRetrieve
     35{
     36     // Parameters used
    4437    private static final String LEVEL_PARAM = "level";
    4538
     
    5043   
    5144    private String default_level = null;
    52 
    53 
    54     /** constructor */
    55     public GS2MGPPRetrieve()
    56     {
     45    private String mgpp_textdir = null;
     46   
     47    public GS2MGPPRetrieve() {
    5748    this.mgpp_src = new MGPPWrapper();
    58     // only the classifier service has strings at present
    59     this.dictionary_name = "ClassifierBrowse";
    60 
    6149    }
    62 
    6350
    6451    /** configure this service */
     
    7865    }
    7966    // System.out.println("Default level: " + default_level_);
     67   
     68    // The location of the MGPP text files
     69    mgpp_textdir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) +
     70        File.separatorChar + GSFile.collectionTextPath(this.cluster_name);
    8071
    8172    // Do generic configuration
    8273    return super.configure(info, extra_info);
     74 
     75    }
     76   
     77    /** returns the content of a node
     78     * should return a nodeContent element:
     79     * <nodeContent>text content or other elements</nodeContent>
     80     */
     81    protected Element getNodeContent(String doc_id) {
     82    String lang = "en"; //  **********
     83    long doc_num = this.gdbm_src.OID2Docnum(doc_id);
     84    if (doc_num == -1) {
     85        System.err.println("OID "+doc_id +" couldn't be converted to mgpp num");
     86        return null;
     87    }
     88    Element content_node = this.doc.createElement(GSXML.NODE_CONTENT_ELEM);
     89   
     90    String doc_content = "";
     91    try {
     92        doc_content = this.mgpp_src.getDocument(this.mgpp_textdir,
     93                            this.default_level,
     94                            doc_num);
     95        if (doc_content != null) {
     96        doc_content = resolveTextMacros(doc_content, doc_id, lang);
     97        }
     98    } catch (Exception e) {
     99        System.out.println("exception happended with mgpp_src.getDocument()" + e);
     100        doc_content = "this is the content for section hash id "+ doc_id+", mgpp doc num "+doc_num+"\n";
     101
     102    }
     103    Text t = this.doc.createTextNode(doc_content);
     104    content_node.appendChild(t);
     105    return content_node;
     106
    83107    }
    84108
    85    
    86     /** Retrieve the content of a document */
    87     protected Element processDocumentContentRetrieve(Element request)
    88     {
    89     // Create a new (empty) result message
    90     Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
    91     result.setAttribute(GSXML.FROM_ATT,DOCUMENT_CONTENT_RETRIEVE_SERVICE );
    92     result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
    93109
    94     // Get the parameters of the request
    95     Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    96     Element extlink_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, EXTLINK_PARAM);
    97     boolean extlink = false;
    98     if (extlink_param != null && GSXML.getValue(extlink_param).equals("1")) {
    99         extlink = true;
    100     }
    101 
    102     // Get the request doc_list
    103     Element query_doc_list = (Element) GSXML.getChildByTagName(request, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
    104     if (query_doc_list == null) {
    105         System.err.println("Error: DocumentContentRetrieve request specified no doc nodes.\n");
    106         return result;
    107     }
    108     String lang = request.getAttribute(GSXML.LANG_ATT);
    109     Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
    110     result.appendChild(doc_list);
    111 
    112     // The location of the MGPP text files
    113     String textdir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) +
    114         File.separatorChar + GSFile.collectionTextPath(this.cluster_name);
    115 
    116     // Get the documents
    117     String[] doc_ids = GSXML.getAttributeValuesFromList(query_doc_list,
    118                              GSXML.NODE_ID_ATT);
    119     for (int i = 0; i < doc_ids.length; i++) {
    120         String doc_id = doc_ids[i];
    121         Element doc = this.doc.createElement(GSXML.DOC_NODE_ELEM);
    122         doc.setAttribute(GSXML.NODE_ID_ATT, doc_id);
    123         doc_list.appendChild(doc);
    124        
    125         if (extlink) {
    126         doc_id = this.gdbm_src.extlink2OID(doc_id);
    127         if (doc_id==null) {
    128             continue;
    129         }
    130         doc.setAttribute(GSXML.NODE_ID_ATT, doc_id);
    131         }
    132         else if (OID.needsTranslating(doc_id)) {
    133         doc_id = this.gdbm_src.translateOID(doc_id);
    134         if (doc_id==null) {
    135             continue;
    136         }
    137         doc.setAttribute(GSXML.NODE_ID_ATT, doc_id);
    138         }
    139        
    140         long doc_num = this.gdbm_src.OID2Docnum(doc_id);
    141         if (doc_num == -1) {
    142         continue;
    143         }
    144         String doc_content = this.mgpp_src.getDocument(textdir, this.default_level, doc_num);
    145         doc_content = resolveTextMacros(doc_content, doc_id, lang);
    146        
    147         // For now, stick it in a text node - eventually should be parsed as xml??
    148         GSXML.addDocText(this.doc, doc, doc_content);
    149        
    150 
    151     }
    152    
    153     return result;
    154     }
    155110}
    156 
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2MGRetrieve.java

    r8955 r8959  
    11/*
    22 *    GS2MGRetrieve.java
    3  *    Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
     3 *    Copyright (C) 2005 New Zealand Digital Library, http://www.nzdl.org
    44 *
    55 *    This program is free software; you can redistribute it and/or modify
     
    1919package org.greenstone.gsdl3.service;
    2020
    21 
    2221// Greenstone classes
    2322import org.greenstone.mg.*;
    24 import org.greenstone.gsdl3.util.*;
     23import org.greenstone.gsdl3.util.GSFile;
     24import org.greenstone.gsdl3.util.GSXML;
    2525
    2626// XML classes
    2727import org.w3c.dom.Element;
     28import org.w3c.dom.Text;
    2829
    2930// General Java classes
    3031import java.io.File;
    3132
    32 
    33 /**
    34  *
    35  * @author <a href="mailto:[email protected]">Katherine Don</a>
    36  *
    37  */
    38 
    3933public class GS2MGRetrieve
    40     extends GS2Retrieve {
    41 
    42     // Parameters used
    43     private static final String INDEX_PARAM = "index";
    44 
     34    extends AbstractGS2DocumentRetrieve
     35{
    4536    // Elements used in the config file that are specific to this class
    4637    private static final String DEFAULT_INDEX_ELEM = "defaultIndex";
    4738
    4839    private MGWrapper mg_src = null;
    49 
     40    private String mg_basedir = null;
     41    private String mg_textdir = null;
    5042    private String default_index = null;
    51 
    52 
    53     /** constructor */
    54     public GS2MGRetrieve()
    55     {
     43   
     44    public GS2MGRetrieve() {
    5645    this.mg_src = new MGWrapper();
    57     // only the classifier service has strings at present
    58     this.dictionary_name = "ClassifierBrowse";
    5946    }
    60 
    6147
    6248    /** configure this service */
     
    7965    // System.out.println("Default index: " + this.default_index);
    8066
     67    // The location of the MG index and text files
     68    mg_basedir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) + File.separatorChar;  // Needed by MG
     69    mg_textdir = GSFile.collectionTextPath(this.cluster_name);
     70    // index is only needed to start up MG, not used so just use the default index
     71    String indexpath = GSFile.collectionIndexPath(this.cluster_name, this.default_index);
     72    this.mg_src.setIndex(indexpath);
     73
    8174    // Do generic configuration
    8275    return super.configure(info, extra_info);
    8376    }
     77   
     78    /** returns the content of a node
     79     * should return a nodeContent element:
     80     * <nodeContent>text content or other elements</nodeContent>
     81     */
     82    protected Element getNodeContent(String doc_id) {
     83    String lang = "en"; //  **********
     84    long doc_num = this.gdbm_src.OID2Docnum(doc_id);
     85    if (doc_num == -1) {
     86        System.err.println("OID "+doc_id +" couldn't be converted to mg num");
     87        return null;
     88    }
     89    Element content_node = this.doc.createElement(GSXML.NODE_CONTENT_ELEM);
     90   
     91    String doc_content = this.mg_src.getDocument(this.mg_basedir,
     92                             this.mg_textdir, doc_num);
     93   
     94    if (doc_content!=null) {
     95        // remove any ctrl-c or ctrl-b
     96        doc_content = doc_content.replaceAll("\u0002|\u0003", "");
     97        // replace _httpimg_ with the correct address
     98        doc_content = resolveTextMacros(doc_content, doc_id, lang);
     99        //GSXML.addDocText(this.doc, doc, doc_content);
     100    } else {
     101        System.err.println("the doc content was null, not getting that section\n");
     102        doc_content = "couldn't retrieve content for this section\n";
     103    }
     104    Text t = this.doc.createTextNode(doc_content);
     105    content_node.appendChild(t);
     106    return content_node;
     107
     108    }
    84109
    85110
    86     /** Retrieve the content of a document */
    87     protected Element processDocumentContentRetrieve(Element request)
    88     {
    89     // Create a new (empty) result message
    90     Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
    91     result.setAttribute(GSXML.FROM_ATT, DOCUMENT_CONTENT_RETRIEVE_SERVICE);
    92     result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
    93 
    94     // Get the parameters of the request - no parameters at this stage
    95     Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    96     Element extlink_param = GSXML.getNamedElement(param_list, GSXML.PARAM_ELEM, GSXML.NAME_ATT, EXTLINK_PARAM);
    97     boolean extlink = false;
    98     if (extlink_param != null && GSXML.getValue(extlink_param).equals("1")) {
    99         extlink = true;
    100     }
    101     // Get the request content
    102     Element query_doc_list = (Element) GSXML.getChildByTagName(request, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
    103     if (query_doc_list == null) {
    104         System.err.println("Error: DocumentContentRetrieve request specified no doc nodes.\n");
    105         return result;
    106     }
    107    
    108     String lang = request.getAttribute(GSXML.LANG_ATT);
    109     Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
    110     result.appendChild(doc_list);
    111    
    112     // The location of the MG index and text files
    113     String basedir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) + File.separatorChar;  // Needed by MG
    114     String textdir = GSFile.collectionTextPath(this.cluster_name);
    115     // index is only needed to start up MG, not used so just use the default index
    116     String indexpath = GSFile.collectionIndexPath(this.cluster_name, this.default_index);
    117     this.mg_src.setIndex(indexpath);
    118    
    119     // Get the documents
    120     String[] doc_ids = GSXML.getAttributeValuesFromList(query_doc_list,
    121                                  GSXML.NODE_ID_ATT);
    122     for (int i = 0; i < doc_ids.length; i++) {
    123         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        
    129         if (extlink) {
    130         if (OID.needsTranslating(doc_id)) {
    131            
    132             // just ignore the extension cos it has no meaning here
    133             // or should it be added back on for the next step???
    134             doc_id = this.gdbm_src.extlink2OID(doc_id.substring(0,doc_id.length()-3));
    135         } else {
    136             doc_id = this.gdbm_src.extlink2OID(doc_id);
    137         }
    138         if (doc_id == null) {
    139             System.err.println("extlink "+doc_id +" couldn't be converted to proper id");
    140             continue;
    141         }
    142         doc.setAttribute(GSXML.NODE_ID_ATT, doc_id); // reset the att cos it may have changed
    143            
    144         }
    145         else if (OID.needsTranslating(doc_id)) {
    146         doc_id = this.gdbm_src.translateOID(doc_id);
    147         doc.setAttribute(GSXML.NODE_ID_ATT, doc_id); // reset the att cos it may have changed
    148         }
    149        
    150         long doc_num = this.gdbm_src.OID2Docnum(doc_id);
    151         if (doc_num == -1) {
    152         System.err.println("OID "+doc_id +" couldn't be converted to mg num");
    153         continue;
    154         }
    155         String doc_content = this.mg_src.getDocument(basedir, textdir, doc_num);
    156        
    157         if (doc_content!=null) {
    158         // remove any ctrl-c or ctrl-b (I hope these are the right codes)
    159         doc_content = doc_content.replaceAll("\u0002|\u0003", "");
    160         // replace _httpimg_ with the correct address
    161         doc_content = resolveTextMacros(doc_content, doc_id, lang);
    162         GSXML.addDocText(this.doc, doc, doc_content);
    163         } else {
    164         System.err.println("the doc content was null, not getting that section\n");
    165         GSXML.addDocText(this.doc, doc, "couldn't retrieve content for this section\n");
    166         }
    167     }
    168 
    169     return result;
    170     }
    171111}
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS2Retrieve.java

    r8955 r8959  
    7373    protected static final String INFO_SIB_POS = "siblingPosition";
    7474
    75     protected static final String EXTLINK_PARAM = "ext";
     75    protected static final String EXTID_PARAM = "ext";
    7676   
    7777    protected static final int DOCUMENT=1;
     
    462462        node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_LEAF);
    463463        } else {
    464         node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_INTERIOR);
     464        node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_INTERNAL);
    465465        }
    466466    }
     
    794794        }
    795795        metadata_list.add(metadata);
    796         } else if (param.getAttribute(GSXML.NAME_ATT).equals(EXTLINK_PARAM)&& GSXML.getValue(param).equals("1")) {
     796        } else if (param.getAttribute(GSXML.NAME_ATT).equals(EXTID_PARAM)&& GSXML.getValue(param).equals("1")) {
    797797        extlink = true;
    798798        }
     
    824824            // just ignore the extension cos it has no meaning here
    825825            // or should it be added back on for the next step???
    826             node_id = this.gdbm_src.extlink2OID(node_id.substring(0,node_id.length()-3));
     826            node_id = this.gdbm_src.externalId2OID(node_id.substring(0,node_id.length()-3));
    827827        } else {
    828             node_id = this.gdbm_src.extlink2OID(node_id);
     828            node_id = this.gdbm_src.externalId2OID(node_id);
    829829        }
    830830        }
     
    850850            String key = (String)it.next();
    851851            String value = info.getInfo(key);
    852             GSXML.addMetadata(this.doc, node_meta_list, key, this.macro_resolver.resolve(value, lang, GS2MacroResolver.SCOPE_META, node_id, info));
     852            GSXML.addMetadata(this.doc, node_meta_list, key, this.macro_resolver.resolve(value, lang, GS2MacroResolver.SCOPE_META, node_id));
    853853        }
    854854        } else { // just get the selected ones
     
    875875    if (pos ==-1) {
    876876        // just a plain meta entry eg dc.Title
    877         return macro_resolver.resolve((String)info.getInfo(metadata), lang, GS2MacroResolver.SCOPE_META, node_id, info);
     877        return macro_resolver.resolve((String)info.getInfo(metadata), lang, GS2MacroResolver.SCOPE_META, node_id);
    878878    }
    879879   
     
    935935
    936936    if (!multiple) {
    937         result.append(this.macro_resolver.resolve(relation_info.getInfo(metadata), lang, GS2MacroResolver.SCOPE_META, relation_id, relation_info));
     937        result.append(this.macro_resolver.resolve(relation_info.getInfo(metadata), lang, GS2MacroResolver.SCOPE_META, relation_id));
    938938    } else {
    939939        // we have multiple meta
     
    947947            result.append(separator);
    948948            }
    949             result.append(this.macro_resolver.resolve((String)values.elementAt(i), lang, GS2MacroResolver.SCOPE_META, relation_id, relation_info));
     949            result.append(this.macro_resolver.resolve((String)values.elementAt(i), lang, GS2MacroResolver.SCOPE_META, relation_id));
    950950        }
    951951        }
     
    964964        if (!multiple) {
    965965        result.insert(0, separator);
    966         result.insert(0, this.macro_resolver.resolve(relation_info.getInfo(metadata), lang, GS2MacroResolver.SCOPE_META, relation_id, relation_info));
     966        result.insert(0, this.macro_resolver.resolve(relation_info.getInfo(metadata), lang, GS2MacroResolver.SCOPE_META, relation_id));
    967967        } else {
    968968        Vector values = relation_info.getMultiInfo(metadata);
     
    970970            for (int i=values.size()-1; i>=0; i--) {
    971971            result.insert(0, separator);
    972             result.insert(0, this.macro_resolver.resolve((String)values.elementAt(i), lang, GS2MacroResolver.SCOPE_META, relation_id, relation_info));
     972            result.insert(0, this.macro_resolver.resolve((String)values.elementAt(i), lang, GS2MacroResolver.SCOPE_META, relation_id));
    973973            }
    974974        }
     
    10051005    }
    10061006    // resolve any collection specific macros
    1007     doc_content = macro_resolver.resolve(doc_content, lang, GS2MacroResolver.SCOPE_TEXT, doc_id, info);
     1007    doc_content = macro_resolver.resolve(doc_content, lang, GS2MacroResolver.SCOPE_TEXT, doc_id);
    10081008    return doc_content;
    10091009    }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3MGRetrieve.java

    r8925 r8959  
    11/*
    22 *    GS3MGRetrieve.java
    3  *    Copyright (C) 2002 New Zealand Digital Library, http://www.nzdl.org
     3 *    Copyright (C) 2005 New Zealand Digital Library, http://www.nzdl.org
    44 *
    55 *    This program is free software; you can redistribute it and/or modify
     
    1919package org.greenstone.gsdl3.service;
    2020
    21 
    2221// Greenstone classes
    2322import org.greenstone.mg.*;
    24 import org.greenstone.gsdl3.util.*;
     23import org.greenstone.gsdl3.util.GSFile;
     24import org.greenstone.gsdl3.util.GSXML;
     25import org.greenstone.gsdl3.util.GS3OID;
    2526
    2627// XML classes
    2728import org.w3c.dom.Element;
     29import org.w3c.dom.Text;
    2830
    2931// General Java classes
    3032import java.io.File;
    3133
    32 
    33 /** The content retrieval class for GS3 building
    34  *
    35  * @author <a href="mailto:[email protected]">Katherine Don</a>
    36  * @version $Revision$
    37  */
    38 
    3934public class GS3MGRetrieve
    40     extends ServiceRack {
    41     // the services on offer
    42     protected static final String DOCUMENT_CONTENT_RETRIEVE_SERVICE = "DocumentContentRetrieve";
    43    
    44     // Parameters used
    45     private static final String INDEX_PARAM = "index";
    46 
     35    extends AbstractGS3DocumentRetrieve
     36{
    4737    // Elements used in the config file that are specific to this class
    4838    private static final String DEFAULT_INDEX_ELEM = "defaultIndex";
    4939
    5040    private MGWrapper mg_src = null;
    51     protected SQLQuery database = null;
    52    
    53     protected Element config_info = null; // the xml from the config file
    54 
     41    private String mg_basedir = null;
     42    private String mg_textdir = null;
    5543    private String default_index = null;
    56 
    57     /** constructor */
    58     public GS3MGRetrieve()
    59     {
    60     this.database = new SQLQuery();
     44   
     45    public GS3MGRetrieve() {
    6146    this.mg_src = new MGWrapper();
    6247    }
    63 
    6448
    6549    /** configure this service */
    6650    public boolean configure(Element info, Element extra_info)
    6751    {
    68     this.config_info = info;
    6952    // Do specific configuration
    7053    System.out.println("Configuring GS3MGRetrieve...");
     
    8164        return false;
    8265    }
     66    // System.out.println("Default index: " + this.default_index);
    8367
    84     // System.out.println("Default index: " + this.default_index);
    85     Element dcr_service = this.doc.createElement(GSXML.SERVICE_ELEM);
    86     dcr_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
    87     dcr_service.setAttribute(GSXML.NAME_ATT, DOCUMENT_CONTENT_RETRIEVE_SERVICE);
    88     this.short_service_info.appendChild(dcr_service);
     68    // The location of the MG index and text files
     69    mg_basedir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) + File.separatorChar;  // Needed by MG
     70    mg_textdir = GSFile.collectionTextPath("index");
     71    // index is only needed to start up MG, not used so just use the default index
     72    String indexpath = GSFile.collectionIndexPath("index", this.default_index);
     73    this.mg_src.setIndex(indexpath);
    8974
    90     // check that site_home is set
    91     if (this.site_home == null || this.site_home.equals("")) {
    92         System.err.println("GS3Retrieve Error: site_home is not set, so cannot work out the site name and cannot determine the database name");
    93         return false;
    94     }
    95     String site_name = this.site_home.substring(this.site_home.lastIndexOf(File.separator)+1);
    96     if (site_name.equals("")) {
    97         System.err.println("GS3Retrieve Error: Cannot extract the site name from site home: "+this.site_home);
    98         return false;
    99     }
    100     if (!database.setDatabase(site_name+"_"+this.cluster_name)) {
    101         System.err.println("GS3Retrieve Error: Could not open SQL database!");
    102         return false;
     75    // Do generic configuration
     76    return super.configure(info, extra_info);
     77    }
     78   
     79    /** returns the content of a node.
     80     * node_id should already have been translated if necessary
     81     * should return a nodeContent element:
     82     * <nodeContent>text content or other elements</nodeContent>
     83     */
     84    protected Element getNodeContent(String doc_id) {
     85
     86    if (GS3OID.isDocTop(doc_id) && database.isHierarchicalDocument(doc_id)) {
     87        // if we have a whole doc id, and the document is hierarchical,
     88        // we want to change the id to be the top id of the section
     89        // hierarchy
     90        doc_id = GS3OID.createOID(doc_id, "1");
    10391    }
    10492
    105     // look for document display format
    106     String path = GSPath.appendLink(GSXML.DISPLAY_ELEM, GSXML.FORMAT_ELEM);
    107     Element display_format = (Element)GSXML.getNodeByPath(extra_info, path);
    108     if (display_format != null) {
    109         this.format_info_map.put(DOCUMENT_CONTENT_RETRIEVE_SERVICE, this.doc.importNode(display_format, true));
    110         // should we make a copy?
     93    String doc_num = this.database.OID2MGNum(doc_id);       
     94    // doc nums have the index prefixed
     95    doc_num = doc_num.substring(doc_num.indexOf(".")+1);
     96    int doc_int = Integer.parseInt(doc_num);
     97   
     98    String doc_content = "";
     99    try {
     100        doc_content = this.mg_src.getDocument(this.mg_basedir,
     101                          this.mg_textdir,
     102                          doc_int);
     103        // remove any ctrl-c or ctrl-b
     104        doc_content = doc_content.replaceAll("\u0002|\u0003", "");
     105        doc_content = resolveRelativeLinks(doc_content, doc_id);
     106
     107    } catch (Exception e) {
     108        System.out.println("exception happended with mg_src.getDocument()");
     109        doc_content = "this is the content for section hash id "+ doc_id+", mg doc num "+doc_int+"\n";
    111110    }
     111   
     112    Element content_node = this.doc.createElement(GSXML.NODE_CONTENT_ELEM);
     113   
     114    Text t = this.doc.createTextNode(doc_content);
     115    content_node.appendChild(t);
     116    return content_node;
    112117
    113     return true;
    114118    }
    115119
    116     protected Element getServiceDescription(String service_id, String lang, String subset) {
    117     if (service_id.equals(DOCUMENT_CONTENT_RETRIEVE_SERVICE)) {
    118         Element dcr_service = this.doc.createElement(GSXML.SERVICE_ELEM);
    119         dcr_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
    120         dcr_service.setAttribute(GSXML.NAME_ATT, DOCUMENT_CONTENT_RETRIEVE_SERVICE);
    121         return dcr_service;
    122     }
    123 
    124     return null;
    125     }
    126     /** Retrieve the content of a document */
    127     protected Element processDocumentContentRetrieve(Element request)
    128     {
    129     // Create a new (empty) result message
    130     Element result = this.doc.createElement(GSXML.RESPONSE_ELEM);
    131     result.setAttribute(GSXML.FROM_ATT, DOCUMENT_CONTENT_RETRIEVE_SERVICE);
    132     result.setAttribute(GSXML.TYPE_ATT, GSXML.REQUEST_TYPE_PROCESS);
    133 
    134     // Get the parameters of the request - no parameters at this stage
    135     //Element param_list = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
    136 
    137     // Get the request content
    138    
    139     Element query_doc_list = (Element) GSXML.getChildByTagName(request, GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
    140     if (query_doc_list == null) {
    141         System.err.println("Error: DocumentContentRetrieve request specified no doc nodes.\n");
    142         return result;
    143     }
    144    
    145     Element doc_list = this.doc.createElement(GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
    146     result.appendChild(doc_list);
    147    
    148     // The location of the MG index and text files
    149     String basedir = GSFile.collectionBaseDir(this.site_home, this.cluster_name) + File.separatorChar;  // Needed by MG
    150     String textdir = GSFile.collectionTextPath("index");//this.cluster_name);
    151     // index is only needed to start up MG, not used so just use the default index
    152     String indexpath = GSFile.collectionIndexPath("index"/*this.cluster_name*/, this.default_index);
    153     this.mg_src.setIndex(indexpath);
    154    
    155     // Get the documents
    156     String[] doc_ids = GSXML.getAttributeValuesFromList(query_doc_list,
    157                                  GSXML.NODE_ID_ATT);
    158     for (int i = 0; i < doc_ids.length; i++) {
    159         //ystem.out.println("getting doc id "+doc_ids[i]);
    160         String doc_id = doc_ids[i];
    161         if (GS3OID.needsTranslating(doc_id)) {
    162         //doc_id = this.gdbm_src.translateOID(doc_id);
    163         doc_id = GS3OID.translateOID(doc_id);
    164         //ystem.out.println("translated id = "+doc_id);
    165         }
    166         if (GS3OID.isDocTop(doc_id) && database.isHierarchicalDocument(doc_id)) {
    167         // if we have a whole doc id, and the document is hierarchical,
    168         // we want to change the id to be the top id of the section
    169         // hierarchy
    170             doc_id = GS3OID.createOID(doc_id, "1");
    171         }
    172         String doc_num = this.database.OID2MGNum(doc_id);       
    173         // doc nums have the index prefixed
    174         doc_num = doc_num.substring(doc_num.indexOf(".")+1);
    175         int doc_int = Integer.parseInt(doc_num);
    176        
    177         String doc_content = "";
    178         try {
    179         doc_content = this.mg_src.getDocument(basedir, textdir, doc_int);
    180         } catch (Exception e) {
    181         System.out.println("exception happended with mg_src.getDocument()");
    182         doc_content = "this is the content for section hash id "+ doc_id+", mg doc num "+doc_int+"\n";
    183         }
    184        
    185         //ystem.out.println("Doc content: " + doc_content + "|");
    186         //ystem.out.println("Doc ID: " + doc_id);
    187         // remove any ctrl-c or ctrl-b (I hope these are the right codes)
    188         doc_content = doc_content.replaceAll("\u0002|\u0003", "");
    189         doc_content = resolveRelativeLinks(doc_content, doc_id);
    190         // replace _httpimg_ with the correct address
    191         //doc_content = resolveImages(doc_content, doc_id);
    192         // Stick it in a text node
    193         Element doc = this.doc.createElement(GSXML.DOC_NODE_ELEM);
    194         doc.setAttribute(GSXML.NODE_ID_ATT, doc_id);
    195         GSXML.addDocText(this.doc, doc, doc_content);
    196         Element nodeContent = (Element)GSXML.getChildByTagName(doc, "nodeContent");
    197         //Element file_elem = this.doc.createElement("file");
    198         //file_elem.setAttribute("mimeType", "image/jpeg");
    199         //file_elem.setAttribute("href", "import/meinahole.jpg");
    200         //nodeContent.appendChild(file_elem);
    201         doc_list.appendChild(doc);
    202     }
    203 
    204     return result;
    205     }
    206     protected String resolveRelativeLinks(String doc_content, String doc_id) {
    207 
    208     String http_path  = this.site_http_address + "/collect/"+this.cluster_name;
    209     doc_content = doc_content.replaceAll("_httpcollection_", http_path);
    210     return doc_content;
    211    
    212     }
    213120
    214121}
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3Retrieve.java

    r8955 r8959  
    351351        node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_ROOT);
    352352        } else if (parent || database.documentHasChildren(node_id)){
    353         node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_INTERIOR);
     353        node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_INTERNAL);
    354354        } else {
    355355        node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_LEAF);
Note: See TracChangeset for help on using the changeset viewer.