Changeset 22319

Show
Ignore:
Timestamp:
28.06.2010 17:28:42 (10 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.

Location:
main/trunk/greenstone3/src/java/org/greenstone/gsdl3
Files:
5 modified

Legend:

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

    r21663 r22319  
    123123    /** if id ends in .fc, .pc etc, then translate it to the correct id */ 
    124124    protected String translateId(String node_id) { 
    125     return this.coll_db.translateOID(node_id); 
     125    return OID.translateOID(this.coll_db, node_id); //return this.coll_db.translateOID(node_id); 
    126126    } 
    127127     
  • 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; 
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/GS2Browse.java

    r15326 r22319  
    107107    /** if id ends in .fc, .pc etc, then translate it to the correct id */ 
    108108    protected String translateId(String node_id) { 
    109     return this.coll_db.translateOID(node_id); 
     109    return OID.translateOID(this.coll_db, node_id); //return this.coll_db.translateOID(node_id); 
    110110    } 
    111111 
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/OID.java

    r18503 r22319  
    1919package org.greenstone.gsdl3.util; 
    2020 
     21import org.apache.log4j.*; 
     22 
    2123/** utility class to handle greenstone OIDs 
    2224 * 
     
    2426 */ 
    2527public class OID { 
     28 
     29    static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.OID.class.getName()); 
     30 
     31    public interface OIDTranslatable { 
     32    public String processOID(String doc_id, String top, String suffix, int sibling_num); 
     33    } 
    2634     
    2735    /** returns everything up to the first dot  
     
    102110      return child.startsWith(parent); 
    103111    } 
     112 
     113     
     114  /** translates relative oids into proper oids: 
     115   * .pr (parent), .rt (root) .fc (first child), .lc (last child), 
     116   * .ns (next sibling), .ps (previous sibling)  
     117   * .np (next page), .pp (previous page) : links sections in the order that you'd read the document 
     118   * a suffix is expected to be present so test before using 
     119   * Other classes can implement the method processOID of interface OIDTranslatable 
     120   * to process the oid further to handle siblings. 
     121   */ 
     122    public static String translateOID(OIDTranslatable translator, String oid) { 
     123    int p = oid.lastIndexOf('.'); 
     124    if (p != oid.length()-3) { 
     125      logger.info("translateoid error: '.' is not the third to last char!!"); 
     126      return oid; 
     127    } 
     128     
     129    String top = oid.substring(0, p); 
     130    String suff = oid.substring(p+1); 
     131 
     132    // just in case we have multiple extensions, we must translate 
     133    // we process inner ones first 
     134    if (OID.needsTranslating(top)) { 
     135    top = OID.translateOID(translator, top); 
     136    } 
     137    if (suff.equals("pr")) { 
     138      return OID.getParent(top); 
     139    }  
     140    if (suff.equals("rt")) { 
     141      return OID.getTop(top); 
     142    }  
     143    if (suff.equals("np")) { 
     144      // try first child 
     145 
     146      String node_id = OID.translateOID(translator, top+".fc"); 
     147      if (!node_id.equals(top)) { 
     148      return node_id; 
     149      } 
     150 
     151      // try next sibling 
     152      node_id = OID.translateOID(translator, top+".ns"); 
     153      if (!node_id.equals(top)) { 
     154      return node_id; 
     155      } 
     156      // otherwise we keep trying parents sibling 
     157      String child_id = top; 
     158      String parent_id = OID.getParent(child_id); 
     159      while(!parent_id.equals(child_id)) { 
     160    node_id = OID.translateOID(translator, parent_id+".ns"); 
     161    if (!node_id.equals(parent_id)) { 
     162      return node_id; 
     163    } 
     164    child_id = parent_id; 
     165    parent_id = OID.getParent(child_id); 
     166      } 
     167      return top; // we couldn't get a next page, so just return the original 
     168    }  
     169    if (suff.equals("pp")) { 
     170      String prev_sib = OID.translateOID(translator, top+".ps"); 
     171      if (prev_sib.equals(top)) { 
     172    // no previous sibling, so return the parent 
     173    return OID.getParent(top); 
     174      } 
     175      // there is a previous sibling, so it's either this section, or the last child of the last child 
     176      String last_child = OID.translateOID(translator, prev_sib+".lc"); 
     177      while (!last_child.equals(prev_sib)) { 
     178    prev_sib = last_child; 
     179    last_child = OID.translateOID(translator, prev_sib+".lc"); 
     180      } 
     181      return last_child; 
     182    }  
     183     
     184    int sibling_num = 0; 
     185    if (suff.equals("ss")) { 
     186      // we have to remove the sib num before we get top 
     187      p = top.lastIndexOf('.'); 
     188      sibling_num = Integer.parseInt(top.substring(p+1)); 
     189      top = top.substring(0, p); 
     190    } 
     191     
     192    // need to get info out of Fedora 
     193    String doc_id = top; 
     194    if (suff.endsWith("s")) { 
     195      doc_id = OID.getParent(top); 
     196      if (doc_id.equals(top)) { 
     197    // i.e. we are already at the top 
     198    return top; 
     199      } 
     200    } 
     201     
     202    return translator.processOID(doc_id, top, suff, sibling_num); 
     203 
     204  } 
    104205} 
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/SimpleCollectionDatabase.java

    r16797 r22319  
    2121import org.apache.log4j.*; 
    2222 
    23 public class SimpleCollectionDatabase { 
     23public class SimpleCollectionDatabase implements OID.OIDTranslatable { 
    2424   
    2525  static Logger logger = Logger.getLogger(org.greenstone.gsdl3.util.SimpleCollectionDatabase.class.getName()); 
     
    136136    return null; 
    137137  } 
    138    
    139   /** translates relative oids into proper oids: 
     138 
     139  /** After OID.translateOID() is through, this method processes OID further  
     140   * to translate relative oids into proper oids: 
    140141   * .pr (parent), .rt (root) .fc (first child), .lc (last child), 
    141142   * .ns (next sibling), .ps (previous sibling)  
     
    143144   * a suffix is expected to be present so test before using  
    144145   */ 
    145   public String translateOID(String oid) { 
    146  
    147     int p = oid.lastIndexOf('.'); 
    148     if (p != oid.length()-3) { 
    149       logger.info("translateoid error: '.' is not the third to last char!!"); 
    150       return oid; 
    151     } 
    152      
    153     String top = oid.substring(0, p); 
    154     String suff = oid.substring(p+1); 
    155     // just in case we have multiple extensions, we must translate 
    156     // we process inner ones first 
    157     if (OID.needsTranslating(top)) { 
    158       top = translateOID(top); 
    159     } 
    160     if (suff.equals("pr")) { 
    161       return OID.getParent(top); 
    162     }  
    163     if (suff.equals("rt")) { 
    164       return OID.getTop(top); 
    165     }  
    166     if (suff.equals("np")) { 
    167       // try first child 
    168       String node_id = translateOID(top+".fc"); 
    169       if (!node_id.equals(top)) { 
    170     return node_id; 
    171       } 
    172       // try next sibling 
    173       node_id = translateOID(top+".ns"); 
    174       if (!node_id.equals(top)) { 
    175     return node_id; 
    176       } 
    177       // otherwise we keep trying parents sibling 
    178       String child_id = top; 
    179       String parent_id = OID.getParent(child_id); 
    180       while(!parent_id.equals(child_id)) { 
    181     node_id = translateOID(parent_id+".ns"); 
    182     if (!node_id.equals(parent_id)) { 
    183       return node_id; 
    184     } 
    185     child_id = parent_id; 
    186     parent_id = OID.getParent(child_id); 
    187       } 
    188       return top; // we couldn't get a next page, so just return the original 
    189     }  
    190     if (suff.equals("pp")) { 
    191       String prev_sib = translateOID(top+".ps"); 
    192       if (prev_sib.equals(top)) { 
    193     // no previous sibling, so return the parent 
    194     return OID.getParent(top); 
    195       } 
    196       // there is a previous sibling, so its either this section, or the last child of the last child.. 
    197       String last_child = translateOID(prev_sib+".lc"); 
    198       while (!last_child.equals(prev_sib)) { 
    199     prev_sib = last_child; 
    200     last_child = translateOID(prev_sib+".lc"); 
    201       } 
    202       return last_child; 
    203     }  
    204      
    205     int sibling_num = 0; 
    206     if (suff.equals("ss")) { 
    207       // we have to remove the sib num before we get top 
    208       p = top.lastIndexOf('.'); 
    209       sibling_num = Integer.parseInt(top.substring(p+1)); 
    210       top = top.substring(0, p); 
    211     } 
    212      
    213     // need to get info out of collection db - 
    214     String doc_id = top; 
    215     if (suff.endsWith("s")) { 
    216       doc_id = OID.getParent(top); 
    217       if (doc_id.equals(top)) { 
    218     // i.e. we are already at the top 
    219     return top; 
    220       } 
    221     } 
    222     DBInfo info = getInfo(doc_id); 
     146    public String processOID(String doc_id, String top, String suff, int sibling_num) { 
     147    DBInfo info = getInfo(doc_id); 
    223148    if (info==null) { 
    224149      logger.info("info is null!!"); 
     
    264189     
    265190    return top; 
    266   } 
     191    }   
    267192}