Changeset 22212

Show
Ignore:
Timestamp:
01.06.2010 15:10:34 (9 years ago)
Author:
kjdon
Message:

tidied up the config classes. moved all the global params into oaiconfig instead of having them in the collection map. put setname and description into the collection map instead of having their own maps. Added methods to access baseURL etc

Location:
main/trunk/greenstone2/runtime-src/src/oaiservr
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/runtime-src/src/oaiservr/oaiconfig.cpp

    r20827 r22212  
    218218    } 
    219219  } 
    220   else if (key == "oaisetname" && cfgline.size() == 2) { 
    221     this->setNameMap[cfgline[0]] = cfgline[1]; 
    222   } 
    223   else if (key == "oaisetdescription" && cfgline.size() == 2) { 
    224     this->setDescriptionMap[cfgline[0]] = cfgline[1]; 
    225   } 
    226   else if (key == "oaiversion" && cfgline.size() >= 1) { 
    227     this->oaiVersion = cfgline[0]; 
    228   } 
     220  else if ( key == "oaisetname" || key == "oaisetdescription") {  
     221    text_t coll_name; 
     222    text_t value = ""; 
     223    if (this->collection != "") { 
     224      // we are in collect.cfg 
     225      coll_name = this->collection; 
     226      if (cfgline.size() == 1) { 
     227    // just the collection value 
     228    value = cfgline[0]; 
     229      } 
     230      else if (cfgline.size() == 2) { 
     231    // we have a subset name (eg for classifier) 
     232    coll_name.append(":"); 
     233    coll_name.append(cfgline[0]); 
     234    value = cfgline[1]; 
     235      } 
     236    } else if (cfgline.size() == 2) { 
     237      // oai.cfg, line should be collname, setName 
     238      coll_name = cfgline[0]; 
     239      value = cfgline[1]; 
     240    } 
     241    if (value != "") { 
     242      if (this->collectMap[coll_name] == NULL) { 
     243    this->collectMap[coll_name] = new oaicollectconfig(coll_name); 
     244      } 
     245      if (key == "oaisetname") { 
     246    this->collectMap[coll_name]->setName = value; 
     247      } else if (key == "oaisetdescription") { 
     248    this->collectMap[coll_name]->setDescription = value; 
     249      } 
     250    } 
     251  } 
     252 
    229253  else if (key == "resumeafter" && cfgline.size() >= 1) { 
    230254    this->resumptionSize = cfgline[0].getint(); 
    231255  } 
    232   // get and note a maintainer item to support the Identify Verb of OAI 
    233   else if (key == "maintainer" && cfgline.size() >= 1) { 
    234     int line = 0; 
    235      
    236     // TODO: exhaustive checks for empty or default values of maintainer 
    237     while (line < cfgline.size()) { 
    238       if (cfgline[line] != "NULL" && 
    239       cfgline[line] != "") { 
    240     // do something 
    241     break; 
    242       } 
    243       else { 
    244     ++line; 
    245       } 
    246     } 
    247      
    248     // Only try to set the configuration if we have a legitimate value ... 
    249     if (line < cfgline.size()) { 
    250       // ensure we have a map to write to 
    251       if (this->collectMap[this->collection] == NULL) { 
    252     this->collectMap[this->collection] = new oaicollectconfig(this->collection); 
    253       } 
    254       this->collectMap[this->collection]->maintainer = cfgline[line]; 
    255     } 
    256   } 
    257   else if (key == "repositoryName" && cfgline.size() >= 1) { 
    258     int line = 0; 
    259      
    260     // TODO: exhaustive checks for empty or default values of repositoryName 
    261     while (line < cfgline.size()) { 
    262       if (cfgline[line] != "NULL" && 
    263       cfgline[line] != "") { 
    264     // do something 
    265     break; 
    266       } 
    267       else { 
    268     ++line; 
    269       } 
    270     } 
    271      
    272     // Only try to set the configuration if we have a legitimate value ... 
    273     if (line < cfgline.size()) { 
    274       // ensure we have a map to write to 
    275       if (this->collectMap[this->collection] == NULL) { 
    276     this->collectMap[this->collection] = new oaicollectconfig(this->collection); 
    277       } 
    278       this->collectMap[this->collection]->repositoryName = cfgline[line]; 
    279     } 
    280   } 
    281   else if (key == "baseURL" && cfgline.size() >= 1) { 
    282     int line = 0; 
    283      
    284     while (line < cfgline.size()) { 
    285       if (cfgline[line] != "NULL" && 
    286       cfgline[line] != "") { 
    287     // do something 
    288     break; 
    289       } 
    290       else { 
    291     ++line; 
    292       } 
    293     } 
    294      
    295     // Only try to set the configuration if we have a legitimate value ... 
    296     if (line < cfgline.size()) { 
    297       // ensure we have a map to write to 
    298       if (this->collectMap[this->collection] == NULL) { 
    299     this->collectMap[this->collection] = new oaicollectconfig(this->collection); 
    300       } 
    301       this->collectMap[this->collection]->baseURL = cfgline[line]; 
    302     } 
    303   } 
    304   else if (key == "baseDocRoot" && cfgline.size() >= 1) { 
    305     int line = 0; 
    306      
    307     while (line < cfgline.size()) { 
    308       if (cfgline[line] != "NULL" && 
    309       cfgline[line] != "") { 
    310     // do something 
    311     break; 
    312       } 
    313       else { 
    314     ++line; 
    315       } 
    316     } 
    317      
    318     // Only try to set the configuration if we have a legitimate value ... 
    319     if (line < cfgline.size()) { 
    320       // ensure we have a map to write to 
    321       if (this->collectMap[this->collection] == NULL) { 
    322     this->collectMap[this->collection] = new oaicollectconfig(this->collection); 
    323       } 
    324       this->collectMap[this->collection]->baseDocRoot = cfgline[line]; 
    325     } 
    326   } 
    327 } 
    328  
    329 /**  
    330  *  TODO: store all field values in a map per collection 
    331  */ 
    332 text_t oaiconfig::getCollectionConfig(const text_t &collection, const text_t &field) 
    333 { 
    334   if (this->collectMap[collection] == NULL) { 
    335     return ""; 
    336   } 
    337   if (field == "maintainer") { 
    338     return this->collectMap[collection]->maintainer; 
    339   } 
    340  
    341   if (field == "repositoryName") { 
    342     return this->collectMap[collection]->repositoryName; 
    343   } 
    344  
    345   if (field == "baseURL") { 
    346     return this->collectMap[collection]->baseURL; 
    347   } 
    348  
    349   if (field == "baseDocRoot") { 
    350     return this->collectMap[collection]->baseDocRoot; 
    351   } 
    352  
    353   return ""; 
    354 } 
     256 
     257  else if (key == "maintainer") { 
     258    this->maintainer = cfgline[0]; 
     259  } 
     260  else if (key == "repositoryName") { 
     261    this->repositoryName = cfgline[0]; 
     262  } 
     263  else if (key == "baseURL") { 
     264    this->baseURL = cfgline[0]; 
     265  }  
     266  else if (key == "baseLibraryURL") { 
     267    this->baseLibraryURL = cfgline[0]; 
     268  } 
     269  else if (key == "baseDocRoot") { 
     270    this->baseDocRoot = cfgline[0]; 
     271  } 
     272   
     273} 
     274 
    355275 
    356276text_t oaiconfig::getMapping(const text_t &collection, const text_t &collectfield) 
     
    398318} 
    399319 
    400  
     320text_t oaiconfig::getBaseURL() 
     321{ 
     322  return this->baseURL; 
     323} 
     324text_t oaiconfig::getBaseLibraryURL() 
     325{ 
     326  return this->baseLibraryURL; 
     327} 
     328text_t oaiconfig::getBaseDocRoot() 
     329{ 
     330  return this->baseDocRoot; 
     331} 
     332text_t oaiconfig::getRepositoryName() 
     333{ 
     334  return this->repositoryName; 
     335} 
     336text_t oaiconfig::getMaintainer() 
     337{ 
     338  return this->maintainer; 
     339} 
    401340text_t oaiconfig::getSetName(const text_t &setSpec) 
    402341{ 
    403   if (setNameMap.find(setSpec) != setNameMap.end()) 
    404   { 
    405     return setNameMap[setSpec]; 
    406   } 
    407  
    408   return ""; 
    409 } 
    410  
     342  if (this->collectMap[setSpec] == NULL) { 
     343    return "" ; 
     344  } 
     345   
     346  return this->collectMap[setSpec]->setName; 
     347   
     348} 
    411349 
    412350text_t oaiconfig::getSetDescription(const text_t &setSpec) 
    413351{ 
    414   if (setDescriptionMap.find(setSpec) != setDescriptionMap.end()) 
    415   { 
    416     return setDescriptionMap[setSpec]; 
    417   } 
    418  
    419   return ""; 
    420 } 
     352  if (this->collectMap[setSpec] == NULL) { 
     353    return "" ; 
     354  } 
     355   
     356  return this->collectMap[setSpec]->setDescription; 
     357} 
     358 
  • main/trunk/greenstone2/runtime-src/src/oaiservr/oaiconfig.h

    r21455 r22212  
    66#include <map> 
    77 
    8 // TODO: sort out the members of oaicollectconfig as private/public and add 
    9 //       corresponding set/get functions 
    10  
    118class oaicollectconfig { 
    129 public: 
    1310  oaicollectconfig(const text_t &collectname) { this->collection = collectname; } 
    1411  text_t    collection; 
    15   text_t    maintainer; 
    16   text_t    repositoryName; 
    17   text_t    baseURL; // URL of oaiserver.cgi 
    18   text_t    baseDocRoot; // Base URL for gsdl directory  
     12  text_t    setName; // A display name for the set (collection) 
     13  text_t    setDescription; // A display description for the set (collection) 
    1914  text_tmap fieldMap;    // maps from OAI name to GSDL name 
    2015}; 
     
    2823  virtual ~oaiconfig(); 
    2924  virtual void  configure(const text_t &key, const text_tarray &cfgline); 
    30   text_t        getCollectionConfig(const text_t &collection, const text_t &field); 
    3125  text_tarray & getCollectionsList() { return this->collectList; } 
    3226  text_tset & getMetadataSet() { return this->metadataSet; } 
     
    3630  text_t        getSetName(const text_t &setSpec); 
    3731  text_t        getSetDescription(const text_t &setSpec); 
    38   int           getOAIVersion(); 
    39   int           resumeAfter(); 
     32  int getOAIVersion(); 
     33  int resumeAfter(); 
     34  text_t getBaseURL(); 
     35  text_t getBaseLibraryURL(); 
     36  text_t getBaseDocRoot(); 
     37  text_t getRepositoryName(); 
     38  text_t getMaintainer(); 
    4039 private: 
    4140  bool configureCollection(const text_t &gsdlhome, const text_t &collection); 
    4241   
     42  text_t    repositoryName; 
     43  text_t    baseURL; // URL of oaiserver.cgi 
     44  text_t    baseLibraryURL; // URL of library.cgi (used for urls to greenstone documents ) 
     45  text_t    baseDocRoot; // Base URL for gsdl directory (used for urls to source documents ) 
     46  text_t    oaiVersion;        // The version of OAI running 
     47  int       resumptionSize;    // The number of items to produce before spitting out a resumptionToken 
     48  text_t    maintainer; 
     49 
    4350  text_tarray collectList;  // The list of collections to be taken in hand 
    4451  text_tset metadataSet; // The list of metadata sets to be supported 
    4552  text_tmap infoMap;        // Holds the information to be given in the case 
    4653                            // of an OAI identify request 
    47   text_tmap setNameMap;     // Holds user-defined names for the sets 
    48   text_tmap setDescriptionMap;  // Holds user-defined descriptions for the sets 
    4954  oaicollectmap collectMap; // The configuration of collections 
    5055  text_t collection;        // Used to track which collection is being configured 
    51   text_t oaiVersion;        // The version of OAI running 
    52   int    resumptionSize;    // The number of items to produce before spitting out a 
    53                             // resumptionToken 
    5456   
    5557};