Changeset 7312 for trunk


Ignore:
Timestamp:
2004-05-12T14:04:09+12:00 (20 years ago)
Author:
kjdon
Message:

GS3REtrieve now is not abstract, and provides the structure and metadata retrieval services, while GS3MGRetrieve just provides the content retrieve service. soem small modifications for an updated collection format

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

Legend:

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

    r6517 r7312  
    3131
    3232
    33 /**
     33/** The content retrieval class for GS3 building
    3434 *
    3535 * @author <a href="mailto:[email protected]">Katherine Don</a>
     
    3838
    3939public class GS3MGRetrieve
    40     extends GS3Retrieve {
    41 
     40    extends ServiceRack {
     41    // the services on offer
     42    protected static final String DOCUMENT_CONTENT_RETRIEVE_SERVICE = "DocumentContentRetrieve";
     43   
    4244    // Parameters used
    4345    private static final String INDEX_PARAM = "index";
     
    4749
    4850    private MGWrapper mg_src = null;
     51    protected SQLQuery database = null;
     52   
     53    protected Element config_info = null; // the xml from the config file
    4954
    5055    private String default_index = null;
    51 
    5256
    5357    /** constructor */
    5458    public GS3MGRetrieve()
    5559    {
     60    this.database = new SQLQuery();
    5661    this.mg_src = new MGWrapper();
    5762    }
     
    6166    public boolean configure(Element info, Element extra_info)
    6267    {
     68    this.config_info = info;
    6369    // Do specific configuration
    6470    System.out.println("Configuring GS3MGRetrieve...");
     
    7581        return false;
    7682    }
     83
    7784    // System.out.println("Default index: " + this.default_index);
    78 
    79     // Do generic configuration
    80     return super.configure(info, extra_info);
    81     }
    82 
    83 
     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);
     89
     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;
     103    }
     104
     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?
     111    }
     112
     113    return true;
     114    }
     115
     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    }
    84126    /** Retrieve the content of a document */
    85127    protected Element processDocumentContentRetrieve(Element request)
     
    117159        //ystem.out.println("getting doc id "+doc_ids[i]);
    118160        String doc_id = doc_ids[i];
    119         if (OID.needsTranslating(doc_id)) {
     161        if (GS3OID.needsTranslating(doc_id)) {
    120162        //doc_id = this.gdbm_src.translateOID(doc_id);
    121         doc_id = translateOID(doc_id);
     163        doc_id = GS3OID.translateOID(doc_id);
    122164        //ystem.out.println("translated id = "+doc_id);
    123165        }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3MGSearch.java

    r6517 r7312  
    4949
    5050    private MGWrapper mg_src = null;
    51 
    5251
    5352    /** constructor */
     
    140139    for (int d = 0; d < docs.size(); d++) {
    141140        long docnum = ((MGDocInfo) docs.elementAt(d)).num_;
    142         String mg_id = index+"."+docnum;
     141        ////String mg_id = index+"."+docnum;
     142        String mg_id = this.base_index_prefix+"."+docnum;
    143143        String doc_id = database.MGNum2OID(mg_id);
     144        // hack !!!
     145        if (doc_id.endsWith("-All")) {
     146        System.err.print("replacing doc id "+doc_id+" with ");
     147        doc_id=doc_id.replaceAll("All","1");
     148        System.err.println(doc_id);
     149        }
     150       
    144151        //String doc_id = this.gdbm_src.docnum2Oid(docnum);
    145152        Element doc_node = createDocumentNodeElement(doc_id);
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3Retrieve.java

    r6871 r7312  
    3737import java.util.ArrayList;
    3838
    39 /** Implements the generic retrieval and classifier services for GS3
     39/** Implements the generic structure and metadata retrieval and classifier services for GS3
    4040 * collections.
    4141 *
     
    4545 */
    4646
    47 public abstract class GS3Retrieve
     47public class GS3Retrieve
    4848    extends ServiceRack {
    4949
     
    5252    protected static final String DOCUMENT_STRUCTURE_RETRIEVE_SERVICE = "DocumentStructureRetrieve";
    5353    protected static final String DOCUMENT_METADATA_RETRIEVE_SERVICE = "DocumentMetadataRetrieve";
    54     protected static final String DOCUMENT_CONTENT_RETRIEVE_SERVICE = "DocumentContentRetrieve";
    55 
    5654
    5755    // the browsing services -  now in here, these will only be advertised if classifiers have been specified in the config file
     
    7674    protected static final int CLASSIFIER=2;
    7775
    78     //protected GDBMWrapper gdbm_src = null;
    7976    protected SQLQuery database = null;
    8077   
     
    8279
    8380    /** constructor */
    84     protected GS3Retrieve()
     81    public GS3Retrieve()
    8582    {
    86     //this.gdbm_src = new GDBMWrapper();
    8783    this.database = new SQLQuery();
    8884    }
     
    105101    dmr_service.setAttribute(GSXML.NAME_ATT, DOCUMENT_METADATA_RETRIEVE_SERVICE);
    106102    this.short_service_info.appendChild(dmr_service);
    107 
    108     Element dcr_service = this.doc.createElement(GSXML.SERVICE_ELEM);
    109     dcr_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
    110     dcr_service.setAttribute(GSXML.NAME_ATT, DOCUMENT_CONTENT_RETRIEVE_SERVICE);
    111     this.short_service_info.appendChild(dcr_service);
    112103
    113104    // open the database for querying
     
    186177    }
    187178
    188     // look for document display format
    189     String path = GSPath.appendLink(GSXML.DISPLAY_ELEM, GSXML.FORMAT_ELEM);
    190     Element display_format = (Element)GSXML.getNodeByPath(extra_info, path);
    191     if (display_format != null) {
    192         this.format_info_map.put(DOCUMENT_CONTENT_RETRIEVE_SERVICE, this.doc.importNode(display_format, true));
    193         // should we make a copy?
    194     }
    195179    return true;
    196180    }
     
    272256        dmr_service.setAttribute(GSXML.NAME_ATT, DOCUMENT_METADATA_RETRIEVE_SERVICE);
    273257        return dmr_service;
    274     }
    275 
    276     if (service_id.equals(DOCUMENT_CONTENT_RETRIEVE_SERVICE)) {
    277         Element dcr_service = this.doc.createElement(GSXML.SERVICE_ELEM);
    278         dcr_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
    279         dcr_service.setAttribute(GSXML.NAME_ATT, DOCUMENT_CONTENT_RETRIEVE_SERVICE);
    280         return dcr_service;
    281258    }
    282259
     
    598575       
    599576        if (GS3OID.needsTranslating(doc_id)) {
    600         doc_id = translateOID(doc_id);
     577        doc_id = GS3OID.translateOID(doc_id);
    601578        }
    602579        if (type==DOCUMENT && GS3OID.isDocTop(doc_id)) {
     
    756733        if (GS3OID.needsTranslating(node_id)) {
    757734        //node_id = this.gdbm_src.translateOID(node_id);
    758         node_id = translateOID(node_id);
     735        node_id = GS3OID.translateOID(node_id);
    759736        }
    760737       
     
    866843//      }
    867844   
    868     /** Retrieve the content of a document - implemented by concrete subclasses */
    869     protected abstract Element processDocumentContentRetrieve(Element request);
    870845
    871846    /** needs to get info from gdbm database - if the calling code gets it already it may pay to pass it in instead */
     
    930905//      }
    931906   
    932     protected String translateOID(String oid) {
    933    
    934     int p = oid.lastIndexOf('.');
    935     if (p != oid.length()-3) {
    936         System.out.println("translateoid error: '.' is not the third to last char!!");
    937         return oid;
    938     }
    939    
    940     String top = oid.substring(0, p);
    941     String suff = oid.substring(p+1);
    942     if (suff.equals("pr")) {
    943         return GS3OID.getParent(top);
    944     } else if (suff.equals("rt")) {
    945         return GS3OID.getTop(top);
    946     }
    947     return oid;
    948 
    949     }
    950907   
    951908}   
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3Search.java

    r6871 r7312  
    3232/**
    3333 *
    34  * @author <a href="mailto:[email protected]">Michael Dewsnip</a>
     34 * @author Katherine Don
    3535 * @version $Revision$
    3636 */
     
    7474    /** the default index */
    7575    protected String default_index = null;
    76 
     76    /** the base index prefix */
     77    protected String base_index_prefix = null;
    7778
    7879    /** constructor */
     
    8081    {
    8182    this.database = new SQLQuery();
    82     //this.gdbm_src = new GDBMWrapper();
    8383    }
    8484
     
    101101    }
    102102
     103    // get the base prefix
     104    def = (Element) GSXML.getChildByTagName(info, "baseIndexPrefix");
     105    if (def != null) {
     106        this.base_index_prefix = def.getAttribute(GSXML.NAME_ATT);
     107    }
     108    if (this.base_index_prefix == null || this.base_index_prefix.equals("")) {
     109        System.err.println("Error: base index prefix not specified!");
     110        return false;
     111    }
    103112    // these entries should reflect the build config file - some services may not be available depending on how the collection was built.
    104113    // set up short_service_info_ - for now just has id and type. the name (lang dependent) will be added in if the list is requested.
     
    108117    this.short_service_info.appendChild(tq_service);
    109118
    110 
    111     // Open GDBM database for querying
    112     //String gdbm_db_file = GSFile.GDBMDatabaseFile(this.site_home, this.cluster_name);
    113     //if (!this.gdbm_src.openDatabase(gdbm_db_file, GDBMWrapper.READER)) {
    114     //    System.err.println("Error: Could not open GDBM database!");
    115     //    return false;
    116     //}
    117119    // open the database for querying
    118120    // the database name is a combination of site name and collection name
Note: See TracChangeset for help on using the changeset viewer.