Ignore:
Timestamp:
2010-06-28T17:28:42+12:00 (14 years ago)
Author:
ak19
Message:

Moved the portion of SimpleCollectionDatabase.translateOID() that is now common to FedoraServiceProxy into util's OID.java class which has a new interface that both SimpleCollectionDB and FedoraServiceProxy now implement in order to use the shared recursive function OID.translateOID and expand it with the interface's processOID() to add their custom code to it for further processing the OID.

File:
1 edited

Legend:

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

    r22307 r22319  
    5353 */
    5454public class FedoraServiceProxy
    55     extends ServiceRack
     55    extends ServiceRack implements OID.OIDTranslatable
    5656{
    5757
     
    417417    protected String translateId(String id) {
    418418    if (OID.needsTranslating(id)) {
    419         return translateOID(id);
    420     }
    421     return id;}
     419        return OID.translateOID(this, id); //return translateOID(id);
     420    }
     421    return id;
     422    }
    422423   
    423424    /** if an id is not a greenstone id (an external id) then translate
     
    434435   * a suffix is expected to be present so test before using
    435436   */
    436   public String translateOID(String oid) {     
    437     int p = oid.lastIndexOf('.');
    438     if (p != oid.length()-3) {
    439       logger.info("translateoid error: '.' is not the third to last char!!");
    440       return oid;
    441     }
    442    
    443     String top = oid.substring(0, p);
    444     String suff = oid.substring(p+1);
    445 
    446     // just in case we have multiple extensions, we must translate
    447     // we process inner ones first
    448     if (OID.needsTranslating(top)) {
    449       top = translateOID(top);
    450     }
    451     if (suff.equals("pr")) {
    452       return OID.getParent(top);
    453     }
    454     if (suff.equals("rt")) {
    455       return OID.getTop(top);
    456     }
    457     if (suff.equals("np")) {
    458       // try first child
    459 
    460       String node_id = translateOID(top+".fc");
    461       if (!node_id.equals(top)) {
    462       return node_id;
    463       }
    464 
    465       // try next sibling
    466       node_id = translateOID(top+".ns");
    467       if (!node_id.equals(top)) {
    468       return node_id;
    469       }
    470       // otherwise we keep trying parents sibling
    471       String child_id = top;
    472       String parent_id = OID.getParent(child_id);
    473       while(!parent_id.equals(child_id)) {
    474     node_id = translateOID(parent_id+".ns");
    475     if (!node_id.equals(parent_id)) {
    476       return node_id;
    477     }
    478     child_id = parent_id;
    479     parent_id = OID.getParent(child_id);
    480       }
    481       return top; // we couldn't get a next page, so just return the original
    482     }
    483     if (suff.equals("pp")) {
    484       String prev_sib = translateOID(top+".ps");
    485       if (prev_sib.equals(top)) {
    486     // no previous sibling, so return the parent
    487     return OID.getParent(top);
    488       }
    489       // there is a previous sibling, so its either this section, or the last child of the last child
    490       String last_child = translateOID(prev_sib+".lc");
    491       while (!last_child.equals(prev_sib)) {
    492     prev_sib = last_child;
    493     last_child = translateOID(prev_sib+".lc");
    494       }
    495       return last_child;
    496     }
    497    
    498     int sibling_num = 0;
    499     if (suff.equals("ss")) {
    500       // we have to remove the sib num before we get top
    501       p = top.lastIndexOf('.');
    502       sibling_num = Integer.parseInt(top.substring(p+1));
    503       top = top.substring(0, p);
    504     }
    505    
    506     // need to get info out of Fedora
    507     String doc_id = top;
    508     if (suff.endsWith("s")) {
    509       doc_id = OID.getParent(top);
    510       if (doc_id.equals(top)) {
    511     // i.e. we are already at the top
    512     return top;
    513       }
    514     }
    515    
     437    public String processOID(String doc_id, String top, String suff, int sibling_num) {
     438
    516439    // send off request to get sibling etc. information from Fedora
    517440    Element response = null;
Note: See TracChangeset for help on using the changeset viewer.