source: branches/corba/gsdl/src/colservr/collectset.cpp@ 1510

Last change on this file since 1510 was 1510, checked in by davidb, 24 years ago

Improvements to corba implementation so images within a collection
are handled better and images in the remote site that are missing
locally are cached.

  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1/**********************************************************************
2 *
3 * collectset.cpp --
4 * Copyright (C) 1999 The New Zealand Digital Library Project
5 *
6 * A component of the Greenstone digital library software
7 * from the New Zealand Digital Library Project at the
8 * University of Waikato, New Zealand.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 * $Id: collectset.cpp 1510 2000-09-06 21:51:08Z davidb $
25 *
26 *********************************************************************/
27
28
29#include "collectserver.h"
30#include "filter.h"
31#include "browsefilter.h"
32#include "queryfilter.h"
33#include "infodbclass.h"
34#include "mgsearch.h"
35#include "mggdbmsource.h"
36#include "fileutil.h"
37#include <assert.h>
38
39#include "colservrconfig.h"
40#include "recptconfig.h"
41
42#include "collectset.h"
43
44collectset::collectset (text_t &gsdlhome) {
45
46 text_tarray collections;
47
48 // get gsdlhome (if we fail the error will be picked up later -- in
49 // cgiwrapper)
50 if (site_cfg_read (gsdlhome,httpdomain,httpprefix)) {
51 text_t collectdir = filename_cat (gsdlhome, "collect");
52 if (!read_dir (collectdir, collections)) {
53 cerr << "couldn't read collect directory - make sure gsdlhome field is correct in gsdlsite.cfg\n";
54 exit (1);
55 }
56 }
57
58 text_tarray::const_iterator thiscol = collections.begin();
59 text_tarray::const_iterator endcol = collections.end();
60
61 while (thiscol != endcol) {
62
63 // ignore the modelcol
64 if (*thiscol == "modelcol") {
65 thiscol ++;
66 continue;
67 }
68
69 // this memory is created but never destroyed
70 // we're also not doing any error checking to make sure we didn't
71 // run out of memory
72 collectserver *cserver = new collectserver();
73 gdbmclass *gdbmhandler = new gdbmclass();
74 mgsearchclass *mgsearch = new mgsearchclass();
75
76 // add a null filter
77 filterclass *filter = new filterclass ();
78 cserver->add_filter (filter);
79
80 // add a browse filter
81 browsefilterclass *browsefilter = new browsefilterclass();
82 browsefilter->set_gdbmptr (gdbmhandler);
83 cserver->add_filter (browsefilter);
84
85 // add a query filter
86 queryfilterclass *queryfilter = new queryfilterclass();
87 queryfilter->set_gdbmptr (gdbmhandler);
88 queryfilter->set_mgsearchptr (mgsearch);
89 cserver->add_filter (queryfilter);
90
91 // add a mg and gdbm source
92 mggdbmsourceclass *mggdbmsource = new mggdbmsourceclass ();
93 mggdbmsource->set_gdbmptr (gdbmhandler);
94 mggdbmsource->set_mgsearchptr (mgsearch);
95 cserver->add_source (mggdbmsource);
96
97 // inform collection server and everything it contains about its
98 // collection name
99 cserver->configure ("collection", *thiscol);
100
101 // GRB: removed proto.add_collectserver (cserver);
102 // GRB: added to build our own cservers list
103 cservers.addcollectserver (cserver);
104
105 thiscol ++;
106 }
107}
108
109collectset::~collectset () {
110}
111
112bool collectset::init (ostream &logout) {
113 collectservermapclass::iterator here = cservers.begin();
114 collectservermapclass::iterator end = cservers.end();
115
116 while (here != end) {
117 assert ((*here).second.c != NULL);
118 if ((*here).second.c != NULL) {
119 const colservrconf &configinfo = (*here).second.c->get_configinfo ();
120
121 // configure this collection server
122
123 // note that we read build.cfg before collect.cfg so that the indexmaps
124 // are available to decode defaultindex, defaultsubcollection, and
125 // defaultlanguage
126
127 if (!build_cfg_read (*((*here).second.c), configinfo.gsdlhome,
128 configinfo.collection)) {
129 outconvertclass text_t2ascii;
130 logout << text_t2ascii
131 << "Warning: couldn't read build.cfg file for collection \""
132 << configinfo.collection << "\", gsdlhome=\""
133 << configinfo.gsdlhome << "\"\n";
134 here ++;
135 continue;
136 }
137
138 if (!collect_cfg_read (*((*here).second.c), configinfo.gsdlhome,
139 configinfo.collection)) {
140 outconvertclass text_t2ascii;
141 logout << text_t2ascii
142 << "Warning: couldn't read collect.cfg file for collection \""
143 << configinfo.collection << "\", gsdlhome=\""
144 << configinfo.gsdlhome << "\"\n";
145 here ++;
146 continue;
147 }
148
149 if (!(*here).second.c->init (logout)) return false;
150
151 (*here).second.c->configure("httpdomain",httpdomain);
152 (*here).second.c->configure("httpprefix",httpprefix);
153 }
154 here++;
155 }
156
157 return true;
158}
159
160collectservermapclass collectset::servers()
161{ return cservers;
162}
163
164void collectset::configure(const text_t &key, const text_tarray &cfgline)
165{
166 if (key == "collection" || key == "collectdir") return;
167
168 collectservermapclass::iterator here = cservers.begin();
169 collectservermapclass::iterator end = cservers.end();
170
171 while (here != end) {
172 assert ((*here).second.c != NULL);
173 if ((*here).second.c != NULL) {
174 if (key == "collectinfo") {
175 if ((*here).first == cfgline[0]) {
176 (*here).second.c->configure ("gsdlhome", cfgline[1]);
177 (*here).second.c->configure ("gdbmhome", cfgline[2]);
178 }
179 } else {
180 // cout << "*** Passing on key = " << key << " = " << cfgline[0] << endl; // ****
181 (*here).second.c->configure (key, cfgline);
182 }
183 }
184
185 here++;
186 }
187}
188
189void collectset::getCollectionList (text_tarray &collist)
190{
191 collist.erase(collist.begin(),collist.end());
192
193 collectservermapclass::iterator here = cservers.begin();
194 collectservermapclass::iterator end = cservers.end();
195 while (here != end) {
196 assert ((*here).second.c != NULL);
197 if ((*here).second.c != NULL) {
198 collist.push_back ((*here).second.c->get_collection_name());
199 }
200 here++;
201 }
202}
203
Note: See TracBrowser for help on using the repository browser.