Changeset 15002

Show
Ignore:
Timestamp:
22.02.2008 11:25:40 (11 years ago)
Author:
davidb
Message:

Collections can now be put in to "groups" i.e. can be located inside another collection, which is marked as "collectgroup" true. The top-level collection appears on the home page, and when clicked upon display a new "home page" with only the collections appearing within its folder displayed. To implement this, the main change is in collectset.cpp, which now runs "add_all_collection_groups" after it has added all the top-level collections. comtypes.h has been updated to include the new field, "isCollectGroup". Finally, pageaction.cpp has been updated so these changes are reflected in the home page generated.

Location:
gsdl/trunk/src
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/src/colservr/collectserver.cpp

    r13982 r15002  
    9898      if (value == "true") collectinfo.isBeta = true; 
    9999      else collectinfo.isBeta = false; 
     100    } else if (key == "collectgroup") { 
     101      if (value == "true") collectinfo.isCollectGroup = true; 
     102      else collectinfo.isCollectGroup = false; 
    100103    } else if ((key == "ccscols") || (key == "supercollection")) collectinfo.ccsCols = cfgline; 
    101104    else if (key == "supercollectionoptions") { 
  • gsdl/trunk/src/colservr/collectserver.h

    r9929 r15002  
    101101  const colservrconf &get_configinfo () {return configinfo;} 
    102102  text_t get_collection_name () {return configinfo.collection;} 
     103  bool is_collection_group () {return collectinfo.isCollectGroup;} 
     104 
    103105 
    104106  // ping indicates whether the collection has appropriate data structures 
  • gsdl/trunk/src/colservr/collectset.cpp

    r12246 r15002  
    5151  // get gsdlhome (if we fail the error will be picked up later -- in 
    5252  // cgiwrapper) 
     53 
    5354  if (site_cfg_read (gsdlhome, httpdomain, httpprefix)) { 
    5455    if (!gsdlhome.empty() && directory_exists(gsdlhome)) { 
     
    6667      } 
    6768 
    68       // read config file to see if built with mg, mgpp, or lucene 
    69       text_t buildtype = "mg"; // mg is default 
    70       text_tarray cfgline; 
    71       text_t key; 
    72       text_t filename = filename_cat(collectdir, *thiscol, "index" , "build.cfg"); 
    73       ifstream confin(filename.getcstr()); 
    74  
    75       if (confin) { 
    76         while (read_cfg_line(confin, cfgline) >= 0) { 
    77           if (cfgline.size() ==2 ) { 
    78         key = cfgline[0]; 
    79         cfgline.erase(cfgline.begin()); 
    80         if (key =="buildtype") { 
    81           buildtype = cfgline[0]; 
    82           break; 
    83         } 
    84           } 
    85         } 
    86       } 
    87        
    88       confin.close(); 
    89  
    90       // this memory is created but never destroyed 
    91       // we're also not doing any error checking to make sure we didn't 
    92       // run out of memory 
    93       collectserver *cserver = new collectserver(); 
    94       gdbmclass *gdbmhandler = new gdbmclass(); 
    95      
    96       // add a null filter 
    97       filterclass *filter = new filterclass (); 
    98       cserver->add_filter (filter); 
    99        
    100       // add a browse filter 
    101       browsefilterclass *browsefilter = new browsefilterclass(); 
    102       browsefilter->set_gdbmptr (gdbmhandler); 
    103       cserver->add_filter (browsefilter); 
    104        
    105       if (buildtype == "mg") { 
    106         mgsearch = new mgsearchclass(); 
    107          
    108         // add a query filter 
    109         mgqueryfilterclass *queryfilter = new mgqueryfilterclass(); 
    110         queryfilter->set_gdbmptr (gdbmhandler); 
    111         queryfilter->set_textsearchptr (mgsearch); 
    112         cserver->add_filter (queryfilter); 
    113          
    114         // add a mg and gdbm source 
    115         mggdbmsourceclass *mggdbmsource = new mggdbmsourceclass (); 
    116         mggdbmsource->set_gdbmptr (gdbmhandler); 
    117         mggdbmsource->set_textsearchptr (mgsearch); 
    118         cserver->add_source (mggdbmsource); 
    119  
    120       } 
    121       else if (buildtype == "mgpp") { 
    122          
    123         mgppsearch = new mgppsearchclass(); 
    124                  
    125         // add a query filter 
    126         mgppqueryfilterclass *queryfilter = new mgppqueryfilterclass(); 
    127         queryfilter->set_gdbmptr (gdbmhandler); 
    128         queryfilter->set_textsearchptr (mgppsearch); 
    129         cserver->add_filter (queryfilter); 
    130          
    131         // add a mg and gdbm source 
    132         mggdbmsourceclass *mggdbmsource = new mggdbmsourceclass (); 
    133         mggdbmsource->set_gdbmptr (gdbmhandler); 
    134         mggdbmsource->set_textsearchptr (mgppsearch); 
    135         cserver->add_source (mggdbmsource);    
    136       } 
    137       else if (buildtype == "lucene") { 
    138         lucenesearch = new lucenesearchclass(); 
    139         lucenesearch->set_gsdlhome(gsdlhome); 
    140  
    141         // add a query filter 
    142         lucenequeryfilterclass *queryfilter = new lucenequeryfilterclass(); 
    143         queryfilter->set_gdbmptr (gdbmhandler); 
    144         queryfilter->set_textsearchptr (lucenesearch); 
    145         cserver->add_filter (queryfilter); 
    146          
    147         // add a lucene and gdbm source 
    148         lucenegdbmsourceclass *lucenegdbmsource = new lucenegdbmsourceclass (); 
    149         lucenegdbmsource->set_gdbmptr (gdbmhandler); 
    150         lucenegdbmsource->set_textsearchptr (lucenesearch); 
    151         cserver->add_source (lucenegdbmsource);    
    152       } 
    153  
    154  
    155       // inform collection server and everything it contains about its 
    156       // collection name 
    157       cserver->configure ("collection", *thiscol); 
    158       // AZIZ: added on 10/10/00 
    159       //       the cserver object does not have a reference to gsdlhome 
    160       cserver->configure ("gsdlhome", gsdlhome); 
    161      
    162       // GRB: removed    proto.add_collectserver (cserver); 
    163       // GRB: added to build our own cservers list 
    164       cservers.addcollectserver (cserver); 
     69      this->add_collection (*thiscol, gsdlhome); 
    16570 
    16671      ++thiscol; 
    16772    } 
     73 
     74    this->add_all_collection_groups(gsdlhome); 
    16875      } 
    16976    } 
     
    198105      // are available to decode defaultindex, defaultsubcollection, and 
    199106      // defaultlanguage 
     107 
     108      bool failed_build_cfg = false; 
    200109      if (!build_cfg_read (*((*here).second.c), configinfo.gsdlhome, 
    201110               configinfo.collection)) { 
     111    failed_build_cfg = true; 
     112 
    202113    outconvertclass text_t2ascii; 
    203114    logout << text_t2ascii  
     
    205116           << configinfo.collection << "\", gsdlhome=\"" 
    206117           << configinfo.gsdlhome << "\"\n"; 
    207     ++here; 
    208     continue; 
    209       } 
    210  
     118      } 
     119 
     120      bool failed_collect_cfg = false; 
    211121      if (!collect_cfg_read (*((*here).second.c), configinfo.gsdlhome, 
    212122                 configinfo.collection)) { 
     123    failed_collect_cfg = true; 
    213124    outconvertclass text_t2ascii; 
    214125    logout << text_t2ascii  
     
    216127           << configinfo.collection << "\", gsdlhome=\""  
    217128           << configinfo.gsdlhome << "\"\n"; 
     129      } 
     130 
     131       
     132      bool is_colgroup = (*here).second.c->is_collection_group(); 
     133 
     134      if (failed_collect_cfg) { 
    218135    ++here; 
    219136    continue; 
    220137      } 
     138 
     139      if (failed_build_cfg && (!is_colgroup)) { 
     140    ++here; 
     141    continue; 
     142      } 
     143      // let a failed build.cfg through if its 'collect.cfg' marks it as 'collectgroup true' 
    221144 
    222145      if (!(*here).second.c->init (logout)) return false; 
     
    258181      ++thiscol; 
    259182    } 
     183 
     184    this->add_all_collection_groups(gsdlhome); 
    260185  } 
    261186} 
     
    266191                 const text_t &gsdlhome) { 
    267192 
    268   // if an old collection server exists for this collection we should 
    269   // delete it first 
    270   collectservermapclass::iterator here = cservers.begin(); 
    271   collectservermapclass::iterator end = cservers.end(); 
    272   while (here != end) { 
    273     if ((*here).second.c != NULL && (*here).first == collection) { 
    274       delete (*here).second.c; 
    275       cservers.erase (here); 
    276       break; 
    277     } 
    278     ++here; 
    279   } 
    280        
     193  this->remove_collection(collection); 
     194   
    281195  // read config file to see if built with mg, mgpp, or lucene 
    282196  // -- we can rely on the collection (and therefore the build.cfg) 
     
    371285  cserver->configure ("gsdlhome", gsdlhome); 
    372286 
    373   /* Removed from add_collection 24/11/2000; already done elsewhere in collectset.   
    374   // configure receptionist's collectinfo structure  
    375   text_tarray colinfo; 
    376   colinfo.push_back (collection); 
    377   colinfo.push_back (gsdlhome); 
    378   colinfo.push_back (gdbmhome); 
    379   */ 
    380287  cservers.addcollectserver (cserver); 
    381288} 
     
    399306  } 
    400307  cservers.clear(); 
     308} 
     309 
     310void collectset::add_collection_group(const text_t& collection,  
     311                      const text_t& gsdlhome) 
     312{ 
     313  text_tarray group; 
     314  text_t collect_group_dir = filename_cat (gsdlhome, "collect", collection); 
     315 
     316  // need to read collect.cfg for 'collectgroup' as class hasn't been initialised through 'init' yet 
     317  text_t is_collect_group; 
     318  text_tarray cfgline; 
     319  text_t key; 
     320  text_t build_cfg = filename_cat(gsdlhome, "collect", collection, "etc", "collect.cfg"); 
     321  char *collect_cfgc = build_cfg.getcstr(); 
     322  ifstream confin(collect_cfgc); 
     323 
     324  if (confin) { 
     325    while (read_cfg_line(confin, cfgline) >= 0) { 
     326      if (cfgline.size() == 2) { 
     327    key = cfgline[0]; 
     328    cfgline.erase(cfgline.begin()); 
     329    if (key == "collectgroup") { 
     330      is_collect_group = cfgline[0]; 
     331      break; 
     332    } 
     333      } 
     334    } 
     335    confin.close(); 
     336  } 
     337  delete []collect_cfgc; 
     338 
     339  if (is_collect_group == "true") { 
     340 
     341    if (read_dir (collect_group_dir, group)) { 
     342       
     343      text_tarray::const_iterator thiscol = group.begin(); 
     344      text_tarray::const_iterator endcol = group.end(); 
     345       
     346      while (thiscol != endcol) { 
     347    // ignore the modelcol 
     348    if (*thiscol == "etc") { 
     349      ++thiscol; 
     350      continue; 
     351    } 
     352     
     353    this->add_collection (collection + "/" + *thiscol, gsdlhome); 
     354     
     355    ++thiscol; 
     356      } 
     357    } 
     358  } 
     359} 
     360 
     361void collectset::add_all_collection_groups (const text_t& gsdlhome)  
     362 
     363{ 
     364  collectservermapclass::iterator here = cservers.begin(); 
     365  collectservermapclass::iterator end = cservers.end(); 
     366   
     367  while (here != end) { 
     368    text_t collection = (*here).second.c->get_collection_name(); 
     369    this->add_collection_group(collection,gsdlhome); 
     370 
     371    ++here; 
     372  } 
     373} 
     374 
     375 
     376// remove_collection deletes the collection server of collection. 
     377// This only needs to be called if a collectionserver is to be 
     378// removed while the library is running. The destructor function 
     379// cleans up all collectservers when the program exits. 
     380void collectset::remove_collection (const text_t &collection) { 
     381 
     382  // do nothing if no collection server exists for this collection  
     383  if (cservers.getcollectserver(collection) == NULL) return; 
     384 
     385  // first unload any cached mg databases - we may need to do something 
     386  // similar to this for mgpp and lucene too 
     387  if (mgsearch != NULL) { 
     388    mgsearch->unload_database(); 
     389  } 
     390 
     391  // now delete the collection server object 
     392  collectservermapclass::iterator here = cservers.begin(); 
     393  collectservermapclass::iterator end = cservers.end(); 
     394 
     395  while (here != end) { 
     396    if ((*here).second.c != NULL && (*here).first == collection) { 
     397      delete (*here).second.c; 
     398      cservers.erase (here); 
     399      return; 
     400    } 
     401    ++here; 
     402  } 
    401403} 
    402404 
     
    408410void collectset::remove_collection (const text_t &collection, ostream &logout) { 
    409411 
    410   // do nothing if no collection server exists for this collection  
    411   if (cservers.getcollectserver(collection) == NULL) return; 
    412  
    413   // first unload any cached mg databases - we may need to do something 
    414   // similar to this for mgpp and lucene too 
    415   if (mgsearch != NULL) { 
    416     mgsearch->unload_database(); 
    417   } 
    418  
    419   // now delete the collection server object 
    420   collectservermapclass::iterator here = cservers.begin(); 
    421   collectservermapclass::iterator end = cservers.end(); 
    422  
    423   while (here != end) { 
    424     if ((*here).second.c != NULL && (*here).first == collection) { 
    425       delete (*here).second.c; 
    426       cservers.erase (here); 
    427       return; 
    428     } 
    429     ++here; 
    430   } 
     412  remove_collection(collection); 
     413 
    431414  outconvertclass text_t2ascii; 
    432415  logout << text_t2ascii << "nullproto::remove_collection: failed to remove collectserver for " 
  • gsdl/trunk/src/colservr/collectset.h

    r9028 r15002  
    4242  void add_all_collections (const text_t &gsdlhome); 
    4343  void remove_all_collections (); 
     44  
     45  void remove_collection (const text_t &collection); 
     46  void remove_collection (const text_t &collection, ostream& logout); 
    4447 
    45   void remove_collection (const text_t &collection, ostream &logout); 
    4648  void add_collection (const text_t &collection,  
    4749               const text_t &gsdlhome); 
     50 
     51  void add_collection_group(const text_t& collection,  
     52                const text_t& gsdlhome); 
     53  void add_all_collection_groups (const text_t& gsdlhome); 
    4854 
    4955  // return the total number of servers in the set 
  • gsdl/trunk/src/recpt/comtypes.cpp

    r13982 r15002  
    5555  isBeta=false; 
    5656  isSegmented=false; 
     57  isCollectGroup=false; 
    5758  languages.erase(languages.begin(), languages.end()); 
    5859  ccsCols.erase(ccsCols.begin(), ccsCols.end()); 
  • gsdl/trunk/src/recpt/comtypes.h

    r13982 r15002  
    8888  bool isBeta; 
    8989  bool isSegmented; 
     90  bool isCollectGroup; // used to group a set of collections as one item on the home page 
    9091  unsigned long buildDate; 
    9192  text_tarray ccsCols;    // empty if collection does not use cross-collection searching 
  • gsdl/trunk/src/recpt/pageaction.cpp

    r13982 r15002  
    180180    bool first = true; 
    181181    while (collist_here != collist_end) { 
     182 
    182183      ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout); 
    183184       
     
    253254    int count = 0; 
    254255    while (collist_here != collist_end) { 
     256 
    255257      ColInfoResponse_t *cinfo = recpt->get_collectinfo_ptr ((*rprotolist_here).p, *collist_here, logout); 
     258 
     259      text_t arg_g = args["g"]; 
     260      text_t colname_dir = *collist_here; 
    256261       
     262      if (arg_g.empty()) { 
     263        // normal top-level home page 
     264        text_t::const_iterator begin = colname_dir.begin(); 
     265        text_t::const_iterator end = colname_dir.end(); 
     266 
     267        if (findchar(begin,end,'/')!=end) { 
     268          // no g argument, so generating top level home page 
     269          // => if colname_dir has "/" in collection name, filter it out 
     270 
     271          ++collist_here; 
     272          continue; 
     273        } 
     274      } 
     275      else { 
     276        // show only collections in the named group 
     277 
     278         
     279        if (colname_dir == arg_g) { 
     280          // display about this collect text 
     281 
     282          text_t collectionextra = cinfo->get_collectionmeta("collectionextra", args["l"]); 
     283          if (!collectionextra.empty()) { 
     284        // prepend text on at start 
     285        homeextra = "<p>" + collectionextra + "</p>" + homeextra; 
     286          } 
     287 
     288          ++collist_here; 
     289          continue; 
     290        } 
     291 
     292 
     293        // => filter out anything that does not start with the group prefix 
     294         
     295        if (!starts_with(colname_dir,arg_g + "/")) { 
     296          ++collist_here; 
     297          continue; 
     298        } 
     299      } 
     300 
     301 
    257302      if (cinfo != NULL) { 
    258         if (cinfo->isPublic && (cinfo->buildDate > 0)) { 
     303        if (cinfo->isPublic && ((cinfo->buildDate > 0)) || (cinfo->isCollectGroup)) { 
    259304 
    260305          found_valid_col = true; 
     
    264309        alt = collectionname; 
    265310          } 
     311 
     312 
     313          comerror_t err; 
     314          text_t optsite = g_EmptyText; 
     315          text_t site_name = (*rprotolist_here).p->get_site_name (err); 
     316          if (!site_name.empty()) { optsite = "site="+site_name+"&amp;"; } 
     317 
     318          text_t link; 
     319 
     320          if (cinfo->isCollectGroup) { 
     321        link = "<a class=\"collectiontitle\" href=\"_gwcgi_?"+optsite+"a=p&amp;p=home&amp;g=" + *collist_here; 
     322        link += "&amp;l=" + args["l"] + "&amp;w=" + args["w"] + "\">"; 
     323          } 
     324          else { 
     325        link = "<a class=\"collectiontitle\"href=\"_gwcgi_?"+optsite+"a=p&amp;p=about&amp;c=" + *collist_here; 
     326        link += "&amp;l=" + args["l"] + "&amp;w=" + args["w"] + "\">"; 
     327          } 
     328           
     329          if (!cinfo->receptionist.empty())  
     330        link = "<a class=\"collectiontitle\"href=\"" + cinfo->receptionist + "\">"; 
     331           
    266332           
    267333          // url to image: try iconcollectionsmall, then iconcollection 
     
    291357         
    292358        collectionname  
    293           = "<img width=\"150\" src=\"" + iconurl + "\" alt=\"" + alt + "\">"; 
    294           } else { 
    295         collectionname = alt; 
     359          = link + "<img width=\"150\" src=\"" + iconurl + "\" alt=\"" + alt + "\">" + "</a>"; 
     360          } else {       
     361 
     362        collectionname = "<div class=\"collecttitle\" style=\"width: 150px; border: 1px solid; \"><p class=\"collectiontitle\" style=\"font-size: 18px; width: 150px; white-space:normal; \">"; 
     363        collectionname += alt + "</p></div>"; 
     364 
     365        collectionname = link + collectionname + "</a>"; 
     366 
    296367          } 
    297368           
    298369          if (count%configinfo.HomePageCols == 0) 
    299         homeextra += "<tr valign=\"top\">\n"; 
    300            
    301           comerror_t err; 
    302           text_t optsite = g_EmptyText; 
    303           text_t site_name = (*rprotolist_here).p->get_site_name (err); 
    304           if (!site_name.empty()) { optsite = "site="+site_name+"&amp;"; } 
    305  
    306           text_t link = "<a href=\"_gwcgi_?"+optsite+"a=p&amp;p=about&amp;c=" + *collist_here; 
    307           link += "&amp;l=" + args["l"] + "&amp;w=" + args["w"] + "\">"; 
    308            
    309           if (!cinfo->receptionist.empty())  
    310         link = "<a href=\"" + cinfo->receptionist + "\">"; 
    311            
    312           homeextra += "<td>" + link + collectionname + "</a></td>\n"; 
     370        homeextra += "<tr valign=\"top\">\n";          
     371 
     372          homeextra += "<td align=\"center\">" + collectionname + "</td>\n"; 
    313373           
    314374          ++count;