Show
Ignore:
Timestamp:
01.06.2010 15:10:34 (10 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

Files:
1 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