Changeset 21782


Ignore:
Timestamp:
2010-03-15T10:57:35+13:00 (14 years ago)
Author:
kjdon
Message:

slightly modified where info comes from in config files. service rack now in collectionConfig, indexstem and infodbtype from metadata in buildConfig

File:
1 edited

Legend:

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

    r16871 r21782  
    6161  protected String site_name = "";
    6262  protected String coll_name = "";
    63   protected Element coll_config_xml = null;
    64  
     63 
    6564  /** constructor */
    6665  public OAIPMH() {
     
    7271    this.coll_db.closeDatabase();
    7372  }
    74   /** configure this service */
     73  /** configure this service
     74  info is the OAIPMH service rack from collectionConfig.xml, and
     75  extra_info is buildConfig.xml */
    7576  public boolean configure(Element info, Element extra_info) {
    7677    if (!super.configure(info, extra_info)){
     
    8081   
    8182    //get the names from ServiceRack.java
    82     site_name = this.router.getSiteName();
    83     coll_name = this.cluster_name;
    84     //get the collection-specific configurations from collectionConfig.xml
    85     coll_config_xml = OAIXML.getCollectionConfigXML(site_name, coll_name);
     83    this.site_name = this.router.getSiteName();
     84    this.coll_name = this.cluster_name;
    8685   
    8786    logger.info("Configuring OAIPMH...");
    88     // this call passes the indexStem in of ServiceRack element in buildConfig.xml to the super class.
     87
    8988    this.config_info = info;
    9089   
    91     // the index stem is either specified in the buildConfig.xml file or uses the collection name
    92     Element index_stem_elem = (Element) GSXML.getChildByTagName(info, GSXML.INDEX_STEM_ELEM);
    93     String index_stem = null;
    94     if (index_stem_elem != null) {
    95       index_stem = index_stem_elem.getAttribute(GSXML.NAME_ATT);
    96     }
     90    // the index stem is either specified in the buildConfig.xml file (extra_info) or uses the collection name
     91    Element metadata_list = (Element) GSXML.getChildByTagName(extra_info, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
     92    String index_stem = "";
     93    String infodb_type = "";
     94    if (metadata_list != null) {
     95     
     96      Element index_stem_elem = (Element) GSXML.getNamedElement(metadata_list, GSXML.METADATA_ELEM, GSXML.NAME_ATT, "indexStem");
     97     
     98      if (index_stem_elem != null) {
     99    index_stem = GSXML.getNodeText(index_stem_elem);
     100      }
     101
     102      Element infodb_type_elem = (Element) GSXML.getNamedElement(metadata_list, GSXML.METADATA_ELEM, GSXML.NAME_ATT, "infodbType");
     103      if (infodb_type_elem != null) {
     104    infodb_type = GSXML.getNodeText(infodb_type_elem);
     105      }
     106
     107    }
     108
    97109    if (index_stem == null || index_stem.equals("")) {
    98110      index_stem = this.cluster_name;
    99111    }
    100  
    101     // find out what kind of database we have
    102     Element database_type_elem = (Element) GSXML.getChildByTagName(info, GSXML.DATABASE_TYPE_ELEM);
    103     String database_type = null;
    104     if (database_type_elem != null) {
    105       database_type = database_type_elem.getAttribute(GSXML.NAME_ATT);
    106     }
    107     if (database_type == null || database_type.equals("")) {
    108       database_type = "gdbm"; // the default
    109     }
    110     coll_db = new SimpleCollectionDatabase(database_type);
     112    if (infodb_type == null || infodb_type.equals("")) {
     113      infodb_type = "gdbm"; // the default
     114    }
     115
     116    coll_db = new SimpleCollectionDatabase(infodb_type);
    111117    if (coll_db == null) {
    112       logger.error("Couldn't create the collection database of type "+database_type);
     118      logger.error("Couldn't create the collection database of type "+infodb_type);
    113119      return false;
    114120    }
    115121   
    116122    // Open database for querying
    117     String coll_db_file = GSFile.collectionDatabaseFile(this.site_home, this.cluster_name, index_stem, database_type);
     123    String coll_db_file = GSFile.collectionDatabaseFile(this.site_home, this.cluster_name, index_stem, infodb_type);
    118124    if (!this.coll_db.openDatabase(coll_db_file, SimpleCollectionDatabase.READ)) {
    119125      logger.error("Could not open collection database!");
     
    395401      return OAIXML.getResponse(OAIXML.createErrorElement(OAIXML.CANNOT_DISSEMINATE_FORMAT, ""));
    396402    }
    397 // Another way of doing the same job!   
    398 //    HashMap prefix_map = OAIXML.getChildrenMapByTagName(coll_config_xml, OAIXML.METADATA_PREFIX);
    399 //    if(!prefix_map.contains(prefix)) {
    400 //      logger.error("metadata prefix is not supported.");
    401 //      return OAIXML.getResponse(OAIXML.createErrorElement(OAIXML.CANNOT_DISSEMINATE_FORMAT, ""));
    402 //    }
    403403   
    404404    //get a list of identifiers (it contains a list of strings)
     
    452452   */
    453453  private Element getMetadataFormatElement(String prefix) {
    454     Element oai = (Element)GSXML.getChildByTagName(this.coll_config_xml, OAIXML.OAI);
    455     Element list_meta_format = (Element)GSXML.getChildByTagName(oai, OAIXML.LIST_METADATA_FORMATS);
     454    Element list_meta_format = (Element)GSXML.getChildByTagName(this.config_info, OAIXML.LIST_METADATA_FORMATS);
    456455    Element metadata_format = GSXML.getNamedElement(list_meta_format, OAIXML.METADATA_FORMAT, OAIXML.METADATA_PREFIX, prefix);
    457456    return metadata_format;
     
    537536    }
    538537   
    539     NodeList meta_list = getMetadataFormatList(this.coll_config_xml);
     538    NodeList meta_list = getMetadataFormatList();
    540539    if (meta_list == null || meta_list.getLength() == 0) {
    541540      logger.error("No metadata format is present in collectionConfig.xml");
     
    569568   *  Currently, it will only contain one metadata format: oai_dc
    570569   */
    571   protected NodeList getMetadataFormatList(Element coll_config_xml) {
    572     Element oai_elem = (Element)GSXML.getChildByTagName(coll_config_xml, OAIXML.OAI);
    573     Element list_meta_formats = (Element)GSXML.getChildByTagName(oai_elem, OAIXML.LIST_METADATA_FORMATS);
     570  protected NodeList getMetadataFormatList() {
     571    Element list_meta_formats = (Element)GSXML.getChildByTagName(this.config_info, OAIXML.LIST_METADATA_FORMATS);
    574572    return GSXML.getChildrenByTagName(list_meta_formats, OAIXML.METADATA_FORMAT);
    575573  }
     
    684682      }
    685683      if(key.equals(second_name)) {
    686         String meta_value = info.getInfo(key);
     684    String meta_value = info.getInfo(key);
    687685        name_value[0] = first_name;
    688         name_value[1] = meta_value;
    689         return name_value;
     686    name_value[1] = meta_value;
     687    return name_value;
    690688      }
    691689    }
     
    698696    for(int i=0; i<metadata_names.length; i++) {
    699697      String[] name_value = getMetadata(info, metadata_names[i]);
    700       if(name_value != null) {
     698      if(name_value != null) { 
    701699        map.put(name_value[0], name_value[1]);
    702700        empty_map = false;
Note: See TracChangeset for help on using the changeset viewer.